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

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

Introduction

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

Prototype

public abstract R getRight();

Source Link

Document

Gets the right element from this pair.

When treated as a key-value pair, this is the value.

Usage

From source file:com.bitranger.parknshop.common.recommend.util.Functional.java

public static <T> Function<Pair<?, T>, T> pairRight() {
    return new Function<Pair<?, T>, T>() {
        @Nullable//from www  . java 2s  .c o  m
        @Override
        public T apply(@Nullable Pair<?, T> input) {
            if (input == null) {
                return null;
            } else {
                return input.getRight();
            }
        }
    };
}

From source file:com.github.aptd.simulation.ui.CHTTPServer.java

/**
 * register agent if server started/* w  ww.  j a  v  a 2s.  com*/
 *
 * @param p_agentgroup tupel of agent and stream of group names
 * @return agent object
 * @tparam T agent type
 */
public static <T extends IElement<?>> T register(final Pair<T, Stream<String>> p_agentgroup) {
    return register(p_agentgroup.getLeft(), p_agentgroup.getRight().toArray(String[]::new));
}

From source file:com.intuit.karate.JsonUtils.java

public static void setValueByPath(DocumentContext doc, String path, Object value) {
    if ("$".equals(path)) {
        throw new RuntimeException("cannot replace root path $");
    }//from  w  ww .  j  a  v  a  2  s  .c o  m
    Pair<String, String> pathLeaf = getParentAndLeafPath(path);
    String left = pathLeaf.getLeft();
    String right = pathLeaf.getRight();
    if (right.endsWith("]")) { // json array
        int indexPos = right.lastIndexOf('[');
        int index = Integer.valueOf(right.substring(indexPos + 1, right.length() - 1));
        right = right.substring(0, indexPos);
        List list;
        String listPath = left + "." + right;
        try {
            list = doc.read(listPath);
            if (index < list.size()) {
                list.set(index, value);
            } else {
                list.add(value);
            }
        } catch (Exception e) {
            logger.trace("will create non-existent path: {}", listPath);
            list = new ArrayList();
            list.add(value);
            doc.put(left, right, list);
        }
    } else {
        doc.put(left, right, value);
    }
    logger.trace("after set: {}", doc.jsonString());
}

From source file:ivorius.ivtoolkit.rendering.grid.BlockQuadCache.java

public static GridQuadCache<?> createQuadCache(final IvBlockCollection blockCollection, float[] scale) {
    final Object handle = new Object();

    final int[] size = { blockCollection.width, blockCollection.height, blockCollection.length };

    return GridQuadCache.createQuadCache(size, scale, new Function<Pair<BlockCoord, ForgeDirection>, Object>() {
        @Nullable//from w  ww  . j  a  v a2s  . c om
        @Override
        public Object apply(Pair<BlockCoord, ForgeDirection> input) {
            Block block = blockCollection.getBlock(input.getLeft());
            return block.isOpaqueCube() && blockCollection.shouldRenderSide(input.getLeft(), input.getRight())
                    ? handle
                    : null;
        }
    });
}

From source file:enumj.EnumeratorTimingTestBase.java

public static int percentage(Pair<Long, Long> result) {
    return percentage(result.getLeft(), result.getRight());
}

From source file:com.github.steveash.guavate.ObjIntPair.java

/**
 * Obtains an instance from a {@code Pair}.
 *
 * @param <A> the first element type
 * @param pair  the pair to convert//from ww  w . j a v  a2s .c om
 * @return a pair formed by extracting values from the pair
 */
public static <A> ObjIntPair<A> ofPair(Pair<A, Integer> pair) {
    Preconditions.checkNotNull(pair, "pair");
    return new ObjIntPair<A>(pair.getLeft(), pair.getRight());
}

From source file:com.github.rvesse.airline.parser.ParserUtil.java

@SuppressWarnings("unchecked")
public static <T> T injectOptions(T commandInstance, Iterable<OptionMetadata> options,
        List<Pair<OptionMetadata, Object>> parsedOptions, ArgumentsMetadata arguments,
        Iterable<Object> parsedArguments, Iterable<Accessor> metadataInjection,
        Map<Class<?>, Object> bindings) {
    // inject options
    for (OptionMetadata option : options) {
        List<Object> values = new ArrayList<>();
        for (Pair<OptionMetadata, Object> parsedOption : parsedOptions) {
            if (option.equals(parsedOption.getLeft()))
                values.add(parsedOption.getRight());
        }/*from w  w w.jav a 2 s.  c  o  m*/
        if (values != null && !values.isEmpty()) {
            for (Accessor accessor : option.getAccessors()) {
                accessor.addValues(commandInstance, values);
            }
        }
    }

    // inject args
    if (arguments != null && parsedArguments != null) {
        for (Accessor accessor : arguments.getAccessors()) {
            accessor.addValues(commandInstance, parsedArguments);
        }
    }

    for (Accessor accessor : metadataInjection) {
        Object injectee = bindings.get(accessor.getJavaType());

        if (injectee != null) {
            accessor.addValues(commandInstance,
                    ListUtils.unmodifiableList(AirlineUtils.singletonList(injectee)));
        }
    }

    return commandInstance;
}

From source file:cn.lambdalib.util.client.font.Fragmentor.java

public static List<String> toMultiline(String str, IFontSizeProvider font, double local_x, double limit) {
    Fragmentor frag = new Fragmentor(str);
    List<String> ret = new ArrayList<>();

    StringBuilder builder = new StringBuilder();
    while (frag.hasNext()) {
        Pair<TokenType, String> next = frag.next();
        TokenType type = next.getLeft();
        String content = next.getRight();
        double len = font.getTextWidth(content);
        if (local_x + len > limit) {
            if (!type.canSplit) { // Draws as whole in next line
                if (builder.length() > 0) {
                    ret.add(builder.toString());
                }//from w  w  w.  j a  v  a  2  s.com
                builder.setLength(0);
                builder.append(content);
                local_x = len;
            } else { // Seperate to this line and next line
                while (!content.isEmpty()) {
                    double acc = 0.0;
                    int i = 0;
                    for (; i < content.length() && local_x + acc <= limit; ++i) {
                        acc += font.getCharWidth(content.charAt(i));
                    }

                    if (i < content.length() && isPunct(content.charAt(i))) {
                        ++i;
                    }

                    builder.append(content.substring(0, i));
                    String add = builder.toString();
                    ret.add(add);

                    builder.setLength(0);
                    local_x = 0;

                    content = content.substring(i);
                }
            }
        } else {
            builder.append(content);
            local_x += len;
        }
    }

    if (builder.length() > 0) {
        ret.add(builder.toString());
    }

    return ret;
}

From source file:eu.openanalytics.rsb.SuiteITCase.java

private static void putTestFileInCatalog(final CatalogSection catalogSection, final String fileName)
        throws IOException {
    final Pair<PutCatalogFileResult, File> putResult = catalogManager.putCatalogFile(catalogSection, "ignored",
            fileName, AbstractITCase.getTestData(fileName));

    catalogTestFiles.add(putResult.getRight());
}

From source file:de.unentscheidbar.validation.internal.Methods.java

public static MethodChain findMethod(Class<?> clazz, List<Pair<String, Class<?>>> candidates,
        String... propertyHierarchy) {

    MethodChain result = null;/*w ww .jav a  2s.  com*/
    for (Pair<String, Class<?>> candidate : candidates) {
        String methodName = candidate.getLeft();
        List<Class<?>> parameterType = Collections.<Class<?>>singletonList(candidate.getRight());

        result = findMethod(clazz, methodName, parameterType, propertyHierarchy);
        if (result != null)
            break;
    }
    return result;
}