Merge "Install tools/libs from doc hub image"
[aaf/authz.git] / cadi / aaf / src / main / java / org / onap / aaf / cadi / aaf / v2_0 / AbsAAFLocator.java
index 19beef6..fc29760 100644 (file)
@@ -28,6 +28,7 @@ import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.NoSuchElementException;
 
 import org.onap.aaf.cadi.Access;
 import org.onap.aaf.cadi.Access.Level;
@@ -81,21 +82,8 @@ public abstract class AbsAAFLocator<TRANS extends Trans> implements Locator<URI>
                        this.version = Config.AAF_DEFAULT_VERSION;
                } else {
                        String[] split = Split.split(':', name);
-                       
-                       switch(split.length) {
-                               case 1:
-                                       this.name = split[0];
-                                       this.version = Config.AAF_DEFAULT_VERSION;
-                                       break;
-                               case 0:
-                                       this.name = name;
-                                       this.version = Config.AAF_DEFAULT_VERSION;
-                                       break;
-                               default:
-                                       this.version = split[1];
-                                       this.name = split[0];
-                                       
-                       }
+                       this.name = split[0];
+                       this.version = (split.length > 1) ? split[1] : Config.AAF_DEFAULT_VERSION;
                }
                
        }
@@ -137,13 +125,11 @@ public abstract class AbsAAFLocator<TRANS extends Trans> implements Locator<URI>
                if(key.startsWith("http")) {
                        if(name!=null) {
                                if(locatorCreator != null) {
-                                       if(name!=null) {
-                                               AbsAAFLocator<?> aal = locatorCreator.create(name, version);
-                                               if(pathInfo!=null) {
-                                                       aal.setPathInfo(pathInfo);
-                                               }
-                                               return aal;
+                                       AbsAAFLocator<?> aal = locatorCreator.create(name, version);
+                                       if(pathInfo!=null) {
+                                               aal.setPathInfo(pathInfo);
                                        }
+                                       return aal;
                                }
                        } else {
                                return new PropertyLocator(key);
@@ -291,7 +277,8 @@ public abstract class AbsAAFLocator<TRANS extends Trans> implements Locator<URI>
                        case 1:
                                return new AAFLItem(iter,first);
                        default:
-                               int i = Math.abs(sr.nextInt())%lep.size();
+                               int rand = sr.nextInt(); // Sonar chokes without.
+                               int i = Math.abs(rand)%lep.size();
                                if(i<0) {
                                        return null;
                                } else {
@@ -340,6 +327,9 @@ public abstract class AbsAAFLocator<TRANS extends Trans> implements Locator<URI>
 
                @Override
                public EP next() {
+                       if(!hasNext() ) {
+                               throw new NoSuchElementException();
+                       }
                        return (EP)epa[idx++];
                }
 
@@ -434,10 +424,10 @@ public abstract class AbsAAFLocator<TRANS extends Trans> implements Locator<URI>
                public int compareTo(EP o) {
                        if(distance<o.distance) {
                                return -1;
-                       } else if(distance==o.distance) {
-                               return 0;
-                       } else {
+                       } else if(distance>o.distance) {
                                return 1;
+                       } else {
+                               return 0;
                        }
                }
                
@@ -486,7 +476,7 @@ public abstract class AbsAAFLocator<TRANS extends Trans> implements Locator<URI>
                        try {
                                return new URI(rv.getScheme(),rv.getUserInfo(),rv.getHost(),rv.getPort(),pathInfo,query,fragment);
                        } catch (URISyntaxException e) {
-                               throw new LocatorException("Error coping URL");
+                               throw new LocatorException("Error copying URL");
                        }
                }
                return rv;