Example usage for org.apache.commons.lang3.tuple Pair getValue

List of usage examples for org.apache.commons.lang3.tuple Pair getValue

Introduction

In this page you can find the example usage for org.apache.commons.lang3.tuple Pair getValue.

Prototype

@Override
public R getValue() 

Source Link

Document

Gets the value from this pair.

This method implements the Map.Entry interface returning the right element as the value.

Usage

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. ja va2  s  .  c  o m
        jspWriter.append(msg);
    } catch (IOException e) {
        e.printStackTrace();
    }

    return SKIP_BODY;
}

From source file:com.ottogroup.bi.streaming.operator.json.insert.JsonStaticContentInsertion.java

/**
 * @see org.apache.flink.api.common.functions.MapFunction#map(java.lang.Object)
 *///from www . j a  v a 2 s.  c  o  m
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;
}

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  ww .ja 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.flowpowered.api.util.SyncedStringMap.java

@SuppressWarnings("fallthrough")
public void handleUpdate(SyncedMapEvent message) {
    switch (message.getAction()) {
    case SET:/*w  ww . j  a va 2 s.  c o  m*/
        super.clear();
    case ADD:
        for (Pair<Integer, String> pair : message.getModifiedElements()) {
            store.set(pair.getValue(), pair.getKey());
        }
        break;
    case REMOVE:
        for (Pair<Integer, String> pair : message.getModifiedElements()) {
            store.remove(pair.getValue());
        }
        break;
    }
    callEvent(new SyncedMapEvent(this, message.getAction(), message.getModifiedElements()));
}

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 {/*from www . ja v  a2  s.co  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.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   w  w w . j a v  a  2 s.com
        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:cc.kave.commons.pointsto.evaluation.cv.CVEvaluator.java

public double evaluate(SetProvider setProvider) {
    List<Future<Pair<Integer, Double>>> futures = new ArrayList<>(numFolds);
    double[] evaluationResults = new double[numFolds];

    for (int i = 0; i < numFolds; ++i) {
        futures.add(executorService.submit(new FoldEvaluation(i, setProvider)));
    }//  w ww  . ja v  a 2 s  . c om

    for (int i = 0; i < evaluationResults.length; ++i) {
        try {
            Pair<Integer, Double> result = futures.get(i).get();
            evaluationResults[i] = result.getValue();
            log("\tFold %d: %.3f\n", i + 1, evaluationResults[i]);
        } catch (ExecutionException e) {
            throw new RuntimeException(e.getCause());
        } catch (InterruptedException e) {
            e.printStackTrace();
            return Double.NaN;
        }

    }

    return StatUtils.mean(evaluationResults);
}

From source file:io.gameover.utilities.pixeleditor.Frame.java

public List<Pair<Integer, Integer>> extractColors() {
    Map<Integer, Integer> m = new HashMap<>();
    for (int i = 0; i < argb.length; i++) {
        for (int j = 0; j < argb[0].length; j++) {
            int c = argb[i][j];
            if (!m.containsKey(c)) {
                m.put(c, 1);//from   w  w w .  ja v a2s . com
            } else {
                m.put(c, m.get(c) + 1);
            }
        }
    }
    List<Pair<Integer, Integer>> ret = new ArrayList<>();
    for (Integer k : m.keySet()) {
        ret.add(Pair.of(k, m.get(k)));
    }
    Collections.sort(ret, new Comparator<Pair<Integer, Integer>>() {
        @Override
        public int compare(Pair<Integer, Integer> o1, Pair<Integer, Integer> o2) {
            return o2.getValue() - o1.getValue();
        }
    });
    return ret;
}

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));
        }// ww  w .  ja va 2  s .c om
    }

    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.storagearm.StorageModule.java

@Override
protected void refresh(@NotNull EventStateHandle eventState) throws AzureCmdException {
    removeAllChildNodes();//w ww.j  a va2  s. c  o m

    AzureManager azureManager = AzureManagerImpl.getManager(getProject());
    // load all Storage Accounts
    List<Subscription> subscriptionList = azureManager.getSubscriptionList();
    List<Pair<String, String>> failedSubscriptions = new ArrayList<>();
    for (Subscription subscription : subscriptionList) {
        try {
            List<ArmStorageAccount> storageAccounts = AzureArmManagerImpl.getManager(getProject())
                    .getStorageAccounts(subscription.getId());

            if (eventState.isEventTriggered()) {
                return;
            }

            for (StorageAccount sm : storageAccounts) {
                String type = sm.getType();

                if (type.equals(StorageAccountTypes.STANDARD_GRS)
                        || type.equals(StorageAccountTypes.STANDARD_LRS)
                        || type.equals(StorageAccountTypes.STANDARD_RAGRS)
                        || type.equals(StorageAccountTypes.STANDARD_ZRS)) {

                    addChildNode(new StorageNode(this, subscription.getId(), sm));
                }
            }
        } catch (Exception ex) {
            failedSubscriptions.add(new ImmutablePair<>(subscription.getName(), ex.getMessage()));
            continue;
        }
    }

    // load External Accounts
    for (ClientStorageAccount clientStorageAccount : ExternalStorageHelper.getList(getProject())) {
        ClientStorageAccount storageAccount = StorageClientSDKManagerImpl.getManager()
                .getStorageAccount(clientStorageAccount.getConnectionString());

        if (eventState.isEventTriggered()) {
            return;
        }

        //            addChildNode(new ExternalStorageNode(this, storageAccount));
    }
    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);
    }
}