List of usage examples for com.google.common.collect Iterables getOnlyElement
public static <T> T getOnlyElement(Iterable<T> iterable)
From source file:com.opengamma.financial.analytics.model.black.BlackDiscountingSpotGammaFXOptionFunction.java
@Override public CompiledFunctionDefinition compile(final FunctionCompilationContext context, final Instant atInstant) { return new BlackDiscountingCompiledFunction(getTargetToDefinitionConverter(context), getDefinitionToDerivativeConverter(context), false) { @Override/*w w w .ja v a 2s . c o m*/ protected Set<ComputedValue> getValues(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target, final Set<ValueRequirement> desiredValues, final InstrumentDerivative derivative, final FXMatrix fxMatrix) { final BlackForexSmileProvider blackData = getBlackSurface(executionContext, inputs, target, fxMatrix); final double gamma = derivative.accept(CALCULATOR, blackData); final ValueRequirement desiredValue = Iterables.getOnlyElement(desiredValues); final ValueProperties properties = desiredValue.getConstraints().copy().get(); final ValueSpecification spec = new ValueSpecification(GAMMA, target.toSpecification(), properties); return Collections.singleton(new ComputedValue(spec, gamma)); } }; }
From source file:com.google.template.soy.types.proto.SoyProtoType.java
SoyProtoType(SoyTypeRegistry typeRegistry, Descriptor descriptor, Set<FieldDescriptor> extensions) { this.typeDescriptor = descriptor; ImmutableMap.Builder<String, Field> fields = ImmutableMap.builder(); for (FieldDescriptor fieldDescriptor : descriptor.getFields()) { if (Protos.shouldJsIgnoreField(fieldDescriptor)) { continue; }/*ww w. j a va2s .c o m*/ NormalField field = new NormalField(typeRegistry, fieldDescriptor); fields.put(field.getName(), field); } SetMultimap<String, ExtensionField> extensionsBySoyName = MultimapBuilder.hashKeys().hashSetValues() .build(); for (FieldDescriptor extension : extensions) { ExtensionField field = new ExtensionField(typeRegistry, extension); extensionsBySoyName.put(field.getName(), field); } for (Map.Entry<String, Set<ExtensionField>> group : Multimaps.asMap(extensionsBySoyName).entrySet()) { String fieldName = group.getKey(); Set<ExtensionField> ambiguousFields = group.getValue(); if (ambiguousFields.size() == 1) { fields.put(fieldName, Iterables.getOnlyElement(ambiguousFields)); } else { AmbiguousFieldSet value = new AmbiguousFieldSet(fieldName, ambiguousFields); logger.severe("Proto " + descriptor.getFullName() + " has multiple extensions with the name \"" + fieldName + "\": " + value.getFullFieldNames() + "\nThis field will not be accessible from soy"); fields.put(fieldName, value); } } this.fields = fields.build(); }
From source file:de.gebit.integrity.annotation.JvmFixtureEvaluation.java
/** * Processes the given method and returns a list of all annotated parameters. Only supports one annotation per * parameter./* ww w . j a va 2 s . c o m*/ * * @param aMethod * Method to be checked. * @param someAnnotationTypes * Types that should be collected. * @return A list of all parameters linked to the annotation of the given types for this method. */ public List<Pair<JvmFormalParameter, JvmAnnotationReference>> getAllAnnotatedParameter(MethodReference aMethod, Set<Class<? extends Annotation>> someAnnotationTypes) { if (aMethod == null) { return emptyList(); } final JvmOperation tempOperation = aMethod.getMethod(); Preconditions.checkArgument(tempOperation != null, "Methodreference did not resolve to a JVM operation!"); List<Pair<JvmFormalParameter, JvmAnnotationReference>> tempResult = new LinkedList<Pair<JvmFormalParameter, JvmAnnotationReference>>(); for (JvmFormalParameter tempParameter : tempOperation.getParameters()) { try { tempResult.add(Tuples.create(tempParameter, Iterables .getOnlyElement(filter(tempParameter.getAnnotations(), isOneOf(someAnnotationTypes))))); } catch (NoSuchElementException exc) { // Expected if there's no matching annotation continue; } } return tempResult; }
From source file:io.prestosql.sql.planner.plan.SampleNode.java
@Override public PlanNode replaceChildren(List<PlanNode> newChildren) { return new SampleNode(getId(), Iterables.getOnlyElement(newChildren), sampleRatio, sampleType); }
From source file:org.sosy_lab.cpachecker.cpa.smg.objects.sll.SMGSingleLinkedListCandidateSequence.java
@Override public CLangSMG execute(CLangSMG pSMG, SMGState pSmgState) throws SMGInconsistentException { SMGObject prevObject = candidate.getStartObject(); int nfo = candidate.getNfo(); pSmgState.pruneUnreachable();// w ww .j av a2s . com // Abstraction not reachable if (!pSMG.getHeapObjects().contains(prevObject)) { return pSMG; } for (int i = 1; i < length; i++) { SMGEdgeHasValue nextEdge = Iterables.getOnlyElement( pSMG.getHVEdges(SMGEdgeHasValueFilter.objectFilter(prevObject).filterAtOffset(nfo))); SMGObject nextObject = pSMG.getPointer(nextEdge.getValue()).getObject(); if (length > 1) { SMGJoinSubSMGsForAbstraction jointest = new SMGJoinSubSMGsForAbstraction(new CLangSMG(pSMG), prevObject, nextObject, candidate, pSmgState); if (!jointest.isDefined()) { return pSMG; } } SMGJoinSubSMGsForAbstraction join = new SMGJoinSubSMGsForAbstraction(pSMG, prevObject, nextObject, candidate, pSmgState); if (!join.isDefined()) { throw new AssertionError("Unexpected join failure while abstracting longest mergeable sequence"); } SMGObject newAbsObj = join.getNewAbstractObject(); Map<Integer, Integer> reached = new HashMap<>(); for (SMGEdgePointsTo pte : SMGUtils.getPointerToThisObject(nextObject, pSMG)) { pSMG.removePointsToEdge(pte.getValue()); if (pte.getTargetSpecifier() == SMGTargetSpecifier.ALL) { SMGEdgePointsTo newPte = new SMGEdgePointsTo(pte.getValue(), newAbsObj, pte.getOffset(), SMGTargetSpecifier.ALL); pSMG.addPointsToEdge(newPte); } } reached.clear(); for (SMGEdgePointsTo pte : SMGUtils.getPointerToThisObject(prevObject, pSMG)) { pSMG.removePointsToEdge(pte.getValue()); if (pte.getTargetSpecifier() == SMGTargetSpecifier.ALL) { SMGEdgePointsTo newPte = new SMGEdgePointsTo(pte.getValue(), newAbsObj, pte.getOffset(), SMGTargetSpecifier.ALL); pSMG.addPointsToEdge(newPte); } else { if (reached.containsKey(pte.getOffset())) { int val = reached.get(pte.getOffset()); pSMG.mergeValues(val, pte.getValue()); } else { SMGEdgePointsTo newPte = new SMGEdgePointsTo(pte.getValue(), newAbsObj, pte.getOffset(), SMGTargetSpecifier.FIRST); pSMG.addPointsToEdge(newPte); reached.put(newPte.getOffset(), newPte.getValue()); } } } SMGEdgeHasValue nextObj2hve = Iterables.getOnlyElement( pSMG.getHVEdges(SMGEdgeHasValueFilter.objectFilter(nextObject).filterAtOffset(nfo))); for (SMGObject obj : join.getNonSharedObjectsFromSMG1()) { pSMG.removeHeapObjectAndEdges(obj); } for (SMGObject obj : join.getNonSharedObjectsFromSMG2()) { pSMG.removeHeapObjectAndEdges(obj); } pSMG.removeHeapObjectAndEdges(nextObject); pSMG.removeHeapObjectAndEdges(prevObject); prevObject = newAbsObj; SMGEdgeHasValue nfoHve = new SMGEdgeHasValue(nextObj2hve.getType(), nextObj2hve.getOffset(), newAbsObj, nextObj2hve.getValue()); pSMG.addHasValueEdge(nfoHve); pSmgState.pruneUnreachable(); } return pSMG; }
From source file:org.jclouds.ec2.compute.predicates.GetImageWhenStatusAvailablePredicateWithResult.java
private org.jclouds.ec2.domain.Image findImage(String id, String region) { return Iterables.getOnlyElement(ec2Client.getAMIServices().describeImagesInRegion(region, new DescribeImagesOptions().imageIds(id))); }
From source file:ai.grakn.graph.internal.concept.RelationImpl.java
/** * Reifys and returns the {@link RelationReified} *//* w ww.ja v a 2 s. c o m*/ public RelationReified reify() { if (relationStructure.isReified()) return relationStructure.reify(); //Get the role players to transfer Map<Role, Set<Thing>> rolePlayers = structure().allRolePlayers(); //Now Reify relationStructure = relationStructure.reify(); //Transfer relationships rolePlayers.forEach((role, things) -> { Thing thing = Iterables.getOnlyElement(things); addRolePlayer(role, thing); }); return relationStructure.reify(); }
From source file:com.google.devtools.javatools.transform.SourceTransformer.java
/** * Parses Java source code, and returns the compilation tree. *//*from w w w . j a va 2s. c om*/ @VisibleForTesting public static CompilationUnitTree parse(final String source) throws IOException { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); JavaFileObject file = new SimpleJavaFileObject(URI.create("string://virtual-source-file.java"), JavaFileObject.Kind.SOURCE) { @Override public CharSequence getCharContent(boolean ignoreEncodingErrors) { return source; } }; JavacTask parseTask = (JavacTask) compiler.getTask(null, null, FailOnErrorDiagnosticListener.INSTANCE, PARSING_OPTIONS, null, ImmutableList.of(file)); return Iterables.getOnlyElement(parseTask.parse()); }
From source file:com.opengamma.financial.analytics.model.black.BlackDiscountingValueDeltaFXOptionFunction.java
@Override public CompiledFunctionDefinition compile(final FunctionCompilationContext context, final Instant atInstant) { return new BlackDiscountingCompiledFunction(getTargetToDefinitionConverter(context), getDefinitionToDerivativeConverter(context), true) { @Override/*from ww w.j a va2s. com*/ protected Set<ComputedValue> getValues(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target, final Set<ValueRequirement> desiredValues, final InstrumentDerivative derivative, final FXMatrix fxMatrix) { final BlackForexSmileProvider blackData = getBlackSurface(executionContext, inputs, target, fxMatrix); final double valueDelta = derivative.accept(CALCULATOR, blackData); final ValueRequirement desiredValue = Iterables.getOnlyElement(desiredValues); final ValueProperties properties = desiredValue.getConstraints().copy().get(); final ValueSpecification spec = new ValueSpecification(VALUE_DELTA, target.toSpecification(), properties); return Collections.singleton(new ComputedValue(spec, valueDelta)); } }; }
From source file:com.opengamma.financial.analytics.model.black.BlackDiscountingValueGammaFXOptionFunction.java
@Override public CompiledFunctionDefinition compile(final FunctionCompilationContext context, final Instant atInstant) { return new BlackDiscountingCompiledFunction(getTargetToDefinitionConverter(context), getDefinitionToDerivativeConverter(context), true) { @Override//from ww w .ja va 2s . c o m protected Set<ComputedValue> getValues(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target, final Set<ValueRequirement> desiredValues, final InstrumentDerivative derivative, final FXMatrix fxMatrix) { final BlackForexSmileProvider blackData = getBlackSurface(executionContext, inputs, target, fxMatrix); final double valueGamma = derivative.accept(CALCULATOR, blackData); final ValueRequirement desiredValue = Iterables.getOnlyElement(desiredValues); final ValueProperties properties = desiredValue.getConstraints().copy().get(); final ValueSpecification spec = new ValueSpecification(VALUE_GAMMA, target.toSpecification(), properties); return Collections.singleton(new ComputedValue(spec, valueGamma)); } }; }