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

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

Introduction

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

Prototype

public abstract M getMiddle();

Source Link

Document

Gets the middle element from this triple.

Usage

From source file:gobblin.ingestion.google.webmaster.UrlTriePrefixGrouperTest.java

/**
 * The trie is://from w  w  w  .  ja v a  2  s . c  om
 *     /
 *     0
 *  1*   2*
 */
@Test
public void testGrouping1() {
    UrlTrie trie = new UrlTrie(_property, Arrays.asList(_property + "01", _property + "02"));
    UrlTriePrefixGrouper grouper = new UrlTriePrefixGrouper(trie, 1);
    ArrayList<String> chars = new ArrayList<>();
    ArrayList<FilterOperator> operators = new ArrayList<>();

    while (grouper.hasNext()) {
        Triple<String, FilterOperator, UrlTrieNode> group = grouper.next();
        chars.add(group.getLeft());
        operators.add(group.getMiddle());
    }
    Assert.assertEquals(new String[] { _property + "01", _property + "02" }, chars.toArray());
    Assert.assertEquals(new FilterOperator[] { FilterOperator.CONTAINS, FilterOperator.CONTAINS },
            operators.toArray());
}

From source file:gobblin.ingestion.google.webmaster.UrlTriePrefixGrouperTest.java

/**
 * The trie is:/*  ww w  .  j  a v a2s  .  c o m*/
 *     /
 *     0*
 *  1*    2*
 */
@Test
public void testGrouping2() {
    UrlTrie trie = new UrlTrie(_property, Arrays.asList(_property + "0", _property + "01", _property + "02"));
    UrlTriePrefixGrouper grouper = new UrlTriePrefixGrouper(trie, 1);
    ArrayList<String> chars = new ArrayList<>();
    ArrayList<FilterOperator> operators = new ArrayList<>();

    while (grouper.hasNext()) {
        Triple<String, FilterOperator, UrlTrieNode> group = grouper.next();
        chars.add(group.getLeft());
        operators.add(group.getMiddle());
    }
    Assert.assertEquals(new String[] { _property + "01", _property + "02", _property + "0" }, chars.toArray());
    Assert.assertEquals(
            new FilterOperator[] { FilterOperator.CONTAINS, FilterOperator.CONTAINS, FilterOperator.EQUALS },
            operators.toArray());
}

From source file:blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.java

private static void handleMapForDamage(Set<Triple<Connection, Vec3d, Vec3d>> in, EntityLivingBase e,
        BlockPos here) {/*from w ww.  j  av a  2s  .com*/
    final double KNOCKBACK_PER_DAMAGE = 10;
    if (!in.isEmpty()) {
        AxisAlignedBB eAabb = e.getEntityBoundingBox();
        for (Triple<Connection, Vec3d, Vec3d> conn : in)
            if (conn.getLeft().cableType.canCauseDamage()) {
                double extra = conn.getLeft().cableType.getDamageRadius();
                AxisAlignedBB includingExtra = eAabb.grow(extra).offset(-here.getX(), -here.getY(),
                        -here.getZ());
                boolean endpointsInEntity = includingExtra.contains(conn.getMiddle())
                        || includingExtra.contains(conn.getRight());
                RayTraceResult rayRes = endpointsInEntity ? null
                        : includingExtra.calculateIntercept(conn.getMiddle(), conn.getRight());
                if (endpointsInEntity || (rayRes != null && rayRes.typeOfHit == RayTraceResult.Type.BLOCK)) {
                    IImmersiveConnectable iic = toIIC(conn.getLeft().start, e.world);
                    float damage = 0;
                    if (iic != null)
                        damage = iic.getDamageAmount(e, conn.getLeft());
                    if (damage == 0) {
                        iic = toIIC(conn.getLeft().end, e.world);
                        if (iic != null)
                            damage = iic.getDamageAmount(e, conn.getLeft());
                    }
                    if (damage != 0) {
                        IEDamageSources.ElectricDamageSource dmg = IEDamageSources.causeWireDamage(damage,
                                conn.getLeft().cableType.getElectricSource());
                        if (dmg.apply(e)) {
                            damage = dmg.dmg;
                            Vec3d v = e.getLookVec();
                            knockbackNoSource(e, damage / KNOCKBACK_PER_DAMAGE, v.x, v.z);
                            iic.processDamage(e, damage, conn.getLeft());
                        }
                    }
                }
            }
    }
}

From source file:gobblin.ingestion.google.webmaster.UrlTriePrefixGrouperTest.java

@Test
public void testWhenTrieSizeLessThanGroupSize1() {
    List<String> pages = Arrays.asList(_property + "13");
    UrlTrie trie1 = new UrlTrie(_property, pages);
    UrlTriePrefixGrouper grouper = new UrlTriePrefixGrouper(trie1, 1);
    Triple<String, FilterOperator, UrlTrieNode> next = grouper.next();
    Assert.assertEquals(next.getLeft(), _property);
    Assert.assertEquals(next.getMiddle(), FilterOperator.CONTAINS);
    Assert.assertEquals(next.getRight().getValue(), Character.valueOf('/'));
    Assert.assertFalse(next.getRight().isExist());
    Assert.assertFalse(grouper.hasNext());
}

From source file:gobblin.ingestion.google.webmaster.UrlTriePrefixGrouperTest.java

@Test
public void testWhenTrieSizeLessThanGroupSize2() {
    List<String> pages = Arrays.asList(_property + "13");
    UrlTrie trie1 = new UrlTrie(_property, pages);
    UrlTriePrefixGrouper grouper = new UrlTriePrefixGrouper(trie1, 2);
    Triple<String, FilterOperator, UrlTrieNode> next = grouper.next();
    Assert.assertEquals(next.getLeft(), _property);
    Assert.assertEquals(next.getMiddle(), FilterOperator.CONTAINS);
    Assert.assertEquals(next.getRight().getValue(), Character.valueOf('/'));
    Assert.assertFalse(next.getRight().isExist());
    Assert.assertFalse(grouper.hasNext());
}

From source file:com.boozallen.cognition.ingest.storm.bolt.starter.LineRegexReplaceInRegionBoltTest.java

@Test
public void testConfigureRegexRegions() throws Exception {
    XMLConfiguration conf = new XMLConfiguration(getResource(this.getClass(), "regexRegions.xml"));

    bolt.configureRegexRegions(conf);//from ww w.  j  a v a  2  s  .co  m

    assertThat(bolt.groupSearchReplaceList.size(), is(2));

    Triple<Pattern, String, String> entry0 = bolt.groupSearchReplaceList.get(0);
    Triple<Pattern, String, String> entry1 = bolt.groupSearchReplaceList.get(1);

    assertNotNull(entry0.getLeft());
    assertThat(entry0.getMiddle(), is("regex0"));
    assertThat(entry0.getRight(), is("replacement0"));
    assertNotNull(entry1.getLeft());
    assertThat(entry1.getMiddle(), is("regex1"));
    assertThat(entry1.getRight(), is("replacement1"));
}

From source file:at.gridtec.lambda4j.consumer.tri.TriConsumer.java

/**
 * Applies this consumer to the given tuple.
 *
 * @param tuple The tuple to be applied to the consumer
 * @throws NullPointerException If given argument is {@code null}
 * @see org.apache.commons.lang3.tuple.Triple
 *//*  w w  w  .j a va2s  . c  om*/
default void accept(@Nonnull Triple<T, U, V> tuple) {
    Objects.requireNonNull(tuple);
    accept(tuple.getLeft(), tuple.getMiddle(), tuple.getRight());
}

From source file:de.ellpeck.actuallyadditions.mod.blocks.BlockGreenhouseGlass.java

@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
    if (world.isRemote)
        return;// w  ww  .  j ava2 s .c o m
    if (world.canBlockSeeSky(pos) && world.isDaytime()) {
        Triple<BlockPos, IBlockState, IGrowable> trip = firstBlock(world, pos);
        boolean once = false;
        if (trip != null)
            for (int i = 0; i < 3; i++) {
                IBlockState growState = i == 0 ? trip.getMiddle() : world.getBlockState(trip.getLeft());
                if (growState.getBlock() == trip.getRight()
                        && trip.getRight().canGrow(world, trip.getLeft(), growState, false)) {
                    trip.getRight().grow(world, rand, trip.getLeft(), growState);
                    once = true;
                }
            }
        if (once)
            world.playEvent(2005, trip.getMiddle().isOpaqueCube() ? trip.getLeft().up() : trip.getLeft(), 0);
    }
}

From source file:cherry.goods.telno.TelNoNormalizerImpl.java

private String[] split(String telNo, Triple<Integer, Integer, Integer> triple) {
    if (telNo.length() <= triple.getLeft()) {
        return new String[] { telNo };
    }// w  w w  . ja  v a 2  s  .  c o m
    String first = telNo.substring(0, triple.getLeft());
    if (telNo.length() <= triple.getLeft() + triple.getMiddle()) {
        String second = telNo.substring(triple.getLeft());
        return new String[] { first, second };
    }
    String second = telNo.substring(triple.getLeft(), triple.getLeft() + triple.getMiddle());
    String third = telNo.substring(triple.getLeft() + triple.getMiddle());
    return new String[] { first, second, third };
}

From source file:gobblin.ingestion.google.webmaster.UrlTriePrefixGrouperTest.java

/**
 * The trie is:/*from w w w. ja va 2 s  .c o  m*/
 *     /
 *  0  1  2
 * 3 4   5 6
 *       7
 */
@Test
public void testTrie2GroupingWithSize3() {
    UrlTrie trie = UrlTriePostOrderIteratorTest.getUrlTrie2(_property);
    UrlTriePrefixGrouper grouper = new UrlTriePrefixGrouper(trie, 3);
    ArrayList<String> chars = new ArrayList<>();
    ArrayList<FilterOperator> operators = new ArrayList<>();

    Triple<String, FilterOperator, UrlTrieNode> group = null;
    while (grouper.hasNext()) {
        group = grouper.next();
        chars.add(group.getLeft());
        operators.add(group.getMiddle());
    }
    Assert.assertEquals(new String[] { _property + "0", _property + "1", _property + "25", _property + "26",
            _property + "2" }, chars.toArray());
    Assert.assertEquals(new FilterOperator[] { FilterOperator.CONTAINS, FilterOperator.CONTAINS,
            FilterOperator.CONTAINS, FilterOperator.CONTAINS, FilterOperator.EQUALS }, operators.toArray());

    //The group is at www.linkedin.com/2 in the end with operator EQUALS
    ArrayList<String> pages = UrlTriePrefixGrouper.groupToPages(group);
    Assert.assertEquals(pages.toArray(), new String[] { _property + "2" });
}