Example usage for java.lang Long compareTo

List of usage examples for java.lang Long compareTo

Introduction

In this page you can find the example usage for java.lang Long compareTo.

Prototype

public int compareTo(Long anotherLong) 

Source Link

Document

Compares two Long objects numerically.

Usage

From source file:Main.java

public static void main(String[] args) {
    Long long1 = new Long(12345L);
    Long long2 = new Long("12346");

    System.out.println(long1.compareTo(long2));
}

From source file:org.sisto.jeeplate.domain.ObjectId.java

public static Boolean xisNew(ObjectId oid) {
    boolean isNew = false;
    boolean isNull = (oid == null) ? true : false;
    boolean isIdNull = (oid == null || oid.id() == null) ? true : false;

    if (isNull || isIdNull) {
        isNew = true;//from   w  w w. j  a  va2  s.c  o m
    } else {
        Long id = oid.id();
        boolean isDefault = (id.compareTo(DEFAULT_ID) == 0) ? true : false;

        if (isDefault) {
            isNew = true;
        } else {
            isNew = false;
        }
    }

    return isNew;
}

From source file:com.griddynamics.jagger.engine.e1.scenario.DefaultWorkloadSuggestionMaker.java

private static Integer findClosestPoint(BigDecimal desiredTps, Map<Integer, Pair<Long, BigDecimal>> stats) {
    final int MAX_POINTS_FOR_REGRESSION = 10;

    SortedMap<Long, Integer> map = Maps.newTreeMap(new Comparator<Long>() {
        @Override//  w w w  .  j a  v a 2  s .  com
        public int compare(Long first, Long second) {
            return second.compareTo(first);
        }
    });
    for (Map.Entry<Integer, Pair<Long, BigDecimal>> entry : stats.entrySet()) {
        map.put(entry.getValue().getFirst(), entry.getKey());
    }

    if (map.size() < 2) {
        throw new IllegalArgumentException("Not enough stats to calculate point");
    }

    // <time><number of threads> - sorted by time
    Iterator<Map.Entry<Long, Integer>> iterator = map.entrySet().iterator();

    SimpleRegression regression = new SimpleRegression();
    Integer tempIndex;
    double previousValue = -1.0;
    double value;
    double measuredTps;

    log.debug("Selecting next point for balancing");
    int indx = 0;
    while (iterator.hasNext()) {

        tempIndex = iterator.next().getValue();

        if (previousValue < 0.0) {
            previousValue = tempIndex.floatValue();
        }
        value = tempIndex.floatValue();
        measuredTps = stats.get(tempIndex).getSecond().floatValue();

        regression.addData(value, measuredTps);

        log.debug(String.format("   %7.2f    %7.2f", value, measuredTps));

        indx++;
        if (indx > MAX_POINTS_FOR_REGRESSION) {
            break;
        }
    }

    double intercept = regression.getIntercept();
    double slope = regression.getSlope();

    double approxPoint;

    // if no slope => use previous number of threads
    if (Math.abs(slope) > 1e-12) {
        approxPoint = (desiredTps.doubleValue() - intercept) / slope;
    } else {
        approxPoint = previousValue;
    }

    // if approximation point is negative - ignore it
    if (approxPoint < 0) {
        approxPoint = previousValue;
    }

    log.debug(String.format("Next point   %7d    (target tps: %7.2f)", (int) Math.round(approxPoint),
            desiredTps.doubleValue()));

    return (int) Math.round(approxPoint);
}

From source file:com.palantir.paxos.PaxosStateLogImpl.java

private static final Comparator<File> nameAsLongComparator() {
    return new Comparator<File>() {
        @Override/*from w  ww.  j  ava  2 s.c o  m*/
        public int compare(File f1, File f2) {
            Long s1 = getSeqFromFilename(f1);
            Long s2 = getSeqFromFilename(f2);
            return s1.compareTo(s2);
        }
    };
}

From source file:me.doshou.admin.maintain.editor.web.controller.utils.OnlineEditorUtils.java

public static void sort(final List<Map<Object, Object>> files, final Sort sort) {

    Collections.sort(files, new Comparator<Map<Object, Object>>() {
        @Override// w  w w. j  av a2  s. c  om
        public int compare(Map<Object, Object> o1, Map<Object, Object> o2) {
            if (sort == null) {
                return 0;
            }
            Sort.Order nameOrder = sort.getOrderFor("name");
            if (nameOrder != null) {
                String n1 = (String) o1.get("name");
                String n2 = (String) o2.get("name");
                Boolean n1IsDirecoty = (Boolean) o1.get("isDirectory");
                Boolean n2IsDirecoty = (Boolean) o2.get("isDirectory");

                if (n1IsDirecoty.equals(Boolean.TRUE) && n2IsDirecoty.equals(Boolean.FALSE)) {
                    return -1;
                } else if (n1IsDirecoty.equals(Boolean.FALSE) && n2IsDirecoty.equals(Boolean.TRUE)) {
                    return 1;
                }

                if (nameOrder.getDirection() == Sort.Direction.ASC) {
                    return n1.compareTo(n2);
                } else {
                    return -n1.compareTo(n2);
                }
            }

            Sort.Order lastModifiedOrder = sort.getOrderFor("lastModified");
            if (lastModifiedOrder != null) {
                Long l1 = (Long) o1.get("lastModifiedForLong");
                Long l2 = (Long) o2.get("lastModifiedForLong");
                if (lastModifiedOrder.getDirection() == Sort.Direction.ASC) {
                    return l1.compareTo(l2);
                } else {
                    return -l1.compareTo(l2);
                }
            }

            Sort.Order sizeOrder = sort.getOrderFor("size");
            if (sizeOrder != null) {
                Long s1 = (Long) o1.get("size");
                Long s2 = (Long) o2.get("size");
                if (sizeOrder.getDirection() == Sort.Direction.ASC) {
                    return s1.compareTo(s2);
                } else {
                    return -s1.compareTo(s2);
                }
            }

            return 0;
        }
    });

}

From source file:v7db.files.mongodb.BSONUtils.java

/**
 * stores a number as Integer, if it fits, or as a Long, if not. This saves
 * space in the database, but you lose the ability to sort or do range
 * queries.//  ww w.  ja va  2 s .com
 */
static Number putIntegerOrLong(BSONObject b, String fieldName, Object x) {
    if (x instanceof Integer)
        return putInteger(b, fieldName, x);

    Long l = toLong(x);
    if (l == null) {
        removeField(b, fieldName);
        return null;
    }
    if (l.compareTo(MAX_INT) < 0 && l.compareTo(MIN_INT) > 0) {
        Integer i = l.intValue();
        b.put(fieldName, i);
        return i;
    }
    b.put(fieldName, l);
    return l;
}

From source file:org.commoncrawl.mapred.ec2.parser.EC2ParserTask.java

/** build a list of parse candidates sorted by timestamp 
 * //from  w w w. j  a  va  2  s  .  co m
 * @param fs
 * @param logFilePath
 * @return a Set of Candidates
 * @throws IOException
 */
private static TreeSet<Path> buildCandidateList(FileSystem fs, Path logFilePath) throws IOException {

    TreeSet<Path> candidateList = new TreeSet<Path>(new Comparator<Path>() {

        @Override
        public int compare(Path p1, Path p2) {
            String n1 = p1.getName();
            String n2 = p2.getName();
            Matcher m1 = CRAWL_LOG_REG_EXP.matcher(n1);
            Matcher m2 = CRAWL_LOG_REG_EXP.matcher(n2);
            m1.matches();
            m2.matches();
            Long v1 = Long.parseLong(m1.group(1));
            Long v2 = Long.parseLong(m2.group(1));

            return v1.compareTo(v2);
        }

    });

    LOG.info("Scanning for Log Files at:" + logFilePath);
    FileStatus candidateItems[] = fs.globStatus(new Path(logFilePath, "CrawlLog*"));
    for (FileStatus candidate : candidateItems) {
        candidateList.add(candidate.getPath());
    }

    return candidateList;
}

From source file:net.sf.eclipsecs.core.builder.CheckerFactory.java

/**
 * Tries to reuse an already configured checker for this configuration.
 *
 * @param config//  ww w.j  a v  a  2s  . c  o  m
 *            the configuration file
 * @param cacheKey
 *            the key for cache access
 * @return the cached checker or null
 */
private static Checker tryCheckerCache(String cacheKey, long modificationStamp) {

    // try the cache
    Checker checker = sCheckerMap.get(cacheKey);

    // if cache hit
    if (checker != null) {

        // compare modification times of the configs
        Long oldTime = sModifiedMap.get(cacheKey);
        Long newTime = new Long(modificationStamp);

        // no match - remove checker from cache
        if (oldTime == null || oldTime.compareTo(newTime) != 0) {
            checker = null;
            sCheckerMap.remove(cacheKey);
            sModifiedMap.remove(cacheKey);
            sAdditionalDataMap.remove(cacheKey);
        }
    }
    return checker;
}

From source file:com.wms.utils.DataUtil.java

/**
 * safe equal/* w w w.  j a  va  2  s .c om*/
 *
 * @param obj1 Long
 * @param obj2 Long
 * @return boolean
 */
public static boolean safeEqual(Long obj1, Long obj2) {
    return ((obj1 != null) && (obj2 != null) && (obj1.compareTo(obj2) == 0));
}

From source file:ips1ap101.lib.core.util.STP.java

public static boolean esObjetoEnRango(Object objeto, Object minimo, Object maximo) {
    boolean es = true;
    TipoDatoParEnumeration tipo;/*  w  w  w . ja v  a2  s .  c  o  m*/
    if (objeto == null) {
        return false;
    } else if (objeto instanceof String) {
        tipo = TipoDatoParEnumeration.ALFANUMERICO;
    } else if (objeto instanceof BigDecimal) {
        tipo = TipoDatoParEnumeration.NUMERICO;
    } else if (objeto instanceof Timestamp) {
        tipo = TipoDatoParEnumeration.FECHA_HORA;
    } else if (objeto instanceof Integer) {
        tipo = TipoDatoParEnumeration.ENTERO;
    } else if (objeto instanceof Long) {
        tipo = TipoDatoParEnumeration.ENTERO_GRANDE;
    } else if (objeto instanceof BigInteger) {
        tipo = TipoDatoParEnumeration.ENTERO_GRANDE;
    } else {
        return false;
    }
    switch (tipo) {
    case ALFANUMERICO:
        String val1 = (String) objeto;
        String min1 = (String) minimo;
        String max1 = (String) maximo;
        if (min1 != null && val1.compareTo(min1) < 0) {
            es = false;
        }
        if (max1 != null && val1.compareTo(max1) > 0) {
            es = false;
        }
        break;
    case NUMERICO:
        BigDecimal val2 = (BigDecimal) objeto;
        BigDecimal min2 = (BigDecimal) minimo;
        BigDecimal max2 = (BigDecimal) maximo;
        if (min2 != null && val2.compareTo(min2) < 0) {
            es = false;
        }
        if (max2 != null && val2.compareTo(max2) > 0) {
            es = false;
        }
        break;
    case FECHA_HORA:
        Timestamp val3 = (Timestamp) objeto;
        Timestamp min3 = (Timestamp) minimo;
        Timestamp max3 = (Timestamp) maximo;
        if (min3 != null && val3.compareTo(min3) < 0) {
            es = false;
        }
        if (max3 != null && val3.compareTo(max3) > 0) {
            es = false;
        }
        break;
    case ENTERO:
        Integer val4 = (Integer) objeto;
        Integer min4 = (Integer) minimo;
        Integer max4 = (Integer) maximo;
        if (min4 != null && val4.compareTo(min4) < 0) {
            es = false;
        }
        if (max4 != null && val4.compareTo(max4) > 0) {
            es = false;
        }
        break;
    case ENTERO_GRANDE:
        Long val5 = objeto instanceof BigInteger ? ((BigInteger) objeto).longValue() : (Long) objeto;
        Long min5 = (Long) minimo;
        Long max5 = (Long) maximo;
        if (min5 != null && val5.compareTo(min5) < 0) {
            es = false;
        }
        if (max5 != null && val5.compareTo(max5) > 0) {
            es = false;
        }
        break;
    }
    return es;
}