List of usage examples for java.util TreeSet add
public boolean add(E e)
From source file:br.bireme.ngrams.NGrams.java
private static Set<String> results2pipe(final Parameters parameters, final Set<Result> results) { assert parameters != null; assert results != null; final TreeSet<String> ret = new TreeSet<>(); for (Result result : results) { final String[] param = result.param; final Document doc = result.doc; final String itext = (String) doc.get(parameters.indexed.name + "~notnormalized").replace('|', '!'); final String stext = param[parameters.indexed.pos].trim().replace('|', '!'); final String id1 = param[parameters.id.pos]; final String id2 = (String) doc.get("id~notnormalized"); final String src1 = param[parameters.db.pos]; final String src2 = (String) doc.get("database"); final String str = result.score + "|" + result.similarity + "|" + id1 + "|" + id2 + "|" + stext + "|" + itext + "|" + src1 + "|" + src2; //System.out.println("! " + result.compare); ret.add(str); }/*w w w .ja va 2s . c o m*/ return ret.descendingSet(); }
From source file:edu.umass.cs.msocket.proxy.console.ConsoleModule.java
/** * Loads the commands for this module/*from w w w . j av a 2 s . c o m*/ */ protected void loadCompletor() { List completors = new LinkedList(); int size = commands.size(); if (size > 0) { TreeSet set = new TreeSet(); Iterator it = commands.iterator(); while (it.hasNext()) { set.add(((ConsoleCommand) it.next()).getCommandName()); } completors.add(new SimpleCompletor((String[]) set.toArray(new String[size]))); } completors.add(new FileNameCompletor()); Completor[] completorsArray = (Completor[]) completors.toArray(new Completor[completors.size()]); consoleCompletor = new ArgumentCompletor(completorsArray, new CommandDelimiter()); }
From source file:net.spfbl.core.Reverse.java
public TreeSet<String> getAddressSet(String ip, boolean refresh) { if (addressSet == null) { return new TreeSet<String>(); } else {/* w ww. j a va 2 s . c o m*/ if (refresh) { refresh(); } TreeSet<String> resultSet = new TreeSet<String>(); for (String hostname : addressSet) { if (SPF.matchHELO(ip, hostname, refresh)) { resultSet.add(hostname); } } return resultSet; } }
From source file:fr.inria.oak.paxquery.common.xml.navigation.NavigationTreePattern.java
/** * Recursive method called in order to create the normalized tree pattern. * //ww w.j av a 2 s. c o m * @param node a tree pattern node, we will order its children * @param counter the value of the counter that we are using for renumbering the tree pattern nodes * @return the counter that we are using for renumbering the tree pattern nodes */ private int recGetNormalizedTreePattern(NavigationTreePatternNode node, int counter) { if (node.getEdges().isEmpty()) return counter; TreeSet<NavigationTreePatternNode> sortedSetChildrenNodes = new TreeSet<NavigationTreePatternNode>(); int newCounter = counter + node.getEdges().size(); for (NavigationTreePatternEdge edge : node.getEdges()) { newCounter = recGetNormalizedTreePattern(edge.n2, newCounter); sortedSetChildrenNodes.add(edge.n2); } node.cleanEdges(); for (NavigationTreePatternNode child : sortedSetChildrenNodes.descendingSet()) { child.setNodeCode(counter); counter++; child.getParentEdge().n1.addEdge(child.getParentEdge()); } return newCounter; }
From source file:com.qpark.maven.plugin.flowmapper.AbstractMappingTypeGenerator.java
protected String getChildrenImports(final List<ComplexTypeChild> children) { StringBuffer sb = new StringBuffer(256); TreeSet<String> imports = new TreeSet<String>(); for (ComplexTypeChild child : children) { if (!child.getComplexType().getClassNameFullQualified().startsWith("java.lang.") && !"interfaceName".equals(child.getChildName()) && child.getComplexType().getPackageName() != null && child.getComplexType().getPackageName().length() > 0) { sb.setLength(0);/*from www .j a v a 2 s .c o m*/ sb.append("import "); sb.append(child.getComplexType().getClassNameFullQualified()); sb.append(";\n"); imports.add(sb.toString()); } } sb.setLength(0); for (String string : imports) { sb.append(string); } return sb.toString(); }
From source file:com.qpark.maven.plugin.flowmapper.AbstractMappingTypeGenerator.java
protected String getChildrenImporxts(final List<ComplexTypeChild> children) { StringBuffer sb = new StringBuffer(256); TreeSet<String> imports = new TreeSet<String>(); for (ComplexTypeChild child : children) { if (!child.getComplexType().getClassNameFullQualified().startsWith("java.lang.") && !"interfaceName".equals(child.getChildName()) && child.getComplexType().getPackageName() != null && child.getComplexType().getPackageName().length() > 0) { sb.setLength(0);/* w w w .ja v a 2 s .com*/ sb.append("import "); sb.append(child.getComplexType().getClassNameFullQualified()); sb.append(";\n"); imports.add(sb.toString()); } } sb.setLength(0); for (String string : imports) { sb.append(string); } return sb.toString(); }
From source file:com.cyberway.issue.crawler.settings.XMLSettingsHandler.java
public Collection getDomainOverrides(String rootDomain) { File settingsDir = getSettingsDirectory(); //Find the right start directory. ArrayList<String> domains = new ArrayList<String>(); //First we deconstruct the rootDomain string while (rootDomain != null && rootDomain.length() > 0) { if (rootDomain.indexOf('.') < 0) { // Last level. domains.add(rootDomain);/*from ww w . j a v a2 s . com*/ break; //We're done. } else { // Got more then one level left. domains.add(rootDomain.substring(0, rootDomain.indexOf('.'))); // Strip down rootDomain. rootDomain = rootDomain.substring(rootDomain.indexOf('.') + 1); } } //Build up a proper path //Since the domains are right to left, we start at the end of the array. StringBuffer subDir = new StringBuffer(); for (int i = (domains.size() - 1); i >= 0; i--) { subDir.append(File.separator + domains.get(i)); } //Then we move to the approprite directory. settingsDir = new File(settingsDir.getPath() + subDir); TreeSet<String> confirmedSubDomains = new TreeSet<String>(); if (settingsDir.exists()) { // Found our place! Search through it's subdirs. File[] possibleSubDomains = settingsDir.listFiles(); for (int i = 0; i < possibleSubDomains.length; i++) { if (possibleSubDomains[i].isDirectory() && isOverride(possibleSubDomains[i])) { // Found one! confirmedSubDomains.add(possibleSubDomains[i].getName()); } } } return confirmedSubDomains; }
From source file:edu.fullerton.ldvw.ImageHistory.java
/** * Add a table of buttons/links and info to control display and deletion * * @param imgCnt total number of records in selection *//* w w w . ja v a 2s . c o m*/ private PageItemList getNavBar(int imgCnt, boolean isBottom, String frmName) throws WebUtilException, LdvTableException, SQLException { PageItemList ret = new PageItemList(); PageTable navBar = new PageTable(); PageTableRow cmds = new PageTableRow(); // add next/prev buttons if applicable PageFormButton prevBtn = new PageFormButton("submitAct", "<", "Prev"); prevBtn.setEnabled(strt > 0); cmds.add(prevBtn); String botSuffix = isBottom ? "2" : ""; int curPage = strt / cnt + 1; int nPage = (imgCnt + cnt - 1) / cnt; PageItemList pageSel = new PageItemList(); pageSel.add("Page: "); PageFormText pageNum = new PageFormText("pageNum" + botSuffix, String.format("%1$,d", curPage)); pageNum.setSize(3); pageNum.setMaxLen(6); pageNum.addEvent("onchange", "historySubmit('Go" + botSuffix + "', this);"); pageSel.add(pageNum); pageSel.add(String.format(" of %d ", nPage)); cmds.add(pageSel); PageFormButton nextBtn = new PageFormButton("submitAct", ">", "Next"); nextBtn.setEnabled(curPage < nPage); cmds.add(nextBtn); int stop = Math.min(strt + cnt, imgCnt); String showing = String.format("Showing %1$d-%2$d for:", strt + 1, stop); cmds.add(showing); // add selection by user String cn = vuser.getCn(); TreeMap<String, Integer> ucounts = imgTbl.getCountByUser(); String[] usrs = new String[ucounts.size() + 1]; String sel = "All"; usrs[0] = "All"; int i = 1; for (Map.Entry<String, Integer> entry : ucounts.entrySet()) { String u = entry.getKey(); Integer cnts = entry.getValue(); String opt = String.format("%1$s (%2$d)", u, cnts); if (userWanted.equalsIgnoreCase(u)) { sel = opt; } usrs[i] = opt; i++; } if (!isBottom) { // allow them to select another user (or all) PageFormSelect usrSel = new PageFormSelect("usrSel", usrs); usrSel.setSelected(sel); usrSel.addEvent("onchange", "this.form.submit()"); PageItemList owner = new PageItemList(); owner.add(new PageItemString("Owner: ", false)); owner.add(usrSel); cmds.add(owner); // Group selector TreeSet<String> groups = imgGrpTbl.getGroups(userWanted); if (!groups.isEmpty()) { PageItemList grpPIL = new PageItemList(); grpPIL.add(new PageItemString("Group: ", false)); groups.add("All"); PageFormSelect grpSel = new PageFormSelect("group"); grpSel.add(groups); String curGroup = request.getParameter("group"); if (curGroup != null && !curGroup.isEmpty() && groups.contains(curGroup)) { grpSel.setSelected(curGroup); } else { grpSel.setSelected("All"); } grpSel.addEvent("onchange", "document." + frmName + ".submit()"); grpPIL.add(grpSel); cmds.add(grpPIL); } } cmds.setClassAll("noborder"); navBar.addRow(cmds); ret.add(navBar); if (!isBottom) { // New table because this one has fewer columns and we want to hide it by default navBar = new PageTable(); navBar.setClassName("hidable"); navBar.addStyle("display", "none"); // allow them to change image size PageTableRow cmd2 = new PageTableRow(); String[] sizes = { "original", "small", "med" }; PageFormSelect sizeSel = new PageFormSelect("size", sizes); String curSize = request.getParameter("size"); if (curSize != null && !curSize.isEmpty() && ArrayUtils.contains(sizes, curSize)) { sizeSel.setSelected(curSize); } sizeSel.addEvent("onchange", "document." + frmName + ".submit()"); PageItemString lbl; lbl = new PageItemString("Size: ", false); lbl.setAlign(PageItem.Alignment.RIGHT); cmd2.add(lbl); PageTableColumn col; col = new PageTableColumn(sizeSel); cmd2.add(col); cmd2.add(); cmd2.add(); cmd2.setClassAll("noborder"); navBar.addRow(cmd2); cmd2 = new PageTableRow(); lbl = new PageItemString("Selections: ", false); lbl.setAlign(PageItem.Alignment.RIGHT); cmd2.add(lbl); PageFormButton selAll = new PageFormButton("selAll", "Select all", "selall"); selAll.setType("button"); selAll.addEvent("onclick", "setChkBoxByClass('selBox',true)"); cmd2.add(selAll); PageFormButton clrAll = new PageFormButton("selAll", "Clear all", "clrall"); clrAll.setType("button"); clrAll.addEvent("onclick", "setChkBoxByClass('selBox', false)"); cmd2.add(clrAll); cmd2.add(); cmd2.setClassAll("noborder"); navBar.addRow(cmd2); if (userWanted.equalsIgnoreCase(vuser.getCn()) || vuser.isAdmin()) { cmd2 = new PageTableRow(); lbl = new PageItemString("Delete images: ", false); lbl.setAlign(PageItem.Alignment.RIGHT); cmd2.add(lbl); col = new PageTableColumn(new PageFormSubmit("submitAct", "Delete Selected")); cmd2.add(col); cmd2.add(); cmd2.add(); cmd2.setClassAll("noborder"); navBar.addRow(cmd2); } PageTableRow grpRow = new PageTableRow(); lbl = new PageItemString("My groups: ", false); lbl.setAlign(PageItem.Alignment.RIGHT); grpRow.add(lbl); TreeSet<String> myGroup = imgGrpTbl.getGroups(curUser); if (!myGroup.contains("Favorites")) { myGroup.add("Favorites"); } myGroup.remove("Last result"); PageFormSelect grpSel = new PageFormSelect("op_group"); grpSel.add(myGroup); String curGroup = request.getParameter("groupSel"); if (curGroup != null && !curGroup.isEmpty() && myGroup.contains(curGroup)) { grpSel.setSelected(curGroup); } else { grpSel.setSelected("Favorites"); } grpRow.add(grpSel); grpRow.add(new PageFormSubmit("submitAct", "Add to grp")); grpRow.add(new PageFormSubmit("submitAct", "Del from grp")); grpRow.setClassAll("noborder"); navBar.addRow(grpRow); grpRow = new PageTableRow(); lbl = new PageItemString("New Group: ", false); lbl.setAlign(PageItem.Alignment.RIGHT); grpRow.add(lbl); PageFormText grpNameTxt = new PageFormText("newGrpName", "<new group name>"); grpNameTxt.addEvent("onfocus", "if(this.value == '<new group name>'){ this.value = ''; }"); grpNameTxt.addEvent("onblur", "if(this.value == ''){ this.value = '<new group name>'; }"); grpRow.add(grpNameTxt); PageFormSubmit newGrpBtn = new PageFormSubmit("submitAct", "New grp"); grpRow.add(newGrpBtn); grpRow.add(); grpRow.setClassAll("noborder"); navBar.addRow(grpRow); ret.add(navBar); PageItemString optBtn = new PageItemString("+More options"); optBtn.addEvent("onclick", "showByClass('hidable',this)"); optBtn.setClassName("showCmd"); ret.addBlankLines(1); ret.add(optBtn); } vpage.includeJS("showByClass.js"); return ret; }
From source file:com.autentia.intra.jsf.schedule.renderer.BitacoreScheduleDetailedDayRenderer.java
protected void writeEntries(FacesContext context, HtmlSchedule schedule, ScheduleDay day, ResponseWriter writer) throws IOException { final String clientId = schedule.getClientId(context); FormInfo parentFormInfo = RendererUtils.findNestingForm(schedule, context); String formId = parentFormInfo == null ? null : parentFormInfo.getFormName(); TreeSet entrySet = new TreeSet(); for (Iterator entryIterator = day.iterator(); entryIterator.hasNext();) { entrySet.add(new EntryWrapper((ScheduleEntry) entryIterator.next(), day)); }/*from www. ja va2 s .c om*/ EntryWrapper[] entries = (EntryWrapper[]) entrySet.toArray(new EntryWrapper[entrySet.size()]); //determine overlaps scanEntries(entries, 0); //determine the number of columns within this day int maxColumn = 0; for (Iterator entryIterator = entrySet.iterator(); entryIterator.hasNext();) { EntryWrapper wrapper = (EntryWrapper) entryIterator.next(); maxColumn = Math.max(wrapper.column, maxColumn); } int numberOfColumns = maxColumn + 1; //make sure the entries take up all available space horizontally maximizeEntries(entries, numberOfColumns); //now determine the width in percent of 1 column float columnWidth = 100 / numberOfColumns; //and now draw the entries in the columns for (Iterator entryIterator = entrySet.iterator(); entryIterator.hasNext();) { EntryWrapper wrapper = (EntryWrapper) entryIterator.next(); boolean selected = isSelected(schedule, wrapper); //compose the CSS style for the entry box StringBuffer entryStyle = new StringBuffer(); entryStyle.append(wrapper.getBounds(schedule, columnWidth)); String entryBorderColor = getEntryRenderer(schedule).getColor(context, schedule, wrapper.entry, selected); if (entryBorderColor != null) { entryStyle.append(" border-color: "); entryStyle.append(entryBorderColor); entryStyle.append(";"); } if (selected) { writer.startElement(HTML.DIV_ELEM, schedule); writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "entry-selected"), null); writer.writeAttribute(HTML.STYLE_ATTR, entryStyle.toString(), null); //draw the tooltip if (showTooltip(schedule)) { getEntryRenderer(schedule).renderToolTip(context, writer, schedule, wrapper.entry, selected); } //draw the content getEntryRenderer(schedule).renderContent(context, writer, schedule, day, wrapper.entry, false, selected); writer.endElement(HTML.DIV_ELEM); } else { //if the schedule is read-only, the entries should not be //hyperlinks writer.startElement(schedule.isReadonly() ? HTML.DIV_ELEM : HTML.ANCHOR_ELEM, schedule); //draw the tooltip if (showTooltip(schedule)) { getEntryRenderer(schedule).renderToolTip(context, writer, schedule, wrapper.entry, selected); } if (!schedule.isReadonly()) { writer.writeAttribute("href", "#", null); writer.writeAttribute(HTML.ONMOUSEUP_ATTR, "fireEntrySelected('" + formId + "', '" + clientId + "', '" + wrapper.entry.getId() + "');", null); } writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "entry"), null); writer.writeAttribute(HTML.STYLE_ATTR, entryStyle.toString(), null); //draw the content getEntryRenderer(schedule).renderContent(context, writer, schedule, day, wrapper.entry, false, selected); writer.endElement(schedule.isReadonly() ? HTML.DIV_ELEM : "a"); } } }
From source file:com.autentia.tnt.jsf.schedule.renderer.BitacoreScheduleDetailedDayRenderer.java
protected void writeEntries(FacesContext context, HtmlSchedule schedule, ScheduleDay day, ResponseWriter writer) throws IOException { final String clientId = schedule.getClientId(context); FormInfo parentFormInfo = RendererUtils.findNestingForm(schedule, context); String formId = parentFormInfo == null ? null : parentFormInfo.getFormName(); TreeSet entrySet = new TreeSet(); for (Iterator entryIterator = day.iterator(); entryIterator.hasNext();) { entrySet.add(new EntryWrapper((ScheduleEntry) entryIterator.next(), day)); }//from w w w . j av a2s. com EntryWrapper[] entries = (EntryWrapper[]) entrySet.toArray(new EntryWrapper[entrySet.size()]); //determine overlaps scanEntries(entries, 0); //determine the number of columns within this day int maxColumn = 0; for (Iterator entryIterator = entrySet.iterator(); entryIterator.hasNext();) { EntryWrapper wrapper = (EntryWrapper) entryIterator.next(); maxColumn = Math.max(wrapper.column, maxColumn); } int numberOfColumns = maxColumn + 1; //make sure the entries take up all available space horizontally maximizeEntries(entries, numberOfColumns); //now determine the width in percent of 1 column float columnWidth = (float) 100 / numberOfColumns; //and now draw the entries in the columns for (Iterator entryIterator = entrySet.iterator(); entryIterator.hasNext();) { EntryWrapper wrapper = (EntryWrapper) entryIterator.next(); boolean selected = isSelected(schedule, wrapper); //compose the CSS style for the entry box StringBuffer entryStyle = new StringBuffer(); entryStyle.append(wrapper.getBounds(schedule, columnWidth)); String entryBorderColor = getEntryRenderer(schedule).getColor(context, schedule, wrapper.entry, selected); if (entryBorderColor != null) { entryStyle.append(" border-color: "); entryStyle.append(entryBorderColor); entryStyle.append(";"); } if (selected) { writer.startElement(HTML.DIV_ELEM, schedule); writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "entry-selected"), null); writer.writeAttribute(HTML.STYLE_ATTR, entryStyle.toString(), null); //draw the tooltip if (showTooltip(schedule)) { getEntryRenderer(schedule).renderToolTip(context, writer, schedule, wrapper.entry, selected); } //draw the content getEntryRenderer(schedule).renderContent(context, writer, schedule, day, wrapper.entry, false, selected); writer.endElement(HTML.DIV_ELEM); } else { //if the schedule is read-only, the entries should not be //hyperlinks writer.startElement(schedule.isReadonly() ? HTML.DIV_ELEM : HTML.ANCHOR_ELEM, schedule); //draw the tooltip if (showTooltip(schedule)) { getEntryRenderer(schedule).renderToolTip(context, writer, schedule, wrapper.entry, selected); } if (!schedule.isReadonly()) { writer.writeAttribute("href", "#", null); writer.writeAttribute(HTML.ONMOUSEUP_ATTR, "fireEntrySelected('" + formId + "', '" + clientId + "', '" + wrapper.entry.getId() + "');", null); } writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "entry"), null); writer.writeAttribute(HTML.STYLE_ATTR, entryStyle.toString(), null); //draw the content getEntryRenderer(schedule).renderContent(context, writer, schedule, day, wrapper.entry, false, selected); writer.endElement(schedule.isReadonly() ? HTML.DIV_ELEM : "a"); } } }