1515 */
1616package com .ibm .g11n .pipeline .resfilter ;
1717
18+ import java .util .ArrayList ;
19+ import java .util .Collections ;
1820import java .util .Comparator ;
21+ import java .util .List ;
1922import java .util .Objects ;
2023
2124/**
2427 */
2528
2629public final class ResourceString {
27- private final String note ;
30+ private List < String > notes ;
2831 private final String key ;
2932 private final String value ;
3033 private int sequenceNumber ;
3134
32- public ResourceString (String note , String key , String value , int sequenceNumber ) {
33- this .note = note ;
35+ public ResourceString (List < String > notes , String key , String value , int sequenceNumber ) {
36+ this .notes = notes ;
3437 this .key = key ;
3538 this .value = value ;
3639 this .sequenceNumber = sequenceNumber ;
3740 }
38-
41+
3942 public ResourceString (String key , String value , int sequenceNumber ) {
4043 this (null , key , value , sequenceNumber );
4144 }
@@ -52,8 +55,18 @@ public String getValue() {
5255 return value ;
5356 }
5457
55- public String getNote () {
56- return note ;
58+ public List <String > getNotes () {
59+ if (notes == null ) {
60+ return Collections .emptyList ();
61+ }
62+ return Collections .unmodifiableList (notes );
63+ }
64+
65+ public void addNote (String note ) {
66+ if (notes == null ) {
67+ notes = new ArrayList <String >();
68+ }
69+ notes .add (note );
5770 }
5871
5972 public void setSequenceNumber (int sequenceNumber ) {
@@ -70,10 +83,8 @@ public boolean equals(Object obj) {
7083 return false ;
7184 }
7285 ResourceString rs = (ResourceString ) obj ;
73- return Objects .equals (this .key , rs .key )
74- && Objects .equals (this .value , rs .value )
75- && Objects .equals (this .note , rs .note )
76- && this .sequenceNumber == rs .sequenceNumber ;
86+ return Objects .equals (this .key , rs .key ) && Objects .equals (this .value , rs .value )
87+ && Objects .equals (this .notes , rs .notes ) && this .sequenceNumber == rs .sequenceNumber ;
7788 }
7889
7990 @ Override
@@ -85,8 +96,8 @@ public String toString() {
8596 builder .append (getKey ());
8697 builder .append (" Value=" );
8798 builder .append (getValue ());
88- builder .append (" Note =" );
89- builder .append (getNote ());
99+ builder .append (" Notes =" );
100+ builder .append (getNotes (). toString ());
90101 return builder .toString ();
91102 }
92103
@@ -132,7 +143,7 @@ public int compare(ResourceString o1, ResourceString o2) {
132143 cmp = compareStrings (o1 .getValue (), o2 .getValue ());
133144 if (cmp == 0 ) {
134145 // Note value's natural order as tie-breaker
135- cmp = compareStrings (o1 .getNote (), o2 .getNote ());
146+ cmp = compareNotes (o1 .getNotes (), o2 .getNotes ());
136147 }
137148 }
138149
@@ -152,5 +163,32 @@ private static int compareStrings(String s1, String s2) {
152163 }
153164 return s1 .compareTo (s2 );
154165 }
166+
167+ private static int compareNotes (List <String > n1 , List <String > n2 ) {
168+ // null as lowest value
169+ if (n1 == null ) {
170+ if (n2 == null ) {
171+ return 0 ;
172+ } else {
173+ return -1 ;
174+ }
175+ } else if (n2 == null ) {
176+ return 1 ;
177+ }
178+ int cmp = 0 ;
179+ int index = 0 ;
180+ while (cmp == 0 && index < n1 .size ()) {
181+ String s1 = n1 .get (index );
182+ String s2 ;
183+ try {
184+ s2 = n2 .get (index );
185+ } catch (IndexOutOfBoundsException ex ) {
186+ s2 = null ;
187+ }
188+ cmp = compareStrings (s1 , s2 );
189+ index ++;
190+ }
191+ return cmp ;
192+ }
155193 }
156194}
0 commit comments