Created
October 29, 2015 15:41
-
-
Save jpetitto/9db54c105fed2acd628b to your computer and use it in GitHub Desktop.
Least Hacky Loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<Item> allBucket = ... | |
List<Item> genderBucket = ... | |
List<Item> sizeBucket = ... | |
List<Item> colorBucket = ... | |
List<Item> recommendations = new ArrayList<>(); | |
picker(recommendations, limit, colorBucket, sizeBucket, genderBucket, allBucket); | |
private <T> int picker(List<T> src, List<T> dst, int limit) { | |
Iterator<T> iterator = src.iterator(); | |
while (iterator.hasNext() && limit > 0) { | |
dst.add(iterator.next()); | |
limit--; | |
} | |
return limit; | |
} | |
private <T> void picker(List<T> dst, int limit, List<T>... sources) { | |
for (List<T> src : sources) { | |
while (picker(src, dst, limit) > 0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment