Example usage for java.util TreeSet add

List of usage examples for java.util TreeSet add

Introduction

In this page you can find the example usage for java.util TreeSet add.

Prototype

public boolean add(E e) 

Source Link

Document

Adds the specified element to this set if it is not already present.

Usage

From source file:ml.arunreddy.research.sentiment.graphtransfer.ucross.GraphMatrixGenerator.java

private static List<String> getUniqueUsers(InstanceList posList, InstanceList negList) {
    TreeSet<String> uniqueUsersSet = new TreeSet<String>();
    ArrayList<String> uniqueUsersList = new ArrayList<String>();

    // Positive posts.
    for (Instance instance : posList) {
        String instanceName = (String) instance.getName();
        String user = instanceName.split("__")[1];
        uniqueUsersSet.add(user);
    }//from  w ww .  j a  va  2s  .  c  o  m

    // Negative posts.
    for (Instance instance : negList) {
        String instanceName = (String) instance.getName();
        String user = instanceName.split("__")[1];
        uniqueUsersSet.add(user);
    }

    uniqueUsersList.addAll(uniqueUsersSet);

    return uniqueUsersList;
}

From source file:ai.susi.json.JsonRepository.java

private static SortedSet<File> getDumps(final File path, final String prefix, final String suffix, int count) {
    String[] list = path.list();//www .java 2s.co  m
    TreeSet<File> dumps = new TreeSet<File>(); // sort the names with a tree set
    for (String s : list) {
        if ((prefix == null || s.startsWith(prefix)) && (suffix == null || s.endsWith(suffix)))
            dumps.add(new File(path, s));
    }
    return tailSet(dumps, count);
}

From source file:org.opendatakit.persistence.table.GrantedAuthorityHierarchyTable.java

public static final TreeMap<String, TreeSet<String>> getEntireGrantedAuthorityHierarchy(Datastore ds, User user)
        throws ODKDatastoreException {

    GrantedAuthorityHierarchyTable relation;
    List<? extends CommonFieldsBase> groupsList;
    relation = GrantedAuthorityHierarchyTable.assertRelation(ds, user);
    Query query = ds.createQuery(relation, "GrantedAuthorityHierarchyTable.getEntireGrantedAuthorityHierarchy",
            user);//  w ww  . j av  a2s .co  m
    query.addSort(GrantedAuthorityHierarchyTable.DOMINATING_GRANTED_AUTHORITY, Direction.ASCENDING);
    groupsList = query.executeQuery();

    TreeMap<String, TreeSet<String>> inheritFrom = new TreeMap<String, TreeSet<String>>();
    for (CommonFieldsBase b : groupsList) {
        GrantedAuthorityHierarchyTable group = (GrantedAuthorityHierarchyTable) b;

        GrantedAuthority dom = group.getDominatingGrantedAuthority();
        GrantedAuthority sub = group.getSubordinateGrantedAuthority();

        if (!GrantedAuthorityName.permissionsCanBeAssigned(dom.toString()))
            continue;
        TreeSet<String> auths = inheritFrom.get(dom.getAuthority());
        if (auths == null) {
            auths = new TreeSet<String>();
            inheritFrom.put(dom.getAuthority(), auths);
        }
        auths.add(sub.getAuthority());
    }

    return inheritFrom;
}

From source file:org.opendatakit.persistence.table.GrantedAuthorityHierarchyTable.java

public static final void assertGrantedAuthorityHierarchy(GrantedAuthority dominantGrant,
        Collection<String> desiredGrants, CallingContext cc) throws ODKDatastoreException {

    if (!GrantedAuthorityName.permissionsCanBeAssigned(dominantGrant.getAuthority())) {
        throw new IllegalArgumentException("Dominant grant must be permissions-assignable!");
    }//from w  w w . j  av  a  2  s.c  o m

    Datastore ds = cc.getDatastore();
    User user = cc.getCurrentUser();

    boolean hasNotChanged = true;

    try {
        GrantedAuthorityHierarchyTable relation = GrantedAuthorityHierarchyTable.assertRelation(ds, user);

        TreeSet<String> groups = new TreeSet<String>();
        TreeSet<String> roles = new TreeSet<String>();
        for (String grant : desiredGrants) {
            if (!GrantedAuthorityName.permissionsCanBeAssigned(grant)) {
                roles.add(grant);
            } else {
                groups.add(grant);
            }
        }

        // get the hierarchy as currently defined for this group
        List<? extends CommonFieldsBase> groupsList;
        relation = GrantedAuthorityHierarchyTable.assertRelation(ds, user);
        Query query = ds.createQuery(relation, "GrantedAuthorityHierarchyTable.assertGrantedAuthorityHierarchy",
                user);
        query.addFilter(GrantedAuthorityHierarchyTable.DOMINATING_GRANTED_AUTHORITY, FilterOperation.EQUAL,
                dominantGrant.getAuthority());
        groupsList = query.executeQuery();

        // OK we have the groups and roles to establish for this dominantGrant.
        // AND we have the groupsList of groups and roles already established for dominantGrant.
        List<EntityKey> deleted = new ArrayList<EntityKey>();
        for (CommonFieldsBase b : groupsList) {
            GrantedAuthorityHierarchyTable t = (GrantedAuthorityHierarchyTable) b;
            String authority = t.getSubordinateGrantedAuthority().getAuthority();
            if (groups.contains(authority)) {
                groups.remove(authority);
            } else if (roles.contains(authority)) {
                roles.remove(authority);
            } else {
                deleted.add(t.getEntityKey());
            }
        }
        // we now have the list of groups and roles to insert, and the list of
        // existing records to delete...
        List<GrantedAuthorityHierarchyTable> added = new ArrayList<GrantedAuthorityHierarchyTable>();
        for (String group : groups) {
            GrantedAuthorityHierarchyTable t = ds.createEntityUsingRelation(relation, user);
            t.setDominatingGrantedAuthority(dominantGrant.getAuthority());
            t.setSubordinateGrantedAuthority(group);
            added.add(t);
        }

        for (String role : roles) {
            GrantedAuthorityHierarchyTable t = ds.createEntityUsingRelation(relation, user);
            t.setDominatingGrantedAuthority(dominantGrant.getAuthority());
            t.setSubordinateGrantedAuthority(role);
            added.add(t);
        }

        hasNotChanged = added.isEmpty() && deleted.isEmpty();

        // we now have the list of EntityKeys to delete, and the list of records to add -- do it.
        ds.putEntities(added, user);
        ds.deleteEntities(deleted, user);
    } finally {
        if (!hasNotChanged) {
            // finally, since we mucked with the group hierarchies, flag that
            // the cache of those hierarchies has changed.
            SecurityRevisionsTable.setLastRoleHierarchyRevisionDate(ds, user);
        }
    }
}

From source file:md.MangaDownloader.java

public static String automaticVolumeName(List<MangaChaptersInfo> selectedChapters) {
    TreeSet<Integer> chapterNumbers = new TreeSet<Integer>();
    String alternative = "";
    for (MangaChaptersInfo m : selectedChapters) {
        try {//  w w  w  . ja v  a2 s .c  o  m
            if (!m.chapterNumber.equals("")) {
                int test = Integer.parseInt(m.chapterNumber);
                chapterNumbers.add(test);
            }
        } catch (NumberFormatException e) {
            //If more than one alternative chapter name then all renamed to "Extras"
            if (alternative.equals("")) {
                alternative = m.chapterNumber;
            } else {
                alternative = STRINGS.getString("NAME_EXTRAS");
            }
        }
    }

    String result = "";
    if (!chapterNumbers.isEmpty()) {
        int firstInSequence = Integer.MIN_VALUE;
        int lastInSequence;

        for (Iterator<Integer> i = chapterNumbers.iterator(); i.hasNext();) {
            int actualNumber = i.next();
            if (firstInSequence == Integer.MIN_VALUE)
                firstInSequence = actualNumber;
            lastInSequence = actualNumber;
            int next;
            if (i.hasNext()) {
                next = chapterNumbers.higher(actualNumber);
            } else {
                next = Integer.MIN_VALUE;
            }
            if ((actualNumber + 1 != next) || (next == Integer.MIN_VALUE)) {
                //FIN DE SECUENCIA
                if (!result.equals("")) {
                    result += ", ";
                }
                if (firstInSequence == lastInSequence) {
                    result += String.format("%04d", firstInSequence);
                } else {
                    result += String.format("%04d - %04d", firstInSequence, lastInSequence);
                }
                firstInSequence = Integer.MIN_VALUE;
            }
        }

    }

    if (!alternative.equals("")) {
        if (!result.equals(""))
            result += " & ";
        result += alternative;
    }

    return result;
}

From source file:com.opengamma.financial.analytics.volatility.surface.EquityOptionVolatilitySurfaceDataFunctionDeprecated.java

/**
 * // Computes active expiry dates, which fall on the Saturday following the 3rd Friday of an expiry month
 * @param valDate The evaluation date// w ww.  j  ava  2  s .c  o  m
 * @return The expiry dates
 */
public static TreeSet<LocalDate> getExpirySet(final LocalDate valDate) {

    final TemporalAdjuster thirdFriday = TemporalAdjusters.dayOfWeekInMonth(3, DayOfWeek.FRIDAY);
    TreeSet<LocalDate> expirySet = new TreeSet<LocalDate>();

    // Add the next six months' Expiries although they are not guaranteed to be traded
    final LocalDate thisMonthsExpiry = valDate.with(thirdFriday).plusDays(1);
    if (thisMonthsExpiry.isAfter(valDate)) {
        expirySet.add(thisMonthsExpiry);
    }
    for (int m = 1; m <= 6; m++) {
        expirySet.add(valDate.plusMonths(m).with(thirdFriday).plusDays(1));
    }

    // Add the Quarterly IMM months out 3 years
    final Set<Month> immQuarters = EnumSet.of(Month.MARCH, Month.JUNE, Month.SEPTEMBER, Month.DECEMBER);
    LocalDate nextQuarter = valDate;
    do {
        nextQuarter = nextQuarter.plusMonths(1);
    } while (!immQuarters.contains(nextQuarter.getMonth()));

    for (int q = 1; q <= 12; q++) {
        expirySet.add(nextQuarter.with(thirdFriday).plusDays(1));
        nextQuarter = nextQuarter.plusMonths(3);
    }

    return expirySet;
}

From source file:dendroscope.autumn.hybridnetwork.ComputeHybridizationNetwork.java

private static Collection<Root> copyAll(Collection<Root> list) {
    TreeSet<Root> copy = new TreeSet<Root>(new NetworkComparator());
    for (Root r : list) {
        copy.add(r.copySubNetwork());
    }/*from w w w  .  java  2 s .  c  o  m*/
    return copy;
}

From source file:de.minestar.minestarlibrary.utils.PlayerUtils.java

/**
 * @return Sorted Set of all player's nicknames who has ever conntected to
 *         the server. The nicknames are all in lowercase!
 *//*w w w.j av  a2  s.  c o  m*/
public static String[] getAllPlayerNames() {

    TreeSet<String> playerNames = new TreeSet<String>();

    OfflinePlayer[] players = Bukkit.getServer().getOfflinePlayers();
    for (OfflinePlayer player : players)
        playerNames.add(player.getName().toLowerCase());

    return playerNames.toArray(new String[playerNames.size()]);
}

From source file:net.sf.jasperreports.engine.util.JRFontUtil.java

/**
 * Returns the font family names available through extensions, in alphabetical order.
 *//*  ww  w.  j  a va  2 s .  c om*/
public static Collection<String> getFontFamilyNames() {
    TreeSet<String> familyNames = new TreeSet<String>();//FIXMEFONT use collator for order?
    //FIXMEFONT do some cache
    List<FontFamily> families = ExtensionsEnvironment.getExtensionsRegistry().getExtensions(FontFamily.class);
    for (Iterator<FontFamily> itf = families.iterator(); itf.hasNext();) {
        FontFamily family = itf.next();
        familyNames.add(family.getName());
    }
    return familyNames;
}

From source file:com.l2jfree.network.mmocore.ReadWriteThread.java

private static String describeInterestOps(int interestOps) {
    final TreeSet<String> result = new TreeSet<String>();
    if ((interestOps & SelectionKey.OP_ACCEPT) != 0)
        result.add("ACCEPT");
    if ((interestOps & SelectionKey.OP_CONNECT) != 0)
        result.add("CONNECT");
    if ((interestOps & SelectionKey.OP_READ) != 0)
        result.add("READ");
    if ((interestOps & SelectionKey.OP_WRITE) != 0)
        result.add("WRITE");
    return StringUtils.join(result, "|");
}