Example usage for com.google.common.collect ImmutableList get

List of usage examples for com.google.common.collect ImmutableList get

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableList get.

Prototype

E get(int index);

Source Link

Document

Returns the element at the specified position in this list.

Usage

From source file:org.eigenbase.rex.RexUtil.java

/**
 * Converts a collection of expressions into an OR.
 * If there are zero expressions, returns FALSE.
 * If there is one expression, returns just that expression.
 * Removes expressions that always evaluate to FALSE.
 * Flattens expressions that are ORs.//from   w  ww.  j  a  v a  2  s  .  c  o m
 */
public static RexNode composeDisjunction(RexBuilder rexBuilder, Iterable<? extends RexNode> nodes,
        boolean nullOnEmpty) {
    ImmutableList<RexNode> list = flattenOr(nodes);
    switch (list.size()) {
    case 0:
        return nullOnEmpty ? null : rexBuilder.makeLiteral(false);
    case 1:
        return list.get(0);
    default:
        return rexBuilder.makeCall(SqlStdOperatorTable.OR, list);
    }
}

From source file:google.registry.flows.domain.DomainFlowTmchUtils.java

public SignedMark verifySignedMarks(ImmutableList<AbstractSignedMark> signedMarks, String domainLabel,
        DateTime now) throws EppException {
    if (signedMarks.size() > 1) {
        throw new TooManySignedMarksException();
    }/*from   w w  w .  j a  v a  2s  .  com*/
    if (!(signedMarks.get(0) instanceof EncodedSignedMark)) {
        throw new SignedMarksMustBeEncodedException();
    }
    return verifyEncodedSignedMark((EncodedSignedMark) signedMarks.get(0), domainLabel, now);
}

From source file:com.google.javascript.jscomp.newtypes.FunctionType.java

/**
 * Unify the two types symmetrically, given that we have already instantiated
 * the type variables of interest in {@code f1} and {@code f2}, treating
 * JSType.UNKNOWN as a "hole" to be filled.
 * @return The unified type, or null if unification fails
 *///w  w w . j av  a  2  s  . c  o m
static FunctionType unifyUnknowns(FunctionType f1, FunctionType f2) {
    Preconditions.checkState(f1 != null || f2 != null);
    if (f1 == null || f2 == null) {
        return null;
    }
    Preconditions.checkArgument(f1.typeParameters.isEmpty());
    Preconditions.checkArgument(f2.typeParameters.isEmpty());
    Preconditions.checkArgument(f1.outerVarPreconditions.isEmpty());
    Preconditions.checkArgument(f2.outerVarPreconditions.isEmpty());
    if (f1.equals(f2)) {
        return f1;
    }

    ImmutableList<JSType> formals1 = f1.requiredFormals;
    ImmutableList<JSType> formals2 = f2.requiredFormals;
    if (formals1.size() != formals2.size()) {
        return null;
    }
    FunctionTypeBuilder builder = new FunctionTypeBuilder();
    int numReqFormals = formals1.size();
    for (int i = 0; i < numReqFormals; i++) {
        JSType t = JSType.unifyUnknowns(formals1.get(i), formals2.get(i));
        if (t == null) {
            return null;
        }
        builder.addReqFormal(t);
    }

    formals1 = f1.optionalFormals;
    formals2 = f2.optionalFormals;
    if (formals1.size() != formals2.size()) {
        return null;
    }
    int numOptFormals = formals1.size();
    for (int i = 0; i < numOptFormals; i++) {
        JSType t = JSType.unifyUnknowns(formals1.get(i), formals2.get(i));
        if (t == null) {
            return null;
        }
        builder.addOptFormal(t);
    }

    if (f1.restFormals == null && f2.restFormals != null || f1.restFormals != null && f2.restFormals == null) {
        return null;
    }
    if (f1.restFormals != null) {
        JSType t = JSType.unifyUnknowns(f1.restFormals, f2.restFormals);
        if (t == null) {
            return null;
        }
        builder.addRestFormals(t);
    }

    JSType t = JSType.unifyUnknowns(f1.returnType, f2.returnType);
    if (t == null) {
        return null;
    }
    builder.addRetType(t);

    // Don't unify unknowns in nominal types; it's going to be rare.
    if (!Objects.equals(f1.nominalType, f2.nominalType)) {
        return null;
    }
    builder.addNominalType(f1.nominalType);

    if (!Objects.equals(f1.receiverType, f2.receiverType)) {
        return null;
    }
    builder.addReceiverType(f1.receiverType);

    return builder.buildFunction();
}

From source file:com.google.devtools.build.lib.syntax.Eval.java

private void execStatements(ImmutableList<Statement> statements) throws EvalException, InterruptedException {
    // Hot code path, good chance of short lists which don't justify the iterator overhead.
    for (int i = 0; i < statements.size(); i++) {
        exec(statements.get(i));
    }//from w  w w.  j  a  v a 2  s  . com
}

From source file:org.glowroot.storage.repo.helper.RollupLevelService.java

public int getGaugeRollupLevelForView(long captureTimeFrom, long captureTimeTo) throws Exception {
    long millis = captureTimeTo - captureTimeFrom;
    long timeAgoMillis = clock.currentTimeMillis() - captureTimeFrom;
    ImmutableList<Integer> rollupExpirationHours = configRepository.getStorageConfig().rollupExpirationHours();
    List<RollupConfig> rollupConfigs = configRepository.getRollupConfigs();
    // gauge point rollup level 0 shares rollup level 1's expiration
    if (millis < rollupConfigs.get(0).viewThresholdMillis()
            && HOURS.toMillis(rollupExpirationHours.get(0)) > timeAgoMillis) {
        return 0;
    }//  w  w  w . j  a v a  2  s  .com
    for (int i = 0; i < rollupConfigs.size() - 1; i++) {
        if (millis < rollupConfigs.get(i + 1).viewThresholdMillis()
                && HOURS.toMillis(rollupExpirationHours.get(i)) > timeAgoMillis) {
            return i + 1;
        }
    }
    return rollupConfigs.size();
}

From source file:com.google.errorprone.refaster.BlockTemplate.java

private Choice<List<BlockTemplateMatch>> matchesStartingAtBeginning(final JCBlock block, final int offset,
        final ImmutableList<? extends StatementTree> statements, final Context context) {
    if (statements.isEmpty()) {
        return Choice.none();
    }//  w  w  w . jav  a 2 s  . co m
    final JCStatement firstStatement = (JCStatement) statements.get(0);
    Choice<UnifierWithUnconsumedStatements> choice = Choice
            .of(UnifierWithUnconsumedStatements.create(new Unifier(context), statements));
    for (UStatement templateStatement : templateStatements()) {
        choice = choice.thenChoose(templateStatement);
    }
    return choice.thenChoose(new Function<UnifierWithUnconsumedStatements, Choice<List<BlockTemplateMatch>>>() {
        @Override
        public Choice<List<BlockTemplateMatch>> apply(UnifierWithUnconsumedStatements state) {
            Unifier unifier = state.unifier();
            Inliner inliner = unifier.createInliner();
            try {
                Optional<Unifier> checkedUnifier = typecheck(unifier, inliner, new Warner(firstStatement),
                        expectedTypes(inliner), actualTypes(inliner));
                if (checkedUnifier.isPresent()) {
                    int consumedStatements = statements.size() - state.unconsumedStatements().size();
                    BlockTemplateMatch match = new BlockTemplateMatch(block, checkedUnifier.get(), offset,
                            offset + consumedStatements);
                    return matchesStartingAnywhere(block, offset + consumedStatements,
                            statements.subList(consumedStatements, statements.size()), context)
                                    .transform(prepend(match));
                }
            } catch (CouldNotResolveImportException e) {
                // fall through
            }
            return Choice.none();
        }
    });
}

From source file:org.geogit.osm.changeset.internal.CreateOSMChangesetOp.java

/**
 * Executes the diff operation./*from ww w .j  a  va  2s.c  o m*/
 * 
 * @return an iterator to a set of differences between the two trees
 * @see DiffEntry
 */
@Override
public Iterator<ChangeContainer> call() {

    Iterator<DiffEntry> nodeIterator = command(DiffOp.class).setFilter(OSMUtils.NODE_TYPE_NAME)
            .setNewVersion(newRefSpec).setOldVersion(oldRefSpec).setReportTrees(false).call();
    Iterator<DiffEntry> wayIterator = command(DiffOp.class).setFilter(OSMUtils.WAY_TYPE_NAME)
            .setNewVersion(newRefSpec).setOldVersion(oldRefSpec).setReportTrees(false).call();
    Iterator<DiffEntry> iterator = Iterators.concat(nodeIterator, wayIterator);

    final EntityConverter converter = new EntityConverter();
    Function<DiffEntry, ChangeContainer> function = new Function<DiffEntry, ChangeContainer>() {

        @Override
        @Nullable
        public ChangeContainer apply(@Nullable DiffEntry diff) {
            NodeRef ref = diff.changeType().equals(ChangeType.REMOVED) ? diff.getOldObject()
                    : diff.getNewObject();
            RevFeature revFeature = command(RevObjectParse.class).setObjectId(ref.objectId())
                    .call(RevFeature.class).get();
            RevFeatureType revFeatureType = command(RevObjectParse.class).setObjectId(ref.getMetadataId())
                    .call(RevFeatureType.class).get();
            SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(
                    (SimpleFeatureType) revFeatureType.type());
            ImmutableList<PropertyDescriptor> descriptors = revFeatureType.sortedDescriptors();
            ImmutableList<Optional<Object>> values = revFeature.getValues();
            for (int i = 0; i < descriptors.size(); i++) {
                PropertyDescriptor descriptor = descriptors.get(i);
                Optional<Object> value = values.get(i);
                featureBuilder.set(descriptor.getName(), value.orNull());
            }
            SimpleFeature feature = featureBuilder.buildFeature(ref.name());
            Entity entity = converter.toEntity(feature);
            EntityContainer container;
            if (entity instanceof Node) {
                container = new NodeContainer((Node) entity);
            } else {
                container = new WayContainer((Way) entity);
            }

            ChangeAction action = diff.changeType().equals(ChangeType.ADDED) ? ChangeAction.Create
                    : diff.changeType().equals(ChangeType.MODIFIED) ? ChangeAction.Modify : ChangeAction.Delete;

            return new ChangeContainer(container, action);

        }

    };
    return Iterators.transform(iterator, function);
}

From source file:com.opengamma.strata.pricer.bond.DiscountingBondFutureProductPricer.java

/**
 * Calculates the price of the bond future product.
 * <p>//from  w w  w. ja v  a 2  s. c o  m
 * The price of the product is the price on the valuation date.
 * <p>
 * Strata uses <i>decimal prices</i> for bond futures. This is coherent with the pricing of {@link FixedCouponBond}.
 * For example, a price of 99.32% is represented in Strata by 0.9932.
 * 
 * @param future  the future
 * @param discountingProvider  the discounting provider
 * @return the price of the product, in decimal form
 */
public double price(ResolvedBondFuture future, LegalEntityDiscountingProvider discountingProvider) {
    ImmutableList<ResolvedFixedCouponBond> basket = future.getDeliveryBasket();
    int size = basket.size();
    double[] priceBonds = new double[size];
    for (int i = 0; i < size; ++i) {
        ResolvedFixedCouponBond bond = basket.get(i);
        double dirtyPrice = bondPricer.dirtyPriceFromCurves(bond, discountingProvider,
                future.getLastDeliveryDate());
        priceBonds[i] = bondPricer.cleanPriceFromDirtyPrice(bond, future.getLastDeliveryDate(), dirtyPrice)
                / future.getConversionFactors().get(i);
    }
    return Doubles.min(priceBonds);
}

From source file:com.epam.dlab.configuration.BillingToolConfiguration.java

/**
 * Check and return module.//from  ww w. ja v a 2  s  .c  o m
 *
 * @param modules    the list of modules.
 * @param name       the name of module.
 * @param isOptional optional module or not.
 * @return module
 * @throws InitializationException
 */
private <T extends ModuleBase> T getModule(ImmutableList<T> modules, String name, boolean isOptional)
        throws InitializationException {
    T module = (modules != null && modules.size() == 1 ? modules.get(0) : null);
    if (!isOptional && module == null) {
        throw new InitializationException("Invalid configuration for property " + name);
    }
    return module;
}

From source file:com.opengamma.strata.pricer.bond.DiscountingBondFutureProductPricer.java

/**
 * Calculates the price of the bond future product with z-spread.
 * <p>//from www.  j  av a  2s  .  com
 * The price of the product is the price on the valuation date.
 * <p>
 * The z-spread is a parallel shift applied to continuously compounded rates or periodic compounded rates 
 * of the issuer discounting curve.
 * <p>
 * Strata uses <i>decimal prices</i> for bond futures. This is coherent with the pricing of {@link FixedCouponBond}.
 * For example, a price of 99.32% is represented in Strata by 0.9932.
 * 
 * @param future  the future
 * @param discountingProvider  the discounting provider
 * @param zSpread  the z-spread
 * @param compoundedRateType  the compounded rate type
 * @param periodPerYear  the number of periods per year
 * @return the price of the product, in decimal form
 */
public double priceWithZSpread(ResolvedBondFuture future, LegalEntityDiscountingProvider discountingProvider,
        double zSpread, CompoundedRateType compoundedRateType, int periodPerYear) {

    ImmutableList<ResolvedFixedCouponBond> basket = future.getDeliveryBasket();
    int size = basket.size();
    double[] priceBonds = new double[size];
    for (int i = 0; i < size; ++i) {
        ResolvedFixedCouponBond bond = basket.get(i);
        double dirtyPrice = bondPricer.dirtyPriceFromCurvesWithZSpread(bond, discountingProvider, zSpread,
                compoundedRateType, periodPerYear, future.getLastDeliveryDate());
        priceBonds[i] = bondPricer.cleanPriceFromDirtyPrice(bond, future.getLastDeliveryDate(), dirtyPrice)
                / future.getConversionFactors().get(i);
    }
    return Doubles.min(priceBonds);
}