Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

list-compare

두 개의 리스트의 비교 결과

img.png Comparer 클래스를 통해서 두 개의 리스트를 비교하여 각각의 차집합과 교집합을 구할 수 있습니다.


usage

@Test
void useage() {
    List<SampleA> sampleAList = List.of(new SampleA("kureung", 10), new SampleA("mark", 15));
    List<SampleB> sampleBList = List.of(new SampleB("kureung", "news"), new SampleB("June", "coffee"));

    Comparer<SampleA, SampleB, SampleMatched> sut = new ComparerBuilder<SampleA, SampleB, SampleMatched>()
    .aList(sampleAList)
    .bList(sampleBList)
    .matchingClass(SampleMatched.class)
    .matchingCondition((a, b) -> a.name().equals(b.name()))
    .build();

    ComparedResult<SampleA, SampleB, SampleMatched> result = sut.compare();

    // A 차집합
    List<SampleA> onlyAList = result.onlyAList();
    assertThat(onlyAList)
    .hasSize(1)
    .contains(new SampleA("mark", 15));

    // B 차집합
    List<SampleB> onlyBList = result.onlyBList();
    assertThat(onlyBList)
    .hasSize(1)
    .contains(new SampleB("June", "coffee"));

    // 교집합
    List<SampleMatched> matched = result.matched();
    assertThat(matched)
    .hasSize(1)
    .contains(new SampleMatched("kureung", "news", 10));
    }
}

사용 조건

public SampleMatched(SampleA a, SampleB b) {
    this(a.name(), b.title(), a.age());
}
  • 교집합인SampleMatched클래스는 비교대상인 A 클래스B 클래스를 인수로 갖는 생성자를 가지고 있어야 합니다.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages