List of usage examples for org.apache.commons.lang3.tuple Pair getKey
@Override public final L getKey()
Gets the key from this pair.
This method implements the Map.Entry interface returning the left element as the key.
From source file:com.hortonworks.registries.storage.impl.jdbc.provider.sql.query.AbstractStorableUpdateQuery.java
public AbstractStorableUpdateQuery(Storable storable) { super(storable); Map<String, Object> columnsToValues = storable.toMap(); columns.forEach(col -> bindings.add(Pair.of(col, columnsToValues.get(col.getName())))); primaryKey.getFieldsToVal().forEach((f, o) -> { bindings.add(Pair.of(f, o));//from ww w . j a v a2s. co m whereFields.add(f); }); try { Optional<Pair<Field, Long>> versionFieldValue = StorageUtils.getVersionFieldValue(storable); if (versionFieldValue.isPresent()) { Pair<Field, Long> fv = versionFieldValue.get(); Schema.Field versionField = Schema.Field.of(fv.getKey().getName(), Schema.fromJavaType(fv.getValue().getClass())); whereFields.add(versionField); // update only if its the previous bindings.add(Pair.of(versionField, fv.getValue() - 1)); } } catch (Exception ex) { LOG.error("Got exception", ex); } }
From source file:code.elix_x.excore.utils.net.packets.runnable.RunnableMessageHandler.java
@Override public REPLY onMessage(REQ message, MessageContext ctx) { Pair<Runnable, REPLY> pair = run.apply(new ImmutablePair<REQ, MessageContext>(message, ctx)); getThreadListener(ctx).addScheduledTask(pair.getKey()); return pair.getValue(); }
From source file:com.trenako.web.tags.PeriodTags.java
@Override protected int writeTagContent(JspWriter jspWriter, String contextPath) throws JspException { Pair<String, Integer> p = periodUntilNow(getSince()); String msg = getMessageSource().getMessage(p.getKey(), new Object[] { p.getValue() }, p.getKey(), getRequestContext().getLocale()); try {//w w w . j a v a 2s . c o m jspWriter.append(msg); } catch (IOException e) { e.printStackTrace(); } return SKIP_BODY; }
From source file:com.microsoft.tooling.msservices.serviceexplorer.azure.vmarm.VMArmModule.java
@Override protected void refreshItems() throws AzureCmdException { List<Pair<String, String>> failedSubscriptions = new ArrayList<>(); try {/*from w w w . j a va 2s.c o m*/ AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager(); // not signed in if (azureManager == null) { return; } SubscriptionManager subscriptionManager = azureManager.getSubscriptionManager(); Set<String> sidList = subscriptionManager.getAccountSidList(); for (String sid : sidList) { try { Azure azure = azureManager.getAzure(sid); List<VirtualMachine> virtualMachines = azure.virtualMachines().list(); for (VirtualMachine vm : virtualMachines) { addChildNode(new VMNode(this, sid, vm)); } } catch (Exception ex) { failedSubscriptions.add(new ImmutablePair<>(sid, ex.getMessage())); continue; } } } catch (Exception ex) { DefaultLoader.getUIHelper() .logError("An error occurred when trying to load Virtual Machines\n\n" + ex.getMessage(), ex); } if (!failedSubscriptions.isEmpty()) { StringBuilder errorMessage = new StringBuilder( "An error occurred when trying to load Storage Accounts for the subscriptions:\n\n"); for (Pair error : failedSubscriptions) { errorMessage.append(error.getKey()).append(": ").append(error.getValue()).append("\n"); } DefaultLoader.getUIHelper().logError( "An error occurred when trying to load Storage Accounts\n\n" + errorMessage.toString(), null); } }
From source file:com.michellemay.URLLanguageDetectorTest.java
public void validateTestCases(URLLanguageDetector detector, List<Pair<String, String>> testCases) throws Exception { List<Pair<Pair<String, String>, Optional<Locale>>> failedTests = testCases.stream() .map((test) -> Pair.of(test, detector.detect(test.getKey()))).filter((testAndResult) -> { Pair<String, String> test = testAndResult.getKey(); Optional<Locale> detectedLanguage = testAndResult.getValue(); boolean localTestFailed = (detectedLanguage.isPresent() != !test.getValue().isEmpty()); if (!localTestFailed && detectedLanguage.isPresent()) { localTestFailed = !detectedLanguage.get().equals(LocaleUtils.toLocale(test.getValue())); }// www. j a v a2 s . c om return localTestFailed; }).collect(Collectors.toList()); failedTests .forEach((test) -> System.out.println("FAILED: " + test.getKey() + ", FOUND: " + test.getValue())); assertTrue(failedTests.isEmpty()); }
From source file:au.gov.ga.earthsci.bookmark.properties.layer.LayersProperty.java
/** * Add additional layer state to this property. * //from www.ja v a 2 s . c om * @param id * The id of the layer * @param opacity * The opacity of the layer */ public void addLayer(String id, Pair<String, String>... keyandValues) { if (!layerStateInfo.containsKey(id)) { layerStateInfo.put(id, new ConcurrentHashMap<String, String>()); } for (Pair<String, String> pair : keyandValues) { layerStateInfo.get(id).put(pair.getKey(), pair.getValue()); } }
From source file:com.astamuse.asta4d.web.test.form.field.FieldRenderBuilder.java
public Renderer toRenderer(boolean forEdit) { Renderer renderer = Renderer.create(); for (FormFieldPrepareRenderer prepare : prepareList) { String fieldName = ((SimpleFormFieldPrepareRenderer) prepare).getGivenFieldName(); renderer.add(prepare.preRender(editSelector(fieldName), displaySelector(fieldName))); }/*from ww w . j a v a 2s.co m*/ FormFieldValueRenderer valueRenderer; try { valueRenderer = valueRenderCls.newInstance(); for (Pair<String, Object> value : valueList) { String edit = editSelector(value.getKey()); String display = displaySelector(value.getKey()); renderer.add(forEdit ? valueRenderer.renderForEdit(edit, value.getValue()) : valueRenderer.renderForDisplay(edit, display, value.getValue())); } } catch (InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); } for (FormFieldPrepareRenderer prepare : prepareList) { String fieldName = ((SimpleFormFieldPrepareRenderer) prepare).getGivenFieldName(); renderer.add(prepare.postRender(editSelector(fieldName), displaySelector(fieldName))); } return renderer; }
From source file:com.intuit.quickbase.MergeStatServiceHashMap.java
public void retrieveCountryPopulationList() { DBStatService dbStatService = new DBStatService(); List<Pair<String, Integer>> dbList = dbStatService.GetCountryPopulations(); ConcreteStatService conStatService = new ConcreteStatService(); List<Pair<String, Integer>> apiList = conStatService.GetCountryPopulations(); List<Pair<String, Integer>> modifiedAPIList = new ArrayList<>(); if (apiList != null) { // Converting the keys of each element in the API list to lowercase Iterator iterator = apiList.iterator(); while (iterator.hasNext()) { Pair<String, Integer> pair = (Pair) iterator.next(); String key = pair.getKey().toLowerCase(); Integer value = pair.getValue(); modifiedAPIList.add(new ImmutablePair<String, Integer>(key, value)); }//from w w w .ja v a 2 s .co m } if (modifiedAPIList != null) { Iterator iterator = modifiedAPIList.iterator(); while (iterator.hasNext()) { Pair<String, Integer> pair = (Pair) iterator.next(); System.out.println("key: " + pair.getLeft() + ": value: " + pair.getRight()); } } // if(dbList != null) { // // Merge two list and remove duplicates // Collection<Pair<String, Integer>> result = Stream.concat(dbList.stream(), modifiedAPIList.stream()) // .filter(pred) // .collect( Collectors.toMap(Pair::getLeft, p -> p, (p, q) -> p, LinkedHashMap::new)) // .values(); // // // Need to Convert collection to List // List<Pair<String, Integer>> merge = new ArrayList<>(result); // merge.forEach(pair -> System.out.println("key: " + pair.getLeft() + ": value: " + pair.getRight())); // // } // else { // System.out.println("Country list retrieved form database is empty"); // } // } else { // System.out.println("Country list retrieved form API is empty"); // } }
From source file:com.microsoft.tooling.msservices.serviceexplorer.azure.rediscache.RedisCacheModule.java
@Override protected void refreshItems() throws AzureCmdException { List<Pair<String, String>> failedSubscriptions = new ArrayList<>(); try {/* w ww . j a v a2s .c o m*/ AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager(); // not signed in if (azureManager == null) { return; } SubscriptionManager subscriptionManager = azureManager.getSubscriptionManager(); Set<String> sidList = subscriptionManager.getAccountSidList(); for (String sid : sidList) { try { Azure azure = azureManager.getAzure(sid); for (RedisCache cache : azure.redisCaches().list()) { addChildNode(new RedisCacheNode(this, sid, cache)); } } catch (Exception ex) { failedSubscriptions.add(new ImmutablePair<>(sid, ex.getMessage())); continue; } } } catch (Exception ex) { DefaultLoader.getUIHelper() .logError("An error occurred when trying to load Redis Caches\n\n" + ex.getMessage(), ex); } if (!failedSubscriptions.isEmpty()) { StringBuilder errorMessage = new StringBuilder( "An error occurred when trying to load Redis Caches for the subscriptions:\n\n"); for (Pair error : failedSubscriptions) { errorMessage.append(error.getKey()).append(": ").append(error.getValue()).append("\n"); } DefaultLoader.getUIHelper().logError( "An error occurred when trying to load Redis Caches\n\n" + errorMessage.toString(), null); } }
From source file:com.ottogroup.bi.streaming.operator.json.insert.JsonStaticContentInsertion.java
/** * @see org.apache.flink.api.common.functions.MapFunction#map(java.lang.Object) *//*w ww .j ava 2 s . c om*/ public JSONObject map(JSONObject json) throws Exception { // if no values were configured or the incoming json equals // null simply let the message go through un-processed if (json == null || values.isEmpty()) return json; // otherwise step through configuration holding static values and insert them // at referenced locations for (final Pair<JsonContentReference, Serializable> v : values) { json = insert(json, v.getKey().getPath(), v.getValue()); } return json; }