All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.databasesandlife.util.UuidTreeSet Maven / Gradle / Ivy

There is a newer version: 21.0.1
Show newest version
package com.databasesandlife.util;

import java.util.Collection;
import java.util.Comparator;
import java.util.TreeSet;
import java.util.UUID;

/**
 * This is an ordered set of UUIDs.
 * Unfortunately a standard TreeSet of UUIDs is broken, it puts them in the wrong order,
 * see this Java bug which is marked "will not fix".
 *
 * @author This source is copyright Adrian Smith and licensed under the LGPL 3.
 * @see Project on GitHub
 */
public class UuidTreeSet extends TreeSet {

    public static class UuidComparator implements Comparator {
        @Override public int compare(UUID o1, UUID o2) {
            return o1.toString().compareTo(o2.toString());
        }
    }

    public UuidTreeSet() {
        super(new UuidComparator());
    }

    public UuidTreeSet(Collection values) {
        this();
        addAll(values);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy