List of usage examples for org.apache.commons.lang3.tuple Pair getValue
@Override
public R getValue()
Gets the value from this pair.
This method implements the Map.Entry interface returning the right element as the value.
From source file:edu.sjsu.pokemonclassifier.classification.UserPreferenceInfo.java
public Map<String, Integer> getRecommendPokemon() { // API for downard module // Put all strongerCandidates to GMM model List<Pair<Integer, Double>> weightPairList = new ArrayList<>(); GaussianMixtureModel model = gmmTrainer.getModel(); for (int j = 0; j < model.getK(); j++) { weightPairList.add(Pair.of(j, model.weights()[j])); }/* ww w .j a v a 2 s .c o m*/ Collections.sort(weightPairList, new Comparator<Pair<Integer, Double>>() { @Override public int compare(Pair<Integer, Double> o1, Pair<Integer, Double> o2) { if (o1.getValue() < o2.getKey()) return -1; else if (o1.getValue().equals(o2.getValue())) return 0; else return 1; } }); // Get top-5 // 5 is temp number // <String, Interger> -> <PokemonName, Rank#> HashMap<String, Integer> rankedPokemon = new HashMap<String, Integer>(); HashMap<Integer, String> strongerCandidatesMap = new HashMap<Integer, String>(); for (String strongerCandidate : strongerCandidates) { strongerCandidatesMap.put(strongerCandidates.indexOf(strongerCandidate), strongerCandidate); } // for (int i = 0; i < strongerCandidates.size(); i++) { // // strongerCandidatesMap.put(i, strongerCandidates.get(i).toLowerCase()); // } // modified by sidmishraw for getting top 10 pokemons rather than 5 int totalClusters = Math.min(model.getK(), 10); int rank = 1; for (int i = totalClusters - 1; i >= 0; i--) { int modelIdx = weightPairList.get(i).getKey(); double[] meanVector = model.gaussians()[modelIdx].mean().toArray(); double att = meanVector[0]; double def = meanVector[1]; double hp = meanVector[2]; double minDist = Double.MAX_VALUE; int minIdx = 0; String bestFitName = null; for (int j = 0; j < strongerCandidatesMap.size(); j++) { String name = strongerCandidatesMap.get(j); if (name == null) { continue; } //name = name.toLowerCase(); System.out.println("HARMLESS:::: name = " + name); System.out.println("HARMLESS:::: att2 = " + PokemonDict.getInstance().getAttack(name)); System.out.println("HARMLESS:::: def2 = " + PokemonDict.getInstance().getDefense(name)); System.out.println("HARMLESS:::: hp2 = " + PokemonDict.getInstance().getHP(name)); int att2 = PokemonDict.getInstance().getAttack(name); int def2 = PokemonDict.getInstance().getDefense(name); int hp2 = PokemonDict.getInstance().getHP(name); double dist = Math .sqrt((att - att2) * (att - att2) + (def - def2) * (def - def2) + (hp - hp2) * (hp - hp2)); if (dist < minDist) { minDist = dist; minIdx = j; bestFitName = name; } } strongerCandidatesMap.remove(minIdx); rankedPokemon.put(bestFitName, rank); rank++; } return rankedPokemon; }
From source file:com.hortonworks.registries.storage.impl.jdbc.provider.sql.statement.PreparedStatementBuilder.java
private void setStorableUpdatePreparedStatement(AbstractStorableUpdateQuery updateQuery) throws SQLException { List<Pair<Schema.Field, Object>> bindings = updateQuery.getBindings(); for (int i = 0; i < bindings.size(); i++) { Pair<Schema.Field, Object> binding = bindings.get(i); Schema.Type javaType = binding.getKey().getType(); storageDataTypeContext.setPreparedStatementParams(preparedStatement, javaType, i + 1, binding.getValue()); }/*from w ww . j ava 2s. co m*/ }
From source file:alfio.repository.EventRepositoryTest.java
@Test public void testJavaInsertedDatesRespectTheirTimeZone() throws Exception { //these are the values of what we have inserted in the SQL insert script ZonedDateTime beginEventDate = ZonedDateTime.of(2015, 4, 18, 0, 0, 0, 0, ZoneId.of("America/New_York")); ZonedDateTime endEventDate = ZonedDateTime.of(2015, 4, 19, 23, 59, 59, 0, ZoneId.of("America/New_York")); Pair<Integer, Integer> pair = eventRepository.insert("test from unit test", "unittest", "http://localhost:8080/", "http://localhost:8080", "http://localhost:8080", "Lugano", "9", "8", beginEventDate, endEventDate, NEW_YORK_TZ, 0, "CHF", 4, true, new BigDecimal(1), "", "", 0); Event e = eventRepository.findById(pair.getValue()); assertNotNull("Event not found in DB", e); assertEquals("Begin date is not correct", beginEventDate, e.getBegin()); assertEquals("End date is not correct", endEventDate, e.getEnd()); //since when debugging the toString method is used .... and it rely on the system TimeZone, we test it too System.out.println(e.getBegin().toString()); System.out.println(e.getEnd().toString()); }
From source file:com.netflix.genie.agent.execution.services.impl.FetchingCacheServiceImpl.java
/** * {@inheritDoc}/* w w w . j av a 2s.co m*/ */ @Override public void get(final Set<Pair<URI, File>> sourceDestinationPairs) throws DownloadException, IOException { for (final Pair<URI, File> sourceDestinationPair : sourceDestinationPairs) { get(sourceDestinationPair.getKey(), sourceDestinationPair.getValue()); } }
From source file:com.galenframework.speclang2.specs.SpecImageProcessor.java
@Override public Spec process(StringCharReader reader, String contextPath) { List<Pair<String, String>> parameters = Expectations.commaSeparatedRepeatedKeyValues().read(reader); SpecImage spec = new SpecImage(); spec.setImagePaths(new LinkedList<String>()); spec.setStretch(false);//from w ww. ja va 2s . c o m spec.setErrorRate(GalenConfig.getConfig().getImageSpecDefaultErrorRate()); spec.setTolerance(GalenConfig.getConfig().getImageSpecDefaultTolerance()); for (Pair<String, String> parameter : parameters) { if ("file".equals(parameter.getKey())) { if (contextPath != null) { spec.getImagePaths().add(contextPath + File.separator + parameter.getValue()); } else { spec.getImagePaths().add(parameter.getValue()); } } else if ("error".equals(parameter.getKey())) { spec.setErrorRate(SpecImage.ErrorRate.fromString(parameter.getValue())); } else if ("tolerance".equals(parameter.getKey())) { spec.setTolerance(parseIntegerParameter("tolerance", parameter.getValue())); } else if ("analyze-offset".equals(parameter.getKey())) { spec.setAnalyzeOffset(parseIntegerParameter("analyze-offset", parameter.getValue())); } else if ("stretch".equals(parameter.getKey())) { spec.setStretch(true); } else if ("area".equals(parameter.getKey())) { spec.setSelectedArea(parseRect(parameter.getValue())); } else if ("filter".equals(parameter.getKey())) { ImageFilter filter = parseImageFilter(parameter.getValue(), contextPath); spec.getOriginalFilters().add(filter); spec.getSampleFilters().add(filter); } else if ("filter-a".equals(parameter.getKey())) { ImageFilter filter = parseImageFilter(parameter.getValue(), contextPath); spec.getOriginalFilters().add(filter); } else if ("filter-b".equals(parameter.getKey())) { ImageFilter filter = parseImageFilter(parameter.getValue(), contextPath); spec.getSampleFilters().add(filter); } else if ("map-filter".equals(parameter.getKey())) { ImageFilter filter = parseImageFilter(parameter.getValue(), contextPath); spec.getMapFilters().add(filter); } else if ("crop-if-outside".equals(parameter.getKey())) { spec.setCropIfOutside(true); } else if ("ignore-objects".equals(parameter.getKey())) { String ignoreObjects = parseExcludeObjects(parameter.getValue()); if (spec.getIgnoredObjectExpressions() == null) { spec.setIgnoredObjectExpressions(new LinkedList<>()); } spec.getIgnoredObjectExpressions().add(ignoreObjects); } else { throw new SyntaxException("Unknown parameter: " + parameter.getKey()); } } if (spec.getImagePaths() == null || spec.getImagePaths().size() == 0) { throw new SyntaxException("There are no images defined"); } return spec; }
From source file:com.nextdoor.bender.operation.substitution.regex.RegexSubstitution.java
@Override protected void doSubstitution(InternalEvent ievent, DeserializedEvent devent, Map<String, Object> nested) { Pair<String, Map<String, Object>> kv; try {/*from w ww .j a v a 2s. c o m*/ kv = getRegexMatches(devent); } catch (FieldNotFoundException e) { if (this.failSrcNotFound) { throw new OperationException(e); } return; } nested.putAll(kv.getValue()); /* * Remove source field */ if (this.removeSrcField) { try { devent.removeField(kv.getKey()); } catch (FieldNotFoundException e) { if (this.failSrcNotFound) { throw new OperationException(e); } } } }
From source file:com.uber.hoodie.common.util.TestCompactionUtils.java
@Test public void testBuildFromFileSlices() { Pair<List<Pair<String, FileSlice>>, HoodieCompactionPlan> inputAndPlan = buildCompactionPlan(); testFileSlicesCompactionPlanEquality(inputAndPlan.getKey(), inputAndPlan.getValue()); }
From source file:com.act.lcms.db.model.LCMSWell.java
public List<LCMSWell> insertFromPlateComposition(DB db, PlateCompositionParser parser, Plate p) throws SQLException, IOException { Map<Pair<String, String>, String> msids = parser.getCompositionTables().get("msid"); List<Pair<String, String>> sortedCoordinates = new ArrayList<>(msids.keySet()); Collections.sort(sortedCoordinates, new Comparator<Pair<String, String>>() { // TODO: parse the values of these pairs as we read them so we don't need this silly comparator. @Override/*from ww w .j a v a 2 s . com*/ public int compare(Pair<String, String> o1, Pair<String, String> o2) { if (o1.getKey().equals(o2.getKey())) { return Integer.valueOf(Integer.parseInt(o1.getValue())) .compareTo(Integer.parseInt(o2.getValue())); } return o1.getKey().compareTo(o2.getKey()); } }); List<LCMSWell> results = new ArrayList<>(); for (Pair<String, String> coords : sortedCoordinates) { String msid = msids.get(coords); if (msid == null || msid.isEmpty()) { continue; } String composition = parser.getCompositionTables().get("composition").get(coords); String chemical = parser.getCompositionTables().get("chemical").get(coords); String note = null; if (parser.getCompositionTables().get("note") != null) { note = parser.getCompositionTables().get("note").get(coords); } Pair<Integer, Integer> index = parser.getCoordinatesToIndices().get(coords); LCMSWell s = INSTANCE.insert(db, p.getId(), index.getLeft(), index.getRight(), msid, composition, chemical, note); results.add(s); } return results; }
From source file:com.nextdoor.bender.operation.substitution.regex.RegexSubstitution.java
@Override protected void doSubstitution(InternalEvent ievent, DeserializedEvent devent) { Pair<String, Map<String, Object>> kv; try {// ww w . jav a 2 s . c o m kv = getRegexMatches(devent); } catch (FieldNotFoundException e) { if (this.failSrcNotFound) { throw new OperationException(e); } return; } ((Map<String, Object>) kv.getValue()).forEach((k, v) -> { try { devent.setField(k, v); } catch (FieldNotFoundException e) { if (this.failDstNotFound) { throw new OperationException(e); } } }); /* * Do not remove source field if it has been replaced by a regex group. */ if (this.removeSrcField && !kv.getValue().containsKey(kv.getKey())) { try { devent.removeField(kv.getKey()); } catch (FieldNotFoundException e) { if (this.failSrcNotFound) { throw new OperationException(e); } } } }
From source file:com.astamuse.asta4d.render.test.RendererTester.java
private Object getAttrAsObject(String selector, String attr, boolean allowList, boolean allowEmpty) { List<Renderer> rendererList = renderer.asUnmodifiableList(); List<Object> valueList = new LinkedList<>(); for (Renderer r : rendererList) { if (r.getSelector().equals(selector)) { List<Transformer<?>> list = r.getTransformerList(); if (list.isEmpty()) { continue; } else { Transformer<?> t = list.get(0); if (t.getContent() instanceof AttributeSetter) { AttributeSetter setter = (AttributeSetter) t.getContent(); @SuppressWarnings("unchecked") Pair<String, Object> data = (Pair<String, Object>) setter.retrieveTestableData(); if (data.getKey().equals(attr)) { Object obj = data.getValue(); valueList.add(obj); }// ww w . j a v a 2s . c om } else { continue; } } } } if (!allowEmpty && valueList.isEmpty()) { throw new RendererTestException( "There is no value to be rendered for attr:[" + attr + "] of selector:[" + selector + "]"); } else if (valueList.size() > 1) { if (allowList) { return valueList; } else { throw new RendererTestException("There are more than one values(" + valueList.toString() + ") to be rendered for attr:[" + attr + "] of selector:[" + selector + "]"); } } else { if (allowList) { return valueList; } else { return valueList.get(0); } } }