List of usage examples for java.util HashSet size
public int size()
From source file:edu.cornell.mannlib.vitro.webapp.search.controller.PagedSearchController.java
private List<VClassSearchLink> getVClassLinks(VClassDao vclassDao, SearchResultDocumentList docs, SearchResponse rsp, String qtxt) { HashSet<String> typesInHits = getVClassUrisForHits(docs); List<VClass> classes = new ArrayList<VClass>(typesInHits.size()); Map<String, Long> typeURItoCount = new HashMap<String, Long>(); List<SearchFacetField> ffs = rsp.getFacetFields(); for (SearchFacetField ff : ffs) { if (VitroSearchTermNames.RDFTYPE.equals(ff.getName())) { List<Count> counts = ff.getValues(); for (Count ct : counts) { String typeUri = ct.getName(); long count = ct.getCount(); try { if (VitroVocabulary.OWL_THING.equals(typeUri) || count == 0) continue; VClass type = vclassDao.getVClassByURI(typeUri); if (type != null && !type.isAnonymous() && type.getName() != null && !"".equals(type.getName()) && type.getGroupURI() != null) { //don't display classes that aren't in classgroups typeURItoCount.put(typeUri, count); classes.add(type); }//from w w w.j av a 2 s.co m } catch (Exception ex) { if (log.isDebugEnabled()) log.debug("could not add type " + typeUri, ex); } } } } Collections.sort(classes, new Comparator<VClass>() { public int compare(VClass o1, VClass o2) { return o1.compareTo(o2); } }); List<VClassSearchLink> vClassLinks = new ArrayList<VClassSearchLink>(classes.size()); for (VClass vc : classes) { long count = typeURItoCount.get(vc.getURI()); vClassLinks.add(new VClassSearchLink(qtxt, vc, count)); } return vClassLinks; }
From source file:org.compass.core.lucene.engine.store.DefaultLuceneSearchEngineStore.java
public String[] calcSubIndexes(String[] subIndexes, String[] aliases) { if (aliases == null) { if (subIndexes == null) { return getSubIndexes(); }//w w w .ja va2 s. c om // filter out any duplicates HashSet<String> ret = new HashSet<String>(); ret.addAll(Arrays.asList(subIndexes)); return ret.toArray(new String[ret.size()]); } HashSet<String> ret = new HashSet<String>(); for (String aliase : aliases) { List<String> subIndexesList = subIndexesByAlias.get(aliase); if (subIndexesList == null) { throw new IllegalArgumentException("No sub-index is mapped to alias [" + aliase + "]"); } for (String subIndex : subIndexesList) { ret.add(subIndex); } } if (subIndexes != null) { ret.addAll(Arrays.asList(subIndexes)); } return ret.toArray(new String[ret.size()]); }
From source file:org.nuxeo.ecm.automation.core.impl.OperationServiceImpl.java
@Override public List<OperationDocumentation> getDocumentation() throws OperationException { List<OperationDocumentation> result = new ArrayList<OperationDocumentation>(); HashSet<OperationType> ops = new HashSet<>(operations.lookup().values()); OperationCompoundExceptionBuilder errorBuilder = new OperationCompoundExceptionBuilder(); for (OperationType ot : ops.toArray(new OperationType[ops.size()])) { try {//from w ww . j a va2 s. c om result.add(ot.getDocumentation()); } catch (OperationNotFoundException e) { errorBuilder.add(e); } } errorBuilder.throwOnError(); Collections.sort(result); return result; }
From source file:com.illustrationfinder.process.post.HtmlPostProcessor.java
@Override public List<String> generateKeywords() { // TODO If two words are always close to each other, they should be considered as an expression and managed like one word if (this.url == null) return null; try {//from ww w . j a v a 2s .c o m // Retrieve the document and store it temporary try (final InputStream stream = this.url.openStream()) { final String rawText = IOUtils.toString(stream); // Retrieve useful HTML data final Document document = Jsoup.parse(rawText); String htmlTitle = document.title(); String htmlKeywords = document.select("meta[name=keywords]").text(); String htmlDescription = document.select("meta[name=description]").text(); // Extract the content of the raw text String content = ArticleExtractor.getInstance().getText(rawText); // Now we apply a simple algorithm to get keywords // 1) We remove all punctuation marks from the title // 2) We remove all words with less than 4 characters // 3) We remove excessive spacing and tabulations htmlTitle = htmlTitle.toLowerCase(); htmlTitle = htmlTitle.replaceAll(PUNCTUATION_REGEX, ""); htmlTitle = htmlTitle.replaceAll(WORD_WITH_LESS_THAN_4_CHARACTERS_REGEX, ""); htmlTitle = htmlTitle.replaceAll(EXCESSIVE_SPACING_REGEX, " "); final List<String> keywords = new ArrayList<>(); final List<String> keywordsList = Arrays.asList(htmlTitle.split(" ")); for (String tmp : keywordsList) { if (tmp.length() >= MINIMUM_WORD_LENGTH) { keywords.add(tmp); } } // If there is enough keywords, we return if (keywords.size() >= MINIMUM_KEYWORDS_COUNT) { return keywords; } else { // Otherwise, we look for more keywords from the text by taking the more frequent words content = content.toLowerCase(); content = content.replaceAll(PUNCTUATION_REGEX, ""); content = content.replaceAll(WORD_WITH_LESS_THAN_4_CHARACTERS_REGEX, ""); content = content.replaceAll(EXCESSIVE_SPACING_REGEX, " "); final Map<String, Integer> frequencies = new HashMap<>(); final String[] words = content.split(" "); // Count word frequencies for (final String word : words) { if (frequencies.containsKey(word)) { frequencies.put(word, frequencies.get(word) + 1); } else { frequencies.put(word, 1); } } // Sort the words per frequency final SortedMap<Integer, HashSet<String>> sortedWords = new TreeMap<>(); for (Map.Entry<String, Integer> entry : frequencies.entrySet()) { if (sortedWords.containsKey(entry.getValue())) { sortedWords.get(entry.getValue()).add(entry.getKey()); } else { final HashSet<String> set = new HashSet<>(); set.add(entry.getKey()); sortedWords.put(entry.getValue(), set); } } // Add the most frequent words until we reach the minimu keywords count while (keywords.size() < MINIMUM_KEYWORDS_COUNT) { final HashSet<String> set = sortedWords.get(sortedWords.lastKey()); final String keyword = set.iterator().next(); set.remove(keyword); if (set.size() == 0) { sortedWords.remove(sortedWords.lastKey()); } if (keyword.length() > MINIMUM_WORD_LENGTH) { keywords.add(keyword); } } return keywords; } } } catch (BoilerpipeProcessingException e) { // TODO e.printStackTrace(); } catch (IOException e) { // TODO e.printStackTrace(); } return null; }
From source file:org.lexgrid.valuesets.helper.DefaultCompiler.java
/** * Return the leaf nodes for the supplied graph. As the graph to be traversed could be quite large, this is * done breadth first and non-recursively. With apologies to Walt Whitman * //w w w. ja v a 2 s .c om * Note: were we to implement both the forward and reverse closure on * transitive graphs, this routine could be replaced with the intersection of the supplied graph and the immediate * children or ancestors of the top or bottom nodes respectively. * * @param cng - graph to be traversed * @param isTargetToSource - direction to traverse the graph * @param root - the root node to start the traverse at * @param vdd - value domain definition to resolve leaf nodes against if isLeaf is set * @param refVersions - map of coding Scheme URI to version (may be updated by this routine) * @param versionTag - version tag (e.g. devel, production, etc.) to resolve new nodes * @return - a list of all leaf nodes * @throws LBException */ protected CodedNodeSet leavesOfGraph(CodedNodeGraph cng, boolean isTargetToSource, ConceptReference root, ValueSetDefinition vdd, HashMap<String, String> refVersions, String versionTag) throws LBException { ConceptReferenceList leaves = new ConceptReferenceList(); ConceptReferenceList probes = new ConceptReferenceList(); probes.addConceptReference(root); HashSet<String> seenNode = new HashSet<String>(); // Trade performance for space while (probes.getConceptReferenceCount() > 0) { ConceptReferenceList newProbes = new ConceptReferenceList(); Iterator<? extends ConceptReference> cri = probes.iterateConceptReference(); while (cri.hasNext()) { ConceptReference probe = cri.next(); // Never look at a node more than once. if (seenNode.contains(helper.constructKey(probe))) continue; if (seenNode.size() < helper.getMaxLeafCacheSize()) seenNode.add(helper.constructKey(probe)); boolean probeHasChildren = false; CodedNodeSet directChildren = cng.toNodeList(probe, !isTargetToSource, isTargetToSource, 1, -1); if (directChildren != null) { ResolvedConceptReferencesIterator dcIter = directChildren.resolve(null, null, null, null, false); while (dcIter.hasNext()) { ConceptReference childNode = dcIter.next(); if (!helper.equalReferences(probe, childNode)) { probeHasChildren = true; newProbes.addConceptReference(childNode); } } } if (!probeHasChildren) leaves.addConceptReference(probe); } probes = newProbes; } return helper.conceptReferenceListToCodedNodeSet(leaves, vdd, refVersions, versionTag); }
From source file:com.ubershy.streamsis.project.CuteProject.java
/** * Validates list with Actors/SisScenes. <br> * Throws exceptions if something is wrong telling programmer about errors he made. * * @param list// ww w. ja v a2s . com * the list with Actors or SisScenes */ private <T> void validateListOfActorsOrSisScenes(ObservableList<T> list) { if (list.isEmpty()) { return; } if (list.contains(null)) { throw new RuntimeException("One of the elements in list is null"); } String elementType = null; Object firstElement = list.get(0); if (firstElement instanceof Actor) { elementType = "Actor"; } if (firstElement instanceof SisScene) { elementType = "SisScene"; } if (elementType == null) { throw new RuntimeException("This method only checks lists of Actors or SisScenes"); } ArrayList<String> names = new ArrayList<String>(); for (T element : list) { String name = ((CuteElement) element).getElementInfo().getName(); if (name != null) { names.add(name); } else { throw new RuntimeException(elementType + " has null name"); } } HashSet<String> uniqueNames = new HashSet<String>(names); if (names.size() != uniqueNames.size()) { throw new RuntimeException("Some of " + elementType + "s don't have unique names"); } }
From source file:com.android.messaging.datamodel.BugleDatabaseOperations.java
/** * Refresh conversation names/avatars based on a list of participants that are changed. */// www.j a v a 2s. c o m @DoesNotRunOnMainThread public static void refreshConversationsForParticipants(final ArrayList<String> participants) { Assert.isNotMainThread(); final HashSet<String> conversationIds = getConversationsForParticipants(participants); if (conversationIds.size() > 0) { for (final String conversationId : conversationIds) { refreshConversation(conversationId); } MessagingContentProvider.notifyConversationListChanged(); if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) { LogUtil.v(TAG, "Number of conversations refreshed:" + conversationIds.size()); } } }
From source file:at.treedb.util.SevenZip.java
/** * Extracts some data (files and directories) from the archive without * extracting the whole archive.//from ww w . j ava2 s . c o m * * @param archive * 7-zip archive * @param fileList * file extraction list, a path with an ending '/' denotes a * directory * @return file list as a map file name/file data * @throws IOException */ public static HashMap<String, byte[]> exctact(File archive, String... fileList) throws IOException { HashSet<String> fileSet = new HashSet<String>(); ArrayList<String> dirList = new ArrayList<String>(); for (String f : fileList) { if (!f.endsWith("/")) { fileSet.add(f); } else { dirList.add(f); } } HashMap<String, byte[]> resultMap = new HashMap<String, byte[]>(); SevenZFile sevenZFile = new SevenZFile(archive); do { SevenZArchiveEntry entry = sevenZFile.getNextEntry(); if (entry == null) { break; } // convert window path to unix style String name = entry.getName().replace('\\', '/'); if (!entry.isDirectory()) { boolean storeFile = false; if (fileSet.contains(name)) { storeFile = true; } else { // search directories for (String s : dirList) { if (name.startsWith(s)) { storeFile = true; break; } } } // store the file if (storeFile) { int size = (int) entry.getSize(); byte[] data = new byte[size]; sevenZFile.read(data, 0, size); resultMap.put(name, data); // in this case we can finish the extraction loop if (dirList.isEmpty() && resultMap.size() == fileSet.size()) { break; } } } } while (true); sevenZFile.close(); return resultMap; }
From source file:org.oscarehr.web.MisReportUIBean.java
private DataRow getIndividualsSeen() { HashSet<Integer> individuals = new HashSet<Integer>(); // count face to face individuals in the system pertaining to the allowed programs during that time frame. for (Program program : selectedPrograms) { addIndividualsSeenInProgram(individuals, program); }//from ww w. ja v a 2s . com return (new DataRow(4526000, "Service Recipients Seen, (anonymous or no client record, excluding unique anonymous)", individuals.size())); }
From source file:org.apache.phoenix.jdbc.SecureUserConnectionsIT.java
@Test public void testMultipleConnectionsAsSameUserWithoutLogin() throws Exception { final HashSet<ConnectionInfo> connections = new HashSet<>(); final String princ1 = getUserPrincipal(1); final File keytab1 = getUserKeytabFile(1); // Using the same UGI should result in two equivalent ConnectionInfo objects final String url = joinUserAuthentication(BASE_URL, princ1, keytab1); connections.add(ConnectionInfo.create(url).normalize(ReadOnlyProps.EMPTY_PROPS, EMPTY_PROPERTIES)); assertEquals(1, connections.size()); // Sanity check verifyAllConnectionsAreKerberosBased(connections); // Because the UGI instances are unique, so are the connections connections.add(ConnectionInfo.create(url).normalize(ReadOnlyProps.EMPTY_PROPS, EMPTY_PROPERTIES)); assertEquals(1, connections.size()); }