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.sakaiproject.contentreview.impl.turnitin.TurnitinReviewServiceImpl.java

public String getIconUrlforScore(Long score) {

    String urlBase = "/sakai-contentreview-tool-tii/images/score_";
    String suffix = ".gif";

    if (score.equals(Long.valueOf(0))) {
        return urlBase + "blue" + suffix;
    } else if (score.compareTo(Long.valueOf(25)) < 0) {
        return urlBase + "green" + suffix;
    } else if (score.compareTo(Long.valueOf(50)) < 0) {
        return urlBase + "yellow" + suffix;
    } else if (score.compareTo(Long.valueOf(75)) < 0) {
        return urlBase + "orange" + suffix;
    } else {//from   w w  w .j a v a  2 s  .  c om
        return urlBase + "red" + suffix;
    }

}

From source file:org.alfresco.repo.domain.node.AbstractNodeDAOImpl.java

/**
 * Invalidate cache entries for all children of a give node.  This usually applies
 * where the child associations or nodes are modified en-masse.
 * /*from   w  ww . j a  v  a 2 s.com*/
 * @param parentNodeId          the parent node of all child nodes to be invalidated (may be <tt>null</tt>)
 * @param touchNodes            <tt>true<tt> to also touch the nodes
 * @return                      the number of child associations found (might be capped)
 */
private int invalidateNodeChildrenCaches(Long parentNodeId, boolean primary, boolean touchNodes) {
    Long txnId = getCurrentTransaction().getId();

    int count = 0;
    List<Long> childNodeIds = new ArrayList<Long>(256);
    Long minChildNodeIdInclusive = Long.MIN_VALUE;
    while (minChildNodeIdInclusive != null) {
        childNodeIds.clear();
        List<ChildAssocEntity> childAssocs = selectChildNodeIds(parentNodeId, Boolean.valueOf(primary),
                minChildNodeIdInclusive, 256);
        // Remove the cache entries as we go
        for (ChildAssocEntity childAssoc : childAssocs) {
            Long childNodeId = childAssoc.getChildNode().getId();
            if (childNodeId.compareTo(minChildNodeIdInclusive) < 0) {
                throw new RuntimeException("Query results did not increase for child node id ID");
            } else {
                minChildNodeIdInclusive = new Long(childNodeId.longValue() + 1L);
            }
            // Invalidate the node cache
            childNodeIds.add(childNodeId);
            invalidateNodeCaches(childNodeId);
            count++;
        }
        // Bring all the nodes into the transaction, if required
        if (touchNodes) {
            updateNodes(txnId, childNodeIds);
        }
        // Now break out if we didn't have the full set of results
        if (childAssocs.size() < 256) {
            break;
        }
    }
    // Done
    return count;
}

From source file:org.alfresco.repo.domain.node.AbstractNodeDAOImpl.java

@Override
public Pair<Long, ChildAssociationRef> getChildAssoc(Long parentNodeId, Long childNodeId, QName assocTypeQName,
        QName assocQName) {// w w w . ja v  a 2s  .  co m
    List<ChildAssocEntity> assocs = selectChildAssoc(parentNodeId, childNodeId, assocTypeQName, assocQName);
    if (assocs.size() == 0) {
        return null;
    } else if (assocs.size() == 1) {
        return assocs.get(0).getPair(qnameDAO);
    }
    // Keep the primary association or, if there isn't one, the association with the smallest ID
    Map<Long, ChildAssocEntity> assocsToDeleteById = new HashMap<Long, ChildAssocEntity>(assocs.size() * 2);
    Long minId = null;
    Long primaryId = null;
    for (ChildAssocEntity assoc : assocs) {
        // First store it
        Long assocId = assoc.getId();
        assocsToDeleteById.put(assocId, assoc);
        if (minId == null || minId.compareTo(assocId) > 0) {
            minId = assocId;
        }
        if (assoc.isPrimary()) {
            primaryId = assocId;
        }
    }
    // Remove either the primary or min assoc
    Long assocToKeepId = primaryId == null ? minId : primaryId;
    ChildAssocEntity assocToKeep = assocsToDeleteById.remove(assocToKeepId);
    // If the current transaction allows, remove the other associations
    if (AlfrescoTransactionSupport.getTransactionReadState() == TxnReadState.TXN_READ_WRITE) {
        for (Long assocIdToDelete : assocsToDeleteById.keySet()) {
            deleteChildAssoc(assocIdToDelete);
        }
    }
    // Done
    return assocToKeep.getPair(qnameDAO);
}

From source file:org.openTwoFactor.server.util.TwoFactorServerUtilsElSafe.java

/**
 * @param values//ww w . jav  a2  s  .co m
 * @return the max long in the list of args
 */
public static Long getMaxLongValue(Long... values) {
    if (values == null || values.length == 0) {
        return null;
    }

    Long maxValue = null;
    for (int i = 0; i < values.length; i++) {
        if (values[i] != null) {
            if (maxValue == null || maxValue.compareTo(values[i]) < 0) {
                maxValue = new Long(values[i]);
            }
        }
    }

    return maxValue;
}

From source file:org.openTwoFactor.server.util.TwoFactorServerUtilsElSafe.java

/**
 * @param values//w  w w .  j a  v  a2 s .  c o  m
 * @return the min long in the list of args
 */
public static Long getMinLongValue(Long... values) {
    if (values == null || values.length == 0) {
        return null;
    }

    Long minValue = null;
    for (int i = 0; i < values.length; i++) {
        if (values[i] != null) {
            if (minValue == null || minValue.compareTo(values[i]) > 0) {
                minValue = new Long(values[i]);
            }
        }
    }

    return minValue;
}

From source file:edu.harvard.iq.dvn.core.web.admin.OptionsPage.java

public String handleCheckRange_action() {
    handleCheckReport = null;/*from w ww . j a  va  2s .c  om*/

    if (studyIdRange == null || !(studyIdRange.matches("^[0-9][0-9]*$")
            || studyIdRange.matches("^[0-9][0-9]*\\-[0-9][0-9]*$"))) {
        addMessage("handleMessage", "Invalid study ID range!");
        return null;

    }

    String checkOutput = "";

    if (studyIdRange.indexOf('-') > 0) {
        // range: 
        Long idStart = null;
        Long idEnd = null;

        try {
            String rangeStart = studyIdRange.substring(0, studyIdRange.indexOf('-'));
            String rangeEnd = studyIdRange.substring(studyIdRange.indexOf('-') + 1);

            idStart = new Long(rangeStart);
            idEnd = new Long(rangeEnd);
        } catch (Exception ex) {
            addMessage("handleMessage", "Invalid study ID range: " + studyIdRange);
            return null;
        }

        if (!(idStart.compareTo(idEnd) < 0)) {
            addMessage("handleMessage", "Invalid numeric range: " + studyIdRange);
            return null;
        }

        Long studyId = idStart;

        while (studyId.compareTo(idEnd) <= 0) {
            try {
                Study chkStudy = studyService.getStudy(studyId);
                String chkHandle = chkStudy.getAuthority() + "/" + chkStudy.getStudyId();
                if (gnrsService.isHandleRegistered(chkHandle)) {
                    checkOutput = checkOutput.concat(studyId + "\thdl:" + chkHandle + "\tok\n");
                } else {
                    checkOutput = checkOutput.concat(studyId + "\thdl:" + chkHandle + "\tNOT REGISTERED\n");
                }

            } catch (Exception ex) {
                checkOutput = checkOutput.concat(studyId + "\t\tNO SUCH STUDY\n");
            }
            studyId = studyId + 1;
        }
        //addMessage("handleMessage", checkOutput);
        handleCheckReport = checkOutput;

    } else {
        // single id: 
        try {
            Long studyId = new Long(studyIdRange);
            Study chkStudy = studyService.getStudy(studyId);
            String chkHandle = chkStudy.getAuthority() + "/" + chkStudy.getStudyId();
            if (gnrsService.isHandleRegistered(chkHandle)) {
                checkOutput = studyId + "\thdl:" + chkHandle + "\t\tok\n";
            } else {
                checkOutput = studyId + "\thdl:" + chkHandle + "\t\tNOT REGISTERED\n";
            }

            //addMessage("handleMessage", checkOutput);
            handleCheckReport = checkOutput;

        } catch (Exception ex) {
            addMessage("handleMessage", "No such study: id=" + studyIdRange);
        }
    }
    return null;
}

From source file:org.alfresco.repo.search.impl.lucene.ADMLuceneTest.java

/**
 * @throws Exception/*from w  w w . jav a  2  s .  c  om*/
 */
public void testSort() throws Exception {
    Collator collator = Collator.getInstance(I18NUtil.getLocale());

    luceneFTS.pause();
    buildBaseIndex();
    runBaseTests();

    ADMLuceneSearcherImpl searcher = buildSearcher();

    SearchParameters sp = new SearchParameters();
    sp.addStore(rootNodeRef.getStoreRef());
    sp.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp.setQuery("PATH:\"//.\"");
    sp.addSort("ID", true);
    ResultSet results = searcher.query(sp);

    String current = null;
    for (ResultSetRow row : results) {
        String id = row.getNodeRef().getId();

        if (current != null) {
            if (collator.compare(current, id) > 0) {
                fail();
            }
        }
        current = id;
    }
    results.close();

    SearchParameters sp2 = new SearchParameters();
    sp2.addStore(rootNodeRef.getStoreRef());
    sp2.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp2.setQuery("PATH:\"//.\"");
    sp2.addSort("ID", false);
    results = searcher.query(sp2);

    current = null;
    for (ResultSetRow row : results) {
        String id = row.getNodeRef().getId();
        if (current != null) {
            if (collator.compare(current, id) < 0) {
                fail();
            }
        }
        current = id;
    }
    results.close();

    luceneFTS.resume();

    SearchParameters sp3 = new SearchParameters();
    sp3.addStore(rootNodeRef.getStoreRef());
    sp3.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp3.setQuery("PATH:\"//.\"");
    sp3.addSort(SearchParameters.SORT_IN_DOCUMENT_ORDER_ASCENDING);
    results = searcher.query(sp3);

    int count = 0;
    for (ResultSetRow row : results) {
        assertEquals(documentOrder[count++], row.getNodeRef());
    }
    results.close();

    SearchParameters sp4 = new SearchParameters();
    sp4.addStore(rootNodeRef.getStoreRef());
    sp4.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp4.setQuery("PATH:\"//.\"");
    sp4.addSort(SearchParameters.SORT_IN_DOCUMENT_ORDER_DESCENDING);
    results = searcher.query(sp4);

    count = 1;
    for (ResultSetRow row : results) {
        assertEquals(documentOrder[documentOrder.length - (count++)], row.getNodeRef());
    }
    results.close();

    SearchParameters sp5 = new SearchParameters();
    sp5.addStore(rootNodeRef.getStoreRef());
    sp5.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp5.setQuery("PATH:\"//.\"");
    sp5.addSort(SearchParameters.SORT_IN_SCORE_ORDER_ASCENDING);
    results = searcher.query(sp5);

    float score = 0;
    for (ResultSetRow row : results) {
        assertTrue(score <= row.getScore());
        score = row.getScore();
    }
    results.close();

    SearchParameters sp6 = new SearchParameters();
    sp6.addStore(rootNodeRef.getStoreRef());
    sp6.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp6.setQuery("PATH:\"//.\"");
    sp6.addSort(SearchParameters.SORT_IN_SCORE_ORDER_DESCENDING);
    results = searcher.query(sp6);

    score = 1.0f;
    for (ResultSetRow row : results) {
        assertTrue(score >= row.getScore());
        score = row.getScore();
    }
    results.close();

    // sort by created date

    SearchParameters sp7 = new SearchParameters();
    sp7.addStore(rootNodeRef.getStoreRef());
    sp7.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp7.setQuery("PATH:\"//.\"");
    sp7.addSort("@" + createdDate.getPrefixedQName(namespacePrefixResolver), true);
    results = searcher.query(sp7);

    Date date = null;
    for (ResultSetRow row : results) {
        Date currentBun = DefaultTypeConverter.INSTANCE.convert(Date.class,
                nodeService.getProperty(row.getNodeRef(), createdDate));
        // System.out.println(currentBun);
        if (date != null) {
            assertTrue(date.compareTo(currentBun) <= 0);
        }
        date = currentBun;
    }
    results.close();

    SearchParameters sp8 = new SearchParameters();
    sp8.addStore(rootNodeRef.getStoreRef());
    sp8.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp8.setQuery("PATH:\"//.\"");
    sp8.addSort("@" + createdDate, false);
    results = searcher.query(sp8);

    date = null;
    for (ResultSetRow row : results) {
        Date currentBun = DefaultTypeConverter.INSTANCE.convert(Date.class,
                nodeService.getProperty(row.getNodeRef(), createdDate));
        // System.out.println(currentBun);
        if ((date != null) && (currentBun != null)) {
            assertTrue(date.compareTo(currentBun) >= 0);
        }
        date = currentBun;
    }
    results.close();

    SearchParameters sp_7 = new SearchParameters();
    sp_7.addStore(rootNodeRef.getStoreRef());
    sp_7.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp_7.setQuery("PATH:\"//.\"");
    sp_7.addSort("@" + ContentModel.PROP_MODIFIED, true);
    results = searcher.query(sp_7);

    date = null;
    for (ResultSetRow row : results) {
        Date currentBun = DefaultTypeConverter.INSTANCE.convert(Date.class,
                nodeService.getProperty(row.getNodeRef(), ContentModel.PROP_MODIFIED));
        if (currentBun != null) {
            Calendar c = new GregorianCalendar();
            c.setTime(currentBun);
            c.set(Calendar.MILLISECOND, 0);
            c.set(Calendar.SECOND, 0);
            c.set(Calendar.MINUTE, 0);
            c.set(Calendar.HOUR_OF_DAY, 0);
            currentBun = c.getTime();
        }
        if ((date != null) && (currentBun != null)) {
            assertTrue(date.compareTo(currentBun) <= 0);
        }
        date = currentBun;
    }
    results.close();

    SearchParameters sp_8 = new SearchParameters();
    sp_8.addStore(rootNodeRef.getStoreRef());
    sp_8.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp_8.setQuery("PATH:\"//.\"");
    sp_8.addSort("@" + ContentModel.PROP_MODIFIED, false);
    results = searcher.query(sp_8);

    date = null;
    for (ResultSetRow row : results) {
        Date currentBun = DefaultTypeConverter.INSTANCE.convert(Date.class,
                nodeService.getProperty(row.getNodeRef(), ContentModel.PROP_MODIFIED));
        // System.out.println(currentBun);
        if (currentBun != null) {
            Calendar c = new GregorianCalendar();
            c.setTime(currentBun);
            c.set(Calendar.MILLISECOND, 0);
            c.set(Calendar.SECOND, 0);
            c.set(Calendar.MINUTE, 0);
            c.set(Calendar.HOUR_OF_DAY, 0);
            currentBun = c.getTime();
        }

        if ((date != null) && (currentBun != null)) {
            assertTrue(date.compareTo(currentBun) >= 0);
        }
        date = currentBun;
    }
    results.close();

    // sort by double

    SearchParameters sp9 = new SearchParameters();
    sp9.addStore(rootNodeRef.getStoreRef());
    sp9.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp9.setQuery("PATH:\"//.\"");
    sp9.addSort("@" + orderDouble, true);
    results = searcher.query(sp9);

    Double d = null;
    for (ResultSetRow row : results) {
        Double currentBun = DefaultTypeConverter.INSTANCE.convert(Double.class,
                nodeService.getProperty(row.getNodeRef(), orderDouble));
        // System.out.println( (currentBun == null ? "null" : NumericEncoder.encode(currentBun))+ " "+currentBun);
        if (d != null) {
            assertTrue(d.compareTo(currentBun) <= 0);
        }
        d = currentBun;
    }
    results.close();

    SearchParameters sp10 = new SearchParameters();
    sp10.addStore(rootNodeRef.getStoreRef());
    sp10.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp10.setQuery("PATH:\"//.\"");
    sp10.addSort("@" + orderDouble, false);
    results = searcher.query(sp10);

    d = null;
    for (ResultSetRow row : results) {
        Double currentBun = DefaultTypeConverter.INSTANCE.convert(Double.class,
                nodeService.getProperty(row.getNodeRef(), orderDouble));
        // System.out.println(currentBun);
        if ((d != null) && (currentBun != null)) {
            assertTrue(d.compareTo(currentBun) >= 0);
        }
        d = currentBun;
    }
    results.close();

    // sort by float

    SearchParameters sp11 = new SearchParameters();
    sp11.addStore(rootNodeRef.getStoreRef());
    sp11.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp11.setQuery("PATH:\"//.\"");
    sp11.addSort("@" + orderFloat, true);
    results = searcher.query(sp11);

    Float f = null;
    for (ResultSetRow row : results) {
        Float currentBun = DefaultTypeConverter.INSTANCE.convert(Float.class,
                nodeService.getProperty(row.getNodeRef(), orderFloat));
        // System.out.println( (currentBun == null ? "null" : NumericEncoder.encode(currentBun))+ " "+currentBun);
        if (f != null) {
            assertTrue(f.compareTo(currentBun) <= 0);
        }
        f = currentBun;
    }
    results.close();

    SearchParameters sp12 = new SearchParameters();
    sp12.addStore(rootNodeRef.getStoreRef());
    sp12.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp12.setQuery("PATH:\"//.\"");
    sp12.addSort("@" + orderFloat, false);
    results = searcher.query(sp12);

    f = null;
    for (ResultSetRow row : results) {
        Float currentBun = DefaultTypeConverter.INSTANCE.convert(Float.class,
                nodeService.getProperty(row.getNodeRef(), orderFloat));
        // System.out.println(currentBun);
        if ((f != null) && (currentBun != null)) {
            assertTrue(f.compareTo(currentBun) >= 0);
        }
        f = currentBun;
    }
    results.close();

    // sort by long

    SearchParameters sp13 = new SearchParameters();
    sp13.addStore(rootNodeRef.getStoreRef());
    sp13.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp13.setQuery("PATH:\"//.\"");
    sp13.addSort("@" + orderLong, true);
    results = searcher.query(sp13);

    Long l = null;
    for (ResultSetRow row : results) {
        Long currentBun = DefaultTypeConverter.INSTANCE.convert(Long.class,
                nodeService.getProperty(row.getNodeRef(), orderLong));
        // System.out.println( (currentBun == null ? "null" : NumericEncoder.encode(currentBun))+ " "+currentBun);
        if (l != null) {
            assertTrue(l.compareTo(currentBun) <= 0);
        }
        l = currentBun;
    }
    results.close();

    SearchParameters sp14 = new SearchParameters();
    sp14.addStore(rootNodeRef.getStoreRef());
    sp14.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp14.setQuery("PATH:\"//.\"");
    sp14.addSort("@" + orderLong, false);
    results = searcher.query(sp14);

    l = null;
    for (ResultSetRow row : results) {
        Long currentBun = DefaultTypeConverter.INSTANCE.convert(Long.class,
                nodeService.getProperty(row.getNodeRef(), orderLong));
        // System.out.println(currentBun);
        if ((l != null) && (currentBun != null)) {
            assertTrue(l.compareTo(currentBun) >= 0);
        }
        l = currentBun;
    }
    results.close();

    // sort by int

    SearchParameters sp15 = new SearchParameters();
    sp15.addStore(rootNodeRef.getStoreRef());
    sp15.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp15.setQuery("PATH:\"//.\"");
    sp15.addSort("@" + orderInt, true);
    results = searcher.query(sp15);

    Integer i = null;
    for (ResultSetRow row : results) {
        Integer currentBun = DefaultTypeConverter.INSTANCE.convert(Integer.class,
                nodeService.getProperty(row.getNodeRef(), orderInt));
        // System.out.println( (currentBun == null ? "null" : NumericEncoder.encode(currentBun))+ " "+currentBun);
        if (i != null) {
            assertTrue(i.compareTo(currentBun) <= 0);
        }
        i = currentBun;
    }
    results.close();

    SearchParameters sp16 = new SearchParameters();
    sp16.addStore(rootNodeRef.getStoreRef());
    sp16.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp16.setQuery("PATH:\"//.\"");
    sp16.addSort("@" + orderInt, false);
    results = searcher.query(sp16);

    i = null;
    for (ResultSetRow row : results) {
        Integer currentBun = DefaultTypeConverter.INSTANCE.convert(Integer.class,
                nodeService.getProperty(row.getNodeRef(), orderInt));
        // System.out.println(currentBun);
        if ((i != null) && (currentBun != null)) {
            assertTrue(i.compareTo(currentBun) >= 0);
        }
        i = currentBun;
    }
    results.close();

    // sort by text

    SearchParameters sp17 = new SearchParameters();
    sp17.addStore(rootNodeRef.getStoreRef());
    sp17.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp17.setQuery("PATH:\"//.\"");
    sp17.addSort("@" + orderText, true);
    results = searcher.query(sp17);

    String text = null;
    for (ResultSetRow row : results) {
        String currentBun = DefaultTypeConverter.INSTANCE.convert(String.class,
                nodeService.getProperty(row.getNodeRef(), orderText));
        // System.out.println( (currentBun == null ? "null" : NumericEncoder.encode(currentBun))+ " "+currentBun);
        if ((text != null) && (currentBun != null)) {
            assertTrue(collator.compare(text, currentBun) <= 0);
        }
        text = currentBun;
    }
    results.close();

    SearchParameters sp18 = new SearchParameters();
    sp18.addStore(rootNodeRef.getStoreRef());
    sp18.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp18.setQuery("PATH:\"//.\"");
    sp18.addSort("@" + orderText, false);
    results = searcher.query(sp18);

    text = null;
    for (ResultSetRow row : results) {
        String currentBun = DefaultTypeConverter.INSTANCE.convert(String.class,
                nodeService.getProperty(row.getNodeRef(), orderText));
        // System.out.println(currentBun);
        if ((text != null) && (currentBun != null)) {
            assertTrue(collator.compare(text, currentBun) >= 0);
        }
        text = currentBun;
    }
    results.close();

    // sort by content size

    // sort by ML text

    // Locale[] testLocales = new Locale[] { I18NUtil.getLocale(), Locale.ENGLISH, Locale.FRENCH, Locale.CHINESE };
    Locale[] testLocales = new Locale[] { I18NUtil.getLocale(), Locale.ENGLISH, Locale.FRENCH };
    for (Locale testLocale : testLocales) {
        Collator localisedCollator = Collator.getInstance(testLocale);

        SearchParameters sp19 = new SearchParameters();
        sp19.addStore(rootNodeRef.getStoreRef());
        sp19.setLanguage(SearchService.LANGUAGE_LUCENE);
        sp19.setQuery("PATH:\"//.\"");
        sp19.addSort("@" + orderMLText, true);
        sp19.addLocale(testLocale);
        results = searcher.query(sp19);

        text = null;
        for (ResultSetRow row : results) {
            MLText mltext = DefaultTypeConverter.INSTANCE.convert(MLText.class,
                    nodeService.getProperty(row.getNodeRef(), orderMLText));
            if (mltext != null) {
                String currentBun = mltext.getValue(testLocale);
                // System.out.println( (currentBun == null ? "null" : NumericEncoder.encode(currentBun))+ "
                // "+currentBun);
                if ((text != null) && (currentBun != null)) {
                    assertTrue(localisedCollator.compare(text, currentBun) <= 0);
                }
                text = currentBun;
            }
        }
        results.close();

        SearchParameters sp20 = new SearchParameters();
        sp20.addStore(rootNodeRef.getStoreRef());
        sp20.setLanguage(SearchService.LANGUAGE_LUCENE);
        sp20.setQuery("PATH:\"//.\"");
        sp20.addSort("@" + orderMLText, false);
        sp20.addLocale(testLocale);
        results = searcher.query(sp20);

        text = null;
        for (ResultSetRow row : results) {
            MLText mltext = DefaultTypeConverter.INSTANCE.convert(MLText.class,
                    nodeService.getProperty(row.getNodeRef(), orderMLText));
            if (mltext != null) {
                String currentBun = mltext.getValue(testLocale);
                if ((text != null) && (currentBun != null)) {
                    assertTrue(localisedCollator.compare(text, currentBun) >= 0);
                }
                text = currentBun;
            }
        }
        results.close();

    }

    luceneFTS.resume();

    SearchParameters spN = new SearchParameters();
    spN.addStore(rootNodeRef.getStoreRef());
    spN.setLanguage(SearchService.LANGUAGE_LUCENE);
    spN.setQuery("PATH:\"//.\"");
    spN.addSort("cabbage", false);
    results = searcher.query(spN);
    results.close();

    // test sort on unkown properties ALF-4193

    spN = new SearchParameters();
    spN.addStore(rootNodeRef.getStoreRef());
    spN.setLanguage(SearchService.LANGUAGE_LUCENE);
    spN.setQuery("PATH:\"//.\"");
    spN.addSort("PARENT", false);
    results = searcher.query(spN);
    results.close();

    spN = new SearchParameters();
    spN.addStore(rootNodeRef.getStoreRef());
    spN.setLanguage(SearchService.LANGUAGE_LUCENE);
    spN.setQuery("PATH:\"//.\"");
    spN.addSort("@PARENT:PARENT", false);
    results = searcher.query(spN);
    results.close();

    luceneFTS.resume();

    // sort by content size

    SearchParameters sp20 = new SearchParameters();
    sp20.addStore(rootNodeRef.getStoreRef());
    sp20.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp20.setQuery("PATH:\"//.\"");
    sp20.addSort("@" + ContentModel.PROP_CONTENT + ".size", false);
    results = searcher.query(sp20);

    Long size = null;
    for (ResultSetRow row : results) {
        ContentData currentBun = DefaultTypeConverter.INSTANCE.convert(ContentData.class,
                nodeService.getProperty(row.getNodeRef(), ContentModel.PROP_CONTENT));
        // System.out.println(currentBun);
        if ((size != null) && (currentBun != null)) {
            assertTrue(size.compareTo(currentBun.getSize()) >= 0);
        }
        if (currentBun != null) {
            size = currentBun.getSize();
        }
    }
    results.close();

    // sort by content mimetype

    SearchParameters sp21 = new SearchParameters();
    sp21.addStore(rootNodeRef.getStoreRef());
    sp21.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp21.setQuery("PATH:\"//.\"");
    sp21.addSort("@" + ContentModel.PROP_CONTENT + ".mimetype", false);
    results = searcher.query(sp21);

    String mimetype = null;
    for (ResultSetRow row : results) {
        ContentData currentBun = DefaultTypeConverter.INSTANCE.convert(ContentData.class,
                nodeService.getProperty(row.getNodeRef(), ContentModel.PROP_CONTENT));
        // System.out.println(currentBun);
        if ((mimetype != null) && (currentBun != null)) {
            assertTrue(mimetype.compareTo(currentBun.getMimetype()) >= 0);
        }
        if (currentBun != null) {
            mimetype = currentBun.getMimetype();
        }
    }
    results.close();

}

From source file:ca.oson.json.Oson.java

private <E, R> String long2Json(FieldData objectDTO) {
    if (objectDTO == null || objectDTO.json2Java) {
        return null;
    }//from   w w  w.jav a2  s.  c  o m

    E value = (E) objectDTO.valueToProcess;
    Class<R> returnType = objectDTO.returnType;

    if (returnType != null && value != null && (returnType == long.class || returnType == Long.class)) {
        Long valueToProcess = null;

        if (returnType == long.class) {
            valueToProcess = Long.valueOf((Long) value);
        } else {
            valueToProcess = (Long) value;
        }

        if (valueToProcess != null) {
            try {

                Function function = objectDTO.getSerializer();
                if (function != null) {
                    if (function instanceof DataMapper2JsonFunction) {
                        DataMapper classData = new DataMapper(returnType, value, objectDTO.classMapper,
                                objectDTO.level, getPrettyIndentation());
                        return ((DataMapper2JsonFunction) function).apply(classData);

                    } else if (function instanceof Long2JsonFunction) {
                        return ((Long2JsonFunction) function).apply(valueToProcess);

                    } else {

                        Object returnedValue = function.apply(valueToProcess);

                        if (returnedValue instanceof Optional) {
                            returnedValue = ObjectUtil.unwrap(returnedValue);
                        }

                        if (returnedValue == null) {
                            return null;

                        } else if (returnedValue instanceof Long) {
                            valueToProcess = (Long) returnedValue;

                        } else {
                            objectDTO.valueToProcess = returnedValue;
                            return object2String(objectDTO);
                        }

                    }

                }

                if (valueToProcess != null) {
                    Long min = objectDTO.getMin();
                    Long max = objectDTO.getMax();

                    if (min != null && min > valueToProcess.longValue()) {
                        valueToProcess = min.longValue();
                    }

                    if (max != null && valueToProcess.compareTo(Long.valueOf(max)) > 0) {
                        valueToProcess = Long.valueOf(max);
                    }

                    Integer precision = objectDTO.getPrecision();
                    if (precision != null) {
                        valueToProcess = (Long) NumberUtil.setPrecision(valueToProcess, precision,
                                getRoundingMode());
                    }

                    return NumberUtil.toPlainString(valueToProcess);
                }

            } catch (Exception ex) {
                // ex.printStackTrace();
            }
        }
    }

    return long2JsonDefault(objectDTO);
}

From source file:ca.oson.json.Oson.java

private <E, R> Long json2Long(FieldData objectDTO) {
    if (objectDTO == null || !objectDTO.json2Java) {
        return null;
    }/* www  .j av  a  2  s  .com*/

    E value = (E) objectDTO.valueToProcess;
    Class<R> returnType = objectDTO.returnType;

    Long valueToReturn = null;

    if (value != null && value.toString().trim().length() > 0) {
        String valueToProcess = value.toString().trim();

        try {
            Function function = objectDTO.getDeserializer();

            if (function != null) {
                try {
                    Object returnedValue = null;

                    if (function instanceof Json2DataMapperFunction) {
                        DataMapper classData = new DataMapper(returnType, value, objectDTO.classMapper,
                                objectDTO.level, getPrettyIndentation());
                        returnedValue = ((Json2DataMapperFunction) function).apply(classData);

                    } else if (function instanceof Json2FieldDataFunction) {
                        Json2FieldDataFunction f = (Json2FieldDataFunction) function;
                        FieldData fieldData = objectDTO.clone();

                        returnedValue = f.apply(fieldData);

                    } else if (function instanceof Json2LongFunction) {
                        return ((Json2LongFunction) function).apply(valueToProcess);
                    } else {
                        returnedValue = function.apply(valueToProcess);
                    }

                    if (returnedValue instanceof Optional) {
                        returnedValue = ObjectUtil.unwrap(returnedValue);
                    }

                    if (returnedValue == null) {
                        return null;

                        //  || returnedValue.getClass().isPrimitive()
                    } else if (Number.class.isAssignableFrom(returnedValue.getClass())) {

                        if (returnedValue instanceof Long) {
                            valueToReturn = (Long) returnedValue;

                        } else if (returnedValue instanceof String) {
                            valueToReturn = Long
                                    .parseLong(NumberUtil.removeTrailingDecimalZeros(returnedValue));
                            //  byte, double, float, int, long, and short.
                        } else if (returnedValue instanceof Integer) {
                            valueToReturn = ((Integer) returnedValue).longValue();
                        } else if (returnedValue instanceof Double) {
                            valueToReturn = ((Double) returnedValue).longValue();
                        } else if (returnedValue instanceof Float) {
                            valueToReturn = ((Float) returnedValue).longValue();
                        } else if (returnedValue instanceof Byte) {
                            valueToReturn = ((Byte) returnedValue).longValue();
                        } else if (returnedValue instanceof Short) {
                            valueToReturn = ((Short) returnedValue).longValue();
                        } else if (returnedValue instanceof BigInteger) {
                            valueToReturn = ((BigInteger) returnedValue).longValue();
                        } else if (returnedValue instanceof BigDecimal) {
                            valueToReturn = ((BigDecimal) returnedValue).longValue();
                        } else if (returnedValue instanceof AtomicInteger) {
                            valueToReturn = ((AtomicInteger) returnedValue).longValue();
                        } else if (returnedValue instanceof AtomicLong) {
                            valueToReturn = ((AtomicLong) returnedValue).longValue();
                        } else {
                            valueToReturn = ((Number) returnedValue).longValue();
                        }

                    } else if (returnedValue instanceof Character) {
                        valueToReturn = Long.valueOf((Character.getNumericValue((Character) returnedValue)));

                    } else if (Enum.class.isAssignableFrom(returnedValue.getClass())) {
                        valueToReturn = Long.valueOf(((Enum) returnedValue).ordinal());

                    } else if (returnedValue instanceof Boolean) {
                        if ((Boolean) returnedValue)
                            valueToReturn = 1l;
                        else
                            valueToReturn = 0l;

                    } else if (Date.class.isAssignableFrom(returnedValue.getClass())) {
                        valueToReturn = ((Date) returnedValue).getTime();

                    } else {
                        valueToReturn = Long.parseLong(NumberUtil.removeTrailingDecimalZeros(returnedValue));
                    }

                    return valueToReturn;

                } catch (Exception e) {
                    e.printStackTrace();
                }

            } else {
                valueToReturn = Long.parseLong(NumberUtil.removeTrailingDecimalZeros(valueToProcess));
            }

            if (valueToReturn != null) {
                Long min = objectDTO.getMin();
                Long max = objectDTO.getMax();
                if (min != null && min > valueToReturn.longValue()) {
                    return min.longValue();
                }

                if (max != null && valueToReturn.compareTo(Long.valueOf(max)) > 0) {
                    valueToReturn = Long.valueOf(max);
                }

                return valueToReturn;
            }

        } catch (Exception ex) {
            //ex.printStackTrace();
        }

    }

    return json2LongDefault(objectDTO);
}