1 // Copyright 2009 Google Inc. All Rights Reserved.
2 package com
.google
.appengine
.api
.datastore
;
4 import com
.google
.apphosting
.datastore
.DatastoreV3Pb
.Query
.Filter
;
5 import com
.google
.apphosting
.datastore
.DatastoreV3Pb
.Query
.Order
;
6 import com
.google
.storage
.onestore
.v3
.OnestoreEntity
;
7 import com
.google
.storage
.onestore
.v3
.OnestoreEntity
.EntityProto
;
9 import java
.util
.ArrayList
;
10 import java
.util
.Collection
;
11 import java
.util
.Collections
;
12 import java
.util
.Comparator
;
13 import java
.util
.List
;
16 * Utilities for comparing {@link EntityProto}. This class is
17 * only public because the dev appserver needs access to it. It should not be
18 * accessed by user code.
21 public final class EntityProtoComparators
{
23 public static final Comparator
<Comparable
<Object
>> MULTI_TYPE_COMPARATOR
=
24 BaseEntityComparator
.MULTI_TYPE_COMPARATOR
;
27 * A comparator for {@link com.google.storage.onestore.v3.OnestoreEntity.EntityProto}
28 * objects with the same ordering as {@link EntityComparator}.
30 public static final class EntityProtoComparator
31 extends BaseEntityComparator
<OnestoreEntity
.EntityProto
> {
33 public EntityProtoComparator(List
<Order
> orders
) {
34 super(orders
, Collections
.<Filter
>emptyList());
37 public EntityProtoComparator(List
<Order
> orders
, List
<Filter
> filters
) {
38 super(orders
, filters
);
41 public List
<Order
> getAdjustedOrders() {
42 return Collections
.unmodifiableList(orders
);
45 public boolean matches(OnestoreEntity
.EntityProto proto
) {
46 for (String property
: filters
.keySet()) {
47 List
<Comparable
<Object
>> values
= getComparablePropertyValues(proto
, property
);
48 if (values
== null || !filters
.get(property
).matches(values
)) {
55 public boolean matches(OnestoreEntity
.Property prop
) {
56 FilterMatcher filter
= filters
.get(prop
.getName());
60 return filter
.matches(Collections
.singletonList(
61 DataTypeTranslator
.getComparablePropertyValue(prop
)));
65 List
<Comparable
<Object
>> getComparablePropertyValues(
66 OnestoreEntity
.EntityProto entityProto
, String propertyName
) {
67 Collection
<OnestoreEntity
.Property
> entityProperties
=
68 DataTypeTranslator
.findIndexedPropertiesOnPb(entityProto
, propertyName
);
69 if (entityProperties
.isEmpty()) {
72 if (propertyName
.equals(Entity
.KEY_RESERVED_PROPERTY
) && !entityProto
.hasKey()) {
75 List
<Comparable
<Object
>> values
= new ArrayList
<>(entityProperties
.size());
76 for (OnestoreEntity
.Property prop
: entityProperties
) {
77 values
.add(DataTypeTranslator
.getComparablePropertyValue(prop
));
83 private EntityProtoComparators() {}