@SuppressWarnings("unchecked") public T direction(Direction direction) { QueryOrderingProperty currentOrderingProperty = null; if (!orderingProperties.isEmpty()) { currentOrderingProperty = orderingProperties.get(orderingProperties.size() - 1); } ensureNotNull(NotValidException.class, "You should call any of the orderBy methods first before specifying a direction", "currentOrderingProperty", currentOrderingProperty); if (currentOrderingProperty.getDirection() != null) { ensureNull(NotValidException.class, "Invalid query: can specify only one direction desc() or asc() for an ordering constraint", "direction", direction); } currentOrderingProperty.setDirection(direction); return (T) this; }
@SuppressWarnings("unchecked") public T direction(Direction direction) { QueryOrderingProperty currentOrderingProperty = null; if (!orderingProperties.isEmpty()) { currentOrderingProperty = orderingProperties.get(orderingProperties.size() - 1); } ensureNotNull(NotValidException.class, "You should call any of the orderBy methods first before specifying a direction", "currentOrderingProperty", currentOrderingProperty); if (currentOrderingProperty.getDirection() != null) { ensureNull(NotValidException.class, "Invalid query: can specify only one direction desc() or asc() for an ordering constraint", "direction", direction); } currentOrderingProperty.setDirection(direction); return (T) this; }
orderingProperty.setDirection(direction); properties.add(orderingProperty);
orderingProperty.setDirection(direction); properties.add(orderingProperty);
@SuppressWarnings({ "rawtypes", "unchecked" }) protected void assertQuerySorting(String property, Query<?, ?> query, Comparable... items) { AbstractQuery<?, ?> queryImpl = (AbstractQuery<?, ?>) query; // save order properties to later reverse ordering List<QueryOrderingProperty> orderProperties = queryImpl.getOrderingProperties(); List<? extends Comparable> sortedList = Arrays.asList(items); Collections.sort(sortedList); List<Matcher<Object>> matchers = new ArrayList<Matcher<Object>>(); for (Comparable comparable : sortedList) { matchers.add(hasProperty(property, equalTo(comparable))); } List<?> instances = query.asc().list(); assertEquals(sortedList.size(), instances.size()); assertThat(instances, contains(matchers.toArray(new Matcher[matchers.size()]))); // reverse ordering for (QueryOrderingProperty orderingProperty : orderProperties) { orderingProperty.setDirection(Direction.DESCENDING); } // reverse matchers Collections.reverse(matchers); instances = query.list(); assertEquals(sortedList.size(), instances.size()); assertThat(instances, contains(matchers.toArray(new Matcher[matchers.size()]))); }
property.setDirection(Direction.findByName(direction));
property.setDirection(Direction.findByName(direction));
@SuppressWarnings("unchecked") public T direction(Direction direction) { QueryOrderingProperty currentOrderingProperty = null; if (!orderingProperties.isEmpty()) { currentOrderingProperty = orderingProperties.get(orderingProperties.size() - 1); } ensureNotNull(NotValidException.class, "You should call any of the orderBy methods first before specifying a direction", "currentOrderingProperty", currentOrderingProperty); if (currentOrderingProperty.getDirection() != null) { ensureNull(NotValidException.class, "Invalid query: can specify only one direction desc() or asc() for an ordering constraint", "direction", direction); } currentOrderingProperty.setDirection(direction); return (T) this; }
orderingProperty.setDirection(direction); properties.add(orderingProperty);
@SuppressWarnings({ "rawtypes", "unchecked" }) protected void assertQuerySorting(String property, Query<?, ?> query, Comparable... items) { AbstractQuery<?, ?> queryImpl = (AbstractQuery<?, ?>) query; // save order properties to later reverse ordering List<QueryOrderingProperty> orderProperties = queryImpl.getOrderingProperties(); List<? extends Comparable> sortedList = Arrays.asList(items); Collections.sort(sortedList); List<Matcher<Object>> matchers = new ArrayList<Matcher<Object>>(); for (Comparable comparable : sortedList) { matchers.add(hasProperty(property, equalTo(comparable))); } List<?> instances = query.asc().list(); assertEquals(sortedList.size(), instances.size()); assertThat(instances, contains(matchers.toArray(new Matcher[matchers.size()]))); // reverse ordering for (QueryOrderingProperty orderingProperty : orderProperties) { orderingProperty.setDirection(Direction.DESCENDING); } // reverse matchers Collections.reverse(matchers); instances = query.list(); assertEquals(sortedList.size(), instances.size()); assertThat(instances, contains(matchers.toArray(new Matcher[matchers.size()]))); }
property.setDirection(Direction.findByName(direction));