List of usage examples for java.util TreeSet add
public boolean add(E e)
From source file:com.joliciel.talismane.machineLearning.linearsvm.LinearSVMDecisionMaker.java
@Override public List<Decision<T>> decide(List<FeatureResult<?>> featureResults) { List<Feature> featureList = new ArrayList<Feature>(featureResults.size()); this.prepareData(featureResults, featureList); 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 w w .j a va 2 s .c om*/ decisions = new ArrayList<Decision<T>>(outcomeSet); } else { Feature[] instance = new Feature[1]; instance = featureList.toArray(instance); double[] probabilities = new double[model.getLabels().length]; Linear.predictProbability(model, instance, probabilities); TreeSet<Decision<T>> outcomeSet = new TreeSet<Decision<T>>(); for (int i = 0; i < model.getLabels().length; i++) { Decision<T> decision = decisionFactory.createDecision(outcomes.get(i), probabilities[i]); outcomeSet.add(decision); } decisions = new ArrayList<Decision<T>>(outcomeSet); } return decisions; }
From source file:org.modeshape.web.jcr.rest.handler.RestItemHandlerImpl.java
/** * Performs a bulk deletion of items, using a single {@link javax.jcr.Session}. If any of the items cannot be deleted for whatever * reason, the entire operation fails./* www .j av a 2s . c om*/ * * @param request the servlet request; may not be null or unauthenticated * @param repositoryName the URL-encoded repository name * @param workspaceName the URL-encoded workspace name * @param requestContent the JSON-encoded array of the nodes to remove * @return a {@code non-null} {@link Result} * @throws javax.jcr.RepositoryException if any of the JCR operations fail * @see RestItemHandlerImpl#deleteItem(Request, String, String, String) */ @Override public void deleteItems(Request request, String repositoryName, String workspaceName, String requestContent) throws RepositoryException { ArrayNode requestArray = stringToJSONArray(requestContent); if (requestArray.size() == 0) { return; } Session session = getSession(request, repositoryName, workspaceName); TreeSet<String> pathsInOrder = new TreeSet<>(); for (int i = 0; i < requestArray.size(); i++) { pathsInOrder.add(absPath(requestArray.get(i).toString())); } List<String> pathsInOrderList = new ArrayList<>(pathsInOrder); Collections.reverse(pathsInOrderList); for (String path : pathsInOrderList) { doDelete(path, session); } session.save(); }
From source file:com.vaushell.shaarlijavaapi.ShaarliClientTest.java
/** * Test a link creation for a unlogged user. */// ww w . j a va 2 s .c om @Test public void testCreateUnlogged() { final TreeSet<String> tags = new TreeSet<>(); tags.add("java"); tags.add("coding"); clientUnauth.createLink("http://fabien.vauchelles.com/1", "Blog de Fabien Vauchelles n1", "Du coooodde rahhh::!!!!! #", tags, false); assertEquals("Unlogged user can't create links", 0, clientUnauth.getLinksCount()); }
From source file:com.zimbra.common.util.ngxlookup.ZimbraNginxLookUpClient.java
/** * Parse a server list.//from w ww .ja va 2 s . c o m * Each server value is hostname:port or just hostname. * @param serverList * @return */ private List<Route> parseServerList(String[] servers, int defaultPort) { // Eliminate duplicates and sort case-insensitively. This negates operator error // configuring server list with inconsistent order on different Nginx Route Handler clients. // TreeSet provides deduping and sorting. TreeSet<String> tset = new TreeSet<String>(); for (int i = 0; i < servers.length; ++i) { tset.add(servers[i].toLowerCase()); } servers = tset.toArray(new String[0]); if (servers != null) { List<Route> addrs = new ArrayList<Route>(servers.length); for (String server : servers) { if (server.length() == 0) continue; // In case of nginx lookup handlers, there might be additional '/service/extension/nginx-lookup' at the end. // Remove it as the parser expects a server value with hostname:port or just hostname if (defaultPort == DEFAULT_NGINX_HANDLER_PORT) { server = server.replace(urlExtension, ""); ZimbraLog.misc.debug("Lookup server after removing urlExtension " + server); } ZimbraLog.misc.debug("Server before parsing " + server); String[] parts = server.split(":"); if (parts != null) { String host; int port = defaultPort; if (parts.length == 1) { host = parts[0]; } else if (parts.length == 2) { host = parts[0]; try { port = Integer.parseInt(parts[1]); } catch (NumberFormatException e) { ZimbraLog.misc.warn("Invalid server parsing ports " + server); continue; } } else { ZimbraLog.misc.warn("Invalid server " + server + "has %d parts" + parts.length); continue; } Route rt = this.new Route(new InetSocketAddress(host, port), 0); addrs.add(rt); } else { ZimbraLog.misc.warn("Invalid server has null parts" + server); continue; } } return addrs; } else { return new ArrayList<Route>(0); } }
From source file:joshelser.LimitAndSumColumnFamilyIterator.java
private SortedSet<Text> getColumns(Map<String, String> options) { String serializedColumns = options.get(COLUMNS); if (null == serializedColumns) { throw new IllegalArgumentException("Did not find " + COLUMNS + " in the options map"); }//from w w w . ja va2 s.c o m String[] columns = StringUtils.split(serializedColumns, ','); TreeSet<Text> sortedColumns = new TreeSet<Text>(); for (String column : columns) { sortedColumns.add(new Text(column)); } return sortedColumns; }
From source file:com.vaushell.shaarlijavaapi.ShaarliClientTest.java
/** * Test if burst mecanism protects from the same ID generation. */// w w w . j a va2 s . c om @Test public void testBurstMecanism() { final TreeSet<String> tags = new TreeSet<>(); tags.add("java"); tags.add("coding"); clientAuth.createLink("http://fabien.vauchelles.com/1", "Blog de Fabien Vauchelles n1", "Du coooodde rahhh::!!!!! #", tags, false); final TreeSet<String> tags2 = new TreeSet<>(); tags2.add("java"); tags2.add("coding"); clientAuth.createLink("http://fabien.vauchelles.com/2", "Blog de Fabien Vauchelles n2", "Du code, du vrai", tags2, false); assertEquals("2 quick creations can't have the same id (one creation per second)", 2, clientAuth.getLinksCount()); }
From source file:com.fileanalyzer.util.LineStatisticCalculator.java
public FileStatistic getFileStatistic() { FileStatistic fileStatis = new FileStatistic(); fileStatis.setLengthLine(new Long(line.length())); String strArr[] = line.split(regexp); TreeSet<Integer> maxWord = new TreeSet(); TreeSet<Integer> minWord = new TreeSet(); long sumWords = 0; for (int i = 0; i < strArr.length; ++i) { int strSize = strArr[i].length(); sumWords += strSize;/*from w w w .j a v a 2 s . com*/ if (i > 0 && i < strArr.length - 1) maxWord.add(strSize); minWord.add(strSize); } fileStatis.setLine(HtmlUtils.htmlEscape(line)); if (sumWords > 0) { fileStatis.setAvgWord(new Double(sumWords / strArr.length)); fileStatis.setMinWord(new Long(minWord.first())); } if (maxWord.size() > 0) fileStatis.setMaxWord(new Long(maxWord.last())); if (getIdFk() != null) fileStatis.setFileId(getIdFk()); return fileStatis; }
From source file:com.fileanalyzer.util.LineStatisticCalculator.java
public StringBuilder getSqlInsertFileStatistic() { Map<String, Object> params = new HashMap<>(); StringBuilder sql = new StringBuilder("INSERT INTO " + FileStatistic.FileStatisticKey.TABLE + " "); params.put(FileStatisticKey.LENGTHLINE, new Long(line.length())); String strArr[] = line.split(regexp); TreeSet<Integer> maxWord = new TreeSet(); TreeSet<Integer> minWord = new TreeSet(); long sumWords = 0; for (int i = 0; i < strArr.length; ++i) { int strSize = strArr[i].length(); sumWords += strSize;//from w ww. j a va 2s . com if (i > 0 && i < strArr.length - 1) maxWord.add(strSize); minWord.add(strSize); } params.put(FileStatisticKey.LINE, HtmlUtils.htmlEscape(line)); if (sumWords > 0) { params.put(FileStatisticKey.AVGWORD, new Double(sumWords / strArr.length)); params.put(FileStatisticKey.MINWORD, new Long(minWord.first())); } if (maxWord.size() > 0) params.put(FileStatisticKey.MAXWORD, new Long(new Long(maxWord.last()))); if (getIdFk() != null) params.put(FileStatisticKey.FILEID, getIdFk()); genParamAndValues(sql, params); return sql; }
From source file:massbank.api.ApiParameter.java
/** * CGIpp??[^(ID)//from w w w .j ava 2s . c o m */ public String getCgiParamId(String[] ids) { // ID?dr??A\?[g TreeSet<String> tree = new TreeSet<String>(); for (int i = 0; i < ids.length; i++) { tree.add(ids[i]); } String id = "ids="; Iterator it = tree.iterator(); while (it.hasNext()) { id += it.next() + ","; } if (!id.equals("")) { id = id.substring(0, id.length() - 1); } return id; }
From source file:com.vaushell.shaarlijavaapi.ShaarliClientTest.java
/** * Test search term./*from ww w .j a v a 2s . co m*/ */ @Test public void testSearchTerm() { final TreeSet<String> tags = new TreeSet<>(); tags.add("java"); tags.add("coding"); DateTime t = new DateTime(); clientAuth.createOrUpdateLink(t, "http://fabien.vauchelles.com/1", "Blog de Fabien Vauchelles n1", "Du coooodde rahhh::!!!!! #", tags, false); t = t.plusSeconds(1); final TreeSet<String> tags2 = new TreeSet<>(); tags2.add("java"); tags2.add("coding"); clientAuth.createOrUpdateLink(t, "http://fabien.vauchelles.com/2", "Blog de Fabien Vauchelles n2", "Du code, du vrai", tags2, false); assertEquals("2 links should have been created", 2, clientAuth.getLinksCount()); final Iterator<ShaarliLink> it = clientAuth.searchTermIterator("code"); assertTrue("Search should work", it.hasNext()); final ShaarliLink link = it.next(); assertEquals("Search should find the good result", "Blog de Fabien Vauchelles n2", link.getTitle()); }