Example usage for com.google.common.collect Lists reverse

List of usage examples for com.google.common.collect Lists reverse

Introduction

In this page you can find the example usage for com.google.common.collect Lists reverse.

Prototype

@CheckReturnValue
public static <T> List<T> reverse(List<T> list) 

Source Link

Document

Returns a reversed view of the specified list.

Usage

From source file:org.apache.niolex.common.guava.GuavaCollections.java

/**
 * @param args/*from  w  w  w .  j  a  v a 2  s.  c  o  m*/
 */
public static void main(String[] args) {
    Multiset<String> wordsMultiset = HashMultiset.create();
    wordsMultiset.add("abc");
    wordsMultiset.add("abc");
    wordsMultiset.add("abcd");
    System.out.println("count => " + wordsMultiset.count("abc"));
    System.out.println("count => " + wordsMultiset.count("abcd"));

    BiMap<String, String> biMap = HashBiMap.create();
    biMap.put("good", "morning");
    biMap.put("bad", "afternoon");
    System.out.println("good => " + biMap.get("good"));
    System.out.println("afternoon => " + biMap.inverse().get("afternoon"));

    RangeMap<Integer, String> rangeMap = TreeRangeMap.create();
    rangeMap.put(Range.closed(1, 11), "Nice");
    rangeMap.put(Range.openClosed(11, 15), "Girl");
    System.out.println("11 => " + rangeMap.get(11));
    System.out.println("12 => " + rangeMap.get(12));
    System.out.println("15 => " + rangeMap.get(15));
    System.out.println("16 => " + rangeMap.get(16));

    List<Integer> countUp = Ints.asList(1, 2, 3, 4, 5);
    List<Integer> countDown = Lists.reverse(countUp); // {5, 4, 3, 2, 1}
    System.out.println("countUp => " + countUp);
    System.out.println("countDown => " + countDown);
}

From source file:io.airlift.drift.server.FilteredMethodInvoker.java

public static ServerMethodInvoker createFilteredMethodInvoker(List<MethodInvocationFilter> filters,
        ServerMethodInvoker methodInvoker) {
    for (MethodInvocationFilter filter : Lists.reverse(filters)) {
        methodInvoker = new FilteredMethodInvoker(filter, methodInvoker);
    }//from   ww w .  j  a va 2s.c o  m
    return methodInvoker;
}

From source file:org.jclouds.googlecloudstorage.domain.DomainUtils.java

public static byte[] reverse(byte[] b) {
    List<Byte> hashByte = Bytes.asList(b);
    List<Byte> reversedList = Lists.reverse(hashByte);
    return Bytes.toArray(reversedList);
}

From source file:io.airlift.drift.client.FilteredMethodInvoker.java

public static MethodInvoker createFilteredMethodInvoker(List<MethodInvocationFilter> filters,
        MethodInvoker methodInvoker) {/*from  w  w w  . jav  a 2s  .  co  m*/
    for (MethodInvocationFilter filter : Lists.reverse(filters)) {
        methodInvoker = new FilteredMethodInvoker(filter, methodInvoker);
    }
    return methodInvoker;
}

From source file:com.opengamma.core.FudgeUniqueIdResolutionTools.java

public static void appendNewVersion(MutableFudgeMsg message, FudgeContext fudgeContext, UniqueId newVersion,
        Instant effectiveInstantFrom, Instant effectiveInstantTo, Instant correctionInstantFrom,
        Instant correctionInstantTo) {

    // First, modify the previous version if required.
    // Can be changed to be index based for performance if necessary.
    List<FudgeField> fields = message.getAllFields();
    fields = Lists.reverse(fields);
    boolean foundMatchingOid = false;
    boolean mutatedOlderOid = false;
    for (FudgeField field : fields) {
        MutableFudgeMsg record = (MutableFudgeMsg) field.getValue();
        UniqueId recordId = UniqueId.parse(record.getString("uid"));
        if (!recordId.getObjectId().equals(newVersion.getObjectId())) {
            // No need to modify.
            continue;
        }//from   w  w w  . j ava  2  s  .  c  om

        foundMatchingOid = true;
        Instant recordEffectiveFrom = record.getFieldValue(Instant.class, record.getByName("eff-from"));
        Instant recordEffectiveTo = record.getFieldValue(Instant.class, record.getByName("eff-to"));
        //Instant recordCorrectionFrom = record.getFieldValue(Instant.class, record.getByName("cor-from"));
        Instant recordCorrectionTo = record.getFieldValue(Instant.class, record.getByName("cor-to"));

        if (ObjectUtils.equals(recordEffectiveFrom, effectiveInstantFrom)) {
            // The two EffectiveTo better match as well.
            ArgumentChecker.isTrue(ObjectUtils.equals(recordEffectiveTo, effectiveInstantTo),
                    "Record matches effectiveFrom but not effectiveTo.");

            // Must be a new version on the correction.
            if (recordCorrectionTo != null) {
                continue;
            }
            record.remove("cor-to");
            record.add("cor-to", correctionInstantFrom);
            mutatedOlderOid = true;
        } else if (recordEffectiveFrom.isBefore(effectiveInstantFrom) && (recordEffectiveTo == null)) {
            record.add("eff-to", effectiveInstantFrom);
            mutatedOlderOid = true;
        }

    }
    if (foundMatchingOid && !mutatedOlderOid) {
        throw new OpenGammaRuntimeException("Algorithm failure: found existing OID but did not mutate any.");
    }

    MutableFudgeMsg record = fudgeContext.newMessage();
    record.add("uid", newVersion.toString());
    record.add("eff-from", effectiveInstantFrom);
    if (effectiveInstantTo != null) {
        record.add("eff-to", effectiveInstantTo);
    }
    record.add("corr-from", correctionInstantFrom);
    if (effectiveInstantTo != null) {
        record.add("corr-to", correctionInstantTo);
    }
    message.add(0, record);
}

From source file:com.demigodsrpg.util.misc.MapUtil2.java

/**
 * Sort a Map from smallest to largest, or in <code>reverse</code>.
 *
 * @param map     The Map object to be sorted.
 * @param reverse Reverse the ordering./*from ww  w.  j  a  v  a2s.c o m*/
 * @return A sorted version of <code>map</code>.
 */
public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map, boolean reverse) {
    List<Map.Entry<K, V>> list = new LinkedList<Map.Entry<K, V>>(map.entrySet());
    Collections.sort(list, new Comparator<Map.Entry<K, V>>() {
        public int compare(Map.Entry<K, V> o1, Map.Entry<K, V> o2) {
            return (o1.getValue()).compareTo(o2.getValue());
        }
    });

    if (reverse)
        list = Lists.reverse(list);

    Map<K, V> result = new LinkedHashMap<K, V>();
    for (Map.Entry<K, V> entry : list) {
        result.put(entry.getKey(), entry.getValue());
    }
    return result;
}

From source file:com.censoredsoftware.library.util.MapUtil2.java

/**
 * Sort a Map from smallest to largest, or in <code>reverse</code>.
 *
 * @param map     The Map object to be sorted.
 * @param reverse Reverse the ordering./*from   ww  w . j av a2s.c o  m*/
 * @return A sorted version of <code>map</code>.
 */
public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map, boolean reverse) {
    List<Map.Entry<K, V>> list = new LinkedList<Map.Entry<K, V>>(map.entrySet());
    Collections.sort(list, new Comparator<Map.Entry<K, V>>() {
        public int compare(Map.Entry<K, V> o1, Map.Entry<K, V> o2) {
            return (o1.getValue()).compareTo(o2.getValue());
        }
    });

    if (reverse)
        list = Lists.reverse(list);

    Map<K, V> result = new LinkedHashMap<K, V>();
    for (Map.Entry<K, V> entry : list)
        result.put(entry.getKey(), entry.getValue());
    return result;
}

From source file:eu.lp0.cursus.util.SwingHacks.java

public static void addButtonsInUIOrder(Container container, List<? extends JButton> buttons,
        List<? extends Object> constraints) {
    Preconditions.checkArgument(buttons.size() == constraints.size());

    if (isYesLast()) {
        constraints = Lists.reverse(constraints);
    }//w  w w.j  av a  2 s.  c  o  m

    Iterator<? extends JButton> bIter = buttons.iterator();
    Iterator<? extends Object> cIter = constraints.iterator();
    while (bIter.hasNext()) {
        container.add(bIter.next(), cIter.next());
    }
}

From source file:org.eclipse.elk.alg.layered.p3order.counting.CrossMinUtil.java

/**
 * Iterate over ports in north to south and east to west order.
 * //from ww w.j a v  a 2s.co m
 * @param node
 *            whose ports are being considered.
 * @param side
 *            of the node we are interested in
 * @return Iterable for ports on given node and side in given order.
 */
public static Iterable<LPort> inNorthSouthEastWestOrder(final LNode node, final PortSide side) {
    switch (side) {
    case EAST:
    case NORTH:
        return node.getPortSideView(side);
    case SOUTH:
    case WEST:
        return Lists.reverse(node.getPortSideView(side));
    }
    return Collections.emptyList();
}

From source file:net.joala.time.TimeFormat.java

/**
 * <p>//w w  w .ja va  2  s.co m
 * Format the given time amount in a "human readable" way.
 * </p>
 *
 * @param amount   amount of time units
 * @param timeUnit the time unit
 * @return time amount in human readable format (for example converted to seconds or minutes)
 */
public static String format(@Nonnegative final long amount, @Nonnull final TimeUnit timeUnit) {
    final List<TimeUnit> reverse = Lists.reverse(Arrays.asList(TimeUnit.values()));
    for (final TimeUnit currentUnit : reverse) {
        if (currentUnit.equals(timeUnit) || currentUnit.convert(amount, timeUnit) >= TIMEUNIT_LIMIT) {
            return TimeUnitFormat.getFormat(currentUnit).format(amount, timeUnit);
        }
    }
    throw new IllegalArgumentException(String.format("TimeUnit %s not supported for formatting.", timeUnit));
}