Example usage for org.apache.commons.lang3.tuple MutablePair setLeft

List of usage examples for org.apache.commons.lang3.tuple MutablePair setLeft

Introduction

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

Prototype

public void setLeft(final L left) 

Source Link

Document

Sets the left element of the pair.

Usage

From source file:be.shad.tsqb.test.SelectTests.java

/**
 * Select an object and use some of the values of this object to transform into another dto.
 * <p>/*from ww w.j  av  a 2  s .  c  o  m*/
 * Using a proxy as select value to get values from it should be avoided. Only do this
 * if there is no other option! (value on a dto without a default constructor for example)
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void selectProxyTransformedValue() {
    Person person = query.from(Person.class);
    Relation relation = query.join(person.getChildRelations());

    MutablePair<Long, ImmutablePair<Long, Integer>> select = query.select(MutablePair.class);
    select.setLeft(person.getId());
    select.setRight(query.select(ImmutablePair.class, relation.getChild(),
            new SelectionValueTransformer<Person, ImmutablePair>() {
                @Override
                public ImmutablePair<Long, Integer> convert(Person a) {
                    return new ImmutablePair<Long, Integer>(a.getId(), a.getAge());
                }
            }));

    validate(
            "select hobj1.id as left, hobj3 as right from Person hobj1 join hobj1.childRelations hobj2 join hobj2.child hobj3");
}

From source file:be.shad.tsqb.test.SelectTests.java

/**
 * Test distinct is selected after another selection was made
 * but shows up first in the hql select list.
 *///www . j  a v a  2  s  . c o  m
@Test
public void selectDistinctIsMovedToFrontOfProjections() {
    House house = query.from(House.class);

    @SuppressWarnings("unchecked")
    MutablePair<Long, Integer> dto = query.select(MutablePair.class);
    dto.setLeft(house.getId());
    dto.setRight(query.hqlFunction().distinct(house.getFloors()).select());

    validate("select distinct hobj1.floors as right, hobj1.id as left from House hobj1");
}

From source file:be.shad.tsqb.test.SelectTests.java

/**
 * Test wrapped distinct function// ww  w  . ja v  a  2s .  c om
 */
@Test
public void selectCountDistinct() {
    House house = query.from(House.class);

    TypeSafeValueFunctions fun = query.hqlFunction();
    @SuppressWarnings("unchecked")
    MutablePair<Long, Integer> dto = query.select(MutablePair.class);
    dto.setLeft(fun.countDistinct(house.getFloors()).select());
    dto.setRight(query.groupBy(house.getFloors()).select());

    validate(
            "select count(distinct hobj1.floors) as left, hobj1.floors as right from House hobj1 group by hobj1.floors");
}

From source file:be.shad.tsqb.test.SelectTests.java

@Test
public void selectCompositeTypeValues() {
    Building building = query.from(Building.class);

    @SuppressWarnings("unchecked")
    MutablePair<String, Style> result = query.select(MutablePair.class);
    result.setLeft(building.getAddress().getNumber());
    result.setRight(building.getStyle());

    validate("select hobj1.address.number as left, hobj1.style as right from Building hobj1");
}

From source file:be.shad.tsqb.test.SelectTests.java

/**
 * Select the entity and a property of the entity
 *//*  ww w. j  a va2  s  .  c o m*/
@Test
public void selectEntityAndPropertyOfEntity() {
    House house = query.from(House.class);

    @SuppressWarnings("unchecked")
    MutablePair<House, Integer> result = query.select(MutablePair.class);
    result.setLeft(house);
    result.setRight(house.getFloors());

    validate("select hobj1 as left, hobj1.floors as right from House hobj1");
}

From source file:be.shad.tsqb.test.SelectTests.java

@Test
public void selectComponentTypeValues() {
    Town town = query.from(Town.class);

    @SuppressWarnings("unchecked")
    MutablePair<Double, Double> result = query.select(MutablePair.class);
    result.setLeft(town.getGeographicCoordinate().getLongitude());
    result.setRight(town.getGeographicCoordinate().getLattitude());

    validate(//from   ww w .jav a 2  s.c o  m
            "select hobj1.geographicCoordinate.longitude as left, hobj1.geographicCoordinate.lattitude as right from Town hobj1");
}

From source file:be.shad.tsqb.test.SelectTests.java

@Test
public void selectSubQueryValueAndProperty() {
    House house = query.from(House.class);

    TypeSafeSubQuery<String> nameSubQuery = query.subquery(String.class);
    House houseSub = nameSubQuery.from(House.class);
    nameSubQuery.where(house.getId()).eq(houseSub.getId());

    nameSubQuery.select(houseSub.getName());

    @SuppressWarnings("unchecked")
    MutablePair<Integer, String> result = query.select(MutablePair.class);
    result.setLeft(house.getFloors());
    result.setRight(nameSubQuery.select());

    validate(//  ww w.ja  v  a  2  s  .  com
            "select hobj1.floors as left, (select hobj2.name from House hobj2 where hobj1.id = hobj2.id) as right from House hobj1");
}

From source file:be.shad.tsqb.test.SelectTests.java

@Test
public void selectCaseWhenValue() throws ParseException {
    House house = query.from(House.class);

    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String dateString = "1500-02-08 12:00:00";
    Date date = df.parse(dateString);
    CaseTypeSafeValue<String> value = new CaseTypeSafeValue<String>(query, String.class);
    value.is("Test1").when(house.getFloors()).gt(40);
    value.is((String) null).when(house.getName()).startsWith("Castle");
    value.is("Old").when(house.getConstructionDate()).before(date);
    value.is(house.getName()).otherwise();

    @SuppressWarnings("unchecked")
    MutablePair<String, Object> pair = query.select(MutablePair.class);
    pair.setLeft(value.select());

    validate("select (" + "case when (hobj1.floors > 40) " + "then 'Test1' "
            + "when (hobj1.name like 'Castle%') " + "then null " + "when (hobj1.constructionDate < "
            + getHelper().toLiteral(date) + ") " + "then 'Old' " + "else hobj1.name end) as left "
            + "from House hobj1");
}

From source file:be.shad.tsqb.test.SelectTests.java

@Test
public void selectUserTypeValue() {
    Building building = query.from(Building.class);

    @SuppressWarnings("unchecked")
    MutablePair<TextWrappingObject, Style> result = query.select(MutablePair.class);
    result.setLeft(building.getText());
    result.setRight(building.getStyle());

    validate("select hobj1.text as left, hobj1.style as right from Building hobj1");
}

From source file:hu.mta.sztaki.lpds.cloud.simulator.DeferredEvent.java

/**
 * Allows constructing objects that will receive an eventAction() call from
 * Timed after delay ticks.//from  w  w  w.  j a v  a 2  s.com
 * 
 * @param delay
 *            the number of ticks that should pass before this deferred
 *            event object's eventAction() will be called.
 */
public DeferredEvent(final long delay) {
    if (delay <= 0) {
        eventArrival = Timed.getFireCount();
        eventAction();
        received = true;
        return;
    }
    eventArrival = Timed.calcTimeJump(delay);
    MutablePair<Integer, DeferredEvent[]> simultaneousReceiverPairs = toSweep.get(eventArrival);
    if (simultaneousReceiverPairs == null) {
        simultaneousReceiverPairs = new MutablePair<Integer, DeferredEvent[]>(0, new DeferredEvent[5]);
        toSweep.put(eventArrival, simultaneousReceiverPairs);
    }
    int len = simultaneousReceiverPairs.getLeft();
    DeferredEvent[] simultaneousReceivers = simultaneousReceiverPairs.getRight();
    if (len == simultaneousReceivers.length) {
        DeferredEvent[] temp = new DeferredEvent[simultaneousReceivers.length * 2];
        System.arraycopy(simultaneousReceivers, 0, temp, 0, len);
        simultaneousReceivers = temp;
        simultaneousReceiverPairs.setRight(temp);
    }
    simultaneousReceivers[len++] = this;
    simultaneousReceiverPairs.setLeft(len);
    if (!dispatcherSingleton.isSubscribed() || dispatcherSingleton.getNextEvent() > eventArrival) {
        dispatcherSingleton.updateDispatcher();
    }
}