Example usage for java.util HashSet contains

List of usage examples for java.util HashSet contains

Introduction

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

Prototype

public boolean contains(Object o) 

Source Link

Document

Returns true if this set contains the specified element.

Usage

From source file:Main.java

public static void getTop(float[] array, ArrayList<Integer> rankList, ArrayList<Float> rankProbs, int i) {
    // clear/* w  w w.j av  a  2 s  .c o m*/
    rankList.clear();
    rankProbs.clear();
    //
    int index = 0;
    int count = 0;
    HashSet<Integer> scanned = new HashSet<Integer>();
    float max = Float.MIN_VALUE;
    for (int m = 0; m < i && m < array.length; m++) {
        boolean flag = false;
        max = Float.MIN_VALUE;
        for (int no = 0; no < array.length; no++) {
            if (array[no] >= max && !scanned.contains(no)) {
                index = no;
                max = array[no];
                flag = true;
            }
        }
        if (flag) { // found value
            scanned.add(index);
            rankList.add(index);
            rankProbs.add(array[index]);
        }
        //System.out.println(m + "\t" + index);
    }
}

From source file:Main.java

public static String getAddressString(Address[] addresses) {
    if (addresses == null || addresses.length <= 0) {
        return "";
    }// ww  w  .  java  2 s. com
    HashSet<String> foundAddress = new HashSet<String>();

    StringBuffer sb = new StringBuffer();
    InternetAddress addr = null;
    int length = addresses.length;
    for (int i = 0; i < length; i++) {
        addr = (InternetAddress) addresses[i];
        if (foundAddress.contains(addr.getAddress())) {
            continue;
        }
        foundAddress.add(addr.getAddress());

        if (addr.getPersonal() != null) {
            String personaladdr = getOneString(getTokens(addr.getPersonal(), "\r\n"), "");
            sb.append(personaladdr).append(" <").append(addr.getAddress()).append(">, ");
        } else {
            sb.append(addr.getAddress()).append(", ");
        }
    }
    String addressStr = sb.toString();
    return addressStr.substring(0, addressStr.length() - 2);
}

From source file:Main.java

private static void walkNodes(Node nodeIn, HashSet<String> hElements) {
    if (nodeIn == null)
        return;/*from  w  w  w  .j  a v  a  2 s .  co  m*/
    NodeList nodes = nodeIn.getChildNodes();
    for (int i = 0; i < nodes.getLength(); i++) {
        Node n = nodes.item(i);
        if (n.getNodeType() == Node.ELEMENT_NODE) {
            String sNodeName = n.getNodeName();
            if (!hElements.contains(sNodeName))
                hElements.add(sNodeName);
            walkNodes(n, hElements);
        }
    }
}

From source file:models.TextInputCleaner.java

public static String clean(String input) {
    HashSet<String> stoplist = new HashSet<String>();
    for (int i = 0; i < stopwords.length; i++) {
        stoplist.add(stopwords[i]);/*from   w w  w  . j  av  a2 s.  c  o m*/
    }
    String[] tokenSeq = input.toLowerCase().split("\\s");
    ArrayList<String> outputList = new ArrayList<String>();

    for (String str : tokenSeq) {
        if (!stoplist.contains(str)) {
            outputList.add(str);
        }
    }

    //String outStr = StringUtils.join(outputList, " ").replaceAll("[\\W_]+", "");
    String outStr = StringUtils.join(outputList, " ");

    return outStr;
}

From source file:edu.cornell.mannlib.vitro.webapp.utils.fields.FieldUtils.java

public static List<Individual> removeIndividualsAlreadyInRange(List<Individual> individuals,
        List<ObjectPropertyStatement> stmts, String predicateUri, String objectUriBeingEdited) {
    HashSet<String> range = new HashSet<String>();

    for (ObjectPropertyStatement ops : stmts) {
        if (ops.getPropertyURI().equals(predicateUri))
            range.add(ops.getObjectURI());
    }//from  w  w w  . ja  v  a2s. c o m

    int removeCount = 0;
    ListIterator<Individual> it = individuals.listIterator();
    while (it.hasNext()) {
        Individual ind = it.next();
        if (range.contains(ind.getURI()) && !(ind.getURI().equals(objectUriBeingEdited))) {
            it.remove();
            ++removeCount;
        }
    }

    return individuals;
}

From source file:exm.stc.ic.ICUtil.java

public static void removeDuplicates(List<Var> varList) {
    ListIterator<Var> it = varList.listIterator();
    HashSet<Var> alreadySeen = new HashSet<Var>();
    while (it.hasNext()) {
        Var v = it.next();/*w  ww  .  ja  va  2s  .c  om*/
        if (alreadySeen.contains(v)) {
            it.remove();
        } else {
            alreadySeen.add(v);
        }
    }
}

From source file:edu.ku.brc.util.AttachmentUtils.java

/**
 * @param f the file to be opened/*from w  w  w .ja  va 2s  .  c  o  m*/
 * @throws Exception
 */
public static void openFile(final File f) throws Exception {
    if (UIHelper.isWindows()) {
        HashSet<String> hashSet = new HashSet<String>();
        Collections.addAll(hashSet, new String[] { "wav", "mp3", "snd", "mid", "aif", "aiff", });
        String ext = FilenameUtils.getExtension(f.getName()).toLowerCase();
        if (hashSet.contains(ext)) {
            Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + f.getAbsolutePath());
            return;
        }
    }
    Desktop.getDesktop().open(f);
}

From source file:com.googlesource.gerrit.plugins.supermanifest.JiriManifestParser.java

public static JiriProjects getProjects(GerritRemoteReader reader, String repoKey, String ref, String manifest)
        throws ConfigInvalidException, IOException {

    try (RepoMap<String, Repository> repoMap = new RepoMap<>()) {
        repoMap.put(repoKey, reader.openRepository(repoKey));
        Queue<ManifestItem> q = new LinkedList<>();
        q.add(new ManifestItem(repoKey, manifest, ref, "", false));
        HashMap<String, HashSet<String>> processedRepoFiles = new HashMap<>();
        HashMap<String, JiriProjects.Project> projectMap = new HashMap<>();

        while (q.size() != 0) {
            ManifestItem mi = q.remove();
            Repository repo = repoMap.get(mi.repoKey);
            if (repo == null) {
                repo = reader.openRepository(mi.repoKey);
                repoMap.put(mi.repoKey, repo);
            }//ww w . j av  a 2 s.co m
            HashSet<String> processedFiles = processedRepoFiles.get(mi.repoKey);
            if (processedFiles == null) {
                processedFiles = new HashSet<String>();
                processedRepoFiles.put(mi.repoKey, processedFiles);
            }
            if (processedFiles.contains(mi.manifest)) {
                continue;
            }
            processedFiles.add(mi.manifest);
            JiriManifest m;
            try {
                m = parseManifest(repo, mi.ref, mi.manifest);
            } catch (JAXBException | XMLStreamException e) {
                throw new ConfigInvalidException("XML parse error", e);
            }

            for (JiriProjects.Project project : m.projects.getProjects()) {
                project.fillDefault();
                if (mi.revisionPinned && project.Key().equals(mi.projectKey)) {
                    project.setRevision(mi.ref);
                }
                if (projectMap.containsKey(project.Key())) {
                    if (!projectMap.get(project.Key()).equals(project))
                        throw new ConfigInvalidException(String.format(
                                "Duplicate conflicting project %s in manifest %s\n%s\n%s", project.Key(),
                                mi.manifest, project.toString(), projectMap.get(project.Key()).toString()));
                } else {
                    projectMap.put(project.Key(), project);
                }
            }

            URI parentURI;
            try {
                parentURI = new URI(mi.manifest);
            } catch (URISyntaxException e) {
                throw new ConfigInvalidException("Invalid parent URI", e);
            }
            for (JiriManifest.LocalImport l : m.imports.getLocalImports()) {
                ManifestItem tw = new ManifestItem(mi.repoKey, parentURI.resolve(l.getFile()).getPath(), mi.ref,
                        mi.projectKey, mi.revisionPinned);
                q.add(tw);
            }

            for (JiriManifest.Import i : m.imports.getImports()) {
                i.fillDefault();
                URI uri;
                try {
                    uri = new URI(i.getRemote());
                } catch (URISyntaxException e) {
                    throw new ConfigInvalidException("Invalid URI", e);
                }
                String iRepoKey = new Project.NameKey(StringUtils.strip(uri.getPath(), "/")).toString();
                String iRef = i.getRevision();
                boolean revisionPinned = true;
                if (iRef.isEmpty()) {
                    iRef = REFS_HEADS + i.getRemotebranch();
                    revisionPinned = false;
                }

                ManifestItem tmi = new ManifestItem(iRepoKey, i.getManifest(), iRef, i.Key(), revisionPinned);
                q.add(tmi);
            }
        }
        return new JiriProjects(projectMap.values().toArray(new JiriProjects.Project[0]));
    }
}

From source file:com.sencko.basketball.stats.advanced.FIBAJsonParser.java

static void analyzeGame(Game game) {
    HashSet[] playersInGameTeam = { new HashSet<String>(5), new HashSet<String>(5) };
    HashSet[] playersInRest = { new HashSet<String>(5), new HashSet<String>(5) };
    HashMap[][] plusMinusPlayers = { { new HashMap<String, Integer>(), new HashMap<String, Integer>() },
            { new HashMap<String, Integer>(), new HashMap<String, Integer>() } };
    for (int i = game.getPbp().size() - 1; i >= 0; i--) {
        Event event = game.getPbp().get(i);
        if (EventType.sub.equals(event.getTyp())) {
            HashSet<String> teamSet = playersInGameTeam[event.getTno() - 1];
            HashSet<String> restSet = playersInRest[event.getTno() - 1];
            String actor = event.getActor().toString();
            if (teamSet.contains(actor)) {
                teamSet.remove(actor);//from  w w  w  . jav a 2  s  . co m
                restSet.add(actor);
            } else {
                teamSet.add(actor);
                if (restSet.contains(actor)) {
                    restSet.remove(actor);
                } else {
                    //add plus minus on bench
                    HashMap<String, Integer> bench = plusMinusPlayers[event.getTno() - 1][1];
                    int change = (event.getTno() == 1) ? (event.getS1() - event.getS2())
                            : (event.getS2() - event.getS1());
                    bench.put(actor, change);
                }
            }

            //   System.out.println(Arrays.toString(playersInGameTeam));
        } else if (i != game.getPbp().size() - 1) {
            Event previousEvent = game.getPbp().get(i + 1);
            int change = 0;
            if (previousEvent.getS1() != event.getS1()) {
                change += event.getS1() - previousEvent.getS1();
            }
            if (previousEvent.getS2() != event.getS2()) {
                change -= event.getS2() - previousEvent.getS2();
            }
            for (int j = 0; j < 2; j++) {
                HashSet<String> teamSet = playersInGameTeam[j];
                for (String player : teamSet) {
                    HashMap<String, Integer> prev = plusMinusPlayers[j][0];
                    Integer previous = prev.get(player);
                    if (previous == null) {
                        previous = 0;
                    }
                    previous = previous + change;
                    prev.put(player, previous);
                }

                HashSet<String> restSet = playersInRest[j];
                for (String player : restSet) {
                    HashMap<String, Integer> prev = plusMinusPlayers[j][1];
                    Integer previous = prev.get(player);
                    if (previous == null) {
                        previous = 0;
                    }
                    previous = previous + change;
                    prev.put(player, previous);
                }

                change = -change;
            }
        }
    }
    //     System.out.println(Arrays.deepToString(plusMinusPlayers));

    for (int i = 0; i < 2; i++) {
        HashMap<String, Integer> board = plusMinusPlayers[i][0];
        HashMap<String, Integer> bench = plusMinusPlayers[i][1];
        int checkSum = 0;
        for (String name : board.keySet()) {
            int plusS = board.get(name);
            int plusB = bench.get(name);
            int total = plusS - plusB;
            System.out.printf("%20s\t%4d\t%4d\t%4d\n", name, plusS, plusB, total);
            checkSum += total;
        }

        System.out.println(checkSum + "----------------------------------------");
    }
}

From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.PushProjectDownRule.java

private static boolean pushNeededProjections(HashSet<LogicalVariable> toPush, Mutable<ILogicalOperator> opRef,
        IOptimizationContext context, ILogicalOperator initialOp) throws AlgebricksException {
    HashSet<LogicalVariable> allP = new HashSet<LogicalVariable>();
    AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
    VariableUtilities.getLiveVariables(op, allP);

    HashSet<LogicalVariable> toProject = new HashSet<LogicalVariable>();
    for (LogicalVariable v : toPush) {
        if (allP.contains(v)) {
            toProject.add(v);/*from w  w w  .  j  av  a  2  s  . com*/
        }
    }
    if (toProject.equals(allP)) {
        // projection would be redundant, since we would project everything
        // but we can try with the children
        boolean push = false;
        if (pushThroughOp(toProject, opRef, initialOp, context).first) {
            push = true;
        }
        return push;
    } else {
        return pushAllProjectionsOnTopOf(toProject, opRef, context, initialOp);
    }
}