Example usage for org.apache.commons.collections Bag iterator

List of usage examples for org.apache.commons.collections Bag iterator

Introduction

In this page you can find the example usage for org.apache.commons.collections Bag iterator.

Prototype

Iterator iterator();

Source Link

Document

Returns an Iterator over the entire set of members, including copies due to cardinality.

Usage

From source file:org.apache.maven.shared.jar.identification.exposers.TimestampExposer.java

public void expose(JarIdentification identification, JarAnalyzer jarAnalyzer) {
    List entries = jarAnalyzer.getEntries();
    SimpleDateFormat tsformat = new SimpleDateFormat("yyyyMMdd", Locale.US); //$NON-NLS-1$
    Bag timestamps = new HashBag();
    Iterator it = entries.iterator();
    while (it.hasNext()) {
        JarEntry entry = (JarEntry) it.next();
        long time = entry.getTime();
        String timestamp = tsformat.format(new Date(time));
        timestamps.add(timestamp);/*w  ww  . java 2s . co m*/
    }

    it = timestamps.iterator();
    String ts = "";
    int tsmax = 0;
    while (it.hasNext()) {
        String timestamp = (String) it.next();
        int count = timestamps.getCount(timestamp);
        if (count > tsmax) {
            ts = timestamp;
            tsmax = count;
        }
    }

    if (StringUtils.isNotEmpty(ts)) {
        identification.addVersion(ts);
    }
}

From source file:org.marketcetera.util.test.CollectionAssert.java

/**
 * Asserts that the two given arrays are permutations of each
 * other. This assertion holds if both arrays are null, or if they
 * have one or more (but an equal number of) null elements. If the
 * assertion does not hold, the {@link AssertionError} thrown
 * starts with the given message, which may be null if no such
 * custom message prefix is desired./* w  ww. j  a v a  2s. c  om*/
 *
 * @param message The identifying message.
 * @param expected The expected array.
 * @param actual The actual array.
 */

public static <T> void assertArrayPermutation(String message, T[] expected, T[] actual) {
    if ((expected == null) && (actual == null)) {
        return;
    }
    String content = null;
    if (expected == null) {
        content = "expected array is null but actual is not"; //$NON-NLS-1$
    } else if (actual == null) {
        content = "actual array is null but expected is not"; //$NON-NLS-1$
    } else if (expected.getClass() != actual.getClass()) {
        content = "expected array class is " + //$NON-NLS-1$
                expected.getClass().getName() + " but actual array class is " + //$NON-NLS-1$
                actual.getClass().getName();
    } else {
        Bag expectedBag = new HashBag(Arrays.asList(expected));
        Bag actualBag = new HashBag(Arrays.asList(actual));
        for (Object e : expectedBag) {
            if (!actualBag.remove(e, 1)) {
                content = "actual is missing '" + //$NON-NLS-1$
                        e + "'"; //$NON-NLS-1$
                break;
            }
        }
        if (content == null) {
            if (actualBag.size() == 0) {
                return;
            }
            content = "actual contains extra elements such as " + //$NON-NLS-1$
                    actualBag.iterator().next();
        }
    }
    if (message != null) {
        content = message + " " + content; //$NON-NLS-1$
    }
    fail(content);
}