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:com.google.enterprise.connector.persist.MigrateStore.java

/**
 * Returns a Collection of the names of configured PersistentStores.
 *///from   w  ww  . j  av a 2 s  .  co m
private Collection<String> getConnectorNames(PersistentStore sourceStore) {
    ImmutableMap<StoreContext, ConnectorStamps> inventory = sourceStore.getInventory();
    TreeSet<String> names = new TreeSet<String>();
    for (StoreContext context : inventory.keySet()) {
        names.add(context.getConnectorName());
    }
    return names;
}

From source file:alluxio.web.WebInterfaceConfigurationServlet.java

private SortedSet<Pair<String, String>> getSortedProperties() {
    TreeSet<Pair<String, String>> rtn = new TreeSet<>();
    for (Map.Entry<String, String> entry : Configuration.toMap().entrySet()) {
        String key = entry.getKey();
        if (key.startsWith(ALLUXIO_CONF_PREFIX) && !ALLUXIO_CONF_EXCLUDES.contains(key)) {
            rtn.add(new ImmutablePair<>(key, Configuration.get(PropertyKey.fromString(key))));
        }//from  w  w  w . j a v a 2s .  co m
    }
    return rtn;
}

From source file:com.hichinaschool.flashcards.libanki.Utils.java

private static void printJSONObject(JSONObject jsonObject, String indentation, BufferedWriter buff) {
    try {//from   w w  w . j  a  va2 s  . co  m
        @SuppressWarnings("unchecked")
        Iterator<String> keys = (Iterator<String>) jsonObject.keys();
        TreeSet<String> orderedKeysSet = new TreeSet<String>();
        while (keys.hasNext()) {
            orderedKeysSet.add(keys.next());
        }

        Iterator<String> orderedKeys = orderedKeysSet.iterator();
        while (orderedKeys.hasNext()) {
            String key = orderedKeys.next();

            try {
                Object value = jsonObject.get(key);
                if (value instanceof JSONObject) {
                    if (buff != null) {
                        buff.write(indentation + " " + key + " : ");
                        buff.newLine();
                    }
                    // Log.i(AnkiDroidApp.TAG, "   " + indentation + key + " : ");
                    printJSONObject((JSONObject) value, indentation + "-", buff);
                } else {
                    if (buff != null) {
                        buff.write(indentation + " " + key + " = " + jsonObject.get(key).toString());
                        buff.newLine();
                    }
                    // Log.i(AnkiDroidApp.TAG, "   " + indentation + key + " = " + jsonObject.get(key).toString());
                }
            } catch (JSONException e) {
                Log.e(AnkiDroidApp.TAG, "JSONException = " + e.getMessage());
            }
        }
    } catch (IOException e1) {
        Log.e(AnkiDroidApp.TAG, "IOException = " + e1.getMessage());
    }
}

From source file:org.motechproject.server.omod.web.model.JSONLocationSerializer.java

public void populateJavascriptMaps(ModelMap model) {
    Map<String, TreeSet<String>> regionMap = new HashMap<String, TreeSet<String>>();
    Map<String, TreeSet<Community>> districtMap = new HashMap<String, TreeSet<Community>>();

    MotechService motechService = contextService.getMotechService();
    List<Facility> facilities = motechService.getAllFacilities();
    List<MessageLanguage> languages = motechService.getAllLanguages();

    for (Facility facility : facilities) {
        Location location = facility.getLocation();
        if (location != null) {
            String region = location.getRegion();
            String district = location.getCountyDistrict();
            TreeSet<String> districts = regionMap.get(region);
            if (districts == null) {
                districts = new TreeSet<String>();
            }//from ww  w  . j a  va2  s.c o m
            if (StringUtils.isNotEmpty(district))
                districts.add(district);
            regionMap.put(region, districts);
            TreeSet<Community> communities = districtMap.get(district);
            if (communities == null) {
                communities = new TreeSet<Community>(communityNameComparator);
            }
            communities.addAll(facility.getCommunities());
            districtMap.put(district, communities);
        }
    }
    FacilityComparator facilityComparator = new FacilityComparator();
    Collections.sort(facilities, facilityComparator);

    model.addAttribute("languages", languages);
    model.addAttribute("regionMap", regionMap);
    model.addAttribute("districtMap", districtMap);
    model.addAttribute("facilities", facilities);
    model.addAttribute("country", new Country("Ghana").withFacilities(facilities));

}

From source file:com.joliciel.talismane.machineLearning.linearsvm.LinearSVMOneVsRestDecisionMaker.java

@Override
public List<Decision<T>> decide(List<FeatureResult<?>> featureResults) {
    List<Feature> featureList = LinearSVMUtils.prepareData(featureResults, featureIndexMap);

    List<Decision<T>> decisions = null;

    if (featureList.size() == 0) {
        LOG.info("No features for current context.");
        TreeSet<Decision<T>> outcomeSet = new TreeSet<Decision<T>>();
        double uniformProb = 1 / outcomes.size();
        for (String outcome : outcomes) {
            Decision<T> decision = decisionFactory.createDecision(outcome, uniformProb);
            outcomeSet.add(decision);
        }/* w ww  . java 2  s  . co  m*/
        decisions = new ArrayList<Decision<T>>(outcomeSet);
    } else {
        Feature[] instance = new Feature[1];
        instance = featureList.toArray(instance);

        TreeSet<Decision<T>> outcomeSet = new TreeSet<Decision<T>>();

        int i = 0;
        for (Model model : models) {
            int myLabel = 0;
            for (int j = 0; j < model.getLabels().length; j++)
                if (model.getLabels()[j] == 1)
                    myLabel = j;
            double[] probabilities = new double[2];
            Linear.predictProbability(model, instance, probabilities);

            Decision<T> decision = decisionFactory.createDecision(outcomes.get(i), probabilities[myLabel]);
            outcomeSet.add(decision);
            i++;
        }
        decisions = new ArrayList<Decision<T>>(outcomeSet);
    }
    return decisions;
}

From source file:FormatStorage1.IColumnDataFile.java

public void open(String fileName, ArrayList<Integer> idxs) throws IOException {
    this.columnprojects = new ArrayList<ArrayList<Integer>>();
    this.head = new IHead();
    this.readidxs = new TreeSet<Integer>();
    FileSystem fs = FileSystem.get(conf);
    FileStatus[] statuss = fs.globStatus(new Path(fileName + "_idx*"));
    this.cp2ifdfs.clear();
    this.idx2ifdfs.clear();
    if (idxs != null && idxs.size() > 0) {
        readidxs.addAll(idxs);//from   w  ww . j a  v a2  s. c  o m
        for (int i = 0; i < statuss.length; i++) {
            String file = statuss[i].getPath().toString();
            IFormatDataFile ifdf = null;
            String idxstr = file.substring(file.lastIndexOf("_idx") + 4);
            String[] sts = idxstr.split("_");
            TreeSet<Integer> ts = new TreeSet<Integer>();
            for (int j = 0; j < sts.length; j++) {
                ts.add(Integer.parseInt(sts[j]));
            }

            boolean contains = false;
            for (Integer id : idxs) {
                if (ts.contains(id)) {
                    contains = true;
                    if (ifdf == null) {
                        ifdf = new IFormatDataFile(conf);
                        ifdf.open(file);
                    }
                    this.idx2ifdfs.put(id, ifdf);
                }
            }
            if (contains) {
                ArrayList<Integer> cp = new ArrayList<Integer>();
                cp.addAll(ts);
                this.columnprojects.add(cp);
                this.cp2ifdfs.put(cp, ifdf);
            }
        }

    } else {
        for (int i = 0; i < statuss.length; i++) {
            String file = statuss[i].getPath().toString();
            IFormatDataFile ifdf = null;
            String idxstr = file.substring(file.lastIndexOf("_idx") + 4);
            String[] sts = idxstr.split("_");
            TreeSet<Integer> ts = new TreeSet<Integer>();
            ifdf = new IFormatDataFile(conf);
            ifdf.open(file);

            for (int j = 0; j < sts.length; j++) {
                int id = Integer.parseInt(sts[j]);
                ts.add(id);
                this.idx2ifdfs.put(id, ifdf);
            }

            ArrayList<Integer> cp = new ArrayList<Integer>();
            cp.addAll(ts);
            this.readidxs.addAll(ts);
            this.columnprojects.add(cp);
            this.cp2ifdfs.put(cp, ifdf);
        }
    }
    this.fieldtypes = new HashMap<Integer, IRecord.IFType>();
    for (Integer idx : this.readidxs) {
        this.fieldtypes.put(idx, this.idx2ifdfs.get(idx).fileInfo().head().fieldMap().fieldtypes().get(idx));
    }
    workstatus = ConstVar.WS_Read;
}

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

private static void showOwnerships(ICommandSender sender, CommandContext args, IStructureAPI structureAPI,
        OwnerType type) throws CommandException {
    IColors COLOR = structureAPI.getPlatform().getChatColors();
    GraphDatabaseService graph = SettlerCraft.getInstance().getNeo4j();

    TreeSet<String> ownerships = Sets.newTreeSet(ALPHABETICAL_ORDER);
    String structureName = null;//  ww w  .  j a  v a 2 s  .  co  m
    Long structureId;
    try (Transaction tx = graph.beginTx()) {
        StructureNode structure = getStructure(args, tx);
        structureName = structure.getName();
        structureId = structure.getId();
        for (SettlerNode member : structure.getOwnerDomain().getOwners(type)) {
            ownerships.add(member.getName());
        }

        tx.success();
    }
    String ownershipString = "";
    int size = ownerships.size();

    if (size != 0) {
        int count = 0;

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

        }
    } else {
        ownershipString = "None";
    }

    String ownersString;
    if (type == OwnerType.MASTER) {
        ownersString = "Masters: ";
    } else if (type == OwnerType.OWNER) {
        ownersString = "Owners: ";
    } else {
        ownersString = "Members: ";
    }

    if (size == 0) {
        sender.sendMessage("#" + COLOR.gold() + structureId + " - " + COLOR.blue() + structureName,
                COLOR.reset() + ownersString + COLOR.red() + ownershipString);
    } else {
        sender.sendMessage("#" + COLOR.gold() + structureId + " - " + COLOR.blue() + structureName,
                COLOR.reset() + ownersString, ownershipString);
    }

}

From source file:com.yahoo.ycsb.bulk.hbase.RangePartitioner.java

private synchronized Text[] getCutPoints() throws IOException {
    if (cutPointArray == null) {
        String cutFileName = conf.get(CUTFILE_KEY);
        Path[] cf = DistributedCache.getLocalCacheFiles(conf);

        if (cf != null) {
            for (Path path : cf) {
                if (path.toUri().getPath().endsWith(cutFileName.substring(cutFileName.lastIndexOf('/')))) {
                    TreeSet<Text> cutPoints = new TreeSet<Text>();
                    Scanner in = new Scanner(new BufferedReader(new FileReader(path.toString())));
                    try {
                        while (in.hasNextLine())
                            cutPoints.add(new Text(Base64.decodeBase64(in.nextLine().getBytes())));
                    } finally {
                        in.close();/*from   w ww.  ja  v a2 s.c o m*/
                    }
                    cutPointArray = cutPoints.toArray(new Text[cutPoints.size()]);
                    break;
                }
            }
        }
        if (cutPointArray == null)
            throw new FileNotFoundException(cutFileName + " not found in distributed cache");
    }
    return cutPointArray;
}

From source file:io.jeandavid.projects.vod.entities.DvdOrder.java

@JsonIgnore
public TreeSet<DvdOrderDvd> getSortedDvdOrderDvds() {
    TreeSet<DvdOrderDvd> result = new TreeSet<>();
    for (DvdOrderDvd dvdOrderDvd : this.getDvdOrderDvds()) {
        result.add(dvdOrderDvd);
    }//from w w w  .  ja  v  a 2 s  .  c o  m
    return result;
}

From source file:com.enitalk.configs.DateCache.java

public NavigableSet<DateTime> days(JsonNode tree, String tz, JsonNode teacherNode) {
    ConcurrentSkipListSet<DateTime> dates = new ConcurrentSkipListSet<>();

    Iterator<JsonNode> els = tree.elements();
    DateTimeZone dz = DateTimeZone.forID(tz);
    DateTimeFormatter hour = DateTimeFormat.forPattern("HH:mm").withZone(dz);

    DateTime today = DateTime.now().millisOfDay().setCopy(0);
    while (els.hasNext()) {

        JsonNode el = els.next();/*from  ww  w . java2  s  .c o  m*/
        String day = el.path("day").asText();

        boolean plus = today.getDayOfWeek() > days.get(day);
        if (el.has("start") && el.has("end")) {
            DateTime start = hour.parseDateTime(el.path("start").asText()).dayOfMonth()
                    .setCopy(today.getDayOfMonth()).monthOfYear().setCopy(today.getMonthOfYear()).year()
                    .setCopy(today.getYear()).withDayOfWeek(days.get(day)).plusWeeks(plus ? 1 : 0);
            DateTime end = hour.parseDateTime(el.path("end").asText()).dayOfMonth()
                    .setCopy(today.getDayOfMonth()).monthOfYear().setCopy(today.getMonthOfYear()).year()
                    .setCopy(today.getYear()).withDayOfWeek(days.get(day)).plusWeeks(plus ? 1 : 0);

            Hours hours = Hours.hoursBetween(start, end);
            int hh = hours.getHours() + 1;

            while (hh-- > 0) {
                dates.add(start.plusHours(hh).toDateTime(DateTimeZone.UTC));
            }
        } else {
            List<String> datesAv = jackson.convertValue(el.path("times"), List.class);
            logger.info("Array of dates {} {}", datesAv, day);

            datesAv.forEach((String dd) -> {
                DateTime date = hour.parseDateTime(dd).dayOfMonth().setCopy(today.getDayOfMonth()).monthOfYear()
                        .setCopy(today.getMonthOfYear()).year().setCopy(today.getYear())
                        .withDayOfWeek(days.get(day)).plusWeeks(plus ? 1 : 0);
                dates.add(date.toDateTime(DateTimeZone.UTC));
            });

        }

    }

    final TreeSet<DateTime> addWeek = new TreeSet<>();
    for (int i = 1; i < 2; i++) {
        for (DateTime e : dates) {
            addWeek.add(e.plusWeeks(i));

        }
    }

    dates.addAll(addWeek);

    DateTime nowUtc = DateTime.now().toDateTime(DateTimeZone.UTC);
    nowUtc = nowUtc.plusHours(teacherNode.path("notice").asInt(2));

    NavigableSet<DateTime> ss = dates.tailSet(nowUtc, true);

    return ss;

}