Example usage for java.util HashSet size

List of usage examples for java.util HashSet size

Introduction

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

Prototype

public int size() 

Source Link

Document

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

Usage

From source file:org.entrystore.repository.impl.ListImpl.java

public boolean setChildren(java.util.List<URI> newChildren, boolean singleParentForListsRequirement,
        boolean orderedSetRequirement) {
    PrincipalManager pm = this.entry.getRepositoryManager().getPrincipalManager();
    boolean isOwnerOfContext = false;

    if (pm != null) {
        pm.checkAuthenticatedUserAuthorized(this.entry, AccessProperty.WriteResource);
        try {//  ww  w  .j a va2  s .  c o m
            pm.checkAuthenticatedUserAuthorized(this.entry.getContext().getEntry(),
                    AccessProperty.WriteResource);
            isOwnerOfContext = true;
        } catch (AuthorizationException ae) {
        }
    }

    if (children == null) {
        loadChildren();
    }
    java.util.List<URI> toRemove = new java.util.ArrayList<URI>(children);
    toRemove.removeAll(newChildren);
    java.util.List<URI> toAdd = new java.util.ArrayList<URI>(newChildren);
    toAdd.removeAll(children);

    for (URI uri : toAdd) {
        EntryImpl childEntry = (EntryImpl) this.entry.getContext().getByEntryURI(uri);
        if (singleParentForListsRequirement && childEntry.getGraphType() == GraphType.List
                && !childEntry.getReferringListsInSameContext().isEmpty()) {
            throw new org.entrystore.repository.RepositoryException(
                    "Cannot set the list since the child " + uri + " is a list which already have a parent.");
        }
        if (childEntry == null) {
            throw new org.entrystore.repository.RepositoryException(
                    "Cannot set the list since the child " + uri + " does not exist.");
        }
    }

    if (orderedSetRequirement) {
        HashSet<URI> set = new HashSet<URI>(newChildren);
        if (set.size() < newChildren.size()) {
            throw new org.entrystore.repository.RepositoryException(
                    "Cannot set the list since some of its children occur multiple times.");
        }
    }

    for (URI uri : toRemove) {
        EntryImpl childEntry = (EntryImpl) this.entry.getContext().getByEntryURI(uri);
        if (childEntry == null) {
            log.warn("List contains entry which does not exist: " + uri);
            continue;
        }
        if (!canRemove(true, childEntry, isOwnerOfContext)) {
            throw new org.entrystore.repository.RepositoryException(
                    "Cannot set the list since you do not have the rights to remove the child " + uri
                            + " from the list.");
        }
    }

    try {
        synchronized (this.entry.repository) {
            RepositoryConnection rc = entry.repository.getConnection();
            Vector<URI> oldChildrenList = children;
            try {
                rc.setAutoCommit(false);
                children = new Vector<URI>(newChildren);
                saveChildren(rc);
                for (URI uri : toAdd) {
                    EntryImpl childEntry = (EntryImpl) this.entry.getContext().getByEntryURI(uri);
                    if (childEntry != null) {
                        childEntry.addReferringList(this, rc); //TODO deprecate addReferringList.
                        if (isOwnerOfContext) {
                            childEntry.setOriginalListSynchronized(null, rc,
                                    entry.repository.getValueFactory());
                        }
                        entry.getRepositoryManager().fireRepositoryEvent(
                                new RepositoryEventObject(childEntry, RepositoryEvent.EntryUpdated));
                    }
                }
                for (URI uri : toRemove) {
                    EntryImpl childEntry = (EntryImpl) this.entry.getContext().getByEntryURI(uri);
                    if (childEntry != null) {
                        childEntry.removeReferringList(this, rc); //TODO deprecate removeReferringList.
                        if (isOwnerOfContext) {
                            childEntry.setOriginalListSynchronized(null, rc,
                                    entry.repository.getValueFactory());
                        }
                        entry.getRepositoryManager().fireRepositoryEvent(
                                new RepositoryEventObject(childEntry, RepositoryEvent.EntryUpdated));
                    }
                }
                rc.commit();
                entry.getRepositoryManager()
                        .fireRepositoryEvent(new RepositoryEventObject(entry, RepositoryEvent.ResourceUpdated));
            } catch (Exception e) {
                e.printStackTrace();
                rc.rollback();
                for (URI uri : toAdd) {
                    EntryImpl childEntry = ((EntryImpl) this.entry.getContext().getByEntryURI(uri));
                    childEntry.refreshFromRepository(rc);
                    entry.getRepositoryManager().fireRepositoryEvent(
                            new RepositoryEventObject(childEntry, RepositoryEvent.EntryUpdated));
                }
                for (URI uri : toRemove) {
                    EntryImpl childEntry = ((EntryImpl) this.entry.getContext().getByEntryURI(uri));
                    childEntry.refreshFromRepository(rc);
                    entry.getRepositoryManager().fireRepositoryEvent(
                            new RepositoryEventObject(childEntry, RepositoryEvent.EntryUpdated));
                }
                children = oldChildrenList;
                throw new org.entrystore.repository.RepositoryException(
                        "Cannot set the list since: " + e.getMessage());
            } finally {
                rc.close();
            }
        }
    } catch (RepositoryException e) {
        log.error(e.getMessage(), e);
    }
    return true;
}

From source file:org.apache.hadoop.hdfs.server.blockmanagement.BlockInfo.java

/**
 * Returns an array of storages where the replicas are stored
 *///w ww .  j a  v a2  s  .  c o  m
protected DatanodeStorageInfo[] getStorages(DatanodeManager datanodeMgr, List<? extends ReplicaBase> replicas) {
    int numLocations = replicas.size();
    HashSet<DatanodeStorageInfo> set = new HashSet<>();
    for (int i = numLocations - 1; i >= 0; i--) {
        DatanodeStorageInfo desc = datanodeMgr.getStorage(replicas.get(i).getStorageId());
        if (desc != null) {
            set.add(desc);
        } else {
            replicas.remove(i);
        }
    }
    DatanodeStorageInfo[] storages = new DatanodeStorageInfo[set.size()];
    return set.toArray(storages);
}

From source file:com.rc.droid_stalker.components.NetworkStats.java

/**
 * Return list of unique interfaces known by this data structure.
 *///from   w  w  w.ja  v  a  2s .c  o  m
public String[] getUniqueIfaces() {
    final HashSet<String> ifaces = new HashSet<String>();
    for (String iface : this.iface) {
        if (iface != IFACE_ALL) {
            ifaces.add(iface);
        }
    }
    return ifaces.toArray(new String[ifaces.size()]);
}

From source file:de.dfki.km.perspecting.obie.experiments.ProperNameExperiment.java

/**
 * Test method for// w w w .  j av  a 2s.  com
 * {@link de.dfki.km.perspecting.obie.dixi.service.SimpleScobieService#extractInformationFromURL(java.lang.String, java.lang.String)}
 * .
 */
@Test
public void testExtractInformationFromURL() {
    try {
        StringBuffer b = new StringBuffer();

        for (int i = 0; i < 1; i++) {

            Document document = pipeline.createDocument(
                    FileUtils.toFile(new URL("http://en.wikipedia.org/wiki/Special:Random")),
                    new URI("http://en.wikipedia.org/wiki/Special:Random"), MediaType.HTML,
                    "SELECT * WHERE {?s ?p ?o}", Language.EN);

            Evaluator evaluator = new Evaluator(pipeline);

            for (int step = 0; pipeline.hasNext(step) && step <= 5; step = pipeline.execute(step, document)) {
                System.out.println(step);
            }

            HashSet<String> wordsOfPhrases = new HashSet<String>();
            HashSet<String> wordsOfDocument = new HashSet<String>();

            for (Token token : document.getTokens()) {
                wordsOfDocument.add(token.toString());
            }

            int count = 0;
            for (TokenSequence<String> np : document.getNounPhrases()) {
                String[] words = np.toString().split("[\\s]+");
                count += words.length;
                wordsOfPhrases.addAll(Arrays.asList(words));
            }

            b.append(document.getTokens().size() + "\t" + document.getNounPhrases().size() + "\t" + count + "\t"
                    + wordsOfPhrases.size() + "\t" + wordsOfDocument.size() + "\n");

        }
        System.out.println("tok in doc\tnp in doc\ttok in nps\tdistinct tok in nps\tdistinct tok in doc");
        System.out.println(b);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:malware_classification.Malware_Classification.java

private double[][] get_elements(double[][] data, HashSet<Integer> indices) {
    double[][] new_data = new double[indices.size()][data[0].length];
    int new_data_index = 0;
    for (int i = 0; i < data.length; i++) {
        if (indices.contains(i)) {
            System.arraycopy(data[i], 0, new_data[new_data_index], 0, data[i].length);
            new_data_index++;
        }/*  w  ww. ja va2s.  c  om*/
    }

    return new_data;
}

From source file:org.metaservice.core.utils.GitUtil.java

public String[] getParentHashes(@NotNull String revision) throws GitException {
    Process process = execInWorkdir("git rev-list --parents -n 1 " + revision);
    try {//from   w  ww  .j  av a2s .  c o m
        String s = IOUtils.toString(process.getInputStream());
        debug(process);
        //ignore current
        LOGGER.info(s);
        s = s.replaceAll("^" + revision + "[^\\s]*", "").trim();
        HashSet<String> parents = new HashSet<>();
        int i = 0;
        LOGGER.info(s);
        while (!s.isEmpty() && i++ < 10) {
            String x = s.replaceAll("^([^\\s])+", "$0");
            LOGGER.info("X " + x);
            if (x.length() > 1)
                parents.add(x);
            s = s.replaceAll("^([^\\s])+", "").trim();
            LOGGER.info(s);
        }
        LOGGER.info("parents: " + revision + " -> " + parents);
        return parents.toArray(new String[parents.size()]);
    } catch (IOException e) {
        throw new GitException(e);
    }
}

From source file:org.owasp.jbrofuzz.core.Database.java

/**
 * <p>// www  .  j  av  a 2s.  c o  m
 * Given a category, return all prototype names that belong to that
 * category.
 * </p>
 * 
 * @param category
 *            the category as a string to check
 * @return String[] array of prototype names
 * 
 * @author subere@uncon.org
 * @version 1.3
 * @since 1.2
 */
public String[] getPrototypeNamesInCategory(final String category) {

    final HashSet<String> o = new HashSet<String>();
    final String[] ids = getAllPrototypeIDs();

    for (final String id : ids) {

        final Prototype g = prototypes.get(id);
        if (g.isAMemberOfCategory(category)) {
            o.add(g.getName());
        }
    }

    final String[] uCategotiesArray = new String[o.size()];
    o.toArray(uCategotiesArray);

    return uCategotiesArray;
}

From source file:com.puppycrawl.tools.checkstyle.checks.coding.CustomDeclarationOrderCheck.java

@Override
public int[] getDefaultTokens() {
    //HashSet for unique Tokens
    final HashSet<String> classMembers = new HashSet<String>();

    for (FormatMatcher currentRule : mCustomOrderDeclaration) {
        // check existing of InnerClass in rule
        if ("CLASS_DEF".equals(currentRule.getClassMember())) {
            mInnerClass = true;//from  www.j a v  a  2s  . c  o m
        } else {
            classMembers.add(currentRule.mClassMember); //add Tokens
        }
    }

    final int defaultTokens[] = new int[classMembers.size() + 1];
    defaultTokens[0] = TokenTypes.CLASS_DEF;

    int index = 1;
    for (String token : classMembers) {
        if ("VARIABLE_DEF".equals(token)) {
            defaultTokens[index] = TokenTypes.VARIABLE_DEF;
        } else if ("METHOD_DEF".equals(token)) {
            defaultTokens[index] = TokenTypes.METHOD_DEF;
        } else if ("CTOR_DEF".equals(token)) {
            defaultTokens[index] = TokenTypes.CTOR_DEF;
        } else {
            defaultTokens[index] = defaultTokens[0];
        }
        ++index;
    }
    return defaultTokens;
}

From source file:malware_classification.Malware_Classification.java

private double[][] get_elements_not_excluded(double[][] data, HashSet<Integer> indices) {
    double[][] new_data = new double[data.length - indices.size()][data[0].length];
    int new_data_index = 0;
    for (int i = 0; i < data.length; i++) {
        if (!indices.contains(i)) {
            System.arraycopy(data[i], 0, new_data[new_data_index], 0, data[i].length);
            new_data_index++;
        }/*from   www.  j ava 2s.c  o m*/
    }

    return new_data;

}

From source file:org.apache.axis.encoding.TypeMappingImpl.java

/**
 * Returns an array of all the classes contained within this mapping
 *///from w  ww.java2  s .  com
public Class[] getAllClasses(TypeMappingDelegate next) {
    java.util.HashSet temp = new java.util.HashSet();
    if (next != null) {
        temp.addAll(java.util.Arrays.asList(next.getAllClasses()));
    }
    temp.addAll(class2Pair.keySet());
    return (Class[]) temp.toArray(new Class[temp.size()]);
}