blob: 71a4f928c4d285402b9282cb2c5aa212937e5cc7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
package net.lacolaco.smileessence.entity;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import net.lacolaco.smileessence.util.UIObservable;
public class User extends UIObservable {
// 重複防止用キャッシュ こっちは weak reference
private static Cache<Long, User> storage = CacheBuilder.newBuilder().weakValues().build();
public synchronized static User fetch(long userId) {
return storage.getIfPresent(userId);
}
public synchronized static User fromTwitter(final twitter4j.User st) {
User u = fetch(st.getId());
if (u == null) {
u = new User();
storage.put(st.getId(), u);
}
u.update(st);
return u;
}
// only for initialization; DO NOT have reference for this object
public synchronized static User _makeSkeleton(long id, String screenName) {
User u = fetch(id);
if (u != null) {
return u;
} else {
u = new User();
u.id = id;
u.screenName = screenName;
storage.put(id, u);
return u;
}
}
// インスタンス
private long id;
private boolean isProtected;
private String screenName;
private String name;
private String profileImageUrl;
private String profileBannerUrl;
private String description;
private String location;
private String url;
private int favoritesCount;
private int statusesCount;
private int friendsCount;
private int followersCount;
private boolean isVerified;
private User() {
}
private void update(twitter4j.User user) {
id = user.getId();
if (isProtected() != user.isProtected() ||
getScreenName() == null || !getScreenName().equals(user.getScreenName()) ||
getName() == null || !getName().equals(user.getName()) ||
getProfileImageUrl() == null || !getProfileImageUrl().equals(user.getProfileImageURLHttps())) {
isProtected = user.isProtected();
if (user.getScreenName() != null)
screenName = user.getScreenName();
if (user.getName() != null)
name = user.getName();
if (user.getProfileImageURLHttps() != null)
profileImageUrl = user.getProfileImageURLHttps();
notifyChange(RO.BASIC);
}
if (getProfileBannerUrl() == null || !getProfileBannerUrl().equals(user.getProfileBannerURL()) ||
getDescription() == null || !getDescription().equals(user.getDescription()) ||
getLocation() == null || !getLocation().equals(user.getLocation()) ||
getUrl() == null || !getUrl().equals(user.getURL()) ||
getFavoritesCount() != user.getFavouritesCount() ||
getStatusesCount() != user.getStatusesCount() ||
getFriendsCount() != user.getFriendsCount() ||
getFollowersCount() != user.getFollowersCount()) {
isVerified = user.isVerified();
if (user.getProfileBannerURL() != null)
profileBannerUrl = user.getProfileBannerURL();
if (user.getDescription() != null)
description = user.getDescription();
if (user.getLocation() != null)
location = user.getLocation();
if (user.getURL() != null)
url = user.getURL();
if (user.getFavouritesCount() != -1)
favoritesCount = user.getFavouritesCount();
if (user.getStatusesCount() != -1)
statusesCount = user.getStatusesCount();
if (user.getFriendsCount() != -1)
friendsCount = user.getFriendsCount();
if (user.getFollowersCount() != -1)
followersCount = user.getFollowersCount();
notifyChange(RO.DETAIL);
}
}
public long getId() {
return id;
}
public boolean isProtected() {
return isProtected;
}
public String getScreenName() {
return screenName;
}
public String getName() {
return name;
}
public String getProfileImageUrl() {
return profileImageUrl;
}
public String getProfileImageUrlOriginal() {
return getProfileImageUrlWithSuffix("");
}
private String getProfileImageUrlWithSuffix(String suffix) {
String original = getProfileImageUrl();
if (original != null) {
String url = original.substring(0, original.lastIndexOf("_")) + suffix;
int extIndex = original.lastIndexOf(".");
if (extIndex > original.lastIndexOf("/")) {
url += original.substring(extIndex);
}
return url;
}
return null;
}
public String getProfileBannerUrl() {
return profileBannerUrl;
}
public String getDescription() {
return description;
}
public String getLocation() {
return location;
}
public String getUrl() {
return url;
}
public int getFavoritesCount() {
return favoritesCount;
}
public int getStatusesCount() {
return statusesCount;
}
public int getFriendsCount() {
return friendsCount;
}
public int getFollowersCount() {
return followersCount;
}
public boolean isVerified() {
return isVerified;
}
// helper methods
public String getUserHomeURL() {
return String.format("https://twitter.com/%s", getScreenName());
}
public String getAclogTimelineURL() {
return String.format("http://aclog.koba789.com/%s/timeline", getScreenName());
}
public String getFavstarRecentURL() {
return String.format("http://favstar.fm/users/%s/recent", getScreenName());
}
public String getTwilogURL() {
return String.format("http://twilog.org/%s", getScreenName());
}
}
|