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:google.registry.rdap.RdapJsonFormatter.java

/**
 * Creates a vCard address entry: array of strings specifying the components of the address.
 *
 * @see <a href="https://tools.ietf.org/html/rfc7095">
 *        RFC 7095: jCard: The JSON Format for vCard</a>
 *///from ww  w  . ja  v a2s  .co m
private static ImmutableList<Object> makeVCardAddressEntry(Address address) {
    if (address == null) {
        return null;
    }
    ImmutableList.Builder<Object> jsonBuilder = new ImmutableList.Builder<>();
    jsonBuilder.add(""); // PO box
    jsonBuilder.add(""); // extended address

    // The vCard spec allows several different ways to handle multiline street addresses. Per
    // Gustavo Lozano of ICANN, the one we should use is an embedded array of street address lines
    // if there is more than one line:
    //
    //   RFC7095 provides two examples of structured addresses, and one of the examples shows a
    //   street JSON element that contains several data elements. The example showing (see below)
    //   several data elements is the expected output when two or more <contact:street> elements
    //   exists in the contact object.
    //
    //   ["adr", {}, "text",
    //    [
    //    "", "",
    //    ["My Street", "Left Side", "Second Shack"],
    //    "Hometown", "PA", "18252", "U.S.A."
    //    ]
    //   ]
    ImmutableList<String> street = address.getStreet();
    if (street.isEmpty()) {
        jsonBuilder.add("");
    } else if (street.size() == 1) {
        jsonBuilder.add(street.get(0));
    } else {
        jsonBuilder.add(street);
    }
    jsonBuilder.add(nullToEmpty(address.getCity()));
    jsonBuilder.add(nullToEmpty(address.getState()));
    jsonBuilder.add(nullToEmpty(address.getZip()));
    jsonBuilder.add(new Locale("en", address.getCountryCode()).getDisplayCountry(new Locale("en")));
    return ImmutableList.<Object>of("adr", ImmutableMap.of(), "text", jsonBuilder.build());
}

From source file:com.liveramp.megadesk.recipes.queue.Queue.java

@Override
protected VALUE internalRead(ImmutableList<VALUE> transfer) {
    if (transfer.isEmpty()) {
        return null;
    } else {/*from w w w . j ava  2  s  . c  om*/
        return transfer.get(0);
    }
}

From source file:uk.q3c.krail.core.option.hierarchy.SimpleUserHierarchy.java

@Override
public synchronized String highestRankName() {
    ImmutableList<String> ranks = ranksForCurrentUser();
    return ranks.get(0);
}

From source file:uk.q3c.krail.core.option.hierarchy.SimpleUserHierarchy.java

@Override
public synchronized String lowestRankName() {
    ImmutableList<String> ranks = ranksForCurrentUser();
    return ranks.get(ranks.size() - 1);
}

From source file:org.xlrnet.tibaija.commands.io.OutputCommand.java

/**
 * Main method for invoking a command. Must be overwritten by the specific implementation. When this method gets
 * called by the framework, both hasValidArgumentValues() and hasValidNumberOfArguments() have already been called.
 *
 * @param arguments/*from w  w w  . ja  v a  2 s .  c  om*/
 *         The arguments for the command.
 * @return An optional return value.
 */
@NotNull
@Override
protected Optional<Value> execute(@NotNull ImmutableList<Parameter> arguments) {
    double rowIndex = arguments.get(0).value().realPart();
    double columnIndex = arguments.get(1).value().realPart();
    Value printValue = arguments.get(2).value();

    getEnvironment().getHomeScreen().printAt(printValue, (int) columnIndex, (int) rowIndex);

    return Optional.empty();
}

From source file:ratpack.registry.internal.DefaultRegistryBuilder.java

@Override
public Registry build() {
    ImmutableList<RegistryEntry<?>> entries = builder.build();
    if (entries.size() == 1) {
        return new SingleEntryRegistry(entries.get(0));
    } else {/*w  w  w  .  ja v a2  s .  c  o  m*/
        return CachingRegistry.of(new MultiEntryRegistry(entries.reverse()));
    }
}

From source file:uk.q3c.krail.core.user.profile.SimpleUserHierarchy.java

/**
 * Returns the identifier of the {@code hierarchyRank}, for the current user.  From the example given in the
 * {@link Option} javadoc, above that could be 'Development' if an implementation represented an Organisation,
 * and the current user is Emily//from  w  w  w .  j  a va  2s. c o  m
 *
 * @param hierarchyRank
 *         the rank (index) which is required.
 *
 * @return the rank name, for the current user, at the rank specified by {@code hierarchyRank}.
 *
 * @throws IllegalArgumentException
 *         if {@code hierarchyRank} is out of bounds
 */
@Override
public synchronized String rankName(int hierarchyRank) {
    checkArgument(hierarchyRank >= 0, "hierarchyRank must be 0 or greater");
    ImmutableList<String> ranks = ranksForCurrentUser();
    try {
        return ranks.get(hierarchyRank);
    } catch (IndexOutOfBoundsException e) {
        throw new IllegalArgumentException("Hierarchy level of " + hierarchyRank + " is too high");
    }
}

From source file:org.xlrnet.tibaija.commands.io.OutputCommand.java

/**
 * Can be overwritten by the concrete commands if at least the value of one parameter must be checked.
 * Checks all values of all passed parameters.
 * An explaining error message must be output by the concrete command.<br>
 *
 * @param arguments/* ww  w. j a  v a 2 s. c  o m*/
 *         The immutable list of parameters to check.
 * @return True if all values of all passed parameters are correct. False if at least one value of one parameter is
 * incorrect.
 */
@Override
protected boolean hasValidArgumentValues(@NotNull ImmutableList<Parameter> arguments) {
    Value rowIndex = arguments.get(0).value();
    Value columnIndex = arguments.get(1).value();

    Preconditions.checkValueType(rowIndex, Variables.VariableType.NUMBER);
    Preconditions.checkValueType(columnIndex, Variables.VariableType.NUMBER);

    checkArgument(!rowIndex.hasImaginaryValue(), "Row index may not be imaginary");
    checkArgument(!columnIndex.hasImaginaryValue(), "Column index may not be imaginary");

    // Check for value bounds on row index
    if (!NumberUtils.isInteger(rowIndex.realPart()) || rowIndex.realPart() < 0
            || rowIndex.realPart() > getEnvironment().getHomeScreen().getMaxRows()) {
        return false;
    }

    // Check for value bounds on column index
    if (!NumberUtils.isInteger(columnIndex.realPart()) || columnIndex.realPart() < 0
            || columnIndex.realPart() > getEnvironment().getHomeScreen().getMaxColumns()) {
        return false;
    }

    return true;
}

From source file:uk.q3c.krail.core.option.hierarchy.SimpleUserHierarchy.java

/**
 * Returns the identifier of the {@code hierarchyRank}, for the current user.  From the example given in the
 * {@link Option} javadoc, above that could be 'Development' if an implementation represented an Organisation,
 * and the current user is Emily/*from   w  w  w .  j a  va2s  .co  m*/
 *
 * @param hierarchyRank
 *         the rank (index) which is required.
 *
 * @return the rank name, for the current user, at the rank specified by {@code hierarchyRank}.
 *
 * @throws IllegalArgumentException
 *         if {@code hierarchyRank} is out of bounds
 */
@Override
public synchronized String rankName(int hierarchyRank) {
    checkArgument(hierarchyRank >= 0, "hierarchyRank must be 0 or greater");
    ImmutableList<String> ranks = ranksForCurrentUser();
    try {
        return ranks.get(hierarchyRank);
    } catch (IndexOutOfBoundsException e) {
        throw new IllegalArgumentException("Hierarchy level of " + hierarchyRank + " is too high", e);
    }
}

From source file:org.apache.aurora.common.args.parsers.RangeParser.java

@Override
public Range<Integer> doParse(String raw) throws IllegalArgumentException {
    ImmutableList<String> numbers = ImmutableList.copyOf(Splitter.on('-').omitEmptyStrings().split(raw));
    try {//from  w w  w . j  a  v a2 s  .c o  m
        int from = Integer.parseInt(numbers.get(0));
        int to = Integer.parseInt(numbers.get(1));
        if (numbers.size() != 2) {
            throw new IllegalArgumentException("Failed to parse the range:" + raw);
        }
        if (to < from) {
            return Range.closed(to, from);
        } else {
            return Range.closed(from, to);
        }
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException("Failed to parse the range:" + raw, e);
    }
}