List of usage examples for java.util HashSet addAll
boolean addAll(Collection<? extends E> c);
From source file:org.apache.axis.wsdl.toJava.JavaStubWriter.java
/** * This method returns a set of all the TypeEntry in a given PortType. * The elements of the returned HashSet are Types. * /* w w w.j a v a2 s . com*/ * @param portType * @return */ private HashSet getTypesInPortType(PortType portType) { HashSet types = new HashSet(); HashSet firstPassTypes = new HashSet(); // Get all the types from all the operations List operations = portType.getOperations(); for (int i = 0; i < operations.size(); ++i) { Operation op = (Operation) operations.get(i); firstPassTypes.addAll(getTypesInOperation(op)); } // Add all the types nested and derived from the types // in the first pass. Iterator i = firstPassTypes.iterator(); while (i.hasNext()) { TypeEntry type = (TypeEntry) i.next(); if (!types.contains(type)) { types.add(type); types.addAll(type.getNestedTypes(symbolTable, true)); } } if (emitter.isAllWanted()) { HashMap rawSymbolTable = symbolTable.getHashMap(); for (Iterator j = rawSymbolTable.values().iterator(); j.hasNext();) { Vector typeVector = (Vector) j.next(); for (Iterator k = typeVector.iterator(); k.hasNext();) { Object symbol = k.next(); if (symbol instanceof DefinedType) { TypeEntry type = (TypeEntry) symbol; if (!types.contains(type)) { types.add(type); } } } } } return types; }
From source file:org.apache.lucene.index.SegmentInfos.java
/** Returns all file names referenced by SegmentInfo * instances matching the provided Directory (ie files * associated with any "external" segments are skipped). * The returned collection is recomputed on each * invocation. *///from ww w . j av a2s . co m public Collection<String> files(Directory dir, boolean includeSegmentsFile) throws IOException { HashSet<String> files = new HashSet<String>(); if (includeSegmentsFile) { files.add(getCurrentSegmentFileName()); files.add(getCurrentSegmentFileNameCRC()); } final int size = size(); for (int i = 0; i < size; i++) { final SegmentInfo info = info(i); if (info.dir == dir) { files.addAll(info(i).files()); } } return files; }
From source file:com.odoo.core.orm.OModel.java
private String[] updateProjection(String[] projection) { HashSet<String> names = new HashSet<>(); String[] allProjection = projection; if (allProjection == null) { allProjection = projection();/*from ww w.ja va 2 s. co m*/ } else { for (String col : projection) { OColumn column = getColumn(col); if (column.isFunctionalColumn() && column.canFunctionalStore()) { names.add(column.getName()); } } } names.addAll(Arrays.asList(allProjection)); names.addAll( Arrays.asList(new String[] { OColumn.ROW_ID, "id", "_write_date", "_is_dirty", "_is_active" })); return names.toArray(new String[names.size()]); }
From source file:hudson.model.View.java
public List<Computer> getComputers() { Computer[] computers = Jenkins.getInstance().getComputers(); if (!isFilterExecutors()) { return Arrays.asList(computers); }//from www . j a va2s. c o m List<Computer> result = new ArrayList<Computer>(); HashSet<Label> labels = new HashSet<Label>(); for (Item item : getItems()) { if (item instanceof AbstractProject<?, ?>) { labels.addAll(((AbstractProject<?, ?>) item).getRelevantLabels()); } } for (Computer c : computers) { if (isRelevant(labels, c)) result.add(c); } return result; }
From source file:edu.virginia.iath.snac.helpers.GeoNamesHelper.java
/** * Gets <code>max</code> next Cheshire results (in normalized XML format), in no particular order. It ignores the * first best match, only returning results 2 to max. There are no duplicates in this list. * /*from w ww .j a v a 2 s.com*/ * @param max Maximum number of results to return * @return String of concatenated XML results, each wrapped in a place tag. */ public String getNextUniqueReturnResults(int max) { String result = ""; int i = 0; HashSet<String> uniqueResults = new HashSet<String>(); uniqueResults.addAll(results); if (results.size() > 0) uniqueResults.remove(results.get(0)); for (String res : uniqueResults) { result += "<place>" + getXMLReturnValue(res) + "</place>\n"; if (i++ > max) break; } return result; }
From source file:org.cgiar.ccafs.marlo.action.projects.ProjectLocationAction.java
public void prepareFundingList() { Project projectDB = projectManager.getProjectById(project.getId()); List<ProjectBudget> projectBudgets = new ArrayList<>(projectDB .getProjectBudgets().stream().filter(pb -> pb.isActive() && pb.getProject().isActive() && pb.getPhase() != null && pb.getPhase().equals(this.getActualPhase())) .collect(Collectors.toList())); List<FundingSource> fundingSources = new ArrayList<>(); for (ProjectBudget projectBudget : projectBudgets) { FundingSource fundingSourceDb = fundingSourceManager .getFundingSourceById(projectBudget.getFundingSource().getId()); fundingSources.add(fundingSourceDb); }/*from w ww.j a v a 2 s . c o m*/ HashSet<FundingSource> fuHashSet = new HashSet<>(); fuHashSet.addAll(fundingSources); fundingSources = new ArrayList<>(fuHashSet); for (FundingSource fundingSource : fundingSources) { fundingSource.getFundingSourceInfo(this.getActualPhase()); } List<LocElement> locElements = new ArrayList<>(); List<LocElementType> locElementTypes = new ArrayList<>(); if (project.getProjecInfoPhase(this.getActualPhase()).getLocationRegional() == null) { project.getProjecInfoPhase(this.getActualPhase()).setLocationRegional(false); } boolean calculateYesOrNo = !this.hasSpecificities(APConstants.CRP_OTHER_LOCATIONS); if (calculateYesOrNo) { project.getProjecInfoPhase(this.getActualPhase()).setLocationGlobal(false); project.getProjecInfoPhase(this.getActualPhase()).setLocationRegional(false); } for (FundingSource fundingSource : fundingSources) { fundingSource = fundingSourceManager.getFundingSourceById(fundingSource.getId()); fundingSource.setFundingSourceInfo(fundingSource.getFundingSourceInfo(this.getActualPhase())); if (fundingSource.getFundingSourceInfo() != null) { if (calculateYesOrNo) { project.getProjecInfoPhase(this.getActualPhase()) .setLocationGlobal(project.getProjecInfoPhase(this.getActualPhase()).getLocationGlobal() || fundingSource.getFundingSourceInfo(this.getActualPhase()).isGlobal()); } // get the funding source info from db fundingSource = fundingSourceManager.getFundingSourceById(fundingSource.getId()); FundingSourceInfo fundingSourceInfo = fundingSource.getFundingSourceInfo(this.getActualPhase()); // Filter The Fundign Source Location Acroding List<FundingSourceLocation> fundingSourceLocations = new ArrayList<>( fundingSource.getFundingSourceLocations().stream() .filter(fs -> fs.isActive() && fs.getPhase().equals(fundingSourceInfo.getPhase())) .collect(Collectors.toList())); for (FundingSourceLocation fundingSourceLocation : fundingSourceLocations) { if (fundingSourceLocation.getLocElementType() == null) { locElements.add(fundingSourceLocation.getLocElement()); if (fundingSourceLocation.getLocElement().getLocElementType().getId() != 2) { if (calculateYesOrNo) { project.getProjecInfoPhase(this.getActualPhase()).setLocationRegional( project.getProjecInfoPhase(this.getActualPhase()).getLocationRegional() || true); } } } else { locElementTypes.add(fundingSourceLocation.getLocElementType()); if (calculateYesOrNo) { project.getProjecInfoPhase(this.getActualPhase()).setLocationRegional( project.getProjecInfoPhase(this.getActualPhase()).getLocationRegional() || true); } } } } } if (project.getCountryFS() == null) { project.setCountryFS(new ArrayList<>()); } if (project.getRegionFS() == null) { project.setRegionFS(new ArrayList<>()); } HashSet<LocElement> hashElements = new HashSet<>(); hashElements.addAll(locElements); locElements = new ArrayList<>(hashElements); for (LocElement locElement : hashElements) { CountryFundingSources countryFundingSources = new CountryFundingSources(); countryFundingSources.setLocElement(locElement); List<FundingSource> sources = fundingSourceManager.searchFundingSourcesByLocElement(projectID, locElement.getId(), this.getCurrentCycleYear(), loggedCrp.getId(), this.getActualPhase().getId()); for (FundingSource fundingSourceElement : sources) { fundingSourceElement .setFundingSourceInfo(fundingSourceElement.getFundingSourceInfo(this.getActualPhase())); } countryFundingSources.setFundingSources(new ArrayList<>(sources)); if (locElement.getLocElementType().getId().longValue() == 2) { if (!project.getCountryFS().contains(countryFundingSources)) { project.getCountryFS().add(countryFundingSources); } } else { if (!project.getRegionFS().contains(countryFundingSources)) { project.getRegionFS().add(countryFundingSources); } } } HashSet<LocElementType> hashElementTypes = new HashSet<>(); hashElementTypes.addAll(locElementTypes); locElementTypes = new ArrayList<>(hashElementTypes); for (LocElementType locElementType : hashElementTypes) { CountryFundingSources countryFundingSources = new CountryFundingSources(); countryFundingSources.setLocElementType(locElementType); List<FundingSource> sources = fundingSourceManager.searchFundingSourcesByLocElementType(projectID, locElementType.getId(), this.getCurrentCycleYear(), loggedCrp.getId()); for (FundingSource fundingSourceElement : sources) { fundingSourceElement .setFundingSourceInfo(fundingSourceElement.getFundingSourceInfo(this.getActualPhase())); } countryFundingSources.setFundingSources(new ArrayList<>(sources)); if (!project.getRegionFS().contains(countryFundingSources)) { project.getRegionFS().add(countryFundingSources); } } Collections.sort(project.getCountryFS(), (tu1, tu2) -> tu1.getLocElement().getName().compareTo(tu2.getLocElement().getName())); }
From source file:org.gbif.ipt.task.Eml2Rtf.java
/** * Add authors section.//from w w w . j a v a 2s. c o m * * @param doc Document * @param eml EML * @throws DocumentException if problem occurs during add */ private void addAuthors(Document doc, Eml eml) throws DocumentException { // Creating set of authors with different names. (first names + last names). HashSet<Agent> tempAgents = new LinkedHashSet<Agent>(); if (exists(eml.getResourceCreator()) && exists(eml.getResourceCreator().getLastName())) { tempAgents.add(eml.getResourceCreator()); } if (exists(eml.getMetadataProvider()) && exists(eml.getMetadataProvider().getLastName())) { tempAgents.add(eml.getMetadataProvider()); } tempAgents.addAll(eml.getAssociatedParties()); // comparing and removing those repeated agents with same name and same address. Collection<Integer> toRemove = new ArrayList<Integer>(); int counter = 0; for (Iterator<Agent> i = tempAgents.iterator(); i.hasNext(); counter++) { if (toRemove.contains(counter)) { i.next(); i.remove(); } else { Agent agentA = i.next(); // when second iterator should be start boolean flag = false; int countTemp = 0; for (Iterator<Agent> j = tempAgents.iterator(); j.hasNext(); countTemp++) { Agent agentB = j.next(); if (flag) { if (equal(agentA.getLastName(), agentB.getLastName()) && equal(agentA.getFirstName(), agentB.getFirstName()) && equal(agentA.getAddress(), agentB.getAddress())) { toRemove.add(countTemp); } } else if (agentA.equals(agentB)) { flag = true; } } } } Agent[] agentsArray = new Agent[tempAgents.size()]; tempAgents.toArray(agentsArray); // Adding authors Paragraph p = new Paragraph(); p.setFont(font); p.setAlignment(Element.ALIGN_CENTER); java.util.List<Agent> affiliations = new ArrayList<Agent>(); int superScriptCounter = 1; for (int c = 0; c < agentsArray.length; c++) { if (exists(agentsArray[c].getLastName())) { if (c != 0) { p.add(", "); } // First Name and Last Name if (exists(agentsArray[c].getFirstName())) { p.add(agentsArray[c].getFirstName() + " "); } p.add(agentsArray[c].getLastName()); // Looking for addresses and organisations of other authors // (superscripts should not be repeated). boolean isRepeated = false; // look into the affiliations array to find any previous repeated agent info. for (int index = 0; index < affiliations.size(); index++) { if (equal(agentsArray[c].getAddress(), affiliations.get(index).getAddress()) && equal(agentsArray[c].getOrganisation(), affiliations.get(index).getOrganisation())) { p.add(createSuperScript(String.valueOf(index + 1))); isRepeated = true; break; } } // if the agent is not repeated. if (!isRepeated) { p.add(createSuperScript(String.valueOf(superScriptCounter))); affiliations.add(agentsArray[c]); superScriptCounter++; } } } doc.add(p); p.clear(); doc.add(Chunk.NEWLINE); tempAgents.clear(); // <AFFILIATIONS> p = new Paragraph(); p.setFont(font); p.setAlignment(Element.ALIGN_JUSTIFIED); for (int c = 0; c < affiliations.size(); c++) { if (c != 0) { p.add("; "); } p.add((c + 1) + " "); if (exists(affiliations.get(c).getOrganisation())) { p.add(affiliations.get(c).getOrganisation() + ", "); } if (exists(affiliations.get(c).getAddress().getAddress())) { p.add(affiliations.get(c).getAddress().getAddress() + ", "); } if (exists(affiliations.get(c).getAddress().getPostalCode())) { p.add(affiliations.get(c).getAddress().getPostalCode() + ", "); } if (exists(affiliations.get(c).getAddress().getCity())) { p.add(affiliations.get(c).getAddress().getCity()); } if (exists(affiliations.get(c).getAddress().getCountry())) { VocabularyConcept concept = vocabManager.get(Constants.VOCAB_URI_COUNTRY) .findConcept(affiliations.get(c).getAddress().getCountry()); // write country in default language as matched from vocabulary or original value if (exists(concept)) { p.add(", " + WordUtils.capitalizeFully(concept.getPreferredTerm(DEFAULT_LANGUAGE).getTitle())); } else { p.add(", " + WordUtils.capitalizeFully(affiliations.get(c).getAddress().getCountry())); } } } doc.add(p); p.clear(); doc.add(Chunk.NEWLINE); // <Corresponding Authors> p = new Paragraph(); p.setAlignment(Element.ALIGN_JUSTIFIED); p.add(new Phrase(getText("rtf.authors") + ": ", fontTitle)); p.setFont(font); boolean isFirst = true; if (exists(eml.getResourceCreator())) { if (exists(eml.getResourceCreator().getFirstName())) { p.add(eml.getResourceCreator().getFirstName() + " "); } p.add(eml.getResourceCreator().getLastName()); if (exists(eml.getResourceCreator().getEmail())) { p.add(" (" + eml.getResourceCreator().getEmail() + ")"); } isFirst = false; } if (exists(eml.getMetadataProvider())) { boolean sameAsCreator = false; if (!isFirst) { sameAsCreator = equal(eml.getMetadataProvider().getAddress(), eml.getResourceCreator().getAddress()) && equal(eml.getMetadataProvider().getEmail(), eml.getResourceCreator().getEmail()); } if (!sameAsCreator) { p.add(", "); if (exists(eml.getMetadataProvider().getFirstName())) { p.add(eml.getMetadataProvider().getFirstName() + " "); } p.add(eml.getMetadataProvider().getLastName()); if (exists(eml.getMetadataProvider().getEmail())) { p.add(" (" + eml.getMetadataProvider().getEmail() + ")"); } } } p.add(Chunk.NEWLINE); doc.add(p); p.clear(); }
From source file:at.tuwien.ifs.somtoolbox.apps.viewer.MapPNode.java
/** * Replaces currentClusteringElements with elements and makes sure the correct stuff is displayed. Also accepts null * -> just removes./*w ww . ja v a2 s . c o m*/ */ public void setClusteringElements(SortedMap<Integer, ClusterElementsStorage> elements) { // Remove all oldborders and labels if (currentClusteringElements != null) { HashSet<PNode> tmp = new HashSet<PNode>(); // use set to avoid duplicates (labels appearing on multiple // layers) for (ClusterElementsStorage n : currentClusteringElements.values()) { if (n.clusterBorders != null) { tmp.addAll(n.clusterBorders); } if (n.clusterLabels != null) { tmp.addAll(n.clusterLabels); } if (n.clusterColors != null) { tmp.addAll(n.clusterColors); } } this.removeChildren(tmp); } currentClusteringElements = elements; // show new elements if (elements != null) { for (ClusterElementsStorage n : currentClusteringElements.values()) { if (n.clusterBorders != null) { // System.out.println("Added border node " + n.border.hashCode() + " (" + n.hashCode() + ")"); for (PNode borderLine : n.clusterBorders) { addChild(borderLine); borderLine.moveToBack(); if (currentVisualizationImage != null) { borderLine.moveInFrontOf(currentVisualizationImage); } } } if (n.clusterLabels != null) { // System.out.println("Added label node " + n.labels.hashCode() + " (" + n.hashCode() + ")"); for (PNode label : n.clusterLabels) { addChild(label); label.moveToFront(); } } if (n.clusterColors != null) { for (PNode colorCluster : n.clusterColors) { addChild(colorCluster); colorCluster.moveToBack(); } } } } // System.out.println("Applied new clustering " + elements.hashCode()); }
From source file:com.datatorrent.stram.engine.StreamingContainer.java
public void teardown() { operateListeners(containerContext, false); deactivate();/*from ww w . j av a 2 s . c om*/ assert (streams.isEmpty()); eventBus.shutdown(); nodes.clear(); HashSet<WindowGenerator> gens = new HashSet<WindowGenerator>(); gens.addAll(generators.values()); generators.clear(); for (WindowGenerator wg : gens) { wg.teardown(); } if (bufferServer != null) { eventloop.stop(bufferServer); eventloop.stop(); } gens.clear(); }
From source file:org.hyperic.hq.authz.server.session.RoleManagerImpl.java
/** * List the roles that this subject is not in and that are not one of the * specified roles.//from w w w . j ava 2s .c o m * * @param whoami The current running user. * @param system If true, then only system roles are returned. If false, * then only non-system roles are returned. * @param subjectId The id of the subject. * @return List of roles. * @throws NotFoundException Unable to find a given or dependent entities. * @throws PermissionException whoami is not allowed to perform listRoles on * this role. * * */ @Transactional(readOnly = true) public PageList<RoleValue> getAvailableRoles(AuthzSubject whoami, boolean system, Integer subjectId, Integer[] roleIds, PageControl pc) throws PermissionException, NotFoundException { Collection<Role> foundRoles; pc = PageControl.initDefaults(pc, SortAttribute.ROLE_NAME); int attr = pc.getSortattribute(); switch (attr) { case SortAttribute.ROLE_NAME: foundRoles = roleDAO.findBySystemAndAvailableForSubject_orderName(system, whoami.getId(), !pc.isDescending()); break; default: throw new NotFoundException("Unrecognized sort attribute: " + attr); } HashSet<Integer> index = new HashSet<Integer>(); if (roleIds != null) { index.addAll(Arrays.asList(roleIds)); } Collection<Role> roles = new ArrayList<Role>(); for (Role r : foundRoles) { if (!index.contains(r.getId())) { roles.add(r); } } // AUTHZ Check // filter the viewable roles roles = filterViewableRoles(whoami, roles); PageList<RoleValue> plist = new PageList<RoleValue>(); plist = rolePager.seek(roles, pc.getPagenum(), pc.getPagesize()); plist.setTotalSize(roles.size()); // 6729 - if caller is a member of the root role, show it // 5345 - allow access to the root role by the root user so it can // be used by others if (isRootRoleMember(whoami) && pc.getPagenum() == 0 && !index.contains(AuthzConstants.rootRoleId)) { Role role = roleDAO.findAvailableRoleForSubject(AuthzConstants.rootRoleId, subjectId); if (role == null) { return plist; } OwnedRoleValue rootRoleValue = role.getOwnedRoleValue(); PageList<RoleValue> newList = new PageList<RoleValue>(); newList.add(rootRoleValue); newList.addAll(plist); newList.setTotalSize(plist.getTotalSize() + 1); return newList; } return plist; }