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:org.timer4method.log.Timer4MethodLoggerImpl.java

@Override
public void setTimeMail(Long mail) {
    if (mail != null && mail.compareTo(0l) != 0) {
        timeMail = mail;
    }
}

From source file:org.timer4method.log.Timer4MethodLoggerImpl.java

@Override
public void setTimeError(Long error) {
    if (error != null && error.compareTo(0l) != 0) {
        timeError = error;/*www  .ja v  a2 s. c  o  m*/
    }
}

From source file:sturesy.votinganalysis.TimeChart.java

/**
 * Converts a set of Votes to an Array of Votes over Time
 * /*from   w w  w . ja v  a2s. c  o m*/
 * @param setvotes
 *            Set of Votes
 * @return Array of Votes over Time
 */
private double[] createArrayOfVotes(Set<Vote> setvotes) {
    ArrayList<Vote> votes = new ArrayList<Vote>(setvotes);
    Collections.sort(votes, new Comparator<Vote>() {

        @Override
        public int compare(Vote o1, Vote o2) {
            Long i1 = o1.getTimeDiff();
            Long i2 = o2.getTimeDiff();
            return i1.compareTo(i2);
        }
    });

    int totalduration = (int) (votes.get(votes.size() - 1).getTimeDiff() / 1000);

    double[] dubble = new double[totalduration + 1];

    for (Vote v : votes) {
        int slot = ((int) (v.getTimeDiff() / 1000));
        dubble[slot]++;
    }

    return dubble;
}

From source file:org.timer4method.log.Timer4MethodLoggerImpl.java

@Override
public void setTimeWarning(Long warning) {
    if (warning != null && warning.compareTo(0l) != 0) {
        timeWarning = warning;/*w  w  w  . j  a  v a  2  s . c  o  m*/
    }
}

From source file:ips1ap101.lib.base.util.StrUtils.java

public static boolean esObjetoEnRango(Object objeto, Object minimo, Object maximo) {
    boolean es = true;
    //      EnumTipoDatoParametro tipo;
    if (objeto == null) {
        return false;
    } else if (objeto instanceof String) {
        //          tipo = EnumTipoDatoParametro.ALFANUMERICO;
        String val1 = (String) objeto;
        String min1 = (String) minimo;
        String max1 = (String) maximo;
        if (min1 != null && val1.compareTo(min1) < 0) {
            es = false;/*from   w  ww .ja  va2 s. com*/
        }
        if (max1 != null && val1.compareTo(max1) > 0) {
            es = false;
        }
    } else if (objeto instanceof Integer) {
        //          tipo = EnumTipoDatoParametro.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;
        }
    } else if (objeto instanceof Long || objeto instanceof BigInteger) {
        //          tipo = EnumTipoDatoParametro.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;
        }
    } else if (objeto instanceof BigDecimal) {
        //          tipo = EnumTipoDatoParametro.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;
        }
    } else if (objeto instanceof Timestamp) {
        //          tipo = EnumTipoDatoParametro.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;
        }
    } else {
        return false;
    }
    return es;
}

From source file:org.compiere.web.AdempiereMonitorFilter.java

/**
 *    Filter/*  ww w . jav  a  2 s .  c  om*/
 *   @param request request
 *   @param response response
 *   @param chain chain
 *   @throws IOException
 *   @throws ServletException
 */
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    boolean error = false;
    String errorPage = "/error.html";
    boolean pass = false;
    try {
        if (!(request instanceof HttpServletRequest && response instanceof HttpServletResponse)) {
            request.getRequestDispatcher(errorPage).forward(request, response);
            return;
        }
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse resp = (HttpServletResponse) response;
        //   Previously checked
        HttpSession session = req.getSession(true);
        Long compare = (Long) session.getAttribute(AUTHORIZATION);
        if (compare != null && compare.compareTo(m_authorization) == 0) {
            pass = true;
        } else if (checkAuthorization(req.getHeader("Authorization"))) {
            session.setAttribute(AUTHORIZATION, m_authorization);
            pass = true;
        }
        //   --------------------------------------------
        if (pass) {
            chain.doFilter(request, response);
        } else {
            resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
            resp.setHeader("WWW-Authenticate", "BASIC realm=\"Adempiere Server\"");
        }
        return;
    } catch (Exception e) {
        log.log(Level.SEVERE, "filter", e);
    }
    request.getRequestDispatcher(errorPage).forward(request, response);
}

From source file:ar.com.zauber.commons.web.proxy.impl.dao.properties.PropertiesChainedRegexURLRequestMapperDAO.java

/** @see URLRequestMapperDAO#load() */
public final URLRequestMapper load() {
    final Properties p = provider.getProperties();
    final List<Entry<Object, Object>> l = new ArrayList<Entry<Object, Object>>(p.entrySet());

    Collections.sort(l, new Comparator<Entry<Object, Object>>() {
        public int compare(final Entry<Object, Object> o1, final Entry<Object, Object> o2) {
            final Long i1 = Long.parseLong(o1.getKey().toString());
            final Long i2 = Long.parseLong(o2.getKey().toString());
            return i1.compareTo(i2);
        }/*w w w  .java 2  s  .  co  m*/
    });

    final StringBuffer sb = new StringBuffer();
    for (final Entry<Object, Object> entry : l) {
        sb.append(entry.getValue());
        sb.append('\n');
    }
    final URLRequestMapperEditor propertyEditor = new URLRequestMapperEditor();
    propertyEditor.setStripContextPath(stripContextPath);
    propertyEditor.setStripServletPath(stripServletPath);
    propertyEditor.setAsText(sb.toString());
    return (URLRequestMapper) propertyEditor.getValue();
}

From source file:ch.javaee.basicMvc.repository.UserRepositoryImpl.java

@Override
@Transactional(readOnly = true)//from  w w  w.j ava  2s.  c  o m
public boolean isEmailAlreadyExists(String email) {
    Long count = (Long) em.createQuery("select count(u.email) from user u where email = :email")
            .setParameter("email", email).getSingleResult();
    if (count.compareTo(0l) > 0) {
        return true;
    }
    return false;

}

From source file:org.apache.sling.resourcebuilder.test.ResourceAssertions.java

/** Assert that a file exists and verify its properties. */
public Resource assertFile(String path, String mimeType, String expectedContent, Long lastModified)
        throws IOException {
    final Comparator<Long> defaultComparator = new Comparator<Long>() {
        @Override/*from w  w  w.ja v  a 2s . co  m*/
        public int compare(Long expected, Long fromResource) {
            if (expected == -1) {
                return 0;
            }
            return expected.compareTo(fromResource);
        }
    };
    return assertFile(path, mimeType, expectedContent, lastModified, defaultComparator);
}

From source file:org.kuali.mobility.push.dao.PushDeviceTupleDaoImplTest.java

@Test
@DirtiesContext/* ww  w  .  j  a  v a 2 s  . co  m*/
public void testUpdateTuple() {
    List<PushDeviceTuple> tuples = getDao().findUnsentTuples();
    PushDeviceTuple tuple = tuples.get(2);
    Calendar cal = Calendar.getInstance();
    tuple.setPostedTimestamp(new Timestamp(cal.getTimeInMillis()));
    Long oldId = tuple.getId();
    Long newId = getDao().saveTuple(tuple);
    assertTrue("Tuple was inserted, not updated.", oldId.compareTo(newId) == 0);
}