Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add findDuplicates Method to ListUtils with Comprehensive Test Cases #537

Closed
wants to merge 35 commits into from
Closed
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
91e76c8
Add findDuplicates method to ListUtils with comprehensive test cases
hemanth0525 Aug 31, 2024
e12fc22
findDuplicates
hemanth0525 Sep 1, 2024
53c385d
updated tests
hemanth0525 Sep 1, 2024
8a2808a
Update tests
hemanth0525 Sep 1, 2024
0f26985
Merge branch 'apache:master' into master
hemanth0525 Sep 1, 2024
53f249d
Merge branch 'apache:master' into feature/findDuplicates
hemanth0525 Sep 1, 2024
c455e6a
Add findDuplicates
hemanth0525 Sep 1, 2024
f5c7e46
Merge branch 'apache:master' into feature/findDuplicates
hemanth0525 Sep 2, 2024
6ebffeb
Add findDuplicates
hemanth0525 Sep 2, 2024
9197ae3
Add findDuplicates
hemanth0525 Sep 1, 2024
57e86e3
Bump org.easymock:easymock from 5.3.0 to 5.4.0
dependabot[bot] Sep 1, 2024
a465792
Bump org.easymock:easymock from 5.3.0 to 5.4.0 #521
garydgregory Sep 1, 2024
2081cbe
Whitespace
garydgregory Sep 1, 2024
ff20df6
Use Java 8's Map.getOrDefault()
garydgregory Sep 1, 2024
2adf5ee
Reimplement the package-private CollectionUtils.CardinalityHelper using
garydgregory Sep 1, 2024
40dc0aa
Add HashBag.HashBag(Iterable)
garydgregory Sep 1, 2024
94c51b3
[COLLECTIONS-858] CartesianProductIterator
alexey-pelykh Jun 25, 2024
eb748a3
Add CartesianProductIterator #509
garydgregory Sep 1, 2024
740ed3a
Javadoc
garydgregory Sep 1, 2024
3c991c0
Inline redundant package-private method that wraps
garydgregory Sep 1, 2024
6e273e7
Use Assertions.assertInstanceOf()
garydgregory Sep 1, 2024
1036610
Add findDuplicates
hemanth0525 Sep 2, 2024
dd78ec6
Merge branch 'feature/findDuplicates' of https://github.com/hemanth05…
hemanth0525 Sep 2, 2024
3137d22
Merge branch 'apache:master' into master
hemanth0525 Sep 2, 2024
053d2dd
Merge branch 'master' of https://github.com/apache/commons-collection…
hemanth0525 Sep 2, 2024
0e70f14
Add findDuplicates
hemanth0525 Sep 2, 2024
cb62f7a
Merge branch 'apache:master' into master
hemanth0525 Sep 3, 2024
e915879
Merge branch 'apache:master' into feature/findDuplicates
hemanth0525 Sep 4, 2024
277063f
Add diverse test cases for IterableUtils.duplicateList:
hemanth0525 Sep 4, 2024
3eaeeb6
Merge branch 'master' of https://github.com/hemanth0525/commons-colle…
hemanth0525 Sep 4, 2024
6423bf3
Corrected spaces and lines
hemanth0525 Sep 5, 2024
1f6ce8b
Merge branch 'apache:master' into feature/findDuplicates
hemanth0525 Sep 8, 2024
bcb765b
Add more Comprehensive tests IterableUtils.duplicateList
hemanth0525 Sep 8, 2024
f1b2f22
Merge branch 'feature/findDuplicates' of https://github.com/hemanth05…
hemanth0525 Sep 8, 2024
12dccf9
remove duplicate imports
hemanth0525 Sep 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.Set;

import org.apache.commons.collections4.bag.HashBag;
Expand Down Expand Up @@ -300,6 +301,92 @@ public void testDuplicatSetAllSameInDeque() {
assertEquals(new HashSet<>(Arrays.asList(5)), IterableUtils.duplicateSet(input));
}

@Test
public void testDuplicateListMixedElementTypes() {
final List<Object> input = Arrays.asList(1, "a", 2, "a", 3, "b", "b");
final List<Object> expected = Arrays.asList("a", "b");
assertEquals(expected, IterableUtils.duplicateList(input));
}

@Test
public void testDuplicateListNestedCollections() {
final List<List<Integer>> input = Arrays.asList(
Arrays.asList(1, 2, 3),
Arrays.asList(1, 2, 3),
Arrays.asList(4, 5, 6),
Arrays.asList(4, 5, 6)
);
final List<List<Integer>> expected = Arrays.asList(
Arrays.asList(1, 2, 3),
Arrays.asList(4, 5, 6)
);
assertEquals(expected, IterableUtils.duplicateList(input));
}

@Test
public void testDuplicateListCustomObjects() {
class Person {
String name;
int age;

Person(String name, int age) {
this.name = name;
this.age = age;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Person person = (Person) o;
return age == person.age && name.equals(person.name);
}

@Override
public int hashCode() {
return Objects.hash(name, age);
}
}

final List<Person> input = Arrays.asList(
new Person("Linus", 30),
new Person("Torvalds", 25),
new Person("Linus", 30),
new Person("Tim", 35),
new Person("Torvalds", 25)
);
final List<Person> expected = Arrays.asList(
new Person("Linus", 30),
new Person("Torvalds", 25)
);
assertEquals(expected, IterableUtils.duplicateList(input));
}

@Test
public void testDuplicateListLargeScaleData() {
final List<Integer> input = new ArrayList<>();
for (int i = 0; i < 1000; i++) {
input.add(i % 100);
}
final List<Integer> expected = new ArrayList<>();
for (int i = 0; i < 100; i++) {
expected.add(i);
}
final List<Integer> actual = IterableUtils.duplicateList(input);
assertEquals(expected, actual);
}

@Test
public void testDuplicateListImmutableCollections() {
final List<Integer> input = Collections.unmodifiableList(Arrays.asList(1, 2, 3, 1, 2, 4));
final List<Integer> expected = Arrays.asList(1, 2);
assertEquals(expected, IterableUtils.duplicateList(input));
}

@Test
public void testFind() {
Predicate<Number> testPredicate = equalPredicate(4);
Expand Down