List of usage examples for java.util TreeSet add
public boolean add(E e)
From source file:annis.gui.resultview.ResultViewPanel.java
public SortedSet<String> getVisibleTokenAnnos() { TreeSet<String> result = new TreeSet<>(); for (Entry<String, Boolean> e : tokenAnnoVisible.entrySet()) { if (e.getValue().booleanValue() == true) { result.add(e.getKey()); }//from w ww.ja va 2 s . c o m } return result; }
From source file:com.ichi2.libanki.Tags.java
/** Strip duplicates, adjust case to match existing tags, and sort. */ public TreeSet<String> canonify(List<String> tagList) { // NOTE: The python version creates a list of tags, puts them into a set, then sorts them. The TreeSet // used here already guarantees uniqueness and sort order, so we return it as-is without those steps. TreeSet<String> strippedTags = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER); for (String t : tagList) { String s = sCanonify.matcher(t).replaceAll(""); for (String existingTag : mTags.keySet()) { if (s.equalsIgnoreCase(existingTag)) { s = existingTag;/*from w ww .j a v a 2s.c o m*/ } } strippedTags.add(s); } return strippedTags; }
From source file:br.bireme.mlts.MoreLikeThat.java
/** * Finds similar documents/*from w ww . j a v a2 s . c o m*/ * @param likeText string used to find similar documents * @param fieldName the name of the document field used to compare with * @param getDocContent brings the document likeText if true * likeText. @see Docx * @return an ordered set of documents. * @throws IOException */ public TreeSet<DocX> moreLikeThat(final Reader likeText, final String[] fieldsName, final boolean getDocContent) throws IOException { if (likeText == null) { throw new NullPointerException("likeText"); } if (fieldsName == null) { throw new NullPointerException("fieldsName"); } final MoreLikeThis mlt = new MoreLikeThis(ir); final ScoreDoc[] hits; mlt.setAnalyzer(analyzer); if (maxDocFreq >= 0) { mlt.setMaxDocFreq(maxDocFreq); } if (maxDocFreqPct >= 0) { mlt.setMaxDocFreqPct(maxDocFreqPct); } mlt.setMaxNumTokensParsed(maxNumTokensParsed); mlt.setMaxQueryTerms(maxQueryTerms); mlt.setMaxWordLen(maxWordLen); mlt.setMinDocFreq(minDocFreq); mlt.setMinTermFreq(minTermFreq); mlt.setMinWordLen(minWordLen); if (stopwords != null) { mlt.setStopWords(stopwords); } mlt.setFieldNames(fieldsName); final Query query = mlt.like(likeText, null/*fieldName*/); final TreeSet<DocX> ret = new TreeSet<DocX>(new DocXComparator()); hits = is.search(query, maxHits).scoreDocs; for (ScoreDoc sdoc : hits) { final Map<String, List<String>> doc = getDocContent ? getDocument(sdoc) : null; ret.add(new DocX(sdoc.doc, sdoc.score, doc)); } return ret; }
From source file:com.kixeye.chassis.transport.shared.PropertiesServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // get list of properties TreeSet<String> properties = new TreeSet<String>(); AbstractConfiguration config = ConfigurationManager.getConfigInstance(); Iterator<String> keys = config.getKeys(); while (keys.hasNext()) { String key = keys.next(); Object value = config.getProperty(key); if ("aws.accessId".equals(key) || "aws.secretKey".equals(key) || "experiments-service.secret".equals(key) || "java.class.path".equals(key) || key.contains("framework.securityDefinition") || key.contains("password") || key.contains("secret")) { value = "*****"; }/*from w w w . j a v a2 s. c o m*/ properties.add(key + "=" + value.toString()); } // write them out in sorted order for (String line : properties) { resp.getWriter().append(line).println(); } }
From source file:de.dfki.km.perspecting.obie.experiments.PhraseExperiment.java
@Test public void testDifferentPrefixLengths() { final String template = "SELECT * WHERE {?s ?p ?o}"; try {/* ww w.j av a 2 s .co m*/ URL url = new URL("http://en.wikipedia.org/wiki/Kaiserslautern"); Document document = pipeline.createDocument(FileUtils.toFile(url), url.toURI(), MediaType.HTML, template, Language.EN); for (int step = 0; pipeline.hasNext(step) && step <= 5; step = pipeline.execute(step, document)) { System.out.println(step); } final BufferedWriter bw = new BufferedWriter( new FileWriter($SCOOBIE_HOME + "results/response_time_prefix_hashing.csv")); for (int SIZE = 1; SIZE < 11; SIZE++) { TreeSet<String> hist = new TreeSet<String>(); int count = 0; for (TokenSequence<String> i : document.getNounPhrases()) { String[] words = i.toString().split("[\\s]+"); for (String word : words) { count++; if (word.length() >= SIZE) hist.add(word.substring(0, SIZE)); else hist.add(word); } } StringBuilder query = new StringBuilder(); query.append("SELECT count(*) FROM index_literals, symbols WHERE " + "( symbols.object = index_literals.index AND substr(index_literals.literal,1," + SIZE + ") IN ("); for (String p : hist) { query.append("(?) , "); } query.setLength(query.length() - 3); query.append("))"); System.out.println(query.toString()); Connection c = pool.getConnection(); PreparedStatement stmtGetDatatypePropertyValues = c.prepareStatement(query.toString()); int paramIndex = 0; for (String p : hist) { stmtGetDatatypePropertyValues.setString(++paramIndex, p); } long start = System.currentTimeMillis(); ResultSet rs = stmtGetDatatypePropertyValues.executeQuery(); long end = System.currentTimeMillis(); while (rs.next()) { bw.append(SIZE + "\t" + (end - start) + "\t" + rs.getInt(1)); bw.newLine(); } stmtGetDatatypePropertyValues.close(); c.close(); } bw.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:de.dfki.km.perspecting.obie.model.Document.java
/** * @return the tokens//from w w w. j ava 2 s . com */ public List<Token> getTokens() { TreeSet<Token> tokens = new TreeSet<Token>(); for (String key : this.data.getKeys(TokenSequence.TOKEN)) { tokens.add(new Token(Integer.parseInt(key), this)); } return new ArrayList<Token>(tokens); }
From source file:net.dv8tion.jda.entities.impl.MessageImpl.java
@Override public String getStrippedContent() { if (strippedContent == null) { String tmp = getContent(); //all the formatting keys to keep track of String[] keys = new String[] { "*", "_", "`", "~~" }; //find all tokens (formatting strings described above) TreeSet<FormatToken> tokens = new TreeSet<>((t1, t2) -> Integer.compare(t1.start, t2.start)); for (String key : keys) { Matcher matcher = Pattern.compile(Pattern.quote(key)).matcher(tmp); while (matcher.find()) { tokens.add(new FormatToken(key, matcher.start())); }//from w ww . j a v a 2 s. com } //iterate over all tokens, find all matching pairs, and add them to the list toRemove Stack<FormatToken> stack = new Stack<>(); List<FormatToken> toRemove = new ArrayList<>(); boolean inBlock = false; for (FormatToken token : tokens) { if (stack.empty() || !stack.peek().format.equals(token.format) || stack.peek().start + token.format.length() == token.start) { //we are at opening tag if (!inBlock) { //we are outside of block -> handle normally if (token.format.equals("`")) { //block start... invalidate all previous tags stack.clear(); inBlock = true; } stack.push(token); } else if (token.format.equals("`")) { //we are inside of a block -> handle only block tag stack.push(token); } } else if (!stack.empty()) { //we found a matching close-tag toRemove.add(stack.pop()); toRemove.add(token); if (token.format.equals("`") && stack.empty()) { //close tag closed the block inBlock = false; } } } //sort tags to remove by their start-index and iteratively build the remaining string Collections.sort(toRemove, (t1, t2) -> Integer.compare(t1.start, t2.start)); StringBuilder out = new StringBuilder(); int currIndex = 0; for (FormatToken formatToken : toRemove) { if (currIndex < formatToken.start) { out.append(tmp.substring(currIndex, formatToken.start)); } currIndex = formatToken.start + formatToken.format.length(); } if (currIndex < tmp.length()) { out.append(tmp.substring(currIndex)); } //return the stripped text, escape all remaining formatting characters (did not have matching open/close before or were left/right of block strippedContent = out.toString().replace("*", "\\*").replace("_", "\\_").replace("~", "\\~"); } return strippedContent; }
From source file:com.idega.block.cal.renderer.AbstractCompactScheduleRenderer.java
/** * <p>/*w w w . j a v a 2 s. 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.DIV_ELEM, schedule); writer.startElement(HTML.DIV_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(HTML.CLASS_ATTR, CalendarConstants.SCHEDULE_ENTRY_STYLE_CLASS, null); writer.writeAttribute(HTML.HREF_ATTR, "javascript:void(0)", null); writer.writeAttribute("entryid", entry.getId(), null); DateFormat format; String pattern = null; if ((pattern != null) && (pattern.length() > 0)) { format = new SimpleDateFormat(pattern); } else { if (context.getApplication().getDefaultLocale() != null) { format = DateFormat.getDateInstance(DateFormat.MEDIUM, context.getApplication().getDefaultLocale()); } else { format = DateFormat.getDateInstance(DateFormat.MEDIUM); } } String startTime = format.format(entry.getStartTime()); startTime += " "; startTime += entry.getStartTime().getHours(); startTime += ":"; if (entry.getStartTime().getMinutes() < 10) { startTime += "0"; startTime += entry.getStartTime().getMinutes(); } else { startTime += entry.getStartTime().getMinutes(); } String endTime = ""; endTime += entry.getEndTime().getHours(); endTime += ":"; if (entry.getEndTime().getMinutes() < 10) { endTime += "0"; endTime += entry.getEndTime().getMinutes(); } else { endTime += entry.getEndTime().getMinutes(); } } // 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.DIV_ELEM); writer.endElement(HTML.DIV_ELEM); } }
From source file:ca.uvic.cs.tagsea.statistics.svn.jobs.SVNCommentScanningJob.java
/** * @param c//from w w w .j a v a2 s .c o m * @param ann * @return */ private String getAuthor(Comment c, ISVNAnnotations ann) { String author = "unknown"; if (ann != null) { TreeSet authors = new TreeSet(); int i = c.START_LINE; for (i = c.START_LINE; i <= c.END_LINE; i++) { String a = ann.getAuthor(i); if (a == null) a = ""; authors.add(a); } author = ""; for (Iterator it = authors.iterator(); it.hasNext();) { String a = (String) it.next(); author += a + ","; } } return author; }
From source file:org.opendatakit.security.server.SecurityServiceUtil.java
/** * Method to enforce an access configuration constraining only registered users, authenticated * users and anonymous access./*from w w w .j a v a2 s. com*/ * * Add additional checks of the incoming parameters and patch things up if the incoming list of * users omits the super-user. * * @param users * @param anonGrants * @param allGroups * @param cc * @throws DatastoreFailureException * @throws AccessDeniedException */ public static final void setStandardSiteAccessConfiguration(ArrayList<UserSecurityInfo> users, ArrayList<GrantedAuthorityName> allGroups, CallingContext cc) throws DatastoreFailureException, AccessDeniedException { // remove anonymousUser from the set of users and collect its // permissions (anonGrantStrings) which will be placed in // the granted authority hierarchy table. List<String> anonGrantStrings = new ArrayList<String>(); { UserSecurityInfo anonUser = null; for (UserSecurityInfo i : users) { if (i.getType() == UserType.ANONYMOUS) { anonUser = i; // clean up grants for anonymousUser -- // ignore anonAuth (the grant under which we will place things) // and forbid Site Admin for (GrantedAuthorityName a : i.getAssignedUserGroups()) { if (anonAuth.getAuthority().equals(a.name())) continue; // avoid circularity... // only allow ROLE_ATTACHMENT_VIEWER and GROUP_ assignments. if (!a.name().startsWith(GrantedAuthorityName.GROUP_PREFIX)) { continue; } // do not allow Site Admin assignments for Anonymous -- // or Tables super-user or Tables Administrator. // those all give access to the full set of users on the system // and giving that information to Anonymous is a security // risk. if (GrantedAuthorityName.GROUP_SITE_ADMINS.equals(a) || GrantedAuthorityName.GROUP_ADMINISTER_TABLES.equals(a) || GrantedAuthorityName.GROUP_SUPER_USER_TABLES.equals(a)) { continue; } anonGrantStrings.add(a.name()); } break; } } if (anonUser != null) { users.remove(anonUser); } } // scan through the users and remove any entries under assigned user groups // that do not begin with GROUP_. // // Additionally, if the user is an e-mail, remove the GROUP_DATA_COLLECTORS // permission since ODK Collect does not support oauth2 authentication. { TreeSet<GrantedAuthorityName> toRemove = new TreeSet<GrantedAuthorityName>(); for (UserSecurityInfo i : users) { // only working with registered users if (i.getType() != UserType.REGISTERED) { continue; } // get the list of assigned groups // -- this is not a copy -- we can directly manipulate this. TreeSet<GrantedAuthorityName> assignedGroups = i.getAssignedUserGroups(); // scan the set of assigned groups and remove any that don't begin with GROUP_ toRemove.clear(); for (GrantedAuthorityName name : assignedGroups) { if (!name.name().startsWith(GrantedAuthorityName.GROUP_PREFIX)) { toRemove.add(name); } } if (!toRemove.isEmpty()) { assignedGroups.removeAll(toRemove); } // for e-mail accounts, remove the Data Collector permission since ODK Collect // does not support an oauth2 authentication mechanism. if (i.getEmail() != null) { assignedGroups.remove(GrantedAuthorityName.GROUP_DATA_COLLECTORS); } } } // find the entry(entries) for the designated super-user(s) String superUserUsername = cc.getUserService().getSuperUserUsername(); int expectedSize = ((superUserUsername != null) ? 1 : 0); ArrayList<UserSecurityInfo> superUsers = new ArrayList<UserSecurityInfo>(); for (UserSecurityInfo i : users) { if (i.getType() == UserType.REGISTERED) { if (i.getUsername() != null && superUserUsername != null && i.getUsername().equals(superUserUsername)) { superUsers.add(i); } } } if (superUsers.size() != expectedSize) { // we are missing one or both super-users. // remove any we have and recreate them from scratch. users.removeAll(superUsers); superUsers.clear(); // Synthesize a UserSecurityInfo object for the super-user(s) // and add it(them) to the list. try { List<RegisteredUsersTable> tList = RegisteredUsersTable.assertSuperUsers(cc); for (RegisteredUsersTable t : tList) { UserSecurityInfo i = new UserSecurityInfo(t.getUsername(), t.getFullName(), t.getEmail(), UserSecurityInfo.UserType.REGISTERED); superUsers.add(i); users.add(i); } } catch (ODKDatastoreException e) { e.printStackTrace(); throw new DatastoreFailureException("Incomplete update"); } } // reset super-user privileges to have (just) site admin privileges // even if caller attempts to change, add, or remove them. for (UserSecurityInfo i : superUsers) { TreeSet<GrantedAuthorityName> grants = new TreeSet<GrantedAuthorityName>(); grants.add(GrantedAuthorityName.GROUP_SITE_ADMINS); grants.add(GrantedAuthorityName.ROLE_SITE_ACCESS_ADMIN); // override whatever the user gave us. i.setAssignedUserGroups(grants); } try { // enforce our fixed set of groups and their inclusion hierarchy. // this is generally a no-op during normal operations. GrantedAuthorityHierarchyTable.assertGrantedAuthorityHierarchy(siteAuth, SecurityServiceUtil.siteAdministratorGrants, cc); GrantedAuthorityHierarchyTable.assertGrantedAuthorityHierarchy(administerTablesAuth, SecurityServiceUtil.administerTablesGrants, cc); GrantedAuthorityHierarchyTable.assertGrantedAuthorityHierarchy(superUserTablesAuth, SecurityServiceUtil.superUserTablesGrants, cc); GrantedAuthorityHierarchyTable.assertGrantedAuthorityHierarchy(synchronizeTablesAuth, SecurityServiceUtil.synchronizeTablesGrants, cc); GrantedAuthorityHierarchyTable.assertGrantedAuthorityHierarchy(dataOwnerAuth, SecurityServiceUtil.dataOwnerGrants, cc); GrantedAuthorityHierarchyTable.assertGrantedAuthorityHierarchy(dataViewerAuth, SecurityServiceUtil.dataViewerGrants, cc); GrantedAuthorityHierarchyTable.assertGrantedAuthorityHierarchy(dataCollectorAuth, SecurityServiceUtil.dataCollectorGrants, cc); // place the anonymous user's permissions in the granted authority table. GrantedAuthorityHierarchyTable.assertGrantedAuthorityHierarchy(anonAuth, anonGrantStrings, cc); // get all granted authority names TreeSet<String> authorities = GrantedAuthorityHierarchyTable .getAllPermissionsAssignableGrantedAuthorities(cc.getDatastore(), cc.getCurrentUser()); // remove the groups that have structure (i.e., those defined above). authorities.remove(siteAuth.getAuthority()); authorities.remove(administerTablesAuth.getAuthority()); authorities.remove(superUserTablesAuth.getAuthority()); authorities.remove(synchronizeTablesAuth.getAuthority()); authorities.remove(dataOwnerAuth.getAuthority()); authorities.remove(dataViewerAuth.getAuthority()); authorities.remove(dataCollectorAuth.getAuthority()); authorities.remove(anonAuth.getAuthority()); // delete all hierarchy structures under anything else. // i.e., if somehow USER_IS_REGISTERED had been granted GROUP_FORM_MANAGER // then this loop would leave USER_IS_REGISTERED without any grants. // (it repairs the database to conform to our privilege hierarchy expectations). List<String> empty = Collections.emptyList(); for (String s : authorities) { GrantedAuthorityHierarchyTable.assertGrantedAuthorityHierarchy(new SimpleGrantedAuthority(s), empty, cc); } // declare all the users (and remove users that are not in this set) Map<UserSecurityInfo, String> pkMap = setUsers(users, cc); // now, for each GROUP_..., update the user granted authority // table with the users that have that GROUP_... assignment. setUsersOfGrantedAuthority(pkMap, siteAuth, cc); setUsersOfGrantedAuthority(pkMap, administerTablesAuth, cc); setUsersOfGrantedAuthority(pkMap, superUserTablesAuth, cc); setUsersOfGrantedAuthority(pkMap, synchronizeTablesAuth, cc); setUsersOfGrantedAuthority(pkMap, dataOwnerAuth, cc); setUsersOfGrantedAuthority(pkMap, dataViewerAuth, cc); setUsersOfGrantedAuthority(pkMap, dataCollectorAuth, cc); // all super-users would already have their site admin role and // we leave that unchanged. The key is to ensure that the // super users are in the users list so they don't get // accidentally removed and that they have siteAuth group // membership. I.e., we don't need to manage ROLE_SITE_ACCESS_ADMIN // here. it is done elsewhere. } catch (ODKDatastoreException e) { e.printStackTrace(); throw new DatastoreFailureException("Incomplete update"); } finally { Datastore ds = cc.getDatastore(); User user = cc.getCurrentUser(); try { SecurityRevisionsTable.setLastRegisteredUsersRevisionDate(ds, user); } catch (ODKDatastoreException e) { // if it fails, use RELOAD_INTERVAL to force reload. e.printStackTrace(); } try { SecurityRevisionsTable.setLastRoleHierarchyRevisionDate(ds, user); } catch (ODKDatastoreException e) { // if it fails, use RELOAD_INTERVAL to force reload. e.printStackTrace(); } } }