Example usage for org.apache.commons.lang3.tuple ImmutablePair ImmutablePair

List of usage examples for org.apache.commons.lang3.tuple ImmutablePair ImmutablePair

Introduction

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

Prototype

public ImmutablePair(final L left, final R right) 

Source Link

Document

Create a new pair instance.

Usage

From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails.java

public Integer getLatestEnabledVersion() {
    List<Integer> versions = new ArrayList<>(instances.keySet());
    if (!versions.isEmpty()) {
        versions.sort(Integer::compareTo);
        versions.sort(Comparator.reverseOrder());
    }/*from   w ww .j a v a 2 s.  c  o  m*/

    return versions.stream().map(i -> new ImmutablePair<>(i, instances.get(i)))
            .filter(is -> is.getRight().stream().allMatch(i -> i.isHealthy() && i.isRunning())).findFirst()
            .orElse(new ImmutablePair<>(null, null)).getLeft();
}

From source file:com.intuit.quickbase.MergeStatService.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();

    //Use of Predicate Interface
    Predicate<Pair<String, Integer>> pred = (pair) -> pair != null;

    if (apiList != null) {
        // Converting the keys of each element in the API list to lowercase
        List<Pair<String, Integer>> modifiedAPIList = apiList.stream().filter(pred)
                .map(p -> new ImmutablePair<String, Integer>(p.getKey().toLowerCase(), p.getValue()))
                .collect(Collectors.toList());
        //modifiedAPIList.forEach(pair -> 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)/* ww  w. j av  a 2 s . c  o  m*/
                    .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.getKey() + ": value: " + pair.getValue()));

        } else {
            System.out.println("Country list retrieved form database is empty");
        }
    } else {
        System.out.println("Country list retrieved form API is empty");
    }

    //            if(apiList != null) {
    //                Iterator itr = apiList.iterator();
    //                for(Pair<String, Integer> pair : apiList){                    
    //                    //System.out.println("key: " + pair.getLeft() + ": value: " + pair.getRight());
    //                }                
    //            }    

}

From source file:eu.bittrade.libs.steemj.BaseIT.java

/**
 * Call this method in case the tests should be fired against a WebSocket
 * endpoint instead of using the default HTTPS endpoint.
 * /*from  ww w. j  a v  a  2 s.c  om*/
 * @throws URISyntaxException
 *             If the URL is wrong.
 */
public static void configureSteemWebSocketEndpoint() throws URISyntaxException {
    ArrayList<Pair<URI, Boolean>> endpoints = new ArrayList<>();

    ImmutablePair<URI, Boolean> webSocketEndpoint;
    webSocketEndpoint = new ImmutablePair<>(new URI("wss://steemd.steemit.com"), true);

    endpoints.add(webSocketEndpoint);
    config.setEndpointURIs(endpoints);
}

From source file:com.yahoo.bard.webservice.druid.model.aggregation.CountAggregation.java

/**
 * Nesting a 'count' aggregation changes the outer aggregation
 * to a 'longSum' whereas the inner aggregation remains unchanged.
 * Base class aggregation transformation is also performed.
 *//*  w  w  w .ja v  a  2 s.  c o  m*/
@Override
public Pair<Aggregation, Aggregation> nest() {
    String nestingName = getName();
    Aggregation inner = withName(nestingName);
    Aggregation outer = new LongSumAggregation(getName(), nestingName);
    return new ImmutablePair<>(outer, inner);
}

From source file:fi.jgke.miniplc.unit.VariableTest.java

@Test
public void typeSanity() {
    List<Pair<VariableType, Object>> types = new ArrayList<>();
    types.add(new ImmutablePair<>(VariableType.BOOL, "str"));
    types.add(new ImmutablePair<>(VariableType.BOOL, 5));
    types.add(new ImmutablePair<>(VariableType.BOOL, null));
    types.add(new ImmutablePair<>(VariableType.STRING, true));
    types.add(new ImmutablePair<>(VariableType.STRING, 5));
    types.add(new ImmutablePair<>(VariableType.STRING, null));
    types.add(new ImmutablePair<>(VariableType.INT, true));
    types.add(new ImmutablePair<>(VariableType.INT, "str"));
    types.add(new ImmutablePair<>(VariableType.INT, null));
    for (Pair<VariableType, Object> p : types) {
        try {/* w  w  w.  jav a2  s  .  c  o m*/
            createVariable(p.getLeft(), p.getRight());
            assertTrue(false);
        } catch (TypeException e) {
            assertNotNull(p.getRight());
        } catch (IllegalStateException e) {
            assertNull(p.getRight());
        }
    }
}

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));
        }//  w w w.j a v  a 2s  . c o 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.trenako.utility.PeriodUtils.java

static Pair<String, Integer> period(DateTime start, DateTime now) {
    Pair<String, Integer> p;

    p = periodValue(yearsBetween(start, now));
    if (p != null) {
        return p;
    }/*from  ww  w.  j a v  a2s.  c o  m*/

    p = periodValue(monthsBetween(start, now));
    if (p != null) {
        return p;
    }

    p = periodValue(weeksBetween(start, now));
    if (p != null) {
        return p;
    }

    p = periodValue(daysBetween(start, now));
    if (p != null) {
        return p;
    }

    p = periodValue(hoursBetween(start, now));
    if (p != null) {
        return p;
    }

    p = periodValue(minutesBetween(start, now));
    if (p != null) {
        return p;
    }

    return new ImmutablePair<>("interval.minutes.one.label", 1);
}

From source file:eu.nerdz.api.impl.fastreverse.messages.FastReverseConversation.java

public Pair<String, Boolean> getLastMessageInfo() {
    return new ImmutablePair<String, Boolean>(this.mLastMessage, this.mLastWasOther);
}

From source file:net.mindengine.blogix.utils.BlogixUtils.java

private static Pair<Class<?>, Method> findClassAndMethod(ClassLoader[] classLoaders, String classPath,
        String methodName, String[] defaultPackages) {
    Class<?> controllerClass = null;

    for (String defaultPackage : defaultPackages) {
        try {//from  w ww  .j a v  a 2s.  co m
            controllerClass = findClassInClassLoaders(classLoaders, defaultPackage + "." + classPath);
            break;
        } catch (Exception e) {
        }

    }
    if (controllerClass == null) {
        try {
            controllerClass = Class.forName(classPath);
        } catch (ClassNotFoundException e) {
            throw new RouteParserException("Cannot find a class for controller: " + classPath);
        }
    }

    Method method = findMethodInClass(controllerClass, methodName);
    if (method != null) {
        return new ImmutablePair<Class<?>, Method>(controllerClass, method);
    } else
        throw new RouteParserException(
                "Cannot find method '" + methodName + "' for controller " + controllerClass.getName());
}

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();
}