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

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

Introduction

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

Prototype

public static <L, R> Pair<L, R> of(final L left, final R right) 

Source Link

Document

Obtains an immutable pair of from two objects inferring the generic types.

This factory allows the pair to be created using inference to obtain the generic types.

Usage

From source file:cc.recommenders.evaluation.OutputUtils.java

public void count(ICoReTypeName type, int foldNum, int num) {
    Pair<ICoReTypeName, Integer> p = Pair.of(type, foldNum);
    if (!alreadyCounted.contains(p)) {
        alreadyCounted.add(p);/*from  w w  w. j  ava2s .co m*/
        if (typeTotals.containsKey(type)) {
            int oldNum = typeTotals.get(type);
            typeTotals.put(type, oldNum + num);
        } else {
            typeTotals.put(type, num);
        }
        typeNums.put(type, num);
    }
}

From source file:net.minecraftforge.client.model.pipeline.LightUtil.java

public static void putBakedQuad(IVertexConsumer consumer, BakedQuad quad) {
    try {/*from  ww w.j  a  va2s.c  o m*/
        consumer.setTexture(quad.getSprite());
    } catch (AbstractMethodError e) {
        // catch missing method errors caused by change to IVertexConsumer
    }
    consumer.setQuadOrientation(quad.getFace());
    if (quad.hasTintIndex()) {
        consumer.setQuadTint(quad.getTintIndex());
    }
    consumer.setApplyDiffuseLighting(quad.shouldApplyDiffuseLighting());
    //int[] eMap = mapFormats(consumer.getVertexFormat(), DefaultVertexFormats.ITEM);
    float[] data = new float[4];
    VertexFormat formatFrom = consumer.getVertexFormat();
    VertexFormat formatTo = quad.getFormat();
    int countFrom = formatFrom.getElementCount();
    int countTo = formatTo.getElementCount();
    int[] eMap = formatMaps.getUnchecked(Pair.of(formatFrom, formatTo));
    for (int v = 0; v < 4; v++) {
        for (int e = 0; e < countFrom; e++) {
            if (eMap[e] != countTo) {
                unpack(quad.getVertexData(), data, quad.getFormat(), v, eMap[e]);
                consumer.put(e, data);
            } else {
                consumer.put(e);
            }
        }
    }
}

From source file:com.github.steveash.jg2p.aligntag.AlignTagModel.java

private List<Pair<String, String>> makeGraphemes(Word x, Sequence<Object> outSeq) {
    List<String> letters = x.getValue();
    Preconditions.checkArgument(outSeq.size() == letters.size());
    ArrayList<Pair<String, String>> result = Lists.newArrayListWithCapacity(letters.size());

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < letters.size(); i++) {
        if (sb.length() > 0) {
            sb.append(' ');
        }//  w  w w . j ava 2s .c  o  m
        sb.append(letters.get(i));
        if (outSeq.get(i).equals("1")) {
            result.add(Pair.of(sb.toString(), ""));
            sb.delete(0, sb.length());
        }
    }
    if (sb.length() > 0) {
        result.add(Pair.of(sb.toString(), ""));
    }
    return result;
}

From source file:com.yahoo.elide.parsers.state.RecordTerminalState.java

@Override
public Supplier<Pair<Integer, JsonNode>> handlePatch(StateContext state) {
    final JsonNode empty = JsonNodeFactory.instance.nullNode();
    JsonApiDocument jsonApiDocument = state.getJsonApiDocument();

    Data<Resource> data = jsonApiDocument.getData();

    if (data == null) {
        throw new InvalidEntityBodyException("Expected data but found null");
    }//w  ww  .ja va2s  .c o  m

    if (data.get() instanceof SingleElementSet) {
        Resource resource = data.get().iterator().next();
        if (record.matchesId(resource.getId())) {
            patch(data.get().iterator().next(), state.getRequestScope());
            return () -> Pair.of(HttpStatus.SC_NO_CONTENT, empty);
        }
    }
    throw new InvalidEntityBodyException("Expected single element but found list");
}

From source file:com.uber.hoodie.common.util.collection.converter.HoodieRecordConverter.java

@Override
public byte[] getBytes(HoodieRecord hoodieRecord) {
    try {//from  w w w .j  a  v  a  2s. com
        // Need to initialize this to 0 bytes since deletes are handled by putting an empty record in HoodieRecord
        byte[] val = new byte[0];
        if (hoodieRecord.getData().getInsertValue(schema).isPresent()) {
            val = HoodieAvroUtils
                    .avroToBytes((GenericRecord) hoodieRecord.getData().getInsertValue(schema).get());
        }
        byte[] currentLocation = hoodieRecord.getCurrentLocation() != null
                ? SerializationUtils.serialize(hoodieRecord.getCurrentLocation())
                : new byte[0];
        byte[] newLocation = hoodieRecord.getNewLocation().isPresent()
                ? SerializationUtils.serialize((HoodieRecordLocation) hoodieRecord.getNewLocation().get())
                : new byte[0];

        // Triple<Pair<RecordKey, PartitionPath>, Pair<oldLocation, newLocation>, data>
        Triple<Pair<String, String>, Pair<byte[], byte[]>, byte[]> data = Triple.of(
                Pair.of(hoodieRecord.getKey().getRecordKey(), hoodieRecord.getKey().getPartitionPath()),
                Pair.of(currentLocation, newLocation), val);
        return SerializationUtils.serialize(data);
    } catch (IOException io) {
        throw new HoodieNotSerializableException("Cannot serialize value to bytes", io);
    }
}

From source file:com.blacklocus.jres.handler.JresJsonResponseHandler.java

<RESPONSE extends JresReply> Pair<JsonNode, RESPONSE> read(HttpResponse http, Class<RESPONSE> responseClass) {
    if (http.getEntity() == null) {
        return null;

    } else {//from www  .  j  a va 2 s .  co  m
        ContentType contentType = ContentType.parse(http.getEntity().getContentType().getValue());
        if (ContentType.APPLICATION_JSON.getMimeType().equals(contentType.getMimeType())) {
            try {

                JsonNode node = ObjectMappers.fromJson(http.getEntity().getContent(), JsonNode.class);
                if (LOG.isDebugEnabled()) {
                    LOG.debug(ObjectMappers.toJson(node));
                }
                return Pair.of(node,
                        responseClass == null ? null : ObjectMappers.fromJson(node, responseClass));

            } catch (IOException e) {
                throw new RuntimeException(e);
            }

        } else {
            throw new RuntimeException("Unable to read content with " + contentType
                    + ". This ResponseHandler can only decode " + ContentType.APPLICATION_JSON);
        }
    }
}

From source file:at.beris.virtualfile.shell.Shell.java

private Pair<Command, List<String>> parseCommandLine(String line) {
    List<String> lineParts = new LinkedList<>(Arrays.asList(line.split(" ")));

    for (Command availCmd : Command.values()) {
        if (availCmd.toString().equals(lineParts.get(0).toUpperCase())) {
            lineParts.remove(0);/*from   w w w  .jav  a2 s. c o m*/
            return Pair.of(availCmd, lineParts);
        }
    }
    return Pair.of(Command.UNKNOWN, Collections.<String>emptyList());
}

From source file:forge.game.GameOutcome.java

public GameOutcome(GameEndReason reason, final Iterable<Player> list) {
    winCondition = reason;//from   w  w w  . j  a v a2 s .  c om
    players = list;
    for (final Player n : list) {
        this.playerRating.add(Pair.of(n.getLobbyPlayer(), n.getStats()));
    }
    calculateLifeDelta();
}

From source file:com.snaplogic.snaps.checkfree.soapsuggestions.AbstractSuggestions.java

@Override
public void suggest(SuggestionBuilder suggestionBuilder, PropertyValues propertyValues) {
    Object wsdlUrlObject = propertyValues.get(PROP_WSDL_URL);
    Object serviceNameObject = propertyValues.get(PROP_SERVICE);
    Object portNameObject = propertyValues.get(PROP_ENDPOINT);
    isTrustAll = Boolean.TRUE.equals(propertyValues.get(CheckfreeExecute.TRUST_ALL_CERTS_PROP));
    List<Map<String, Object>> httpHeader = propertyValues.get(PropertiesTemplate.HTTP_HEADER_PROP);
    List<Pair<ExpressionProperty, ExpressionProperty>> httpHeaders = new ArrayList<>();
    List<Header> headerList = new ArrayList<>();
    if (httpHeader != null) {
        for (Map<String, Object> item : httpHeader) {
            ExpressionProperty keyProp = propertyValues.getExpressionPropertyFor(item,
                    PropertiesTemplate.HEADER_KEY_PROP);
            ExpressionProperty valueProp = propertyValues.getExpressionPropertyFor(item,
                    PropertiesTemplate.HEADER_VALUE_PROP);
            httpHeaders.add(Pair.of(keyProp, valueProp));
            Map<String, Object> keyMap = (Map<String, Object>) item.get(PropertiesTemplate.HEADER_KEY_PROP);
            Map<String, Object> valueMap = (Map<String, Object>) item.get(PropertiesTemplate.HEADER_VALUE_PROP);
            String headerKey = (String) keyMap.get(VALUE);
            String headerValue = (String) valueMap.get(VALUE);
            if (!StringUtils.isEmpty(headerKey) && !StringUtils.isEmpty(headerValue)) {
                headerList.add(new BasicHeader(headerKey, headerValue));
            }//from  w  w  w.j  a v  a  2  s. c  o  m
        }
    }
    if (wsdlUrlObject != null && wsdlUrlObject instanceof String) {
        if (validateSettings(wsdlUrlObject, serviceNameObject, portNameObject, suggestionBuilder)) {
            String wsdlUrl = (String) wsdlUrlObject;
            String serviceName = (String) serviceNameObject;
            String portName = (String) portNameObject;
            // build Headers from configuration, default accept type to text/xml
            Header[] suggestHeaders = headerList.toArray(new Header[0]);
            getSuggestion(suggestionBuilder, wsdlUrl, serviceName, portName, suggestHeaders);
        }
    } else {
        suggestionBuilder.node(nodeKey).suggestions(WSDL_MUST_BE_DEFINED_FIRST);
    }
}

From source file:com.act.lcms.db.analysis.AnalysisHelper.java

private static <A, B> Pair<List<A>, List<B>> split(List<Pair<A, B>> lpairs) {
    List<A> a = new ArrayList<>();
    List<B> b = new ArrayList<>();
    for (Pair<A, B> p : lpairs) {
        a.add(p.getLeft());// w  w w  .  j a  v  a2 s. c o  m
        b.add(p.getRight());
    }
    return Pair.of(a, b);
}