Example usage for org.apache.commons.lang3.tuple Triple getLeft

List of usage examples for org.apache.commons.lang3.tuple Triple getLeft

Introduction

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

Prototype

public abstract L getLeft();

Source Link

Document

Gets the left element from this triple.

Usage

From source file:com.quartercode.jtimber.rh.agent.asm.InsertJAXBTweaksClassAdapter.java

private void generateAfterUnmarshalMethod(Method method) {

    GeneratorAdapter mg = new GeneratorAdapter(ACC_PUBLIC, method, null, null, cv);

    /*/*w w w  . j  a va 2 s.com*/
     * Iterate through all fields annotated with "SubstituteWithWrapper" and replace their current value with their current value wrapped inside a wrapper.
     * This section first reads the current field value, then creates a new wrapper which wraps around that field value, and finally sets the field to the wrapper.
     */
    for (Triple<String, Type, Type> field : fieldsForWrapperSubstitution) {
        String fieldName = field.getLeft();
        Type fieldType = fields.get(fieldName);
        Type wrapperType = field.getMiddle();
        // Null means "default"; in that case, the field type is used as the type of the first argument of the wrapper constructor
        Type wrapperConstructorArgType = field.getRight() == null ? fieldType : field.getRight();

        // Note that this reference will be used for the PUTFIELD instruction later on
        mg.loadThis();

        // ----- Stack: [this]

        // Creates the wrapper using the current field value
        {
            // Create a new instance of the wrapper type and duplicate it for the constructor call later on
            mg.newInstance(wrapperType);
            mg.dup();

            // ----- Stack: [this, wrapper, wrapper]

            // Retrieve the current field value
            ASMUtils.generateGetField(mg, classType, fieldName, fieldType);

            // ----- Stack: [this, wrapper, wrapper, fieldValue]

            // Call the constructor of the new wrapper using the current field value as the first argument
            mg.invokeConstructor(wrapperType,
                    Method.getMethod("void <init> (" + wrapperConstructorArgType.getClassName() + ")"));

            // ----- Stack: [this, wrapper]
        }

        // Store the new wrapper in the field the value has been retrieved from before
        // The substitution is complete
        mg.putField(classType, fieldName, fieldType);

        // ----- Stack: []
    }

    /*
     * Iterate through all fields.
     * For each field, call the addParent() method with "this" as parent if the current field value is parent-aware
     */
    for (Entry<String, Type> field : fields.entrySet()) {
        String fieldName = field.getKey();
        Type fieldType = field.getValue();

        ASMUtils.generateGetField(mg, classType, fieldName, fieldType);

        // ----- Stack: [fieldValue]

        ASMUtils.generateAddOrRemoveThisAsParent(mg, "addParent");
    }

    // End the method
    mg.returnValue();
    mg.endMethod();
}

From source file:com.microsoft.azure.management.datalake.store.uploader.StringExtensionsTests.java

@Test
public void StringExtensions_FindNewLine_UTF8() {
    for (Triple<String, Integer, Integer> t : TestDataUTF8) {
        byte[] exactBuffer = t.getLeft().getBytes(StandardCharsets.UTF_8);
        byte[] largerBuffer = new byte[exactBuffer.length + 100];
        System.arraycopy(exactBuffer, 0, largerBuffer, 0, exactBuffer.length);

        int forwardInExactBuffer = StringExtensions.findNewline(exactBuffer, 0, exactBuffer.length, false,
                StandardCharsets.UTF_8, null);
        Assert.assertEquals(t.getMiddle().intValue(), forwardInExactBuffer);

        int forwardInLargeBuffer = StringExtensions.findNewline(largerBuffer, 0, exactBuffer.length, false,
                StandardCharsets.UTF_8, null);
        Assert.assertEquals(t.getMiddle().intValue(), forwardInLargeBuffer);

        int reverseInExactBuffer = StringExtensions.findNewline(exactBuffer,
                Math.max(0, exactBuffer.length - 1), exactBuffer.length, true, StandardCharsets.UTF_8, null);
        Assert.assertEquals(t.getRight().intValue(), reverseInExactBuffer);

        int reverseInLargeBuffer = StringExtensions.findNewline(largerBuffer,
                Math.max(0, exactBuffer.length - 1), exactBuffer.length, true, StandardCharsets.UTF_8, null);
        Assert.assertEquals(t.getRight().intValue(), reverseInLargeBuffer);
    }//from ww w.  java2 s.  c om

    for (Triple<String, Integer, Integer> t : TestDataUTF8CustomDelim) {
        byte[] exactBuffer = t.getLeft().getBytes(StandardCharsets.UTF_8);
        byte[] largerBuffer = new byte[exactBuffer.length + 100];
        System.arraycopy(exactBuffer, 0, largerBuffer, 0, exactBuffer.length);

        int forwardInExactBuffer = StringExtensions.findNewline(exactBuffer, 0, exactBuffer.length, false,
                StandardCharsets.UTF_8, customDelim);
        Assert.assertEquals(t.getMiddle().intValue(), forwardInExactBuffer);

        int forwardInLargeBuffer = StringExtensions.findNewline(largerBuffer, 0, exactBuffer.length, false,
                StandardCharsets.UTF_8, customDelim);
        Assert.assertEquals(t.getMiddle().intValue(), forwardInLargeBuffer);

        int reverseInExactBuffer = StringExtensions.findNewline(exactBuffer,
                Math.max(0, exactBuffer.length - 1), exactBuffer.length, true, StandardCharsets.UTF_8,
                customDelim);
        Assert.assertEquals(t.getRight().intValue(), reverseInExactBuffer);

        int reverseInLargeBuffer = StringExtensions.findNewline(largerBuffer,
                Math.max(0, exactBuffer.length - 1), exactBuffer.length, true, StandardCharsets.UTF_8,
                customDelim);
        Assert.assertEquals(t.getRight().intValue(), reverseInLargeBuffer);
    }
}

From source file:com.microsoft.azure.management.datalake.store.uploader.StringExtensionsTests.java

@Test
public void StringExtensions_FindNewLine_ASCII() {
    for (Triple<String, Integer, Integer> t : TestDataUTF8) {
        byte[] exactBuffer = t.getLeft().getBytes(StandardCharsets.US_ASCII);
        byte[] largerBuffer = new byte[exactBuffer.length + 100];
        System.arraycopy(exactBuffer, 0, largerBuffer, 0, exactBuffer.length);

        int forwardInExactBuffer = StringExtensions.findNewline(exactBuffer, 0, exactBuffer.length, false,
                StandardCharsets.US_ASCII, null);
        Assert.assertEquals(t.getMiddle().intValue(), forwardInExactBuffer);

        int forwardInLargeBuffer = StringExtensions.findNewline(largerBuffer, 0, exactBuffer.length, false,
                StandardCharsets.US_ASCII, null);
        Assert.assertEquals(t.getMiddle().intValue(), forwardInLargeBuffer);

        int reverseInExactBuffer = StringExtensions.findNewline(exactBuffer,
                Math.max(0, exactBuffer.length - 1), exactBuffer.length, true, StandardCharsets.US_ASCII, null);
        Assert.assertEquals(t.getRight().intValue(), reverseInExactBuffer);

        int reverseInLargeBuffer = StringExtensions.findNewline(largerBuffer,
                Math.max(0, exactBuffer.length - 1), exactBuffer.length, true, StandardCharsets.US_ASCII, null);
        Assert.assertEquals(t.getRight().intValue(), reverseInLargeBuffer);
    }//from w w  w .  ja va2  s. c  o m

    for (Triple<String, Integer, Integer> t : TestDataUTF8CustomDelim) {
        byte[] exactBuffer = t.getLeft().getBytes(StandardCharsets.US_ASCII);
        byte[] largerBuffer = new byte[exactBuffer.length + 100];
        System.arraycopy(exactBuffer, 0, largerBuffer, 0, exactBuffer.length);

        int forwardInExactBuffer = StringExtensions.findNewline(exactBuffer, 0, exactBuffer.length, false,
                StandardCharsets.US_ASCII, customDelim);
        Assert.assertEquals(t.getMiddle().intValue(), forwardInExactBuffer);

        int forwardInLargeBuffer = StringExtensions.findNewline(largerBuffer, 0, exactBuffer.length, false,
                StandardCharsets.US_ASCII, customDelim);
        Assert.assertEquals(t.getMiddle().intValue(), forwardInLargeBuffer);

        int reverseInExactBuffer = StringExtensions.findNewline(exactBuffer,
                Math.max(0, exactBuffer.length - 1), exactBuffer.length, true, StandardCharsets.US_ASCII,
                customDelim);
        Assert.assertEquals(t.getRight().intValue(), reverseInExactBuffer);

        int reverseInLargeBuffer = StringExtensions.findNewline(largerBuffer,
                Math.max(0, exactBuffer.length - 1), exactBuffer.length, true, StandardCharsets.US_ASCII,
                customDelim);
        Assert.assertEquals(t.getRight().intValue(), reverseInLargeBuffer);
    }
}

From source file:com.microsoft.azure.management.datalake.store.uploader.StringExtensionsTests.java

@Test
public void StringExtensions_FindNewLine_UTF16() {
    for (Triple<String, Integer, Integer> t : TestDataUTF16) {
        byte[] exactBuffer = t.getLeft().getBytes(StandardCharsets.UTF_16LE);
        byte[] largerBuffer = new byte[exactBuffer.length + 100];
        System.arraycopy(exactBuffer, 0, largerBuffer, 0, exactBuffer.length);

        int forwardInExactBuffer = StringExtensions.findNewline(exactBuffer, 0, exactBuffer.length, false,
                StandardCharsets.UTF_16LE, null);
        Assert.assertEquals(t.getMiddle().intValue(), forwardInExactBuffer);

        int forwardInLargeBuffer = StringExtensions.findNewline(largerBuffer, 0, exactBuffer.length, false,
                StandardCharsets.UTF_16LE, null);
        Assert.assertEquals(t.getMiddle().intValue(), forwardInLargeBuffer);

        int reverseInExactBuffer = StringExtensions.findNewline(exactBuffer,
                Math.max(0, exactBuffer.length - 1), exactBuffer.length, true, StandardCharsets.UTF_16LE, null);
        Assert.assertEquals(t.getRight().intValue(), reverseInExactBuffer);

        int reverseInLargeBuffer = StringExtensions.findNewline(largerBuffer,
                Math.max(0, exactBuffer.length - 1), exactBuffer.length, true, StandardCharsets.UTF_16LE, null);
        Assert.assertEquals(t.getRight().intValue(), reverseInLargeBuffer);
    }//from   w  w w.j a v  a2  s.c  o m

    for (Triple<String, Integer, Integer> t : TestDataUTF16CustomDelim) {
        byte[] exactBuffer = t.getLeft().getBytes(StandardCharsets.UTF_16LE);
        byte[] largerBuffer = new byte[exactBuffer.length + 100];
        System.arraycopy(exactBuffer, 0, largerBuffer, 0, exactBuffer.length);

        int forwardInExactBuffer = StringExtensions.findNewline(exactBuffer, 0, exactBuffer.length, false,
                StandardCharsets.UTF_16LE, customDelim);
        Assert.assertEquals(t.getMiddle().intValue(), forwardInExactBuffer);

        int forwardInLargeBuffer = StringExtensions.findNewline(largerBuffer, 0, exactBuffer.length, false,
                StandardCharsets.UTF_16LE, customDelim);
        Assert.assertEquals(t.getMiddle().intValue(), forwardInLargeBuffer);

        int reverseInExactBuffer = StringExtensions.findNewline(exactBuffer,
                Math.max(0, exactBuffer.length - 1), exactBuffer.length, true, StandardCharsets.UTF_16LE,
                customDelim);
        Assert.assertEquals(t.getRight().intValue(), reverseInExactBuffer);

        int reverseInLargeBuffer = StringExtensions.findNewline(largerBuffer,
                Math.max(0, exactBuffer.length - 1), exactBuffer.length, true, StandardCharsets.UTF_16LE,
                customDelim);
        Assert.assertEquals(t.getRight().intValue(), reverseInLargeBuffer);
    }
}

From source file:com.microsoft.azure.management.datalake.store.uploader.StringExtensionsTests.java

@Test
public void StringExtensions_FindNewLine_UTF16BigEndian() {
    for (Triple<String, Integer, Integer> t : TestDataUTF16) {
        byte[] exactBuffer = t.getLeft().getBytes(StandardCharsets.UTF_16BE);
        byte[] largerBuffer = new byte[exactBuffer.length + 100];
        System.arraycopy(exactBuffer, 0, largerBuffer, 0, exactBuffer.length);

        int forwardInExactBuffer = StringExtensions.findNewline(exactBuffer, 0, exactBuffer.length, false,
                StandardCharsets.UTF_16BE, null);
        Assert.assertEquals(t.getMiddle().intValue(), forwardInExactBuffer);

        int forwardInLargeBuffer = StringExtensions.findNewline(largerBuffer, 0, exactBuffer.length, false,
                StandardCharsets.UTF_16BE, null);
        Assert.assertEquals(t.getMiddle().intValue(), forwardInLargeBuffer);

        int reverseInExactBuffer = StringExtensions.findNewline(exactBuffer,
                Math.max(0, exactBuffer.length - 1), exactBuffer.length, true, StandardCharsets.UTF_16BE, null);
        Assert.assertEquals(t.getRight().intValue(), reverseInExactBuffer);

        int reverseInLargeBuffer = StringExtensions.findNewline(largerBuffer,
                Math.max(0, exactBuffer.length - 1), exactBuffer.length, true, StandardCharsets.UTF_16BE, null);
        Assert.assertEquals(t.getRight().intValue(), reverseInLargeBuffer);
    }/*  w w w. j  a  va2s  .c o  m*/

    for (Triple<String, Integer, Integer> t : TestDataUTF16CustomDelim) {
        byte[] exactBuffer = t.getLeft().getBytes(StandardCharsets.UTF_16BE);
        byte[] largerBuffer = new byte[exactBuffer.length + 100];
        System.arraycopy(exactBuffer, 0, largerBuffer, 0, exactBuffer.length);

        int forwardInExactBuffer = StringExtensions.findNewline(exactBuffer, 0, exactBuffer.length, false,
                StandardCharsets.UTF_16BE, customDelim);
        Assert.assertEquals(t.getMiddle().intValue(), forwardInExactBuffer);

        int forwardInLargeBuffer = StringExtensions.findNewline(largerBuffer, 0, exactBuffer.length, false,
                StandardCharsets.UTF_16BE, customDelim);
        Assert.assertEquals(t.getMiddle().intValue(), forwardInLargeBuffer);

        int reverseInExactBuffer = StringExtensions.findNewline(exactBuffer,
                Math.max(0, exactBuffer.length - 1), exactBuffer.length, true, StandardCharsets.UTF_16BE,
                customDelim);
        Assert.assertEquals(t.getRight().intValue(), reverseInExactBuffer);

        int reverseInLargeBuffer = StringExtensions.findNewline(largerBuffer,
                Math.max(0, exactBuffer.length - 1), exactBuffer.length, true, StandardCharsets.UTF_16BE,
                customDelim);
        Assert.assertEquals(t.getRight().intValue(), reverseInLargeBuffer);
    }
}

From source file:com.magnet.mmx.server.plugin.mmxmgmt.util.MMXConfigurationTest.java

private void testSetGetAttribute(MBeanServerConnection connection, ObjectName name) throws Exception {
    for (Triple<String, String, String> pair : mbeanAttributes) {
        String attrName = pair.getLeft();
        String attrType = pair.getRight();
        Object attrValue;/*www.java  2 s.com*/
        if (attrType.equals("int"))
            attrValue = RandomUtils.nextInt(30000, 65535);
        else if (attrType.equals("long"))
            attrValue = RandomUtils.nextLong(10, 1000);
        else
            attrValue = RandomStringUtils.randomAlphabetic(10);
        Attribute attr1 = new Attribute(attrName, attrValue);
        server.setAttribute(name, attr1);
        Object attr2 = server.getAttribute(name, attrName);
        assertEquals("Attribute values do not match", attrValue, attr2);
    }
}

From source file:at.gridtec.lambda4j.function.tri.TriFunction.java

/**
 * Applies this function to the given tuple.
 *
 * @param tuple The tuple to be applied to the function
 * @return The return value from the function, which is its result.
 * @throws NullPointerException If given argument is {@code null}
 * @see org.apache.commons.lang3.tuple.Triple
 *//* ww w.j a  v  a 2s . co m*/
default R apply(@Nonnull Triple<T, U, V> tuple) {
    Objects.requireNonNull(tuple);
    return apply(tuple.getLeft(), tuple.getMiddle(), tuple.getRight());
}

From source file:blusunrize.immersiveengineering.common.blocks.cloth.TileEntityBalloon.java

@Override
public void onEntityCollision(World world, Entity entity) {
    if (entity instanceof EntityArrow || entity instanceof EntityRevolvershot) {
        Vec3d pos = new Vec3d(getPos()).add(.5, .5, .5);
        world.playSound(null, pos.x, pos.y, pos.z, SoundEvents.ENTITY_FIREWORK_BLAST, SoundCategory.BLOCKS,
                1.5f, 0.7f);//from   ww  w.j a v a2 s  .  c o  m
        world.setBlockToAir(getPos());
        world.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, pos.x, pos.y, pos.z, 0, .05, 0);
        Triple<ItemStack, ShaderRegistryEntry, ShaderCase> shader = ShaderRegistry
                .getStoredShaderAndCase(this.shader);
        if (shader != null)
            shader.getMiddle().getEffectFunction().execute(world, shader.getLeft(), null,
                    shader.getRight().getShaderType(), pos, null, .375f);

    }
}

From source file:com.magnet.mmx.server.plugin.mmxmgmt.util.MMXConfigurationTest.java

/**
 * Set the Configuration property via REST interface and check whether the JMX interface returns the same value
 *
 * @throws Exception/*from   w w  w.  jav a  2  s. c om*/
 */
//TODO: Use the web target JAXRS API to execute these request possibly ?
@Ignore
@Test
public void testSetRESTGetMBeanLocal() throws Exception {
    LOGGER.debug("testSetRESTGetMBeanLocal");
    ObjectName name = new ObjectName(MMX_MBEAN_OBJECT_NAME);
    ServletTester tester = new ServletTester();
    tester.addServlet(LaxConfigServlet.class, "/config");
    tester.start();

    for (Triple<String, String, String> triple : mbeanAttributes) {
        String attrName = triple.getLeft();
        String attrType = triple.getRight();

        String attrValueStr;
        if (attrType.equals("int"))
            attrValueStr = Integer.toString(RandomUtils.nextInt(30000, 65535));
        else if (attrType.equals("long"))
            attrValueStr = Long.toString(RandomUtils.nextLong(10, 1000));
        else
            attrValueStr = RandomStringUtils.randomAlphabetic(10);

        String str = constructGson(triple.getMiddle(), attrValueStr);

        HttpTester request = new HttpTester();
        request.setMethod("POST");
        request.setHeader("Host", "tester");
        request.setContent(str);
        request.setHeader("Content-Type", "application/json");

        request.setURI("/config");
        HttpTester response = new HttpTester();
        //response = response.parse(tester.getResponses(request.generate()));
        response.parse(tester.getResponses(request.generate()));
        assertEquals("Values do not match", server.getAttribute(name, triple.getLeft()).toString(),
                attrValueStr);

    }
}

From source file:com.magnet.mmx.server.plugin.mmxmgmt.util.MMXConfigurationTest.java

/**
 * Set the Configuration property via JMX and check whether the REST interface returns the same value
 *
 * @throws Exception/*from ww w  .j ava2s .c  o  m*/
 */
//TODO: Use the web target JAXRS API to execute these request possibly ?
@Ignore
@Test
public void testSetMBeanLocalGetREST() throws Exception {
    ObjectName name = new ObjectName(MMX_MBEAN_OBJECT_NAME);
    ServletTester tester = new ServletTester();
    tester.addServlet(LaxConfigServlet.class, "/config");
    tester.start();

    for (Triple<String, String, String> triple : mbeanAttributes) {
        String attrName = triple.getLeft();
        String attrType = triple.getRight();
        Object attrValue;
        if (attrType.equals("int")) {
            attrValue = RandomUtils.nextInt(30000, 65535);
        } else if (attrType.equals("long")) {
            attrValue = RandomUtils.nextLong(10, 1000);
        } else {
            attrValue = RandomStringUtils.randomAlphabetic(10);
        }
        Attribute attr1 = new Attribute(attrName, attrValue);
        server.setAttribute(name, attr1);
        Object attr2 = server.getAttribute(name, attrName);
        assertEquals("Attribute values do not match", attrValue, attr2);
        HttpTester request = new HttpTester();
        // HttpTester.Request request = HttpTester.newRequest();
        request.setMethod("GET");
        request.setHeader("Host", "tester");
        request.setURI("/config");
        request.setContent("");
        HttpTester response = new HttpTester();
        response.parse(tester.getResponses(request.generate()));
        JsonElement jelement = new JsonParser().parse(response.getContent());
        JsonObject jobject = jelement.getAsJsonObject();
        jobject = jobject.getAsJsonObject("configs");
        String attrValueRest = jobject.get(triple.getMiddle()).getAsString();
        if (attrType.equals("int"))
            assertEquals("Values do not match", attrValue, Integer.parseInt(attrValueRest));
        else if (attrType.equals("long"))
            assertEquals("Values do not match", attrValue, Long.parseLong(attrValueRest));
        else
            assertEquals("Values do not match", attrValue, attrValueRest);
    }
}