Skip to content

Commit 7627fd7

Browse files
authored
Merge math package to the lodash package.
1 parent 3d64c00 commit 7627fd7

File tree

15 files changed

+121
-993
lines changed

15 files changed

+121
-993
lines changed

checkstyle.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<module name="FileLength">
2121
<property name="fileExtensions" value="java"/>
2222
<property name="severity" value="warning"/>
23-
<property name="max" value="2600"/>
23+
<property name="max" value="3100"/>
2424
</module>
2525
<module name="RegexpSingleline">
2626
<property name="format" value="\s+$"/>

src/main/java/com/github/underscore/math/Directory.java renamed to src/main/java/com/github/underscore/lodash/Directory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* The MIT License (MIT)
33
*
4-
* Copyright 2017 Valentyn Kolesnikov
4+
* Copyright 2017-2018 Valentyn Kolesnikov
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -21,7 +21,7 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2222
* THE SOFTWARE.
2323
*/
24-
package com.github.underscore.math;
24+
package com.github.underscore.lodash;
2525

2626
import java.util.ArrayList;
2727
import java.util.List;

src/main/java/com/github/underscore/math/Entry.java renamed to src/main/java/com/github/underscore/lodash/Entry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* The MIT License (MIT)
33
*
4-
* Copyright 2017 Valentyn Kolesnikov
4+
* Copyright 2017-2018 Valentyn Kolesnikov
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -21,7 +21,7 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2222
* THE SOFTWARE.
2323
*/
24-
package com.github.underscore.math;
24+
package com.github.underscore.lodash;
2525

2626
public abstract class Entry {
2727
private final Directory parent;

src/main/java/com/github/underscore/math/File.java renamed to src/main/java/com/github/underscore/lodash/File.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* The MIT License (MIT)
33
*
4-
* Copyright 2017 Valentyn Kolesnikov
4+
* Copyright 2017-2018 Valentyn Kolesnikov
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -21,7 +21,7 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2222
* THE SOFTWARE.
2323
*/
24-
package com.github.underscore.math;
24+
package com.github.underscore.lodash;
2525

2626
public class File extends Entry {
2727
private final java.io.ByteArrayOutputStream stream;

src/main/java/com/github/underscore/lodash/U.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,11 @@ public Chain<String> fetch() {
653653
public Chain<String> fetch(final String method, final String body) {
654654
return new Chain<String>(U.fetch((String) item(), method, body).text());
655655
}
656+
657+
@SuppressWarnings("unchecked")
658+
public Chain<List<T>> createPermutationWithRepetition(final int permutationLength) {
659+
return new Chain<List<T>>(U.createPermutationWithRepetition((List<T>) value(), permutationLength));
660+
}
656661
}
657662

658663
public static Chain<String> chain(final String item) {
@@ -2955,4 +2960,53 @@ public void put(K key, V value) {
29552960
public static <K, V> LRUCache<K, V> createLRUCache(final int capacity) {
29562961
return new LRUCache<K, V>(capacity);
29572962
}
2963+
2964+
public static <T> List<List<T>> createPermutationWithRepetition(final List<T> list, final int permutationLength) {
2965+
final long resultSize = (long) Math.pow(list.size(), permutationLength);
2966+
final List<List<T>> result = new ArrayList<List<T>>((int) resultSize);
2967+
final int[] bitVector = new int[permutationLength];
2968+
for (int index = 0; index < resultSize; index += 1) {
2969+
List<T> result2 = new ArrayList<T>(permutationLength);
2970+
for (int index2 = 0; index2 < permutationLength; index2 += 1) {
2971+
result2.add(list.get(bitVector[index2]));
2972+
}
2973+
int index3 = 0;
2974+
while (index3 < permutationLength && bitVector[index3] == list.size() - 1) {
2975+
bitVector[index3] = 0;
2976+
index3 += 1;
2977+
}
2978+
if (index3 < permutationLength) {
2979+
bitVector[index3] += 1;
2980+
}
2981+
result.add(result2);
2982+
}
2983+
return result;
2984+
}
2985+
2986+
@SuppressWarnings("unchecked")
2987+
public List<List<T>> createPermutationWithRepetition(final int permutationLength) {
2988+
return createPermutationWithRepetition((List<T>) value(), permutationLength);
2989+
}
2990+
2991+
public static List<Entry> findByName(final Entry entry, final String name) {
2992+
final List<Entry> result = new ArrayList<Entry>();
2993+
final Queue<Entry> allFiles = new LinkedList<Entry>();
2994+
allFiles.add(entry);
2995+
while (!allFiles.isEmpty()) {
2996+
final Entry localEntry = allFiles.poll();
2997+
if (localEntry instanceof Directory) {
2998+
final List<Entry> files = ((Directory) localEntry).getContents();
2999+
for (final Entry innerFile : files) {
3000+
if (innerFile instanceof Directory) {
3001+
allFiles.add(innerFile);
3002+
} else if (innerFile.getName().equals(name)) {
3003+
result.add(innerFile);
3004+
}
3005+
}
3006+
} else if (localEntry.getName().equals(name)) {
3007+
result.add(localEntry);
3008+
}
3009+
}
3010+
return result;
3011+
}
29583012
}

0 commit comments

Comments
 (0)