Search in sources :

Example 6 with Pair

use of com.mysema.commons.lang.Pair in project querydsl by querydsl.

the class GroupByIterateTest method map3.

@Test
public void map3() {
    CloseableIterator<Map<Integer, Map<Integer, String>>> results = MAP3_RESULTS.transform(groupBy(postId).iterate(map(postId, map(commentId, commentText))));
    List<Map<Integer, Map<Integer, String>>> actual = IteratorAdapter.asList(results);
    Object postId = null;
    Map<Integer, Map<Integer, String>> posts = null;
    List<Map<Integer, Map<Integer, String>>> expected = new LinkedList<Map<Integer, Map<Integer, String>>>();
    for (Iterator<Tuple> iterator = MAP3_RESULTS.iterate(); iterator.hasNext(); ) {
        Tuple tuple = iterator.next();
        Object[] array = tuple.toArray();
        if (posts == null || !(postId == array[0] || postId != null && postId.equals(array[0]))) {
            posts = new LinkedHashMap<Integer, Map<Integer, String>>();
            expected.add(posts);
        }
        postId = array[0];
        @SuppressWarnings("unchecked") Pair<Integer, Pair<Integer, String>> pair = (Pair<Integer, Pair<Integer, String>>) array[1];
        Integer first = pair.getFirst();
        Map<Integer, String> comments = posts.computeIfAbsent(first, k -> new LinkedHashMap<Integer, String>());
        Pair<Integer, String> second = pair.getSecond();
        comments.put(second.getFirst(), second.getSecond());
    }
    assertEquals(expected.toString(), actual.toString());
}
Also used : Tuple(com.querydsl.core.Tuple) Pair(com.mysema.commons.lang.Pair) Test(org.junit.Test)

Example 7 with Pair

use of com.mysema.commons.lang.Pair in project querydsl by querydsl.

the class GroupByListTest method map4.

@Test
public void map4() {
    CloseableIterator<Map<Map<Integer, String>, String>> results = MAP4_RESULTS.transform(groupBy(postId).iterate(map(map(postId, commentText), postName)));
    List<Map<Map<Integer, String>, String>> actual = IteratorAdapter.asList(results);
    Object commentId = null;
    Map<Map<Integer, String>, String> comments = null;
    List<Map<Map<Integer, String>, String>> expected = new LinkedList<Map<Map<Integer, String>, String>>();
    for (Iterator<Tuple> iterator = MAP4_RESULTS.iterate(); iterator.hasNext(); ) {
        Tuple tuple = iterator.next();
        Object[] array = tuple.toArray();
        if (comments == null || !(commentId == array[0] || commentId != null && commentId.equals(array[0]))) {
            comments = new LinkedHashMap<Map<Integer, String>, String>();
            expected.add(comments);
        }
        commentId = array[0];
        @SuppressWarnings("unchecked") Pair<Pair<Integer, String>, String> pair = (Pair<Pair<Integer, String>, String>) array[1];
        Pair<Integer, String> first = pair.getFirst();
        Map<Integer, String> posts = Collections.singletonMap(first.getFirst(), first.getSecond());
        comments.put(posts, pair.getSecond());
    }
    assertEquals(expected.toString(), actual.toString());
}
Also used : Tuple(com.querydsl.core.Tuple) Pair(com.mysema.commons.lang.Pair) Test(org.junit.Test)

Example 8 with Pair

use of com.mysema.commons.lang.Pair in project querydsl by querydsl.

the class TypeTest method test.

@SuppressWarnings("unchecked")
@Test
public void test() throws MalformedURLException, SQLException {
    List<Pair<?, ?>> valueAndType = new ArrayList<Pair<?, ?>>();
    valueAndType.add(Pair.of(new BigDecimal("1"), new BigDecimalType()));
    valueAndType.add(Pair.of(new BigInteger("2"), new BigIntegerType()));
    valueAndType.add(Pair.of(new BigDecimal("1.0"), new BigDecimalAsDoubleType()));
    valueAndType.add(Pair.of(new BigInteger("2"), new BigIntegerAsLongType()));
    // valueAndType.add(Pair.of(Boolean.TRUE,         new BooleanType()));
    valueAndType.add(Pair.of((byte) 1, new ByteType()));
    valueAndType.add(Pair.of(new byte[0], new BytesType()));
    valueAndType.add(Pair.of(Calendar.getInstance(), new CalendarType()));
    valueAndType.add(Pair.of('c', new CharacterType()));
    valueAndType.add(Pair.of(Currency.getInstance("EUR"), new CurrencyType()));
    valueAndType.add(Pair.of(new java.sql.Date(0), new DateType()));
    valueAndType.add(Pair.of(1.0, new DoubleType()));
    valueAndType.add(Pair.of(1.0f, new FloatType()));
    valueAndType.add(Pair.of(1, new IntegerType()));
    valueAndType.add(Pair.of(true, new NumericBooleanType()));
    valueAndType.add(Pair.of(1L, new LongType()));
    valueAndType.add(Pair.of(new Object(), new ObjectType()));
    valueAndType.add(Pair.of((short) 1, new ShortType()));
    valueAndType.add(Pair.of("", new StringType()));
    valueAndType.add(Pair.of(true, new TrueFalseType()));
    valueAndType.add(Pair.of(true, new YesNoType()));
    valueAndType.add(Pair.of(new Timestamp(0), new TimestampType()));
    valueAndType.add(Pair.of(new Time(0), new TimeType()));
    valueAndType.add(Pair.of(new URL("http://www.mysema.com"), new URLType()));
    valueAndType.add(Pair.of(new java.util.Date(), new UtilDateType()));
    valueAndType.add(Pair.of(new DateTime(), new DateTimeType()));
    valueAndType.add(Pair.of(new LocalDateTime(), new LocalDateTimeType()));
    valueAndType.add(Pair.of(new LocalDate(), new LocalDateType()));
    valueAndType.add(Pair.of(new LocalTime(), new LocalTimeType()));
    valueAndType.add(Pair.of(Gender.MALE, new EnumByNameType<Gender>(Gender.class)));
    valueAndType.add(Pair.of(Gender.MALE, new EnumByOrdinalType<Gender>(Gender.class)));
    valueAndType.add(Pair.of(EasyMock.createNiceMock(Blob.class), new BlobType()));
    valueAndType.add(Pair.of(EasyMock.createNiceMock(Clob.class), new ClobType()));
    valueAndType.add(Pair.of(UUID.randomUUID(), new UtilUUIDType(true)));
    valueAndType.add(Pair.of(UUID.randomUUID(), new UtilUUIDType(false)));
    for (Pair pair : valueAndType) {
        value = null;
        Type type = (Type) pair.getSecond();
        assertNull(type.toString(), type.getValue(resultSet, 0));
        type.setValue(statement, 0, pair.getFirst());
        assertEquals(type.toString(), pair.getFirst(), type.getValue(resultSet, 0));
    }
}
Also used : LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) LocalDateTime(org.joda.time.LocalDateTime) LocalTime(org.joda.time.LocalTime) BigInteger(java.math.BigInteger) LocalDateTime(org.joda.time.LocalDateTime) DateTime(org.joda.time.DateTime) LocalTime(org.joda.time.LocalTime) LocalDateTime(org.joda.time.LocalDateTime) URL(java.net.URL) Pair(com.mysema.commons.lang.Pair) BigDecimal(java.math.BigDecimal) LocalDate(org.joda.time.LocalDate) Test(org.junit.Test)

Aggregations

Pair (com.mysema.commons.lang.Pair)8 Test (org.junit.Test)8 Tuple (com.querydsl.core.Tuple)7 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 URL (java.net.URL)1 DateTime (org.joda.time.DateTime)1 LocalDate (org.joda.time.LocalDate)1 LocalDateTime (org.joda.time.LocalDateTime)1 LocalTime (org.joda.time.LocalTime)1