Skip to content

Commit 707811c

Browse files
committed
getMostInactiveMembers() and searchMembers()
1 parent 82fb72b commit 707811c

File tree

2 files changed

+49
-14
lines changed

2 files changed

+49
-14
lines changed

src/main/java/material/clan/Clan.java

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
import utils.HttpUtils;
1818
import utils.StringUtils;
1919

20-
import java.util.ArrayList;
21-
import java.util.Date;
22-
import java.util.List;
20+
import java.util.*;
2321
import java.util.concurrent.CompletableFuture;
2422
import java.util.concurrent.ExecutionException;
2523

@@ -80,6 +78,21 @@ private void assignValues() {
8078

8179
}
8280

81+
/**
82+
* Search for all of the members in this clan that have the string in their name
83+
*/
84+
public List<BungieUser> searchMembers(String name) {
85+
List<BungieUser> list = new LinkedList<>();
86+
87+
for (BungieUser bungieUser : getMembers()) {
88+
if (bungieUser.getDisplayName().contains(name)) {
89+
list.add(bungieUser);
90+
}
91+
}
92+
93+
return list;
94+
}
95+
8396
public String getClanID() {
8497
return clanId + "";
8598
}
@@ -135,6 +148,35 @@ public double getAverageInactivityAmongMembers() {
135148
return (double) a / getMembers().size();
136149
}
137150

151+
/**
152+
* Sort all of the players in the clan by how inactive they are
153+
* Most inactive is 1st, next is 2nd, etc.
154+
*/
155+
public List<BungieUser> getMostInactiveMembers(int numberOfResults, String... exclude) {
156+
List<BungieUser> list = getMembers();
157+
List<String> exlcluded = Arrays.asList(exclude);
158+
List<BungieUser> sorted = new LinkedList<>();
159+
BungieUser temp = null;
160+
161+
for(int i = 0; i < numberOfResults; i++) {
162+
for (BungieUser bungieUser : list) {
163+
if (temp != null) {
164+
if (temp != bungieUser && !sorted.contains(bungieUser) && !exlcluded.contains(bungieUser.getBungieMembershipID())) {
165+
if (bungieUser.getDaysSinceLastPlayed() > temp.getDaysSinceLastPlayed()) {
166+
temp = bungieUser;
167+
}
168+
}
169+
} else {
170+
temp = bungieUser;
171+
}
172+
}
173+
sorted.add(temp);
174+
temp = null;
175+
}
176+
177+
return sorted;
178+
}
179+
138180
/**
139181
* Returns a list of all members of the clan
140182
* Now deprecated in favor of getMembers()
@@ -168,7 +210,6 @@ public List<BungieUser> getMembersOld() {
168210

169211
/**
170212
* Old getExperimental method
171-
*
172213
* Does not cache valus anymore, now the developer is responsible for that
173214
* Should be faster than before
174215
*/
@@ -192,7 +233,7 @@ public List<BungieUser> getMembers() {
192233
int[] list = splitIntoParts(stream.size(), 15); // A list of integers used to separate the stream
193234
int listIndex = 0; // The index in the integer array we are currently on
194235

195-
while(index < stream.size()) { // Until we have completely looped through the stream
236+
while (index < stream.size()) { // Until we have completely looped through the stream
196237
int i = list[listIndex];
197238
new MemberThread(source, stream.subList(index, index + i)).start();
198239

@@ -221,7 +262,7 @@ private int[] splitIntoParts(int whole, int parts) {
221262
* Returns if this BungieUser is a member of the clan
222263
*/
223264
public boolean isMember(BungieUser bungieUser) {
224-
return isMember(bungieUser.getBungieMembershipID());
265+
return isMember(bungieUser.getBungieMembershipID());
225266
}
226267

227268
public boolean isMember(String bungieID) {
@@ -240,7 +281,7 @@ public boolean isMember(String bungieID) {
240281
*/
241282
public JsonObject getClanStats(ActivityMode... filter) {
242283
String queryString = "/?modes=";
243-
for(ActivityMode activityMode : filter) {
284+
for (ActivityMode activityMode : filter) {
244285
queryString = queryString.concat(activityMode.getBungieValue() + ",");
245286
}
246287
queryString = queryString.substring(0, queryString.length() - 2); // Remove the last comma

src/main/java/material/user/BungieUser.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,7 @@ public JsonObject getJsonObject() {
228228

229229
public void checkJO() {
230230
if (jo == null) {
231-
CompletableFuture<JsonObject> cf = new CompletableFuture<>();
232-
cf.completeAsync(() -> hu.urlRequestGET("https://www.bungie.net/Platform/Destiny2/-1/Profile/" + bungieMembershipID + "/LinkedProfiles/?components=200"));
233-
try {
234-
jo = cf.get();
235-
} catch (InterruptedException | ExecutionException e) {
236-
e.printStackTrace();
237-
}
231+
jo = hu.urlRequestGET("https://www.bungie.net/Platform/Destiny2/-1/Profile/" + bungieMembershipID + "/LinkedProfiles/?components=200");
238232
}
239233
}
240234

0 commit comments

Comments
 (0)