2016-10-17 3 views
0

P.P.S. 좋아, 나는 Javers Comparing Lists 다음의 코멘트를 발견했다.LEVENSHTEIN_DISTANCE는 목록을 비교하여 순서를 무시하지 않습니다.

JaVers리스트 비교 알고리즘에는 이동의 개념이 없다. 이동 후에는 언급 한 것처럼 ValueAdded와 ValueRemoved라는 두 가지 변경 사항이보고됩니다.

하지만 실제로 어떻게 목록이 변경되지 않았는지 어떻게 알 수 있습니까?

P. @Entities와 @Id를 ZasFish, ZasCatchZone 및 ZasCatchArea로 가져가도 여전히 Diff : 1. NewObject {globalId : 'my.javers.comparator.ZasFish/2'} 2. ObjectRemoved {globalId : 'my. javers.comparator.ZasFish/1 '}

사용자 지정 개체 목록을 비교하려고합니다. LEVENSHTEIN_DISTANCE를 설정하고 맞춤 비교자를 만들었습니다. 객체 간의 유일한 차이점은 목록에있는 값의 순서입니다. 나는 "변화 없음"을 기대하지만 ListChange를 얻었다. 그 결과와 예가 아래와 같습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

많은 감사와 안부 안드레이

Diff: 
1. ListChange{globalId:'my.javers.comparator.ZasFish/', property:'zones', containerChanges:[(2).'[email protected]'>>'[email protected]', (1).'[email protected]'>>'[email protected]', (0).'[email protected]'>>'[email protected]']} 
2. ListChange{globalId:'my.javers.comparator.ZasFish/', property:'areas', containerChanges:[(2).'[email protected]'>>'[email protected]', (1).'[email protected]'>>'[email protected]', (0).'[email protected]'>>'[email protected]']} 



package my.javers.comparator; 

public class ZasCatchArea { 
    String catchArea; 

    public String getCatchArea() { 
     return catchArea; 
    } 

    public void setCatchArea(String catchArea) { 
     this.catchArea = catchArea; 
    } 
} 

public class ZasCatchZone { 
    String catchZone; 

    public String getCatchZone() { 
     return catchZone; 
    } 

    public void setCatchZone(String catchZone) { 
     this.catchZone = catchZone; 
    } 
} 

public class ZasFish { 
    String fischName; 
    List<ZasCatchZone> zones = new ArrayList<ZasCatchZone>(); 
    List<ZasCatchArea> areas = new ArrayList<ZasCatchArea>(); 

    public String getFischName() { 
     return fischName; 
    } 

    public void setFischName(String fischName) { 
     this.fischName = fischName; 
    } 

    public List<ZasCatchZone> getZones() { 
     return zones; 
    } 

    public void setZones(List<ZasCatchZone> zones) { 
     this.zones = zones; 
    } 

    public List<ZasCatchArea> getAreas() { 
     return areas; 
    } 
    public void setAreas(List<ZasCatchArea> areas) { 
     this.areas = areas; 
    } 
} 

public class ZasCatchAreaComparator implements 
CustomPropertyComparator<ZasCatchArea, ValueChange> { 

    public ValueChange compare(ZasCatchArea left, ZasCatchArea right, 
       GlobalId affectedCdoId, Property propertyName) { 
     if (left.getCatchArea().equals(right.getCatchArea())) 
      return null; 

     return new ValueChange(affectedCdoId, propertyName.getName(), left, right); 
    } 

} 

public class ZasCatchZoneComparator implements 
CustomPropertyComparator<ZasCatchZone, ValueChange> { 

    public ValueChange compare(ZasCatchZone left, ZasCatchZone right, 
        GlobalId affectedCdoId, Property propertyName) { 
     if (left.getCatchZone().equals(right.getCatchZone())) 
      return null; 

     return new ValueChange(affectedCdoId, propertyName.getName(), left, right); 
    } 

} 

public class MyComparator { 

    public static void main(String[] args) { 
     Javers javers = JaversBuilder.javers() 
      .registerCustomComparator(new ZasCatchAreaComparator(), ZasCatchArea.class) 
      .registerCustomComparator(new ZasCatchZoneComparator(), ZasCatchZone.class) 
      .withListCompareAlgorithm(ListCompareAlgorithm.LEVENSHTEIN_DISTANCE).build(); 

     ZasFish fisch1 = new ZasFish(); 
     ZasFish fisch2 = new ZasFish(); 

     ZasCatchZone z1 = new ZasCatchZone(); 
     z1.setCatchZone("zone1"); 
     ZasCatchZone z2 = new ZasCatchZone(); 
     z2.setCatchZone("zone2"); 
     ZasCatchZone z3 = new ZasCatchZone(); 
     z3.setCatchZone("zone3"); 

     fisch1.getZones().add(z1); 
     fisch1.getZones().add(z2); 
     fisch1.getZones().add(z3); 

     ZasCatchArea a1 = new ZasCatchArea(); 
     a1.setCatchArea("area1"); 
     ZasCatchArea a2 = new ZasCatchArea(); 
     a2.setCatchArea("area2"); 
     ZasCatchArea a3 = new ZasCatchArea(); 
     a3.setCatchArea("area3"); 

     fisch1.getAreas().add(a1); 
     fisch1.getAreas().add(a2); 
     fisch1.getAreas().add(a3); 

     ZasCatchZone z4 = new ZasCatchZone(); 
     z4.setCatchZone("zone3"); 
     ZasCatchZone z5 = new ZasCatchZone(); 
     z5.setCatchZone("zone2"); 
     ZasCatchZone z6 = new ZasCatchZone(); 
     z6.setCatchZone("zone1"); 

     fisch2.getZones().add(z4); 
     fisch2.getZones().add(z5); 
     fisch2.getZones().add(z6); 

     ZasCatchArea a4 = new ZasCatchArea(); 
     a4.setCatchArea("area3"); 
     ZasCatchArea a5 = new ZasCatchArea(); 
     a5.setCatchArea("area1"); 
     ZasCatchArea a6 = new ZasCatchArea(); 
     a6.setCatchArea("area2"); 

     fisch2.getAreas().add(a4); 
     fisch2.getAreas().add(a5); 
     fisch2.getAreas().add(a6); 

     Diff diff = javers.compare(fisch1, fisch2); 


     System.out.println(diff); 

    } 

} 

답변

0

나는 내 문제에 대한 해결책을 발견 생각합니다. 나는 그런 다음이

final Javers javers = JaversBuilder.javers() 
      .registerCustomComparator(new ZasCatchAreaComparator(), ZasCatchArea.class) 
      .registerCustomComparator(new ZasCatchZoneComparator(), ZasCatchZone.class) 
      .registerValue(ZasCatchArea.class).registerValue(ZasCatchZone.class).registerValueObject(ZasFish.class) 
      .withListCompareAlgorithm(ListCompareAlgorithm.LEVENSHTEIN_DISTANCE).build(); 

같은 가치와 값 객체를 등록하면 나는

1. ListChange{globalId:'my.javers.comparator.ZasFish/', property:'zones', containerChanges:[(2).'[email protected]'>>'[email protected]', (1).'[email protected]'>>'[email protected]', (0).'[email protected]'>>'[email protected]']} 
2. ListChange{globalId:'my.javers.comparator.ZasFish/', property:'areas', containerChanges:[(2).'[email protected]'>>'[email protected]', (1).'[email protected]'>>'[email protected]', (0).'[email protected]'>>'[email protected]']} 

으로 사랑하는 얻을 그리고이 경우에 어떤 ValueChange을 가지고 있지 않는 한 나는 ListChange를 무시할 수 있습니다 -> 내 목록이 동일 .

관련 문제