List of usage examples for com.google.common.collect ImmutableList get
E get(int index);
From source file:bots.mctsbot.ai.bots.bot.gametree.mcts.strategies.selection.UCTPlusPlusSelector.java
@Override public INode select(InnerNode innerNode) { ImmutableList<INode> children = innerNode.getChildren(); double[] probabilities = innerNode.getProbabilities(); double[] cumulSums = new double[children.size()]; double cumulSum = 0; for (int i = 0; i < children.size(); i++) { double weight = probabilities[i] * children.get(i).getEVStdDev(); cumulSum += weight;//from w w w . ja va 2 s. co m cumulSums[i] = cumulSum; } double randVar = random.nextDouble() * cumulSum; for (int i = 0; i < cumulSums.length; i++) { if (randVar < cumulSums[i]) { return children.get(i); } } return children.get(cumulSums.length - 1); }
From source file:org.locationtech.geogig.api.plumbing.diff.DiffPathFilter.java
/** * If this method is called then {@link #treeApplies(String)} returned {@code true} for the pair * of trees the buckets belong to, meaning that {@code treePath} either matches exactly one of * the filters, or is a filter children. If the former, all tree buckets apply. If the later, * only the ones whose simple name/* www . ja v a 2 s . c om*/ * <ul> * <li>a filter refers to exactly the same tree than {@code treePath}, in which case all buckets * apply * <li>a filter is a child of {@code treePath}, in which case the bucket applies * </ul> * * @param treePath the path of the tree the bucket belong to * @param bucketIndex * @param bucketDepth * @return */ public boolean bucketApplies(final String treePath, final int bucketIndex, final int bucketDepth) { String filter; for (int i = 0; i < pathFilters.size(); i++) { filter = pathFilters.get(i); if (filter.equals(treePath)) { // all buckets apply if (LOGGER.isTraceEnabled()) { LOGGER.trace("Filter: '{}', tree: '{}', depth: {}, bucket idx {}, applies: {}", filter, treePath, bucketDepth, bucketIndex, true); } return true; } boolean filterIsChildOfTree = NodeRef.isChild(treePath, filter); if (filterIsChildOfTree) { ImmutableList<String> filterSteps = NodeRef.split(filter); ImmutableList<String> treeSteps = NodeRef.split(treePath); String childName = filterSteps.get(treeSteps.size()); int childBucket = ORDER.bucket(childName, bucketDepth); boolean applies = childBucket == bucketIndex; if (LOGGER.isTraceEnabled()) { LOGGER.trace( "Filter: '{}', tree: '{}', depth: {}, bucket idx {}, child bucket: {}, child name: '{}', applies: {}", filter, treePath, bucketDepth, bucketIndex, childBucket, childName, applies); } if (applies) { return true; } } } return false; }
From source file:org.locationtech.geogig.plumbing.diff.DiffPathFilter.java
/** * If this method is called then {@link #treeApplies(String)} returned {@code true} for the pair * of trees the buckets belong to, meaning that {@code treePath} either matches exactly one of * the filters, or is a filter children. If the former, all tree buckets apply. If the later, * only the ones whose simple name/* w ww. ja va2 s . c o m*/ * <ul> * <li>a filter refers to exactly the same tree than {@code treePath}, in which case all buckets * apply * <li>a filter is a child of {@code treePath}, in which case the bucket applies * </ul> * * @param treePath the path of the tree the bucket belong to * @param bucketIndex * @return */ public boolean bucketApplies(final String treePath, final BucketIndex bucketIndex) { String filter; for (int i = 0; i < pathFilters.size(); i++) { filter = pathFilters.get(i); if (filter.equals(treePath)) { // all buckets apply if (LOGGER.isTraceEnabled()) { LOGGER.trace("Filter: '{}', tree: '{}', bucket idx {}, applies: {}", filter, treePath, bucketIndex, true); } return true; } boolean filterIsChildOfTree = NodeRef.isChild(treePath, filter); if (filterIsChildOfTree) { ImmutableList<String> filterSteps = NodeRef.split(filter); ImmutableList<String> treeSteps = NodeRef.split(treePath); String childName = filterSteps.get(treeSteps.size()); int childBucket = ORDER.bucket(childName, bucketIndex.depthIndex()); boolean applies = childBucket == bucketIndex.lastIndex().intValue(); if (LOGGER.isTraceEnabled()) { LOGGER.trace( "Filter: '{}', tree: '{}', bucket idx {}, child bucket: {}, child name: '{}', applies: {}", filter, treePath, bucketIndex, childBucket, childName, applies); } if (applies) { return true; } } } return false; }
From source file:com.opengamma.strata.pricer.calibration.SyntheticCurveCalibrator.java
/** * Constructs the synthetic market data from an existing rates provider and the configuration of the new curves. * /* w w w . j av a2 s . c o m*/ * @param inputMulticurve the input rates provider * @param group the curve group definition for the synthetic curves and instruments * @return the market data */ public MarketData marketData(RatesProvider inputMulticurve, CurveGroupDefinition group) { LocalDate valuationDate = inputMulticurve.getValuationDate(); ImmutableList<NodalCurveDefinition> curveGroups = group.getCurveDefinitions(); // Create fake market quotes of 0, only to be able to generate trades Map<MarketDataKey<?>, Double> mapKey0 = new HashMap<>(); for (NodalCurveDefinition entry : curveGroups) { ImmutableList<CurveNode> nodes = entry.getNodes(); for (int i = 0; i < nodes.size(); i++) { for (SimpleMarketDataKey<?> key : nodes.get(i).requirements()) { mapKey0.put(key, 0.0d); } } } ImmutableMarketData marketQuotes0 = ImmutableMarketData.of(valuationDate, mapKey0); // Generate market quotes from the trades Map<MarketDataKey<?>, Double> mapKeySy = new HashMap<>(); for (NodalCurveDefinition entry : curveGroups) { ImmutableList<CurveNode> nodes = entry.getNodes(); for (CurveNode node : nodes) { Trade trade = node.trade(valuationDate, marketQuotes0); double mq = measures.value(trade, inputMulticurve); MarketDataKey<?> k = node.requirements().iterator().next(); mapKeySy.put(k, mq); } } return ImmutableMarketData.of(valuationDate, mapKeySy); }
From source file:org.jclouds.compute.functions.NodeAndTemplateOptionsToStatementWithoutPublicKey.java
@Override public Statement apply(NodeMetadata node, TemplateOptions options) { ImmutableList.Builder<Statement> builder = ImmutableList.builder(); if (options.getRunScript() != null) { builder.add(options.getRunScript()); }//w w w . j av a 2 s . c o m if (options.getPrivateKey() != null) { builder.add(new InstallRSAPrivateKey(options.getPrivateKey())); } ImmutableList<Statement> bootstrap = builder.build(); if (!bootstrap.isEmpty()) { if (options.getTaskName() == null && !(options.getRunScript() instanceof InitScript)) { options.nameTask("bootstrap"); } return bootstrap.size() == 1 ? bootstrap.get(0) : new StatementList(bootstrap); } return null; }
From source file:org.jclouds.digitalocean.compute.functions.TemplateOptionsToStatementWithoutPublicKey.java
@Override public Statement apply(TemplateOptions options) { ImmutableList.Builder<Statement> builder = ImmutableList.builder(); if (options.getRunScript() != null) { builder.add(options.getRunScript()); }//from w w w . j av a 2 s . c o m if (options.getPrivateKey() != null) { builder.add(new InstallRSAPrivateKey(options.getPrivateKey())); } ImmutableList<Statement> bootstrap = builder.build(); if (!bootstrap.isEmpty()) { if (options.getTaskName() == null && !(options.getRunScript() instanceof InitScript)) { options.nameTask("bootstrap"); } return bootstrap.size() == 1 ? bootstrap.get(0) : new StatementList(bootstrap); } return null; }
From source file:com.google.gerrit.metrics.dropwizard.TimerImplN.java
@SuppressWarnings("unchecked") @Override/* w ww . j ava 2 s.c om*/ String name(Object key) { ImmutableList<Object> keyList = (ImmutableList<Object>) key; String[] parts = new String[fields.length]; for (int i = 0; i < fields.length; i++) { Function<Object, String> fmt = (Function<Object, String>) fields[i].formatter(); parts[i] = fmt.apply(keyList.get(i)).replace('/', '-'); } return Joiner.on('/').join(parts); }
From source file:com.facebook.buck.rules.macros.QueryOutputsMacroExpander.java
@Override public ImmutableList<BuildRule> extractBuildTimeDeps(BuildTarget target, CellPathResolver cellNames, final BuildRuleResolver resolver, ImmutableList<String> input) throws MacroException { if (input.isEmpty()) { throw new MacroException("One quoted query expression is expected with optional flags"); }//from w ww . ja v a 2s .com String queryExpression = CharMatcher.anyOf("\"'").trimFrom(input.get(0)); return ImmutableList.copyOf(resolveQuery(target, cellNames, resolver, queryExpression).map(queryTarget -> { Preconditions.checkState(queryTarget instanceof QueryBuildTarget); return resolver.getRule(((QueryBuildTarget) queryTarget).getBuildTarget()); }).sorted().collect(Collectors.toList())); }
From source file:com.facebook.buck.rules.macros.BuildTargetMacroExpander.java
@Override protected BuildTarget parse(BuildTarget target, CellPathResolver cellNames, ImmutableList<String> input) throws MacroException { if (input.size() != 1) { throw new MacroException(String.format("expected a single argument: %s", input)); }//ww w. j a v a 2s .co m try { return BuildTargetParser.INSTANCE.parse(input.get(0), BuildTargetPatternParser.forBaseName(target.getBaseName()), cellNames); } catch (BuildTargetParseException e) { throw new MacroException(e.getMessage(), e); } }
From source file:org.nmdp.service.epitope.service.EpitopeServiceImpl.java
/** * {@inheritDoc}/*from w ww . java 2 s . co m*/ */ @Override public Integer getGroupForAllele(Allele allele) { ImmutableList<Integer> list = alleleGroupMap.get(allele); if (list.size() == 0) return null; // throw new RuntimeException("no group for allele: " + allele); return list.get(0); }