Example usage for java.util SortedSet iterator

List of usage examples for java.util SortedSet iterator

Introduction

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

Prototype

Iterator<E> iterator();

Source Link

Document

Returns an iterator over the elements in this set.

Usage

From source file:com.tussle.main.Utility.java

public static Collection<ProjectionVector> prunedProjections(Collection<ProjectionVector> vectors) {
    SortedSet<ProjectionVector> sortedVectors = new ConcurrentSkipListSet<>(
            Comparator.comparingDouble((ProjectionVector p) -> -p.magnitude()));
    sortedVectors.addAll(vectors);/*from ww  w. ja v a2  s .  com*/
    if (isPruned(sortedVectors))
        return sortedVectors;
    double reduceMagnitude = 0;
    Iterator<ProjectionVector> i = sortedVectors.iterator();
    ProjectionVector p0 = i.next();
    ProjectionVector p1 = i.next();
    double cos0 = p0.xNorm();
    double sin0 = p0.yNorm();
    double cos1 = p1.xNorm();
    double sin1 = p1.yNorm();
    //zeroth on the right, first on the left
    if (cos0 * sin1 < cos1 * sin0) {
        double tmpcos = cos1;
        double tmpsin = sin1;
        cos1 = cos0;
        sin1 = sin0;
        cos0 = tmpcos;
        sin0 = tmpsin;
    }
    while (i.hasNext()) {
        ProjectionVector next = i.next();
        double nextcos = next.xNorm();
        double nextsin = next.yNorm();
        if (nextcos * sin0 >= cos0 * nextsin && cos1 * nextsin >= nextcos * sin1) {
            //Case 0: Within cross product bounds
        } else if (nextcos * sin0 >= cos0 * nextsin) {
            //Case 1: Over the left, extend those bounds
            cos1 = nextcos;
            sin1 = nextsin;
        } else if (cos1 * nextsin >= nextcos * sin1) {
            //Case 2: Over the right, extend those bounds
            cos0 = nextcos;
            sin0 = nextsin;
        } else {
            //Case 3: Opposite side, immediately return false
            reduceMagnitude = next.magnitude();
            break;
        }
    }
    //Now given reduceMagnitude, remove elements with lesser magnitude and
    //reduce the magnitude of remaining elements
    if (Double.isFinite(reduceMagnitude)) {
        for (Iterator<ProjectionVector> j = sortedVectors.iterator(); j.hasNext();) {
            ProjectionVector vec = j.next();
            if (vec.magnitude() <= reduceMagnitude)
                j.remove();
            else
                vec = new ProjectionVector(vec.xNorm(), vec.yNorm(), vec.magnitude() - reduceMagnitude);
        }
    }
    return sortedVectors;
}

From source file:org.jasig.schedassist.model.AvailableBlockBuilder.java

/**
 * Combine adjacent {@link AvailableBlock}s in the argument {@link Set}.
 * /* w ww .  java 2 s .c o  m*/
 * @param smallBlocks
 * @return the new set
 */
public static SortedSet<AvailableBlock> combine(SortedSet<AvailableBlock> smallBlocks) {
    SortedSet<AvailableBlock> largeBlocks = new TreeSet<AvailableBlock>();

    Iterator<AvailableBlock> smallBlockIterator = smallBlocks.iterator();

    if (smallBlockIterator.hasNext()) {
        AvailableBlock current = smallBlockIterator.next();
        while (smallBlockIterator.hasNext()) {
            AvailableBlock next = smallBlockIterator.next();
            if (combinable(current, next)) {
                // current and next are adjacent AND have the same visitorLimit AND have same meetinglocation
                // update current to have current.startTime and next.endTime
                try {
                    current = new AvailableBlock(current.getStartTime(), next.getEndTime(),
                            current.getVisitorLimit(), current.getMeetingLocation());
                } catch (IllegalArgumentException e) {
                    // could not create a block, what to do?
                    LOG.error("failed to create an AvailableBlock from " + current.getStartTime() + " and "
                            + next.getEndTime(), e);
                }
            } else {
                // current and next are either not adjacent or have a different visitorLimit
                // current should be pushed into largeBlocks
                largeBlocks.add(current);
                // current should now point to next
                current = next;
            }
        }
        // guarantee that current gets pushed into largeBlocks
        largeBlocks.add(current);
    }

    return largeBlocks;
}

From source file:org.opennms.netmgt.dao.NodeDaoIT.java

private static <T> void assertSetsEqual(Set<T> expectedSet, Set<T> actualSet, String orderProperty,
        AssertEquals<T> comparer) throws Exception {
    SortedSet<T> expectedSorted = new TreeSet<T>(new PropertyComparator(orderProperty));
    expectedSorted.addAll(expectedSet);// ww  w  .j av  a 2s. com
    SortedSet<T> actualSorted = new TreeSet<T>(new PropertyComparator(orderProperty));
    actualSorted.addAll(actualSet);

    Iterator<T> expected = expectedSorted.iterator();
    Iterator<T> actual = actualSorted.iterator();

    while (expected.hasNext() && actual.hasNext()) {
        comparer.assertEqual(expected.next(), actual.next());
    }

    if (expected.hasNext())
        fail("Missing item " + expected.next() + " in the actual list");

    if (actual.hasNext())
        fail("Unexpected item " + actual.next() + " in the actual list");
}

From source file:github.daneren2005.dsub.util.FileUtil.java

public static SortedSet<File> listMediaFiles(File dir) {
    SortedSet<File> files = listFiles(dir);
    Iterator<File> iterator = files.iterator();
    while (iterator.hasNext()) {
        File file = iterator.next();
        if (!file.isDirectory() && !isMediaFile(file)) {
            iterator.remove();//from   www.  ja v  a  2  s  . co  m
        }
    }
    return files;
}

From source file:com.aurel.track.admin.customize.category.filter.execute.loadItems.LoadItemLinksUtil.java

/**
 * Add the linked items to reportbeans//from   w  w w .ja  v  a  2  s. c o  m
 * set also the show value for linked items
 * @param reportBeansList
 * @param personID
 * @param locale
 * @return
 */
public static List<ReportBean> addAllLinkedWorkItemsToReportBeans(List<ReportBean> reportBeansList,
        List<TWorkItemLinkBean> itemLinkBeans, Integer personID, Locale locale) {
    if (reportBeansList != null) {
        boolean useProjectSpecificID = false;
        ApplicationBean appBean = ApplicationBean.getInstance();
        if (appBean.getSiteBean().getProjectSpecificIDsOn() != null) {
            useProjectSpecificID = appBean.getSiteBean().getProjectSpecificIDsOn().booleanValue();
        }
        List<TWorkItemBean> itemBeanList = new LinkedList<TWorkItemBean>();
        if (reportBeansList != null) {
            for (ReportBean reportBean : reportBeansList) {
                TWorkItemBean workItemBean = reportBean.getWorkItemBean();
                itemBeanList.add(workItemBean);
            }
        }
        Map<Integer, SortedSet<ReportBeanLink>> ganntMSProjectReportBeanLinksMap = new HashMap<Integer, SortedSet<ReportBeanLink>>();
        Map<Integer, SortedSet<ReportBeanLink>> allLinkedWorkItemsMap = getAllLinkedWorkItems(itemBeanList,
                itemLinkBeans, personID, locale, ganntMSProjectReportBeanLinksMap);
        for (ReportBean reportBean : reportBeansList) {
            TWorkItemBean workItemBean = reportBean.getWorkItemBean();
            Integer workItemID = workItemBean.getObjectID();
            SortedSet<ReportBeanLink> reportBeanLinksSet = allLinkedWorkItemsMap.get(workItemID);
            if (reportBeanLinksSet != null) {
                reportBean.setReportBeanLinksSet(reportBeanLinksSet);
                //set also the show value
                StringBuilder stringBuilder = new StringBuilder();
                for (Iterator<ReportBeanLink> iterator = reportBeanLinksSet.iterator(); iterator.hasNext();) {
                    ReportBeanLink reportBeanLink = iterator.next();
                    String showLink = null;
                    if (useProjectSpecificID) {
                        showLink = reportBeanLink.getProjectSpecificIssueNo();
                    } else {
                        showLink = reportBeanLink.getWorkItemID().toString();
                    }
                    stringBuilder.append(showLink);
                    if (iterator.hasNext()) {
                        stringBuilder.append(" | ");
                    }
                }
                Map<Integer, String> showValuesMap = reportBean.getShowValuesMap();
                if (showValuesMap != null) {
                    showValuesMap.put(TReportLayoutBean.PSEUDO_COLUMNS.LINKED_ITEMS, stringBuilder.toString());
                }
            }
            SortedSet<ReportBeanLink> ganntMSProjectReportBeanLinksSet = ganntMSProjectReportBeanLinksMap
                    .get(workItemID);
            if (ganntMSProjectReportBeanLinksSet != null) {
                reportBean.setGanntMSProjectReportBeanLinksSet(ganntMSProjectReportBeanLinksSet);
            }
        }
    }
    return reportBeansList;
}

From source file:nl.nn.adapterframework.extensions.sap.SapSystemFactory.java

public Iterator<String> getRegisteredSapSystemNames() {
    SortedSet<String> sortedKeys = new TreeSet<String>(sapSystems.keySet());
    return sortedKeys.iterator();
}

From source file:com.expedia.seiso.security.SeisoUserDetailsContextMapper.java

private String extractUnique(DirContextOperations ctx, String name) {
    SortedSet<String> mailSet = ctx.getAttributeSortedStringSet(name);
    Iterator<String> it = mailSet.iterator();
    return it.hasNext() ? it.next() : null;
}

From source file:nl.nn.adapterframework.jms.JmsRealmFactory.java

/**
 * Get the realmnames as an Iterator, alphabetically sorted
 * @return Iterator with the realm names, alphabetically sorted
 *//* ww  w.  ja v  a 2 s. c  om*/
public Iterator getRegisteredRealmNames() {
    SortedSet sortedKeys = new TreeSet(jmsRealms.keySet());
    return sortedKeys.iterator();
}

From source file:org.sonar.plugins.kt.advance.util.MapCounter.java

/**
 * [{"kt_pev_open":[0.1,1.0]},{"kt_pev_violated":[0.1,1.0]}]
 *
 * @return//from   ww w .  jav a 2s .c om
 */
public String toJson() {
    final StringBuilder sb = new StringBuilder();
    sb.append("[");

    final SortedSet<K> set = new TreeSet<>(keySet());
    final Iterator<K> iterator = set.iterator();
    while (iterator.hasNext()) {

        final K key = iterator.next();
        sb.append("{");

        sb.append("\"key\":");
        sb.append("\"").append(key).append("\",");
        sb.append("\"value\":");
        sb.append("[").append(StringUtils.join(map.get(key), ",")).append("]");

        sb.append("}");
        if (iterator.hasNext()) {
            sb.append(",");
        }

    }
    sb.append("]");
    return sb.toString();
}

From source file:com.liangc.hq.base.utils.BizappUtils.java

public static List sortAppdefResourceType(List resourceType) {
    List sortedList = new ArrayList();
    SortedSet sSet = new TreeSet(COMPARE_NAME);
    sSet.addAll(resourceType);/*from ww w  .  j  a  v a2 s  .  c om*/
    CollectionUtils.addAll(sortedList, sSet.iterator());
    return sortedList;
}