@@ -128,21 +128,20 @@ public boolean equals(Object o) {
128128 if (o == null || o .getClass () != this .getClass ())
129129 return false ;
130130 Port p = (Port )o ;
131- if (p .number != this .number || p .protocol != this .protocol )
132- return false ;
133- if (this .version !=null ) {
134- if (!this .version .equals (p .version ))
135- return false ;
136- } else if (p .version != null ) {
137- return false ;
131+ return (p .number == this .number && p .protocol == this .protocol );
132+ }
133+
134+ /**
135+ * merge data from this port to another
136+ * @param other
137+ */
138+ public void mergeTo (Port other ) {
139+ if (service != null && !service .equals (other .service )) {
140+ other .service = service ;
138141 }
139- if (this .service !=null ) {
140- if (!this .service .equals (p .service ))
141- return false ;
142- } else if (p .service !=null ) {
143- return false ;
142+ if (version != null && !version .equals (other .version )) {
143+ other .version = version ;
144144 }
145- return true ;
146145 }
147146 }
148147
@@ -657,18 +656,18 @@ public String getHostname(){
657656
658657 public void addOpenPort (Port port ){
659658 synchronized (mPorts ) {
660- if (port .service != null ) { // update service but preserve different versions
661- for (Port p : mPorts ) {
662- if (p .number == port .number && (p .service == null || p .service .isEmpty ())) {
663- p .service = port .service ;
664- p .version = port .version ;
665- return ;
666- }
659+ Port existing = null ;
660+ for (Port p : mPorts ) {
661+ if (p .equals (port )) {
662+ existing = p ;
663+ break ;
667664 }
668- mPorts .add (port );
665+ }
666+
667+ if (existing != null ) {
668+ port .mergeTo (existing );
669669 } else {
670- if (!mPorts .contains (port ))
671- mPorts .add (port );
670+ mPorts .add (port );
672671 }
673672 }
674673 }
0 commit comments