Example usage for java.util Set size

List of usage examples for java.util Set size

Introduction

In this page you can find the example usage for java.util Set size.

Prototype

int size();

Source Link

Document

Returns the number of elements in this set (its cardinality).

Usage

From source file:edu.umass.cs.utils.Util.java

public static int[] setToIntArray(Set<Integer> set) {
    int[] array = new int[set.size()];
    int i = 0;//  w  w w .  j a  va2s  . c o m
    for (int id : set) {
        array[i++] = id;
    }
    return array;
}

From source file:edu.umass.cs.utils.Util.java

public static Object[] setToNodeIdArray(Set<?> set) {
    Object[] array = new Object[set.size()];
    int i = 0;/* www  .j a v  a  2 s  .  com*/
    for (Object id : set) {
        array[i++] = id;
    }
    return array;
}

From source file:com.delicious.deliciousfeeds4J.DeliciousUtil.java

public static Set<User> deserializeUsersFromJson(String json) throws Exception {

    logger.debug("Trying to deserialize JSON to Users...");
    logger.trace("Deserializing JSON: " + json);

    //Check if empty or null
    if (json == null || json.isEmpty()) {
        logger.debug("Nothing to deserialize. JSON-string was empty!");
        return null;
    }//  w  ww  . jav a 2s. com

    //Actually deserialize
    final Set<User> users = ((Set<User>) objectMapper.readValue(json, new TypeReference<Set<User>>() {
    }));

    if (users == null || users.isEmpty()) {
        logger.debug("No users found. Collection was empty.");
        return null;
    }

    logger.info("Successfully deserialized {} users!", users.size());

    return users;
}

From source file:com.adaptris.core.SharedComponentList.java

private static Collection<? extends AdaptrisComponent> ensureNoDuplicateIds(
        Collection<? extends AdaptrisComponent> components) throws IllegalArgumentException {
    Set<String> componentIds = new HashSet<>();
    for (AdaptrisComponent c : components) {
        componentIds.add(c.getUniqueId());
    }//from w w  w. j ava  2 s  .  c  o m
    if (componentIds.size() != components.size()) {
        throw new IllegalArgumentException("Found shared components with duplicate IDs; please review config");
    }
    return components;
}

From source file:edu.umass.cs.utils.Util.java

public static Integer[] setToIntegerArray(Set<Integer> set) {
    Integer[] array = new Integer[set.size()];
    int i = 0;/*from  ww  w. j  a  v  a 2  s .c  o  m*/
    for (Integer id : set) {
        array[i++] = id;
    }
    return array;
}

From source file:keepinchecker.utility.EmailUtilities.java

private static String generateBodyText(String senderName) throws Exception {
    StringBuilder bodyText = new StringBuilder();

    bodyText.append("Hello,\n\nOn behalf of " + senderName + ", you have received this"
            + " email with the following data,\n\n");

    Set<KeepInCheckerPacket> packets = packetManager.getPackets();
    if (!packets.isEmpty()) {
        StringBuilder packetData = new StringBuilder();

        for (KeepInCheckerPacket packet : packets) {
            packetData.append("\n" + new Date(packet.getTimestamp()).toString() + " " + packet.getTimezone()
                    + " " + packet.getGetValue() + " " + packet.getHostValue() + " "
                    + packet.getRefererValue());
        }// w w  w .  j  av a 2s .c om

        bodyText.append(packets.size() + " questionable sites were visted:\n");
        bodyText.append(packetData.toString());
    } else {
        bodyText.append("0 questionable sites were visited.");
    }

    bodyText.append("\n\nKeep staying accountable!\n\nSincerely,\nKeepInChecker");

    return bodyText.toString();
}

From source file:com.ecarride.App.java

public static Map<String, String> generateAdminEmailContent(Set<TlcDriver> tlcDrivers) {
    Iterator<TlcDriver> iterator = tlcDrivers.iterator();
    Map<String, String> result = new LinkedHashMap<>();
    String FhvDriverActiveResult = "<b><a href=\"https://data.cityofnewyork.us/Transportation/For-Hire-Vehicles-FHV-Active-Drivers/xjfq-wh2d/data\">These drivers are not active in For-Hire-Vehicles-FHV-Active-Drivers table</a>: "
            + "(" + (tlcDrivers.size() - fhvDriverActiveNum) + "/" + tlcDrivers.size() + ")"
            + "</b> <br><table>";
    String ShlActiveResult = "<b><a href=\"https://data.cityofnewyork.us/Transportation/Street-Hail-Livery-Drivers-Active/5tub-eh45/data\">These drivers are not active in Street-Hail-Livery-Drivers-Active table</a>: "
            + "(" + (tlcDrivers.size() - fhvShlActiveNum) + "/" + tlcDrivers.size() + ")" + "</b> <br><table>";
    String FhvVehicleResult = "<b><a href=\"https://data.cityofnewyork.us/Transportation/For-Hire-Vehicles-FHV-Active-and-Inactive-Vehicles/8wbx-tsch/data\">These drivers are not active in For-Hire-Vehicles-FHV-Active-and-Inactive-Vehicles table</a>: "
            + "(" + (tlcDrivers.size() - fhvVehichleActiveNum) + "/" + tlcDrivers.size() + ")"
            + "</b> <br><table>";
    String BaseChangedResult = "<b><a href=\"https://data.cityofnewyork.us/Transportation/For-Hire-Vehicles-FHV-Active-and-Inactive-Vehicles/8wbx-tsch/data\">These drivers are not affiliated to our base</a>: "
            + "(" + baseChangedNum + "/" + tlcDrivers.size() + ")" + "<b></br><table>";
    while (iterator.hasNext()) {
        TlcDriver driver = iterator.next();
        if (!driver.isActiveInFhvDrivers()) {
            FhvDriverActiveResult += "<tr><td><b>Name: </b><span style='padding-left:5px;'>"
                    + driver.getDriver().getFirstName() + " " + driver.getDriver().getLastName()
                    + "</span></td><td><b>TLC_FHV_License_Number: </b><span style='padding-left:5px;color:red;'>"
                    + driver.getDriver().getDriverTlcFhvLicenseNum()
                    + "  </span></td><td><b>TLC_FHV_Vehicle_License_Number: </b><span style='padding-left:5px;'>"
                    + driver.getTaxiVehicle().getVehicleTlcFhvLicenseNum() + "</span></td></tr>";
        }//from  ww  w.j  a va 2s .  co  m

        if (!driver.isActiveInStreetHailLivery()) {
            ShlActiveResult += "<tr><td><b>Name: </b><span style='padding-left:5px;'>"
                    + driver.getDriver().getFirstName() + " " + driver.getDriver().getLastName()
                    + "</span></td><td><b>TLC_FHV_License_Number: </b><span style='padding-left:5px;color:red;'>"
                    + driver.getDriver().getDriverTlcFhvLicenseNum()
                    + "  </span></td><td><b>TLC_FHV_Vehicle_License_Number: </b><span style='padding-left:5px;'>"
                    + driver.getTaxiVehicle().getVehicleTlcFhvLicenseNum() + "</span></td></tr>";
        }
        if (!driver.isActiveInvehiclesFhv()) {
            FhvVehicleResult += "<tr><td><b>Name: </b><span style='padding-left:5px;'>"
                    + driver.getDriver().getFirstName() + " " + driver.getDriver().getLastName()
                    + "</span></td><td><b>TLC_FHV_License_Number: </b><span style='padding-left:5px;'>"
                    + driver.getDriver().getDriverTlcFhvLicenseNum()
                    + "  </span></td><td><b>TLC_FHV_Vehicle_License_Number: </b><span style='padding-left:5px;color:red;'>"
                    + driver.getTaxiVehicle().getVehicleTlcFhvLicenseNum() + "</span></td></tr>";
        }
        if (driver.isBaseChanged()) {
            BaseChangedResult += "<tr><td><b>Name: </b><span style='padding-left:5px;'>"
                    + driver.getDriver().getFirstName() + " " + driver.getDriver().getLastName()
                    + "</span></td><td><b>TLC_FHV_License_Number: </b><span style='padding-left:5px;'>"
                    + driver.getDriver().getDriverTlcFhvLicenseNum()
                    + "  </span></td><td><b>TLC_FHV_Vehicle_License_Number: </b><span style='padding-left:5px; color:red;'>"
                    + driver.getTaxiVehicle().getVehicleTlcFhvLicenseNum() + "</span></td></tr>";
        }
    }

    FhvDriverActiveResult += "</table>";
    ShlActiveResult += "</table>";
    FhvVehicleResult += "</table>";
    BaseChangedResult += "</table>";

    result.put("Admin_FhvDriver", FhvDriverActiveResult);
    result.put("Admin_Shl", ShlActiveResult);
    result.put("Admin_FhvVehicle", FhvVehicleResult);
    result.put("Admin_BaseChanged", BaseChangedResult);

    return result;
}

From source file:com.reactive.hzdfs.utils.EntityFinder.java

/**
 * // w  w  w . j  a va2 s .c o  m
 * @param provider
 * @param basePkg
 * @return
 * @throws ClassNotFoundException
 */
private static Set<Class<?>> findComponents(ClassPathScanningCandidateComponentProvider provider,
        String basePkg) throws ClassNotFoundException {
    Set<BeanDefinition> beans = null;
    String pkg = "";
    try {
        pkg = StringUtils.hasText(basePkg) ? basePkg : EntityFinder.class.getPackage().getName();
        beans = provider.findCandidateComponents(pkg);
    } catch (Exception e) {
        throw new ClassNotFoundException("Unable to scan for classes under given base package",
                new IllegalArgumentException("Package=> " + pkg, e));
    }

    Set<Class<?>> classes = new HashSet<>();
    if (beans != null && !beans.isEmpty()) {
        classes = new HashSet<>(beans.size());
        for (BeanDefinition bd : beans) {
            classes.add(Class.forName(bd.getBeanClassName()));
        }
    } else {
        log.warn(">> Did not find any classes under the given base package [" + basePkg + "]");
    }
    return classes;
}

From source file:mobile.service.UserService.java

/**
 * ?/*from  w  w w  .j ava 2s  .  co  m*/
 *
 * @param size ??
 * @return
 */
public static List<TopUser> getTopUserList(int size) {
    Set<TopExpert> tops = new LinkedHashSet<>();
    List<TopCate> cates = SkillTag.getTopCateWithCache();
    boolean isContinue = false;
    int counter = 0;
    do {
        isContinue = false;
        for (TopCate topCate : cates) {
            List<TopExpert> topExperts = topCate.getTopExperts();
            if (counter < topExperts.size()) {
                tops.add(topExperts.get(counter));
                if (tops.size() >= size) {
                    isContinue = false;
                    break;
                } else {
                    isContinue = true;
                }
            }
        }
        counter++;
    } while (isContinue);

    List<TopUser> list = new ArrayList<>();
    for (TopExpert expert : tops) {
        list.add(TopUser.create(expert));
    }

    return list;
}

From source file:com.mirth.connect.client.core.api.util.OperationUtil.java

public static String[] getOperationNamesForPermission(String permissionName, Class<?> servletInterface,
        String... extraOperationNames) {
    Set<String> operationNames = new HashSet<String>();

    for (Class<?> coreServletInterface : new Reflections("com.mirth.connect.client.core.api.servlets")
            .getSubTypesOf(BaseServletInterface.class)) {
        addOperationName(permissionName, coreServletInterface, operationNames);
    }//from  w w  w .j a  v a 2  s  .c  o  m

    if (servletInterface != null) {
        addOperationName(permissionName, servletInterface, operationNames);
    }

    if (ArrayUtils.isNotEmpty(extraOperationNames)) {
        operationNames.addAll(Arrays.asList(extraOperationNames));
    }

    return operationNames.toArray(new String[operationNames.size()]);
}