List of usage examples for com.google.common.collect Sets difference
public static <E> SetView<E> difference(final Set<E> set1, final Set<?> set2)
From source file:com.torodb.torod.db.backends.greenplum.converters.json.GreenplumValueToJsonConverterProvider.java
private GreenplumValueToJsonConverterProvider() { converters = Maps.newEnumMap(ScalarType.class); converters.put(ScalarType.ARRAY,/*from w w w .jav a 2 s. c om*/ new ArrayValueToJsonConverter(GreenplumValueToArrayConverterProvider.getInstance())); converters.put(ScalarType.BOOLEAN, new BooleanValueToJsonConverter()); converters.put(ScalarType.DATE, new DateValueToJsonConverter()); converters.put(ScalarType.INSTANT, new InstantValueToJsonConverter()); converters.put(ScalarType.DOUBLE, new DoubleValueToJsonConverter()); converters.put(ScalarType.INTEGER, new IntegerValueToJsonConverter()); converters.put(ScalarType.LONG, new LongValueToJsonConverter()); converters.put(ScalarType.NULL, new NullValueToJsonConverter()); converters.put(ScalarType.STRING, new StringValueToJsonConverter()); converters.put(ScalarType.TIME, new TimeValueToJsonConverter()); converters.put(ScalarType.MONGO_OBJECT_ID, new MongoObjectIdValueToJsonConverter()); converters.put(ScalarType.MONGO_TIMESTAMP, new MongoTimestampValueToJsonConverter()); converters.put(ScalarType.BINARY, new BinaryValueToJsonConverter()); SetView<ScalarType> withoutConverter = Sets.difference(converters.keySet(), SUPPORTED_TYPES); if (!withoutConverter.isEmpty()) { throw new AssertionError("It is not defined how to convert from the following scalar " + "types to json: " + withoutConverter); } }
From source file:clocker.mesos.location.MesosResolver.java
@Override public LocationSpec<? extends Location> newLocationSpecFromString(String spec, Map<?, ?> locationFlags, LocationRegistry registry) {//from ww w. j ava 2 s . c o m LOG.debug("Resolving location '" + spec + "' with flags " + Joiner.on(",").withKeyValueSeparator("=").join(locationFlags)); Matcher matcher = PATTERN.matcher(spec); if (!matcher.matches()) { throw new IllegalArgumentException("Invalid location '" + spec + "'; must specify something like mesos:entityId or mesos:entityId:(name=abc)"); } String argsPart = matcher.group(4); Map<String, String> argsMap = (argsPart != null) ? KeyValueParser.parseMap(argsPart) : Collections.<String, String>emptyMap(); String displayNamePart = argsMap.get("displayName"); String namePart = argsMap.get("name"); if (!ACCEPTABLE_ARGS.containsAll(argsMap.keySet())) { Set<String> illegalArgs = Sets.difference(argsMap.keySet(), ACCEPTABLE_ARGS); throw new IllegalArgumentException("Invalid location '" + spec + "'; illegal args " + illegalArgs + "; acceptable args are " + ACCEPTABLE_ARGS); } if (argsMap.containsKey("displayName") && Strings.isEmpty(displayNamePart)) { throw new IllegalArgumentException( "Invalid location '" + spec + "'; if displayName supplied then value must be non-empty"); } if (argsMap.containsKey("name") && Strings.isEmpty(namePart)) { throw new IllegalArgumentException( "Invalid location '" + spec + "'; if name supplied then value must be non-empty"); } String mesosLocId = matcher.group(2); if (Strings.isBlank(mesosLocId)) { throw new IllegalArgumentException( "Invalid location '" + spec + "'; mesos cluster location id must be non-empty"); } Location mesosLoc = managementContext.getLocationManager().getLocation(mesosLocId); if (mesosLoc == null) { throw new IllegalArgumentException("Unknown Mesos location id " + mesosLocId + ", spec " + spec); } else if (!(mesosLoc instanceof MesosLocation)) { throw new IllegalArgumentException( "Invalid location id for Mesos, spec " + spec + "; instead matches " + mesosLoc); } return LocationSpec.create(MesosLocation.class).configure(LocationConstructor.LOCATION, mesosLoc) .configure(SpecialBrooklynObjectConstructor.Config.SPECIAL_CONSTRUCTOR, LocationConstructor.class); }
From source file:com.torodb.torod.db.backends.postgresql.converters.json.PostgreSQLValueToJsonConverterProvider.java
private PostgreSQLValueToJsonConverterProvider() { converters = Maps.newEnumMap(ScalarType.class); converters.put(ScalarType.ARRAY,/*ww w. j a v a2 s.c o m*/ new ArrayValueToJsonConverter(PostgreSQLValueToArrayConverterProvider.getInstance())); converters.put(ScalarType.BOOLEAN, new BooleanValueToJsonConverter()); converters.put(ScalarType.DATE, new DateValueToJsonConverter()); converters.put(ScalarType.INSTANT, new InstantValueToJsonConverter()); converters.put(ScalarType.DOUBLE, new DoubleValueToJsonConverter()); converters.put(ScalarType.INTEGER, new IntegerValueToJsonConverter()); converters.put(ScalarType.LONG, new LongValueToJsonConverter()); converters.put(ScalarType.NULL, new NullValueToJsonConverter()); converters.put(ScalarType.STRING, new StringValueToJsonConverter()); converters.put(ScalarType.TIME, new TimeValueToJsonConverter()); converters.put(ScalarType.MONGO_OBJECT_ID, new MongoObjectIdValueToJsonConverter()); converters.put(ScalarType.MONGO_TIMESTAMP, new MongoTimestampValueToJsonConverter()); converters.put(ScalarType.BINARY, new BinaryValueToJsonConverter()); SetView<ScalarType> withoutConverter = Sets.difference(converters.keySet(), SUPPORTED_TYPES); if (!withoutConverter.isEmpty()) { throw new AssertionError("It is not defined how to convert from the following scalar " + "types to json: " + withoutConverter); } }
From source file:org.jclouds.codegen.ec2.queryapi.parser.AmazonEC2QueryAPIValidator.java
protected AmazonEC2QueryAPIValidator validateDataType(DataType dataType) { checkState(dataType.getSee().size() >= 1, "see should have at least one entry"); Set<String> fieldNames = Sets .newTreeSet(Iterables.transform(dataType.getContents(), new Function<Content, String>() { public String apply(Content field) { return field.getName(); }// w w w.ja va 2s. c o m })); checkState( Sets.difference(fieldNames, expectedFieldNamesForDataTypeName.get(dataType.getType())).size() == 0, String.format("%1$s hasn't the correct fields. has [%2$s] should have [%3$s]", dataType.getType(), fieldNames, expectedFieldNamesForDataTypeName.get(dataType.getType()))); return this; }
From source file:com.urswolfer.intellij.plugin.gerrit.ui.changesbrowser.CommitDiffBuilder.java
private void addedFiles() throws VcsException { Sets.SetView<String> addedFiles = Sets.difference(changes.keySet(), baseChanges.keySet()); for (String addedFile : addedFiles) { Change change = changes.get(addedFile); ContentRevision beforeRevision = null; if (change.getType().equals(Change.Type.MODIFICATION)) { ContentRevision changeBeforeRevision = change.getBeforeRevision(); assert changeBeforeRevision != null; beforeRevision = new SimpleContentRevision(changeBeforeRevision.getContent(), changeBeforeRevision.getFile(), baseHash); }//from w w w . j av a 2s . c o m diff.add(new Change(beforeRevision, change.getAfterRevision())); } }
From source file:com.google.errorprone.fixes.SuggestedFixes.java
/** Add modifiers to the given class, method, or field declaration. */ @Nullable// w w w . j a va 2 s .c om public static SuggestedFix addModifiers(Tree tree, VisitorState state, Modifier... modifiers) { ModifiersTree originalModifiers = getModifiers(tree); if (originalModifiers == null) { return null; } Set<Modifier> toAdd = Sets.difference(new TreeSet<>(Arrays.asList(modifiers)), originalModifiers.getFlags()); if (originalModifiers.getFlags().isEmpty()) { int pos = state.getEndPosition(originalModifiers) != Position.NOPOS ? state.getEndPosition(originalModifiers) + 1 : ((JCTree) tree).getStartPosition(); int base = ((JCTree) tree).getStartPosition(); java.util.Optional<Integer> insert = state.getTokensForNode(tree).stream() .map(token -> token.pos() + base).filter(thisPos -> thisPos >= pos).findFirst(); int insertPos = insert.orElse(pos); // shouldn't ever be able to get to the else return SuggestedFix.replace(insertPos, insertPos, Joiner.on(' ').join(toAdd) + " "); } // a map from modifiers to modifier position (or -1 if the modifier is being added) // modifiers are sorted in Google Java Style order Map<Modifier, Integer> modifierPositions = new TreeMap<>(); for (Modifier mod : toAdd) { modifierPositions.put(mod, -1); } List<ErrorProneToken> tokens = state.getTokensForNode(originalModifiers); int base = ((JCTree) originalModifiers).getStartPosition(); for (ErrorProneToken tok : tokens) { Modifier mod = getTokModifierKind(tok); if (mod != null) { modifierPositions.put(mod, base + tok.pos()); } } SuggestedFix.Builder fix = SuggestedFix.builder(); // walk the map of all modifiers, and accumulate a list of new modifiers to insert // beside an existing modifier List<Modifier> modifiersToWrite = new ArrayList<>(); for (Modifier mod : modifierPositions.keySet()) { int p = modifierPositions.get(mod); if (p == -1) { modifiersToWrite.add(mod); } else if (!modifiersToWrite.isEmpty()) { fix.replace(p, p, Joiner.on(' ').join(modifiersToWrite) + " "); modifiersToWrite.clear(); } } if (!modifiersToWrite.isEmpty()) { fix.postfixWith(originalModifiers, " " + Joiner.on(' ').join(modifiersToWrite)); } return fix.build(); }
From source file:com.opengamma.livedata.client.ActiveMQLiveDataClient.java
@Override protected Map<String, Runnable> startReceivingTicks(List<String> specs, Session session, JmsByteArrayMessageDispatcher jmsDispatcher) { Map<String, Runnable> ret = new HashMap<String, Runnable>(); if (specs.isEmpty()) { return ret; }// w ww. j a v a 2s . c o m for (String spec : specs) { ConsumerRecord record = _messageConsumersBySpec.get(spec); if (record != null) { //NOTE: could be on the wrong session, but we don't touch it record.getReceiving().add(spec); ret.put(spec, getCloseAction(spec, record)); } } SetView<String> remaining = Sets.difference(new HashSet<String>(specs), ret.keySet()); List<String> remainingList = new ArrayList<String>(remaining); for (List<String> partition : Lists.partition(remainingList, 100)) { String topicName = getCompositeTopicName(partition); try { Topic topic = session.createTopic(topicName); final MessageConsumer messageConsumer = session.createConsumer(topic); messageConsumer.setMessageListener(jmsDispatcher); ConsumerRecord record = new ConsumerRecord(messageConsumer, partition); for (String tickDistributionSpecification : partition) { _messageConsumersBySpec.put(tickDistributionSpecification, record); ret.put(tickDistributionSpecification, getCloseAction(tickDistributionSpecification, record)); } } catch (JMSException e) { throw new OpenGammaRuntimeException("Failed to create subscription to JMS topics " + partition, e); } } return ret; }
From source file:org.apache.cassandra.castorture.Torturer.java
private static void printReport(int numElements, Set<Integer> acked, Set<Integer> survived) { System.out.println(numElements + " total"); System.out.println(acked.size() + " acknowledged"); System.out.println(survived.size() + " survivors"); Set<Integer> lost = Sets.difference(acked, survived); if (!lost.isEmpty()) { System.out.println(lost.size() + " acknowledged writes lost! ( ?"); System.out.println(lost); }/* w w w . j a va 2 s . c om*/ Set<Integer> unacked = Sets.difference(survived, acked); if (!unacked.isEmpty()) { System.out.println(unacked.size() + " unacknowledged writes found! ()"); System.out.println(unacked); } System.out.println(acked.size() / (double) numElements + " ack rate"); System.out.println(lost.size() / (double) numElements + " loss rate"); System.out.println(unacked.size() / (double) numElements + " unacknowledged but successful rate"); }
From source file:org.sosy_lab.cpachecker.util.predicates.invariants.FormulaInvariantsSupplier.java
public void updateInvariants() { Set<UnmodifiableReachedSet> tmp = aggregatedReached.snapShot(); if (!tmp.equals(lastUsedReachedSets)) { // if we have a former aggregated supplier we do only replace the changed parts Set<UnmodifiableReachedSet> oldElements = Sets.difference(lastUsedReachedSets, tmp); Set<UnmodifiableReachedSet> newElements = Sets.difference(tmp, lastUsedReachedSets); oldElements.forEach(r -> singleInvariantSuppliers.remove(r)); newElements.forEach(r -> singleInvariantSuppliers.put(r, new ReachedSetBasedFormulaSupplier(new LazyLocationMapping(r)))); lastUsedReachedSets = tmp;// ww w . j a v a 2 s . co m lastInvariantSupplier = new AggregatedInvariantSupplier( ImmutableSet.copyOf(singleInvariantSuppliers.values()), logger); } }
From source file:com.b2international.index.revision.DefaultRevisionIndex.java
@Override public <T> T read(final String branchPath, final RevisionIndexRead<T> read) { if (RevisionIndex.isBaseRefPath(branchPath)) { final String branchPathWithoutBaseRef = branchPath.substring(0, branchPath.length() - 1); if (RevisionBranch.MAIN_PATH.equals(branchPathWithoutBaseRef)) { throw new IllegalArgumentException("Cannot query base of MAIN branch"); }/*from w w w . j ava 2 s . c om*/ final RevisionBranch parent = getParentBranch(branchPathWithoutBaseRef); final RevisionBranch branch = getBranch(branchPathWithoutBaseRef); final Set<Integer> commonPath = Sets.intersection(branch.segments(), parent.segments()); final RevisionBranch baseOfBranch = new RevisionBranch(parent.path(), Ordering.natural().max(commonPath), commonPath); return read(baseOfBranch, read); } else if (RevisionIndex.isRevRangePath(branchPath)) { final String[] branches = RevisionIndex.getRevisionRangePaths(branchPath); final String basePath = branches[0]; final String comparePath = branches[1]; final RevisionBranch base = getBranch(basePath); final RevisionBranch compare = getBranch(comparePath); final Set<Integer> compareSegments = Sets.difference(compare.segments(), base.segments()); return read(new RevisionBranch(comparePath, compare.segmentId(), compareSegments), read); } else { return read(getBranch(branchPath), read); } }