Example usage for java.util HashSet add

List of usage examples for java.util HashSet add

Introduction

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

Prototype

public boolean add(E e) 

Source Link

Document

Adds the specified element to this set if it is not already present.

Usage

From source file:Main.java

public static void getTop(float[] array, ArrayList<Integer> rankList, int i) {
    rankList.clear();/*from  www. ja  va2  s  . co  m*/

    int index = 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 (!scanned.contains(no) && array[no] >= max) {
                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 void getTop(float[] array, ArrayList<Integer> rankList, ArrayList<Float> rankProbs, int i) {
    // clear//from  w  w w . j  a  va2 s .c  o m
    rankList.clear();
    rankProbs.clear();
    //
    int index = 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 void getTop(float[] array, ArrayList<Integer> rankList, ArrayList<Float> rankProbs, int i) {
    // clear//from   w  ww. jav  a2  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:kevin.gvmsgarch.Worker.java

private static Set<String> getMessageIds(String textContent) throws JSONException {
    HashSet<String> retval = new HashSet<String>();
    JSONObject top = new JSONObject(textContent);

    JSONObject messages = top.getJSONObject("messages");
    Iterator i = messages.keys();
    if (!i.hasNext()) {
        retval = null;/*from  w  w w. ja va 2s.  c o m*/
    } else {
        while (i.hasNext()) {
            retval.add(i.next().toString());
        }
    }

    return retval;
}

From source file:me.vertretungsplan.parser.UntisInfoParser.java

private static List<Substitution> parseTimetableCell(Element cell, String lesson, String klasse,
        JSONArray cellFormat, ColorProvider colorProvider) throws JSONException {
    List<Substitution> substitutions = new ArrayList<>();
    if (cell.text().trim().equals("")) {
        return substitutions;
    }//from w  w  w  .jav  a  2s  . c o m

    final Elements rows = cell.select("table").first().select("tr");

    int cols = rows.get(0).select("td").size();
    int courseCount = cols / cellFormat.getJSONArray(0).length();

    for (int course = 0; course < courseCount; course++) {
        Substitution s = new Substitution();
        s.setLesson(lesson);

        final HashSet<String> classes = new HashSet<>();
        classes.add(klasse);
        s.setClasses(classes);

        boolean isChange = false;

        for (int row = 0; row < cellFormat.length() && row < rows.size(); row++) {
            JSONArray rowData = cellFormat.getJSONArray(row);
            Element tr = rows.get(row);
            for (int col = 0; col < rowData.length(); col++) {
                if (rowData.getString(col) == null)
                    continue;
                String type = rowData.getString(col);

                try {
                    Element td = tr.select("td").get(col + course * cellFormat.getJSONArray(0).length());
                    if (td.select("font[color=#FF0000]").size() > 0) {
                        isChange = true;
                    }

                    parseTimetableCellContent(s, type, td);
                } catch (IndexOutOfBoundsException e) {
                    if (course == 0)
                        throw e;
                }
            }
        }

        if (s.getSubject() == null && s.getTeacher() == null && s.getRoom() == null) {
            s.setType("Entfall");
        } else {
            s.setType("Vertretung");
        }
        s.setColor(colorProvider.getColor(s.getType()));

        if (isChange) {
            substitutions.add(s);
        }
    }

    return substitutions;
}

From source file:com.mycompany.craftdemo.utility.java

public static HashSet<String> getHolidays() {
    HashSet<String> holidays = new HashSet<>();
    JSONObject holidaysData = getAPIData("http://holidayapi.com/v1/holidays?country=US&year=2016");
    JSONObject dates = (JSONObject) holidaysData.get("holidays");

    for (Iterator iterator = dates.keySet().iterator(); iterator.hasNext();) {
        String key = (String) iterator.next();
        holidays.add(key);
    }//  w  ww . j av  a2  s . c  om
    //returning holidays as a set
    return holidays;
}

From source file:eu.fbk.dkm.sectionextractor.pantheon.WikipediaGoodTextExtractor.java

private static void addRedirects(HashSet<String> pagesToConsider, HashMap<String, String> redirects,
        String line, int depth) {
    if (depth > MAX_DEPTH) {
        return;//w w  w . j  a va 2 s.co  m
    }

    String red = redirects.get(line);
    if (red != null) {
        pagesToConsider.add(red);
        addRedirects(pagesToConsider, redirects, red, depth + 1);
    }
}

From source file:Main.java

/**
 * Returns only the valid child nodes of a node. Eliminates the nodes from
 * the list of child nodes of the input node if the child node type is same
 * with any of <code>ignoreNodeTypes</code>
 * //ww  w .  j a  v a2s .  co  m
 * @param node
 * @param maintainOrder
 * @param ignoreNodeTypes
 * @return HashSet<Node>
 */
public static HashSet<Node> getValidChildNodes(Node node, boolean maintainOrder, short... ignoreNodeTypes) {
    NodeList childNodes = node.getChildNodes();
    HashSet<Node> filteredChildNodes = new HashSet<Node>();
    if (maintainOrder) {
        filteredChildNodes = new LinkedHashSet<Node>();
    }
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node thisNode = childNodes.item(i);
        boolean allowAdd = true;
        for (int j = 0; j < ignoreNodeTypes.length; j++) {
            if (ignoreNodeTypes[j] == thisNode.getNodeType()) {
                allowAdd = false;
                break;
            }
        }
        if (allowAdd) {
            filteredChildNodes.add(thisNode);
        }
    }
    return filteredChildNodes;
}

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);
            }/*w  w 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.termmed.statistics.runner.Runner.java

/**
 * Inits the file providers./*w  w w.ja v a2  s  . com*/
 *
 * @param file the file
 * @throws Exception the exception
 */
private static void initFileProviders(File file) throws Exception {
    logger.logInfo("Initializing file providers");
    XMLConfiguration xmlConfig;
    try {
        xmlConfig = new XMLConfiguration(file);
    } catch (ConfigurationException e) {
        logger.logInfo("ClassificationRunner - Error happened getting params configFile." + e.getMessage());
        throw e;
    }

    String releaseFolder = xmlConfig.getString("releaseFullFolder");
    if (releaseFolder == null || releaseFolder.trim().equals("") || !new File(releaseFolder).exists()) {
        throw new Exception("Release folder doesn't exist.");
    }

    File sourceFolder = new File(releaseFolder);

    Object prop = xmlConfig.getProperty("releaseDependencies.releaseFullFolder");
    HashSet<String> releaseDependencies = null;
    if (prop != null) {
        if (prop instanceof Collection) {
            releaseDependencies = new HashSet<String>();
            for (String loopProp : (Collection<String>) prop) {
                releaseDependencies.add(loopProp);
            }
        } else if (prop instanceof String) {
            releaseDependencies = new HashSet<String>();
            releaseDependencies.add((String) prop);
            System.out.println(prop);
        }

    }
    String releaseDate = xmlConfig.getString("releaseDate");
    String previousReleaseDate = xmlConfig.getString("previousReleaseDate");

    CurrentFile.init(sourceFolder, new File("release" + releaseDate), releaseDependencies, releaseDate);
    PreviousFile.init(sourceFolder, new File("release" + previousReleaseDate), releaseDependencies,
            previousReleaseDate);

    String dependentRelease = xmlConfig.getString("dependentReleaseFullFolder");
    if (dependentRelease != null && !dependentRelease.trim().equals("")) {
        String dependentReleaseDate = xmlConfig.getString("dependentReleaseDate");
        if (dependentReleaseDate == null || dependentReleaseDate.trim().equals("")) {
            dependentReleaseDate = releaseDate;
        }
        DependentFile.init(new File(dependentRelease), new File("dependentrelease" + dependentReleaseDate),
                dependentReleaseDate);

    }

}