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

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

Introduction

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

Prototype

public static <L, R> ImmutablePair<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:com.wrmsr.wava.yen.translation.UnitTranslation.java

public static Function translateFunction(YFunction function, Map<Name, Signature> functionSignatures) {
    requireNonNull(function);// ww w.  jav a 2s  .  co  m
    checkArgument(function.getName().isPresent());
    checkArgument(function.getResult() != Type.UNREACHABLE);
    checkArgument(function.getBody().isPresent());
    checkArgument(function.getLocalNames().size() == function.getNumLocals());
    checkArgument(function.getLocalIndices().size() == function.getNumLocals());
    List<Pair<Name, Index>> localList = function.getLocalIndices().entrySet().stream()
            .map(e -> ImmutablePair.of(e.getKey(), e.getValue())).collect(Collectors.toList());
    localList.sort((l, r) -> l.getValue().compareTo(r.getValue()));
    checkArgument(
            enumerate(localList.stream().map(Pair::getRight)).allMatch(e -> e.getItem().get() == e.getIndex()));
    Locals locals = Locals
            .of(localList.stream().map(l -> ImmutablePair.of(l.getLeft(), function.getLocalType(l.getRight())))
                    .collect(toImmutableList()));
    Node body = NodeTranslation.translateNode(function.getBody().get(), functionSignatures);
    return new Function(function.getName().get(), function.getResult(), function.getNumParams(), locals, body);
}

From source file:edu.umich.flowfence.service.NamespaceSharedPrefs.java

private static ImmutablePair<String, String> getTypeAndKey(String key) {
    int index = key.indexOf(SEPARATOR);
    return ImmutablePair.of(key.substring(0, index), key.substring(index + 1));
}

From source file:im.dadoo.cedar.SelectCriteria.java

public SelectCriteria limit(String limit) {
    this.limits = ImmutablePair.of(Util.placeholder(limit), null);
    return this;
}

From source file:com.yahoo.bullet.storm.testing.CustomBoltDeclarer.java

@Override
public BoltDeclarer fieldsGrouping(String componentId, String streamId, Fields fields) {
    Pair<String, String> key = ImmutablePair.of(componentId, streamId);
    List<Fields> existing = fieldsGroupings.get(key);
    if (existing == null) {
        existing = new ArrayList<>();
    }//from  w  w w .  j a v  a 2s.c  o m
    existing.add(fields);
    fieldsGroupings.put(key, existing);
    return this;
}

From source file:com.netflix.imfutility.audio.SoundfieldGroupInfo.java

public void addChannels(SequenceUUID uuid, FFmpegAudioChannels[] channels)
        throws InvalidAudioChannelAssignmentException {
    for (int i = 0; i < channels.length; i++) {
        FFmpegAudioChannels channel = channels[i];
        if (channelsMap.containsKey(channel)) {
            throw new InvalidAudioChannelAssignmentException(
                    "A soundfield group must contain different channels");
        }/*from   w  w  w.j  a va2  s .c o  m*/
        channelsMap.put(channel, ImmutablePair.of(uuid, i + 1));
    }
}

From source file:im.dadoo.cedar.SelectCriteria.java

public SelectCriteria limit(String pagecount, String pagesize) {
    this.limits = ImmutablePair.of(Util.placeholder(pagecount), Util.placeholder(pagesize));
    return this;
}

From source file:forge.quest.QuestUtilUnlockSets.java

/**
 * Consider unlocking a new expansion in limited quest format.
 * @param qData the QuestController for the current quest
 * @param freeUnlock this unlock is free (e.g., a challenge reward), NOT IMPLEMENTED YET
 * @param presetChoices List<CardEdition> a pregenerated list of options, NOT IMPLEMENTED YET
 * @return CardEdition, the unlocked edition if any.
 *//*from w  ww  .ja v a2  s .co m*/
public static ImmutablePair<CardEdition, Integer> chooseSetToUnlock(final QuestController qData,
        final boolean freeUnlock, List<CardEdition> presetChoices) {

    if (qData.getFormat() == null || !qData.getFormat().canUnlockSets()) {
        return null;
    }

    final ReadPriceList prices = new ReadPriceList();
    final Map<String, Integer> mapPrices = prices.getPriceList();
    final List<ImmutablePair<CardEdition, Integer>> setPrices = new ArrayList<ImmutablePair<CardEdition, Integer>>();

    for (CardEdition ed : getUnlockableEditions(qData)) {
        int price = UNLOCK_COST;
        if (mapPrices.containsKey(ed.getName() + " Booster Pack")) {
            price = Math.max(
                    new Double(30 * Math.pow(Math.sqrt(mapPrices.get(ed.getName() + " Booster Pack")), 1.70))
                            .intValue(),
                    UNLOCK_COST);
        }
        setPrices.add(ImmutablePair.of(ed, price));
    }

    final String setPrompt = "You have " + qData.getAssets().getCredits() + " credits. Unlock:";
    List<String> options = new ArrayList<String>();
    for (ImmutablePair<CardEdition, Integer> ee : setPrices) {
        options.add(String.format("%s [PRICE: %d credits]", ee.left.getName(), ee.right));
    }

    int index = options.indexOf(SGuiChoose.oneOrNone(setPrompt, options));
    if (index < 0 || index >= options.size()) {
        return null;
    }

    ImmutablePair<CardEdition, Integer> toBuy = setPrices.get(index);

    int price = toBuy.right;
    CardEdition choosenEdition = toBuy.left;

    if (qData.getAssets().getCredits() < price) {
        SOptionPane.showMessageDialog(
                "Unfortunately, you cannot afford that set yet.\n" + "To unlock " + choosenEdition.getName()
                        + ", you need " + price + " credits.\n" + "You have only "
                        + qData.getAssets().getCredits() + " credits.",
                "Failed to unlock " + choosenEdition.getName(), null);
        return null;
    }

    if (!SOptionPane
            .showConfirmDialog(
                    "Unlocking " + choosenEdition.getName() + " will cost you " + price + " credits.\n"
                            + "You have " + qData.getAssets().getCredits() + " credits.\n\n"
                            + "Are you sure you want to unlock " + choosenEdition.getName() + "?",
                    "Confirm Unlocking " + choosenEdition.getName())) {
        return null;
    }
    return toBuy;
}

From source file:forge.limited.CustomLimited.java

/**
 * Parses the./*w  w  w.ja v  a 2  s. c  om*/
 *
 * @param dfData the df data
 * @param cubes the cubes
 * @return the custom limited
 */
public static CustomLimited parse(final List<String> dfData, final IStorage<Deck> cubes) {
    final FileSection data = FileSection.parse(dfData, ":");

    List<Pair<String, Integer>> slots = new ArrayList<Pair<String, Integer>>();
    String boosterData = data.get("Booster");
    if (StringUtils.isNotEmpty(boosterData)) {
        final String[] booster = TextUtil.splitWithParenthesis(boosterData, ',');
        for (String slotDesc : booster) {
            String[] kv = TextUtil.splitWithParenthesis(slotDesc, ' ', 2);
            slots.add(ImmutablePair.of(kv[1], Integer.parseInt(kv[0])));
        }
    } else
        slots = SealedProduct.Template.genericBooster.getSlots();

    final CustomLimited cd = new CustomLimited(data.get("Name"), slots);
    cd.landSetCode = data.get("LandSetCode");
    cd.numPacks = data.getInt("NumPacks");
    cd.singleton = data.getBoolean("Singleton");
    final Deck deckCube = cubes.get(data.get("DeckFile"));
    cd.cardPool = deckCube == null
            ? ItemPool.createFrom(FModel.getMagicDb().getCommonCards().getUniqueCards(), PaperCard.class)
            : deckCube.getMain();

    return cd;
}

From source file:com.yahoo.bullet.storm.testing.CustomBoltDeclarer.java

@Override
public BoltDeclarer allGrouping(String componentId, String streamId) {
    allGroupings.add(ImmutablePair.of(componentId, streamId));
    return this;
}

From source file:io.lavagna.web.security.SecurityFilter.java

@Override
public void init(FilterConfig filterConfig) throws ServletException {
    WebApplicationContext ctx = getRequiredWebApplicationContext(filterConfig.getServletContext());
    for (Entry<String, SecurityConfiguration> kv : ctx.getBeansOfType(SecurityConfiguration.class).entrySet()) {
        pathsToCheck.put(kv.getKey(), ImmutablePair.of(kv.getValue(), kv.getValue().buildMatcherList()));
    }/*from  w  ww  .j a  v a 2  s . c o m*/
}