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.terasology.rendering.nui.skin.UISkinBuilder.java
private UIStyleFamily buildFamily(String family, UIStyle defaultStyle) { UIStyle baseStyle = new UIStyle(defaultStyle); if (!family.isEmpty()) { UIStyleFragment fragment = baseStyles.get(family); fragment.applyTo(baseStyle);// w ww . j a v a 2 s . com } 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(styleLookup.keySet(), baseStyleKeys)) { UIStyle elementStyle = new UIStyle(baseStyle); 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.jboss.weld.annotated.enhanced.jlr.EnhancedAnnotatedTypeImpl.java
protected EnhancedAnnotatedTypeImpl(SlimAnnotatedType<T> annotatedType, Map<Class<? extends Annotation>, Annotation> annotationMap, Map<Class<? extends Annotation>, Annotation> declaredAnnotationMap, ClassTransformer classTransformer) { super(annotatedType, annotationMap, declaredAnnotationMap, classTransformer); this.slim = annotatedType; discovered = annotatedType instanceof BackedAnnotatedType<?>; if (discovered) { Class<? super T> superclass = annotatedType.getJavaClass().getSuperclass(); if (superclass == null) { this.superclass = null; } else {/*from w w w .j a v a2 s. co m*/ this.superclass = classTransformer.getEnhancedAnnotatedType(superclass, slim.getIdentifier().getBdaId()); } } else { this.superclass = classTransformer.getEnhancedAnnotatedType(Object.class, AnnotatedTypeIdentifier.NULL_BDA_ID); } // Assign class field information this.declaredAnnotatedFields = ArrayListMultimap .<Class<? extends Annotation>, EnhancedAnnotatedField<?, ? super T>>create(); Set<EnhancedAnnotatedField<?, ? super T>> fieldsTemp = null; ArrayList<EnhancedAnnotatedField<?, ? super T>> declaredFieldsTemp = new ArrayList<EnhancedAnnotatedField<?, ? super T>>(); Class<T> javaClass = annotatedType.getJavaClass(); if (discovered) { this.annotatedFields = null; if (javaClass != Object.class) { for (AnnotatedField<? super T> field : annotatedType.getFields()) { if (field.getJavaMember().getDeclaringClass().equals(javaClass)) { EnhancedAnnotatedField<?, ? super T> annotatedField = EnhancedAnnotatedFieldImpl.of(field, this, classTransformer); declaredFieldsTemp.add(annotatedField); for (Annotation annotation : annotatedField.getAnnotations()) { this.declaredAnnotatedFields.put(annotation.annotationType(), annotatedField); } } } fieldsTemp = new ArraySet<EnhancedAnnotatedField<?, ? super T>>(declaredFieldsTemp).trimToSize(); if ((superclass != null) && (superclass.getJavaClass() != Object.class)) { fieldsTemp = Sets.union(fieldsTemp, Reflections.<Set<EnhancedAnnotatedField<?, ? super T>>>cast(superclass.getFields())); } } this.declaredFields = new ArraySet<EnhancedAnnotatedField<?, ? super T>>(declaredFieldsTemp); } else { this.annotatedFields = ArrayListMultimap .<Class<? extends Annotation>, EnhancedAnnotatedField<?, ?>>create(); fieldsTemp = new HashSet<EnhancedAnnotatedField<?, ? super T>>(); for (AnnotatedField<? super T> annotatedField : annotatedType.getFields()) { EnhancedAnnotatedField<?, ? super T> weldField = EnhancedAnnotatedFieldImpl.of(annotatedField, this, classTransformer); fieldsTemp.add(weldField); if (annotatedField.getDeclaringType().getJavaClass().equals(javaClass)) { declaredFieldsTemp.add(weldField); } for (Annotation annotation : weldField.getAnnotations()) { this.annotatedFields.put(annotation.annotationType(), weldField); if (annotatedField.getDeclaringType().getJavaClass().equals(javaClass)) { this.declaredAnnotatedFields.put(annotation.annotationType(), weldField); } } } this.declaredFields = new ArraySet<EnhancedAnnotatedField<?, ? super T>>(declaredFieldsTemp); fieldsTemp = new ArraySet<EnhancedAnnotatedField<?, ? super T>>(fieldsTemp).trimToSize(); this.annotatedFields.trimToSize(); } this.fields = fieldsTemp; this.declaredFields.trimToSize(); this.declaredAnnotatedFields.trimToSize(); // Assign constructor information this.constructors = new ArraySet<EnhancedAnnotatedConstructor<T>>(); this.declaredConstructorsBySignature = new HashMap<ConstructorSignature, EnhancedAnnotatedConstructor<?>>(); for (AnnotatedConstructor<T> constructor : annotatedType.getConstructors()) { EnhancedAnnotatedConstructor<T> weldConstructor = EnhancedAnnotatedConstructorImpl.of(constructor, this, classTransformer); this.constructors.add(weldConstructor); this.declaredConstructorsBySignature.put(weldConstructor.getSignature(), weldConstructor); } this.constructors.trimToSize(); // Assign method information this.declaredAnnotatedMethods = ArrayListMultimap .<Class<? extends Annotation>, EnhancedAnnotatedMethod<?, ? super T>>create(); this.declaredMethodsByAnnotatedParameters = ArrayListMultimap .<Class<? extends Annotation>, EnhancedAnnotatedMethod<?, ? super T>>create(); Set<EnhancedAnnotatedMethod<?, ? super T>> methodsTemp = new HashSet<EnhancedAnnotatedMethod<?, ? super T>>(); ArrayList<EnhancedAnnotatedMethod<?, ? super T>> declaredMethodsTemp = new ArrayList<EnhancedAnnotatedMethod<?, ? super T>>(); if (discovered) { if (!(javaClass.equals(Object.class))) { for (AnnotatedMethod<? super T> method : annotatedType.getMethods()) { if (method.getJavaMember().getDeclaringClass().equals(javaClass)) { EnhancedAnnotatedMethod<?, ? super T> weldMethod = EnhancedAnnotatedMethodImpl.of(method, this, classTransformer); declaredMethodsTemp.add(weldMethod); for (Annotation annotation : weldMethod.getAnnotations()) { this.declaredAnnotatedMethods.put(annotation.annotationType(), weldMethod); } for (Class<? extends Annotation> annotationType : MAPPED_DECLARED_METHOD_PARAMETER_ANNOTATIONS) { if (weldMethod.getEnhancedParameters(annotationType).size() > 0) { this.declaredMethodsByAnnotatedParameters.put(annotationType, weldMethod); } } } } methodsTemp.addAll(declaredMethodsTemp); if (superclass != null) { EnhancedAnnotatedType<?> current = superclass; while (current.getJavaClass() != Object.class) { Set<EnhancedAnnotatedMethod<?, ? super T>> superClassMethods = Reflections .cast(current.getDeclaredEnhancedMethods()); methodsTemp.addAll(superClassMethods); current = current.getEnhancedSuperclass(); } } } this.declaredMethods = new ArraySet<EnhancedAnnotatedMethod<?, ? super T>>(declaredMethodsTemp); } else { for (AnnotatedMethod<? super T> method : annotatedType.getMethods()) { EnhancedAnnotatedMethod<?, ? super T> enhancedMethod = EnhancedAnnotatedMethodImpl.of(method, this, classTransformer); methodsTemp.add(enhancedMethod); if (method.getJavaMember().getDeclaringClass().equals(javaClass)) { declaredMethodsTemp.add(enhancedMethod); } for (Annotation annotation : enhancedMethod.getAnnotations()) { if (method.getJavaMember().getDeclaringClass().equals(javaClass)) { this.declaredAnnotatedMethods.put(annotation.annotationType(), enhancedMethod); } } for (Class<? extends Annotation> annotationType : MAPPED_DECLARED_METHOD_PARAMETER_ANNOTATIONS) { if (enhancedMethod.getEnhancedParameters(annotationType).size() > 0) { if (method.getJavaMember().getDeclaringClass().equals(javaClass)) { this.declaredMethodsByAnnotatedParameters.put(annotationType, enhancedMethod); } } } } this.declaredMethods = new ArraySet<EnhancedAnnotatedMethod<?, ? super T>>(declaredMethodsTemp); } this.declaredMethods.trimToSize(); this.declaredAnnotatedMethods.trimToSize(); this.declaredMethodsByAnnotatedParameters.trimToSize(); ArraySetMultimap<Class<? extends Annotation>, Annotation> declaredMetaAnnotationMap = new ArraySetMultimap<Class<? extends Annotation>, Annotation>(); for (Annotation declaredAnnotation : declaredAnnotationMap.values()) { // WELD-1310 Include synthetic annotations SlimAnnotatedType<?> syntheticAnnotationAnnotatedType = classTransformer .getSyntheticAnnotationAnnotatedType(declaredAnnotation.annotationType()); if (syntheticAnnotationAnnotatedType == null) { addMetaAnnotations(declaredMetaAnnotationMap, declaredAnnotation, classTransformer.getReflectionCache().getAnnotations(declaredAnnotation.annotationType()), true); } else { addMetaAnnotations(declaredMetaAnnotationMap, declaredAnnotation, syntheticAnnotationAnnotatedType.getAnnotations(), true); } addMetaAnnotations(declaredMetaAnnotationMap, declaredAnnotation, classTransformer.getTypeStore().get(declaredAnnotation.annotationType()), true); declaredMetaAnnotationMap.putSingleElement(declaredAnnotation.annotationType(), declaredAnnotation); } this.declaredMetaAnnotationMap = immutableMap(declaredMetaAnnotationMap); this.overriddenMethods = getOverriddenMethods(this, methodsTemp); // WELD-1548 remove all overriden methods except for those which are overriden by a bridge method methodsTemp.removeAll(getOverriddenMethods(this, methodsTemp, true)); this.methods = methodsTemp; this.annotatedMethods = buildAnnotatedMethodMultimap(this.methods); this.annotatedMethodsByAnnotatedParameters = buildAnnotatedParameterMethodMultimap(this.methods); }
From source file:com.yahoo.pulsar.broker.admin.PersistentTopics.java
@GET @Path("/{property}/{cluster}/{namespace}/{destination}/permissions") @ApiOperation(value = "Get permissions on a destination.", notes = "Retrieve the effective permissions for a destination. These permissions are defined by the permissions set at the" + "namespace level combined (union) with any eventual specific permission set on the destination.") @ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Namespace doesn't exist") }) public Map<String, Set<AuthAction>> getPermissionsOnDestination(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace, @PathParam("destination") @Encoded String destination) { // This operation should be reading from zookeeper and it should be allowed without having admin privileges destination = decode(destination);//ww w .j a v a2 s.c o m validateAdminAccessOnProperty(property); String destinationUri = DestinationName.get(domain(), property, cluster, namespace, destination).toString(); try { Policies policies = policiesCache().get(path("policies", property, cluster, namespace)) .orElseThrow(() -> new RestException(Status.NOT_FOUND, "Namespace does not exist")); Map<String, Set<AuthAction>> permissions = Maps.newTreeMap(); AuthPolicies auth = policies.auth_policies; // First add namespace level permissions for (String role : auth.namespace_auth.keySet()) { permissions.put(role, auth.namespace_auth.get(role)); } // Then add destination level permissions if (auth.destination_auth.containsKey(destinationUri)) { for (Map.Entry<String, Set<AuthAction>> entry : auth.destination_auth.get(destinationUri) .entrySet()) { String role = entry.getKey(); Set<AuthAction> destinationPermissions = entry.getValue(); if (!permissions.containsKey(role)) { permissions.put(role, destinationPermissions); } else { // Do the union between namespace and destination level Set<AuthAction> union = Sets.union(permissions.get(role), destinationPermissions); permissions.put(role, union); } } } return permissions; } catch (Exception e) { log.error("[{}] Failed to get permissions for destination {}", clientAppId(), destinationUri, e); throw new RestException(e); } }
From source file:org.erlide.ui.editors.erl.completion.ErlContentAssistProcessor.java
public ICompletionProposal[] computeCompletionProposals(final ITextViewer viewer, final int offset) { if (module == null) { return null; }// w ww . j a v a 2 s . co m try { final IDocument doc = viewer.getDocument(); String before = getBefore(viewer, doc, offset); final int commaPos = before.lastIndexOf(','); final int colonPos = before.lastIndexOf(':'); final int hashMarkPos = before.lastIndexOf('#'); final int dotPos = before.lastIndexOf('.'); final int parenPos = before.lastIndexOf('('); final int leftBracketPos = before.lastIndexOf('{'); final int interrogationMarkPos = before.lastIndexOf('?'); final String prefix = getPrefix(before); List<String> fieldsSoFar = null; List<ICompletionProposal> result; Set<Kinds> flags; int pos; String moduleOrRecord = null; final IErlProject erlProject = module.getProject(); final IProject project = erlProject != null ? erlProject.getWorkspaceProject() : null; final IErlElement element = getElementAt(offset); RecordCompletion rc = null; if (hashMarkPos >= 0) { rc = ErlideContextAssist.checkRecordCompletion(CoreUtil.getBuildOrIdeBackend(project), before); } if (rc != null && rc.isNameWanted()) { flags = EnumSet.of(Kinds.RECORD_DEFS); pos = hashMarkPos; before = rc.getPrefix(); } else if (rc != null && rc.isFieldWanted()) { flags = EnumSet.of(Kinds.RECORD_FIELDS); pos = hashMarkPos; if (dotPos > hashMarkPos) { pos = dotPos; } else if (leftBracketPos > hashMarkPos) { pos = leftBracketPos; } else { assert false; } before = rc.getPrefix(); moduleOrRecord = rc.getName(); fieldsSoFar = rc.getFields(); } else if (colonPos > commaPos && colonPos > parenPos) { moduleOrRecord = StringUtils.unquote(getPrefix(before.substring(0, colonPos))); flags = EnumSet.of(Kinds.EXTERNAL_FUNCTIONS); pos = colonPos; before = before.substring(colonPos + 1); } else if (interrogationMarkPos > hashMarkPos && interrogationMarkPos > commaPos && interrogationMarkPos > colonPos) { flags = EnumSet.of(Kinds.MACRO_DEFS); pos = interrogationMarkPos; before = before.substring(interrogationMarkPos + 1); } else { // TODO add more contexts... pos = colonPos; before = prefix; if (element != null) { if (element.getKind() == IErlElement.Kind.EXPORT) { flags = EnumSet.of(Kinds.DECLARED_FUNCTIONS, Kinds.ARITY_ONLY, Kinds.UNEXPORTED_ONLY); } else if (element.getKind() == IErlElement.Kind.IMPORT) { final IErlImport i = (IErlImport) element; moduleOrRecord = i.getImportModule(); flags = EnumSet.of(Kinds.EXTERNAL_FUNCTIONS, Kinds.ARITY_ONLY); } else if (element.getKind() == IErlElement.Kind.FUNCTION || element.getKind() == IErlElement.Kind.CLAUSE) { flags = EnumSet.of(Kinds.MODULES); if (module != null) { flags = Sets.union(flags, EnumSet.of(Kinds.VARIABLES, Kinds.DECLARED_FUNCTIONS, Kinds.IMPORTED_FUNCTIONS, Kinds.AUTO_IMPORTED_FUNCTIONS)); } } else { flags = EnumSet.noneOf(Kinds.class); } } else { flags = EnumSet.noneOf(Kinds.class); } } result = addCompletions(flags, offset, before, moduleOrRecord, pos, fieldsSoFar, erlProject, project); final ErlTemplateCompletionProcessor t = new ErlTemplateCompletionProcessor(doc, offset - before.length(), before.length()); result.addAll(Arrays.asList(t.computeCompletionProposals(viewer, offset))); return result.toArray(new ICompletionProposal[result.size()]); } catch (final Exception e) { ErlLogger.warn(e); return null; } }
From source file:com.davidbracewell.reflection.Reflect.java
/** * Gets constructors.//from w w w . j a v a 2 s . com * * @return The set of constructors for the object which is a combination of * and * if <code>allowPrivilegedAccess</code> * was called. */ public Set<Constructor<?>> getConstructors() { return Sets.union(Sets.newHashSet(clazz.getConstructors()), (accessAll ? Sets.newHashSet(clazz.getDeclaredConstructors()) : Collections.<Constructor<?>>emptySet())); }
From source file:org.metaservice.core.provider.ProviderDispatcher.java
/** * this is a long running and heap intensive method. therefore, collections are explicitly nulled when not used any more * @param archiveAddress/*from w ww .ja va 2 s . c om*/ * @param oldMetadata */ private void refreshEntry(ArchiveAddress archiveAddress, @NotNull Set<URI> oldMetadata) { Archive archive = getArchive(archiveAddress.getArchiveUri()); if (archive == null) { return; } try { LOGGER.info("Starting to process " + archiveAddress); Archive.Contents contents = archive.getContent(archiveAddress.getTime(), archiveAddress.getPath()); if (contents == null) { LOGGER.warn("Cannot process content of address {}, skipping.", archiveAddress); return; } List<Statement> nowGeneratedStatements; List<Statement> prevGeneratedStatements; if (contents.now == null) { nowGeneratedStatements = new ArrayList<>(); } else { nowGeneratedStatements = getStatements(contents.now, archiveAddress); } //let gc collect contents.now contents.now = null; if (contents.prev == null) { prevGeneratedStatements = new ArrayList<>(); } else { prevGeneratedStatements = getStatements(contents.prev, archiveAddress); } //let gc collect rest of contents contents = null; LOGGER.debug("finished parsing"); URI metadataAdd = generateMetadata(archiveAddress, repositoryConnection, METASERVICE.ADD_OBSERVATION); URI metadataRemove = generateMetadata(archiveAddress, repositoryConnection, METASERVICE.REMOVE_OBSERVATION); HashSet<Statement> nowSet = new HashSet<>(); nowSet.addAll(nowGeneratedStatements); //noinspection UnusedAssignment nowGeneratedStatements = null; HashSet<Statement> prevSet = new HashSet<>(); prevSet.addAll(prevGeneratedStatements); //noinspection UnusedAssignment prevGeneratedStatements = null; Sets.SetView<Statement> intersection = Sets.intersection(prevSet, nowSet); HashSet<Statement> addedSet = new HashSet<>(nowSet); addedSet.removeAll(intersection); HashSet<Statement> removedSet = new HashSet<>(prevSet); removedSet.removeAll(intersection); //noinspection UnusedAssignment nowSet = null; //noinspection UnusedAssignment prevSet = null; sendDataByLoad(metadataAdd, addedSet, loadedStatements); sendDataByLoad(metadataRemove, removedSet, loadedStatements); if (oldMetadata.size() > 0) { LOGGER.info("clearing {} {}", oldMetadata.size(), oldMetadata); repositoryConnection.clear(oldMetadata.toArray(new URI[oldMetadata.size()])); } Set<URI> resourcesToPostProcess = Sets.union(Sets.union(getSubjects(addedSet), getSubjects(removedSet)), Sets.union(getURIObject(addedSet), getURIObject(removedSet))); notifyPostProcessors(resourcesToPostProcess, new ArrayList<PostProcessingHistoryItem>(), archiveAddress.getTime(), null, null); LOGGER.info("done processing {} {}", archiveAddress.getTime(), archiveAddress.getPath()); } catch (MetaserviceException | RepositoryException e) { LOGGER.error("Could not process {}", archiveAddress, e); } }
From source file:edu.mit.streamjit.impl.common.AbstractDrainer.java
/** * @return Aggregated DrainData after the draining. *//*www . ja v a2 s . c om*/ public final DrainData getDrainData() { DrainData drainData = null; Map<Token, ImmutableList<Object>> boundaryInputData = new HashMap<>(); Map<Token, ImmutableList<Object>> boundaryOutputData = new HashMap<>(); for (BlobNode node : blobGraph.blobNodes.values()) { boundaryInputData.putAll(node.drainData.inputData); boundaryOutputData.putAll(node.drainData.outputData); if (drainData == null) drainData = node.drainData.drainData; else drainData = drainData.merge(node.drainData.drainData); } ImmutableMap.Builder<Token, ImmutableList<Object>> dataBuilder = ImmutableMap.builder(); for (Token t : Sets.union(boundaryInputData.keySet(), boundaryOutputData.keySet())) { ImmutableList<Object> in = boundaryInputData.get(t) != null ? boundaryInputData.get(t) : ImmutableList.of(); ImmutableList<Object> out = boundaryOutputData.get(t) != null ? boundaryOutputData.get(t) : ImmutableList.of(); dataBuilder.put(t, ImmutableList.builder().addAll(in).addAll(out).build()); } ImmutableTable<Integer, String, Object> state = ImmutableTable.of(); DrainData draindata1 = new DrainData(dataBuilder.build(), state); drainData = drainData.merge(draindata1); if (drainDataStatistics == null) { drainDataStatistics = new HashMap<>(); for (Token t : drainData.getData().keySet()) { drainDataStatistics.put(t, new ArrayList<Integer>()); } } for (Token t : drainData.getData().keySet()) { // System.out.print("Aggregated data: " + t.toString() + " - " // + drainData.getData().get(t).size() + " - "); // for (Object o : drainData.getData().get(t)) { // System.out.print(o.toString() + ", "); // } // System.out.print('\n'); drainDataStatistics.get(t).add(drainData.getData().get(t).size()); } return drainData; }
From source file:io.prestosql.metadata.DiscoveryNodeManager.java
private synchronized void refreshNodesInternal() { // This is currently a blacklist. // TODO: make it a whitelist (a failure-detecting service selector) and maybe build in support for injecting this in airlift Set<ServiceDescriptor> services = serviceSelector.selectAllServices().stream() .filter(service -> !failureDetector.getFailed().contains(service)).collect(toImmutableSet()); ImmutableSet.Builder<Node> activeNodesBuilder = ImmutableSet.builder(); ImmutableSet.Builder<Node> inactiveNodesBuilder = ImmutableSet.builder(); ImmutableSet.Builder<Node> shuttingDownNodesBuilder = ImmutableSet.builder(); ImmutableSet.Builder<Node> coordinatorsBuilder = ImmutableSet.builder(); ImmutableSetMultimap.Builder<ConnectorId, Node> byConnectorIdBuilder = ImmutableSetMultimap.builder(); for (ServiceDescriptor service : services) { URI uri = getHttpUri(service, httpsRequired); NodeVersion nodeVersion = getNodeVersion(service); boolean coordinator = isCoordinator(service); if (uri != null && nodeVersion != null) { PrestoNode node = new PrestoNode(service.getNodeId(), uri, nodeVersion, coordinator); NodeState nodeState = getNodeState(node); switch (nodeState) { case ACTIVE: activeNodesBuilder.add(node); if (coordinator) { coordinatorsBuilder.add(node); }/*from w ww . jav a 2s . co m*/ // record available active nodes organized by connector id String connectorIds = service.getProperties().get("connectorIds"); if (connectorIds != null) { connectorIds = connectorIds.toLowerCase(ENGLISH); for (String connectorId : CONNECTOR_ID_SPLITTER.split(connectorIds)) { byConnectorIdBuilder.put(new ConnectorId(connectorId), node); } } // always add system connector byConnectorIdBuilder.put(new ConnectorId(GlobalSystemConnector.NAME), node); break; case INACTIVE: inactiveNodesBuilder.add(node); break; case SHUTTING_DOWN: shuttingDownNodesBuilder.add(node); break; default: log.error("Unknown state %s for node %s", nodeState, node); } } } if (allNodes != null) { // log node that are no longer active (but not shutting down) SetView<Node> missingNodes = difference(allNodes.getActiveNodes(), Sets.union(activeNodesBuilder.build(), shuttingDownNodesBuilder.build())); for (Node missingNode : missingNodes) { log.info("Previously active node is missing: %s (last seen at %s)", missingNode.getNodeIdentifier(), missingNode.getHostAndPort()); } } // nodes by connector id changes anytime a node adds or removes a connector (note: this is not part of the listener system) activeNodesByConnectorId = byConnectorIdBuilder.build(); AllNodes allNodes = new AllNodes(activeNodesBuilder.build(), inactiveNodesBuilder.build(), shuttingDownNodesBuilder.build(), coordinatorsBuilder.build()); // only update if all nodes actually changed (note: this does not include the connectors registered with the nodes) if (!allNodes.equals(this.allNodes)) { // assign allNodes to a local variable for use in the callback below this.allNodes = allNodes; coordinators = coordinatorsBuilder.build(); // notify listeners List<Consumer<AllNodes>> listeners = ImmutableList.copyOf(this.listeners); nodeStateEventExecutor.submit(() -> listeners.forEach(listener -> listener.accept(allNodes))); } }
From source file:com.siemens.sw360.licenseinfo.LicenseInfoHandler.java
private LicenseInfoParsingResult mergeLicenseInfos(LicenseInfoParsingResult lir1, LicenseInfoParsingResult lir2) { if (lir1.getStatus() != LicenseInfoRequestStatus.SUCCESS) { return lir2; }/*from w w w. j a v a 2 s .co m*/ if (lir2.getStatus() != LicenseInfoRequestStatus.SUCCESS) { return lir1; } if (!lir1.isSetLicenseInfo() || !lir2.isSetLicenseInfo() || !lir1.getLicenseInfo().getFiletype().equals(lir2.getLicenseInfo().getFiletype())) { throw new IllegalArgumentException("LicenseInfo filetypes must be equal"); } if (!Objects.equals(lir1.getName(), lir2.getName()) || !Objects.equals(lir1.getVendor(), lir2.getVendor()) || !Objects.equals(lir1.getVersion(), lir2.getVersion())) { throw new IllegalArgumentException( "Method is not intended to merge across releases. Release data must be equal"); } //use copy constructor to copy filetype LicenseInfo mergedLi = new LicenseInfo(lir1.getLicenseInfo()); //merging filenames Set<String> filenames = new HashSet<>(); filenames.addAll(nullToEmptyList(lir1.getLicenseInfo().getFilenames())); filenames.addAll(nullToEmptyList(lir2.getLicenseInfo().getFilenames())); mergedLi.setFilenames(filenames.stream().collect(Collectors.toList())); //merging copyrights mergedLi.setCopyrights(Sets.union(nullToEmptySet(lir1.getLicenseInfo().getCopyrights()), nullToEmptySet(lir2.getLicenseInfo().getCopyrights()))); //merging licenses mergedLi.setLicenseTexts(Sets.union(nullToEmptySet(lir1.getLicenseInfo().getLicenseTexts()), nullToEmptySet(lir2.getLicenseInfo().getLicenseTexts()))); //use copy constructor to copy vendor, name, and version return new LicenseInfoParsingResult(lir1).setStatus(LicenseInfoRequestStatus.SUCCESS) .setLicenseInfo(mergedLi) .setMessage((nullToEmptyString(lir1.getMessage()) + "\n" + nullToEmptyString(lir2.getMessage())) .trim()); }