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:org.motechproject.server.omod.web.controller.FacilityController.java

private void populate(Map<String, TreeSet<String>> map, String key, String value) {
    if (StringUtils.isBlank(key) || StringUtils.isBlank(value))
        return;//from   w  w w .j a  v  a  2 s .co m
    if (map.containsKey(key)) {
        map.get(key).add(value);
        return;
    }
    TreeSet<String> values = new TreeSet<String>();
    values.add(value);
    map.put(key, values);
}

From source file:com.chingo247.structureapi.commands.StructureCommands.java

private static String getInfo(StructureNode structure, IColors colors) {
    TreeSet<String> owners = Sets.newTreeSet(ALPHABETICAL_ORDER);

    List<SettlerNode> mastersNode = structure.getOwnerDomain().getOwners(OwnerType.MASTER);
    for (SettlerNode master : mastersNode) {
        owners.add(master.getName());
    }//from  w w w  .  j  a v a2  s  .  c  o  m

    String ownershipString = "";
    int size = owners.size();
    int count = 0;

    for (String ownership : owners) {
        ownershipString += colors.yellow() + ownership + colors.reset();
        count++;
        if (count != size) {
            ownershipString += ", ";
        }

    }

    String line = "#" + colors.gold() + structure.getId() + " " + colors.blue() + structure.getName() + "\n"
            + colors.reset() + "World: " + colors.yellow() + structure.getWorldName() + "\n";

    Vector position = structure.getOrigin();
    line += colors.reset() + "Location: " + colors.yellow() + "X: " + colors.reset() + position.getX() + " "
            + colors.yellow() + "Y: " + colors.reset() + position.getY() + " " + colors.yellow() + "Z: "
            + colors.reset() + position.getZ() + "\n";

    CuboidRegion region = structure.getCuboidRegion();

    line += colors.reset() + "Width: " + colors.yellow() + region.getWidth() + colors.reset() + " Height: "
            + colors.yellow() + region.getHeight() + colors.reset() + " Length: " + colors.yellow()
            + region.getLength() + colors.reset() + "\n";

    line += colors.reset() + "Status: " + colors.reset() + getStatusString(structure, colors) + "\n";

    if (structure.getPrice() > 0) {
        line += colors.reset() + "Value: " + colors.yellow() + structure.getPrice() + "\n";
    }

    if (!owners.isEmpty()) {
        if (owners.size() == 1) {
            line += colors.reset() + "Owners(MASTER): " + ownershipString + "\n";
        } else {
            line += colors.reset() + "Owners(MASTER): \n" + ownershipString + "\n";
        }
    }

    if (structure.getNode().hasProperty("WGRegion")) {
        line += colors.reset() + "WorldGuard-Region: " + colors.yellow()
                + structure.getNode().getProperty("WGRegion");
    }
    return line;

}

From source file:com.smoketurner.notification.api.NotificationTest.java

@Test
public void testComparison() throws Exception {
    final Notification n1 = Notification.builder().withId(1L).build();
    final Notification n2 = Notification.builder().withId(2L).build();
    final Notification n3 = Notification.builder().withId(3L).build();

    assertThat(n1.compareTo(n1)).isZero();
    assertThat(n1.compareTo(n2)).isEqualTo(1);
    assertThat(n2.compareTo(n1)).isEqualTo(-1);

    final TreeSet<Notification> notifications = Sets.newTreeSet();
    notifications.add(n1);
    notifications.add(n2);//  ww  w.ja  v  a  2s .c  om
    notifications.add(n3);

    assertThat(notifications).containsExactly(n3, n2, n1);

    final Notification n1b = Notification.builder().withId(1L).withUnseen(true).build();

    assertThat(n1.compareTo(n1b) == 0).isEqualTo(n1.equals(n1b));
    assertThat(n1.equals(null)).isFalse();
    assertThat(n1.equals("")).isFalse();
}

From source file:com.espertech.esper.collection.TestNumberSetShiftGroupEnumeration.java

private TreeSet<Integer> getTreeSet(int[] set) {

    TreeSet<Integer> treeSet = new TreeSet<Integer>();
    for (int aSet : set) {
        treeSet.add(aSet);
    }/*from   w  w  w  . j a  v a2 s . com*/
    return treeSet;
}

From source file:net.spfbl.core.Client.java

public static TreeSet<Client> getSet(Permission permission) {
    if (permission == null) {
        return null;
    } else {/*from  w w  w. j ava  2 s  . c o  m*/
        TreeSet<Client> clientSet = new TreeSet<Client>();
        for (Client client : getSet()) {
            if (client.hasPermission(permission)) {
                clientSet.add(client);
            }
        }
        return clientSet;
    }
}

From source file:org.bedework.eventreg.web.AdminAgendaController.java

@Override
public ModelAndView doRequest() throws Throwable {
    sessMan.flushCurrEvent();//from   w w w .  jav  a  2s  . co m
    final Event ev = sessMan.getCurrEvent();

    final TreeSet<Registration> regs = new TreeSet<>();

    for (final Registration reg : sessMan.getRegistrationsByHref(ev.getHref())) {
        reg.setEvent(ev);

        regs.add(reg);
    }

    return objModel("adminagenda", "regs", regs);
}

From source file:api.util.JsonObjectMap.java

@Override
public Set<Entry<String, T>> entrySet() {
    Iterator it = object.keys();/*from w w  w .  j a v  a2 s .c  om*/
    TreeSet set = new TreeSet();
    while (it.hasNext()) {
        final String key = (String) it.next();
        set.add(new Entry<String, Object>() {
            @Override
            public String getKey() {
                return key;
            }

            @Override
            public Object getValue() {
                return get(key);
            }

            @Override
            public Object setValue(Object value) {
                throw new UnsupportedOperationException();
            }
        });
    }
    return set;
}

From source file:org.opendatakit.security.server.SecurityServiceUtil.java

public static void setAuthenticationLists(UserSecurityInfo userInfo, String uriUser, CallingContext cc)
        throws ODKDatastoreException {
    Datastore ds = cc.getDatastore();/*from ww w .  j av a 2s . c  o  m*/
    User user = cc.getCurrentUser();
    RoleHierarchy hierarchy = (RoleHierarchy) cc.getHierarchicalRoleRelationships();
    Set<GrantedAuthority> grants = UserGrantedAuthority.getGrantedAuthorities(uriUser, ds, user);
    Set<GrantedAuthority> badGrants = new TreeSet<GrantedAuthority>();
    TreeSet<GrantedAuthorityName> groups = new TreeSet<GrantedAuthorityName>();
    TreeSet<GrantedAuthorityName> authorities = new TreeSet<GrantedAuthorityName>();
    for (GrantedAuthority grant : grants) {
        GrantedAuthorityName name = mapName(grant, badGrants);
        if (name != null) {
            if (GrantedAuthorityName.permissionsCanBeAssigned(grant.getAuthority())) {
                groups.add(name);
            } else {
                authorities.add(name);
            }
        }
    }
    Collection<? extends GrantedAuthority> auths = hierarchy.getReachableGrantedAuthorities(grants);
    for (GrantedAuthority auth : auths) {
        GrantedAuthorityName name = mapName(auth, badGrants);
        if (name != null && !GrantedAuthorityName.permissionsCanBeAssigned(auth.getAuthority())) {
            authorities.add(name);
        }
    }
    userInfo.setAssignedUserGroups(groups);
    userInfo.setGrantedAuthorities(authorities);
    removeBadGrantedAuthorities(badGrants, cc);
}

From source file:edu.cmu.lti.oaqa.extractors.ExtractorHelper.java

@Override
public void process(JCas aJCas) throws AnalysisEngineProcessException {
    try {//from w  w  w.  jav a2  s.c  om
        String quiid = null;
        FSIterator<Annotation> it = aJCas.getAnnotationIndex(InputElement.type).iterator();
        if (it.hasNext()) {
            InputElement elem = (InputElement) it.next();
            quiid = elem.getQuuid();
        } else {
            throw new Exception("Cannot find the docUri!");
        }

        FSIterator<Annotation> sentenceIterator = AnnotUtils.getIterator(aJCas, Sentence.typeIndexID);

        ArrayList<ArrayList<String>> resList = new ArrayList<ArrayList<String>>();

        for (int j = 0; j < extrList.size(); j++) {
            resList.add(new ArrayList<String>());
        }

        String FileName = new File(quiid).getName();

        String FileNameParts[] = FileName.split("\\.");
        String CountryName = FileNameParts[0].replace('_', ' ');

        TreeSet<String> exceptions = new TreeSet<String>();
        exceptions.add(CountryName);

        getContext().getLogger().log(Level.INFO, "DOCUMENT: " + FileName + " Country: " + CountryName);

        for (int counter = 1; sentenceIterator.isValid(); counter++, sentenceIterator.moveToNext()) {
            Annotation sentence = sentenceIterator.get();
            /*
            getContext().getLogger().log(Level.INFO, "SENTENCE " + counter + 
                    " begin: " + sentence.getBegin() + " end: " + sentence.getEnd());
            */
            for (int i = 0; i < extrList.size(); ++i) {
                Extractor e = extrList.get(i);
                ArrayList<String> res = resList.get(i);

                e.process(aJCas, sentence, res);
            }
        }

        for (int i = 0; i < extrList.size(); ++i) {
            Extractor e = extrList.get(i);
            ArrayList<String> res = resList.get(i);
            Set<String> setRes = e.aggregate(res, exceptions);

            getContext().getLogger().log(Level.INFO,
                    FileName + "#" + e.getClass().getName() + " : " + StringUtils.join(setRes.toArray(), ';'));
        }

    } catch (Exception e) {
        throw new AnalysisEngineProcessException(e);
    }

}

From source file:de.metanome.algorithm_integration.ColumnConditionValue.java

@Override
@JsonIgnore/*  w  w  w . ja  va2 s.  c om*/
public TreeSet<ColumnIdentifier> getContainedColumns() {
    TreeSet<ColumnIdentifier> result = new TreeSet<>();
    result.add(this.columnIdentifier);
    return result;
}