List of usage examples for java.util HashSet iterator
public Iterator<E> iterator()
From source file:org.openflexo.foundation.ie.widget.IERadioButtonWidget.java
public boolean hasSmallestFlexoID() { HashSet<IERadioButtonWidget> v = getWOComponent().getRadioButtonManager().getButtons(this.groupName); if (v == null) { v = getWOComponent().getRadioButtonManager().registerButton(this, groupName); }//from ww w .ja va 2 s . c o m long smallestID = -1; Iterator<IERadioButtonWidget> i = v.iterator(); while (i.hasNext()) { IERadioButtonWidget radio = i.next(); if (radio.getFlexoID() > smallestID) { smallestID = radio.getFlexoID(); } } return smallestID == getFlexoID(); }
From source file:org.apache.ddlutils.model.ForeignKey.java
/** * Compares this foreign key to the given one while ignoring the case of identifiers. * // w ww . j a v a 2 s. com * @param otherFk The other foreign key * @return <code>true</code> if this foreign key is equal (ignoring case) to the given one */ public boolean equalsIgnoreCase(ForeignKey otherFk) { boolean checkName = (_name != null) && (_name.length() > 0) && (otherFk._name != null) && (otherFk._name.length() > 0); if ((!checkName || _name.equalsIgnoreCase(otherFk._name)) && _foreignTableName.equalsIgnoreCase(otherFk._foreignTableName)) { HashSet otherRefs = new HashSet(); otherRefs.addAll(otherFk._references); for (Iterator it = _references.iterator(); it.hasNext();) { Reference curLocalRef = (Reference) it.next(); boolean found = false; for (Iterator otherIt = otherRefs.iterator(); otherIt.hasNext();) { Reference curOtherRef = (Reference) otherIt.next(); if (curLocalRef.equalsIgnoreCase(curOtherRef)) { otherIt.remove(); found = true; break; } } if (!found) { return false; } } return otherRefs.isEmpty(); } else { return false; } }
From source file:org.jumpmind.db.model.ForeignKey.java
/** * Compares this foreign key to the given one while ignoring the case of * identifiers.// w ww. j a v a 2 s. com * * @param otherFk * The other foreign key * @return <code>true</code> if this foreign key is equal (ignoring case) to * the given one */ @SuppressWarnings("unchecked") public boolean equalsIgnoreCase(ForeignKey otherFk) { boolean checkName = isCheckName(otherFk); if ((!checkName || name.equalsIgnoreCase(otherFk.name)) && foreignTableName.equalsIgnoreCase(otherFk.foreignTableName)) { HashSet<Reference> otherRefs = new HashSet<Reference>(); otherRefs.addAll(otherFk.references); for (Iterator<?> it = references.iterator(); it.hasNext();) { Reference curLocalRef = (Reference) it.next(); boolean found = false; for (Iterator<?> otherIt = otherRefs.iterator(); otherIt.hasNext();) { Reference curOtherRef = (Reference) otherIt.next(); if (curLocalRef.equalsIgnoreCase(curOtherRef)) { otherIt.remove(); found = true; break; } } if (!found) { return false; } } return otherRefs.isEmpty(); } else { return false; } }
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 {/* www.j a v a2s .c om*/ // 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.tridas.io.util.ITRDBTaxonConverter.java
/** * Returns a ControlledVoc of the best match from the ITRDB taxon dictionary. Takes a string ArrayList * of possible search terms which can be codes and/or full names. If conflicting search terms are * provided (e.g. QUER, Pinus sylvestris) then it returns null. If no matches are found then it returns null. * /*from www . jav a 2s . com*/ * @param searchStrings * @return */ public static ControlledVoc getBestSpeciesMatch(ArrayList<String> searchStrings) throws ConversionWarningException { if (searchStrings == null || searchStrings.size() == 0) return ITRDBTaxonConverter.getControlledVocFromCode("UNKN"); HashSet<String> codelist = new HashSet<String>(); for (String str : searchStrings) { if (str == null) continue; if (str.length() == 0) continue; if (!getNameFromCode(str).equals(str.toUpperCase())) { codelist.add(str); } else if (!getCodeFromName(str).equals(str)) { codelist.add(getCodeFromName(str)); } } if (codelist.size() == 0) { // None of the search strings matched if (searchStrings.size() == 1) { // Only one string passed to this function so just return as an non-standard string return getControlledVocFromName(searchStrings.get(0)); } else { // Multiple strings passed so we have no way of knowing which is valid throw new ConversionWarningException( new ConversionWarning(WarningType.AMBIGUOUS, "Ambiguous taxon information supplied.")); } } else if (codelist.size() == 2 && codelist.contains("UNKN")) { // List contains 2 values, one of which is UNKN. Just remove it and use the other codelist.remove("UNKN"); } else if (codelist.size() > 1) { throw new ConversionWarningException( new ConversionWarning(WarningType.AMBIGUOUS, "Ambiguous taxon information supplied.")); } Iterator<String> itr = codelist.iterator(); return getControlledVocFromCode(itr.next()); }
From source file:ca.sfu.federation.model.InputTable.java
/** * Get all dependancies for the Inputs in this InputTable. * @return SystolicArrayElements upon which this InputTable is dependant. * TODO: need to think about caching the dependancy list and how updates on the user input on Inputs can propagate dependancy updates to the SAE * TODO: need to think about whether order of dep list is significant, and therefore should be changed to a List output */// w ww. j a v a2 s . co m public Map getDependancies() { // init HashSet dep = new HashSet(); // add dependancies for each input to the set Iterator e = this.inputs.iterator(); while (e.hasNext()) { Input input = (Input) e.next(); dep.addAll((HashSet) input.getDependancies()); } // convert to map // should revisit this at some point .. doesn't make sense any more LinkedHashMap result = new LinkedHashMap(); Iterator iter = dep.iterator(); while (iter.hasNext()) { INamed named = (INamed) iter.next(); result.put(named.getName(), named); } // return result return (Map) result; }
From source file:InlineSchemaValidator.java
public String getPrefix(String namespaceURI) { if (namespaceURI == null) { throw new IllegalArgumentException("Namespace URI cannot be null."); } else if (XMLConstants.XML_NS_URI.equals(namespaceURI)) { return XMLConstants.XML_NS_PREFIX; } else if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(namespaceURI)) { return XMLConstants.XMLNS_ATTRIBUTE; } else if (fURIToPrefixMappings != null) { HashSet prefixes = (HashSet) fURIToPrefixMappings.get(namespaceURI); if (prefixes != null && prefixes.size() > 0) { return (String) prefixes.iterator().next(); }// w ww .ja va2 s.c om } return null; }
From source file:InlineSchemaValidator.java
public Iterator getPrefixes(String namespaceURI) { if (namespaceURI == null) { throw new IllegalArgumentException("Namespace URI cannot be null."); } else if (XMLConstants.XML_NS_URI.equals(namespaceURI)) { return new Iterator() { boolean more = true; public boolean hasNext() { return more; }/*from ww w . ja v a2 s. c o m*/ public Object next() { if (!hasNext()) { throw new NoSuchElementException(); } more = false; return XMLConstants.XML_NS_PREFIX; } public void remove() { throw new UnsupportedOperationException(); } }; } else if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(namespaceURI)) { return new Iterator() { boolean more = true; public boolean hasNext() { return more; } public Object next() { if (!hasNext()) { throw new NoSuchElementException(); } more = false; return XMLConstants.XMLNS_ATTRIBUTE; } public void remove() { throw new UnsupportedOperationException(); } }; } else if (fURIToPrefixMappings != null) { HashSet prefixes = (HashSet) fURIToPrefixMappings.get(namespaceURI); if (prefixes != null && prefixes.size() > 0) { return prefixes.iterator(); } } return Collections.EMPTY_LIST.iterator(); }
From source file:org.unitime.timetable.test.BatchStudentSectioningLoader.java
public void loadLastLikeStudent(org.hibernate.Session hibSession, LastLikeCourseDemand d, org.unitime.timetable.model.Student s, Long courseOfferingId, Hashtable studentTable, Hashtable courseTable, Hashtable classTable, Hashtable classAssignments) { sLog.debug("Loading last like demand of student " + s.getUniqueId() + " (id=" + s.getExternalUniqueId() + ", name=" + s.getFirstName() + " " + s.getMiddleName() + " " + s.getLastName() + ") for " + courseOfferingId);/* w ww . j a va 2s .c o m*/ Student student = (Student) studentTable.get(s.getUniqueId()); if (student == null) { student = new Student(s.getUniqueId().longValue(), true); if (iLoadStudentInfo) loadStudentInfo(student, s); studentTable.put(s.getUniqueId(), student); } int priority = student.getRequests().size(); Vector courses = new Vector(); Course course = (Course) courseTable.get(courseOfferingId); if (course == null) { sLog.warn(" -- course " + courseOfferingId + " not loaded"); return; } courses.addElement(course); CourseRequest request = new CourseRequest(d.getUniqueId().longValue(), priority++, false, student, courses, false, null); sLog.debug(" -- added request " + request); if (classAssignments != null && !classAssignments.isEmpty()) { HashSet assignedSections = new HashSet(); HashSet classIds = (HashSet) classAssignments.get(s.getUniqueId()); if (classIds != null) for (Iterator i = classIds.iterator(); i.hasNext();) { Long classId = (Long) i.next(); Section section = (Section) request.getSection(classId.longValue()); if (section != null) assignedSections.add(section); } if (!assignedSections.isEmpty()) { sLog.debug(" -- committed assignment: " + assignedSections); for (Enrollment enrollment : request.values(getAssignment())) { if (enrollment.getAssignments().containsAll(assignedSections)) { request.setInitialAssignment(enrollment); sLog.debug(" -- found: " + enrollment); break; } } } } }
From source file:org.apache.axis.i18n.ProjectResourceBundle.java
public Enumeration getKeys() { Enumeration myKeys = resourceBundle.getKeys(); if (parent == null) { return myKeys; } else {// ww w. j av a 2s . c o m final HashSet set = new HashSet(); while (myKeys.hasMoreElements()) { set.add(myKeys.nextElement()); } Enumeration pKeys = parent.getKeys(); while (pKeys.hasMoreElements()) { set.add(pKeys.nextElement()); } return new Enumeration() { private Iterator it = set.iterator(); public boolean hasMoreElements() { return it.hasNext(); } public Object nextElement() { return it.next(); } }; } }