1212import org .lfenergy .compas .scl2007b4 .model .TLLN0Enum ;
1313import org .lfenergy .compas .scl2007b4 .model .TServiceType ;
1414
15+ import java .util .Comparator ;
1516import java .util .Objects ;
1617import java .util .regex .Matcher ;
1718import java .util .regex .Pattern ;
3940@ Getter
4041@ Setter
4142@ NoArgsConstructor
42- public class ExtRefBindingInfo {
43+ public class ExtRefBindingInfo implements Comparable < ExtRefBindingInfo > {
4344
45+ public static final Comparator <ExtRefBindingInfo > EXT_REF_BINDING_INFO_COMPARATOR = Comparator .comparing (ExtRefBindingInfo ::getIedName )
46+ .thenComparing (ExtRefBindingInfo ::getLdInst )
47+ .thenComparing (ExtRefBindingInfo ::getLnClass )
48+ .thenComparing (ExtRefBindingInfo ::getLnInst );
4449 private String iedName ;
4550 private String ldInst ;
4651 private String prefix ;
@@ -53,23 +58,24 @@ public class ExtRefBindingInfo {
5358
5459 /**
5560 * Constructor
61+ *
5662 * @param tExtRef input
5763 */
58- public ExtRefBindingInfo (TExtRef tExtRef ){
64+ public ExtRefBindingInfo (TExtRef tExtRef ) {
5965 iedName = tExtRef .getIedName ();
6066 ldInst = tExtRef .getLdInst ();
6167 prefix = tExtRef .getPrefix ();
62- if (!tExtRef .getLnClass ().isEmpty ()) {
68+ if (!tExtRef .getLnClass ().isEmpty ()) {
6369 this .lnClass = tExtRef .getLnClass ().get (0 );
6470 }
6571 lnInst = tExtRef .getLnInst ();
66- if (tExtRef .getDoName () != null ) {
72+ if (tExtRef .getDoName () != null ) {
6773 doName = new DoTypeName (tExtRef .getDoName ());
6874 }
69- if (tExtRef .getDaName () != null ) {
75+ if (tExtRef .getDaName () != null ) {
7076 daName = new DaTypeName (tExtRef .getDaName ());
7177 }
72- if (tExtRef .getServiceType () != null ) {
78+ if (tExtRef .getServiceType () != null ) {
7379 serviceType = tExtRef .getServiceType ();
7480 }
7581 }
@@ -100,33 +106,35 @@ public int hashCode() {
100106
101107 /**
102108 * Check validity of ExtRef binding information
109+ *
103110 * @return validity state
104111 */
105112 public boolean isValid () {
106113 final String validationRegex = DaTypeName .VALIDATION_REGEX ;
107114 String doRef = doName == null ? "" : doName .toString ();
108115
109- Pattern pattern = Pattern .compile (validationRegex ,Pattern .MULTILINE );
116+ Pattern pattern = Pattern .compile (validationRegex , Pattern .MULTILINE );
110117 Matcher matcher = pattern .matcher (doRef );
111118 matcher .find ();
112119
113- if (!StringUtils .isBlank (doRef ) && doRef .length () != matcher .end ()){
120+ if (!StringUtils .isBlank (doRef ) && doRef .length () != matcher .end ()) {
114121 return false ;
115122 }
116123 return !StringUtils .isBlank (iedName ) &&
117124 !StringUtils .isBlank (ldInst ) &&
118125 !StringUtils .isBlank (lnClass ) &&
119- (TLLN0Enum .LLN_0 .value ().equals (lnClass ) || !StringUtils .isBlank (lnInst )) ;
126+ (TLLN0Enum .LLN_0 .value ().equals (lnClass ) || !StringUtils .isBlank (lnInst ));
120127 }
121128
122129 /**
123130 * Check dependency between ExtRef binding information and ExtRef
131+ *
124132 * @param tExtRef object containing ExtRef data's'
125133 * @return dependency state
126134 */
127- public boolean isWrappedIn (TExtRef tExtRef ){
128- return Objects .equals (iedName ,tExtRef .getIedName ()) &&
129- Objects .equals (ldInst ,tExtRef .getLdInst ()) &&
135+ public boolean isWrappedIn (TExtRef tExtRef ) {
136+ return Objects .equals (iedName , tExtRef .getIedName ()) &&
137+ Objects .equals (ldInst , tExtRef .getLdInst ()) &&
130138 Objects .equals (prefix , tExtRef .getPrefix ()) &&
131139 Objects .equals (lnInst , tExtRef .getLnInst ()) &&
132140 tExtRef .getLnClass ().contains (lnClass ) &&
@@ -135,9 +143,10 @@ public boolean isWrappedIn(TExtRef tExtRef){
135143
136144 /**
137145 * Check nullability of ExtRef binding information
138- * @return nullability state
146+ *
147+ * @return nullability state
139148 */
140- public boolean isNull (){
149+ public boolean isNull () {
141150 return iedName == null &&
142151 ldInst == null &&
143152 prefix == null &&
@@ -149,19 +158,13 @@ public boolean isNull(){
149158 }
150159
151160 /**
152- * Convert to string
153- * @return ExtRef binding information formatted to string
161+ * Define the way to compare 2 objects ExtRefBindingInfo in order to allow sorting items
162+ *
163+ * @param o the object to be compared.
164+ * @return the comparaison's result (a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second)
154165 */
155166 @ Override
156- public String toString () {
157- return "ExtRefBindingInfo{" +
158- "iedName='" + iedName + '\'' +
159- ", ldInst='" + ldInst + '\'' +
160- ", prefix='" + prefix + '\'' +
161- ", lnClass='" + lnClass + '\'' +
162- ", lnInst='" + lnInst + '\'' +
163- ", lnType='" + lnType + '\'' +
164- ", serviceType=" + serviceType .value () +
165- '}' ;
167+ public int compareTo (ExtRefBindingInfo o ) {
168+ return EXT_REF_BINDING_INFO_COMPARATOR .compare (this , o );
166169 }
167170}
0 commit comments