Skip to content

Commit 9b957c3

Browse files
committed
Merge branch 'my/primitive_list_api' into feature/primitive_list
2 parents c8a8821 + f1e0528 commit 9b957c3

12 files changed

Lines changed: 117 additions & 35 deletions

realm/realm-library/src/main/java/io/realm/DynamicRealmObject.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,11 @@ public DynamicRealmObject getObject(String fieldName) {
337337
}
338338

339339
/**
340-
* Returns the {@link RealmList} of objects being linked to from this field.
340+
* Returns the {@link RealmList} of {@link DynamicRealmObject}s being linked from the given field.
341341
*
342342
* @param fieldName the name of the field.
343343
* @return the {@link RealmList} data for this field.
344-
* @throws IllegalArgumentException if field name doesn't exist or it doesn't contain a list of links.
344+
* @throws IllegalArgumentException if field name doesn't exist or it doesn't contain a list of objects.
345345
*/
346346
public RealmList<DynamicRealmObject> getList(String fieldName) {
347347
proxyState.getRealm$realm().checkIfValid();
@@ -359,6 +359,18 @@ public RealmList<DynamicRealmObject> getList(String fieldName) {
359359
}
360360
}
361361

362+
/**
363+
* Returns the {@link RealmList} of values being linked from the given field.
364+
*
365+
* @param fieldName the name of the field.
366+
* @return the {@link RealmList} data for this field.
367+
* @throws IllegalArgumentException if field name doesn't exist or it doesn't contain a list of values.
368+
*/
369+
public <T> RealmList<T> getValueList(String fieldName, Class<T> valueClass) {
370+
// TODO implement this
371+
return null;
372+
}
373+
362374
/**
363375
* Checks if the value of a given field is {@code null}.
364376
*
@@ -760,6 +772,19 @@ public void setList(String fieldName, RealmList<DynamicRealmObject> list) {
760772
}
761773
}
762774

775+
/**
776+
* Sets the reference to a {@link RealmList} on the given field.
777+
*
778+
* @param fieldName field name.
779+
* @param list list of references.
780+
* @throws IllegalArgumentException if field name doesn't exist, it is not a list field, the type
781+
* of the object represented by the DynamicRealmObject doesn't match or any element in the list belongs to a
782+
* different Realm.
783+
*/
784+
public void setValueList(String fieldName, RealmList<?> list) {
785+
// TODO implement this
786+
}
787+
763788
/**
764789
* Sets the value to {@code null} for the given field.
765790
*

realm/realm-library/src/main/java/io/realm/OrderedRealmCollection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
* As you can see, after deletion, the size and elements order of snapshot stay the same as before. But the element at
101101
* the position becomes invalid.
102102
*/
103-
public interface OrderedRealmCollection<E extends RealmModel> extends List<E>, RealmCollection<E> {
103+
public interface OrderedRealmCollection<E> extends List<E>, RealmCollection<E> {
104104

105105
/**
106106
* Gets the first object from the collection.

realm/realm-library/src/main/java/io/realm/OrderedRealmCollectionImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
/**
2121
* General implementation for {@link OrderedRealmCollection} which is based on the {@code Collection}.
2222
*/
23-
abstract class OrderedRealmCollectionImpl<E extends RealmModel>
23+
abstract class OrderedRealmCollectionImpl<E>
2424
extends AbstractList<E> implements OrderedRealmCollection<E> {
2525
private final static String NOT_SUPPORTED_MESSAGE = "This method is not supported by 'RealmResults' or" +
2626
" 'OrderedRealmCollectionSnapshot'.";

realm/realm-library/src/main/java/io/realm/OrderedRealmCollectionSnapshot.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
* }
4949
* </pre>
5050
*/
51-
public class OrderedRealmCollectionSnapshot<E extends RealmModel> extends OrderedRealmCollectionImpl<E> {
51+
public class OrderedRealmCollectionSnapshot<E> extends OrderedRealmCollectionImpl<E> {
5252

5353
private int size = -1;
5454

realm/realm-library/src/main/java/io/realm/RealmCollection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
*
3636
* @param <E> type of {@link RealmObject} stored in the collection.
3737
*/
38-
public interface RealmCollection<E extends RealmModel> extends Collection<E>, ManagableObject {
38+
public interface RealmCollection<E> extends Collection<E>, ManagableObject {
3939

4040
/**
4141
* Returns a {@link RealmQuery}, which can be used to query for specific objects from this collection.

realm/realm-library/src/main/java/io/realm/RealmFieldType.java

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,40 @@
1818

1919
import java.nio.ByteBuffer;
2020

21-
import javax.annotation.Nullable;
22-
2321
import io.realm.internal.Keep;
2422

23+
import static io.realm.RealmFieldTypeConstants.CORE_TYPE_VALUE_BINARY;
24+
import static io.realm.RealmFieldTypeConstants.CORE_TYPE_VALUE_BOOLEAN;
25+
import static io.realm.RealmFieldTypeConstants.CORE_TYPE_VALUE_DATE;
26+
import static io.realm.RealmFieldTypeConstants.CORE_TYPE_VALUE_DOUBLE;
27+
import static io.realm.RealmFieldTypeConstants.CORE_TYPE_VALUE_FLOAT;
28+
import static io.realm.RealmFieldTypeConstants.CORE_TYPE_VALUE_INTEGER;
29+
import static io.realm.RealmFieldTypeConstants.CORE_TYPE_VALUE_LINKING_OBJECTS;
30+
import static io.realm.RealmFieldTypeConstants.CORE_TYPE_VALUE_LIST;
31+
import static io.realm.RealmFieldTypeConstants.CORE_TYPE_VALUE_OBJECT;
32+
import static io.realm.RealmFieldTypeConstants.CORE_TYPE_VALUE_STRING;
33+
import static io.realm.RealmFieldTypeConstants.CORE_TYPE_VALUE_UNSUPPORTED_DATE;
34+
import static io.realm.RealmFieldTypeConstants.CORE_TYPE_VALUE_UNSUPPORTED_MIXED;
35+
import static io.realm.RealmFieldTypeConstants.CORE_TYPE_VALUE_UNSUPPORTED_TABLE;
36+
import static io.realm.RealmFieldTypeConstants.LIST_OFFSET;
37+
38+
interface RealmFieldTypeConstants {
39+
int LIST_OFFSET = 1 << 16;
40+
41+
int CORE_TYPE_VALUE_INTEGER = 0;
42+
int CORE_TYPE_VALUE_BOOLEAN = 1;
43+
int CORE_TYPE_VALUE_STRING = 2;
44+
int CORE_TYPE_VALUE_BINARY = 4;
45+
int CORE_TYPE_VALUE_UNSUPPORTED_TABLE = 5;
46+
int CORE_TYPE_VALUE_UNSUPPORTED_MIXED = 6;
47+
int CORE_TYPE_VALUE_UNSUPPORTED_DATE = 7;
48+
int CORE_TYPE_VALUE_DATE = 8;
49+
int CORE_TYPE_VALUE_FLOAT = 9;
50+
int CORE_TYPE_VALUE_DOUBLE = 10;
51+
int CORE_TYPE_VALUE_OBJECT = 12;
52+
int CORE_TYPE_VALUE_LIST = 13;
53+
int CORE_TYPE_VALUE_LINKING_OBJECTS = 14;
54+
}
2555

2656
/**
2757
* List of the types used by Realm's underlying storage engine.
@@ -33,19 +63,28 @@
3363
@Keep
3464
public enum RealmFieldType {
3565
// Makes sure numbers match with <realm/column_type.hpp>.
36-
INTEGER(0),
37-
BOOLEAN(1),
38-
STRING(2),
39-
BINARY(4),
40-
UNSUPPORTED_TABLE(5),
41-
UNSUPPORTED_MIXED(6),
42-
UNSUPPORTED_DATE(7),
43-
DATE(8),
44-
FLOAT(9),
45-
DOUBLE(10),
46-
OBJECT(12),
47-
LIST(13),
48-
LINKING_OBJECTS(14);
66+
INTEGER(CORE_TYPE_VALUE_INTEGER),
67+
BOOLEAN(CORE_TYPE_VALUE_BOOLEAN),
68+
STRING(CORE_TYPE_VALUE_STRING),
69+
BINARY(CORE_TYPE_VALUE_BINARY),
70+
UNSUPPORTED_TABLE(CORE_TYPE_VALUE_UNSUPPORTED_TABLE),
71+
UNSUPPORTED_MIXED(CORE_TYPE_VALUE_UNSUPPORTED_MIXED),
72+
UNSUPPORTED_DATE(CORE_TYPE_VALUE_UNSUPPORTED_DATE),
73+
DATE(CORE_TYPE_VALUE_DATE),
74+
FLOAT(CORE_TYPE_VALUE_FLOAT),
75+
DOUBLE(CORE_TYPE_VALUE_DOUBLE),
76+
OBJECT(CORE_TYPE_VALUE_OBJECT),
77+
78+
LIST(CORE_TYPE_VALUE_LIST),
79+
LINKING_OBJECTS(CORE_TYPE_VALUE_LINKING_OBJECTS),
80+
81+
INTEGER_LIST(CORE_TYPE_VALUE_INTEGER + LIST_OFFSET),
82+
BOOLEAN_LIST(CORE_TYPE_VALUE_BOOLEAN + LIST_OFFSET),
83+
STRING_LIST(CORE_TYPE_VALUE_STRING + LIST_OFFSET),
84+
BINARY_LIST(CORE_TYPE_VALUE_BINARY + LIST_OFFSET),
85+
DATE_LIST(CORE_TYPE_VALUE_DATE + LIST_OFFSET),
86+
FLOAT_LIST(CORE_TYPE_VALUE_FLOAT + LIST_OFFSET),
87+
DOUBLE_LIST(CORE_TYPE_VALUE_DOUBLE + LIST_OFFSET);
4988

5089
// Primitive array for fast mapping between between native values and their Realm type.
5190
private static final RealmFieldType[] typeList = new RealmFieldType[15];

realm/realm-library/src/main/java/io/realm/RealmList.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
* @param <E> the class of objects in list.
5656
*/
5757

58-
public class RealmList<E extends RealmModel> extends AbstractList<E> implements OrderedRealmCollection<E> {
58+
public class RealmList<E> extends AbstractList<E> implements OrderedRealmCollection<E> {
5959

6060
private static final String ONLY_IN_MANAGED_MODE_MESSAGE = "This method is only available in managed mode";
6161
private static final String NULL_OBJECTS_NOT_ALLOWED_MESSAGE = "RealmList does not accept null values";
@@ -1197,7 +1197,7 @@ public void set(E e) {
11971197
* Adding a new object to the RealmList. If the object is not already manage by Realm it will be transparently
11981198
* copied using {@link Realm#copyToRealmOrUpdate(RealmModel)}
11991199
*
1200-
* @see #add(RealmModel)
1200+
* @see #add(Object)
12011201
*/
12021202
@Override
12031203
public void add(E e) {
@@ -1214,4 +1214,16 @@ public void add(E e) {
12141214
}
12151215
}
12161216
}
1217+
1218+
/*
1219+
* MEMO: This method supports {@code long}, {@code int}, {@code short}, {@code byte},
1220+
* {@code double}, {@code float} and {@code boolean} as {@code T} in addition to classes
1221+
* mentioned in the class comment of {@link RealmValueList}.
1222+
*/
1223+
@Nonnull
1224+
@Override
1225+
public <T> T[] toArray(@Nonnull T[] a) {
1226+
// TODO implement this
1227+
return super.toArray(a);
1228+
}
12171229
}

realm/realm-library/src/main/java/io/realm/RealmObjectSchema.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ public boolean hasIndex(String fieldName) {
261261
/**
262262
* Sets a field to be required i.e., it is not allowed to hold {@code null} values. This is equivalent to switching
263263
* between boxed types and their primitive variant e.g., {@code Integer} to {@code int}.
264+
* <p>
265+
* If the type of designated field is a list of values (not {@link RealmObject}s , specified nullability
266+
* only affects its elements, not the field itself. Value list itself is always non-nullable.
264267
*
265268
* @param fieldName name of field in the class.
266269
* @param required {@code true} if field should be required, {@code false} otherwise.
@@ -275,6 +278,9 @@ public boolean hasIndex(String fieldName) {
275278
/**
276279
* Sets a field to be nullable i.e., it should be able to hold {@code null} values. This is equivalent to switching
277280
* between primitive types and their boxed variant e.g., {@code int} to {@code Integer}.
281+
* <p>
282+
* If the type of designated field is a list of values (not {@link RealmObject}s , specified nullability
283+
* only affects its elements, not the field itself. Value list itself is always non-nullable.
278284
*
279285
* @param fieldName name of field in the class.
280286
* @param nullable {@code true} if field should be nullable, {@code false} otherwise.

realm/realm-library/src/main/java/io/realm/RealmQuery.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
* @see Realm#where(Class)
5454
* @see RealmResults#where()
5555
*/
56-
public class RealmQuery<E extends RealmModel> {
56+
public class RealmQuery<E> {
5757

5858
private final Table table;
5959
private final BaseRealm realm;
@@ -98,7 +98,7 @@ public static <E extends RealmModel> RealmQuery<E> createDynamicQuery(DynamicRea
9898
* to run it.
9999
*/
100100
@SuppressWarnings("unchecked")
101-
public static <E extends RealmModel> RealmQuery<E> createQueryFromResult(RealmResults<E> queryResults) {
101+
public static <E> RealmQuery<E> createQueryFromResult(RealmResults<E> queryResults) {
102102
//noinspection ConstantConditions
103103
return (queryResults.classSpec == null)
104104
? new RealmQuery(queryResults, queryResults.className)

realm/realm-library/src/main/java/io/realm/RealmResults.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
* @see RealmQuery#findAll()
6060
* @see Realm#executeTransaction(Realm.Transaction)
6161
*/
62-
public class RealmResults<E extends RealmModel> extends OrderedRealmCollectionImpl<E> {
62+
public class RealmResults<E> extends OrderedRealmCollectionImpl<E> {
6363

6464
// Called from Realm Proxy classes
6565
@SuppressLint("unused")

0 commit comments

Comments
 (0)