List of usage examples for java.util HashSet iterator
public Iterator<E> iterator()
From source file:edu.ucla.cs.scai.canali.core.index.BuildIndex.java
private void loadClassHierarchy() throws Exception { System.out.println("Loading class parents and building the hierarchy"); //firs, we initialize class parents classParents = new HashSet[classIdFromUri.size() + 1]; for (int i = 1; i < classParents.length; i++) { classParents[i] = new HashSet<>(); //we don't initialize class ancestors because the null value is used to check if the class has not been processed yet }//from w w w . j ava 2s . com try (BufferedReader in = new BufferedReader(new FileReader(basePathInput + "class_parents"))) { String l = in.readLine(); while (l != null) { if (l.length() > 0) { StringTokenizer st = new StringTokenizer(l, "\t<>"); String claz = st.nextToken().trim(); String parent = st.nextToken().trim(); //we are interested only in the hierarchical relationships between //classes defined inside our ontology Integer cId = classIdFromUri.get(claz); Integer pId = classIdFromUri.get(parent); if (cId != null && pId != null && !pId.equals(cId)) { classParents[cId].add(pId); } } l = in.readLine(); } //now add Thing to empty sets of parents for (int cId = 1; cId < classParents.length; cId++) { if (classParents[cId].isEmpty()) { classParents[cId].add(thingId); } } classParents[thingId].clear(); //now, for each class compute the set of its ancestors classAncestors = new HashSet[classIdFromUri.size() + 1]; for (int cId = 1; cId < classAncestors.length; cId++) { computeClassAncestors(cId); } //now, reduce the set of class parents, by keeping only the most specific classes for (int cId = 1; cId < classParents.length; cId++) { HashSet<Integer> currentParents = classParents[cId]; HashSet<Integer> reducedParents = new HashSet<>(); for (Integer pId : currentParents) { //check if reducedParents contains an ancestor of parent, //or if parent is an ancestor of any class in reducedParents boolean add = true; for (Iterator<Integer> it = reducedParents.iterator(); it.hasNext();) { Integer c = it.next(); if (classAncestors[c].contains(pId)) { add = false; //we don't add parent, beacause c is a descendant of parent break; } else if (classAncestors[pId].contains(c)) { it.remove(); //we remove c beacause parent is a descendant of c } } if (add) { reducedParents.add(pId); } } classParents[cId] = reducedParents; } //now, compute the class children for each class classChildren = new HashSet[classIdFromUri.size() + 1]; for (int cId = 1; cId < classChildren.length; cId++) { classChildren[cId] = new HashSet<>(); } for (int cId = 1; cId < classParents.length; cId++) { for (Integer pId : classParents[cId]) { classChildren[pId].add(cId); } } //now compute the class descendants for each class classDescendants = new HashSet[classIdFromUri.size() + 1]; for (int cId = 1; cId < classDescendants.length; cId++) { computeClassDescendants(cId); } } }
From source file:org.codehaus.mojo.CppCheckMojo.java
protected String getCommandArgs() { String params = commandArgs + " "; HashSet<String> excudedSet = new HashSet<String>(); Iterator it = includeDirs.iterator(); while (it.hasNext()) { FileSet afileSet = new FileSet(); String dir = it.next().toString(); params += "-I\"" + dir + "\" "; if (StringUtils.isNotEmpty(excludes)) { afileSet.setDirectory(new File(dir).getAbsolutePath()); afileSet.setUseDefaultExcludes(false); // $FB pour viter d'avoir TROP de fichier excludes (inutiles) dans la boucle for ci-aprs afileSet.setExcludes(Arrays.asList(excludes.split(","))); getLog().debug("cppcheck excludes are :" + Arrays.toString(afileSet.getExcludes().toArray())); FileSetManager aFileSetManager = new FileSetManager(); String[] found = aFileSetManager.getExcludedFiles(afileSet); excudedSet.addAll(new HashSet<String>(Arrays.asList(found))); }/* w w w . j av a 2 s. co m*/ } it = sourceDirs.iterator(); while (it.hasNext()) { FileSet afileSet = new FileSet(); String dir = it.next().toString(); params += "-I\"" + dir + "\" "; if (StringUtils.isNotEmpty(excludes)) { afileSet.setDirectory(new File(dir).getAbsolutePath()); afileSet.setUseDefaultExcludes(false); // $FB pour viter d'avoir TROP de fichiers exclude (inutile) dans la boucle for ci-aprs afileSet.setExcludes(Arrays.asList(excludes.split(","))); getLog().debug("cppcheck excludes are :" + Arrays.toString(afileSet.getExcludes().toArray())); FileSetManager aFileSetManager = new FileSetManager(); String[] found = aFileSetManager.getExcludedFiles(afileSet); excudedSet.addAll(new HashSet<String>(Arrays.asList(found))); } } for (Iterator<String> iter = excudedSet.iterator(); iter.hasNext();) { String s = iter.next(); //cppcheck only check *.cpp, *.cxx, *.cc, *.c++, *.c, *.tpp, and *.txx files // so remove unneeded exclusions if (s.matches("(.+\\.cpp)|(.+\\.cxx)|(.+\\.cc)|(.+\\.c\\+\\+)|(.+\\.c)|(.+\\.tpp)|(.+\\.txx)")) { params += "-i\"" + s + "\" "; } } it = sourceDirs.iterator(); while (it.hasNext()) { params += "\"" + it.next() + "\" "; } return params; }
From source file:version1.Neo4jTest.Wiki2Neo4j.java
void connectCubetoAttributes(ArrayList<Cube> all_cubes, RelTypes rel) { registerShutdownHook(graphDb);//from w ww . ja v a 2 s. c o m try (Transaction tx = graphDb.beginTx()) { for (int i = 0; i < all_cubes.size(); i++) { Cube cube = all_cubes.get(i); Node cube_node = (Node) string_node.get(cube.getCubelongName()); HashSet SC_Attribute = new HashSet(); for (String key : cube.Meldekonzept_SCDimensionen.keySet()) { HashSet dummy = cube.Meldekonzept_SCDimensionen.get(key); //Node meldekonzept_node = (Node) string_node.get(key.toString()); if (dummy != null) SC_Attribute.addAll(dummy); // if (meldekonzept_node!=null){ // relationship = meldekonzept_node.createRelationshipTo(cube_node, rel); // java.util.Iterator it = dummy.iterator(); // while(it.hasNext()){ // String sc_attribut_name = (String) it.next(); // Node sc_attribut = (Node) string_node.get(sc_attribut_name); // if (sc_attribut != null & cube_node != null) relationship = sc_attribut.createRelationshipTo(cube_node, rel);//meldekonzept_node // } // } } //Iteration ueber MK java.util.Iterator it = SC_Attribute.iterator(); while (it.hasNext()) { String sc_attribut_name = (String) it.next(); Node sc_attribut_node = (Node) string_node.get(sc_attribut_name); if (sc_attribut_node != null & cube_node != null) relationship = sc_attribut_node.createRelationshipTo(cube_node, rel);//meldekonzept_node } } tx.success(); } }
From source file:edu.cornell.mannlib.vitro.webapp.dao.jena.PropertyDaoJena.java
/** * Finds the classes that have a definition involving a restriction * on the given property. /*from w w w. j a v a 2 s . c o m*/ * * @param propertyURI identifier of a property * @return a list of VClass objects representing the classes that have * definitions involving a restriction on the given property. */ @Override public List<VClass> getClassesWithRestrictionOnProperty(String propertyURI) { if (propertyURI == null) { log.warn("getClassesWithRestrictionOnProperty: called with null propertyURI"); return null; } OntModel ontModel = getOntModel(); ontModel.enterCriticalSection(Lock.READ); HashSet<String> classURISet = new HashSet<String>(); try { Resource targetProp = ontModel.getResource(propertyURI); if (targetProp != null) { StmtIterator stmtIter = ontModel.listStatements((Resource) null, OWL.onProperty, targetProp); while (stmtIter.hasNext()) { Statement statement = stmtIter.next(); if (statement.getSubject().canAs(OntClass.class)) { classURISet.addAll(getRestrictedClasses(statement.getSubject().as(OntClass.class))); } else { log.warn( "getClassesWithRestrictionOnProperty: Unexpected use of onProperty: it is not applied to a class"); } } } else { log.error( "getClassesWithRestrictionOnProperty: Error: didn't find a Property in the ontology model for the URI: " + propertyURI); } } finally { ontModel.leaveCriticalSection(); } List<VClass> classes = new ArrayList<VClass>(); Iterator<String> iter = classURISet.iterator(); VClassDao vcd = getWebappDaoFactory().getVClassDao(); while (iter.hasNext()) { String curi = iter.next(); VClass vc = vcd.getVClassByURI(curi); if (vc != null) { classes.add(vc); } else { log.error("getClassesWithRestrictionOnProperty: Error: no VClass found for URI: " + curi); } } return (classes.size() > 0) ? classes : null; }
From source file:playground.meisterk.org.matsim.run.westumfahrung.CompareScenarios.java
/** * Gets all agents that use a set of links in one plans file and use another set in another plans file. * For example: Find all agents that use the Westtangente in a scenario without the Westumfahrung, that * switch to the Westumfahrung in a case study where the Westumfahrung was included in the scenario. * * Summarize their average trip travel times, the scores of their selected plans, and their home locations. */// ww w . j ava 2 s .c o m private void doAnalyses(World world) { TreeMap<Integer, TreeMap<String, PersonIdRecorder>> personIdRecorders = new TreeMap<Integer, TreeMap<String, PersonIdRecorder>>(); for (Integer analysis : this.analysisNames.keySet()) { personIdRecorders.put(analysis, new TreeMap<String, PersonIdRecorder>()); } TreeMap<String, Population> scenarioPlans = new TreeMap<String, Population>(); TreeMap<String, Network> scenarioNetworks = new TreeMap<String, Network>(); PersonIdRecorder personIdRecorder = null; PersonFilter filterAlgorithm = null; for (String scenarioName : this.scenarioNames) { ScenarioImpl scenario = (ScenarioImpl) ScenarioUtils.createScenario(ConfigUtils.createConfig()); Network network = scenario.getNetwork(); new MatsimNetworkReader(scenario).readFile(this.networkInputFilenames.get(scenarioName)); scenarioNetworks.put(scenarioName, network); //Plans plans = playground.meisterk.MyRuns.initMatsimAgentPopulation(plansInputFilenames.get(scenarioName), false, null, network); PopulationImpl plans = (PopulationImpl) scenario.getPopulation(); PopulationReader plansReader = new MatsimPopulationReader(scenario); plansReader.readFile(this.plansInputFilenames.get(scenarioName)); plans.printPlansCount(); scenarioPlans.put(scenarioName, plans); for (Integer analysis : this.analysisNames.keySet()) { personIdRecorder = new PersonIdRecorder(); // distinguish person filtering by analysis type switch (analysis.intValue()) { case TRANSIT_AGENTS_ANALYSIS_NAME: filterAlgorithm = new PersonIdFilter(TRANSIT_PERSON_ID_PATTERN, personIdRecorder); break; case NON_TRANSIT_AGENTS_ANALYSIS_NAME: filterAlgorithm = new PersonIdFilter(NON_TRANSIT_PERSON_ID_PATTERN, personIdRecorder); break; case ROUTE_SWITCHERS_ANALYSIS_NAME: RouteLinkFilter routeLinkFilter = new RouteLinkFilter(personIdRecorder); filterAlgorithm = new SelectedPlanFilter(routeLinkFilter); for (Id linkId : this.linkSets.get(scenarioName)) { routeLinkFilter.addLink(linkId); } break; case WESTSTRASSE_NEIGHBORS_ANALYSIS_NAME: ActLinkFilter homeAtTheWeststrasseFilter = new ActLinkFilter(".*h.*", personIdRecorder); filterAlgorithm = new SelectedPlanFilter(homeAtTheWeststrasseFilter); for (Id linkId : this.weststrasseLinkIds) { homeAtTheWeststrasseFilter.addLink(linkId); } break; default: break; } personIdRecorders.get(analysis).put(scenarioName, personIdRecorder); plans.addAlgorithm(filterAlgorithm); } plans.runAlgorithms(); } // make this nicer, because all analyses are of the same kind :-) HashSet<Id> routeSwitchersPersonIds = (HashSet<Id>) personIdRecorders.get(ROUTE_SWITCHERS_ANALYSIS_NAME) .get(this.scenarioNameAfter).getIds().clone(); routeSwitchersPersonIds.retainAll( personIdRecorders.get(ROUTE_SWITCHERS_ANALYSIS_NAME).get(this.scenarioNameBefore).getIds()); HashSet<Id> neighborsPersonIds = personIdRecorders.get(WESTSTRASSE_NEIGHBORS_ANALYSIS_NAME) .get(this.scenarioNameBefore).getIds(); HashSet<Id> transitAgentsIds = personIdRecorders.get(TRANSIT_AGENTS_ANALYSIS_NAME) .get(this.scenarioNameBefore).getIds(); HashSet<Id> nonTransitAgentsIds = personIdRecorders.get(NON_TRANSIT_AGENTS_ANALYSIS_NAME) .get(this.scenarioNameBefore).getIds(); log.info("Agents before: " + personIdRecorders.get(ROUTE_SWITCHERS_ANALYSIS_NAME) .get(this.scenarioNameBefore).getIds().size()); log.info("Agents after: " + personIdRecorders.get(ROUTE_SWITCHERS_ANALYSIS_NAME).get(this.scenarioNameAfter).getIds().size()); log.info("Route switchers: " + routeSwitchersPersonIds.size()); log.info("number of neighbors: " + neighborsPersonIds.size()); log.info("number of transit agents: " + transitAgentsIds.size()); log.info("number of non transit agents: " + nonTransitAgentsIds.size()); Iterator<Id> personIterator = null; // HashSet<Id> subPop = new HashSet<Id>(); for (Integer analysis : this.analysisNames.keySet()) { ArrayList<CaseStudyResult> results = new ArrayList<CaseStudyResult>(); for (String scenarioName : this.scenarioNames) { ScenarioImpl subScenario = (ScenarioImpl) ScenarioUtils.createScenario(ConfigUtils.createConfig()); subScenario.setNetwork(scenarioNetworks.get(scenarioName)); Population plansSubPop = subScenario.getPopulation(); switch (analysis.intValue()) { case TRANSIT_AGENTS_ANALYSIS_NAME: personIterator = transitAgentsIds.iterator(); break; case NON_TRANSIT_AGENTS_ANALYSIS_NAME: personIterator = nonTransitAgentsIds.iterator(); break; case ROUTE_SWITCHERS_ANALYSIS_NAME: personIterator = routeSwitchersPersonIds.iterator(); break; case WESTSTRASSE_NEIGHBORS_ANALYSIS_NAME: personIterator = neighborsPersonIds.iterator(); break; default: break; } while (personIterator.hasNext()) { try { plansSubPop .addPerson(scenarioPlans.get(scenarioName).getPersons().get(personIterator.next())); } catch (Exception e) { e.printStackTrace(); } } Activity homeActivity = null; if (analysis.intValue() == ROUTE_SWITCHERS_ANALYSIS_NAME) { if (scenarioName.equals(this.scenarioNames[0])) { this.routeSwitchersLines.add("person\thome_link\thome_x\thome_y"); for (Person person : plansSubPop.getPersons().values()) { for (PlanElement pe : person.getSelectedPlan().getPlanElements()) { if (pe instanceof Activity) { homeActivity = (Activity) pe; if (Pattern.matches(".*h.*", homeActivity.getType())) { continue; } } } this.routeSwitchersLines .add(person.getId().toString() + "\t" + homeActivity.getLinkId().toString() + "\t" + Double.toString(homeActivity.getCoord().getX()) + "\t" + Double.toString(homeActivity.getCoord().getY())); // routeSwitchersLines.add(new String( // person.getId() + "\t" + // homeActivity.getLinkId().toString() + "\t" + // homeActivity.getCoord().getX() + "\t" + // homeActivity.getCoord().getY() // )); } } } PlanAverageScore planAverageScore = new PlanAverageScore(); planAverageScore.run(plansSubPop); CalcAverageTripLength calcAverageTripLength = new CalcAverageTripLength( scenarioNetworks.get(scenarioName)); calcAverageTripLength.run(plansSubPop); EventsManager events = EventsUtils.createEventsManager(); CalcLegTimes calcLegTimes = new CalcLegTimes(); events.addHandler(calcLegTimes); results.add(new CaseStudyResult(scenarioName, plansSubPop, calcLegTimes, planAverageScore, calcAverageTripLength)); // EventsReaderDEQv1 eventsReader = new EventsReaderDEQv1(events); // log.info("events filename: " + this.eventsInputFilenames.get(scenarioName)); // eventsReader.readFile(this.eventsInputFilenames.get(scenarioName)); throw new RuntimeException("reading binary events is no longer supported."); } this.scenarioComparisonLines.add("Analysis: " + this.analysisNames.get(analysis)); this.writeComparison(results); this.scenarioComparisonLines.add(""); } }
From source file:org.gcaldaemon.core.sendmail.SendMail.java
private final void sendPlainText(String email, String content, GmailEntry entry) throws Exception { // Mail properties HashSet to = new HashSet(); HashSet cc = new HashSet(); HashSet bcc = new HashSet(); String subject = "Mail from " + username; QuickWriter body = new QuickWriter(content.length()); if (email != null) { to.add(email);//from w ww .ja v a2 s .c om } // Parse text LineNumberReader reader = new LineNumberReader(new StringReader(content)); boolean readingBody = false; String line, upper; for (;;) { line = reader.readLine(); if (line == null) { break; } if (readingBody) { body.write(line); body.write(CRLF); continue; } if (line.trim().length() == 0) { continue; } upper = line.toUpperCase(); if (upper.startsWith("ENCODING")) { continue; } if (upper.startsWith("SUBJECT")) { subject = getParameter(line); continue; } if (upper.startsWith("TO")) { addParameters(to, line); continue; } if (upper.startsWith("CC")) { addParameters(cc, line); continue; } if (upper.startsWith("BCC")) { addParameters(bcc, line); continue; } readingBody = true; body.write(line); body.write(CRLF); } // Submit mail String toList = ""; String ccList = ""; String bccList = ""; Iterator i = to.iterator(); while (i.hasNext()) { toList += (String) i.next() + ","; } i = cc.iterator(); while (i.hasNext()) { ccList += (String) i.next() + ","; } i = bcc.iterator(); while (i.hasNext()) { bccList += (String) i.next() + ","; } if (toList.length() == 0) { toList = username; } String msg = body.toString(); boolean isHTML = msg.indexOf("/>") != -1 || msg.indexOf("</") != -1; if (isHTML) { msg = cropBody(msg); } if (isHTML) { log.debug("Sending HTML mail..."); } else { log.debug("Sending plain-text mail..."); } entry.send(toList, ccList, bccList, subject, msg, isHTML); log.debug("Mail submission finished."); }
From source file:org.apache.maven.plugin.cxx.CppCheckMojo.java
@Override protected String getCommandArgs() { String params = commandArgs + " "; HashSet<String> excudedSet = new HashSet<String>(); Iterator it = includeDirs.iterator(); while (it.hasNext()) { FileSet afileSet = new FileSet(); String dir = it.next().toString(); params += "-I\"" + dir + "\" "; if (StringUtils.isNotEmpty(excludes)) { afileSet.setDirectory(new File(dir).getAbsolutePath()); // $FB pour viter d'avoir TROP de fichier excludes (inutiles) dans la boucle for ci-aprs afileSet.setUseDefaultExcludes(false); afileSet.setExcludes(Arrays.asList(excludes.split(","))); getLog().debug("cppcheck excludes are :" + Arrays.toString(afileSet.getExcludes().toArray())); FileSetManager aFileSetManager = new FileSetManager(); String[] found = aFileSetManager.getExcludedFiles(afileSet); excudedSet.addAll(new HashSet<String>(Arrays.asList(found))); }//from w w w . j a v a2 s .c o m } it = sourceDirs.iterator(); while (it.hasNext()) { FileSet afileSet = new FileSet(); String dir = it.next().toString(); params += "-I\"" + dir + "\" "; if (StringUtils.isNotEmpty(excludes)) { afileSet.setDirectory(new File(dir).getAbsolutePath()); // $FB pour viter d'avoir TROP de fichiers exclude (inutile) dans la boucle for ci-aprs afileSet.setUseDefaultExcludes(false); afileSet.setExcludes(Arrays.asList(excludes.split(","))); getLog().debug("cppcheck excludes are :" + Arrays.toString(afileSet.getExcludes().toArray())); FileSetManager aFileSetManager = new FileSetManager(); String[] found = aFileSetManager.getExcludedFiles(afileSet); excudedSet.addAll(new HashSet<String>(Arrays.asList(found))); } } for (Iterator<String> iter = excudedSet.iterator(); iter.hasNext();) { String s = iter.next(); //cppcheck only check *.cpp, *.cxx, *.cc, *.c++, *.c, *.tpp, and *.txx files // so remove unneeded exclusions if (s.matches("(.+\\.cpp)|(.+\\.cxx)|(.+\\.cc)|(.+\\.c\\+\\+)|(.+\\.c)|(.+\\.tpp)|(.+\\.txx)")) { params += "-i\"" + s + "\" "; } } it = sourceDirs.iterator(); while (it.hasNext()) { params += "\"" + it.next() + "\" "; } return params; }
From source file:dao.UserpageDaoDb.java
/** * this method returns the second degree of friends * @param userpage - the userpage/* w ww . j a va2s . c o m*/ * @param friend1 - the friend1 * @param friend2 - the friend2 * @throws BaseDaoException - when error occurs */ private void getMySecondFriends(Userpage userpage, String friend1, String friend2, int accessFlag) throws BaseDaoException { if ((userpage == null) || (friend1 == null) || (friend2 == null)) { userpage.setSecondFriends(null); return; } /** * friend1 */ Hdlogin hdlogin = getLoginid(friend1); if (hdlogin == null) { return; } String friendid1 = hdlogin.getValue(DbConstants.LOGIN_ID); /** * friend2 */ hdlogin = getLoginid(friend2); if (hdlogin == null) { return; } /** * first query */ String friendid2 = hdlogin.getValue(DbConstants.LOGIN_ID); Object[] params = { (Object) friendid1, (Object) friendid1 }; List result = null; /** * hdlogin, pendingfriends - no partitioned */ /* String sourceName = null; sourceName = scalabilityManager.getReadZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null " + sourceName); } */ String queryName = null; if (accessFlag == 1) { queryName = scalabilityManager.getWriteZeroScalability("friendcheckquery"); } else { queryName = scalabilityManager.getReadZeroScalability("friendcheckquery"); } friendCheckQuery = getQueryMapper().getQuery(queryName); try { result = friendCheckQuery.execute(params); } catch (Exception e) { throw new BaseDaoException("error executing Query" + friendCheckQuery.getSql(), e); } HashSet hs1 = new HashSet(); if ((result != null) && (result.size() > 0)) { for (int i = 0; i < result.size(); i++) { hs1.add(((Friend) result.get(i)).getValue(DbConstants.FID)); } } Iterator it1; it1 = hs1.iterator(); /** * second query */ params[0] = friendid2; params[1] = friendid2; List result2 = null; try { result2 = friendCheckQuery.execute(params); } catch (Exception e) { throw new BaseDaoException("error executing Query", e); } HashSet hs2 = new HashSet(); if (result2 != null) { if (result2.size() > 0) { for (int i = 0; i < result2.size(); i++) { hs2.add(((Friend) result2.get(i)).getValue(DbConstants.FID)); } } } /** return the intersection of the two sets */ boolean f = hs1.retainAll(hs2); if (hs1.size() == 0) return; /** get the friendids and get the login names */ Iterator it3; it3 = hs1.iterator(); HashSet friendSet = new HashSet(); Hdlogin friendLogin = null; while (it3.hasNext()) { //HdloginidQuery hQuery = new HdloginidQuery(ds); // friendResult = hdloginidQuery.execute(myParams); friendLogin = getLoginid((String) it3.next()); if (friendLogin != null) { friendSet.add(friendLogin); } } userpage.setSecondFriends(friendSet); }
From source file:edu.ucla.cs.scai.canali.core.index.BuildIndex.java
private void loadEntityClasses() throws Exception { System.out.println("Loading entity classes, and keeping only the most specific"); int count = 0; HashSet<Integer> notEmptyClasses = new HashSet<>(); try (BufferedReader in = new BufferedReader(new FileReader(basePathInput + "entity_classes"))) { String l = in.readLine(); while (l != null) { try { StringTokenizer st = new StringTokenizer(l, "\t<>"); String uriE = st.nextToken(); String uriC = st.nextToken(); Integer idE = getEntityIdFromUri(uriE);//entityIdFromUri.get(uriE); Integer idC = classIdFromUri.get(uriC); if (!uriC.equals(THING) && idE != null && idC != null && entityLabels[idE] != null && classLabels[idC] != null) { //we ignore the classes without label and the classes of entities not used in triples //we also ignore thing as class, since every entity is implicitly a thing HashSet<Integer> classes = entityClasses[idE]; if (classes == null) { classes = new HashSet<>(); entityClasses[idE] = classes; count++;/* ww w. jav a2 s. c om*/ } //check if classes contains an ancestor of uriC, //or if uriC is an ancestor of any class in classes boolean add = true; for (Iterator<Integer> it = classes.iterator(); it.hasNext();) { Integer c = it.next(); if (classAncestors[c].contains(idC)) { add = false; //we don't add class, beacause c is a descendant of class break; } else if (classAncestors[idC].contains(c)) { it.remove(); //we remove c beacause uriC is a descendant of c } } if (add) { classes.add(idC); notEmptyClasses.add(idC); } } } catch (Exception e) { System.out.println("Failed to load class: " + l); } l = in.readLine(); } } System.out.println(count + " entities have been assigned a non-thing class"); count = 0; //now, set Thing as class of entities without a class for (int i = 1; i < entityClasses.length; i++) { if (entityClasses[i] == null && entityLabels[i] != null) { entityClasses[i] = new HashSet<>(); entityClasses[i].add(thingId); count++; } } System.out.println(count + " entities have been assigned thing class"); //now drop the classes without entities and without descendant classes - asking for those classes would produce empty results could confuse the user for (int i = 1; i < classLabels.length; i++) { if (i != thingId && !notEmptyClasses.contains(i) && classDescendants[i].isEmpty()) { classLabels[i] = null; classUri[i] = null; } } }
From source file:com.enonic.cms.core.internal.service.DataSourceServiceImpl.java
private String convertSimpleSearch(String search, boolean opAnd) { String operator = opAnd ? " AND " : " OR "; StringBuffer query = new StringBuffer(); if (search != null) { HashSet<String> params = new HashSet<String>(); StringTokenizer tok = new StringTokenizer(search, " "); while (tok.hasMoreTokens()) { String param = tok.nextToken(); if (param.length() > 0) { params.add(param);// ww w .jav a 2s . c o m } } for (Iterator<String> i = params.iterator(); i.hasNext();) { String param = i.next(); query.append("((title CONTAINS \"").append(param).append("\") OR "); query.append("(* CONTAINS \"").append(param).append("\"))"); if (i.hasNext()) { query.append(operator); } } } return query.toString(); }