List of usage examples for java.util ArrayList contains
public boolean contains(Object o)
From source file:gr.demokritos.iit.cru.creativity.reasoning.semantic.ThinkingSeedGenerator.java
public static String ThinkingSeedGenerator(String seed, int difficulty, String language) throws ClassNotFoundException, SQLException, IOException, InstantiationException, IllegalAccessException {/* w w w . j av a 2 s . c o m*/ ArrayList<String> mined = new ArrayList<String>(); Connect c = new Connect(language); RandomWordGenerator r = new RandomWordGenerator(c); String randomPhrase = r.selectRandomWord(seed, difficulty); int size = randomPhrase.split(",").length; Random rand = new Random(); if (language.equalsIgnoreCase("en")) { while (mined.size() < size) { int Point = rand.nextInt(1172);//number of words in english thesaurus String word = FileUtils.readLines(new File(c.getEnglish_thes())).get(Point).trim(); if (mined.contains(word)) {//|| inf.getStop().contains(word)) { continue; } mined.add(word); } } else if (language.equalsIgnoreCase("de")) { while (mined.size() < size) { int Point = rand.nextInt(1704);//number of words in german thesaurus String word = FileUtils.readLines(new File(c.getGerman_thes())).get(Point).trim(); if (mined.contains(word)) { continue; } mined.add(word); } } else { while (mined.size() < size) { int Point = rand.nextInt(933);//number of words in greek thesaurus String word = FileUtils.readLines(new File(c.getGreek_thes())).get(Point).trim(); if (mined.contains(word)) { continue; } mined.add(word); } } c.CloseConnection(); return StringUtils.join(mined, ","); }
From source file:com.icesoft.faces.facelets.D2DFaceletViewHandler.java
/** * Do the least amount of work to find if there are any duplicate ids, * with the assumption being that we won't typically find any * We also mention any null ids, just to be safe * * @param comp UIComponent to recurse down through, searching for * duplicate ids./*from www .j a va 2s .c om*/ * @param ids HashMap<String id, String id> allows for detecting * if an id has already been encountered or not * @param duplicateIds ArrayList<String id> duplicate ids encountered * as we recurse down */ private static void quicklyDetectDuplicateComponentIds(UIComponent comp, HashMap ids, ArrayList duplicateIds) { String id = comp.getId(); if (id == null) { log.debug("UIComponent has null id: " + comp); } else { if (ids.containsKey(id)) { if (!duplicateIds.contains(id)) duplicateIds.add(id); } else { ids.put(id, id); } } Iterator children = comp.getFacetsAndChildren(); while (children.hasNext()) { UIComponent child = (UIComponent) children.next(); quicklyDetectDuplicateComponentIds(child, ids, duplicateIds); } }
From source file:info.varden.anatychia.Main.java
private static File[] listRegionContainers(File base) { ArrayList<File> ret = new ArrayList<File>(); File[] contents = base.listFiles(); for (File f : contents) { if (f.isDirectory()) { ret.addAll(Arrays.asList(listRegionContainers(f))); } else {/*w w w .ja va2 s . c om*/ if (f.getName().endsWith(".mca") && !ret.contains(base)) { ret.add(base); } } } return ret.toArray(new File[0]); }
From source file:gov.nih.nci.rembrandt.web.helper.PCAAppletHelper.java
public static String generateParams(String sessionId, String taskId) { String htm = ""; DecimalFormat nf = new DecimalFormat("0.0000"); try {//from ww w. j a va2s. c o m //retrieve the Finding from cache and build the list of PCAData points PrincipalComponentAnalysisFinding principalComponentAnalysisFinding = (PrincipalComponentAnalysisFinding) businessTierCache .getSessionFinding(sessionId, taskId); ArrayList<PrincipalComponentAnalysisDataPoint> pcaData = new ArrayList(); Collection<ClinicalFactorType> clinicalFactors = new ArrayList<ClinicalFactorType>(); List<String> sampleIds = new ArrayList(); Map<String, PCAresultEntry> pcaResultMap = new HashMap<String, PCAresultEntry>(); List<PCAresultEntry> pcaResults = principalComponentAnalysisFinding.getResultEntries(); for (PCAresultEntry pcaEntry : pcaResults) { sampleIds.add(pcaEntry.getSampleId()); pcaResultMap.put(pcaEntry.getSampleId(), pcaEntry); } Collection<SampleResultset> validatedSampleResultset = ClinicalDataValidator .getValidatedSampleResultsetsFromSampleIDs(sampleIds, clinicalFactors); if (validatedSampleResultset != null) { String id; PCAresultEntry entry; for (SampleResultset rs : validatedSampleResultset) { id = rs.getBiospecimen().getSpecimenName(); entry = pcaResultMap.get(id); PrincipalComponentAnalysisDataPoint pcaPoint = new PrincipalComponentAnalysisDataPoint(id, entry.getPc1(), entry.getPc2(), entry.getPc3()); String diseaseName = rs.getDisease().getValueObject(); if (diseaseName != null) { pcaPoint.setDiseaseName(diseaseName); } else { pcaPoint.setDiseaseName(DiseaseType.NON_TUMOR.name()); } GenderDE genderDE = rs.getGenderCode(); if (genderDE != null) { String gt = genderDE.getValueObject(); if (gt != null) { GenderType genderType = GenderType.valueOf(gt); if (genderType != null) { pcaPoint.setGender(genderType); } } } Long survivalLength = rs.getSurvivalLength(); if (survivalLength != null) { //survival length is stored in days in the DB so divide by 30 to get the //approx survival in months double survivalInMonths = survivalLength.doubleValue() / 30.0; pcaPoint.setSurvivalInMonths(survivalInMonths); } pcaData.add(pcaPoint); } } //make a hashmap // [key=group] hold the array of double[][]s HashMap<String, ArrayList> hm = new HashMap(); //now we should have a collection of PCADataPts double[][] pts = new double[pcaData.size()][3]; for (int i = 0; i < pcaData.size(); i++) { //just create a large 1 set for now //are we breaking groups by gender or disease? PrincipalComponentAnalysisDataPoint pd = pcaData.get(i); pts[i][0] = pd.getPc1value(); pts[i][1] = pd.getPc2value(); pts[i][2] = pd.getPc3value(); ArrayList<double[]> al; try { if (hm.containsKey(pd.getDiseaseName())) { //already has it, so add this one al = (ArrayList) hm.get(pd.getDiseaseName()); } else { al = new ArrayList(); hm.put(pd.getDiseaseName(), new ArrayList()); } if (!al.contains(pts[i])) { al.add(pts[i]); } hm.put(pd.getDiseaseName(), al); } catch (Exception e) { System.out.print(e.toString()); } } int r = hm.size(); if (r == 1) { } //hm should now contain a hashmap of all the disease groups //generate the param tags htm += "<param name=\"key\" value=\"" + taskId + "\" >\n"; htm += "<param name=\"totalPts\" value=\"" + pts.length + "\" >\n"; htm += "<param name=\"totalGps\" value=\"" + hm.size() + "\" >\n"; int ii = 0; for (Object k : hm.keySet()) { String key = k.toString(); //for each group Color diseaseColor = Color.GRAY; if (DiseaseType.valueOf(key) != null) { DiseaseType disease = DiseaseType.valueOf(key); diseaseColor = disease.getColor(); } ArrayList<double[]> al = hm.get(key); htm += "<param name=\"groupLabel_" + ii + "\" value=\"" + key + "\" >\n"; htm += "<param name=\"groupCount_" + ii + "\" value=\"" + al.size() + "\" >\n"; htm += "<param name=\"groupColor_" + ii + "\" value=\"" + diseaseColor.getRGB() + "\" >\n"; int jj = 0; for (double[] d : al) { String comm = nf.format(d[0]) + "," + nf.format(d[1]) + "," + nf.format(d[2]); String h = "<param name=\"pt_" + ii + "_" + jj + "\" value=\"" + comm + "\">\n"; htm += h; jj++; } ii++; } /* //for bulk rendering for(int i=0; i<pts.length; i++) { String comm = String.valueOf(pts[i][0]) + "," + String.valueOf(pts[i][1]) + "," + String.valueOf(pts[i][2]); String h = "<param name=\"pt_"+i+"\" value=\""+ comm +"\">\n"; //htm += h; } */ } //try catch (Exception e) { } return htm; }
From source file:com.nuance.expertassistant.ContentExtractor.java
public static void extract(Document doc) { final Elements links = doc.getElementsByTag("a"); final Elements ps = doc.select("p"); final String title = doc.title(); print("<section id =\"{}\" title =\"" + stripNonValidXMLCharacters(doc.title()) + "\">"); final Elements elements = doc.select("*"); final ArrayList<String> openHeaderList = new ArrayList<String>(); for (final Element element : elements) { if (element.ownText() == null || element.ownText().isEmpty() || element.ownText().trim() == "") { } else if (element.tagName().toString().contains("a")) { } else if (element.tagName().contains("h1") && element.text() != null && !element.text().isEmpty()) { if (openHeaderList.contains("h1")) { openHeaderList.remove("h1"); print("</section>"); }/*from w w w .j a va 2 s . com*/ if (openHeaderList.contains("h2")) { openHeaderList.remove("h2"); print("</section>"); } if (openHeaderList.contains("h3")) { openHeaderList.remove("h3"); print("</section>"); } if (openHeaderList.contains("h4")) { openHeaderList.remove("h4"); print("</section>"); } print("<section id =\"{}\" title =\"" + stripNonValidXMLCharacters(element.text()) + "\">"); openHeaderList.add("h1"); } else if (element.tagName().contains("h2") && element.text() != null && !element.text().isEmpty()) { if (openHeaderList.contains("h2")) { openHeaderList.remove("h2"); print("</section>"); } if (openHeaderList.contains("h3")) { openHeaderList.remove("h3"); print("</section>"); } if (openHeaderList.contains("h4")) { openHeaderList.remove("h4"); print("</section>"); } print("<section id =\"{}\" title =\"" + stripNonValidXMLCharacters(element.text()) + "\">"); openHeaderList.add("h2"); } else if (element.tagName().contains("h3") && element.text() != null && !element.text().isEmpty()) { if (openHeaderList.contains("h3")) { openHeaderList.remove("h3"); print("</section>"); } if (openHeaderList.contains("h4")) { openHeaderList.remove("h4"); print("</section>"); } print("<section id =\"{}\" title =\"" + stripNonValidXMLCharacters(element.text()) + "\">"); openHeaderList.add("h3"); } else if (element.tagName().contains("h4") && element.text() != null && !element.text().isEmpty()) { if (openHeaderList.contains("h4")) { openHeaderList.remove("h4"); print("</section>"); } print("<section id =\"{}\" title =\"" + stripNonValidXMLCharacters(element.text()) + "\">"); openHeaderList.add("h4"); } else { print("<para>"); print(stripNonValidXMLCharacters(element.ownText())); print("</para>"); } /* * if (element.tagName().contains("img")) { print("<img src=\"" + * element.attr("src") + "\"></img>"); } */ } if (openHeaderList.contains("h1")) { openHeaderList.remove("h1"); print("</section>"); } if (openHeaderList.contains("h2")) { openHeaderList.remove("h2"); print("</section>"); } if (openHeaderList.contains("h3")) { openHeaderList.remove("h3"); print("</section>"); } if (openHeaderList.contains("h4")) { openHeaderList.remove("h4"); print("</section>"); } print("</section>"); }
From source file:com.deliciousdroid.platform.ContactManager.java
/** * Add a list of status messages to the contacts provider. * /*ww w.ja v a2 s.c o m*/ * @param context the context to use * @param accountName the username of the logged in user * @param statuses the list of statuses to store */ public static void insertStatuses(Context context, String username, List<User.Status> list) { final ContentValues values = new ContentValues(); final ContentResolver resolver = context.getContentResolver(); final ArrayList<String> processedUsers = new ArrayList<String>(); final BatchOperation batchOperation = new BatchOperation(context, resolver); for (final User.Status status : list) { // Look up the user's sample SyncAdapter data row final String userName = status.getUserName(); if (!processedUsers.contains(userName)) { final long profileId = lookupProfile(resolver, userName); // Insert the activity into the stream if (profileId > 0) { values.put(StatusUpdates.DATA_ID, profileId); values.put(StatusUpdates.STATUS, status.getStatus()); values.put(StatusUpdates.PROTOCOL, Im.PROTOCOL_CUSTOM); values.put(StatusUpdates.CUSTOM_PROTOCOL, CUSTOM_IM_PROTOCOL); values.put(StatusUpdates.IM_ACCOUNT, username); values.put(StatusUpdates.IM_HANDLE, status.getUserName()); values.put(StatusUpdates.STATUS_TIMESTAMP, status.getTimeStamp().getTime()); values.put(StatusUpdates.STATUS_RES_PACKAGE, context.getPackageName()); values.put(StatusUpdates.STATUS_ICON, R.drawable.ic_main); values.put(StatusUpdates.STATUS_LABEL, R.string.label); batchOperation.add(ContactOperations.newInsertCpo(StatusUpdates.CONTENT_URI, true) .withValues(values).build()); // A sync adapter should batch operations on multiple contacts, // because it will make a dramatic performance difference. if (batchOperation.size() >= 50) { batchOperation.execute(); } } processedUsers.add(userName); } } batchOperation.execute(); }
From source file:fr.simon.marquis.preferencesmanager.util.Utils.java
public static ArrayList<String> findXmlFiles(final String packageName) { Log.d(TAG, String.format("findXmlFiles(%s)", packageName)); final ArrayList<String> files = new ArrayList<String>(); CommandCapture cmd = new CommandCapture(CMD_FIND_XML_FILES.hashCode(), false, String.format(CMD_FIND_XML_FILES, packageName)) { @Override//from w w w. j av a2 s. co m public void commandOutput(int i, String s) { if (!files.contains(s)) { files.add(s); } } }; synchronized (cmd) { try { RootTools.getShell(true).add(cmd).wait(); } catch (Exception e) { Log.e(TAG, "Error in findXmlFiles", e); } } Log.d(TAG, "files: " + Arrays.toString(files.toArray())); return files; }
From source file:exm.stc.ic.ICUtil.java
public static void replaceVarsInList(Map<Var, Arg> replacements, List<Var> vars, boolean removeDupes, boolean removeMapped) { // Remove new duplicates ArrayList<Var> alreadySeen = null; if (removeDupes) { alreadySeen = new ArrayList<Var>(vars.size()); }//w w w .ja v a2 s .c om ListIterator<Var> it = vars.listIterator(); while (it.hasNext()) { Var v = it.next(); if (replacements.containsKey(v)) { Arg oa = replacements.get(v); if (oa.isVar()) { if (removeDupes && alreadySeen.contains(oa.getVar())) { it.remove(); } else { it.set(oa.getVar()); if (removeDupes) { alreadySeen.add(oa.getVar()); } } } } else { if (removeDupes) { if (alreadySeen.contains(v)) { it.remove(); } else { alreadySeen.add(v); } } } } }
From source file:net.henryco.opalette.application.programs.sub.programs.bFilter.EdFilter.java
private static List<EdFilter> loadFilterListFromJSON() { /*// ww w . j a v a 2 s . co m { "type": "t255" | "t01" , "filters": [{ "name": "filter1", "color": "#FFFFFFFF", "contrast": "0", "gamma": "1", "hue": "0", "saturation": "0", "lightness": "0", "bw": "false", "min": ["0", "0", "0"], "max": ["255", "255", "255"], "add": ["0", "0", "0"] }] } */ List<EdFilter> filterList = new ArrayList<>(); filterList.add(getDefaultFilter()); String file = GodConfig.TEXTURE_FILTERS_DATA_FILE; InputStream in = EdFilter.class.getClassLoader().getResourceAsStream(file); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); StringBuilder builder = new StringBuilder(); try { String line; while ((line = reader.readLine()) != null) builder.append(line).append('\n'); in.close(); JSONObject data = new JSONObject(builder.toString()); String type = "t01"; try { type = data.getString("type"); } catch (Exception ignored) { } final OPallFunction<Float, Float> corrector; final boolean type255 = type.equalsIgnoreCase("t255"); if (type255) corrector = f -> f / 255f; else corrector = Float::floatValue; ArrayList<String> nameList = new ArrayList<>(); JSONArray filters = data.getJSONArray("filters"); for (int i = 0; i < filters.length(); i++) { JSONObject filter = filters.getJSONObject(i); String f_name = filter.getString("name"); if (nameList.contains(f_name)) throw new RuntimeException("FILTER NAME: " + f_name + " is already exist at position: " + i); nameList.add(f_name); boolean bw = false; float contrast = 1f; float gamma = 1f; int col = 0xFFFFFFFF; float light = 0f; float sat = 0f; float hue = 0f; try { sat = (float) filter.getDouble("saturation"); if (type255) sat /= GodConfig.NORM_RANGE; } catch (Exception ignored) { } try { hue = (float) filter.getDouble("hue"); if (type255) hue /= GodConfig.HUE_CLAMP_RANGE; } catch (Exception ignored) { } try { light = (float) filter.getDouble("lightness"); if (type255) light /= GodConfig.NORM_RANGE; } catch (Exception ignored) { } try { col = Color.parseColor(filter.getString("color")); } catch (Exception ignored) { } try { contrast = (float) filter.getDouble("contrast"); if (type255) contrast /= GodConfig.NORM_RANGE; contrast += 1f; } catch (Exception ignored) { } try { gamma = (float) filter.getDouble("gamma"); } catch (Exception ignored) { } try { bw = filter.getBoolean("bw"); } catch (Exception ignored) { } OPallFunction<float[], String> colorFunc = s -> { try { JSONArray color = filter.getJSONArray(s); float r = corrector.apply((float) color.getDouble(0)); float g = corrector.apply((float) color.getDouble(1)); float b = corrector.apply((float) color.getDouble(2)); return new float[] { r, g, b }; } catch (JSONException e) { return null; } }; float[] add = colorFunc.apply("add"); float[] min = colorFunc.apply("min"); float[] max = colorFunc.apply("max"); EdFilter extFilter = new EdFilter(f_name, col, gamma, contrast, hue, sat, light, bw); if (add != null) extFilter.setAdd(add[0], add[1], add[2]); if (min != null) extFilter.setMin(min[0], min[1], min[2]); if (max != null) extFilter.setMax(max[0], max[1], max[2]); filterList.add(extFilter); } } catch (IOException | JSONException e) { e.printStackTrace(); } Collections.reverse(filterList); return filterList; }
From source file:ch.epfl.bbp.uima.annotationviewer.BlueAnnotationViewGenerator.java
/** * Automatically generates a style map for the given text analysis engine. * The style map will be returned as an XML string. * /*from www . java2 s.c o m*/ * @param aTaeMetaData * Metadata of the Text Analysis Engine whose outputs will be * viewed using the generated style map. * * @return a String containing the XML style map */ public static String autoGenerateStyleMap(AnalysisEngineMetaData aTaeMetaData) { // styles used in automatically generated style maps final String[] STYLES = { "color:black; background:lightblue;", "color:black; background:lightgreen;", "color:black; background:orange;", "color:black; background:yellow;", "color:black; background:pink;", "color:black; background:salmon;", "color:black; background:cyan;", "color:black; background:violet;", "color:black; background:tan;", "color:white; background:brown;", "color:white; background:blue;", "color:white; background:green;", "color:white; background:red;", "color:white; background:mediumpurple;" }; // get list of output types from TAE ArrayList outputTypes = new ArrayList(); Capability[] capabilities = aTaeMetaData.getCapabilities(); for (int i = 0; i < capabilities.length; i++) { TypeOrFeature[] outputs = capabilities[i].getOutputs(); for (int j = 0; j < outputs.length; j++) { if (outputs[j].isType() && !outputTypes.contains(outputs[j].getName())) { outputTypes.add(outputs[j].getName()); } } } // generate style map by mapping each type to a background color StringBuffer buf = new StringBuffer(); buf.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"); buf.append("<styleMap>\n"); int i = 0; Iterator it = outputTypes.iterator(); while (it.hasNext()) { String outputType = (String) it.next(); String label = outputType; int lastDot = outputType.lastIndexOf('.'); if (lastDot > -1) { label = outputType.substring(lastDot + 1); } buf.append("<rule>\n"); buf.append("<pattern>"); buf.append(outputType); buf.append("</pattern>\n"); buf.append("<label>"); buf.append(label); buf.append("</label>\n"); buf.append("<style>"); buf.append(STYLES[i % STYLES.length]); buf.append("</style>\n"); buf.append("</rule>\n"); i++; } buf.append("</styleMap>\n"); return buf.toString(); }