1 package com
.google
.appengine
.api
.datastore
;
3 import static com
.google
.appengine
.api
.datastore
.DataTypeTranslator
.getComparablePropertyValue
;
5 import com
.google
.apphosting
.datastore
.DatastoreV3Pb
.Query
.Filter
;
6 import com
.google
.apphosting
.datastore
.DatastoreV3Pb
.Query
.Order
;
8 import java
.util
.ArrayList
;
9 import java
.util
.Collection
;
10 import java
.util
.Collections
;
11 import java
.util
.List
;
14 * A comparator with the same ordering as {@link EntityProtoComparators} which uses
15 * Entity objects rather than protos.
17 class EntityComparator
extends BaseEntityComparator
<Entity
> {
19 EntityComparator(List
<Order
> orders
) {
20 super(orders
, Collections
.<Filter
>emptyList());
24 List
<Comparable
<Object
>> getComparablePropertyValues(Entity entity
, String propertyName
) {
26 if (propertyName
.equals(Entity
.KEY_RESERVED_PROPERTY
)) {
27 prop
= entity
.getKey();
28 } else if (!entity
.hasProperty(propertyName
)) {
31 prop
= entity
.getProperty(propertyName
);
33 if (prop
instanceof Collection
<?
>) {
34 Collection
<?
> props
= (Collection
<?
>) prop
;
35 if (props
.isEmpty()) {
36 return Collections
.singletonList(null);
38 List
<Comparable
<Object
>> comparableProps
= new ArrayList
<>(props
.size());
39 for (Object curProp
: props
) {
40 comparableProps
.add(getComparablePropertyValue(curProp
));
42 return comparableProps
;
44 return Collections
.singletonList(getComparablePropertyValue(prop
));