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:fr.cnrs.sharp.reasoning.Unification.java

public static int countBN(Model m) {
    Set<RDFNode> set = new HashSet<RDFNode>();
    ResIterator resIt = m.listSubjects();
    while (resIt.hasNext()) {
        Resource r = resIt.next();
        if (r.isAnon()) {
            set.add(r);//from  w  w  w. j  a v  a2s . c  o  m
        }
    }
    NodeIterator nodeIt = m.listObjects();
    while (nodeIt.hasNext()) {
        RDFNode n = nodeIt.next();
        if (n.isAnon()) {
            set.add(n);
        }
    }
    return set.size();
}

From source file:grails.plugin.searchable.internal.util.GrailsDomainClassUtils.java

/**
 * Get the parent GrailsDomainClass for the given GrailsDomainClass, if it
 * exists in the given collection otherwise null
 *
 * @param grailsDomainClass the class whose parent to find
 * @param grailsDomainClasses the collection of possible parents
 * @return null if the given class has no parent or the parent is not in the collection
 *//*from   w w w . j  av  a2 s.  c  o m*/
public static GrailsDomainClass getSuperClass(GrailsDomainClass grailsDomainClass,
        Collection grailsDomainClasses) {
    Set candidates = new HashSet();
    for (Iterator iter = grailsDomainClasses.iterator(); iter.hasNext();) {
        GrailsDomainClass gdc = (GrailsDomainClass) iter.next();
        if (gdc.getSubClasses().contains(grailsDomainClass)) {
            candidates.add(gdc);
        }
    }
    if (candidates.isEmpty()) {
        return null;
    }
    while (candidates.size() > 1) {
        Set copy = new HashSet(candidates);
        for (Iterator iter = copy.iterator(); iter.hasNext();) {
            GrailsDomainClass supsup = (GrailsDomainClass) iter.next();
            boolean remove = false;
            for (Iterator iter2 = candidates.iterator(); iter2.hasNext();) {
                GrailsDomainClass sup = (GrailsDomainClass) iter2.next();
                if (supsup.getSubClasses().contains(sup)) {
                    remove = true;
                    break;
                }
            }
            if (remove) {
                candidates.remove(supsup);
                break;
            }
        }
    }
    return (GrailsDomainClass) candidates.iterator().next();
}

From source file:com.wrmsr.wava.TestWhatever.java

@CheckReturnValue
private static BasicSet shrinkSimpleLoop(BasicLoopInfo li, BasicSet basics, Basic basic) {
    if (basic.getAllTargets().size() != 2 || basic.getAllTargets().contains(Basics.UNREACHABLE_NAME)
            || basic.getAllTargets().contains(basic.getName())) {
        return basics;
    }//ww w.j  a v a  2  s  .  co  m
    Set<Name> backEdgeInputs = basics.getInputs(basic.getName()).stream()
            .filter(t -> li.getBackEdges().containsEntry(basic.getName(), t)).collect(toImmutableSet());
    if (backEdgeInputs.size() != 1) {
        return basics;
    }
    Name loopBodyName = getOnlyElement(backEdgeInputs);
    if (!basic.getAllTargets().contains(loopBodyName) || !ImmutableSet
            .copyOf(basics.getInputs().get(loopBodyName)).equals(ImmutableSet.of(basic.getName()))) {
        return basics;
    }

    Basic loopBody = requireNonNull(basics.get(loopBodyName));
    Name succName;
    Node condition;
    if (loopBodyName.equals(basic.getBreakTable().getDefaultTarget())) {
        succName = getOnlyElement(basic.getBreakTable().getTargets());
        // FIXME r u sure
        condition = new Unary(UnaryOp.EqZ, Type.I32, basic.getBreakTable().getCondition());
    } else {
        succName = basic.getBreakTable().getDefaultTarget();
        condition = basic.getBreakTable().getCondition();
    }

    Node loop = new Loop(
            // FIXME check
            loopBodyName, nodify(ImmutableList.<Node>builder().addAll(loopBody.getBody())
                    .add(new If(condition, new Break(loopBodyName, new Nop()), new Nop())).build()));

    Basic newBasic = new Basic(basic.getName(),
            ImmutableList.<Node>builder().addAll(basic.getBody()).add(loop).build(),
            new BreakTable(ImmutableList.of(), succName, new Nop()), minBasicIndex(basic, loopBody));

    basics = basics.replace(newBasic);
    basics = basics.remove(loopBodyName);

    return basics;
}

From source file:org.eclipse.virgo.ide.facet.core.FacetUtils.java

public static IProject[] getParProjects(IProject project) {
    Set<IProject> bundles = new HashSet<IProject>();
    IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
    for (IProject candidate : projects) {
        if (FacetUtils.isParProject(candidate)) {
            if (Arrays.asList(getBundleProjects(candidate)).contains(project)) {
                bundles.add(candidate);//  w  w w.j  ava2 s .c om
            }
        }
    }
    return (IProject[]) bundles.toArray(new IProject[bundles.size()]);
}

From source file:com.streamsets.pipeline.lib.jdbc.multithread.util.OffsetQueryUtil.java

/**
 * Validates whether offset names match in the stored offset with respect to table configuration
 * @param tableContext {@link TableContext} for table
 * @param offset Stored offset from the previous stage run
 * @return the actual offset map as deserialized from the offset param, if valid
 * @throws StageException if columns mismatch
 *//*from  w ww  .  j  av a2  s .com*/
public static Map<String, String> validateStoredAndSpecifiedOffset(TableContext tableContext, String offset)
        throws StageException {
    Set<String> expectedColumns = Sets.newHashSet(tableContext.getOffsetColumns());
    final Map<String, String> actualOffsets = getColumnsToOffsetMapFromOffsetFormat(offset);

    // only perform the actual validation below if there ARE stored offsets
    if (actualOffsets.size() == 0) {
        return actualOffsets;
    }

    Set<String> actualColumns = actualOffsets.keySet();

    Set<String> expectedSetDifference = Sets.difference(expectedColumns, actualColumns);
    Set<String> actualSetDifference = Sets.difference(actualColumns, expectedColumns);

    if (expectedSetDifference.size() > 0 || actualSetDifference.size() > 0) {
        throw new StageException(JdbcErrors.JDBC_71, tableContext.getQualifiedName(),
                COMMA_SPACE_JOINER.join(actualColumns), COMMA_SPACE_JOINER.join(expectedColumns));
    }
    return actualOffsets;
}

From source file:org.camunda.bpm.spring.boot.starter.property.CamundaBpmProperties.java

static String[] initDeploymentResourcePattern() {
    final Set<String> suffixes = new HashSet<String>();
    suffixes.addAll(Arrays.asList(DEFAULT_DMN_RESOURCE_SUFFIXES));
    suffixes.addAll(Arrays.asList(DEFAULT_BPMN_RESOURCE_SUFFIXES));
    suffixes.addAll(Arrays.asList(DEFAULT_CMMN_RESOURCE_SUFFIXES));

    final Set<String> patterns = new HashSet<String>();
    for (String suffix : suffixes) {
        patterns.add(String.format("%s**/*.%s", CLASSPATH_ALL_URL_PREFIX, suffix));
    }/*from   ww w . j av a2s  .com*/

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

From source file:net.andydvorak.intellij.lessc.fs.VirtualFileLocationChange.java

public static int copyCssFiles(@NotNull final VirtualFileCopyEvent virtualFileCopyEvent,
        @Nullable final LessProfile lessProfile, @NotNull final VfsLocationChangeDialog vfsLocationChangeDialog)
        throws IOException {
    final Set<VirtualFileLocationChange> changes = getChanges(lessProfile, virtualFileCopyEvent);

    if (changes.isEmpty() || !vfsLocationChangeDialog.shouldCopyCssFile(virtualFileCopyEvent))
        return 0;

    for (VirtualFileLocationChange locationChange : changes) {
        locationChange.copy();//from  w  ww  .j  a  v a2  s.c  om
    }

    return changes.size();
}

From source file:net.andydvorak.intellij.lessc.fs.VirtualFileLocationChange.java

public static int moveCssFiles(@NotNull final VirtualFileMoveEvent virtualFileMoveEvent,
        @Nullable final LessProfile lessProfile, @NotNull final VfsLocationChangeDialog vfsLocationChangeDialog)
        throws IOException {
    final Set<VirtualFileLocationChange> changes = getChanges(lessProfile, virtualFileMoveEvent);

    if (changes.isEmpty() || !vfsLocationChangeDialog.shouldMoveCssFile(virtualFileMoveEvent))
        return 0;

    for (VirtualFileLocationChange locationChange : changes) {
        locationChange.move();/*from  w  w w .ja v a  2s  .  co  m*/
    }

    return changes.size();
}

From source file:com.github.gekoh.yagen.util.MappingUtils.java

public static Class[] getEntityClasses(EntityManagerFactory emf) throws Exception {
    Set<EntityType<?>> entities = emf.getMetamodel().getEntities();
    Class[] classes = new Class[entities.size()];
    int arrIdx = 0;
    for (EntityType<?> entityType : entities) {
        classes[arrIdx++] = entityType.getJavaType();
    }/*from   w w w  .  ja  v a2 s.c  o  m*/
    return classes;
}

From source file:edu.uci.ics.jung.algorithms.metrics.TriadicCensus.java

/**
  * Returns an array whose ith element (for i in [1,16]) is the number of 
  * occurrences of the corresponding triad type in <code>g</code>.
  * (The 0th element is not meaningful; this array is effectively 1-based.)
 * // www  .  ja  va 2s  . c  om
 * @param g
 */
public static <V, E> long[] getCounts(DirectedGraph<V, E> g) {
    long[] count = new long[MAX_TRIADS];

    List<V> id = new ArrayList<V>(g.getVertices());

    // apply algorithm to each edge, one at at time
    for (int i_v = 0; i_v < g.getVertexCount(); i_v++) {
        V v = id.get(i_v);
        for (V u : g.getNeighbors(v)) {
            int triType = -1;
            if (id.indexOf(u) <= i_v)
                continue;
            Set<V> neighbors = new HashSet<V>(CollectionUtils.union(g.getNeighbors(u), g.getNeighbors(v)));
            neighbors.remove(u);
            neighbors.remove(v);
            if (g.isSuccessor(v, u) && g.isSuccessor(u, v)) {
                triType = 3;
            } else {
                triType = 2;
            }
            count[triType] += g.getVertexCount() - neighbors.size() - 2;
            for (V w : neighbors) {
                if (shouldCount(g, id, u, v, w)) {
                    count[triType(triCode(g, u, v, w))]++;
                }
            }
        }
    }
    int sum = 0;
    for (int i = 2; i <= 16; i++) {
        sum += count[i];
    }
    int n = g.getVertexCount();
    count[1] = n * (n - 1) * (n - 2) / 6 - sum;
    return count;
}