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:Main.java

public static double computeDice(Collection<String> c1, Collection<String> c2) {
    Set<String> intersection = new HashSet<>(c1);
    intersection.retainAll(c1);/*  w w w  .  j av  a2  s  .  co  m*/
    intersection.retainAll(c2);

    if (intersection.size() == 0)
        return 0.0;
    double score = 2 * (double) intersection.size() / (c1.size() + c2.size());
    return score;

}

From source file:org.atemsource.atem.impl.EntityTypeUtils.java

public static String[] convertToArray(final Set<String> selectableTypeCodes) {
    return selectableTypeCodes.toArray(new String[selectableTypeCodes.size()]);
}

From source file:edu.infsci2560.PageHtmlValidator.java

public static void validatePage(String pageSource) {
    Validator htmlValidator = new ValidatorBuilder().html();
    ValidationResponse response = null;/*  w w w.ja va  2  s  .c om*/
    try {
        response = htmlValidator.validate(pageSource);
    } catch (IOException e) {
        logger.error("Error validation {}", e);
    }

    Set<Defect> errors = response.errors();
    int errorCount = errors.size();
    logger.info("W3C validation errors count: {}", errorCount);
    logDefects(new ArrayList<>(errors), "error");

    Set<Defect> warnings = response.warnings();
    int warningCount = warnings.size();
    logger.info("W3C validation warnings count: {}", warningCount);
    logDefects(new ArrayList<>(warnings), "warning");

    if (errorCount > 0 || warningCount > 0) {
        logger.info(repeat("=", 40));
        logger.info("===PAGE SOURCE==: \n{}", pageSource);
        logger.info(repeat("=", 40));
    }

    assertTrue("Error count exceed.", errorCount <= ALLOWED_ERROR_COUNT);
    assertTrue("Warning count exceed.", warnings.size() <= ALLOWED_WARNING_COUNT);
}

From source file:io.github.dustalov.maxmax.Application.java

private static void write(String filename, MaxMax<String> maxmax) throws IOException {
    try (final BufferedWriter writer = Files.newBufferedWriter(Paths.get(filename))) {
        int i = 0;
        for (final Set<String> cluster : maxmax.getClusters()) {
            writer.write(String.format(Locale.ROOT, "%d\t%d\t%s\n", i++, cluster.size(),
                    String.join(", ", cluster)));
        }/* w w w  .  j  a  v a 2 s .c o m*/
    }
}

From source file:Main.java

/**
 * Checks if a View matches a certain string and returns the amount of total matches.
 * //w  w  w  . j  av  a2 s. co m
 * @param regex the regex to match
 * @param view the view to check
 * @param uniqueTextViews set of views that have matched
 * @return number of total matches
 */

public static int getNumberOfMatches(String regex, TextView view, Set<TextView> uniqueTextViews) {
    if (view == null) {
        return uniqueTextViews.size();
    }

    Pattern pattern = null;
    try {
        pattern = Pattern.compile(regex);
    } catch (PatternSyntaxException e) {
        pattern = Pattern.compile(regex, Pattern.LITERAL);
    }

    Matcher matcher = pattern.matcher(view.getText().toString());

    if (matcher.find()) {
        uniqueTextViews.add(view);
    }

    if (view.getError() != null) {
        matcher = pattern.matcher(view.getError().toString());
        if (matcher.find()) {
            uniqueTextViews.add(view);
        }
    }
    if (view.getText().toString().equals("") && view.getHint() != null) {
        matcher = pattern.matcher(view.getHint().toString());
        if (matcher.find()) {
            uniqueTextViews.add(view);
        }
    }
    return uniqueTextViews.size();
}

From source file:io.fabric8.arquillian.utils.Routes.java

/**
 * Should we try to create a route for the given service?
 * <p/>//from  w  w  w .j a  v a 2 s.co m
 * By default lets ignore the kubernetes services and any service which does not expose ports 80 and 443
 *
 * @returns true if we should create an OpenShift Route for this service.
 */
protected static boolean shouldCreateRouteForService(Logger log, Service service, String id) {
    if ("kubernetes".equals(id) || "kubernetes-ro".equals(id)) {
        return false;
    }
    Set<Integer> ports = KubernetesHelper.getPorts(service);
    if (ports.size() == 1) {
        return true;
    } else {
        log.info("Not generating route for service " + id
                + " as only single port services are supported. Has ports: " + ports);
        return false;
    }
}

From source file:org.centralperf.controller.BaseController.java

/**
 * Validate a bean based on javax.validation API
 * @param bean Bean to validate/*from   w  ww  .j  av  a 2 s .c o  m*/
 * @throws ControllerValidationException If the bean is not validated
 */
protected static void validateBean(Object bean) throws ControllerValidationException {
    ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
    Validator validator = factory.getValidator();
    Set<ConstraintViolation<Object>> constraintViolations = validator.validate(bean);
    if (constraintViolations.size() > 0) {
        StringBuilder errorMessage = new StringBuilder();
        for (ConstraintViolation<Object> constraintViolation : constraintViolations) {
            errorMessage.append(constraintViolation.getMessage());
        }
        throw new ControllerValidationException(errorMessage.toString());
    }
}

From source file:Main.java

public static int[] integerSetToInt(Set<Integer> integerSet) {
    if (integerSet == null)
        return new int[0];

    int i = 0;//  w w  w .  java  2s.c  o  m
    int[] intArrays = new int[integerSet.size()];
    for (Iterator<Integer> Itr = integerSet.iterator(); Itr.hasNext();) {
        intArrays[i] = Itr.next().intValue();
        i++;
    }
    return intArrays;
}

From source file:com.tealcube.minecraft.bukkit.mythicdrops.utils.ChatColorUtil.java

public static ChatColor getRandomChatColorFromSet(Set<ChatColor> chatColors) {
    ChatColor[] chatColors1 = chatColors.toArray(new ChatColor[chatColors.size()]);
    return chatColors1[RandomUtils.nextInt(chatColors1.length)];
}

From source file:Main.java

public static <T> List<T> intersect(List<T> list1, Set<T> set2) {
    List<T> intersection = new ArrayList<>(set2.size());

    for (T e : list1) {
        if (set2.contains(e)) {
            intersection.add(e);// ww w  .jav a  2 s .  co  m
        }
    }
    return intersection;
}