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

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

Introduction

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

Prototype

public static <T> T get(Iterable<T> iterable, int position) 

Source Link

Document

Returns the element at the specified position in an iterable.

Usage

From source file:org.icgc.dcc.portal.util.ElasticsearchResponseUtils.java

public static Boolean getBoolean(Object values) {
    val defaultValue = false;

    if (values == null) {
        return defaultValue;
    }//  ww  w  .  j  ava  2  s. c  o  m

    if (values instanceof Boolean) {
        return (Boolean) values;
    }

    if (values instanceof Iterable<?>) {
        val iterable = (Iterable<?>) values;
        return Iterables.isEmpty(iterable) ? defaultValue : Boolean.TRUE.equals(Iterables.get(iterable, 0));
    }

    return defaultValue;
}

From source file:org.jclouds.vcloud.director.v1_5.compute.util.VCloudDirectorComputeUtils.java

public static Set<String> getIpsFromVApp(VApp vApp) {
    // TODO make this work with composite vApps
    if (vApp.getChildren().getVms().size() == 0)
        return ImmutableSet.of();
    return getIpsFromVm(Iterables.get(vApp.getChildren().getVms(), 0));
}

From source file:com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider.java

public static JavaCompilationArgsProvider merge(Collection<JavaCompilationArgsProvider> providers) {
    if (providers.size() == 1) {
        return Iterables.get(providers, 0);
    }//  w  w w. ja v  a  2  s  .  co  m

    JavaCompilationArgs.Builder javaCompilationArgs = JavaCompilationArgs.builder();
    JavaCompilationArgs.Builder recursiveJavaCompilationArgs = JavaCompilationArgs.builder();
    NestedSetBuilder<Artifact> compileTimeJavaDepArtifacts = NestedSetBuilder.stableOrder();

    for (JavaCompilationArgsProvider provider : providers) {
        javaCompilationArgs.addTransitiveArgs(provider.getJavaCompilationArgs(),
                JavaCompilationArgs.ClasspathType.BOTH);
        recursiveJavaCompilationArgs.addTransitiveArgs(provider.getRecursiveJavaCompilationArgs(),
                JavaCompilationArgs.ClasspathType.BOTH);
        compileTimeJavaDepArtifacts.addTransitive(provider.getCompileTimeJavaDependencyArtifacts());
    }

    return JavaCompilationArgsProvider.create(javaCompilationArgs.build(), recursiveJavaCompilationArgs.build(),
            compileTimeJavaDepArtifacts.build());
}

From source file:blue.lapis.pore.impl.inventory.PorePlayerInventory.java

@Override
public void setBoots(ItemStack boots) {
    Iterables.get(this.getHandle().query(EquipmentTypes.BOOTS).<Slot>slots(), 0)
            .set(ItemStackConverter.of(boots));
}

From source file:org.jclouds.ec2.compute.loaders.CreateSecurityGroupIfNeeded.java

protected void authorizeGroupToItself(String region, String name) {
    logger.debug(">> authorizing securityGroup region(%s) name(%s) permission to itself", region, name);
    String myOwnerId = Iterables.get(securityClient.describeSecurityGroupsInRegion(region, name), 0)
            .getOwnerId();/* www .  jav  a 2s  .c o  m*/
    securityClient.authorizeSecurityGroupIngressInRegion(region, name, new UserIdGroupPair(myOwnerId, name));
    logger.debug("<< authorized securityGroup(%s)", name);
}

From source file:com.yahoo.yqlplus.engine.rules.FallbackPushDown.java

private OperatorNode<SequenceOperator> replaceArgument(OperatorNode<SequenceOperator> current,
        OperatorNode<SequenceOperator> input, int i, OperatorNode<SequenceOperator> replacement) {
    // if current has an alias, and we are pushing a node "through" it, we need to mutate any field references we push through
    // an alias operator will "flatten" which may mean we have to disambiguate which field of the underlying input
    // is intended
    // .. which we can't do without the schemas, which we do not have at this point
    // .. feh/*from  ww w .ja  v  a  2  s  .  c  om*/
    // OK, make it work for the single-visible-alias case and think about how to address the general case
    OperatorNode<SequenceOperator> result = OperatorNode.create(input.getLocation(), input.getAnnotations(),
            input.getOperator(), replace(input.getArguments(), i, replacement));
    if (current.getAnnotation("alias") != null) {
        Set<String> visible = findSources(result);
        //noinspection StatementWithEmptyBody
        if (visible.isEmpty()) {
            // is this even possible?
        } else if (visible.size() > 1) {
            throw new ProgramCompileException(
                    "Pushing transforms below FALLBACK operators with multiple visible aliases not yet supported");
        } else { // visible.size() == 1
            final String oldAlias = (String) current.getAnnotation("alias");
            final String newAlias = Iterables.get(visible, 0);
            result = result.transform(new Function<Object, Object>() {
                @Nullable
                @Override
                public Object apply(@Nullable Object input) {
                    if (input instanceof OperatorNode) {
                        if (ExpressionOperator.IS.apply((OperatorNode<? extends Operator>) input)) {
                            OperatorNode<ExpressionOperator> expr = (OperatorNode<ExpressionOperator>) input;
                            if (expr.getOperator() == ExpressionOperator.READ_FIELD
                                    || expr.getOperator() == ExpressionOperator.READ_RECORD) {
                                String refAlias = expr.getArgument(0);
                                if (refAlias.equals(oldAlias)) {
                                    return OperatorNode.create(expr.getLocation(), expr.getAnnotations(),
                                            expr.getOperator(), replace(expr.getArguments(), 0, newAlias));
                                }
                            }
                        }
                        return ((OperatorNode<? extends Operator>) input).transform(this);
                    } else {
                        return input;
                    }
                }
            });

        }
    }
    return result;
}

From source file:com.replaymod.replaystudio.pathing.interpolation.CatmullRomSplineInterpolator.java

protected void calcPolynomials() {
    for (Map.Entry<Property<?>, Set<Keyframe>> e : framesToProperty.entrySet()) {
        Property<?> property = e.getKey();
        Set<Keyframe> keyframes = e.getValue();

        for (PropertyPart<?> part : property.getParts()) {
            if (!part.isInterpolatable())
                continue;

            Polynomial[] polynomials = new Polynomial[keyframes.size() - 1];

            for (int i = 0; i < keyframes.size() - 1; i++) {
                Keyframe k0, k1, k2, k3;

                k1 = Iterables.get(keyframes, i);
                k2 = Iterables.get(keyframes, i + 1);

                if (i > 0) {
                    k0 = Iterables.get(keyframes, i - 1);
                } else {
                    k0 = k1;/*from   www.ja v  a 2  s  . c  o  m*/
                }

                if (i < keyframes.size() - 2) {
                    k3 = Iterables.get(keyframes, i + 2);
                } else {
                    k3 = k2;
                }

                double p0 = getValueAsDouble(k0, part);
                double p1 = getValueAsDouble(k1, part);
                double p2 = getValueAsDouble(k2, part);
                double p3 = getValueAsDouble(k3, part);

                double t0 = alpha * (p2 - p0);
                double t1 = alpha * (p3 - p1);

                double[] c = new double[] { 2 * p1 - 2 * p2 + t0 + t1, -3 * p1 + 3 * p2 - 2 * t0 - t1, t0, p1 };

                polynomials[i] = new Polynomial(c);
            }

            cubicPolynomials.put(part, polynomials);
        }
    }
}

From source file:org.jclouds.gogrid.GoGridLiveTestDisabled.java

@Test(enabled = true)
public void testDescriptionIs500Characters() {
    final String nameOfServer = "Description" + String.valueOf(new Date().getTime()).substring(6);
    serversToDeleteAfterTheTests.add(nameOfServer);

    Set<Ip> availableIps = api.getIpServices().getUnassignedPublicIpList();
    Ip availableIp = Iterables.getLast(availableIps);

    String ram = Iterables.get(api.getServerServices().getRamSizes(), 0).getName();
    StringBuilder builder = new StringBuilder();

    for (int i = 0; i < 500; i++)
        builder.append('a');

    String description = builder.toString();

    Server createdServer = api.getServerServices().addServer(nameOfServer,
            "GSI-f8979644-e646-4711-ad58-d98a5fa3612c", ram, availableIp.getIp(),
            new AddServerOptions().withDescription(description));
    assertNotNull(createdServer);//from  ww  w.  j  a v a2s .co  m
    assert serverLatestJobCompleted.apply(createdServer);

    assertEquals(Iterables.getLast(api.getServerServices().getServersByName(nameOfServer)).getDescription(),
            description);

}

From source file:com.mmounirou.spotirss.spotify.tracks.SpotifyHrefQuery.java

private XTracks findBestMatchingTrack(List<XTracks> xtracks, final Track track) {
    if (xtracks.size() == 1) {
        return xtracks.get(0);
    }/*from   ww  w. ja va  2s.c  om*/

    TreeMap<Integer, XTracks> sortedTrack = Maps.newTreeMap();
    for (XTracks xTrack : xtracks) {
        sortedTrack.put(getLevenshteinDistance(xTrack, track), xTrack);
    }

    Integer minDistance = Iterables.get(sortedTrack.keySet(), 0);
    XTracks choosedTrack = sortedTrack.get(minDistance);

    if (minDistance > 1) {
        SpotiRss.LOGGER.info(String.format("(%s:%s) choosed for (%s:%s) with distance %d",
                choosedTrack.getOriginalTrackName(), Joiner.on(",").join(choosedTrack.getAllArtists()),
                track.getSong(), Joiner.on(",").join(track.getArtists()), minDistance));
    } else {
        SpotiRss.LOGGER.debug(String.format("(%s:%s) choosed for (%s:%s) with distance %d",
                choosedTrack.getOriginalTrackName(), Joiner.on(",").join(choosedTrack.getAllArtists()),
                track.getSong(), Joiner.on(",").join(track.getArtists()), minDistance));
    }

    return choosedTrack;
}

From source file:org.sosy_lab.cpachecker.cpa.value.symbolic.refiner.ValueTransferBasedStrongestPostOperator.java

@Override
public Optional<ForgettingCompositeState> getStrongestPost(final ForgettingCompositeState pOrigin,
        final Precision pPrecision, final CFAEdge pOperation) throws CPAException, InterruptedException {

    ValueAnalysisState oldValues = getValueStateOfCompositeState(pOrigin);
    ConstraintsState oldConstraints = getConstraintsStateOfCompositeState(pOrigin);

    assert oldValues != null && oldConstraints != null;

    final Collection<ValueAnalysisState> successors = valueTransfer.getAbstractSuccessorsForEdge(oldValues,
            pPrecision, pOperation);// w ww  . j  a v  a 2 s. co  m

    if (isContradiction(successors)) {
        return Optional.absent();

    } else {
        final ValueAnalysisState valuesSuccessor = Iterables.getOnlyElement(successors);

        Collection<? extends AbstractState> constraintsSuccessors = constraintsTransfer
                .getAbstractSuccessorsForEdge(oldConstraints, SingletonPrecision.getInstance(), pOperation);

        if (isContradiction(constraintsSuccessors)) {
            return Optional.absent();
        }

        final ConstraintsState constraintsSuccessor = (ConstraintsState) Iterables.get(constraintsSuccessors,
                0);

        Optional<ConstraintsState> constraintsStrengthenResult = strengthenConstraintsState(
                constraintsSuccessor, valuesSuccessor, pOperation);

        if (!constraintsStrengthenResult.isPresent()) {
            return Optional.absent();

        } else {
            Optional<ValueAnalysisState> valueStrengthenResult = strengthenValueState(valuesSuccessor,
                    constraintsSuccessor, pPrecision, pOperation);

            if (!valueStrengthenResult.isPresent()) {
                return Optional.absent();
            }

            return Optional
                    .of(getNewCompositeState(valueStrengthenResult.get(), constraintsStrengthenResult.get()));
        }
    }
}