5
5
* you may not use this file except in compliance with the License.
6
6
* You may obtain a copy of the License at
7
7
*
8
- * http://www.apache.org/licenses/LICENSE-2.0
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
9
*
10
10
* Unless required by applicable law or agreed to in writing, software
11
11
* distributed under the License is distributed on an "AS IS" BASIS,
15
15
*/
16
16
package com .fernandocejas .android10 .sample .data .repository ;
17
17
18
- import com .fernandocejas .android10 .sample .data .entity .UserEntity ;
19
18
import com .fernandocejas .android10 .sample .data .entity .mapper .UserEntityDataMapper ;
20
19
import com .fernandocejas .android10 .sample .data .repository .datasource .UserDataStore ;
21
20
import com .fernandocejas .android10 .sample .data .repository .datasource .UserDataStoreFactory ;
25
24
import javax .inject .Inject ;
26
25
import javax .inject .Singleton ;
27
26
import rx .Observable ;
28
- import rx .functions .Func1 ;
29
27
30
28
/**
31
29
* {@link UserRepository} for retrieving user data.
@@ -36,20 +34,6 @@ public class UserDataRepository implements UserRepository {
36
34
private final UserDataStoreFactory userDataStoreFactory ;
37
35
private final UserEntityDataMapper userEntityDataMapper ;
38
36
39
- private final Func1 <List <UserEntity >, List <User >> userListEntityMapper =
40
- new Func1 <List <UserEntity >, List <User >>() {
41
- @ Override public List <User > call (List <UserEntity > userEntities ) {
42
- return UserDataRepository .this .userEntityDataMapper .transform (userEntities );
43
- }
44
- };
45
-
46
- private final Func1 <UserEntity , User >
47
- userDetailsEntityMapper = new Func1 <UserEntity , User >() {
48
- @ Override public User call (UserEntity userEntity ) {
49
- return UserDataRepository .this .userEntityDataMapper .transform (userEntity );
50
- }
51
- };
52
-
53
37
/**
54
38
* Constructs a {@link UserRepository}.
55
39
*
@@ -63,14 +47,18 @@ public UserDataRepository(UserDataStoreFactory dataStoreFactory,
63
47
this .userEntityDataMapper = userEntityDataMapper ;
64
48
}
65
49
50
+ @ SuppressWarnings ("Convert2MethodRef" )
66
51
@ Override public Observable <List <User >> getUsers () {
67
52
//we always get all users from the cloud
68
53
final UserDataStore userDataStore = this .userDataStoreFactory .createCloudDataStore ();
69
- return userDataStore .getUserEntityList ().map (userListEntityMapper );
54
+ return userDataStore .getUserEntityList ()
55
+ .map (userEntities -> this .userEntityDataMapper .transform (userEntities ));
70
56
}
71
57
58
+ @ SuppressWarnings ("Convert2MethodRef" )
72
59
@ Override public Observable <User > getUser (int userId ) {
73
60
final UserDataStore userDataStore = this .userDataStoreFactory .create (userId );
74
- return userDataStore .getUserEntityDetails (userId ).map (userDetailsEntityMapper );
61
+ return userDataStore .getUserEntityDetails (userId )
62
+ .map (userEntity -> this .userEntityDataMapper .transform (userEntity ));
75
63
}
76
64
}
0 commit comments