This won't work..
Test Program
Output
Here's the problem..
private void resetList() {
if (future.isEmpty() && !past.isEmpty()) {
future = past;
past.clear();
}
}
You are making future reference the same object as past and then clearing it so let's change that first
private void resetList() {
if (future.isEmpty() && !past.isEmpty()) {
List<Integer> temp = future;
future = past;
past = temp;
past.clear();
}
}
Here you add world values to the future list which is fine..
public WorldHopping(boolean p2pworlds, final boolean f2pworlds, final boolean pvpworlds) {
if (p2pworlds) {
future.addAll(P2P_WORLDS);
}
if (f2pworlds) {
future.addAll(F2P_WORLDS);
}
if (pvpworlds) {
future.addAll(PVP_WORLDS);
}
}
But..
public void toRandomWorldNumber(){
int i = new Random().nextInt(future.size());
int w = future.get(i);
System.out.println(w);
future.remove(i);
past.add(i);
resetList();
}
In each hopping method you add the index of the world in future to past and then remove the value from the future? Why would you do that? The index is useless now right?
I think you meant to add the world value to the past list, like so
public void toRandomWorldNumber(){
int i = new Random().nextInt(future.size());
int w = future.get(i);
System.out.println(w);
future.remove(i);
past.add(w);
resetList();
}
Now we store the past world values rather than their obsolete indexes in the future list
Updated program:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;
/**
* @author Botrepreneur
*/
public class WorldHopping {
private final List<Integer> P2P_WORLDS = Arrays.asList(301, 302, 303, 304, 305, 306, 309, 310, 311, 312,
313, 314, 317, 318, 319, 320, 321, 322, 326, 327, 328, 329, 330, 333, 334,
335, 336, 338, 341, 342, 343, 344, 345, 346, 349, 350, 351, 352, 353, 354, 357,
358, 359, 360, 361, 362, 365, 366, 367, 368, 369, 370, 373, 374, 375, 376, 377, 378);
private final List<Integer> F2P_WORLDS = Arrays.asList(308, 316);
private final List<Integer> PVP_WORLDS = Arrays.asList(325, 337);
private List<Integer> future = new ArrayList<>();
private List<Integer> past = new ArrayList<>();
public WorldHopping(boolean p2pworlds, final boolean f2pworlds, final boolean pvpworlds) {
if (p2pworlds) {
future.addAll(P2P_WORLDS);
}
if (f2pworlds) {
future.addAll(F2P_WORLDS);
}
if (pvpworlds) {
future.addAll(PVP_WORLDS);
}
}
public void toRandomWorldNumber(){
int i = new Random().nextInt(future.size());
int w = future.get(i);
System.out.println(w);
future.remove(i);
past.add(w);
resetList();
}
public void toLowestWorldNumber(){
int w = Collections.min(future);
int i = future.indexOf(w);
System.out.println(w);
future.remove(i);
past.add(w);
resetList();
}
public void toHighestWorldNumber(){
int w = Collections.max(future);
int i = future.indexOf(w);
System.out.println(w);
future.remove(i);
past.add(w);
resetList();
}
private void resetList() {
if (future.isEmpty() && !past.isEmpty()) {
List<Integer> temp = future;
future = past;
past = temp;
past.clear();
}
}
public static void main(String args[])
{
WorldHopping hopper = new WorldHopping(true, true, true);
for(int i = 0; i < 1000; i++)
{
hopper.toRandomWorldNumber();
}
}
}
Output (it ran to 1000 iterations but these are the first few)
Note: You will have to put the world hopping method back from the API