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.addthis.hydra.job.store.CachedSpawnDataStore.java

public CachedSpawnDataStore(SpawnDataStore dataStore, long dataStoreCacheSize) {
    this.dataStore = dataStore;
    this.cache = CacheBuilder.newBuilder().weigher(new Weigher<Pair<String, String>, String>() {
        @Override//from w w w  . j av a 2  s.  c om
        public int weigh(Pair<String, String> key, String value) {
            int leftWeight = key.getLeft() != null ? key.getLeft().length() : 0;

            int rightWeight = key.getRight() != null ? key.getRight().length() : 0;

            // Multiply strlen by 2 (full width characters in java
            return 2 * (value.length() + leftWeight + rightWeight);
        }
    }).maximumWeight(dataStoreCacheSize).build(new CacheLoader<Pair<String, String>, String>() {
        @Override
        public String load(Pair<String, String> key) throws Exception {
            String path = key.getLeft();
            String childId = key.getRight();

            if (childId == null) {
                return CachedSpawnDataStore.this.dataStore.get(path);
            } else {
                return CachedSpawnDataStore.this.dataStore.getChild(path, childId);
            }
        }
    });
}

From source file:controllers.admin.AttachmentsController.java

/**
 * The attachments management main page. Displays a table with the list of all attachments across the application.
 *//*from   w  w  w  .  ja v  a2s .c o m*/
public Result index() {
    String uid = getUserSessionManagerPlugin().getUserSessionId(ctx());
    FilterConfig<AttachmentManagementListView> filterConfig = this.getTableProvider().get().attachmentManagement
            .getResetedFilterConfig().getCurrent(uid, request());

    Pair<Table<AttachmentManagementListView>, Pagination<Attachment>> t = getTable(filterConfig);

    return ok(views.html.admin.attachments.attachments_index.render(t.getLeft(), t.getRight(), filterConfig));
}

From source file:edu.uci.ics.hyracks.api.job.ActivityCluster.java

public ActivityId getConsumerActivity(ConnectorDescriptorId cdId) {
    Pair<Pair<IActivity, Integer>, Pair<IActivity, Integer>> connEdge = connectorActivityMap.get(cdId);
    return connEdge.getRight().getLeft().getActivityId();
}

From source file:edu.wpi.checksims.algorithm.similaritymatrix.output.MatrixToCSVPrinter.java

/**
 * Print a Similarity Matrix in CSV format.
 *
 * @param matrix Matrix to print/*ww  w  .j  a  v  a 2 s. c om*/
 * @return CSV representation of matrix
 * @throws InternalAlgorithmError Thrown on internal error processing matrix
 */
@Override
public String printMatrix(SimilarityMatrix matrix) throws InternalAlgorithmError {
    checkNotNull(matrix);

    StringBuilder builder = new StringBuilder();
    DecimalFormat formatter = new DecimalFormat("0.00");

    Pair<Integer, Integer> arrayBounds = matrix.getArrayBounds();

    // First row: NULL, then all the Y submissions, comma-separated
    builder.append("NULL,");
    for (int y = 0; y < arrayBounds.getRight(); y++) {
        builder.append("\"");
        builder.append(matrix.getYSubmission(y).getName());
        builder.append("\"");
        if (y != (arrayBounds.getRight() - 1)) {
            builder.append(",");
        } else {
            builder.append("\n");
        }
    }

    // Remaining rows: X label, then all Y results in order
    for (int x = 0; x < arrayBounds.getLeft(); x++) {
        // First, append name of the X submission
        builder.append("\"");
        builder.append(matrix.getXSubmission(x).getName());
        builder.append("\",");

        // Next, append all the matrix values, formatted as given
        for (int y = 0; y < arrayBounds.getRight(); y++) {
            builder.append(formatter.format(matrix.getEntryFor(x, y).getSimilarityPercent()));
            if (y != (arrayBounds.getRight() - 1)) {
                builder.append(",");
            } else {
                builder.append("\n");
            }
        }
    }

    return builder.toString();
}

From source file:io.lavagna.service.ListValueMetadataRepositoryTest.java

@Test
public void findAll() {

    Pair<LabelListValue, LabelListValue> llvp = createLabelListValue();

    List<Integer> labelListValueIds = Arrays.asList(llvp.getLeft().getId(), llvp.getRight().getId());

    Assert.assertEquals(0, listValueMetadataQuery.findByLabelListValueIds(labelListValueIds).size());

    listValueMetadataQuery.insert(llvp.getLeft().getId(), "KEY", "VALUE");

    Assert.assertEquals(1, listValueMetadataQuery.findByLabelListValueIds(labelListValueIds).size());

    listValueMetadataQuery.insert(llvp.getRight().getId(), "KEY", "VALUE");

    Assert.assertEquals(2, listValueMetadataQuery.findByLabelListValueIds(labelListValueIds).size());
}

From source file:cherry.foundation.code.CodeManagerImpl.java

@Override
public void afterPropertiesSet() {
    entryCache = CacheBuilder.from(entryCacheSpec).build(new CacheLoader<Pair<String, String>, CodeEntry>() {
        @Override/*from ww  w  . j  a  v a 2s  . c  o m*/
        public CodeEntry load(Pair<String, String> key) {
            return ObjectUtils.firstNonNull(codeStore.findByValue(key.getLeft(), key.getRight()), nullEntry);
        }
    });
    listCache = CacheBuilder.from(listCacheSpec).build(new CacheLoader<String, List<CodeEntry>>() {
        @Override
        public List<CodeEntry> load(String key) {
            return codeStore.getCodeList(key);
        }
    });
}

From source file:com.netflix.genie.web.data.entities.AgentConnectionEntityTest.java

/**
 * Verify validated fields value.//  w ww.  j a  v a 2 s  .  com
 */
@Test
public void cantCreateAgentConnectionEntityDueToSize() {

    final List<Pair<String, String>> invalidParameterPairs = Lists.newArrayList();

    invalidParameterPairs.add(Pair.of(JOB, null));
    invalidParameterPairs.add(Pair.of(null, HOST));
    invalidParameterPairs.add(Pair.of(JOB, " "));
    invalidParameterPairs.add(Pair.of(" ", HOST));
    invalidParameterPairs.add(Pair.of(StringUtils.rightPad(JOB, 256), HOST));
    invalidParameterPairs.add(Pair.of(JOB, StringUtils.rightPad(HOST, 256)));

    for (final Pair<String, String> invalidParameters : invalidParameterPairs) {
        final AgentConnectionEntity entity = new AgentConnectionEntity(invalidParameters.getLeft(),
                invalidParameters.getRight());

        try {
            this.validate(entity);
        } catch (final ConstraintViolationException e) {
            // Expected, move on to the next pair.
            continue;
        }

        Assert.fail("Entity unexpectedly passed validation: " + entity.toString());
    }
}

From source file:com.pinterest.terrapin.client.FileSetViewManagerTest.java

@Test
public void testWithBackup() throws Exception {
    boolean exception = false;
    try {/*w  ww.j a  va2 s. co  m*/
        manager.getFileSetViewInfo(FILE_SET);
    } catch (TerrapinGetException e) {
        assertEquals(TerrapinGetErrorCode.FILE_SET_NOT_FOUND, e.getErrorCode());
        exception = true;
    }
    assertTrue(exception);
    // Now, a fileset watch is triggered but the external view is not triggered.
    FileSetInfo fsInfo1 = new FileSetInfo("file_set", "/terrapin/data/file_set/1", 1,
            (List) Lists.newArrayList(), new Options());
    triggerFileSetInfoWatch(FILE_SET, fsInfo1);
    exception = false;
    try {
        manager.getFileSetViewInfo(FILE_SET);
    } catch (TerrapinGetException e) {
        assertEquals(TerrapinGetErrorCode.INVALID_FILE_SET_VIEW, e.getErrorCode());
        exception = true;
    }
    assertTrue(exception);

    // Now the watch for the first view is triggered.
    ExternalView externalView1 = new ExternalView("$terrapin$data$file_set$1");
    externalView1.setStateMap("0", ImmutableMap.of("host1", "ONLINE"));
    ViewInfo viewInfo1 = new ViewInfo(externalView1);
    triggerViewInfoWatch(viewInfo1);

    Pair<FileSetInfo, ViewInfo> pair = manager.getFileSetViewInfo(FILE_SET);
    assertEquals(fsInfo1, pair.getLeft());
    assertEquals(viewInfo1, pair.getRight());

    // The fileset info alone gets updated but the other watch is not yet triggered.
    FileSetInfo fsInfo2 = new FileSetInfo(FILE_SET, "/terrapin/data/file_set/2", 1, (List) Lists.newArrayList(),
            new Options());
    triggerFileSetInfoWatch(FILE_SET, fsInfo2);
    pair = manager.getFileSetViewInfo(FILE_SET);
    // We should see the view from the backup only.
    assertEquals(fsInfo1, pair.getLeft());
    assertEquals(viewInfo1, pair.getRight());

    // Finally, a watch is triggered for the resource corresponding to the second fileset.
    ExternalView externalView2 = new ExternalView("$terrapin$data$file_set$2");
    externalView2.setStateMap("0", ImmutableMap.of("host2", "ONLINE"));
    ViewInfo viewInfo2 = new ViewInfo(externalView2);
    triggerViewInfoWatch(viewInfo2);

    pair = manager.getFileSetViewInfo(FILE_SET);
    assertEquals(fsInfo2, pair.getLeft());
    assertEquals(viewInfo2, pair.getRight());

    // Watches execute in the correct order. Firs the view is propagated.
    ExternalView externalView3 = new ExternalView("$terrapin$data$file_set$3");
    externalView3.setStateMap("0", ImmutableMap.of("host3", "ONLINE"));
    ViewInfo viewInfo3 = new ViewInfo(externalView3);
    triggerViewInfoWatch(viewInfo3);

    // We should still continue to serve previous view.
    pair = manager.getFileSetViewInfo(FILE_SET);
    assertEquals(fsInfo2, pair.getLeft());
    assertEquals(viewInfo2, pair.getRight());

    // Finally, the fileset version update watch is propagated.
    FileSetInfo fsInfo3 = new FileSetInfo(FILE_SET, "/terrapin/data/file_set/3", 1, (List) Lists.newArrayList(),
            new Options());
    triggerFileSetInfoWatch(FILE_SET, fsInfo3);

    pair = manager.getFileSetViewInfo(FILE_SET);
    assertEquals(fsInfo3, pair.getLeft());
    assertEquals(viewInfo3, pair.getRight());
}

From source file:name.martingeisse.phunky.runtime.code.expression.array.ArrayConstructionExpression.java

@Override
public Object evaluate(Environment environment) {
    PhpVariableArray builder = new PhpVariableArray();
    for (Pair<Expression, Expression> element : elements) {
        boolean hasKey = (element.getLeft() != null);
        Object originalKey = (hasKey ? element.getLeft().evaluate(environment) : null);
        Object value = element.getRight().evaluate(environment);
        if (!hasKey) {
            builder.append().setValue(value);
        } else {/*from   ww  w . j  a v  a2  s  . c om*/
            String key = TypeConversionUtil.convertToArrayKey(originalKey);
            builder.getOrCreateVariable(key).setValue(value);
        }
    }
    return builder.toValueArray();
}

From source file:com.foudroyantfactotum.mod.fousarchive.command.CommandPianoRollID.java

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    try {//from  ww w.j  a va 2 s .  c  o m
        final List<Pair<SearchMatch, String>> pt = parse(getAsSingleString(args));
        if (pt.size() > 10)
            throw new CommandException("Too many matches");
        if (pt.size() == 0)
            pt.add(Pair.of(SearchMatch.Title, ""));

        final List<Predicate<MidiDetails>> func = new ArrayList<>(pt.size());
        final List<SearchMatch> outfString = new LinkedList<>();

        for (Pair<SearchMatch, String> p : pt) {
            func.add(p.getLeft().checkDetails(p.getRight()));
            outfString.add(p.getLeft());
        }

        final ResourceLocation[] songList = LiveMidiDetails.INSTANCE.songDetails();
        final List<Pair<ResourceLocation, MidiDetails>> validList = new LinkedList<>();

        sender.addChatMessage(new TextComponentString("==========Searching=========="));

        song: for (int i = 0; i < songList.length; ++i) {
            final MidiDetails song = LiveMidiDetails.INSTANCE.getDetailsOnSong(songList[i]);

            for (Predicate<MidiDetails> p : func)
                if (!p.test(song))
                    continue song;

            validList.add(Pair.of(songList[i], song));
        }
        int i = 0;

        for (Pair<ResourceLocation, MidiDetails> m : validList)
            sender.addChatMessage(new TextComponentString(
                    "\u00A7l" + (++i) + ". \u00A7r\u00A7o" + toStringer(m.getRight(), outfString) + "\u00A7r"));

        sender.addChatMessage(new TextComponentString("=========End  Search========="));

        if (validList.size() == 1) {
            final BlockPos sp = sender.getPosition();
            final ItemStack stack = new ItemStack(ModItems.pianoRoll, 1,
                    Math.abs(validList.get(0).getLeft().toString().hashCode()) % ItemPianoRoll.iconNo);
            final NBTTagCompound nbt = new NBTTagCompound();

            ItemPianoRoll.setPianoRollNBT(nbt, validList.get(0).getLeft().toString());
            stack.setTagCompound(nbt);

            sender.getEntityWorld().spawnEntityInWorld(
                    new EntityItem(sender.getEntityWorld(), sp.getX(), sp.getY(), sp.getZ(), stack));
        }
    } catch (Exception e) {
        if (e instanceof CommandException)
            throw e;
    }
}