Example usage for java.util SortedSet comparator

List of usage examples for java.util SortedSet comparator

Introduction

In this page you can find the example usage for java.util SortedSet comparator.

Prototype

Comparator<? super E> comparator();

Source Link

Document

Returns the comparator used to order the elements in this set, or null if this set uses the Comparable natural ordering of its elements.

Usage

From source file:com.erinors.hpb.server.handler.SortedSetHandler.java

@Override
public Object clone(CloningContext context, Object object) {
    if (!(object instanceof SortedSet)) {
        return null;
    }/*from  w w  w .j a  v  a2s  .  c o  m*/

    SortedSet<Object> source = (SortedSet<Object>) object;
    SortedSet<Object> result;

    if (source instanceof PersistentSortedSet && !((PersistentSortedSet) source).wasInitialized()) {
        result = new UninitializedPersistentSortedSet<Object>(source.comparator());
        context.addProcessedObject(object, result);
    } else {
        SortedSet<Object> set = new TreeSet<Object>(source.comparator());
        context.addProcessedObject(object, set);

        for (Object element : source) {
            set.add(context.clone(element));
        }

        result = set;
    }

    return result;
}

From source file:jenkins.metrics.util.NameRewriterMetricRegistry.java

private <T> SortedSet<String> rewrite(SortedSet<String> original) {
    if (StringUtils.isBlank(prefix) && StringUtils.isBlank(postfix)) {
        return original;
    }//from  w ww  .  j  a va  2  s  .  c o  m
    SortedSet<String> result = new TreeSet<String>(original.comparator());
    for (String name : original) {
        result.add(name(prefix, name, postfix));
    }
    return result;
}

From source file:com.erinors.hpb.server.handler.SortedSetHandler.java

@Override
public Object merge(MergingContext context, Object object) {
    if (!(object instanceof SortedSet)) {
        return null;
    }// ww  w .  j a  v a 2  s  .c  om

    SortedSet<Object> source = (SortedSet<Object>) object;
    SortedSet<Object> result;

    if (source instanceof UninitializedPersistentSortedSet) {
        result = new PersistentSortedSet(context.getSessionImplementor(), source);
        context.addProcessedObject(object, result);
    } else {
        SortedSet<Object> set = new TreeSet<Object>(source.comparator());
        context.addProcessedObject(object, set);

        for (Object element : source) {
            set.add(context.merge(element));
        }

        result = set;
    }

    return result;
}

From source file:com.google.gwt.emultest.java.util.TreeSetTest.java

/**
 * Test method for 'java.util.SortedSet.comparator()'.
 *
 * @see java.util.SortedSet#comparator()
 *//*  w  ww  .ja  v  a  2s  .  co m*/
public void testComparator() {
    SortedSet<E> sortedSet = createNavigableSet();
    if (isNaturalOrder()) {
        assertEquals(null, sortedSet.comparator());
    } else {
        assertEquals(getComparator(), sortedSet.comparator());
    }
}

From source file:org.jahia.services.importexport.DocumentViewExporter.java

public void export(JCRNodeWrapper rootNode, SortedSet<JCRNodeWrapper> nodes)
        throws SAXException, RepositoryException {
    this.rootNode = rootNode;

    ch.startDocument();/*from ww  w.  j  a va 2s  .co m*/

    nodesList = new ArrayList<JCRNodeWrapper>(nodes);
    for (int i = 0; i < nodesList.size(); i++) {
        List<JCRNodeWrapper> subList = new ArrayList<JCRNodeWrapper>(nodesList.subList(i, nodesList.size()));
        Collections.sort(subList, nodes.comparator());
        nodesList.removeAll(subList);
        nodesList.addAll(subList);
        if (nodesList.get(i).getProvider().canExportNode(nodesList.get(i))) {
            exportNode(nodesList.get(i));
        }
    }
    //        for (Iterator<JCRNodeWrapper> iterator = nodes.iterator(); iterator.hasNext();) {
    //            JCRNodeWrapper node = iterator.next();
    //            exportNode(node);
    //        }
    while (!stack.isEmpty()) {
        String end = stack.pop();
        String name = end.substring(end.lastIndexOf('/') + 1);
        String encodedName = ISO9075.encode(name);
        endElement(encodedName);
    }

    ch.endDocument();
}

From source file:uk.co.flax.biosolr.TreeFacetField.java

private SortedSet<TreeFacetField> cloneHierarchy(SortedSet<TreeFacetField> orig) {
    SortedSet<TreeFacetField> cloned = null;

    if (orig != null) {
        cloned = new TreeSet<>(orig.comparator());

        for (TreeFacetField tff : orig) {
            cloned.add(tff.clone());// w  ww  . j  ava  2s  .  co  m
        }
    }

    return cloned;
}