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:gr.cti.android.experimentation.controller.api.HistoryController.java

private void fillMissingIntervals(TreeSet<Long> treeSet, String rollup, long toLong) {

    //TODO: add non existing intervals
    if (rollup.endsWith("d")) {
        DateTime firstDate = new DateTime(treeSet.iterator().next());

        while (firstDate.isBefore(toLong)) {
            firstDate = firstDate.plusDays(1);
            if (!treeSet.contains(firstDate.getMillis())) {
                treeSet.add(firstDate.getMillis());
            }//from   ww  w .  j ava2s .c  om
        }
    } else if (rollup.endsWith("h")) {
        DateTime firstDate = new DateTime(treeSet.iterator().next());

        while (firstDate.isBefore(toLong)) {
            firstDate = firstDate.plusHours(1);
            if (!treeSet.contains(firstDate.getMillis())) {
                treeSet.add(firstDate.getMillis());
            }
        }
    } else if (rollup.endsWith("m")) {
        DateTime firstDate = new DateTime(treeSet.iterator().next());

        while (firstDate.isBefore(toLong)) {
            firstDate = firstDate.plusMinutes(1);
            if (!treeSet.contains(firstDate.getMillis())) {
                treeSet.add(firstDate.getMillis());
            }
        }
    }
}

From source file:com.autentia.intra.jsf.schedule.renderer.BitacoreAbstractCompactScheduleRenderer.java

/**
 * <p>//from   ww  w. j  a v a 2s . c o  m
 * Draw the schedule entries in the specified day cell
 * </p>
 *
 * @param context  the FacesContext
 * @param schedule the schedule
 * @param day      the day
 * @param writer   the ResponseWriter
 * @throws IOException when the entries could not be drawn
 */
protected void writeEntries(FacesContext context, HtmlSchedule schedule, ScheduleDay day, ResponseWriter writer)
        throws IOException {
    final String clientId = schedule.getClientId(context);
    final FormInfo parentFormInfo = RendererUtils.findNestingForm(schedule, context);
    final String formId = parentFormInfo == null ? null : parentFormInfo.getFormName();
    final TreeSet entrySet = new TreeSet(comparator);

    for (Iterator entryIterator = day.iterator(); entryIterator.hasNext();) {
        ScheduleEntry entry = (ScheduleEntry) entryIterator.next();
        entrySet.add(entry);
    }

    for (Iterator entryIterator = entrySet.iterator(); entryIterator.hasNext();) {
        ScheduleEntry entry = (ScheduleEntry) entryIterator.next();
        writer.startElement(HTML.TR_ELEM, schedule);
        writer.startElement(HTML.TD_ELEM, schedule);

        if (isSelected(schedule, entry)) {
            writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "selected"), null);
        }

        // compose the CSS style for the entry box
        StringBuffer entryStyle = new StringBuffer();
        entryStyle.append("width: 100%;");
        String entryColor = getEntryRenderer(schedule).getColor(context, schedule, entry,
                isSelected(schedule, entry));
        if (isSelected(schedule, entry) && entryColor != null) {
            entryStyle.append(" background-color: ");
            entryStyle.append(entryColor);
            entryStyle.append(";");
            entryStyle.append(" border-color: ");
            entryStyle.append(entryColor);
            entryStyle.append(";");
        }

        writer.writeAttribute(HTML.STYLE_ATTR, entryStyle.toString(), null);

        // draw the tooltip
        if (showTooltip(schedule)) {
            getEntryRenderer(schedule).renderToolTip(context, writer, schedule, entry,
                    isSelected(schedule, entry));
        }

        if (!isSelected(schedule, entry) && !schedule.isReadonly()) {
            writer.startElement("a", schedule);
            writer.writeAttribute("href", "#", null);

            writer.writeAttribute(HTML.ONMOUSEUP_ATTR,
                    "fireEntrySelected('" + formId + "', '" + clientId + "', '" + entry.getId() + "');", null);
        }

        // draw the content
        getEntryRenderer(schedule).renderContent(context, writer, schedule, day, entry, true,
                isSelected(schedule, entry));

        if (!isSelected(schedule, entry) && !schedule.isReadonly()) {
            writer.endElement("a");
        }

        writer.endElement(HTML.TD_ELEM);
        writer.endElement(HTML.TR_ELEM);
    }
}

From source file:com.aionemu.gameserver.world.MapRegion.java

private void createZoneMap(ZoneInstance[] zones) {
    zoneMap = new FastMap<Integer, TreeSet<ZoneInstance>>();
    for (int i = 0; i < zones.length; i++) {
        ZoneInstance zone = zones[i];/*from w  ww . ja va2s . c  o m*/
        int category = -1;
        if (zone.getZoneTemplate().getPriority() != 0) {
            category = zone.getZoneTemplate().getZoneType().ordinal();
        }
        TreeSet<ZoneInstance> zoneCategory = zoneMap.get(category);
        if (zoneCategory == null) {
            zoneCategory = new TreeSet<ZoneInstance>();
            zoneMap.put(category, zoneCategory);
        }
        zoneCategory.add(zone);
    }
}

From source file:com.b2international.index.SortIndexTest.java

@Test
public void sortIntField() throws Exception {
    final PrimitiveIterator.OfInt intIterator = new Random().ints().iterator();
    final TreeSet<Integer> orderedItems = newTreeSet();
    final Map<String, Data> documents = newHashMap();

    for (int i = 0; i < NUM_DOCS; i++) {
        int item = 0;
        while (item == 0 || orderedItems.contains(item)) {
            item = intIterator.nextInt();
        }/*  w w w  . j  a  v  a  2s  . c  o m*/
        orderedItems.add(item);

        final Data data = new Data();
        data.setIntField(item);
        documents.put(Integer.toString(i), data);
    }

    indexDocuments(documents);

    final Query<Data> ascendingQuery = Query.select(Data.class).where(Expressions.matchAll()).limit(NUM_DOCS)
            .sortBy(SortBy.field("intField", Order.ASC)).build();

    checkDocumentOrder(ascendingQuery, data -> data.getIntField(), orderedItems, Integer.class);

    final Query<Data> descendingQuery = Query.select(Data.class).where(Expressions.matchAll()).limit(NUM_DOCS)
            .sortBy(SortBy.field("intField", Order.DESC)).build();

    checkDocumentOrder(descendingQuery, data -> data.getIntField(), orderedItems.descendingSet(),
            Integer.class);
}

From source file:edu.fullerton.viewerplugin.PluginSupport.java

/**
 * Use information from the buffer to create a title for the plot
 * @param dbufs - data being plotted//from w ww  .  ja va2s.com
 * @param compact - if it's a small plot don't tell them too much
 * @return
 * @throws LdvTableException
 */
public String getTitle(ArrayList<ChanDataBuffer> dbufs, boolean compact) throws LdvTableException {
    String ret;
    if (dbufs.size() == 1) {
        ret = getLegend(dbufs.get(0), compact);
    } else if (dbufs.size() > 1) {
        TreeSet<String> chans = new TreeSet<>();
        for (ChanDataBuffer dbuf : dbufs) {
            chans.add(dbuf.getChanInfo().getChanName());
        }
        ret = "";
        for (String cname : chans) {
            if (ret.length() > 0) {
                ret += ", ";
            }
            ret += cname;
        }
    } else {
        ret = "Looks like we don't have any data??";
    }
    return ret;
}

From source file:com.b2international.index.SortIndexTest.java

@Test
public void sortLongField() throws Exception {
    final PrimitiveIterator.OfLong longIterator = new Random().longs().iterator();
    final TreeSet<Long> orderedItems = newTreeSet();
    final Map<String, Data> documents = newHashMap();

    for (int i = 0; i < NUM_DOCS; i++) {
        long item = 0L;
        while (item == 0L || orderedItems.contains(item)) {
            item = longIterator.nextLong();
        }//from w  w w.j a  va2  s.c o m
        orderedItems.add(item);

        final Data data = new Data();
        data.setLongField(item);
        documents.put(Integer.toString(i), data);
    }

    indexDocuments(documents);

    final Query<Data> ascendingQuery = Query.select(Data.class).where(Expressions.matchAll()).limit(NUM_DOCS)
            .sortBy(SortBy.field("longField", Order.ASC)).build();

    checkDocumentOrder(ascendingQuery, data -> data.getLongField(), orderedItems, Long.class);

    final Query<Data> descendingQuery = Query.select(Data.class).where(Expressions.matchAll()).limit(NUM_DOCS)
            .sortBy(SortBy.field("longField", Order.DESC)).build();

    checkDocumentOrder(descendingQuery, data -> data.getLongField(), orderedItems.descendingSet(), Long.class);
}

From source file:models.Calais.java

private JSONObject parseJSON(Reader reader) throws IOException, ParseException {
    myComparator = new Comparator<JSONObject>() {
        public int compare(JSONObject jsonObject, JSONObject jsonObject1) {
            double relevance = (Double) jsonObject.get("relevance");
            double relevance1 = (Double) jsonObject1.get("relevance");
            if (relevance < relevance1)
                return 1;
            return -1;
        }//  w  w w  .jav a 2  s.  c om
    };

    JSONParser parser = new JSONParser();
    JSONObject jsonObject = (JSONObject) parser.parse(reader);
    JSONObject result = new JSONObject();
    TreeSet<JSONObject> people = new TreeSet<JSONObject>(myComparator);
    TreeSet<JSONObject> companies = new TreeSet<JSONObject>(myComparator);

    for (Object value : jsonObject.values()) {
        JSONObject jsonValue = (JSONObject) value;
        String type = (String) jsonValue.get("_type");
        if (type != null && type.equalsIgnoreCase("Person")) {
            people.add(jsonValue);
        } else if (type != null && type.equalsIgnoreCase("Company")) {
            companies.add(jsonValue);
        }
    }

    List<String> peopleList = new ArrayList<String>();
    List<String> companyList = new ArrayList<String>();

    for (JSONObject person : people) {
        peopleList.add((String) person.get("name"));
    }
    for (JSONObject company : companies) {
        companyList.add((String) company.get("name"));
    }

    JSONObject resultValue = new JSONObject();
    resultValue.put("people", peopleList);
    resultValue.put("companies", companyList);
    result.put("result", resultValue);

    return result;
}

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

public static TreeSet<Peer> getSendAllSet() {
    TreeSet<Peer> peerSet = new TreeSet<Peer>();
    for (Peer peer : getSet()) {
        switch (peer.getSendStatus()) {
        case REPUTATION:
        case BLOCK:
        case ALWAYS:
        case REPASS:
            peerSet.add(peer);
            break;
        }/*w ww .ja  v  a  2 s. c  o m*/
    }
    return peerSet;
}

From source file:com.qpark.maven.plugin.springintegration.TestClientGeneratorMojo.java

private void generateAbstractConfig(final XsdsUtil xsds, final String basePackageName,
        final String clientConfig, final TreeSet<String> configImports) {
    String packageName = new StringBuffer(basePackageName).append(".config").toString();
    StringBuffer sb = new StringBuffer(1024);
    configImports.add("org.springframework.context.annotation.Bean");
    configImports.add("org.springframework.oxm.jaxb.Jaxb2Marshaller");
    configImports.add("org.springframework.ws.client.support.interceptor.ClientInterceptor");
    configImports.add("org.springframework.ws.soap.SoapVersion");
    configImports.add("org.springframework.ws.soap.saaj.SaajSoapMessageFactory");
    configImports.add("org.springframework.ws.soap.security.wss4j.Wss4jSecurityInterceptor");

    sb.append("package ");
    sb.append(packageName);/*from  w w w  .j av a  2 s.c om*/
    sb.append(";\n");
    sb.append("\n");
    for (String string : configImports) {
        sb.append("import ");
        sb.append(string);
        sb.append(";\n");
    }
    sb.append("\n");
    sb.append("/**\n");
    sb.append(" * Abstract spring client config.\n");
    sb.append(" *\n");
    sb.append(" * @author bhausen\n");
    sb.append(" */\n");
    sb.append("public abstract class AbstractClientConfig {\n");
    sb.append("   /**\n");
    sb.append("    * Get the client end point URL.\n");
    sb.append("    *\n");
    sb.append("    * @param serviceId\n");
    sb.append("    *            the service id.\n");
    sb.append("    * @return the client end point URL.\n");
    sb.append("    */\n");
    sb.append("   public abstract String getClientEndPointUrl(String serviceId);\n");
    sb.append("\n");
    sb.append("   /**\n");
    sb.append("    * Get the client system user name.\n");
    sb.append("    *\n");
    sb.append("    * @return the client system user name.\n");
    sb.append("    */\n");
    sb.append("   public abstract String getClientSystemUserName();\n");
    sb.append("\n");
    sb.append("   /**\n");
    sb.append("    * Get the client system user password.\n");
    sb.append("    *\n");
    sb.append("    * @return the client system user password.\n");
    sb.append("    */\n");
    sb.append("   public abstract String getClientSystemUserPassword();\n");
    sb.append("\n");

    sb.append(clientConfig);
    sb.append("   /**\n");
    sb.append("    * Get the message factory supporting SOAP version 1.2.\n");
    sb.append("    *\n");
    sb.append("    * @return the {@link SaajSoapMessageFactory}.\n");
    sb.append("    */\n");
    sb.append("   @Bean\n");
    sb.append("   public SaajSoapMessageFactory messageFactory() {\n");
    sb.append("      SaajSoapMessageFactory bean = new SaajSoapMessageFactory();\n");
    sb.append("      bean.setSoapVersion(SoapVersion.SOAP_12);\n");
    sb.append("      return bean;\n");
    sb.append("   }\n");
    sb.append("\n");
    sb.append("   /**\n");
    sb.append("    * The clients {@link Wss4jSecurityInterceptor} providing the web service\n");
    sb.append("    * security.\n");
    sb.append("    *\n");
    sb.append("    * @return the {@link Wss4jSecurityInterceptor} implementation.\n");
    sb.append("    */\n");
    sb.append("   @Bean\n");
    sb.append("   public ClientWss4jSecurityInterceptor securityInterceptor() {\n");
    sb.append("      ClientWss4jSecurityInterceptor bean = new ClientWss4jSecurityInterceptor();\n");
    sb.append("      bean.setSecurementUsername(this.getClientSystemUserName());\n");
    sb.append("      bean.setSecurementPassword(this.getClientSystemUserPassword());\n");
    sb.append("      return bean;\n");
    sb.append("   }\n");
    sb.append("}\n");
    sb.append("\n");

    File f = Util.getFile(this.outputDirectory, packageName,
            new StringBuffer("AbstractClientConfig").append(".java").toString());
    this.getLog().info(new StringBuffer().append("Write ").append(f.getAbsolutePath()));
    try {
        Util.writeToFile(f, sb.toString());
    } catch (Exception e) {
        this.getLog().error(e.getMessage());
        e.printStackTrace();
    }

}

From source file:com.b2international.index.SortIndexTest.java

@Test
public void sortShortField() throws Exception {
    final PrimitiveIterator.OfInt intIterator = new Random().ints().iterator();
    final TreeSet<Short> orderedItems = newTreeSet();
    final Map<String, Data> documents = newHashMap();

    for (short i = 0; i < NUM_DOCS; i++) {
        short item = 0;
        while (item == 0 || orderedItems.contains(item)) {
            item = (short) intIterator.nextInt();
        }/*  www.j  ava2 s  .c  om*/
        orderedItems.add(item);

        final Data data = new Data();
        data.setShortField(item);
        documents.put(Integer.toString(i), data);
    }

    indexDocuments(documents);

    final Query<Data> ascendingQuery = Query.select(Data.class).where(Expressions.matchAll()).limit(NUM_DOCS)
            .sortBy(SortBy.field("shortField", Order.ASC)).build();

    checkDocumentOrder(ascendingQuery, data -> data.getShortField(), orderedItems, Short.class);

    final Query<Data> descendingQuery = Query.select(Data.class).where(Expressions.matchAll()).limit(NUM_DOCS)
            .sortBy(SortBy.field("shortField", Order.DESC)).build();

    checkDocumentOrder(descendingQuery, data -> data.getShortField(), orderedItems.descendingSet(),
            Short.class);
}