List of usage examples for com.google.common.collect ImmutableList get
E get(int index);
From source file:com.google.devtools.build.lib.syntax.FuncallExpression.java
/** * Call a method depending on the type of an object it is called on. * * <p>Public for reflection by the compiler and access from generated byte code. * * @param positionals The first object is expected to be the object the method is called on. * @param call the original expression that caused this call, needed for rules especially *//*w ww . jav a 2 s . c o m*/ public Object invokeObjectMethod(String method, ImmutableList<Object> positionals, ImmutableMap<String, Object> keyWordArgs, FuncallExpression call, Environment env) throws EvalException, InterruptedException { Location location = call.getLocation(); Object value = positionals.get(0); ImmutableList<Object> positionalArgs = positionals.subList(1, positionals.size()); BaseFunction function = Runtime.getFunction(EvalUtils.getSkylarkType(value.getClass()), method); if (function != null) { if (!isNamespace(value.getClass())) { // Use self as an implicit parameter in front. positionalArgs = positionals; } return function.call(positionalArgs, ImmutableMap.<String, Object>copyOf(keyWordArgs), call, env); } else if (value instanceof ClassObject) { Object fieldValue = ((ClassObject) value).getValue(method); if (fieldValue == null) { throw new EvalException(location, String.format("struct has no method '%s'", method)); } if (!(fieldValue instanceof BaseFunction)) { throw new EvalException(location, String.format("struct field '%s' is not a function", method)); } function = (BaseFunction) fieldValue; return function.call(positionalArgs, ImmutableMap.<String, Object>copyOf(keyWordArgs), call, env); } else { // When calling a Java method, the name is not in the Environment, // so evaluating 'func' would fail. Class<?> objClass; Object obj; if (value instanceof Class<?>) { // Static call obj = null; objClass = (Class<?>) value; } else { obj = value; objClass = value.getClass(); } Pair<MethodDescriptor, List<Object>> javaMethod = call.findJavaMethod(objClass, method, positionalArgs, keyWordArgs); if (javaMethod.first.getAnnotation().structField()) { // Not a method but a callable attribute try { return callFunction(javaMethod.first.getMethod().invoke(obj), env); } catch (IllegalAccessException e) { throw new EvalException(getLocation(), "method invocation failed: " + e); } catch (InvocationTargetException e) { if (e.getCause() instanceof FuncallException) { throw new EvalException(getLocation(), e.getCause().getMessage()); } else if (e.getCause() != null) { throw new EvalExceptionWithJavaCause(getLocation(), e.getCause()); } else { // This is unlikely to happen throw new EvalException(getLocation(), "method invocation failed: " + e); } } } return callMethod(javaMethod.first, method, obj, javaMethod.second.toArray(), location, env); } }
From source file:org.kiji.schema.KijiURI.java
/** * Appends the cluster identifier for this {@code KijiURI} to the passed in {@link StringBuilder}. * * This is a default implementation which will append the ZooKeeper ensemble to the string * builder. May be overridden by subclasses if more than the ZooKeeper ensemble is necessary for * the cluster identifier.//from w ww . j av a2 s . com * * @param sb a StringBuilder to append the cluster identifier to. * @param preserveOrdering whether to preserve ordering in the cluster identifier components. * @return the StringBuilder with the cluster identifier appended. */ protected StringBuilder appendClusterIdentifier(final StringBuilder sb, final boolean preserveOrdering) { ImmutableList<String> zookeeperQuorum = preserveOrdering ? mZookeeperQuorum : mZookeeperQuorumNormalized; if (zookeeperQuorum == null) { sb.append(UNSET_URI_STRING); } else if (zookeeperQuorum.size() == 1) { sb.append(zookeeperQuorum.get(0)); } else { sb.append('('); Joiner.on(',').appendTo(sb, zookeeperQuorum); sb.append(')'); } sb.append(':').append(mZookeeperClientPort).append('/'); return sb; }
From source file:com.facebook.buck.artifact_cache.AbstractAsynchronousCache.java
private void processCheck() { try {//from w w w. j a va 2s . c o m if (markAllFetchRequestsAsSkipped) { // Build is finished/terminated, all pending fetch requests should be set to skipped state. skipAllPendingRequests(); return; } ImmutableList<ClaimedFetchRequest> requests = getCheckRequests(); if (requests.isEmpty()) { return; } else if (requests.size() == 1) { // If there is just single fetch request get it directly try (ClaimedFetchRequest request = requests.get(0)) { doFetch(request.getRequest()); } } else { ImmutableMap.Builder<RuleKey, ClaimedFetchRequest> requestsBuilder = ImmutableMap.builder(); try { for (ClaimedFetchRequest request : requests) { requestsBuilder.put(request.getRequest().getRuleKey(), request); } ImmutableMap<RuleKey, ClaimedFetchRequest> ruleKeyToRequest = requestsBuilder.build(); doMultiCheck(ruleKeyToRequest); } finally { requests.forEach(ClaimedFetchRequest::close); } } } catch (Exception e) { // If any exception is thrown in trying to process requests, just fulfill everything with an // error. cancelAllPendingRequests(e); } }
From source file:org.geogit.web.api.repo.MergeFeatureResource.java
@Override protected Representation post(Representation entity) throws ResourceException { try {/* www . j av a 2s.c o m*/ final GeoGIT ggit = (GeoGIT) getApplication().getContext().getAttributes().get("geogit"); final Reader body = entity.getReader(); final JsonParser parser = new JsonParser(); final JsonElement conflictJson = parser.parse(body); Preconditions.checkArgument(conflictJson.isJsonObject(), "Post data should be a JSON Object."); final JsonObject conflict = conflictJson.getAsJsonObject(); String featureId = null; RevFeature ourFeature = null; RevFeatureType ourFeatureType = null; RevFeature theirFeature = null; RevFeatureType theirFeatureType = null; JsonObject merges = null; if (conflict.has("path") && conflict.get("path").isJsonPrimitive()) { featureId = conflict.get("path").getAsJsonPrimitive().getAsString(); } Preconditions.checkState(featureId != null); if (conflict.has("ours") && conflict.get("ours").isJsonPrimitive()) { String ourCommit = conflict.get("ours").getAsJsonPrimitive().getAsString(); Optional<NodeRef> ourNode = parseID(ObjectId.valueOf(ourCommit), featureId, ggit); if (ourNode.isPresent()) { Optional<RevObject> object = ggit.command(RevObjectParse.class) .setObjectId(ourNode.get().objectId()).call(); Preconditions.checkState(object.isPresent() && object.get() instanceof RevFeature); ourFeature = (RevFeature) object.get(); object = ggit.command(RevObjectParse.class).setObjectId(ourNode.get().getMetadataId()).call(); Preconditions.checkState(object.isPresent() && object.get() instanceof RevFeatureType); ourFeatureType = (RevFeatureType) object.get(); } } if (conflict.has("theirs") && conflict.get("theirs").isJsonPrimitive()) { String theirCommit = conflict.get("theirs").getAsJsonPrimitive().getAsString(); Optional<NodeRef> theirNode = parseID(ObjectId.valueOf(theirCommit), featureId, ggit); if (theirNode.isPresent()) { Optional<RevObject> object = ggit.command(RevObjectParse.class) .setObjectId(theirNode.get().objectId()).call(); Preconditions.checkState(object.isPresent() && object.get() instanceof RevFeature); theirFeature = (RevFeature) object.get(); object = ggit.command(RevObjectParse.class).setObjectId(theirNode.get().getMetadataId()).call(); Preconditions.checkState(object.isPresent() && object.get() instanceof RevFeatureType); theirFeatureType = (RevFeatureType) object.get(); } } if (conflict.has("merges") && conflict.get("merges").isJsonObject()) { merges = conflict.get("merges").getAsJsonObject(); } Preconditions.checkState(merges != null); Preconditions.checkState(ourFeatureType != null || theirFeatureType != null); SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder( (SimpleFeatureType) (ourFeatureType != null ? ourFeatureType.type() : theirFeatureType.type())); ImmutableList<PropertyDescriptor> descriptors = (ourFeatureType == null ? theirFeatureType : ourFeatureType).sortedDescriptors(); for (Entry<String, JsonElement> entry : merges.entrySet()) { int descriptorIndex = getDescriptorIndex(entry.getKey(), descriptors); if (descriptorIndex != -1 && entry.getValue().isJsonObject()) { PropertyDescriptor descriptor = descriptors.get(descriptorIndex); JsonObject attributeObject = entry.getValue().getAsJsonObject(); if (attributeObject.has("ours") && attributeObject.get("ours").isJsonPrimitive() && attributeObject.get("ours").getAsBoolean()) { featureBuilder.set(descriptor.getName(), ourFeature == null ? null : ourFeature.getValues().get(descriptorIndex).orNull()); } else if (attributeObject.has("theirs") && attributeObject.get("theirs").isJsonPrimitive() && attributeObject.get("theirs").getAsBoolean()) { featureBuilder.set(descriptor.getName(), theirFeature == null ? null : theirFeature.getValues().get(descriptorIndex).orNull()); } else if (attributeObject.has("value") && attributeObject.get("value").isJsonPrimitive()) { JsonPrimitive primitive = attributeObject.get("value").getAsJsonPrimitive(); if (primitive.isString()) { try { Object object = valueFromString( FieldType.forBinding(descriptor.getType().getBinding()), primitive.getAsString()); featureBuilder.set(descriptor.getName(), object); } catch (Exception e) { throw new Exception("Unable to convert attribute (" + entry.getKey() + ") to required type: " + descriptor.getType().getBinding().toString()); } } else if (primitive.isNumber()) { try { Object value = valueFromNumber( FieldType.forBinding(descriptor.getType().getBinding()), primitive.getAsNumber()); featureBuilder.set(descriptor.getName(), value); } catch (Exception e) { throw new Exception("Unable to convert attribute (" + entry.getKey() + ") to required type: " + descriptor.getType().getBinding().toString()); } } else if (primitive.isBoolean()) { try { Object value = valueFromBoolean( FieldType.forBinding(descriptor.getType().getBinding()), primitive.getAsBoolean()); featureBuilder.set(descriptor.getName(), value); } catch (Exception e) { throw new Exception("Unable to convert attribute (" + entry.getKey() + ") to required type: " + descriptor.getType().getBinding().toString()); } } else if (primitive.isJsonNull()) { featureBuilder.set(descriptor.getName(), null); } else { throw new Exception( "Unsupported JSON type for attribute value (" + entry.getKey() + ")"); } } } } SimpleFeature feature = featureBuilder.buildFeature(NodeRef.nodeFromPath(featureId)); RevFeature revFeature = RevFeatureBuilder.build(feature); ggit.getRepository().getIndex().getDatabase().put(revFeature); return new StringRepresentation(revFeature.getId().toString(), MediaType.TEXT_PLAIN); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.github.rinde.rinsim.examples.demo.factory.FactoryExample.java
/** * Run the example./* ww w .j a v a 2 s. c om*/ * @param endTime The time to stop. * @param display The display to show it on. * @param m The monitor to show it on. * @param list Listener for events. * @return The simulator used in the example. */ public static Simulator run(final long endTime, Display display, @Nullable Monitor m, @Nullable Listener list) { final Rectangle rect; if (m != null) { if (list != null) { rect = m.getClientArea(); } else { // full screen rect = m.getBounds(); } } else { rect = display.getPrimaryMonitor().getClientArea(); } List<String> words = asList(" BioCo3 \nDistriNet"); // spacing between vertical lines in line units // screen if (rect.width == FULL_HD_W) { // AgentWise\nKU Leuven", "iMinds\nDistriNet" // " Agent \n Wise ", " Distri \n Net " words = asList(" iMinds \nDistriNet"); } final ImmutableList<ImmutableList<Point>> points = createPoints(words); final Graph<?> g = createGraph(points); final List<Point> borderNodes = newArrayList(getBorderNodes(g)); Collections.shuffle(borderNodes, new Random(RANDOM_SEED)); View.Builder view = View.builder().with(GraphRoadModelRenderer.builder().withMargin(CANVAS_MARGIN)) .with(BoxRenderer.builder()) .with(RoadUserRenderer.builder().withImageAssociation(AGV.class, "/graphics/flat/forklift2.png")) .withTitleAppendix("Factory Demo").withAutoPlay().withAutoClose().withSpeedUp(SPEED_UP); if (m != null) { view = view.withMonitor(m).withResolution(m.getClientArea().width, m.getClientArea().height) .withDisplay(display); if (list != null) { view = view.withCallback(list).withAsync(); } else { view = view.withFullScreen(); } } final RandomGenerator rng = new MersenneTwister(RANDOM_SEED); final Simulator simulator = Simulator.builder().setRandomGenerator(rng) .addModel(BlockingGraphRoadModel .blockingBuilder(g).withDistanceUnit(SI.METER).withSpeedUnit(NonSI.KILOMETERS_PER_HOUR)) .addModel(DefaultPDPModel.builder()) .addModel(AgvModel.builder() .withPoints(ImmutableList.<ImmutableList<Point>>builder().addAll(points) .add(ImmutableList.copyOf(borderNodes)).build(), getBorderNodes(g))) .addModel(view).build(); for (int i = 0; i < NUM_VEHICLES; i++) { final List<Point> l = points.get(rng.nextInt(points.size())); final Point p = l.get(rng.nextInt(l.size())); simulator.register(new AGV(p)); } simulator.addTickListener(new TickListener() { @Override public void tick(TimeLapse time) { if (time.getStartTime() > endTime) { simulator.stop(); } } @Override public void afterTick(TimeLapse timeLapse) { } }); simulator.start(); return simulator; }
From source file:com.facebook.buck.apple.WorkspaceAndProjectGenerator.java
public Path generateWorkspaceAndDependentProjects(Map<Path, ProjectGenerator> projectGenerators) throws IOException { LOG.debug("Generating workspace for target %s", workspaceBuildTarget); String workspaceName = XcodeWorkspaceConfigDescription.getWorkspaceNameFromArg(workspaceArguments); Path outputDirectory;//from ww w . j av a2s.co m if (combinedProject) { workspaceName += "-Combined"; outputDirectory = BuildTargets.getGenPath(workspaceBuildTarget, "%s").getParent() .resolve(workspaceName + ".xcodeproj"); } else { outputDirectory = workspaceBuildTarget.getBasePath(); } WorkspaceGenerator workspaceGenerator = new WorkspaceGenerator(projectFilesystem, combinedProject ? "project" : workspaceName, outputDirectory); ImmutableMap.Builder<String, XcodeWorkspaceConfigDescription.Arg> schemeConfigsBuilder = ImmutableMap .builder(); ImmutableSetMultimap.Builder<String, Optional<TargetNode<?>>> schemeNameToSrcTargetNodeBuilder = ImmutableSetMultimap .builder(); ImmutableSetMultimap.Builder<String, TargetNode<?>> buildForTestNodesBuilder = ImmutableSetMultimap .builder(); ImmutableMultimap.Builder<AppleTestBundleParamsKey, TargetNode<AppleTestDescription.Arg>> groupedTestsBuilder = ImmutableMultimap .builder(); ImmutableSetMultimap.Builder<String, TargetNode<AppleTestDescription.Arg>> ungroupedTestsBuilder = ImmutableSetMultimap .builder(); buildWorkspaceSchemes(getTargetToBuildWithBuck(), projectGraph, projectGeneratorOptions.contains(ProjectGenerator.Option.INCLUDE_TESTS), projectGeneratorOptions.contains(ProjectGenerator.Option.INCLUDE_DEPENDENCIES_TESTS), groupableTests, workspaceName, workspaceArguments, schemeConfigsBuilder, schemeNameToSrcTargetNodeBuilder, buildForTestNodesBuilder, groupedTestsBuilder, ungroupedTestsBuilder); ImmutableMap<String, XcodeWorkspaceConfigDescription.Arg> schemeConfigs = schemeConfigsBuilder.build(); ImmutableSetMultimap<String, Optional<TargetNode<?>>> schemeNameToSrcTargetNode = schemeNameToSrcTargetNodeBuilder .build(); ImmutableSetMultimap<String, TargetNode<?>> buildForTestNodes = buildForTestNodesBuilder.build(); ImmutableMultimap<AppleTestBundleParamsKey, TargetNode<AppleTestDescription.Arg>> groupedTests = groupedTestsBuilder .build(); ImmutableSetMultimap<String, TargetNode<AppleTestDescription.Arg>> ungroupedTests = ungroupedTestsBuilder .build(); Iterable<PBXTarget> synthesizedCombinedTestTargets = ImmutableList.of(); ImmutableSet<BuildTarget> targetsInRequiredProjects = FluentIterable .from(Optional.presentInstances(schemeNameToSrcTargetNode.values())) .append(buildForTestNodes.values()).transform(HasBuildTarget.TO_TARGET).toSet(); ImmutableMultimap.Builder<BuildTarget, PBXTarget> buildTargetToPbxTargetMapBuilder = ImmutableMultimap .builder(); ImmutableMap.Builder<PBXTarget, Path> targetToProjectPathMapBuilder = ImmutableMap.builder(); Optional<BuildTarget> targetToBuildWithBuck = getTargetToBuildWithBuck(); if (combinedProject) { LOG.debug("Generating a combined project"); ProjectGenerator generator = new ProjectGenerator(projectGraph, targetsInRequiredProjects, projectFilesystem, outputDirectory.getParent(), workspaceName, buildFileName, projectGeneratorOptions, targetToBuildWithBuck, buildWithBuckFlags, executableFinder, environment, cxxPlatforms, defaultCxxPlatform, sourcePathResolverForNode, buckEventBus, attemptToDetermineBestCxxPlatform, halideBuckConfig, cxxBuckConfig) .setAdditionalCombinedTestTargets(groupedTests) .setTestsToGenerateAsStaticLibraries(groupableTests); combinedProjectGenerator = Optional.of(generator); generator.createXcodeProjects(); workspaceGenerator.addFilePath(generator.getProjectPath(), Optional.<Path>absent()); requiredBuildTargetsBuilder.addAll(generator.getRequiredBuildTargets()); buildTargetToPbxTargetMapBuilder.putAll(generator.getBuildTargetToGeneratedTargetMap()); for (PBXTarget target : generator.getBuildTargetToGeneratedTargetMap().values()) { targetToProjectPathMapBuilder.put(target, generator.getProjectPath()); } synthesizedCombinedTestTargets = generator.getBuildableCombinedTestTargets(); for (PBXTarget target : synthesizedCombinedTestTargets) { targetToProjectPathMapBuilder.put(target, generator.getProjectPath()); } } else { ImmutableMultimap.Builder<Path, BuildTarget> projectDirectoryToBuildTargetsBuilder = ImmutableMultimap .builder(); for (TargetNode<?> targetNode : projectGraph.getNodes()) { BuildTarget buildTarget = targetNode.getBuildTarget(); projectDirectoryToBuildTargetsBuilder.put(buildTarget.getBasePath(), buildTarget); } ImmutableMultimap<Path, BuildTarget> projectDirectoryToBuildTargets = projectDirectoryToBuildTargetsBuilder .build(); for (Path projectDirectory : projectDirectoryToBuildTargets.keySet()) { final ImmutableSet<BuildTarget> rules = filterRulesForProjectDirectory(projectGraph, ImmutableSet.copyOf(projectDirectoryToBuildTargets.get(projectDirectory))); if (Sets.intersection(targetsInRequiredProjects, rules).isEmpty()) { continue; } ProjectGenerator generator = projectGenerators.get(projectDirectory); if (generator == null) { LOG.debug("Generating project for directory %s with targets %s", projectDirectory, rules); String projectName; if (projectDirectory.getNameCount() == 0) { // If we're generating a project in the root directory, use a generic name. projectName = "Project"; } else { // Otherwise, name the project the same thing as the directory we're in. projectName = projectDirectory.getFileName().toString(); } generator = new ProjectGenerator(projectGraph, rules, projectFilesystem, projectDirectory, projectName, buildFileName, projectGeneratorOptions, Optionals.bind( targetToBuildWithBuck, new Function<BuildTarget, Optional<BuildTarget>>() { @Override public Optional<BuildTarget> apply(BuildTarget input) { return rules.contains(input) ? Optional.of(input) : Optional.<BuildTarget>absent(); } }), buildWithBuckFlags, executableFinder, environment, cxxPlatforms, defaultCxxPlatform, sourcePathResolverForNode, buckEventBus, attemptToDetermineBestCxxPlatform, halideBuckConfig, cxxBuckConfig).setTestsToGenerateAsStaticLibraries(groupableTests); generator.createXcodeProjects(); requiredBuildTargetsBuilder.addAll(generator.getRequiredBuildTargets()); projectGenerators.put(projectDirectory, generator); } else { LOG.debug("Already generated project for target %s, skipping", projectDirectory); } workspaceGenerator.addFilePath(generator.getProjectPath()); buildTargetToPbxTargetMapBuilder.putAll(generator.getBuildTargetToGeneratedTargetMap()); for (PBXTarget target : generator.getBuildTargetToGeneratedTargetMap().values()) { targetToProjectPathMapBuilder.put(target, generator.getProjectPath()); } } if (!groupedTests.isEmpty()) { ProjectGenerator combinedTestsProjectGenerator = new ProjectGenerator(projectGraph, ImmutableSortedSet.<BuildTarget>of(), projectFilesystem, BuildTargets.getGenPath(workspaceBuildTarget, "%s-CombinedTestBundles"), "_CombinedTestBundles", buildFileName, projectGeneratorOptions, Optional.<BuildTarget>absent(), buildWithBuckFlags, executableFinder, environment, cxxPlatforms, defaultCxxPlatform, sourcePathResolverForNode, buckEventBus, attemptToDetermineBestCxxPlatform, halideBuckConfig, cxxBuckConfig); combinedTestsProjectGenerator.setAdditionalCombinedTestTargets(groupedTests).createXcodeProjects(); workspaceGenerator.addFilePath(combinedTestsProjectGenerator.getProjectPath()); requiredBuildTargetsBuilder.addAll(combinedTestsProjectGenerator.getRequiredBuildTargets()); for (PBXTarget target : combinedTestsProjectGenerator.getBuildTargetToGeneratedTargetMap() .values()) { targetToProjectPathMapBuilder.put(target, combinedTestsProjectGenerator.getProjectPath()); } synthesizedCombinedTestTargets = combinedTestsProjectGenerator.getBuildableCombinedTestTargets(); for (PBXTarget target : synthesizedCombinedTestTargets) { targetToProjectPathMapBuilder.put(target, combinedTestsProjectGenerator.getProjectPath()); } this.combinedTestsProjectGenerator = Optional.of(combinedTestsProjectGenerator); } } Path workspacePath = workspaceGenerator.writeWorkspace(); final Multimap<BuildTarget, PBXTarget> buildTargetToTarget = buildTargetToPbxTargetMapBuilder.build(); final Function<BuildTarget, PBXTarget> targetNodeToPBXTargetTransformer = new Function<BuildTarget, PBXTarget>() { @Override public PBXTarget apply(BuildTarget input) { ImmutableList<PBXTarget> targets = ImmutableList.copyOf(buildTargetToTarget.get(input)); if (targets.size() == 1) { return targets.get(0); } // The only reason why a build target would map to more than one project target is if // there are two project targets: one is the usual one, the other is a target that just // shells out to Buck. Preconditions.checkState(targets.size() == 2); PBXTarget first = targets.get(0); PBXTarget second = targets.get(1); Preconditions.checkState(first.getName().endsWith(ProjectGenerator.BUILD_WITH_BUCK_POSTFIX) ^ second.getName().endsWith(ProjectGenerator.BUILD_WITH_BUCK_POSTFIX)); PBXTarget buildWithBuckTarget; PBXTarget buildWithXcodeTarget; if (first.getName().endsWith(ProjectGenerator.BUILD_WITH_BUCK_POSTFIX)) { buildWithBuckTarget = first; buildWithXcodeTarget = second; } else { buildWithXcodeTarget = first; buildWithBuckTarget = second; } return buildWithBuck ? buildWithBuckTarget : buildWithXcodeTarget; } }; writeWorkspaceSchemes(workspaceName, outputDirectory, schemeConfigs, schemeNameToSrcTargetNode, buildForTestNodes, ungroupedTests, targetToProjectPathMapBuilder.build(), synthesizedCombinedTestTargets, new Function<TargetNode<?>, Collection<PBXTarget>>() { @Override public Collection<PBXTarget> apply(TargetNode<?> input) { return buildTargetToTarget.get(input.getBuildTarget()); } }, targetNodeToPBXTargetTransformer); return workspacePath; }
From source file:org.apache.drill.exec.store.mongo.MongoFilterBuilder.java
@Override public MongoScanSpec visitFunctionCall(FunctionCall call, Void value) throws RuntimeException { MongoScanSpec nodeScanSpec = null;// ww w .j a v a 2s .c o m String functionName = call.getName(); ImmutableList<LogicalExpression> args = call.args; if (MongoCompareFunctionProcessor.isCompareFunction(functionName)) { MongoCompareFunctionProcessor processor = MongoCompareFunctionProcessor.process(call); if (processor.isSuccess()) { try { nodeScanSpec = createMongoScanSpec(processor.getFunctionName(), processor.getPath(), processor.getValue()); } catch (Exception e) { logger.error(" Failed to creare Filter ", e); // throw new RuntimeException(e.getMessage(), e); } } } else { switch (functionName) { case "booleanAnd": case "booleanOr": MongoScanSpec leftScanSpec = args.get(0).accept(this, null); MongoScanSpec rightScanSpec = args.get(1).accept(this, null); if (leftScanSpec != null && rightScanSpec != null) { nodeScanSpec = mergeScanSpecs(functionName, leftScanSpec, rightScanSpec); } else { allExpressionsConverted = false; if ("booleanAnd".equals(functionName)) { nodeScanSpec = leftScanSpec == null ? rightScanSpec : leftScanSpec; } } break; } } if (nodeScanSpec == null) { allExpressionsConverted = false; } return nodeScanSpec; }
From source file:com.google.javascript.jscomp.TypeTransformation.java
private String[] evalStringParams(Node ttlAst, NameResolver nameResolver) { ImmutableList<Node> params = getCallParams(ttlAst); int paramCount = params.size(); String[] result = new String[paramCount]; for (int i = 0; i < paramCount; i++) { result[i] = evalString(params.get(i), nameResolver); }//from ww w.jav a 2s .c o m return result; }
From source file:com.google.javascript.jscomp.TypeTransformation.java
private JSType[] evalTypeParams(Node ttlAst, NameResolver nameResolver) { ImmutableList<Node> params = getCallParams(ttlAst); int paramCount = params.size(); JSType[] result = new JSType[paramCount]; for (int i = 0; i < paramCount; i++) { result[i] = evalInternal(params.get(i), nameResolver); }//from ww w .j av a 2s . c o m return result; }
From source file:com.opengamma.strata.pricer.capfloor.SurfaceIborCapletFloorletVolatilityBootstrapDefinition.java
@Override public SurfaceMetadata createMetadata(RawOptionData capFloorData) { List<GenericVolatilitySurfacePeriodParameterMetadata> list = new ArrayList<>(); ImmutableList<Period> expiries = capFloorData.getExpiries(); int nExpiries = expiries.size(); DoubleArray strikes = capFloorData.getStrikes(); int nStrikes = strikes.size(); for (int i = 0; i < nExpiries; ++i) { for (int j = 0; j < nStrikes; ++j) { if (Double.isFinite(capFloorData.getData().get(i, j))) { list.add(GenericVolatilitySurfacePeriodParameterMetadata.of(expiries.get(i), SimpleStrike.of(strikes.get(j)))); }/*from www. j av a 2s . c o m*/ } } SurfaceMetadata metadata; if (capFloorData.getDataType().equals(ValueType.BLACK_VOLATILITY)) { metadata = Surfaces.blackVolatilityByExpiryStrike(name.getName(), dayCount); } else if (capFloorData.getDataType().equals(ValueType.NORMAL_VOLATILITY)) { metadata = Surfaces.normalVolatilityByExpiryStrike(name.getName(), dayCount); } else { throw new IllegalArgumentException("Data type not supported"); } return metadata.withParameterMetadata(list); }