Package com.google.common.collect

Examples of com.google.common.collect.ComparisonChain


public class ObjectContracts {

    @SuppressWarnings("unchecked")
    public static <T> int compare(T p, T q, String propertyNames) {
        ComparisonChain chain = ComparisonChain.start();
        for (final Clause clause : iterable(propertyNames)) {
            final Comparable<T> propertyValue = (Comparable<T>) clause.getValueOf(p);
            final Comparable<T> propertyValue2 = (Comparable<T>) clause.getValueOf(q);
            chain = chain.compare(propertyValue, propertyValue2, clause.getDirection().getOrdering());
        }
        return chain.result();
    }
View Full Code Here


public class ObjectContracts {

    @SuppressWarnings("unchecked")
    public static <T> int compare(T p, T q, String propertyNames) {
        ComparisonChain chain = ComparisonChain.start();
        for (final Clause clause : iterable(propertyNames)) {
            final Comparable<T> propertyValue = (Comparable<T>) clause.getValueOf(p);
            final Comparable<T> propertyValue2 = (Comparable<T>) clause.getValueOf(q);
            chain = chain.compare(propertyValue, propertyValue2, clause.getDirection().getOrdering());
        }
        return chain.result();
    }
View Full Code Here

public class ObjectContracts {
   

    @SuppressWarnings("unchecked")
    public static <T> int compare(T p, T q, String propertyNames) {
        ComparisonChain chain = ComparisonChain.start();
        for (final Clause clause : iterable(propertyNames)) {
            final Comparable<T> propertyValue = (Comparable<T>) clause.getValueOf(p);
            final Comparable<T> propertyValue2 = (Comparable<T>) clause.getValueOf(q);
            chain = chain.compare(propertyValue, propertyValue2, clause.getDirection().getOrdering());
        }
        return chain.result();
    }
View Full Code Here

      Builder<Hardware> hardware = ImmutableSortedSet.orderedBy(new Comparator<Hardware>() {
         @Override
         public int compare(Hardware h1, Hardware h2) {
            List<? extends Volume> volumes1 = h1.getVolumes();
            List<? extends Volume> volumes2 = h2.getVolumes();
            ComparisonChain comparisonChain = ComparisonChain.start().compare(getCores(h1), getCores(h2))
                    .compare(h1.getRam(), h2.getRam())
                    .compare(getSpace(h1), getSpace(h2))
                    .compare(getBootableDeviceType(h1), getBootableDeviceType(h2));
            if (!volumes1.isEmpty() && !volumes2.isEmpty() && volumes1.size() == volumes2.size()) {
               for (int i = 0; i < volumes1.size(); i++) {
                  comparisonChain.compare(volumes1.get(i).getType(), volumes2.get(i).getType());
               }
            }
            return comparisonChain.result();
         }
      });
      for (VirtualGuestBlockDevice blockDevice : virtualGuestConfiguration.getVirtualGuestBlockDevices()) {
         float capacity = blockDevice.getVirtualDiskImage().getCapacity();
         Type type = blockDevice.getVirtualGuest().isLocalDiskFlag() ? Type.LOCAL : Type.SAN;
View Full Code Here

            throw new ClassCastException(
                    "Object to compare must be of type DefaultPmtKey. Object is " + o == null ? "null" : o.getClass()
                            .getName());
        }
        DefaultPmtKey that = (DefaultPmtKey) o;
        ComparisonChain cmpChain = ComparisonChain.start()
                .compare(firstKey, that.firstKey)
                .compare(pmtPeriod, that.pmtPeriod)
                .compare(count, that.count);

        int result = cmpChain.result();
        if (result != 0) {
            return result;
        }

        // It should never get to this point in the code. Because we are using an Interner, two objects that are equal
        // are the same object, so the first check will return 0. If the objects are not equal, at least one of the
        // three values we check before the list will be unequal, so it should never have to compare the contents of the
        // lists (thankfully).
        for (int i = 0; i < keys.size(); i++) {
            result = cmpChain.compare(keys.get(i), that.keys.get(i)).result();
            if (result != 0) return result;
        }

        return result;
    }
View Full Code Here

      Builder<Hardware> hardware = ImmutableSortedSet.orderedBy(new Comparator<Hardware>() {
         @Override
         public int compare(Hardware h1, Hardware h2) {
            List<? extends Volume> volumes1 = h1.getVolumes();
            List<? extends Volume> volumes2 = h2.getVolumes();
            ComparisonChain comparisonChain = ComparisonChain.start().compare(getCores(h1), getCores(h2))
                    .compare(h1.getRam(), h2.getRam())
                    .compare(getSpace(h1), getSpace(h2))
                    .compare(getBootableDeviceType(h1), getBootableDeviceType(h2));
            if (!volumes1.isEmpty() && !volumes2.isEmpty() && volumes1.size() == volumes2.size()) {
               for (int i = 0; i < volumes1.size(); i++) {
                  comparisonChain.compare(volumes1.get(i).getType(), volumes2.get(i).getType());
               }
            }
            return comparisonChain.result();
         }
      });
      for (VirtualGuestBlockDevice blockDevice : virtualGuestConfiguration.getVirtualGuestBlockDevices()) {
         float capacity = blockDevice.getVirtualDiskImage().getCapacity();
         Type type = blockDevice.getVirtualGuest().isLocalDiskFlag() ? Type.LOCAL : Type.SAN;
View Full Code Here

TOP

Related Classes of com.google.common.collect.ComparisonChain

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.