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:com.supaham.commons.bukkit.area.Poly2DRegion.java

/**
 * Constructs a 2D polygonal region out of a collection of {@link Vector}s and a min & max y
 * coordinate./*from   w  w w .jav a2  s . co  m*/
 *
 * @param points points to define the polygonal region
 * @param minY minimum level on the y axis
 * @param maxY maximum level on the y axis
 *
 * @see #fromLocations(Collection, int, int)
 */
public Poly2DRegion(@Nonnull Collection<Vector> points, int minY, int maxY) {
    Preconditions.checkNotNull(points, "points cannot be null.");
    Preconditions.checkArgument(minY >= 0, "minY cannot be smaller than 0.");
    Preconditions.checkArgument(maxY >= 0, "maxY cannot be smaller than 0.");
    this.points = points;
    Iterator<Vector> it = points.iterator();
    int minX = Iterables.get(points, 0).getBlockX();
    int minZ = Iterables.get(points, 0).getBlockZ();
    int maxX = minX;
    int maxZ = minZ;

    while (it.hasNext()) {
        Vector next = it.next();
        int x = next.getBlockX();
        int z = next.getBlockZ();
        if (x < minX) {
            minX = x;
        } else if (x > maxX) {
            maxX = x;
        }
        if (z < minZ) {
            minZ = z;
        } else if (z > maxZ) {
            maxZ = z;
        }
    }
}

From source file:net.holmes.core.business.streaming.airplay.controlpoint.CommandResponse.java

/**
 * Decode Http response.//from  w ww.ja  va 2s.  c  o m
 *
 * @param responseLines response lines
 */
public void decodeHttpResponse(final List<String> responseLines) {
    // Decode http response on first line
    Matcher matcher = HTTP_RESPONSE_PATTERN.matcher(responseLines.get(0));
    if (matcher.find()) {
        code = Integer.valueOf(matcher.group(2));
        message = matcher.group(3);
    }

    // Decode http headers on next lines
    for (int i = 1; i < responseLines.size(); i++) {
        Iterable<String> it = Splitter.on(PARAMETER_SEPARATOR).trimResults().split(responseLines.get(i));
        httpHeaders.put(Iterables.get(it, 0), Iterables.getLast(it));
    }
}

From source file:org.spongepowered.common.data.processor.data.item.CookedFishDataProcessor.java

@Override
protected Optional<CookedFish> getVal(ItemStack itemStack) {
    return Optional
            .of(Iterables.get(SpongeImpl.getRegistry().getAllOf(CookedFish.class), itemStack.getMetadata()));
}

From source file:org.sonar.java.checks.SelectorMethodArgumentCheck.java

@Override
public void visitNode(Tree tree) {
    if (!hasSemantic()) {
        return;//from ww  w.  j a  v a2 s  .  c  om
    }
    MethodTree methodTree = (MethodTree) tree;
    if (Boolean.TRUE.equals(((MethodTreeImpl) methodTree).isOverriding())) {
        return;
    }
    List<Symbol> booleanParameterSymbols = getBooleanParametersAsSymbol(methodTree.parameters());
    BlockTree blockTree = methodTree.block();

    if (isPublic(methodTree) && blockTree != null && !booleanParameterSymbols.isEmpty()) {
        for (Symbol variable : booleanParameterSymbols) {
            Collection<IdentifierTree> usages = variable.usages();
            if (usages.size() == 1) {
                blockTree.accept(
                        new ConditionalStatementVisitor(variable.name(), Iterables.get(usages, 0), methodTree));
            }
        }
    }
}

From source file:org.jclouds.openstack.keystone.v1_1.suppliers.V1DefaultRegionIdSupplier.java

/**
 * returns {@link Endpoint#isV1Default()} or first endpoint for service
 *///from w  w  w.j av  a 2  s. com
@Override
public String get() {
    Auth authResponse = auth.get();
    Iterable<Endpoint> endpointsForService = authResponse.getServiceCatalog().get(apiType);
    Optional<Endpoint> defaultEndpoint = tryFind(endpointsForService, new Predicate<Endpoint>() {
        @Override
        public boolean apply(Endpoint in) {
            return in.isV1Default();
        }
    });
    return endpointToRegion.apply(defaultEndpoint.or(Iterables.get(endpointsForService, 0)));
}

From source file:com.google.errorprone.bugpatterns.collectionincompatibletype.TypeArgOfMethodArgMatcher.java

@Override
ExpressionTree extractSourceTree(MethodInvocationTree tree, VisitorState state) {
    return Iterables.get(tree.getArguments(), methodArgIndex);
}

From source file:com.anathema_roguelike.main.ui.uielements.interactiveuielements.SelectionScreen.java

private void init(Iterable<T> choices, Message instructionsMessage, boolean cancellable,
        float contentBackground) {
    int x = getX() + (int) (getWidth() * .05);
    int y = getY() + (int) (getHeight() * .2);
    menu = new SelectionMenu<T>(x, y, (int) (getWidth() * .3), getHeight() / 2, false, 1, choices, cancellable,
            contentBackground);/*from w  ww  .j  a v a2  s. c o m*/

    description = new MenuDescription<T>(menu,
            Iterables.isEmpty(choices) ? null : Utils.getSuperclass(Iterables.get(choices, 0)));

    if (instructionsMessage != null) {
        instructions = new TextBox(x, y - 2, menu.getWidth() + description.getWidth(), 1, instructionsMessage,
                contentBackground);
        addUIElement(instructions);
    }

    addUIElement(description);
    setFocusedUIElement(menu);
}

From source file:de.bloxel.engine.material.ColorBloxelAssetManager.java

/**
 * @param theAssetManager/*  w ww  .j a v a2s.  co  m*/
 *          for loading textures etc.
 */
public ColorBloxelAssetManager(final AssetManager theAssetManager) {
    this.assetManager = theAssetManager;
    try {
        final Properties p = new Properties();
        p.load(new ClassPathResource(COLORMAP_PROPERTIES).getInputStream());
        final Set<Entry<Object, Object>> definitions = p.entrySet();
        for (final Entry<Object, Object> d : definitions) {
            final Integer bloxelType = Integer.valueOf(d.getKey().toString());
            final String value = String.format("%s", d.getValue());
            final Iterable<String> rgb = Splitter.on(",").split(value);
            final float r = Integer.valueOf(Iterables.get(rgb, 0));
            final float g = Integer.valueOf(Iterables.get(rgb, 1));
            final float b = Integer.valueOf(Iterables.get(rgb, 2));
            colormap.put(new MapKey(bloxelType, -1), new ColorRGBA(r, g, b, 1f));
        }
    } catch (final IOException e) {
        throw new RuntimeException(
                format("Can't load bloxel definition file '%s' from classpath", COLORMAP_PROPERTIES), e);
    }
    theAssetManager.registerLocator("/de/bloxel/engine/material/", ClasspathLocator.class);
}

From source file:com.eucalyptus.autoscaling.common.AutoScalingResourceName.java

public static AutoScalingResourceName parse(final String resourceName, @Nullable final Type type)
        throws InvalidResourceNameException {
    if (!resourceName.startsWith(prefix)) {
        throw new InvalidResourceNameException(resourceName);
    }//from   w  ww  . j  a v a  2  s.  c o  m

    final Iterable<String> nameParts = nameSpliter.split(resourceName);
    final int namePartCount = Iterables.size(nameParts);
    if (namePartCount < 8 || namePartCount > 9) {
        throw new InvalidResourceNameException(resourceName);
    }

    if (!"autoscaling".equals(Iterables.get(nameParts, PART_SERVICE))) {
        throw new InvalidResourceNameException(resourceName);
    }

    if (type != null && !type.name().equals(Iterables.get(nameParts, PART_RELATIVE_ID_TYPE))) {
        throw new InvalidResourceNameException(resourceName);
    }

    return new AutoScalingResourceName(resourceName, Iterables.get(nameParts, PART_SERVICE),
            Iterables.get(nameParts, PART_NAMESPACE), Iterables.get(nameParts, PART_RELATIVE_ID_TYPE),
            Iterables.get(nameParts, PART_RELATIVE_ID_UUID), Iterables.get(nameParts, PART_RELATIVE_NAME_1),
            namePartCount > PART_RELATIVE_NAME_2 ? Iterables.get(nameParts, PART_RELATIVE_NAME_2) : null);
}

From source file:de.lgblaumeiser.ptm.analysis.analyzer.ProjectComputer.java

private Collection<Booking> getRelevantBookings(final Collection<String> dayOrMonthParameter) {
    if (dayOrMonthParameter.size() > 0) {
        String dayOrMonthString = Iterables.get(dayOrMonthParameter, 0);
        if (dayOrMonthString.length() == 10) {
            return getBookingsForDay(LocalDate.parse(dayOrMonthString));
        }//from  w  ww  .  j  av a 2 s .  c  om
        if (dayOrMonthString.length() == 7) {
            return getBookingsForMonth(YearMonth.parse(dayOrMonthString));
        }
    }
    return getBookingsForMonth(YearMonth.now());
}