List of usage examples for com.google.common.collect Sets union
public static <E> SetView<E> union(final Set<? extends E> set1, final Set<? extends E> set2)
From source file:org.sosy_lab.cpachecker.cfa.ast.c.FileLocationCollectingVisitor.java
@Override public Set<FileLocation> visit(CArrayRangeDesignator pNode) throws RuntimeException { Set<FileLocation> result = Collections.singleton(pNode.getFileLocation()); if (pNode.getCeilExpression() != null) { result = Sets.union(result, pNode.getCeilExpression().accept(this)); }// w w w. j a v a 2 s . c om if (pNode.getFloorExpression() != null) { result = Sets.union(result, pNode.getFloorExpression().accept(this)); } return result; }
From source file:com.intelligentsia.dowsers.entity.meta.MetaEntityContext.java
/** * @return all attributes names. */ public SetView<String> attributeNames() { return Sets.union(definitionAttributeNames, extendedAttributeNames); }
From source file:org.terasology.rendering.nui.skin.UISkinBuilder.java
private UIStyleFamily buildFamily(String family, UISkin skin) { UIStyleFamily baseFamily = skin.getFamily(family); UIStyle baseStyle = new UIStyle(skin.getDefaultStyleFor(family)); if (!family.isEmpty()) { UIStyleFragment fragment = baseStyles.get(family); fragment.applyTo(baseStyle);/* w w w . j a va 2 s .c o m*/ } Set<StyleKey> inheritedStyleKey = Sets.newLinkedHashSet(); for (Class<? extends UIWidget> widget : baseFamily.getWidgets()) { inheritedStyleKey.add(new StyleKey(widget, "", "")); for (String part : baseFamily.getPartsFor(widget)) { inheritedStyleKey.add(new StyleKey(widget, part, "")); for (String mode : baseFamily.getModesFor(widget, part)) { inheritedStyleKey.add(new StyleKey(widget, part, mode)); } } } Map<Class<? extends UIWidget>, Table<String, String, UIStyle>> familyStyles = Maps.newHashMap(); Map<StyleKey, UIStyleFragment> styleLookup = elementStyles.row(family); Map<StyleKey, UIStyleFragment> baseStyleLookup = (family.isEmpty()) ? Maps.<StyleKey, UIStyleFragment>newHashMap() : elementStyles.row(""); for (StyleKey styleKey : Sets.union(Sets.union(styleLookup.keySet(), baseStyleKeys), inheritedStyleKey)) { UIStyle elementStyle = new UIStyle( baseSkin.getStyleFor(family, styleKey.element, styleKey.part, styleKey.mode)); baseStyles.get("").applyTo(elementStyle); baseStyles.get(family).applyTo(elementStyle); List<Class<? extends UIWidget>> inheritanceTree = ReflectionUtil.getInheritanceTree(styleKey.element, UIWidget.class); applyStylesForInheritanceTree(inheritanceTree, "", "", elementStyle, styleLookup, baseStyleLookup); if (!styleKey.part.isEmpty()) { applyStylesForInheritanceTree(inheritanceTree, styleKey.part, "", elementStyle, styleLookup, baseStyleLookup); } if (!styleKey.mode.isEmpty()) { applyStylesForInheritanceTree(inheritanceTree, styleKey.part, styleKey.mode, elementStyle, styleLookup, baseStyleLookup); } Table<String, String, UIStyle> elementTable = familyStyles.get(styleKey.element); if (elementTable == null) { elementTable = HashBasedTable.create(); familyStyles.put(styleKey.element, elementTable); } elementTable.put(styleKey.part, styleKey.mode, elementStyle); } return new UIStyleFamily(baseStyle, familyStyles); }
From source file:org.grycap.gpf4med.reflect.AsyncHandler.java
private Object mergeResults(final List<Object> results) { Object merged = null;//from w w w . ja v a2s . c o m if (results != null && !results.isEmpty()) { if (results.size() == 1) { merged = results.get(0); } else { final Class<?> resultType = results.get(0).getClass(); if (Byte.class.equals(resultType)) { byte total = 0; for (final Object item : results) { total += ((Byte) item).byteValue(); } merged = (Byte) total; } else if (Short.class.equals(resultType)) { short total = 0; for (final Object item : results) { total += ((Short) item).shortValue(); } merged = (Short) total; } else if (Integer.class.equals(resultType)) { int total = 0; for (final Object item : results) { total += ((Integer) item).intValue(); } merged = (Integer) total; } else if (Long.class.equals(resultType)) { long total = 0l; for (final Object item : results) { total += ((Long) item).longValue(); } merged = (Long) total; } else if (Float.class.equals(resultType)) { float total = 0.0f; for (final Object item : results) { total += ((Float) item).floatValue(); } merged = (Float) total; } else if (Double.class.equals(resultType)) { double total = 0.0d; for (final Object item : results) { total += ((Double) item).doubleValue(); } merged = (Double) total; } else if (resultType.isAssignableFrom(List.class)) { List<?> list = Lists.newArrayList(); for (final Object item : results) { list = (List<?>) Iterables.concat(list, (List<?>) item); } merged = list; } else if (resultType.isAssignableFrom(Map.class)) { Map<?, ?> map = Maps.newHashMap(); for (final Object item : results) { map = (Map<?, ?>) Sets.union(map.entrySet(), ((Map<?, ?>) item).entrySet()); } merged = map; } else { throw new UnsupportedOperationException( "Cannot merge the type: " + resultType.getCanonicalName()); } } } return merged; }
From source file:com.b2international.snowowl.datastore.server.snomed.merge.rules.SnomedRefsetMemberReferencingDetachedComponentRule.java
@Override public Collection<MergeConflict> validate(CDOTransaction transaction) { List<MergeConflict> conflicts = newArrayList(); // If SNOMED CT components were detached on target, but SNOMED CT reference set members are referencing them on source branch: Map<String, String> idToComponentTypeMap = newHashMap(); for (Component component : getDetachedObjects(transaction, Component.class)) { idToComponentTypeMap.put(component.getId(), component.eClass().getName()); }//from w w w .j a v a 2 s . c o m if (!idToComponentTypeMap.isEmpty()) { // if there was any detached Component on target branch final Set<String> detachedMemberIds = FluentIterable .from(getDetachedObjects(transaction, SnomedRefSetMember.class)) .transform(MEMBER_TO_ID_FUNCTION).toSet(); final SnomedReferenceSetMembers membersReferencingDetachedComponents = SnomedRequests .prepareSearchMember().filterByReferencedComponent(idToComponentTypeMap.keySet()).all() .build(SnomedDatastoreActivator.REPOSITORY_UUID, BranchPathUtils.createPath(transaction).getPath()) .execute(getEventBus()).getSync(); for (SnomedReferenceSetMember member : membersReferencingDetachedComponents) { if (!detachedMemberIds.contains(member.getId())) { conflicts.add(MergeConflictImpl.builder().componentId(member.getReferencedComponent().getId()) .componentType(idToComponentTypeMap.get(member.getReferencedComponent().getId())) .type(ConflictType.CAUSES_MISSING_REFERENCE).build()); } } } // If SNOMED CT components were detached on source, but SNOMED CT reference set members are referencing them on target: Multimap<String, Pair<String, String>> referencedComponentIdToRefsetMemberMap = HashMultimap .<String, Pair<String, String>>create(); for (SnomedRefSetMember member : getNewObjects(transaction, SnomedRefSetMember.class)) { referencedComponentIdToRefsetMemberMap.put(member.getReferencedComponentId(), Pair.<String, String>of(member.eClass().getName(), member.getUuid())); } if (!referencedComponentIdToRefsetMemberMap.isEmpty()) { // if there was any new reference set member on target Set<String> conceptIds = newHashSet(FluentIterable.from(getNewObjects(transaction, Concept.class)) .transform(COMPONENT_TO_ID_FUNCTION).toSet()); Set<String> descriptionIds = newHashSet( FluentIterable.from(getNewObjects(transaction, Description.class)) .transform(COMPONENT_TO_ID_FUNCTION).toSet()); Set<String> relationshipIds = newHashSet( FluentIterable.from(getNewObjects(transaction, Relationship.class)) .transform(COMPONENT_TO_ID_FUNCTION).toSet()); String branchPath = BranchPathUtils.createPath(transaction).getPath(); Set<String> referencedComponentIds = referencedComponentIdToRefsetMemberMap.keySet(); Set<String> referencedConceptIds = referencedComponentIds.stream() .filter(id -> SnomedIdentifiers.getComponentCategory(id) == ComponentCategory.CONCEPT) .collect(toSet()); Set<String> referencedRelationshipIds = referencedComponentIds.stream() .filter(id -> SnomedIdentifiers.getComponentCategory(id) == ComponentCategory.RELATIONSHIP) .collect(toSet()); Set<String> referencedDescriptionIds = referencedComponentIds.stream() .filter(id -> SnomedIdentifiers.getComponentCategory(id) == ComponentCategory.DESCRIPTION) .collect(toSet()); if (!referencedConceptIds.isEmpty()) { conceptIds .addAll(FluentIterable .from(SnomedRequests.prepareSearchConcept().filterByIds(referencedConceptIds) .setLimit(referencedConceptIds.size()) .build(SnomedDatastoreActivator.REPOSITORY_UUID, branchPath) .execute(getEventBus()).getSync()) .transform(IComponent.ID_FUNCTION).toSet()); } if (!referencedDescriptionIds.isEmpty()) { descriptionIds.addAll(FluentIterable.from(SnomedRequests.prepareSearchDescription() .filterByIds(referencedDescriptionIds).setLimit(referencedDescriptionIds.size()) .build(SnomedDatastoreActivator.REPOSITORY_UUID, branchPath).execute(getEventBus()) .getSync()).transform(IComponent.ID_FUNCTION).toSet()); } if (!referencedRelationshipIds.isEmpty()) { relationshipIds.addAll(FluentIterable.from(SnomedRequests.prepareSearchRelationship() .filterByIds(referencedRelationshipIds).setLimit(referencedRelationshipIds.size()) .build(SnomedDatastoreActivator.REPOSITORY_UUID, branchPath).execute(getEventBus()) .getSync()).transform(IComponent.ID_FUNCTION).toSet()); } Set<String> missingConceptIds = Sets.difference(referencedComponentIds, Sets.union(Sets.union(conceptIds, descriptionIds), relationshipIds)); for (String id : missingConceptIds) { for (Pair<String, String> entry : referencedComponentIdToRefsetMemberMap.get(id)) { conflicts .add(MergeConflictImpl.builder().componentId(entry.getB()).componentType(entry.getA()) .conflictingAttribute(ConflictingAttributeImpl.builder() .property("referencedComponent").value(id).build()) .type(ConflictType.HAS_MISSING_REFERENCE).build()); } } } return conflicts; }
From source file:org.n52.sos.ogc.ows.SosServiceIdentificationFactory.java
public Set<Locale> getAvailableLocales() { if (this.title == null) { if (this.abstrakt == null) { return Collections.emptySet(); } else {// w ww. ja v a 2s. c o m return this.abstrakt.getLocales(); } } else { if (this.abstrakt == null) { return this.title.getLocales(); } else { return Sets.union(this.title.getLocales(), this.abstrakt.getLocales()); } } }
From source file:ezbake.groups.service.CachingEzGroupsService.java
/** * Change which permissions are inherited from the parent to the given group * * This must also update caches for members who were members of the group, or are now members of it * * @param ezSecurityToken security token to validate query * @param groupName name of group who's inheritance to change * @param inheritance new inheritance permissions * @throws EzSecurityTokenException/*from w w w . j a v a 2 s .com*/ * @throws AuthorizationException * @throws EzGroupOperationException */ @Override public void changeGroupInheritance(EzSecurityToken ezSecurityToken, String groupName, GroupInheritancePermissions inheritance) throws EzSecurityTokenException, AuthorizationException, EzGroupOperationException { // Get group members before changing inheritance. These are the users who's caches need to be updated Set<User> oldMembers; try { oldMembers = getGroupMembers(groupName); } catch (VertexNotFoundException e) { logger.error("Failed to get group members, unable to change group inheritance. Group Name: {}", groupName); throw new EzGroupOperationException("Unable to get group members", OperationError.UNRECOVERABLE_ERROR); } // update inheritance impl.changeGroupInheritance(ezSecurityToken, groupName, inheritance); Set<User> newMembers; try { newMembers = getGroupMembers(groupName); } catch (VertexNotFoundException e) { logger.error("Failed to get group members, unable to change group inheritance. Group Name: {}", groupName); throw new EzGroupOperationException("Unable to get group members", OperationError.UNRECOVERABLE_ERROR); } // Rebuild cache for members markCacheNeedsUpdateForGroupMembers(Sets.union(oldMembers, newMembers)); }
From source file:org.eclipse.emf.compare.internal.merge.MergeDependenciesUtil.java
/** * Returns the set of all differences <b>directly</b> related to the given one, either as dependencies or * as implications./*from w w w . j a v a 2 s . c o m*/ * * @param diff * The difference for which we seek all directly related others. * @param mergerRegistry * The {@link IMerger.Registry merger registry} currently in use. * @param mergeRightToLeft * The direction in which we're considering a merge. * @param originalSource * The original side of the diff the dependencies of which we are computing * @return The set of all differences <b>directly</b> related to the given one. */ private static Set<Diff> internalGetResultingMerges(Diff diff, IMerger.Registry mergerRegistry, boolean mergeRightToLeft, DifferenceSource originalSource) { final IMerger merger = mergerRegistry.getHighestRankingMerger(diff); // If a (pseudo-)conflict makes use merge diffs from the other side, // we must then look for the consequences of these diffs // as if they had been merged the other way around. final boolean direction; if (diff.getSource() == originalSource) { direction = mergeRightToLeft; } else { direction = !mergeRightToLeft; } final Set<Diff> directParents; final Set<Diff> directImplications; if (merger instanceof IMerger2) { directParents = ((IMerger2) merger).getDirectMergeDependencies(diff, direction); directImplications = ((IMerger2) merger).getDirectResultingMerges(diff, direction); } else { directParents = Collections.emptySet(); directImplications = Collections.emptySet(); } // FIXME [PERF] Useless copy final LinkedHashSet<Diff> directRelated = Sets .newLinkedHashSet(Sets.union(directParents, directImplications)); if (merger instanceof IMergeOptionAware) { Object subDiffs = ((IMergeOptionAware) merger).getMergeOptions() .get(AbstractMerger.SUB_DIFF_AWARE_OPTION); if (subDiffs == Boolean.TRUE) { addAll(directRelated, ComparisonUtil.getSubDiffs(!direction).apply(diff)); } } return directRelated; }
From source file:org.apache.ctakes.temporal.eval.EvaluationOfEventEventRelations.java
@Override protected AnnotationStatistics<String> test(CollectionReader collectionReader, File directory) throws Exception { AggregateBuilder aggregateBuilder = this.getPreprocessorAggregateBuilder(); aggregateBuilder.add(CopyFromGold.getDescription(EventMention.class, TimeMention.class)); // aggregateBuilder.add(AnalysisEngineFactory.createEngineDescription(MergeContainsOverlap.class, // MergeContainsOverlap.PARAM_RELATION_VIEW, // GOLD_VIEW_NAME)); aggregateBuilder.add(AnalysisEngineFactory.createEngineDescription(RemoveNonContainsRelations.class), CAS.NAME_DEFAULT_SOFA, GOLD_VIEW_NAME); aggregateBuilder.add(AnalysisEngineFactory.createEngineDescription(RemoveCrossSentenceRelations.class, RemoveCrossSentenceRelations.PARAM_SENTENCE_VIEW, CAS.NAME_DEFAULT_SOFA, RemoveCrossSentenceRelations.PARAM_RELATION_VIEW, GOLD_VIEW_NAME)); // TODO - use if relevant. // if (this.useClosure) { // aggregateBuilder.add( // AnalysisEngineFactory.createEngineDescription(AddTransitiveContainsRelations.class), // CAS.NAME_DEFAULT_SOFA, // GOLD_VIEW_NAME); // }/* w w w .j a va 2s. c o m*/ aggregateBuilder.add(AnalysisEngineFactory.createEngineDescription(PreserveEventEventRelations.class), CAS.NAME_DEFAULT_SOFA, GOLD_VIEW_NAME); aggregateBuilder.add(AnalysisEngineFactory.createEngineDescription(RemoveRelations.class)); aggregateBuilder.add(EventEventRelationAnnotator.createAnnotatorDescription(directory)); Function<BinaryTextRelation, ?> getSpan = new Function<BinaryTextRelation, HashableArguments>() { public HashableArguments apply(BinaryTextRelation relation) { return new HashableArguments(relation); } }; Function<BinaryTextRelation, String> getOutcome = AnnotationStatistics.annotationToFeatureValue("category"); AnnotationStatistics<String> stats = new AnnotationStatistics<String>(); for (Iterator<JCas> casIter = new JCasIterator(collectionReader, aggregateBuilder.createAggregate()); casIter.hasNext();) { JCas jCas = casIter.next(); JCas goldView = jCas.getView(GOLD_VIEW_NAME); JCas systemView = jCas.getView(CAS.NAME_DEFAULT_SOFA); Collection<BinaryTextRelation> goldRelations = JCasUtil.select(goldView, BinaryTextRelation.class); Collection<BinaryTextRelation> systemRelations = JCasUtil.select(systemView, BinaryTextRelation.class); stats.add(goldRelations, systemRelations, getSpan, getOutcome); if (this.printRelations) { URI uri = ViewUriUtil.getURI(jCas); String[] path = uri.getPath().split("/"); printRelationAnnotations(path[path.length - 1], systemRelations); } if (this.printErrors) { Map<HashableArguments, BinaryTextRelation> goldMap = Maps.newHashMap(); for (BinaryTextRelation relation : goldRelations) { goldMap.put(new HashableArguments(relation), relation); } Map<HashableArguments, BinaryTextRelation> systemMap = Maps.newHashMap(); for (BinaryTextRelation relation : systemRelations) { systemMap.put(new HashableArguments(relation), relation); } Set<HashableArguments> all = Sets.union(goldMap.keySet(), systemMap.keySet()); List<HashableArguments> sorted = Lists.newArrayList(all); Collections.sort(sorted); for (HashableArguments key : sorted) { BinaryTextRelation goldRelation = goldMap.get(key); BinaryTextRelation systemRelation = systemMap.get(key); if (goldRelation == null) { System.out.println("System added: " + formatRelation(systemRelation)); } else if (systemRelation == null) { System.out.println("System dropped: " + formatRelation(goldRelation)); } else if (!systemRelation.getCategory().equals(goldRelation.getCategory())) { String label = systemRelation.getCategory(); System.out.printf("System labeled %s for %s\n", label, formatRelation(goldRelation)); } else { System.out.println("Nailed it! " + formatRelation(systemRelation)); } } } } return stats; }
From source file:fr.aliacom.obm.common.contact.AddressBookBindingImpl.java
private Set<Integer> getRemovedContacts(ContactUpdates contactUpdates, ContactUpdates userUpdates, Set<Integer> removalCandidates) { SetView<Integer> archived = Sets.union(contactUpdates.getArchived(), userUpdates.getArchived()); return Sets.union(archived, removalCandidates); }