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:cz.hobrasoft.pdfmu.error.ErrorType.java

/**
 * @return true iff the codes stored in {@link #CODES} are pairwise
 * different./*from   w w  w .  j av a 2 s .co m*/
 */
private static boolean codesUnique() {
    Collection<Integer> codes = CODES.intPropertyValues();
    Set<Integer> codesUnique = new HashSet<>(codes);
    assert codes.size() >= codesUnique.size();
    return codes.size() == codesUnique.size();
}

From source file:bayesGame.ui.painter.AndNodePainter.java

public static Image paintPercentage(Color gridColor, Color falseColor, int size, int squaresize, BayesNode node,
        Fraction parentNode1Probability, Fraction parentNode2Probability) {

    BufferedImage img = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB);
    Graphics g = img.getGraphics();

    NodePainter.graphicBackgroundPainter(g, 0, 0, size, size);

    // get non-zero truth table entries from the node
    List<Map<Object, Boolean>> nonZeroEntries = node.getNonZeroProbabilities();

    // get the identities of its parents by taking the first map and querying it 
    // for KeySet, subtracting the object representing the node itself
    Set<Object> nodeParents = nonZeroEntries.get(0).keySet();
    nodeParents.remove(node.type);//www  .  ja v  a 2  s .  c  o m

    if (nodeParents.size() > 2) {
        throw new IllegalArgumentException("AND node with more than 2 parents not yet implemented");
    }

    Object[] nodeParentsArray = nodeParents.toArray();
    Object parent1 = nodeParentsArray[0];
    Object parent2 = nodeParentsArray[1];

    // for each map, check the truth table entry it corresponds to and color
    // those appropriately
    boolean p1true_p2true = false;
    boolean p1true_p2false = false;
    boolean p1false_p2true = false;
    boolean p1false_p2false = false;

    for (Map<Object, Boolean> map : nonZeroEntries) {
        Boolean parent1truth = map.get(parent1);
        Boolean parent2truth = map.get(parent2);

        if (parent1truth && parent2truth) {
            p1true_p2true = true;
        } else if (parent1truth && !parent2truth) {
            p1true_p2false = true;
        } else if (!parent1truth && parent2truth) {
            p1false_p2true = true;
        } else if (!parent1truth && !parent2truth) {
            p1false_p2false = true;
        }
    }

    Color whiteColor = Color.WHITE;

    int XSize = parentNode1Probability.multiply(size).intValue();
    int X_Size = size - XSize;
    int YSize = parentNode2Probability.multiply(size).intValue();
    int Y_Size = size - YSize;

    if (p1true_p2true) {
        NodePainter.squarePainter(g, 0, 0, XSize, YSize, gridColor, Color.BLACK);
    } else {
        NodePainter.squarePainter(g, 0, 0, XSize, YSize, NodePainter.RECTANGLE_BOX_BACKGROUND_COLOR,
                Color.BLACK);
    }

    NodePainter.squarePainter(g, XSize, 0, X_Size, YSize, falseColor, Color.BLACK);
    NodePainter.squarePainter(g, 0, YSize, XSize, Y_Size, falseColor, Color.BLACK);

    if (p1false_p2false) {
        NodePainter.squarePainter(g, XSize, YSize, X_Size, Y_Size, falseColor, Color.BLACK);
    } else {
        NodePainter.squarePainter(g, XSize, YSize, X_Size, Y_Size, NodePainter.RECTANGLE_BOX_BACKGROUND_COLOR,
                Color.BLACK);
    }

    return img;
}

From source file:com.conwet.silbops.model.Constraint.java

/**
 * Deserialize from a JSON representation
 *
 * @param json JSON representation//from www.j  av  a  2  s  .com
 * @return A new constraint
 */
public static Constraint fromJSON(JSONObject json) {

    @SuppressWarnings("unchecked")
    Set<Map.Entry<String, Object>> entries = json.entrySet();

    if (entries.size() != 1) {

        throw new IllegalArgumentException("Malformed object: " + json);
    }

    Entry<String, Object> entry = entries.iterator().next();
    Operator operator = Operator.fromJSON(entry.getKey());
    return (operator == Operator.EXISTS) ? EXIST : new Constraint(operator, Value.fromJSON(entry.getValue()));
}

From source file:com.etsy.arbiter.config.ConfigurationMerger.java

/**
 * Check if all values on a collection of ActionTypes are equal
 *
 * @param actionTypes The collection of ActionTypes to check
 * @param transformFunction The function that produces the value from an ActionType
 * @param <T> The type of value being checked
 * @return true if all given ActionTypes have the same value, false otherwise
 *//*from ww  w  . j  av  a  2  s  . c o  m*/
public static <T> boolean areAllValuesEqual(Collection<ActionType> actionTypes,
        Function<ActionType, T> transformFunction) {
    Collection<T> values = Collections2.transform(actionTypes, transformFunction);
    Set<T> valueSet = new HashSet<>(values);

    return valueSet.size() == 1;
}

From source file:eu.annocultor.converters.europeana.RecordCompletenessRanking.java

/**
 * Utility function: count new words and compute points for them.
 *//*from  w w  w.java2  s . c o  m*/
static int computePoints(Set<String> words, Collection<String> fields, int wordsPerPoint) {

    int wordsBefore = words.size();
    words.addAll(extractWordsFromFields(fields));
    return capPoints((words.size() - wordsBefore) / wordsPerPoint);
}

From source file:com.twitter.ambrose.util.JSONUtil.java

private static ObjectMapper newMapper() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    mapper.enable(SerializationFeature.INDENT_OUTPUT);
    mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
    mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT, false);
    mapper.disable(SerializationFeature.FLUSH_AFTER_WRITE_VALUE);
    mapper.disable(SerializationFeature.CLOSE_CLOSEABLE);
    mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);

    Reflections reflections = new Reflections("com.twitter.ambrose");
    Set<Class<? extends Job>> jobSubTypes = reflections.getSubTypesOf(Job.class);
    mapper.registerSubtypes(jobSubTypes.toArray(new Class<?>[jobSubTypes.size()]));
    return mapper;
}

From source file:net.lldp.checksims.algorithm.AlgorithmRunner.java

/**
 * Run a pairwise similarity detection algorithm.
 *
 * @param submissions Pairs to run on//from w  w w  .j  a v  a  2  s.  c  om
 * @param algorithm Algorithm to use
 * @return Collection of AlgorithmResults, one for each input pair
 */
public static Set<AlgorithmResults> runAlgorithm(Set<Pair<Submission, Submission>> submissions,
        SimilarityDetector<?> algorithm, StatusLogger logger) throws ChecksimsException {
    checkNotNull(submissions);
    checkArgument(submissions.size() > 0, "Must provide at least one pair of submissions to run on!");
    checkNotNull(algorithm);

    Logger logs = LoggerFactory.getLogger(AlgorithmRunner.class);
    long startTime = System.currentTimeMillis();

    logs.info("Performing similarity detection on " + submissions.size() + " pairs using algorithm "
            + algorithm.getName());

    // Perform parallel analysis of all submission pairs to generate a results list
    Set<AlgorithmResults> results = ParallelAlgorithm.parallelSimilarityDetection(algorithm, submissions,
            logger);

    long endTime = System.currentTimeMillis();
    long timeElapsed = endTime - startTime;

    logs.info("Finished similarity detection in " + timeElapsed + " ms");

    return results;
}

From source file:org.killbill.billing.plugin.simpletax.config.http.TaxCodeController.java

private static TaxCodesGETRsc toTaxCodesGETRscOrNull(UUID invoiceId, UUID invoiceItemId, String taxCodes) {
    Set<String> names = splitTaxCodes(taxCodes);
    if (names.size() == 0) {
        return null;
    }/*from ww w.j a  v a  2s  . co  m*/
    ImmutableSet.Builder<TaxCodeRsc> codes = ImmutableSet.builder();
    for (String name : names) {
        codes.add(new TaxCodeRsc(name));
    }
    return new TaxCodesGETRsc(invoiceItemId, invoiceId, codes.build());
}

From source file:com.cloud.utils.PropertiesUtil.java

public static Map<String, Object> toMap(Properties props) {
    Set<String> names = props.stringPropertyNames();
    HashMap<String, Object> map = new HashMap<String, Object>(names.size());
    for (String name : names) {
        map.put(name, props.getProperty(name));
    }//from   w  w w . j  a  v  a2 s  .c  om

    return map;
}

From source file:com.opengamma.integration.viewer.status.AggregateType.java

private static boolean hasDepulicateChar(String aggregateStrType) {
    char[] aggregateTypeChars = aggregateStrType.toCharArray();
    Set<Character> uniqueChars = Sets.newHashSet();
    for (Character character : aggregateTypeChars) {
        uniqueChars.add(character);/*from   ww w .  j a  va2s .  com*/
    }
    return uniqueChars.size() != VALID_AGGRAGATION_CHARS.size();
}