List of usage examples for com.google.common.collect ImmutableSet size
int size();
From source file:dagger2.internal.codegen.ProvidesMethodValidator.java
@Override public ValidationReport<ExecutableElement> validate(ExecutableElement providesMethodElement) { ValidationReport.Builder<ExecutableElement> builder = ValidationReport.Builder.about(providesMethodElement); Provides providesAnnotation = providesMethodElement.getAnnotation(Provides.class); checkArgument(providesAnnotation != null); Element enclosingElement = providesMethodElement.getEnclosingElement(); if (!isAnnotationPresent(enclosingElement, Module.class)) { builder.addItem(formatModuleErrorMessage(BINDING_METHOD_NOT_IN_MODULE), providesMethodElement); }/*from w w w. ja v a 2s. c o m*/ if (!providesMethodElement.getTypeParameters().isEmpty()) { builder.addItem(formatErrorMessage(BINDING_METHOD_TYPE_PARAMETER), providesMethodElement); } Set<Modifier> modifiers = providesMethodElement.getModifiers(); if (modifiers.contains(PRIVATE)) { builder.addItem(formatErrorMessage(BINDING_METHOD_PRIVATE), providesMethodElement); } if (modifiers.contains(ABSTRACT)) { builder.addItem(formatErrorMessage(BINDING_METHOD_ABSTRACT), providesMethodElement); } TypeMirror returnType = providesMethodElement.getReturnType(); TypeKind returnTypeKind = returnType.getKind(); if (returnTypeKind.equals(VOID)) { builder.addItem(formatErrorMessage(BINDING_METHOD_MUST_RETURN_A_VALUE), providesMethodElement); } // check mapkey is right if (!providesAnnotation.type().equals(Provides.Type.MAP) && (getMapKeys(providesMethodElement) != null && getMapKeys(providesMethodElement).size() > 0)) { builder.addItem(formatErrorMessage(BINDING_METHOD_NOT_MAP_HAS_MAP_KEY), providesMethodElement); } validateMethodQualifiers(builder, providesMethodElement); switch (providesAnnotation.type()) { case UNIQUE: // fall through case SET: validateKeyType(builder, returnType); break; case MAP: validateKeyType(builder, returnType); ImmutableSet<? extends AnnotationMirror> annotationMirrors = getMapKeys(providesMethodElement); switch (annotationMirrors.size()) { case 0: builder.addItem(formatErrorMessage(BINDING_METHOD_WITH_NO_MAP_KEY), providesMethodElement); break; case 1: break; default: builder.addItem(formatErrorMessage(BINDING_METHOD_WITH_MULTIPLE_MAP_KEY), providesMethodElement); break; } break; case SET_VALUES: if (!returnTypeKind.equals(DECLARED)) { builder.addItem(PROVIDES_METHOD_SET_VALUES_RETURN_SET, providesMethodElement); } else { DeclaredType declaredReturnType = (DeclaredType) returnType; // TODO(gak): should we allow "covariant return" for set values? if (!declaredReturnType.asElement().equals(getSetElement())) { builder.addItem(PROVIDES_METHOD_SET_VALUES_RETURN_SET, providesMethodElement); } else if (declaredReturnType.getTypeArguments().isEmpty()) { builder.addItem(formatErrorMessage(BINDING_METHOD_SET_VALUES_RAW_SET), providesMethodElement); } else { validateKeyType(builder, Iterables.getOnlyElement(declaredReturnType.getTypeArguments())); } } break; default: throw new AssertionError(); } return builder.build(); }
From source file:com.jeffreybosboom.lyne.Puzzle.java
/** * Returns a Puzzle with the given possibility removed from the edge between * the given nodes. If the possibility is already not possible, this Puzzle * is returned. If this removes the last possibility for this edge, * a ContradictionException is thrown.//ww w.j av a 2s.c o m */ public Puzzle remove(Node a, Node b, Node.Kind possibility) { Pair<Node, Node> p = Pair.sorted(a, b); ImmutableSet<Node.Kind> possibilities = possibilities(a, b); if (!possibilities.contains(possibility)) return this; if (possibilities.size() == 1) throw new ContradictionException(); ImmutableSet<Node.Kind> newSet = ImmutableSet .copyOf(possibilities.stream().filter(x -> x != possibility).iterator()); return withEdgeSet(p, newSet); }
From source file:com.facebook.buck.apple.simulator.AppleSimulatorController.java
public boolean canStartSimulator(String simulatorUdid) throws IOException, InterruptedException { ImmutableSet<String> bootedSimulatorDeviceUdids = getBootedSimulatorDeviceUdids(processExecutor); if (bootedSimulatorDeviceUdids.size() == 0) { return true; } else if (bootedSimulatorDeviceUdids.size() > 1) { LOG.debug("Multiple simulators booted (%s), cannot start simulator.", bootedSimulatorDeviceUdids); return false; } else if (!bootedSimulatorDeviceUdids.contains(simulatorUdid)) { LOG.debug("Booted simulator (%s) does not match desired (%s), cannot start simulator.", Iterables.getOnlyElement(bootedSimulatorDeviceUdids), simulatorUdid); return false; } else {//from w w w . j av a 2 s . c o m return true; } }
From source file:com.facebook.buck.versions.AbstractFlavorSearchTargetNodeFinder.java
public Optional<TargetNode<?>> get(BuildTarget target) { // If this node is in the graph under the given name, return it. TargetNode<?> node = getBuildTargetIndex().get(target); if (node != null) { return Optional.of(node); }//from w w w. j av a 2s . c o m ImmutableSet<ImmutableSet<Flavor>> flavorList = getBaseTargetFlavorMap() .get(target.getUnflavoredBuildTarget()); if (flavorList == null) { return Optional.empty(); } // Otherwise, see if this node exists in the graph with a "less" flavored name. We initially // select all targets which contain a subset of the original flavors, which should be sorted by // from largest flavor set to smallest. We then use the first match, and verify the subsequent // matches are subsets. ImmutableList<ImmutableSet<Flavor>> matches = RichStream.from(flavorList) .filter(target.getFlavors()::containsAll).toImmutableList(); if (!matches.isEmpty()) { ImmutableSet<Flavor> firstMatch = matches.get(0); for (ImmutableSet<Flavor> subsequentMatch : matches.subList(1, matches.size())) { Preconditions .checkState(firstMatch.size() > subsequentMatch.size(), "Expected to find larger flavor lists earlier in the flavor map " + "index (sizeof(%s) <= sizeof(%s))", firstMatch.size(), subsequentMatch.size()); Preconditions.checkState(firstMatch.containsAll(subsequentMatch), "Found multiple disjoint flavor matches for %s: %s and %s (from %s)", target, firstMatch, subsequentMatch, matches); } return Optional.of(Preconditions.checkNotNull(getBaseTargetIndex().get(target.withFlavors(firstMatch)), "%s missing in index", target.withFlavors(firstMatch))); } // Otherwise, return `null` to indicate this node isn't in the target graph. return Optional.empty(); }
From source file:info.gehrels.voting.genderedElections.ElectionCalculationWithFemaleExclusivePositions.java
private long calculateNumberOfElectableFemaleExclusivePositions(GenderedElection election, ImmutableSet<GenderedCandidate> electedFemaleCandidates) { long numberOfElectableNotFemaleExclusivePositions = max(0, election.getNumberOfNotFemaleExclusivePositions() - (election.getNumberOfFemaleExclusivePositions() - electedFemaleCandidates.size())); if (numberOfElectableNotFemaleExclusivePositions < election.getNumberOfNotFemaleExclusivePositions()) { electionCalculationListener.reducedNonFemaleExclusiveSeats( election.getNumberOfFemaleExclusivePositions(), electedFemaleCandidates.size(), election.getNumberOfNotFemaleExclusivePositions(), numberOfElectableNotFemaleExclusivePositions); }/*w w w .ja v a 2 s. co m*/ return numberOfElectableNotFemaleExclusivePositions; }
From source file:dagger2.internal.codegen.ProducesMethodValidator.java
@Override public ValidationReport<ExecutableElement> validate(ExecutableElement producesMethodElement) { ValidationReport.Builder<ExecutableElement> builder = ValidationReport.Builder.about(producesMethodElement); Produces producesAnnotation = producesMethodElement.getAnnotation(Produces.class); checkArgument(producesAnnotation != null); Element enclosingElement = producesMethodElement.getEnclosingElement(); if (!isAnnotationPresent(enclosingElement, ProducerModule.class)) { builder.addItem(formatModuleErrorMessage(BINDING_METHOD_NOT_IN_MODULE), producesMethodElement); }/* w w w. j a v a 2s.c o m*/ if (!producesMethodElement.getTypeParameters().isEmpty()) { builder.addItem(formatErrorMessage(BINDING_METHOD_TYPE_PARAMETER), producesMethodElement); } Set<Modifier> modifiers = producesMethodElement.getModifiers(); if (modifiers.contains(PRIVATE)) { builder.addItem(formatErrorMessage(BINDING_METHOD_PRIVATE), producesMethodElement); } if (modifiers.contains(ABSTRACT)) { builder.addItem(formatErrorMessage(BINDING_METHOD_ABSTRACT), producesMethodElement); } TypeMirror returnType = producesMethodElement.getReturnType(); TypeKind returnTypeKind = returnType.getKind(); if (returnTypeKind.equals(VOID)) { builder.addItem(formatErrorMessage(BINDING_METHOD_MUST_RETURN_A_VALUE), producesMethodElement); } // check mapkey is right if (!producesAnnotation.type().equals(Produces.Type.MAP) && (getMapKeys(producesMethodElement) != null && !getMapKeys(producesMethodElement).isEmpty())) { builder.addItem(formatErrorMessage(BINDING_METHOD_NOT_MAP_HAS_MAP_KEY), producesMethodElement); } ProvidesMethodValidator.validateMethodQualifiers(builder, producesMethodElement); switch (producesAnnotation.type()) { case UNIQUE: // fall through case SET: validateSingleReturnType(builder, returnType); break; case MAP: validateSingleReturnType(builder, returnType); ImmutableSet<? extends AnnotationMirror> annotationMirrors = getMapKeys(producesMethodElement); switch (annotationMirrors.size()) { case 0: builder.addItem(formatErrorMessage(BINDING_METHOD_WITH_NO_MAP_KEY), producesMethodElement); break; case 1: break; default: builder.addItem(formatErrorMessage(BINDING_METHOD_WITH_MULTIPLE_MAP_KEY), producesMethodElement); break; } break; case SET_VALUES: if (returnTypeKind.equals(DECLARED) && MoreTypes.isTypeOf(ListenableFuture.class, returnType)) { DeclaredType declaredReturnType = MoreTypes.asDeclared(returnType); if (!declaredReturnType.getTypeArguments().isEmpty()) { validateSetType(builder, Iterables.getOnlyElement(declaredReturnType.getTypeArguments())); } } else { validateSetType(builder, returnType); } break; default: throw new AssertionError(); } return builder.build(); }
From source file:dagger.internal.codegen.DuplicateBindingsValidation.java
private String incompatibleBindingsMessage(DependencyRequest dependencyRequest, ImmutableSet<BindingNode> duplicateBindings, BindingGraph graph) { ImmutableSet<BindingNode> multibindings = duplicateBindings.stream() .filter(node -> node.binding().kind().isMultibinding()).collect(toImmutableSet()); verify(multibindings.size() == 1, "expected only one multibinding for %s: %s", dependencyRequest, multibindings);/*w ww . jav a 2 s .c om*/ StringBuilder message = new StringBuilder(); java.util.Formatter messageFormatter = new java.util.Formatter(message); messageFormatter.format("%s has incompatible bindings or declarations:\n", dependencyRequest.key()); message.append(INDENT); BindingNode multibinding = getOnlyElement(multibindings); messageFormatter.format("%s bindings and declarations:", multibindingTypeString(multibinding)); formatDeclarations(message, 2, declarations(graph, multibindings)); Set<BindingNode> uniqueBindings = Sets.filter(duplicateBindings, binding -> !binding.equals(multibinding)); message.append(INDENT).append("Unique bindings and declarations:"); formatDeclarations(message, 2, Sets.filter(declarations(graph, uniqueBindings), declaration -> !(declaration instanceof MultibindingDeclaration))); return message.toString(); }
From source file:dagger.model.testing.BindingGraphSubject.java
private BindingSubject bindingWithKeyString(String keyString) { ImmutableSet<Binding> bindings = getBindingNodes(keyString); if (bindings.isEmpty()) { fail("has binding with key", keyString); }/*ww w . j a v a 2 s . c om*/ // TODO(dpb): Handle multiple bindings for the same key. if (bindings.size() > 1) { failWithBadResults("has only one binding with key", keyString, "has the following bindings:", bindings); } return check("bindingWithKey(%s)", keyString).about(BindingSubject::new).that(getOnlyElement(bindings)); }
From source file:com.facebook.buck.ide.intellij.model.AbstractIjModuleAndroidFacet.java
/** * AndroidManifest.xml can be generated when package name is known. Also, it's not generated when * there is exactly one manifest from targets (this manifest will be used in IntelliJ project). *///w w w . j a va2 s . c o m @Value.Lazy public boolean hasValidAndroidManifest() { ImmutableSet<Path> androidManifestPaths = getManifestPaths(); Optional<String> packageName = getPackageName(); // This is guaranteed during target parsing and creation Preconditions.checkState(packageName.isPresent() || !androidManifestPaths.isEmpty()); return androidManifestPaths.size() == 1 || (!packageName.isPresent() && androidManifestPaths.size() > 1); }
From source file:com.pinterest.pinlater.PinLaterQueueConfig.java
public void initialize() throws Exception { // Check if use of serverset is enabled, and if so, register a change monitor so we // can find out how many PinLater servers are active. We use this to compute the // per-server rate limit. if (pinlaterServerSetEnabled) { MorePreconditions.checkNotBlank(pinlaterServerSetPath); LOG.info("Monitoring pinlater serverset: {}", pinlaterServerSetPath); String fullServerSetPath = getClass().getResource("/" + pinlaterServerSetPath).getPath(); ServerSet serverSet = new ConfigFileServerSet(fullServerSetPath); serverSet.monitor(new DynamicHostSet.HostChangeMonitor<ServiceInstance>() { @Override//from w w w . ja v a 2 s . c om public void onChange(ImmutableSet<ServiceInstance> hostSet) { int oldSize = numPinLaterServers.get(); int newSize = hostSet.size(); if (newSize == 0) { LOG.error("PinLater serverset is empty, ignoring and keeping old size: {}", oldSize); return; } if (oldSize == newSize) { LOG.info("PinLater serverset update, size unchanged: {}", oldSize); return; } LOG.info("PinLater serverset update, old size: {}, new size: {}", oldSize, newSize); numPinLaterServers.set(newSize); rebuild(); } }); } else { LOG.info("PinLater server set is disabled; rate limits will be applied per server."); } if (queueConfigFilePath == null || queueConfigFilePath.isEmpty()) { LOG.info("Queue config zookeeper path not specified, using defaults."); return; } LOG.info("Registering watch on queue config: {}", queueConfigFilePath); String fullQueueConfigFilePath = getClass().getResource("/" + queueConfigFilePath).getPath(); ConfigFileWatcher.defaultInstance().addWatch(fullQueueConfigFilePath, new ExceptionalFunction<byte[], Void>() { @Override public Void applyE(byte[] bytes) throws Exception { QueueConfigSchema queueConfigSchema = QueueConfigSchema.load(bytes); LOG.info("Queue config update, new value: {}", queueConfigSchema); queueConfigSchemaRef.set(queueConfigSchema); rebuild(); return null; } }); }