Example usage for java.util Set clear

List of usage examples for java.util Set clear

Introduction

In this page you can find the example usage for java.util Set clear.

Prototype

void clear();

Source Link

Document

Removes all of the elements from this set (optional operation).

Usage

From source file:edu.wisc.my.portlets.bookmarks.domain.Folder.java

/**
 * @see java.lang.Object#toString()/*from  w ww  .j a  v  a 2 s. co m*/
 */
public String toString() {
    final Set<Integer> visited = toStringVisitedFolder.getSet();
    final int identityHash = System.identityHashCode(this);
    try {
        if (!visited.add(identityHash)) {
            visited.clear();
            throw new IllegalStateException("A loop exists in the Folder tree.");
        }

        return new ToStringBuilder(this).appendSuper(super.toString()).append("children", this.children)
                .append("minimized", this.minimized).toString();
    } finally {
        visited.remove(identityHash);
    }
}

From source file:ch.unine.vauchers.fuseerasure.codes.ReedSolomonCode.java

/**
 * Given parity symbols followed by message symbols, return the locations of
 * symbols that are corrupted. Can resolve up to (parity length / 2) error
 * locations./*from  w  w w  . ja  v a  2  s .  c o m*/
 * @param data The message and parity. The parity should be placed in the
 *             first part of the array. In each integer, the relevant portion
 *             is present in the least significant bits of each int.
 *             The number of elements in data is stripeSize() + paritySize().
 *             <b>Note that data may be changed after calling this method.</b>
 * @param errorLocations The set to put the error location results
 * @return true If the locations can be resolved, return true.
 */
public boolean computeErrorLocations(int[] data, Set<Integer> errorLocations) {
    assert (data.length == paritySize + stripeSize && errorLocations != null);
    errorLocations.clear();
    int maxError = paritySize / 2;
    int[][] syndromeMatrix = new int[maxError][];
    for (int i = 0; i < syndromeMatrix.length; ++i) {
        syndromeMatrix[i] = new int[maxError + 1];
    }
    int[] syndrome = new int[paritySize];

    if (computeSyndrome(data, syndrome)) {
        // Parity check OK. No error location added.
        return true;
    }
    for (int i = 0; i < maxError; ++i) {
        for (int j = 0; j < maxError + 1; ++j) {
            syndromeMatrix[i][j] = syndrome[i + j];
        }
    }
    GF.gaussianElimination(syndromeMatrix);
    int[] polynomial = new int[maxError + 1];
    polynomial[0] = 1;
    for (int i = 0; i < maxError; ++i) {
        polynomial[i + 1] = syndromeMatrix[maxError - 1 - i][maxError];
    }
    for (int i = 0; i < paritySize + stripeSize; ++i) {
        int possibleRoot = GF.divide(1, primitivePower[i]);
        if (GF.substitute(polynomial, possibleRoot) == 0) {
            errorLocations.add(i);
        }
    }
    // Now recover with error locations and check the syndrome again
    int[] locations = new int[errorLocations.size()];
    int k = 0;
    for (int loc : errorLocations) {
        locations[k++] = loc;
    }
    int[] erasedValue = new int[locations.length];
    decode(data, locations, erasedValue);
    for (int i = 0; i < locations.length; ++i) {
        data[locations[i]] = erasedValue[i];
    }
    return computeSyndrome(data, syndrome);
}

From source file:edu.wisc.my.portlets.bookmarks.domain.Folder.java

/**
 * @see java.lang.Object#equals(Object)/*from   ww  w .jav  a 2s .com*/
 */
public boolean equals(final Object object) {
    final Set<Integer> visited = equalsVisitedFolder.getSet();
    final int identityHash = System.identityHashCode(this);
    try {
        if (!visited.add(identityHash)) {
            visited.clear();
            throw new IllegalStateException("A loop exists in the Folder tree.");
        }

        if (object == this) {
            return true;
        }
        if (!(object instanceof Folder)) {
            return false;
        }
        Folder rhs = (Folder) object;
        return new EqualsBuilder().appendSuper(super.equals(object)).append(this.children, rhs.children)
                .append(this.minimized, rhs.minimized).isEquals();
    } finally {
        visited.remove(identityHash);
    }
}

From source file:key.secretkey.utils.EntryRecyclerAdapter.java

public void updateSelectedItems(int position, Set<Integer> selectedItems) {
    Set<Integer> temp = new TreeSet<>();
    for (int selected : selectedItems) {
        if (selected > position) {
            temp.add(selected - 1);//from   ww w.  j  a va 2 s  .co m
        } else {
            temp.add(selected);
        }
    }
    selectedItems.clear();
    selectedItems.addAll(temp);
}

From source file:fr.mcc.ginco.services.ConceptHierarchicalRelationshipServiceUtil.java

@Override
public List<ThesaurusConcept> getRootConcepts(ThesaurusConcept concept) {
    ThesaurusConcept start;/*from   ww w  . jav a2  s  .co  m*/
    Map<String, Integer> path = new HashMap<String, Integer>();
    Set<ThesaurusConcept> roots = new HashSet<ThesaurusConcept>();
    path.clear();
    roots.clear();
    path.put(concept.getIdentifier(), 0);
    start = concept;
    getRoot(concept, 0, start, path, roots);
    return new ArrayList<ThesaurusConcept>(roots);
}

From source file:org.seamless_ip.services.dao.IndicatorDaoImpl.java

public void updateIndicatorIdsForProblem(Long problemId, List<String> indicatorIds) {
    try {/*  w ww  . j a va2s.c  om*/
        Query q = query("from Problem as p where p.id = :id").setParameter("id", problemId);
        Problem problem = (Problem) q.uniqueResult();
        if (problem != null) {
            Set<IIndicator> indicators = problem.getIndicators();
            if (indicators == null) {
                indicators = new HashSet<IIndicator>();
                problem.setIndicators(indicators);
            }
            indicators.clear();
            for (String id : indicatorIds)
                indicators.add(findById(new Long(id)));

            currentSession().update(problem);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new RuntimeException("There was a problem saving the indicator selection!", ex);
    }
}

From source file:edu.uci.ics.jung.io.TestGraphMLReader.java

public void testLoadHypergraph() throws IOException, ParserConfigurationException, SAXException {
    Hypergraph<Number, Number> graph = new SetHypergraph<Number, Number>();
    GraphMLReader<Hypergraph<Number, Number>, Number, Number> hyperreader = new GraphMLReader<Hypergraph<Number, Number>, Number, Number>(
            vertexFactory, edgeFactory);
    hyperreader.load("src/test/resources/edu/uci/ics/jung/io/graphml/hyper.graphml", graph);

    Assert.assertEquals(graph.getVertexCount(), 7);
    Assert.assertEquals(graph.getEdgeCount(), 4);

    // n0/*from w  w w.  ja v a 2s.co m*/
    Set<Number> incident = new HashSet<Number>();
    incident.add(0);
    incident.add(3);
    Assert.assertEquals(graph.getIncidentEdges(0), incident);

    // n1
    incident.clear();
    incident.add(0);
    incident.add(2);
    Assert.assertEquals(graph.getIncidentEdges(1), incident);

    // n2
    incident.clear();
    incident.add(0);
    Assert.assertEquals(graph.getIncidentEdges(2), incident);

    // n3
    incident.clear();
    incident.add(1);
    incident.add(2);
    Assert.assertEquals(graph.getIncidentEdges(3), incident);

    // n4
    incident.clear();
    incident.add(1);
    incident.add(3);
    Assert.assertEquals(graph.getIncidentEdges(4), incident);

    // n5
    incident.clear();
    incident.add(1);
    Assert.assertEquals(graph.getIncidentEdges(5), incident);

    // n6
    incident.clear();
    incident.add(1);
    Assert.assertEquals(graph.getIncidentEdges(6), incident);
}

From source file:com.conwet.silbops.msg.UnsubscribeMsgTest.java

@Test
public void shouldDeserializeOptionalUncovered() throws ParseException {

    // this test covers the case clients are sending unsubscribe
    UnsubscribeMsg msg = new UnsubscribeMsg();
    msg.setSubscription(//from   w  ww  .ja va  2s  .co  m
            new Subscription().constrain("attr1", Type.STRING).exists().constrain("attr2", Type.STRING)
                    .eq("hello").constrain("attr3", Type.DOUBLE).gt(10.3D).subscription());
    Set<Subscription> uncovered = new HashSet<>();
    uncovered.add(new Subscription().constrain("attr1", Type.STRING).exists().subscription());
    msg.setUncovered(uncovered);
    JSONObject jsonTmp = msg.toJSON();

    // delete uncovered part
    ((JSONObject) jsonTmp.get("payload")).remove("uncovered");
    uncovered.clear();

    String jsonStr = jsonTmp.toJSONString();
    JSONObject json = (JSONObject) new JSONParser().parse(jsonStr);
    UnsubscribeMsg newMsg = (UnsubscribeMsg) UnsubscribeMsg.fromJSON(json);
    assertThat(newMsg).isEqualTo(msg);
    assertThat(newMsg.getUncovered()).isEqualTo(uncovered);
}

From source file:org.red5.server.scope.WebScope.java

/**
 * Uninitialize and remove all vhosts from the global scope.
 *///  ww  w  . ja  v a2 s .c  om
public void unregister() {
    if (!registered.get()) {
        log.info("Webscope not registered");
        return;
    }
    log.debug("Webscope un-registering: {}", contextPath);
    shuttingDown.set(true);
    keepOnDisconnect = false;
    uninit();
    // disconnect all clients before unregistering
    Set<IConnection> conns = getClientConnections();
    for (IConnection conn : conns) {
        conn.close();
    }
    conns.clear();
    //
    if (hostnames != null && hostnames.length > 0) {
        for (String element : hostnames) {
            server.removeMapping(element, getName());
        }
    }
    //check for null
    if (appContext == null) {
        log.debug("Application context is null, trying retrieve from loader");
        getAppContext();
    }
    //try to stop the app context
    if (appContext != null) {
        log.debug("Stopping app context");
        appContext.stop();
    } else {
        log.debug("Application context is null, could not be stopped");
    }
    // Various cleanup tasks
    store = null;
    setServletContext(null);
    setServer(null);
    setName(null);
    appContext = null;
    registered.set(false);
    shuttingDown.set(false);
}

From source file:br.bireme.ngrams.NGrams.java

/**
 *
 * @param index/*  w ww  . java 2  s . c  o  m*/
 * @param schema
 * @param inFile
 * @param inFileEncoding
 * @param outFile
 * @param outFileEncoding
 * @throws IOException
 * @throws ParseException
 */
public static void search(final NGIndex index, final NGSchema schema, final String inFile,
        final String inFileEncoding, final String outFile, final String outFileEncoding)
        throws IOException, ParseException {
    if (index == null) {
        throw new NullPointerException("index");
    }
    if (schema == null) {
        throw new NullPointerException("schema");
    }
    if (inFile == null) {
        throw new NullPointerException("inFile");
    }
    if (inFileEncoding == null) {
        throw new NullPointerException("inFileEncoding");
    }
    if (outFile == null) {
        throw new NullPointerException("outFile");
    }
    if (outFileEncoding == null) {
        throw new NullPointerException("outFileEncoding");
    }
    final Charset inCharset = Charset.forName(inFileEncoding);
    final Charset outCharset = Charset.forName(outFileEncoding);
    final IndexSearcher searcher = index.getIndexSearcher();
    final NGAnalyzer analyzer = (NGAnalyzer) index.getAnalyzer();
    final Parameters parameters = schema.getParameters();
    final NGramDistance ngDistance = new NGramDistance(analyzer.getNgramSize());
    final Set<String> id_id = new HashSet<>();
    int cur = 0;
    try (final BufferedReader reader = Files.newBufferedReader(new File(inFile).toPath(), inCharset);
            final BufferedWriter writer = Files.newBufferedWriter(new File(outFile).toPath(), outCharset)) {
        writer.append("rank|similarity|search_doc_id|index_doc_id|"
                + "ngram_search_text|ngram_index_text|search_source|" + "index_source\n");

        final Set<Result> results = new HashSet<>();
        while (true) {
            final String line = reader.readLine();
            if (line == null) {
                break;
            }
            if (++cur % 250 == 0) {
                System.out.println("<<< " + cur);
            }

            results.clear();
            final String tline = line.replace(':', ' ').trim();
            if (!tline.isEmpty()) {
                final String[] split = tline.split(" *\\| *", Integer.MAX_VALUE);
                if (split.length != parameters.nameFields.size()) {
                    throw new IOException("invalid number of fields: " + line);
                }
                searchRaw(parameters, searcher, analyzer, ngDistance, tline, true, id_id, results);
                if (!results.isEmpty()) {
                    writeOutput(parameters, results, writer);
                }
            }
        }
        searcher.getIndexReader().close();
    }
}