Example usage for java.util HashSet remove

List of usage examples for java.util HashSet remove

Introduction

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

Prototype

public boolean remove(Object o) 

Source Link

Document

Removes the specified element from this set if it is present.

Usage

From source file:edu.cornell.mannlib.vitro.webapp.dao.jena.PropertyDaoJena.java

@Override
public List<String> getAllSuperPropertyURIs(String propertyURI) {
    HashSet<String> nodeSet = new HashSet<String>();
    nodeSet.add(propertyURI);/*from   ww  w  . ja v  a2  s . c om*/
    getAllSuperPropertyURIs(propertyURI, nodeSet);
    nodeSet.remove(propertyURI);
    List<String> outputList = new LinkedList<String>();
    outputList.addAll(nodeSet);
    return outputList;
}

From source file:edu.ku.brc.specify.dbsupport.cleanuptools.GeoCleanupFuzzySearch.java

/**
 * @return false if index doesn't exist/*from  w  w w.  j  av a  2s . c  o m*/
 */
public boolean initLuceneforReading() {
    if (!FILE_INDEX_DIR.exists())
        return false;

    try {
        reader = DirectoryReader.open(FSDirectory.open(FILE_INDEX_DIR));
        System.out.println("Num Docs: " + reader.numDocs());

    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    Set<?> stdStopWords = StandardAnalyzer.STOP_WORDS_SET;
    HashSet<Object> stopWords = new HashSet<Object>(stdStopWords);
    stopWords.remove("will");

    /*for (Object o : stopWords)
    {
    System.out.print(o.toString()+' ');
    }
    System.out.println();*/

    searcher = new IndexSearcher(reader);
    analyzer = new StandardAnalyzer(Version.LUCENE_47, CharArraySet.EMPTY_SET);
    parser = new QueryParser(Version.LUCENE_47, "name", analyzer);

    return true;
}

From source file:edu.brown.cs.systems.retro.throttling.throttlingqueues.ThrottlingLockingQueue.java

@Override
public void update(ThrottlingPointSpecification spec) {
    // Pull out the tenant IDs for tenants that currently are rate limited
    HashSet<Integer> remainingTenants = new HashSet<Integer>(qs.keySet());

    // Update the limits as specified.
    for (int i = 0; i < spec.getTenantIDCount(); i++) {
        int tenantId = spec.getTenantID(i);
        setRate(tenantId, spec.getThrottlingRate(i));
        remainingTenants.remove(tenantId);
    }//from www.j a v a 2  s . co m

    // If a tenant does not have a rate specified, then it is no longer rate
    // limited
    for (Integer tenantId : remainingTenants) {
        clearRate(tenantId);
    }
}

From source file:net.semanticmetadata.lire.imageanalysis.bovw.LocalFeatureHistogramBuilderFromCodeBook.java

private HashSet<Integer> selectVocabularyDocs() throws IOException {
    // need to make sure that this is not running forever ...
    int loopCount = 0;
    float maxDocs = reader.maxDoc();
    int capacity = (int) Math.min(numDocsForVocabulary, maxDocs);
    if (capacity < 0)
        capacity = (int) (maxDocs / 2);
    HashSet<Integer> result = new HashSet<Integer>(capacity);
    int tmpDocNumber, tmpIndex;
    LinkedList<Integer> docCandidates = new LinkedList<Integer>();
    // three cases:
    ////from www . j  a v  a2  s .c  om
    // either it's more or the same number as documents
    if (numDocsForVocabulary >= maxDocs) {
        for (int i = 0; i < maxDocs; i++) {
            result.add(i);
        }
        return result;
    } else if (numDocsForVocabulary >= maxDocs - 100) { // or it's slightly less:
        for (int i = 0; i < maxDocs; i++) {
            result.add(i);
        }
        while (result.size() > numDocsForVocabulary) {
            result.remove((int) Math.floor(Math.random() * result.size()));
        }
        return result;
    } else {
        for (int i = 0; i < maxDocs; i++) {
            docCandidates.add(i);
        }
        for (int r = 0; r < capacity; r++) {
            boolean worksFine = false;
            do {
                tmpIndex = (int) Math.floor(Math.random() * (double) docCandidates.size());
                tmpDocNumber = docCandidates.get(tmpIndex);
                docCandidates.remove(tmpIndex);
                // check if the selected doc number is valid: not null, not deleted and not already chosen.
                worksFine = (reader.document(tmpDocNumber) != null) && !result.contains(tmpDocNumber);
            } while (!worksFine);
            result.add(tmpDocNumber);
            // need to make sure that this is not running forever ...
            if (loopCount++ > capacity * 100)
                throw new UnsupportedOperationException(
                        "Could not get the documents, maybe there are not enough documents in the index?");
        }
        return result;
    }
}

From source file:amie.keys.CSAKey.java

public HashSet<HashSet<Integer>> buidPropertyGraph(int property) {
    HashSet<HashSet<Integer>> propertyPowerSets = new HashSet<>();
    for (HashSet<Integer> nonKeyInt : nonKeysInt) {
        if (nonKeyInt.contains(property)) {
            HashSet<Integer> remainingSet = new HashSet<>(nonKeyInt);
            remainingSet.addAll(nonKeyInt);
            remainingSet.remove(property);
            propertyPowerSets.addAll(powerSet(remainingSet));
        }/*from w w w.j a v a  2 s . com*/
    }
    return propertyPowerSets;
}

From source file:chanupdater.ChanUpdater.java

private void doUpdates() throws SQLException, IOException, FileNotFoundException, LdvTableException {
    if (verbose > 1) {
        System.out.println("Starting update process.");
    }//from   w  w  w.j  a va 2 s  .com
    ArrayList<ChanListSummary> chanLists;

    HashSet<ChanInfo> del = new HashSet<>();
    totalAdds = 0;
    totalDels = 0;

    for (ChanListSummary cls : cLists) {

        cls.printSummary();
        String server = cls.getServer();
        String cTyp = cls.getcType();

        if (verbose > 2) {
            System.out.format("Check %1$s for type:%2$s ", server, cTyp);
        }

        TreeMap<String, HashSet<ChanInfo>> chanSets = cls.getChanSets();
        for (Entry<String, HashSet<ChanInfo>> ent : chanSets.entrySet()) {
            del.clear();
            HashSet<ChanInfo> newChans = ent.getValue();
            String ifo = ent.getKey();
            if (verbose > 1) {
                System.out.format("Server: %1$s, cType: %2$s, IFO: %3$s, count: %4$,d\n", cls.getServer(),
                        cls.getcType(), ifo, newChans.size());
            }
            String namePat = ifo + ":%";
            TreeSet<ChanInfo> oldSet = chnTbl.getAsSet(server, namePat, cTyp, newChans.size());

            for (ChanInfo old : oldSet) {
                boolean gotit = newChans.contains(old);
                if (gotit) {
                    // it's in both
                    newChans.remove(old);
                } else {
                    if (old.isAvailable()) {
                        // only in old add it to be deleted set
                        del.add(old);
                    }
                }
            }
            totalAdds += newChans.size();
            totalDels += del.size();

            if ((newChans.size() > 0 || del.size() > 0)) {
                if (verbose > 1) {
                    System.out.format("    add: %1$d, del %2$d\n", newChans.size(), del.size());
                }
                for (ChanInfo ci : newChans) {
                    if (verbose > 2) {
                        System.out.print("Add: ");
                        ci.print();
                    }
                    chnTbl.insertNewBulk(ci);
                }
                if (newChans.size() > 0) {
                    chnTbl.insertNewBulk(null); // complete the bulk insert
                }
                if (doDeletes) {
                    for (ChanInfo ci : del) {
                        if (verbose > 2) {
                            System.out.print("Del: ");
                            ci.print();
                        }
                        chnTbl.setAvailable(ci.getId(), false);
                    }
                }
            } else if (verbose > 1) {
                System.out.println("    no updates.");
            }

        }
        if (verbose > 0 && totalAdds + totalDels > 0) {
            System.out.format("Total additions: %1$,d, total removals: %2$,d, " + "Server: %3$s, type: %4$s%n",
                    totalAdds, totalDels, cls.getServer(), cls.getcType());
        } else if (verbose > 1 && totalAdds + totalDels == 0) {
            System.out.println("No changes to channel table. %n");
        }
    }
}

From source file:org.apache.ambari.server.stack.StackManagerTest.java

@Test
public void testServiceDeletion() {
    StackInfo stack = stackManager.getStack("HDP", "2.0.6");
    Collection<ServiceInfo> allServices = stack.getServices();

    assertEquals(11, allServices.size());
    HashSet<String> expectedServices = new HashSet<String>();
    expectedServices.add("GANGLIA");
    expectedServices.add("HBASE");
    expectedServices.add("HCATALOG");
    expectedServices.add("HDFS");
    expectedServices.add("HIVE");
    expectedServices.add("MAPREDUCE2");
    expectedServices.add("OOZIE");
    expectedServices.add("PIG");
    expectedServices.add("ZOOKEEPER");
    expectedServices.add("FLUME");
    expectedServices.add("YARN");

    for (ServiceInfo service : allServices) {
        assertTrue(expectedServices.remove(service.getName()));
    }/*from www .j av a2s. c om*/
    assertTrue(expectedServices.isEmpty());
}

From source file:org.gcaldaemon.core.file.OnlineFileListener.java

private final long saveDir(byte[] iCalBytes, int fileIndex) throws Exception {

    // Mac OS X Leopard (one calendar = multiple iCal files)
    // Get original/old iCalendar files
    File dir = iCalFiles[fileIndex];
    HashSet oldFiles = new HashSet();
    oldFiles.addAll(Arrays.asList(dir.list()));

    // Get component array
    Calendar container = ICalUtilities.parseCalendar(iCalBytes);
    ComponentList list = container.getComponents();
    Component[] array = new Component[list.size()];
    list.toArray(array);/*w w w. j a va 2 s . c  o  m*/

    // Save component
    String fileName;
    for (int i = 0; i < array.length; i++) {
        fileName = saveComponent(dir, array[i], fileIndex);
        oldFiles.remove(fileName);
    }

    // Remove deleted events
    Iterator removedNames = oldFiles.iterator();
    File file;
    while (removedNames.hasNext()) {
        fileName = (String) removedNames.next();
        if (!fileName.endsWith(".ics")) {
            continue;
        }
        try {
            file = new File(dir, fileName);
            file.delete();
            if (log.isDebugEnabled()) {
                log.debug("File deleted (" + file.getCanonicalPath().replace('\\', '/') + ").");
            }
        } catch (Exception ignored) {
        }
    }

    // Return the last modified file's timestamp
    return lastModified(dir);
}

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

@Test(timeout = 180000)
public void testRateLimitingDuringDataNodeStartup() throws Exception {
    Configuration conf = new Configuration();
    conf.setInt(DFS_NAMENODE_MAX_FULL_BLOCK_REPORT_LEASES, 1);
    conf.setLong(DFS_NAMENODE_FULL_BLOCK_REPORT_LEASE_LENGTH_MS, 20L * 60L * 1000L);

    final Semaphore fbrSem = new Semaphore(0);
    final HashSet<DatanodeID> expectedFbrDns = new HashSet<>();
    final HashSet<DatanodeID> fbrDns = new HashSet<>();
    final AtomicReference<String> failure = new AtomicReference<String>("");

    final BlockManagerFaultInjector injector = new BlockManagerFaultInjector() {
        private int numLeases = 0;

        @Override/*from   w  w w  . j  ava2 s.  c o m*/
        public void incomingBlockReportRpc(DatanodeID nodeID, BlockReportContext context) throws IOException {
            LOG.info("Incoming full block report from " + nodeID + ".  Lease ID = 0x"
                    + Long.toHexString(context.getLeaseId()));
            if (context.getLeaseId() == 0) {
                setFailure(failure,
                        "Got unexpected rate-limiting-" + "bypassing full block report RPC from " + nodeID);
            }
            fbrSem.acquireUninterruptibly();
            synchronized (this) {
                fbrDns.add(nodeID);
                if (!expectedFbrDns.remove(nodeID)) {
                    setFailure(failure, "Got unexpected full block report " + "RPC from " + nodeID
                            + ".  expectedFbrDns = " + Joiner.on(", ").join(expectedFbrDns));
                }
                LOG.info("Proceeding with full block report from " + nodeID + ".  Lease ID = 0x"
                        + Long.toHexString(context.getLeaseId()));
            }
        }

        @Override
        public void requestBlockReportLease(DatanodeDescriptor node, long leaseId) {
            if (leaseId == 0) {
                return;
            }
            synchronized (this) {
                numLeases++;
                expectedFbrDns.add(node);
                LOG.info("requestBlockReportLease(node=" + node + ", leaseId=0x" + Long.toHexString(leaseId)
                        + ").  " + "expectedFbrDns = " + Joiner.on(", ").join(expectedFbrDns));
                if (numLeases > 1) {
                    setFailure(failure, "More than 1 lease was issued at once.");
                }
            }
        }

        @Override
        public void removeBlockReportLease(DatanodeDescriptor node, long leaseId) {
            LOG.info("removeBlockReportLease(node=" + node + ", leaseId=0x" + Long.toHexString(leaseId) + ")");
            synchronized (this) {
                numLeases--;
            }
        }
    };
    BlockManagerFaultInjector.instance = injector;

    final int NUM_DATANODES = 5;
    MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(NUM_DATANODES).build();
    cluster.waitActive();
    for (int n = 1; n <= NUM_DATANODES; n++) {
        LOG.info("Waiting for " + n + " datanode(s) to report in.");
        fbrSem.release();
        Uninterruptibles.sleepUninterruptibly(20, TimeUnit.MILLISECONDS);
        final int currentN = n;
        GenericTestUtils.waitFor(new Supplier<Boolean>() {
            @Override
            public Boolean get() {
                synchronized (injector) {
                    if (fbrDns.size() > currentN) {
                        setFailure(failure,
                                "Expected at most " + currentN
                                        + " datanodes to have sent a block report, but actually "
                                        + fbrDns.size() + " have.");
                    }
                    return (fbrDns.size() >= currentN);
                }
            }
        }, 25, 50000);
    }
    cluster.shutdown();
    Assert.assertEquals("", failure.get());
}

From source file:edu.cornell.mannlib.vitro.webapp.dao.jena.VClassDaoJena.java

public List<String> getAllSubClassURIs(String classURI) {
    HashSet<String> nodeSet = new HashSet<String>();
    nodeSet.add(classURI);/*w  w w  .j a  v  a2 s  . c o  m*/
    getAllSubClassURIs(classURI, nodeSet);
    nodeSet.remove(classURI);
    List<String> outputList = new ArrayList<String>();
    outputList.addAll(nodeSet);
    return outputList;
}