List of usage examples for java.util TreeMap get
public V get(Object key)
From source file:com.pezzuto.pezzuto.ui.StickyHeaderFragment.java
public void sendSearchProdRequest(String scope, String query) { RequestsUtils.sendSearchRequest(getContext(), createSearchJSON(scope, query), new Response.Listener<JSONArray>() { @Override// w w w . ja v a 2s . c om public void onResponse(JSONArray response) { Log.d("response", response.toString()); try { JSONArray pr = response.getJSONObject(0).getJSONArray("prodotti"); prods.clear(); List<Product> products = ParseUtils.parseProducts(pr); if (pr.length() == 0) mListener.setEmptyState(MainActivity.PROD_SEARCH); //category division TreeMap<String, List<Product>> catProducts = new TreeMap<>(); for (Product p : products) { String category = p.getCategory(); List<Product> pros = new ArrayList<>(); if (catProducts.containsKey(category)) pros = catProducts.get(category); pros.add(p); p.setLabel(category); catProducts.put(category, pros); } //insert in adapter for (String cat : catProducts.keySet()) for (Product p : catProducts.get(cat)) { prods.add(p); } adapterProd.notifyDataSetChanged(); } catch (JSONException ex) { ex.printStackTrace(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { error.printStackTrace(); } }); }
From source file:org.datacleaner.widgets.properties.MultipleInputColumnsPropertyWidget.java
/** * Reorders the values/*from w w w . j a va 2s.c o m*/ * * @param sortedValue */ public void reorderValue(final InputColumn<?>[] sortedValue) { // the offset represents the search textfield and the button panel final int offset = 2; // reorder the visual components for (int i = 0; i < sortedValue.length; i++) { InputColumn<?> inputColumn = sortedValue[i]; JComponent decoration = getOrCreateCheckBoxDecoration(inputColumn, true); add(decoration, i + offset); } updateUI(); // recreate the _checkBoxes map final TreeMap<InputColumn<?>, DCCheckBox<InputColumn<?>>> checkBoxesCopy = new TreeMap<>(_checkBoxes); _checkBoxes.clear(); for (InputColumn<?> inputColumn : sortedValue) { final DCCheckBox<InputColumn<?>> checkBox = checkBoxesCopy.get(inputColumn); _checkBoxes.put(inputColumn, checkBox); } _checkBoxes.putAll(checkBoxesCopy); setValue(sortedValue); }
From source file:uk.ac.leeds.ccg.andyt.projects.moses.process.RegressionReport_UK1.java
protected static Object[] loadDataHSARHP_ISARCEP(File a_SARFile, File a_CASFile) throws IOException { Object[] result = new Object[3]; TreeMap<String, double[]> a_SAROptimistaionConstraints = loadCASOptimistaionConstraints(a_SARFile); TreeMap<String, double[]> a_CASOptimistaionConstraints = loadCASOptimistaionConstraints(a_CASFile); Vector<String> variables = GeneticAlgorithm_HSARHP_ISARCEP.getVariableList(); variables.add(0, "Zone_Code"); String[] variableNames = new String[0]; variableNames = variables.toArray(variableNames); result[0] = variableNames;//from www. j ava 2s . c o m // Format (Flip) data double[][] a_SARExpectedData = new double[variables.size() - 1][a_SAROptimistaionConstraints.size()]; double[][] a_CASObservedData = new double[variables.size() - 1][a_SAROptimistaionConstraints.size()]; String oa; double[] a_SARExpectedRow; double[] a_CASObservedRow; int j = 0; Iterator<String> iterator_String = a_SAROptimistaionConstraints.keySet().iterator(); while (iterator_String.hasNext()) { oa = iterator_String.next(); a_SARExpectedRow = a_SAROptimistaionConstraints.get(oa); a_CASObservedRow = a_CASOptimistaionConstraints.get(oa); // if (oa.equalsIgnoreCase("00AAFQ0013")){ // System.out.println(oa); // } if (a_SARExpectedRow == null) { System.out.println( "Warning a_SARExpectedRow == null in loadDataHSARHP_ISARCEP(File,File) for OA " + oa); } else { if (a_CASObservedRow == null) { System.out.println( "Warning a_SARExpectedRow == null in loadDataHSARHP_ISARCEP(File,File) for OA " + oa); } else { for (int i = 0; i < variables.size() - 1; i++) { a_SARExpectedData[i][j] = a_SARExpectedRow[i]; a_CASObservedData[i][j] = a_CASObservedRow[i]; } } } j++; } result[1] = a_SARExpectedData; result[2] = a_CASObservedData; return result; }
From source file:com.opengamma.analytics.financial.interestrate.CashFlowEquivalentCalculator.java
@Override public AnnuityPaymentFixed visitGenericAnnuity(final Annuity<? extends Payment> annuity, final YieldCurveBundle curves) { Validate.notNull(curves);// w w w. j av a2s . c o m Validate.notNull(annuity); TreeMap<Double, Double> flow = new TreeMap<Double, Double>(); Currency ccy = annuity.getCurrency(); for (final Payment p : annuity.getPayments()) { AnnuityPaymentFixed cfe = visit(p, curves); for (int loopcf = 0; loopcf < cfe.getNumberOfPayments(); loopcf++) { addcf(flow, cfe.getNthPayment(loopcf).getPaymentTime(), cfe.getNthPayment(loopcf).getAmount()); } } PaymentFixed[] agregatedCfe = new PaymentFixed[flow.size()]; int loopcf = 0; for (double time : flow.keySet()) { agregatedCfe[loopcf++] = new PaymentFixed(ccy, time, flow.get(time), annuity.getDiscountCurve()); } return new AnnuityPaymentFixed(agregatedCfe); }
From source file:com.opengamma.analytics.financial.provider.calculator.discounting.CashFlowEquivalentCalculator.java
@Override public AnnuityPaymentFixed visitGenericAnnuity(final Annuity<? extends Payment> annuity, final MulticurveProviderInterface multicurves) { ArgumentChecker.notNull(annuity, "Annuity"); ArgumentChecker.notNull(multicurves, "Multicurves provider"); final TreeMap<Double, Double> flow = new TreeMap<>(); final Currency ccy = annuity.getCurrency(); for (final Payment p : annuity.getPayments()) { final AnnuityPaymentFixed cfe = p.accept(this, multicurves); for (int loopcf = 0; loopcf < cfe.getNumberOfPayments(); loopcf++) { addcf(flow, cfe.getNthPayment(loopcf).getPaymentTime(), cfe.getNthPayment(loopcf).getAmount()); }//from w w w .ja va 2 s .co m } final PaymentFixed[] agregatedCfe = new PaymentFixed[flow.size()]; int loopcf = 0; for (final double time : flow.keySet()) { agregatedCfe[loopcf++] = new PaymentFixed(ccy, time, flow.get(time)); } return new AnnuityPaymentFixed(agregatedCfe); }
From source file:jetbrains.exodus.env.Reflect.java
private void fetchUsedSpace(LongIterator itr, TreeMap<Long, Long> usedSpace) { while (itr.hasNext()) { try {//from w w w .ja va 2s . c o m final long address = itr.next(); final RandomAccessLoggable loggable = log.read(address); final Long fileAddress = log.getFileAddress(address); Long usedBytes = usedSpace.get(fileAddress); if (usedBytes == null) { usedBytes = 0L; } usedBytes += loggable.length(); usedSpace.put(fileAddress, usedBytes); final int type = loggable.getType(); if (type > MAX_VALID_LOGGABLE_TYPE) { logging.error("Wrong loggable type: " + type); } } catch (ExodusException e) { logging.error("Can't enumerate loggable: " + e); } } }
From source file:com.ibm.bi.dml.debug.DMLDebuggerFunctions.java
/** * Print range of program runtime instructions * @param DMLInstMap Mapping between source code line number and corresponding runtime instruction(s) * @param range Range of lines of DML code to be displayed */// www .j a va 2s .c om public void printRuntimeInstructions(TreeMap<Integer, ArrayList<Instruction>> DMLInstMap, IntRange range) { //Display instructions for (int lineNumber = range.getMinimumInteger(); lineNumber <= range.getMaximumInteger(); lineNumber++) { if (DMLInstMap.get(lineNumber) != null) { for (Instruction currInst : DMLInstMap.get(lineNumber)) { if (currInst instanceof CPInstruction) System.out.format("\t\t id %4d: %s\n", currInst.getInstID(), prepareInstruction(currInst.toString())); else if (currInst instanceof MRJobInstruction) { MRJobInstruction currMRInst = (MRJobInstruction) currInst; System.out.format("\t\t id %4d: %s\n", currInst.getInstID(), prepareInstruction(currMRInst.getMRString(false))); } else if (currInst instanceof BreakPointInstruction) { BreakPointInstruction currBPInst = (BreakPointInstruction) currInst; System.out.format("\t\t id %4d: %s\n", currInst.getInstID(), currBPInst.toString()); } } } } }
From source file:net.sf.sessionAnalysis.SessionVisitorArrivalAndCompletionRate.java
/** * Note that metrics other than max, min are more difficult, as we need to include the duration * that this number of sessions is present in the interval (e.g., for mean, median, ...). *//* w ww . j a v a2s . c o m*/ private void computeMaxSessionsPerInterval() { final long durationNanos = this.maxTimestampNanos - this.minTimestampNanos; final int numBuckets = (int) Math.ceil((double) durationNanos / this.resolutionValueNanos); // Note that the map must not be filled with 0's, because this introduces errors for // intervals without events. TreeMap<Integer, Integer> numSessionsPerInterval = new TreeMap<Integer, Integer>(); for (Entry<Long, Integer> numSessionChangeEvent : this.numConcurrentSessionsOverTime.entrySet()) { final long eventTimeStamp = numSessionChangeEvent.getKey(); final int numSessionsAtTime = numSessionChangeEvent.getValue(); final int eventTimeStampBucket = (int) ((eventTimeStamp - this.minTimestampNanos) / this.resolutionValueNanos); Integer lastMaxNumForBucket = numSessionsPerInterval.get(eventTimeStampBucket); if (lastMaxNumForBucket == null || numSessionsAtTime > lastMaxNumForBucket) { numSessionsPerInterval.put(eventTimeStampBucket, numSessionsAtTime); } } // Now we need to fill intervals without values with the last non-null value int lastNonNullValue = 0; for (int i = 0; i < numBuckets; i++) { Integer curVal = numSessionsPerInterval.get(i); if (curVal == null) { numSessionsPerInterval.put(i, lastNonNullValue); } else { lastNonNullValue = curVal; } } this.maxNumSessionsPerInterval = ArrayUtils .toPrimitive(numSessionsPerInterval.values().toArray(new Integer[0])); }
From source file:com.npower.wurfl.ListManager.java
public TreeMap<String, WurflDevice> getSpecialActualDeviceElementsList() { TreeMap<String, WurflDevice> specialActualDeviceElementsList = new TreeMap<String, WurflDevice>(); CapabilityMatrix cm = this.getObjectsManager().getCapabilityMatrixInstance(); TreeMap<String, Element> actualXOMDevices = wu.getActualDeviceElementsList(); Iterator<String> keys = actualXOMDevices.keySet().iterator(); while (keys.hasNext()) { String key = keys.next(); Element el = actualXOMDevices.get(key); WurflDevice wd = new WurflDevice(el); String bn = cm.getCapabilityForDevice(key, "brand_name"); String mn = cm.getCapabilityForDevice(key, "model_name"); wd.setBrandName(bn);/*from ww w . ja v a 2 s .c o m*/ wd.setModelName(mn); specialActualDeviceElementsList.put(key, wd); } return specialActualDeviceElementsList; }
From source file:ai.susi.mind.SusiMind.java
/** * This is the core principle of creativity: being able to match a given input * with problem-solving knowledge./*from w ww . java2 s . c o m*/ * This method finds ideas (with a query instantiated skills) for a given query. * The skills are selected using a scoring system and pattern matching with the query. * Not only the most recent user query is considered for skill selection but also * previously requested queries and their answers to be able to set new skill selections * in the context of the previous conversation. * @param query the user input * @param previous_argument the latest conversation with the same user * @param maxcount the maximum number of ideas to return * @return an ordered list of ideas, first idea should be considered first. */ public List<SusiIdea> creativity(String query, SusiThought latest_thought, int maxcount) { // tokenize query to have hint for idea collection final List<SusiIdea> ideas = new ArrayList<>(); this.reader.tokenizeSentence(query).forEach(token -> { Set<SusiSkill> skill_for_category = this.skilltrigger.get(token.categorized); Set<SusiSkill> skill_for_original = token.original.equals(token.categorized) ? null : this.skilltrigger.get(token.original); Set<SusiSkill> r = new HashSet<>(); if (skill_for_category != null) r.addAll(skill_for_category); if (skill_for_original != null) r.addAll(skill_for_original); r.forEach(skill -> ideas.add(new SusiIdea(skill).setIntent(token))); }); for (SusiIdea idea : ideas) DAO.log("idea.phrase-1: score=" + idea.getSkill().getScore().score + " : " + idea.getSkill().getPhrases().toString() + " " + idea.getSkill().getActionsClone()); // add catchall skills always (those are the 'bad ideas') Collection<SusiSkill> ca = this.skilltrigger.get(SusiSkill.CATCHALL_KEY); if (ca != null) ca.forEach(skill -> ideas.add(new SusiIdea(skill))); // create list of all ideas that might apply TreeMap<Long, List<SusiIdea>> scored = new TreeMap<>(); AtomicLong count = new AtomicLong(0); ideas.forEach(idea -> { int score = idea.getSkill().getScore().score; long orderkey = Long.MAX_VALUE - ((long) score) * 1000L + count.incrementAndGet(); List<SusiIdea> r = scored.get(orderkey); if (r == null) { r = new ArrayList<>(); scored.put(orderkey, r); } r.add(idea); }); // make a sorted list of all ideas ideas.clear(); scored.values().forEach(r -> ideas.addAll(r)); for (SusiIdea idea : ideas) DAO.log("idea.phrase-2: score=" + idea.getSkill().getScore().score + " : " + idea.getSkill().getPhrases().toString() + " " + idea.getSkill().getActionsClone()); // test ideas and collect those which match up to maxcount List<SusiIdea> plausibleIdeas = new ArrayList<>(Math.min(10, maxcount)); for (SusiIdea idea : ideas) { SusiSkill skill = idea.getSkill(); Collection<Matcher> m = skill.matcher(query); if (m.isEmpty()) continue; // TODO: evaluate leading SEE flow commands right here as well plausibleIdeas.add(idea); if (plausibleIdeas.size() >= maxcount) break; } for (SusiIdea idea : plausibleIdeas) { DAO.log("idea.phrase-3: score=" + idea.getSkill().getScore().score + " : " + idea.getSkill().getPhrases().toString() + " " + idea.getSkill().getActionsClone()); DAO.log("idea.phrase-3: log=" + idea.getSkill().getScore().log); } return plausibleIdeas; }