List of usage examples for java.util LinkedList add
public boolean add(E e)
From source file:eu.morfeoproject.fast.catalogue.planner.CataloguePlanner.java
public List<Plan> searchPlans(URI from, URI to) { LinkedList<Plan> planList = new LinkedList<Plan>(); AllSimplePaths<URI> all = new AllSimplePaths<URI>(graph); for (List<URI> path : all.findAllPaths(from, to)) { Plan plan = new Plan(); for (URI node : path) { plan.getUriList().add(node); }/*from w w w .j a v a2s . c o m*/ planList.add(plan); } return planList; }
From source file:de.fau.cs.osr.hddiff.perfsuite.EditScriptAnalysis.java
private Object printNodeStatsByOp(GenericEditOp needle) { HashSet<String> tmp = new HashSet<>(editsByLabel.keySet()); tmp.remove(null);//from w w w . j a v a 2 s. c o m LinkedList<String> keys = new LinkedList<>(tmp); Collections.sort(keys); keys.add(null); StringBuilder b = new StringBuilder(); b.append(String.format(" %s by label:\n", needle)); boolean empty = true; for (String key : keys) { int count = 0; List<Edit> ops = editsByLabel.get(key); if (ops != null) for (Edit op : ops) { if (op.op == needle) ++count; } if (count > 0) { empty = false; if (key == null) key = "#text"; String paddedKey = StringUtils.rightPad(StringUtils.abbreviate(key, 16) + ":", 17); b.append(String.format(" %s %4d\n", paddedKey, count)); } } return empty ? "" : b.toString(); }
From source file:de.tudarmstadt.ukp.lmf.transform.germanet.GNConverter.java
/** * Converts the informations provided by the initialized {@link GermaNet} object to LMF-format. <br> * The result of the conversion can be obtained by calling {@link GNConverter#getLexicalResource()} *///from w w w. jav a 2 s. co m public void toLMF() { // Setting attributes of LexicalResource lexicalResource.setName("GermaNet"); lexicalResource.setDtdVersion(dtd_version); // *** Setting GlobalInformation *** // GlobalInformation globalInformation = new GlobalInformation(); globalInformation.setLabel("LMF representation of GermaNet 7.0"); lexicalResource.setGlobalInformation(globalInformation); //*** Setting Lexicon (only one since GermaNet is monolingual)***// Lexicon lexicon = new Lexicon(); lexicon.setLanguageIdentifier(ELanguageIdentifier.GERMAN); lexicon.setId("GN_Lexicon_0"); lexicon.setName("GermaNet"); LinkedList<Lexicon> lexicons = new LinkedList<Lexicon>(); lexicons.add(lexicon); lexicalResource.setLexicons(lexicons); // *** Creating LexicalEntries *** // logger.info("Generating LexicalEntries..."); this.groupLUs(); LexicalEntryGenerator leGen = new LexicalEntryGenerator(this, resourceVersion); List<LexicalEntry> lexicalEntries = new LinkedList<LexicalEntry>(); // Create a LexicalEntry for each luGroup for (Set<LexUnit> luGroup : luGroups) { lexicalEntries.add(leGen.createLexicalEntry(luGroup)); } // Setting RelatedForms of LexicalEntries for (LexicalEntry lexicalEntry : lexicalEntries) { leGen.setRelatedForms(lexicalEntry); } // appending lexicalEntries lexicon.setLexicalEntries(lexicalEntries); StringBuffer sb = new StringBuffer(64); sb.append("Generated LexicalEntries: ").append(lexicalEntries.size()); logger.info(sb.toString()); int noVerbs = 0; int noVerbSenses = 0; for (LexicalEntry le : lexicalEntries) { if (le.getPartOfSpeech().equals(EPartOfSpeech.verb)) { noVerbs++; noVerbSenses = noVerbSenses + le.getSenses().size(); } } sb = new StringBuffer(128); sb.append("Generated verb lemmas: ").append(noVerbs).append('\n'); sb.append("Generated verb senses: ").append(noVerbSenses); logger.info(sb.toString()); // *** Appending SubcategorizationFrames *** // lexicon.setSubcategorizationFrames(subcategorizationFrameExtractor.getSubcategorizationFrames()); // *** Appending SemanticPredicates *** // lexicon.setSemanticPredicates(subcategorizationFrameExtractor.getSemanticPredicates()); // *** Appending Synsets *** // synsetGenerator.initialize(); List<Synset> synsets = synsetGenerator.getSynsets(); lexicon.setSynsets(synsets); sb = new StringBuffer(64); sb.append("Generated synsets: ").append(synsets.size()); logger.info(sb.toString()); // *** Appending SynSemCorrespondences *** // lexicon.setSynSemCorrespondences(subcategorizationFrameExtractor.getSynSemCorrespondences()); }
From source file:com.voidsearch.data.provider.facebook.SimpleGraphAPIClient.java
/** * load result list from json response for given feed * * @param results//ww w . j a v a2 s. co m * @param resultArray * @param feedName * @param <T> * @throws Exception */ private <T> void loadResults(LinkedList<T> results, JSONArray resultArray, String feedName) throws Exception { for (int i = 0; i < resultArray.length(); i++) { results.add((T) GraphObjectFactory.getObject(feedName, (JSONObject) resultArray.get(i))); } }
From source file:org.wildfly.test.integration.microprofile.config.smallrye.app.MicroProfileConfigTestCase.java
/** * Check String array, List and Set properties are correctly handled in regards of the default values. * * @throws Exception//from w ww. ja v a 2 s . c o m */ @Test public void testGetWithArraySetListDefaultProperties() throws Exception { try (CloseableHttpClient client = HttpClientBuilder.create().build()) { HttpResponse response = client .execute(new HttpGet(url + appContext + TestApplication.ARRAY_SET_LIST_DEFAULT_APP_PATH)); Assert.assertEquals(200, response.getStatusLine().getStatusCode()); String text = getContent(response); LinkedList<String> petsList = new LinkedList<>(); petsList.add("cat"); petsList.add("lama,yokohama"); Set<String> petsSet = new HashSet<>(); petsSet.add("dog"); petsSet.add("mouse,house"); assertTextContainsProperty(text, "myPets as String array", Arrays.toString(new String[] { "horse", "monkey,donkey" })); assertTextContainsProperty(text, "myPets as String list", petsList); assertTextContainsProperty(text, "myPets as String set", petsSet); // TODO - not sure whether this is safe as Set doesn't assure order? } }
From source file:org.wildfly.test.integration.microprofile.config.smallrye.app.MicroProfileConfigTestCase.java
/** * Check String array, List and Set properties are correctly handled if their default values are overridden. * * @throws Exception//from w w w .j av a2 s . co m */ @Test public void testGetWithArraySetListOverriddenProperties() throws Exception { try (CloseableHttpClient client = HttpClientBuilder.create().build()) { HttpResponse response = client .execute(new HttpGet(url + appContext + TestApplication.ARRAY_SET_LIST_OVERRIDE_APP_PATH)); Assert.assertEquals(200, response.getStatusLine().getStatusCode()); String text = getContent(response); LinkedList<String> petsList = new LinkedList<>(); petsList.add("donkey"); petsList.add("shrek,fiona"); Set<String> petsSet = new HashSet<>(); petsSet.add("donkey"); petsSet.add("shrek,fiona"); assertTextContainsProperty(text, "myPetsOverridden as String array", Arrays.toString(new String[] { "donkey", "shrek,fiona" })); assertTextContainsProperty(text, "myPetsOverridden as String list", petsList); assertTextContainsProperty(text, "myPetsOverridden as String set", petsSet); // TODO - not sure whether this is safe as Set doesn't assure order? // Assert.assertTrue(text.contains("myPetsOverridden as String set = [donkey,shrek]") || text.contains("myPetsOverridden as String set = [shrek,donkey]")); } }
From source file:com.espertech.esper.epl.core.ResultSetProcessorSimple.java
/** * Applies the select-clause to the given events returning the selected events. The number of events stays the * same, i.e. this method does not filter it just transforms the result set. * <p>//from w w w . java 2 s . co m * Also applies a having clause. * @param exprProcessor - processes each input event and returns output event * @param orderByProcessor - for sorting output events according to the order-by clause * @param events - input events * @param optionalHavingNode - supplies the having-clause expression * @param isNewData - indicates whether we are dealing with new data (istream) or old data (rstream) * @param isSynthesize - set to true to indicate that synthetic events are required for an iterator result set * @param exprEvaluatorContext context for expression evalauation * @return output events, one for each input event */ protected static EventBean[] getSelectEventsHaving(SelectExprProcessor exprProcessor, OrderByProcessor orderByProcessor, Set<MultiKey<EventBean>> events, ExprEvaluator optionalHavingNode, boolean isNewData, boolean isSynthesize, ExprEvaluatorContext exprEvaluatorContext) { if ((events == null) || (events.isEmpty())) { return null; } LinkedList<EventBean> result = new LinkedList<EventBean>(); List<EventBean[]> eventGenerators = null; if (orderByProcessor != null) { eventGenerators = new ArrayList<EventBean[]>(); } for (MultiKey<EventBean> key : events) { EventBean[] eventsPerStream = key.getArray(); Boolean passesHaving = (Boolean) optionalHavingNode.evaluate(eventsPerStream, isNewData, exprEvaluatorContext); if ((passesHaving == null) || (!passesHaving)) { continue; } EventBean resultEvent = exprProcessor.process(eventsPerStream, isNewData, isSynthesize, exprEvaluatorContext); result.add(resultEvent); if (orderByProcessor != null) { eventGenerators.add(eventsPerStream); } } if (!result.isEmpty()) { if (orderByProcessor != null) { return orderByProcessor.sort(result.toArray(new EventBean[result.size()]), eventGenerators.toArray(new EventBean[eventGenerators.size()][]), isNewData, exprEvaluatorContext); } else { return result.toArray(new EventBean[result.size()]); } } else { return null; } }
From source file:com.k42b3.aletheia.protocol.http.Response.java
public Response(HttpResponse response) throws Exception { super(response.getEntity() != null ? EntityUtils.toByteArray(response.getEntity()) : null); this.response = response; // get response line this.setLine(response.getStatusLine().toString()); // set headers LinkedList<Header> header = new LinkedList<Header>(); Header[] headers = response.getAllHeaders(); for (int i = 0; i < headers.length; i++) { header.add(headers[i]); }// w w w . jav a 2s.co m this.setHeaders(header); // read body if (this.content != null) { Charset charset = this.detectCharset(); String body = ""; if (charset != null) { body = new String(this.getContent(), charset); } else { if (this.isBinary()) { body = this.toHexdump(); } else { body = new String(this.getContent(), Charset.forName("UTF-8")); } } this.setBody(body); } else { this.setBody(""); } }
From source file:br.com.edu.dbpediaspotlight.db.java
public List<DBpediaResource> extract(Text text) throws AnnotationException { LOG.info("Querying API."); String spotlightResponse;//from w ww .j av a 2s . co m try { String Query = API_URL + "rest/annotate/?" + "confidence=" + CONFIDENCE + "&support=" + SUPPORT + "&spotter=Default" + "&disambiguator=" + disambiguator + "&showScores=" + showScores + "&powered_by=" + powered_by + "&text=" + URLEncoder.encode(text.text(), "utf-8"); LOG.info(Query); GetMethod getMethod = new GetMethod(Query); getMethod.addRequestHeader(new Header("Accept", "application/json")); spotlightResponse = request(getMethod); } catch (UnsupportedEncodingException e) { throw new AnnotationException("Could not encode text.", e); } assert spotlightResponse != null; JSONObject resultJSON = null; JSONArray entities = null; try { resultJSON = new JSONObject(spotlightResponse); entities = resultJSON.getJSONArray("Resources"); } catch (JSONException e) { throw new AnnotationException("Received invalid response from DBpedia Spotlight API."); } LinkedList<DBpediaResource> resources = new LinkedList<DBpediaResource>(); if (entities != null) for (int i = 0; i < entities.length(); i++) { try { JSONObject entity = entities.getJSONObject(i); resources.add(new DBpediaResource(entity.getString("@URI"), Integer.parseInt(entity.getString("@support")))); } catch (JSONException e) { LOG.error("JSON exception " + e); } } return resources; }
From source file:com.googlecode.datasourcetester.server.DataSourceTesterServiceImpl.java
public String[][] queryDataSource(String dataSourceJndiName, String query) { Connection conn = null;/*from ww w .ja v a 2 s. c o m*/ try { InitialContext jndiContext = new InitialContext(); DataSource ds = (DataSource) jndiContext.lookup(dataSourceJndiName); conn = ds.getConnection(); PreparedStatement stmt = conn.prepareStatement(query); ResultSet rs = stmt.executeQuery(); ResultSetMetaData resMeta = rs.getMetaData(); LinkedList<String[]> rowList = new LinkedList<String[]>(); String[] colLabels = new String[resMeta.getColumnCount()]; for (int colNr = 1; colNr <= resMeta.getColumnCount(); colNr++) { colLabels[colNr - 1] = resMeta.getColumnName(colNr); } rowList.add(colLabels); while (rs.next()) { String[] rowData = new String[resMeta.getColumnCount()]; for (int colNr = 1; colNr <= resMeta.getColumnCount(); colNr++) { rowData[colNr - 1] = rs.getString(colNr); } rowList.add(rowData); } conn.close(); return rowList.toArray(new String[rowList.size()][]); } catch (Exception e) { logger.error(e.getMessage(), e); try { if (conn != null && !conn.isClosed()) { conn.close(); } } catch (SQLException sqlEx) { logger.error(sqlEx.getMessage(), sqlEx); } return null; } }