List of usage examples for java.util LinkedList add
public boolean add(E e)
From source file:annis.gui.exporter.GeneralTextExporter.java
@Override public void convertText(String queryAnnisQL, int contextLeft, int contextRight, Set<String> corpora, String keysAsString, String argsAsString, WebResource annisResource, Writer out) { try {/*from w w w.j a v a 2 s.c om*/ // int count = service.getCount(corpusIdList, queryAnnisQL); SaltProject queryResult = null; LinkedList<String> keys = new LinkedList<String>(); if (keysAsString == null) { // auto set keys.add("tok"); List<AnnisAttribute> attributes = new LinkedList<AnnisAttribute>(); for (String corpus : corpora) { attributes.addAll(annisResource.path("corpora").path(URLEncoder.encode(corpus, "UTF-8")) .path("annotations").queryParam("fetchvalues", "false") .queryParam("onlymostfrequentvalues", "false").get(new AnnisAttributeListType())); } for (AnnisAttribute a : attributes) { if (a.getName() != null) { String[] namespaceAndName = a.getName().split(":", 2); if (namespaceAndName.length > 1) { keys.add(namespaceAndName[1]); } else { keys.add(namespaceAndName[0]); } } } } else { // manually specified String[] keysSplitted = keysAsString.split("\\,"); for (String k : keysSplitted) { keys.add(k.trim()); } } Map<String, String> args = new HashMap<String, String>(); for (String s : argsAsString.split("&")) { String[] splitted = s.split("=", 2); String key = splitted[0]; String val = ""; if (splitted.length > 1) { val = splitted[1]; } args.put(key, val); } final int stepSize = 10; int offset = 0; while (offset == 0 || (queryResult != null && queryResult.getSCorpusGraphs().size() > 0)) { try { queryResult = annisResource.path("search").path("annotate").queryParam("q", queryAnnisQL) .queryParam("limit", "" + stepSize).queryParam("offset", "" + offset) .queryParam("left", "" + contextLeft).queryParam("right", "" + contextRight) .queryParam("corpora", StringUtils.join(corpora, ",")).get(SaltProject.class); } catch (UniformInterfaceException ex) { log.error(ex.getResponse().getEntity(String.class), ex); } convertText(LegacyGraphConverter.convertToResultSet(queryResult), keys, args, out, offset); out.flush(); offset += stepSize; } out.append("\n"); out.append("\n"); out.append("finished"); } catch (AnnisQLSemanticsException ex) { log.error(null, ex); } catch (AnnisQLSyntaxException ex) { log.error(null, ex); } catch (AnnisCorpusAccessException ex) { log.error(null, ex); } catch (RemoteException ex) { log.error(null, ex); } catch (IOException ex) { log.error(null, ex); } }
From source file:annis.sqlgen.GraphWithClauseGenerator.java
@Override protected String getMatchesWithClause(QueryData queryData, List<QueryNode> alternative, String indent) { TableAccessStrategy tas = createTableAccessStrategy(); StringBuilder sb = new StringBuilder(); String indent2 = indent + TABSTOP; List<AnnotateQueryData> extensions = queryData.getExtensions(AnnotateQueryData.class); AnnotateQueryData annotateQueryData = extensions.isEmpty() ? new AnnotateQueryData(5, 5) : extensions.get(0);/*ww w . j a va2s .co m*/ List<SaltURIGroupSet> listOfSaltURIs = queryData.getExtensions(SaltURIGroupSet.class); // only work with the first element Validate.isTrue(!listOfSaltURIs.isEmpty()); SaltURIGroupSet saltURIs = listOfSaltURIs.get(0); sb.append(indent).append("matches AS\n"); sb.append(indent).append("(\n"); LinkedList<String> clauses = new LinkedList<String>(); for (Map.Entry<Integer, SaltURIGroup> e : saltURIs.getGroups().entrySet()) { clauses.add( indent2 + "(\n" + singleMatchClause(e.getKey(), e.getValue().getUris(), tas, annotateQueryData, queryData.getCorpusList(), alternative.size(), indent2 + TABSTOP) + indent2 + ")\n"); } String seperator = indent2 + "UNION ALL\n"; sb.append(StringUtils.join(clauses, seperator)); // end WITH inner select sb.append(indent).append(")"); return sb.toString(); }
From source file:eu.morfeoproject.fast.catalogue.planner.ScreenPlanner.java
/** * Creates a list of plans//from ww w . j a va2s . co m * @param goal * @param screens * @return list of plans */ public List<Plan> searchPlans(URI goal, List<Screen> screens) { LinkedList<URI> uriList = new LinkedList<URI>(); for (Screen screen : screens) { uriList.add(screen.getUri()); } LinkedList<Plan> planList = new LinkedList<Plan>(); List<Plan> searchList = searchPlans(goal); planList.addAll(rankList(searchList, uriList)); return reverse(removeDuplicates(planList, uriList)); }
From source file:bigfat.hadoop.HDFSDirInputStream.java
/** * Create a input stream that will read through all the files in one * directory note that the file will be sorted by name, using the * comparator.//from ww w . ja v a 2s . c o m * * @param fs * @param dir * @param comp * @throws IOException */ public HDFSDirInputStream(FileSystem fs, String dir, Comparator<String> comp) throws IOException { this.fs = fs; Path p = new Path(dir); FileStatus fstate = fs.getFileStatus(p); if (fstate.isDir()) { FileStatus[] child = fs.globStatus(new Path(dir + "/*")); LinkedList<String> s = new LinkedList<String>(); Map<String, Path> map = new HashMap<String, Path>(); for (FileStatus c : child) { if (c.isDir()) continue; map.put(c.getPath().getName(), c.getPath()); s.add(c.getPath().getName()); } if (comp != null) Collections.sort(s, comp); else Collections.sort(s); Iterator<String> it = s.iterator(); while (it.hasNext()) { String n = it.next(); Path pr = map.get(n); this.appendFile(pr.toString()); } } else { this.appendFile(dir); } }
From source file:edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.BrowseDataGetter.java
private Map<String, Object> getCommonValues(ServletContext context, VitroRequest vreq) { Map<String, Object> values = new HashMap<String, Object>(); VClassGroupCache vcgc = VClassGroupCache.getVClassGroupCache(context); List<VClassGroup> cgList = vcgc.getGroups(); LinkedList<VClassGroupTemplateModel> cgtmList = new LinkedList<VClassGroupTemplateModel>(); for (VClassGroup classGroup : cgList) { cgtmList.add(new VClassGroupTemplateModel(classGroup)); }// w w w. j ava 2s. co m values.put("vClassGroups", cgtmList); return values; }
From source file:com.appeligo.search.actions.ProgramRemindersPageAction.java
public String execute() throws Exception { //sort programs alphabetically and by programId programAlerts = new LinkedList<ProgramAlert>(getUser().getLiveProgramAlerts()); Collections.sort(programAlerts, new Comparator<ProgramAlert>() { public int compare(ProgramAlert left, ProgramAlert right) { String leftStr = left.getProgram().getLabel(); String rightStr = right.getProgram().getLabel(); int rtn = leftStr.compareTo(rightStr); if (rtn == 0 && left.getProgramId() != null && right.getProgramId() != null) { rtn = left.getProgramId().compareTo(right.getProgramId()); }//from w w w . j av a2 s . co m return rtn; } }); //ensure that programAlerts on matching programs are clustered together LinkedList<ProgramAlert> newlist = new LinkedList<ProgramAlert>(); while (programAlerts.size() > 0) { ProgramAlert alert = programAlerts.remove(0); newlist.add(alert); String targetId = alert.getProgramId(); int j = 0; while (j < programAlerts.size()) { if (programAlerts.get(j).getProgramId().equals(targetId)) { newlist.add(programAlerts.remove(j)); } else { j++; } } } programAlerts = newlist; AlertManager alertManager = AlertManager.getInstance(); EPGProvider epgProvider = alertManager.getEpg(); String lineup = getUser().getLineupId(); nextAiringList = new LinkedList<ScheduledProgram>(); String previousTargetId = null; for (ProgramAlert programAlert : programAlerts) { String targetId = programAlert.getProgramId(); if (!targetId.equals(previousTargetId)) { ScheduledProgram nextAiring = null; if (programAlert.isNewEpisodes()) { nextAiring = epgProvider.getNextShowing(lineup, programAlert.getProgramId(), true, true); } if (nextAiring == null) { nextAiring = epgProvider.getNextShowing(lineup, programAlert.getProgramId(), false, true); } nextAiringList.add(nextAiring); previousTargetId = targetId; } else { nextAiringList.add(null); } } return SUCCESS; }
From source file:hu.ppke.itk.nlpg.purepos.cli.configuration.ConfigurationReader.java
public Configuration read(File f) throws ConfigurationException { XMLConfiguration xconf = new XMLConfiguration(f); List<ConfigurationNode> tagMappings = xconf.getRootNode().getChildren(TAG_MAPPING); LinkedList<StringMapping> tag_ret = new LinkedList<StringMapping>(); for (ConfigurationNode m : tagMappings) { String spat = (String) m.getAttributes(PATTERN).get(0).getValue(); String stag = (String) m.getAttributes(TAG).get(0).getValue(); tag_ret.add(new StringMapping(spat, stag)); }//from www .j a v a 2s.c o m List<ConfigurationNode> lemmaMappings = xconf.getRootNode().getChildren(LEMMA_MAPPING); LinkedList<StringMapping> lemma_ret = new LinkedList<StringMapping>(); for (ConfigurationNode m : lemmaMappings) { String spat = (String) m.getAttributes(PATTERN).get(0).getValue(); String stag = (String) m.getAttributes(TAG).get(0).getValue(); lemma_ret.add(new StringMapping(spat, stag)); } List<ConfigurationNode> markers = xconf.getRootNode().getChildren(GUESSED_MARKER); String guessedMarker = ""; if (markers.size() > 0) { guessedMarker = (String) markers.get(0).getValue(); } List<ConfigurationNode> params = xconf.getRootNode().getChildren(SUFFIX_MODEL_PARAMETERS); Double weight = null; if (params.size() > 0) { weight = Double.valueOf((String) params.get(0).getValue()); } return new Configuration(tag_ret, lemma_ret, guessedMarker, weight); }
From source file:com.github.nethad.clustermeister.provisioning.torque.ConfigurationForTesting.java
@Override public List<Object> getList(String key, List<Object> defaultValue) { LinkedList<Object> list = new LinkedList<Object>(); Object value = configValues.get(key); if (value != null) { list.add(configValues.get(key)); }//from w ww . j a v a 2s .c o m return list; }
From source file:edu.cmu.sphinx.speakerid.SpeakerIdentification.java
/** * //w w w . j a va2 s . co m * @param features * Matrix with feature vectors as rows * @return A list with all changing points detected in the file */ private LinkedList<Integer> getAllChangingPoints(Array2DRowRealMatrix features) { LinkedList<Integer> ret = new LinkedList<Integer>(); ret.add(0); int framesCount = features.getRowDimension(), step = 500; int start = 0, end = step, cp; while (end < framesCount) { cp = getPoint(start, end - start + 1, step / 10, features); if (cp > 0) { start = cp; end = start + step; ret.add(cp); } else end += step; } ret.add(framesCount); return ret; }
From source file:net.doubledoordev.backend.server.FileManager.java
public Collection<File> makeBreadcrumbs() { LinkedList<File> list = new LinkedList<>(); File crumb = file;/*w w w. j a va2s . c o m*/ while (!crumb.equals(serverFolder)) { list.add(crumb); crumb = crumb.getParentFile(); } list.add(serverFolder); Collections.reverse(list); return list; }