Example usage for java.util Collections sort

List of usage examples for java.util Collections sort

Introduction

In this page you can find the example usage for java.util Collections sort.

Prototype

@SuppressWarnings({ "unchecked", "rawtypes" })
public static <T> void sort(List<T> list, Comparator<? super T> c) 

Source Link

Document

Sorts the specified list according to the order induced by the specified comparator.

Usage

From source file:Main.java

public static boolean getBoundaryLevel(Point bound) {
    if (mLevelSet == null)
        mLevelSet = mContext.getSharedPreferences(PREFER, Context.MODE_WORLD_READABLE).getStringSet(LEVELSET,
                null);/* w w w.  j a va 2s .  co m*/
    if (mLevelSet != null) {
        ArrayList<String> array = Collections.list(Collections.enumeration(mLevelSet));
        Collections.sort(array, mComparator);
        bound.x = Integer.valueOf(array.get(0));
        bound.y = Integer.valueOf(array.get(array.size() - 1));
        return true;
    }
    return false;
}

From source file:Main.java

public static boolean isLowestLevel(int level) {
    if (mLevelSet == null)
        mLevelSet = mContext.getSharedPreferences(PREFER, Context.MODE_WORLD_READABLE).getStringSet(LEVELSET,
                null);/*from   w ww.  j  a v a2  s.  c  o  m*/
    if (mLevelSet != null) {
        if (mLevelSet.size() < 5) // data is too few to judge lowest
            return false;
        ArrayList<String> array = Collections.list(Collections.enumeration(mLevelSet));
        Collections.sort(array, mComparator);
        // TODO: may need check statistics to ensure the level is true lowest and not false alarm.
        if (level <= Integer.valueOf(array.get(0)))
            return true;
    }
    return false;
}

From source file:Main.java

/**
 * The specified list will be sorted where then the small numbers comes first
 *///  w ww .java  2s  .c  o  m
public static <T> void sortInplaceLongReverse(List<Entry<T, Long>> entrySet) {
    Collections.sort(entrySet, new Comparator<Entry<T, Long>>() {

        @Override
        public int compare(Entry<T, Long> o1, Entry<T, Long> o2) {
            long i1 = o1.getValue();
            long i2 = o2.getValue();
            if (i1 < i2)
                return -1;
            else if (i1 > i2)
                return 1;
            else
                return 0;
        }
    });
}

From source file:Main.java

private static ZipEntry findRootInstallTxt(List<ZipEntry> entries) {
    List<ZipEntry> iz = new ArrayList<ZipEntry>();
    for (ZipEntry e : entries) {
        if (e.getName().contains("install.txt"))
            iz.add(e);/*w  ww  . j  a  v a2s  .  c om*/
    }

    if (iz.size() == 1)
        return iz.get(0);

    //Log.d(TAG, "has " + iz.size() + " install.txts");
    // sort to get shortest one 
    Collections.sort(iz, zipFilenameCompare);
    //Log.d(TAG, "first" + iz.get(0).getName() + ", last" + iz.get(iz.size() -1).getName());
    return iz.get(0);
}

From source file:Main.java

public static <E> List<E> sorted(Collection<E> col, Comparator<? super E> comparator) {
    ArrayList<E> list = new ArrayList<E>(col);
    Collections.sort(list, comparator);
    return list;/*from  ww  w .  ja  va  2s.c  o  m*/
}

From source file:com.gson.util.Tools.java

public static final boolean checkSignature(String token, String signature, String timestamp, String nonce) {
    List<String> params = new ArrayList<String>();
    params.add(token);/*  ww w .  j  a v  a  2 s.c  o  m*/
    params.add(timestamp);
    params.add(nonce);
    Collections.sort(params, new Comparator<String>() {
        @Override
        public int compare(String o1, String o2) {
            return o1.compareTo(o2);
        }
    });
    String temp = params.get(0) + params.get(1) + params.get(2);
    return DigestUtils.shaHex(temp).equals(signature);
}

From source file:com.hangum.tadpole.commons.util.IPUtil.java

/**
 * ip sort/*from   w  ww . j a  va2s  . co m*/
 * 
 * @param ipList
 * @return
 */
public static List<String> ipSort(List<String> ipList) {

    Collections.sort(ipList, new Comparator<String>() {
        @Override
        public int compare(String o1, String o2) {
            String[] ips1 = o1.split("\\.");
            String updatedIp1 = String.format("%3s.%3s.%3s.%3s", ips1[0], ips1[1], ips1[2], ips1[3]);
            String[] ips2 = o2.split("\\.");
            String updatedIp2 = String.format("%3s.%3s.%3s.%3s", ips2[0], ips2[1], ips2[2], ips2[3]);
            return updatedIp1.compareTo(updatedIp2);
        }
    });

    return ipList;
}

From source file:Main.java

/**
 * @return a sorted list where the object with the highest integer value comes first!
 *///from  w  w  w . j a  va 2  s  .c  o m
public static <T> List<Entry<T, Integer>> sort(Collection<Entry<T, Integer>> entrySet) {
    List<Entry<T, Integer>> sorted = new ArrayList<Entry<T, Integer>>(entrySet);
    Collections.sort(sorted, new Comparator<Entry<T, Integer>>() {
        @Override
        public int compare(Entry<T, Integer> o1, Entry<T, Integer> o2) {
            int i1 = o1.getValue();
            int i2 = o2.getValue();
            if (i1 < i2) {
                return 1;
            } else if (i1 > i2) {
                return -1;
            } else {
                return 0;
            }
        }
    });

    return sorted;
}

From source file:Main.java

/**
 * @return a sorted list where the object with the highest integer value comes first!
 *//*from   ww  w  . ja  v a2s. com*/
public static <T> List<Entry<T, Integer>> sort(Collection<Entry<T, Integer>> entrySet) {
    List<Entry<T, Integer>> sorted = new ArrayList<Entry<T, Integer>>(entrySet);
    Collections.sort(sorted, new Comparator<Entry<T, Integer>>() {

        @Override
        public int compare(Entry<T, Integer> o1, Entry<T, Integer> o2) {
            int i1 = o1.getValue();
            int i2 = o2.getValue();
            if (i1 < i2)
                return 1;
            else if (i1 > i2)
                return -1;
            else
                return 0;
        }
    });

    return sorted;
}

From source file:Main.java

public static <T extends Object> void sort(final List<T> list, final Comparator<? super T> comparator) {
    Collections.sort(list, comparator);
}