List of usage examples for java.util Collections reverse
@SuppressWarnings({ "rawtypes", "unchecked" }) public static void reverse(List<?> list)
This method runs in linear time.
From source file:gov.nih.nci.cabig.caaers.CaaersDbTestCase.java
private List<OpenSessionInViewInterceptor> reverseInterceptors() { List<OpenSessionInViewInterceptor> interceptors = interceptors(); Collections.reverse(interceptors); return interceptors; }
From source file:es.pode.modificador.presentacion.configurar.cambios.navegarArbolCurricular.NavegarArbolCurricularControllerImpl.java
public void navegar(ActionMapping mapping, NavegarForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // De momento en nombreTaxonomia pasamos un null, ms adelante quizs se ponga un combo para escoger una. // El srv por debajo si hay null mete una clave que fuentesTaxonomicas interpreta como que queremos el vigente. try {// w w w .ja v a 2 s . co m TaxonomiaVO tx = null; if (form.getIdTermino() != null && form.getIdTermino().trim().length() > 0) { tx = this.getSrvHerramientaModificacion().navegarArbolCurricular(form.getIdTermino(), null, LdapUserDetailsUtils.getIdioma()); form.setTaxonomia(tx); } else { //para el primer caso tx = this.getSrvHerramientaModificacion().navegarArbolCurricular(null, null, LdapUserDetailsUtils.getIdioma()); } // Es necesario hacer un reverse del taxonPath para mostrar correctamente la rama del arbol: if (tx.getTaxonPath() != null && tx.getTaxonPath().length > 1) { if (logger.isDebugEnabled()) logger.debug("Invierto el orden de taxonPath"); List taxonPath = Arrays.asList(tx.getTaxonPath()); Collections.reverse(taxonPath); tx.setTaxonPath((TaxonVO[]) taxonPath.toArray(new TaxonVO[taxonPath.size()])); } form.setTaxonomia(tx); } catch (RuntimeException e) { logger.error("Excepcion en el servicio de herramienta modificacion al navegar: ", e); saveErrorMessage(request, "areaCurricular.error.inesperado"); } logger.info("Taxonomia genereada correctamente"); form.setIdiomaBuscadorBackingList( IdiomasBuscadorSingleton.getInstance().obtenerIdiomas(LdapUserDetailsUtils.getIdioma()), "idLocalizacion", "nombre"); }
From source file:net.henryco.opalette.application.programs.sub.programs.bFilter.EdFilter.java
private static List<EdFilter> loadFilterListFromJSON() { /*/*w w w. j av a2 s . c o 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:com.sillelien.dollar.api.types.DollarList.java
@NotNull @Override/*from w w w .j a v a 2 s .com*/ @Guarded(NotNullGuard.class) public var $multiply(@NotNull var rhs) { var v = rhs._fixDeep(); ArrayList<var> list = new ArrayList<>(); final int max = Math.abs(v.toInteger()); if (max > MAX_LIST_MULTIPLIER) { return DollarFactory.failure(ErrorType.MULTIPLIER_TOO_LARGE, "Cannot multiply a list by a value greater than " + MAX_LIST_MULTIPLIER, false); } for (int i = 0; i < max; i++) { list.addAll(this.list.mutable()); } if (v.negative()) { Collections.reverse(list); } return DollarFactory.fromValue(list, errors(), v.errors()); }
From source file:com.ibm.bluej.commonutil.PrecisionRecallThreshold.java
private static String stringPRCurve(ArrayList<Pair<Double, Boolean>> pr, double total, int buckets) { StringBuffer buf = new StringBuffer(); Collections.shuffle(pr);/*from w w w. java2 s .c o m*/ Collections.sort(pr, new FirstPairComparator(null)); Collections.reverse(pr); double[] correct = new double[buckets]; double[] answered = new double[buckets]; double[] thresholds = new double[buckets]; int bucketNdx = 0; double cummulativeCorrect = 0; double auc = 0; double allPositive = 0; for (Pair<Double, Boolean> p : pr) { if (p.second) allPositive += 1; } double maxF = 0; for (int i = 0; i < pr.size(); ++i) { if (i >= (1 + bucketNdx) * pr.size() / buckets && bucketNdx < buckets - 1) { thresholds[bucketNdx] = pr.get(i).first; ++bucketNdx; } for (int j = bucketNdx; j < buckets; ++j) { ++answered[j]; if (pr.get(i).second) { ++correct[j]; } } if (pr.get(i).second) { ++cummulativeCorrect; auc += cummulativeCorrect / ((i + 1) * allPositive); } double tp = cummulativeCorrect; double fp = (i + 1) - cummulativeCorrect; double fn = allPositive - cummulativeCorrect; double precision = (double) (tp) / (tp + fp); double recall = (double) (tp) / (tp + fn); double f1 = 2 * precision * recall / (precision + recall); if (f1 > maxF) maxF = f1; } for (int i = 0; i < buckets; ++i) { double precision = correct[i] / answered[i]; double recall = correct[i] / total; double FScore = 2 * precision * recall / (precision + recall); buf.append( "P = " + Lang.dblStr(precision) + " R = " + Lang.dblStr(recall) + " F = " + Lang.dblStr(FScore) + " (C = " + (int) answered[i] + " T = " + Lang.dblStr(thresholds[i]) + ")" + "\n"); } buf.append("AUC = " + auc + "\n"); //not sure if computed correctly buf.append("Max F-Score = " + maxF + "\n"); return buf.toString(); }
From source file:edu.iu.m.news.service.NewsServiceImpl.java
private NewsStream convertRssToNewsStream(Rss rss, boolean sample) { int sampleCount = SAMPLE_COUNT_DEFAULT; if (sample) { try {/*from w ww. j av a 2 s .c o m*/ sampleCount = Integer.parseInt(configParamService.findValueByName(SAMPLE_COUNT)); } catch (Exception e) { } } NewsStream newsStream = new NewsStream(); newsStream.setTitle(rss.getTitle()); newsStream.setDescription(rss.getFormDescription()); List<NewsArticle> articles = new ArrayList<NewsArticle>(); int count = 0; for (RssItem item : rss.getRssItems()) { NewsArticle article = new NewsArticle(); article.setTitle(item.getTitle()); article.setPublishDate(item.getPublishDate()); // article.setArticleId(item.getRssItemId().toString()); article.setLink(item.getLink()); article.setThumbnailImageUrl(item.getEnclosureUrl()); article.setDescription(item.getDescription()); article.setArticleId(item.getLinkUrlEncoded()); articles.add(article); count++; if (sample && count == sampleCount) break; } Collections.sort(articles); // sort the articles in ascending order Collections.reverse(articles); // reverse the list so the newest appears // first List<NewsDay> dayArticles = new ArrayList<NewsDay>(); Calendar date = Calendar.getInstance(); Calendar previousDate = Calendar.getInstance(); SimpleDateFormat longDate = new SimpleDateFormat("EEEEE, MMMMM dd"); String groupDateString; String currentDateString = null; List<NewsArticle> articleListForDate = null; for (NewsArticle article : articles) { date.setTime(article.getPublishDate()); groupDateString = longDate.format(date.getTime()); if (!groupDateString.equals(currentDateString)) { if (currentDateString != null && currentDateString != "") { NewsDay newsDay = new NewsDay(); newsDay.setArticles(articleListForDate); newsDay.setFormattedDate(currentDateString); dayArticles.add(newsDay); } articleListForDate = new ArrayList<NewsArticle>(); currentDateString = groupDateString; previousDate.setTime(article.getPublishDate()); } articleListForDate.add(article); } NewsDay newsDay = new NewsDay(); newsDay.setArticles(articleListForDate); newsDay.setFormattedDate(currentDateString); dayArticles.add(newsDay); newsStream.setArticles(dayArticles); return newsStream; }
From source file:fr.paris.lutece.plugins.asynchronousupload.service.AbstractAsynchronousUploadHandler.java
/** * {@inheritDoc}//from w ww . ja v a 2s . c o m */ @Override public void doRemoveFile(HttpServletRequest request, String strFieldName) { if (hasRemoveFlag(request, strFieldName)) { HttpSession session = request.getSession(false); if (session != null) { // Some previously uploaded files were deleted // Build the prefix of the associated checkboxes String strPrefix = getUploadCheckboxPrefix() + strFieldName; // Look for the checkboxes in the request Enumeration<String> enumParamNames = request.getParameterNames(); List<Integer> listIndexes = new ArrayList<Integer>(); while (enumParamNames.hasMoreElements()) { String strParamName = enumParamNames.nextElement(); if (strParamName.startsWith(strPrefix)) { // Get the index from the name of the checkbox listIndexes.add(Integer.parseInt(strParamName.substring(strPrefix.length()))); } } Collections.sort(listIndexes); Collections.reverse(listIndexes); for (int nIndex : listIndexes) { removeFileItem(strFieldName, session, nIndex); } } } }
From source file:dk.dr.radio.data.Grundata.java
public void leguElsendojn(String radioTxt) { String kapo = null;// www.java 2s . c o m for (String unuo : radioTxt.split("\n\r?\n")) { unuo = unuo.trim(); //Log.d("Unuo: "+unuo); if (unuo.length() == 0) { continue; } if (kapo == null) { kapo = unuo; } else { try { Udsendelse e = new Udsendelse(); String[] x = unuo.split("\n"); /* 3ZZZ en Esperanto 2011-09-29 http://www.melburno.org.au/3ZZZradio/mp3/2011-09-26.3ZZZ.radio.mp3 Anonco : el retmesa?o de Floral Martorell Katastrofo e Vinilkosmo/ Eurokka Kanto : informo pri la kompaktdisko Hiphopa Kompilo 2 Miela obsedo Legado: el la verko de Ken Linton Kanako el Kananam apitro 12 Stranga ?ardeno Lez el Monato de agusto /septembro Tantamas ?topi?oj de Ivo durwael Karlo el Monato Eksplofas la popola kolero [...] */ e.kanalSlug = x[0]; e.startTidKl = x[1]; e.startTid = datoformato.parse(x[1]); e.sonoUrl = x[2]; e.beskrivelse = x[3]; Kanal k = kanalFraNavn.get(e.kanalSlug); // Jen problemo. "Esperanta Retradio" nomi?as "Peranto" en // http://esperanto-radio.com/radio.txt . Ni solvas tion serante anka por la kodo // "kodo": "peranto", // "nomo": "Esperanta Retradio", if (k == null) { k = kanalFraKode.get(e.kanalSlug.toLowerCase()); if (k != null) e.kanalSlug = k.navn; } if (k == null) { Log.d("Nekonata kanalnomo - ALDONAS GXIN: " + e.kanalSlug); k = new Kanal(); k.eo_json = new JSONObject(); k.kode = k.navn = e.kanalSlug; k.eo_datumFonto = "aldonita de radio.txt"; kanalFraKode.put(k.kode, k); kanalFraNavn.put(k.navn, k); kanaler.add(k); } else if (k.eo_datumFonto == null) { k.eo_datumFonto = "radio.txt"; } //Log.d("Aldonas elsendon "+e.toString()); k.udsendelser.add(e); } catch (Exception e) { Log.e("Ne povis legi unuon: " + unuo, e); } } } for (Kanal k : kanaler) Collections.reverse(k.udsendelser); }
From source file:com.wavemaker.runtime.ws.salesforce.SalesforceSupport.java
public JSONObject getPickList(String objName, FieldType currentField, JSONObject fieldAndValuePairs, JSONObject carrier) throws Exception { List<FieldType> fields = getFields(objName); Map<String, FieldType> fieldMap = new HashMap<String, FieldType>(); for (FieldType fld : fields) { fieldMap.put(fld.getName(), fld); }/*from ww w . java2s . c om*/ List<FieldType> controlPath = getControlPath(currentField, fieldMap, null); // if no controller fields are found, get the pick list for the current field and return. if (controlPath == null) { List<PicklistEntryType> picklistValues = currentField.getPicklistValues(); if (picklistValues != null && picklistValues.size() > 0) { return prepareJSONObject(picklistValues, fieldAndValuePairs, currentField); } else { return null; } } Collections.reverse(controlPath); if (carrier == null) { carrier = new JSONObject(); } JSONObject plist = null; for (int i = 0; i < controlPath.size(); i++) { FieldType fld = controlPath.get(i); if (fld.getType().value().equals("boolean")) { continue; } if (carrier.containsKey(downShiftFirstChar(fld.getName()))) { continue; } FieldType controller; // the first field does not have any controller controller = i == 0 ? null : controlPath.get(i - 1); plist = getRestrictedPickList(objName, fld, controller, fieldAndValuePairs); // do not add the last entry to carrier bcz it will be added in the caller (getPiclLists) if (i < controlPath.size() - 1) { carrier.put(downShiftFirstChar(currentField.getName()), plist); } } return plist; }
From source file:org.berlin.batch.bom.DataMessageFinder.java
public List<String> queryConnectRules() { // First, a random selection to determine which rule to use // final Random rand = new Random(System.currentTimeMillis()); // 1 = backwards // 2 = random values // 3(default) = forward int rule = 3; final double r = rand.nextDouble(); if (r >= 0.8) { rule = 1;/*from w w w. j av a 2s .co m*/ } else if (r <= 0.32) { rule = 2; } else { rule = 3; } // End of the if - else // if (this.forceRequestRule != -1) { rule = this.forceRequestRule; } final List<String> ruleData = new ArrayList<String>(); if (2 == rule) { // Reversed list // for (final String term : POPULAR_TERMS) { ruleData.add(term); } // End of the for // Collections.reverse(ruleData); } else if (1 == rule) { // Random list // final Random rand2 = new Random(); for (String s : POPULAR_TERMS) { final int ni = rand2.nextInt(POPULAR_TERMS.length - 1); ruleData.add(POPULAR_TERMS[ni]); } // End of the for // } else { // Forward list // for (final String term : POPULAR_TERMS) { ruleData.add(term); } // End of the for // } // End of the if - else // return ruleData; }