Java Code Examples for com.google.common.collect.Sets#union()

The following examples show how to use com.google.common.collect.Sets#union() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DBM.java    From theta with Apache License 2.0 6 votes vote down vote up
public boolean isLeq(final DBM that, final Collection<? extends VarDecl<RatType>> activeVars) {
	final Set<VarDecl<RatType>> vars = Sets.union(this.signature.toSet(), that.signature.toSet());

	for (final VarDecl<RatType> x : vars) {
		if (!activeVars.contains(x)) {
			continue;
		}

		for (final VarDecl<RatType> y : vars) {
			if (!activeVars.contains(y)) {
				continue;
			}

			if (this.getOrDefault(x, y) > that.getOrDefault(x, y)) {
				return false;
			}

		}
	}
	return true;
}
 
Example 2
Source File: ServerBuilder.java    From armeria with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a list of {@link ServerPort}s which consists of distinct port numbers except for the port
 * {@code 0}. If there are the same port numbers with different {@link SessionProtocol}s,
 * their {@link SessionProtocol}s will be merged into a single {@link ServerPort} instance.
 * The returned list is sorted as the same order of the specified {@code ports}.
 */
private static List<ServerPort> resolveDistinctPorts(List<ServerPort> ports) {
    final List<ServerPort> distinctPorts = new ArrayList<>();
    for (final ServerPort p : ports) {
        boolean found = false;
        // Do not check the port number 0 because a user may want his or her server to be bound
        // on multiple arbitrary ports.
        if (p.localAddress().getPort() > 0) {
            for (int i = 0; i < distinctPorts.size(); i++) {
                final ServerPort port = distinctPorts.get(i);
                if (port.localAddress().equals(p.localAddress())) {
                    final ServerPort merged =
                            new ServerPort(port.localAddress(),
                                           Sets.union(port.protocols(), p.protocols()));
                    distinctPorts.set(i, merged);
                    found = true;
                    break;
                }
            }
        }
        if (!found) {
            distinctPorts.add(p);
        }
    }
    return Collections.unmodifiableList(distinctPorts);
}
 
Example 3
Source File: AbstractConfigurableNetwork.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public Set<E> adjacentEdges(Object edge) {
  Iterator<N> incidentNodesIterator = incidentNodes(edge).iterator();
  Set<E> endpointsIncidentEdges = incidentEdges(incidentNodesIterator.next());
  while (incidentNodesIterator.hasNext()) {
    endpointsIncidentEdges =
       Sets.union(incidentEdges(incidentNodesIterator.next()), endpointsIncidentEdges);
  }
  return Sets.difference(endpointsIncidentEdges, ImmutableSet.of(edge));
}
 
Example 4
Source File: Team.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Set<MatchPlayer> getPlayers() {
    final Change change = CHANGE.get();
    if(change != null) {
        if(equals(change.oldTeam)) {
            return Sets.difference(super.getPlayers(), Collections.singleton(change.player));
        } else if(equals(change.newTeam)) {
            return Sets.union(super.getPlayers(), Collections.singleton(change.player));
        }
    }
    return super.getPlayers();
}
 
Example 5
Source File: ParboiledEnumSetSpecifier.java    From batfish with Apache License 2.0 5 votes vote down vote up
EnumValueSets<T> union(EnumValueSets<T> sets2) {
  return new EnumValueSets<>(
      Sets.union(_including, sets2._including),
      Sets.union(_excluding, sets2._excluding),
      _allValues,
      _groupValues);
}
 
Example 6
Source File: BatchSchedulerUtils.java    From incubator-nemo with Apache License 2.0 5 votes vote down vote up
static void retryTasksAndRequiredParents(final PlanStateManager planStateManager,
                                         final BlockManagerMaster blockManagerMaster,
                                         final Set<String> tasks) {
  final Set<String> requiredParents =
    recursivelyGetParentTasksForLostBlocks(planStateManager, blockManagerMaster, tasks);
  final Set<String> tasksToRetry = Sets.union(tasks, requiredParents);
  LOG.info("Will be retried: {}", tasksToRetry);
  tasksToRetry.forEach(
    taskToReExecute -> planStateManager.onTaskStateChanged(taskToReExecute, TaskState.State.SHOULD_RETRY));
}
 
Example 7
Source File: DBM.java    From theta with Apache License 2.0 5 votes vote down vote up
public boolean isLeq(final DBM that) {
	final Set<VarDecl<RatType>> vars = Sets.union(this.signature.toSet(), that.signature.toSet());

	for (final VarDecl<RatType> x : vars) {
		for (final VarDecl<RatType> y : vars) {
			if (this.getOrDefault(x, y) > that.getOrDefault(x, y)) {
				return false;
			}

		}
	}
	return true;
}
 
Example 8
Source File: ConfigCommand.java    From bazel with Apache License 2.0 5 votes vote down vote up
private static Map<String, Pair<Object, Object>> diffStarlarkOptions(
    BuildConfiguration config1, BuildConfiguration config2) {
  Map<Label, Object> starlarkOptions1 = config1.getOptions().getStarlarkOptions();
  Map<Label, Object> starlarkOptions2 = config2.getOptions().getStarlarkOptions();
  Map<String, Pair<Object, Object>> diffs = new HashMap<>();
  for (Label option : Sets.union(starlarkOptions1.keySet(), starlarkOptions2.keySet())) {
    Object value1 = starlarkOptions1.get(option);
    Object value2 = starlarkOptions2.get(option);
    if (!Objects.equals(value1, value2)) {
      diffs.put(option.toString(), Pair.of(value1, value2));
    }
  }
  return diffs;
}
 
Example 9
Source File: DefaultManifestMergeSpec.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private DefaultManifest mergeManifest(DefaultManifest baseManifest, DefaultManifest toMergeManifest, FileResolver fileResolver) {
    DefaultManifest mergedManifest = new DefaultManifest(fileResolver);
    mergeSection(null, mergedManifest, baseManifest.getAttributes(), toMergeManifest.getAttributes());
    Set<String> allSections = Sets.union(baseManifest.getSections().keySet(), toMergeManifest.getSections().keySet());
    for (String section : allSections) {
        mergeSection(section, mergedManifest,
                GUtil.elvis(baseManifest.getSections().get(section), new DefaultAttributes()),
                GUtil.elvis(toMergeManifest.getSections().get(section), new DefaultAttributes()));
    }
    return mergedManifest;
}
 
Example 10
Source File: SecurityTokenEvaluator.java    From Strata with Apache License 2.0 5 votes vote down vote up
@Override
public Set<String> tokens(Security security) {
  MetaBean metaBean = MetaBean.of(security.getClass());
  return Sets.union(
      Sets.union(metaBean.metaPropertyMap().keySet(), security.getInfo().propertyNames()),
      security.getInfo().getPriceInfo().propertyNames());
}
 
Example 11
Source File: ClientAlgorithmStore.java    From seldon-server with Apache License 2.0 5 votes vote down vote up
private Set<ItemFilter> retrieveFilters(List<String> filters) {
    Set<ItemFilter> filterSet = new HashSet<>();
    if(filters==null) return alwaysOnFilters;
    for (String filter : filters){
        filterSet.add(applicationContext.getBean(filter, ItemFilter.class));
    }
    return Sets.union(filterSet, alwaysOnFilters);
}
 
Example 12
Source File: ParboiledNodeSpecifier.java    From batfish with Apache License 2.0 4 votes vote down vote up
@Override
public Set<String> visitUnionNodeAstNode(UnionNodeAstNode unionNodeAstNode) {
  return Sets.union(
      unionNodeAstNode.getLeft().accept(this), unionNodeAstNode.getRight().accept(this));
}
 
Example 13
Source File: QueryBasedSource.java    From incubator-gobblin with Apache License 2.0 4 votes vote down vote up
@Override
public List<WorkUnit> getWorkunits(SourceState state) {
  initLogger(state);
  lineageInfo = LineageInfo.getLineageInfo(state.getBroker());

  List<WorkUnit> workUnits = Lists.newArrayList();

  // Map<String, String> tableNameToEntityMap = Maps.newHashMap();
  Set<SourceEntity> entities = getFilteredSourceEntities(state);

  Map<SourceEntity, State> tableSpecificPropsMap = shouldObtainTablePropsFromConfigStore(state)
      ? getTableSpecificPropsFromConfigStore(entities, state)
      : getTableSpecificPropsFromState(entities, state);
  Map<SourceEntity, Long> prevWatermarksByTable = getPreviousWatermarksForAllTables(state);

  for (SourceEntity sourceEntity : Sets.union(entities, prevWatermarksByTable.keySet())) {

    log.info("Source entity to be processed: {}, carry-over from previous state: {} ",
             sourceEntity, !entities.contains(sourceEntity));

    SourceState combinedState = getCombinedState(state, tableSpecificPropsMap.get(sourceEntity));
    long previousWatermark = prevWatermarksByTable.containsKey(sourceEntity) ?
        prevWatermarksByTable.get(sourceEntity)
        : ConfigurationKeys.DEFAULT_WATERMARK_VALUE;

    // If a table name exists in prevWatermarksByTable (i.e., it has a previous watermark) but does not exist
    // in talbeNameToEntityMap, create an empty workunit for it, so that its previous watermark is preserved.
    // This is done by overriding the high watermark to be the same as the previous watermark.
    if (!entities.contains(sourceEntity)) {
      combinedState.setProp(ConfigurationKeys.SOURCE_QUERYBASED_END_VALUE, previousWatermark);
    }

    workUnits.addAll(generateWorkUnits(sourceEntity, combinedState, previousWatermark));
  }

  log.info("Total number of workunits for the current run: " + workUnits.size());
  List<WorkUnit> previousWorkUnits = this.getPreviousWorkUnitsForRetry(state);
  log.info("Total number of incomplete tasks from the previous run: " + previousWorkUnits.size());
  workUnits.addAll(previousWorkUnits);

  int numOfMultiWorkunits =
      state.getPropAsInt(ConfigurationKeys.MR_JOB_MAX_MAPPERS_KEY, ConfigurationKeys.DEFAULT_MR_JOB_MAX_MAPPERS);

  return pack(workUnits, numOfMultiWorkunits);
}
 
Example 14
Source File: StackTrace.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public StackTrace(Set<Class<?>> skip) {
    this(new Throwable().getStackTrace(), Sets.union(ImmutableSet.of(StackTrace.class), skip));
}
 
Example 15
Source File: AbstractDirectedNodeConnections.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public Set<E> incidentEdges() {
  return Sets.union(inEdges(), outEdges());
}
 
Example 16
Source File: ExampleServiceRegistrationDataProvider.java    From ob1k with Apache License 2.0 4 votes vote down vote up
private Set<String> extendedTags(final Set<String> tags, final Server server) {
  final String portTag = "httpPort-" + server.getPort();
  final String contextPathTag = "contextPath-" + server.getContextPath();
  return Sets.union(tags, Sets.newHashSet(contextPathTag, portTag));
}
 
Example 17
Source File: PGMMapEnvironment.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Set<String> keySet() {
    return Sets.union(Sets.union(manual.keySet(), Holidays.keys()), permanent().getKeys(false));
}
 
Example 18
Source File: Traceables.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public static StackTrace computeStackTrace(Object obj, Set<Class<?>> skip) {
    return obj instanceof Traceable ? ((Traceable) obj).stackTrace()
                                    : new StackTrace(Sets.union(ImmutableSet.of(Traceables.class), skip));
}
 
Example 19
Source File: AbstractDirectedNodeConnections.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public Set<N> adjacentNodes() {
  return Sets.union(predecessors(), successors());
}
 
Example 20
Source File: BaseGraph.java    From gatk-protected with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Get the set of vertices connected to v by incoming or outgoing edges
 * @param v a non-null vertex
 * @return a set of vertices {X} connected X -> v or v -> Y
 */
public final Set<V> neighboringVerticesOf(final V v) {
    Utils.nonNull(v);
    return Sets.union(incomingVerticesOf(v), outgoingVerticesOf(v));
}