knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kris...@apache.org
Subject [1/5] knox git commit: KNOX-1664 - Miscellaneous code cleanup
Date Sat, 08 Dec 2018 14:29:54 GMT
Repository: knox
Updated Branches:
  refs/heads/master 6736393dd -> f54e9d2d4


http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-util-common/src/main/java/org/apache/knox/gateway/util/JsonPath.java
----------------------------------------------------------------------
diff --git a/gateway-util-common/src/main/java/org/apache/knox/gateway/util/JsonPath.java
b/gateway-util-common/src/main/java/org/apache/knox/gateway/util/JsonPath.java
index 9a2a961..d231f34 100644
--- a/gateway-util-common/src/main/java/org/apache/knox/gateway/util/JsonPath.java
+++ b/gateway-util-common/src/main/java/org/apache/knox/gateway/util/JsonPath.java
@@ -74,17 +74,14 @@ public class JsonPath {
 
     @Override
     public String toString() {
-      StringBuilder s = new StringBuilder();
-      s.append( "JsonPath{" );
-      s.append( "parent=" ); s.append( getParent() );
-      s.append( ",segment=" ); s.append( getSegment() );
-      s.append( ",node=" ); s.append( getNode() );
-      s.append( ",field=" ); s.append( getField() );
-      s.append( ",index=" ); s.append( getIndex() );
-      s.append( "}" );
-      return s.toString();
+      return "JsonPath{" +
+                 "parent=" + getParent() +
+                 ",segment=" + getSegment() +
+                 ",node=" + getNode() +
+                 ",field=" + getField() +
+                 ",index=" + getIndex() +
+                 "}";
     }
-
   }
 
   public static class Expression {
@@ -115,7 +112,7 @@ public class JsonPath {
       Segment segment;
       StringTokenizer parser = new StringTokenizer( expression, "$.[]()@?:,", true );
       String currToken = null;
-      String prevToken = null;
+      String prevToken;
       while( parser.hasMoreTokens() ) {
         prevToken = currToken;
         if( insideBrackets ) {
@@ -372,13 +369,11 @@ public class JsonPath {
 
     @Override
     public String toString() {
-      StringBuilder s = new StringBuilder();
-      s.append( "JsonPath.Segment{" );
-      s.append( "type=" ); s.append( getType() );
-      s.append( ",field=" ); s.append( getField() );
-      s.append( ",index=" ); s.append( getIndex() );
-      s.append( "}" );
-      return s.toString();
+      return "JsonPath.Segment{" +
+                 "type=" + getType() +
+                 ",field=" + getField() +
+                 ",index=" + getIndex() +
+                 "}";
     }
   }
 

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-util-common/src/main/java/org/apache/knox/gateway/util/JsonUtils.java
----------------------------------------------------------------------
diff --git a/gateway-util-common/src/main/java/org/apache/knox/gateway/util/JsonUtils.java
b/gateway-util-common/src/main/java/org/apache/knox/gateway/util/JsonUtils.java
index a86e4d1..6662767 100644
--- a/gateway-util-common/src/main/java/org/apache/knox/gateway/util/JsonUtils.java
+++ b/gateway-util-common/src/main/java/org/apache/knox/gateway/util/JsonUtils.java
@@ -25,10 +25,8 @@ import org.apache.knox.gateway.i18n.GatewayUtilCommonMessages;
 import org.apache.knox.gateway.i18n.messages.MessagesFactory;
 
 import com.fasterxml.jackson.core.JsonFactory;
-import com.fasterxml.jackson.core.JsonParseException;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.JsonMappingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 
 public class JsonUtils {
@@ -55,10 +53,6 @@ public class JsonUtils {
           = new TypeReference<HashMap<String,String>>() {};
     try {
       map = mapper.readValue(json, typeRef);
-    } catch (JsonParseException e) {
-      LOG.failedToGetMapFromJsonString( json, e );
-    } catch (JsonMappingException e) {
-      LOG.failedToGetMapFromJsonString( json, e );
     } catch (IOException e) {
       LOG.failedToGetMapFromJsonString( json, e );
     }

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-util-common/src/main/java/org/apache/knox/gateway/util/Urls.java
----------------------------------------------------------------------
diff --git a/gateway-util-common/src/main/java/org/apache/knox/gateway/util/Urls.java b/gateway-util-common/src/main/java/org/apache/knox/gateway/util/Urls.java
index 346f3f3..bb500a9 100644
--- a/gateway-util-common/src/main/java/org/apache/knox/gateway/util/Urls.java
+++ b/gateway-util-common/src/main/java/org/apache/knox/gateway/util/Urls.java
@@ -131,9 +131,7 @@ public class Urls {
     URLCodec codec = new URLCodec();
     try {
       return codec.decode( str, StandardCharsets.UTF_8.name() );
-    } catch( UnsupportedEncodingException e ) {
-      throw new IllegalArgumentException( e );
-    } catch( DecoderException e ) {
+    } catch( UnsupportedEncodingException | DecoderException e ) {
       throw new IllegalArgumentException( e );
     }
   }
@@ -154,14 +152,14 @@ public class Urls {
     StringBuilder s = new StringBuilder();
     if( parts != null ) {
       String p = "";
-      String n = "";
-      for( int i=0; i<parts.length; i++ ) {
-        n = trimLeadingAndTrailingSlash( parts[i] );
-        if( !n.isEmpty() ) {
-          if( !p.isEmpty() ) {
-            s.append( '/' );
+      String n;
+      for (String part : parts) {
+        n = trimLeadingAndTrailingSlash(part);
+        if (!n.isEmpty()) {
+          if (!p.isEmpty()) {
+            s.append('/');
           }
-          s.append( n );
+          s.append(n);
           p = n;
         }
       }

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-util-common/src/main/java/org/apache/knox/gateway/util/X500PrincipalParser.java
----------------------------------------------------------------------
diff --git a/gateway-util-common/src/main/java/org/apache/knox/gateway/util/X500PrincipalParser.java
b/gateway-util-common/src/main/java/org/apache/knox/gateway/util/X500PrincipalParser.java
index bb1f3fe..7f5c52e 100644
--- a/gateway-util-common/src/main/java/org/apache/knox/gateway/util/X500PrincipalParser.java
+++ b/gateway-util-common/src/main/java/org/apache/knox/gateway/util/X500PrincipalParser.java
@@ -19,7 +19,6 @@ package org.apache.knox.gateway.util;
 
 
 import java.util.ArrayList;
-import java.util.Iterator;
 
 import javax.security.auth.x500.X500Principal;
 
@@ -52,13 +51,11 @@ public class X500PrincipalParser
     ArrayList retList = new ArrayList();
     String searchPart = attributeID + attrTerminator;
 
-    for(Iterator iter = rdnNameArray.iterator(); iter.hasNext();)
-    {
-      ArrayList nameList = (ArrayList)iter.next();
-      String namePart = (String)nameList.get(0);
+    for (Object o : rdnNameArray) {
+      ArrayList nameList = (ArrayList) o;
+      String namePart = (String) nameList.get(0);
 
-      if(namePart.startsWith(searchPart))
-      {
+      if (namePart.startsWith(searchPart)) {
         // Return the string starting after the ID string and the = sign that follows it.
         retList.add(namePart.toString().substring(searchPart.length()));
       }
@@ -125,17 +122,15 @@ public class X500PrincipalParser
     String retNamePart = null;
     String searchPart = attributeID + attrTerminator;
 
-    for(Iterator iter = rdnNameArray.iterator(); iter.hasNext();)
-    {
-      ArrayList nameList = (ArrayList)iter.next();
-      String namePart = (String)nameList.get(0);
+    for (Object o : rdnNameArray) {
+      ArrayList nameList = (ArrayList) o;
+      String namePart = (String) nameList.get(0);
 
-      if(namePart.startsWith(searchPart))
-      {
+      if (namePart.startsWith(searchPart)) {
         // Return the string starting after the ID string and the = sign that follows it.
         retNamePart = namePart.toString().substring(searchPart.length());
         // By definition the first one is most significant
-        if(significance == MOSTSIGNIFICANT)
+        if (significance == MOSTSIGNIFICANT)
           break;
       }
     }

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-util-common/src/test/java/org/apache/knox/gateway/util/JsonPathTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-common/src/test/java/org/apache/knox/gateway/util/JsonPathTest.java
b/gateway-util-common/src/test/java/org/apache/knox/gateway/util/JsonPathTest.java
index 8b9230c..4569647 100644
--- a/gateway-util-common/src/test/java/org/apache/knox/gateway/util/JsonPathTest.java
+++ b/gateway-util-common/src/test/java/org/apache/knox/gateway/util/JsonPathTest.java
@@ -66,6 +66,7 @@ public class JsonPathTest {
         JsonPath.compile( path );
         fail( "Expected IllegalArgumentException" );
       } catch( IllegalArgumentException e ) {
+        // Expected exception
       }
     }
 

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-util-configinjector/src/main/java/org/apache/knox/gateway/config/impl/DefaultConfigurationInjector.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/main/java/org/apache/knox/gateway/config/impl/DefaultConfigurationInjector.java
b/gateway-util-configinjector/src/main/java/org/apache/knox/gateway/config/impl/DefaultConfigurationInjector.java
index 80022c6..8873167 100755
--- a/gateway-util-configinjector/src/main/java/org/apache/knox/gateway/config/impl/DefaultConfigurationInjector.java
+++ b/gateway-util-configinjector/src/main/java/org/apache/knox/gateway/config/impl/DefaultConfigurationInjector.java
@@ -128,7 +128,7 @@ public class DefaultConfigurationInjector implements ConfigurationInjector
{
   }
 
   private Object convertValue( Object target, String name, Object strValue, Class<?>
type ) {
-    Object objValue = null;
+    Object objValue;
     try {
       objValue = DEFAULT_CONVERTER.convert( strValue, type );
     } catch( Exception e ) {
@@ -170,7 +170,7 @@ public class DefaultConfigurationInjector implements ConfigurationInjector
{
     String name = implied;
     if( explicit != null ) {
       String tagValue = explicit.value().trim();
-      if( tagValue.length() > 0 ) {
+      if(!tagValue.isEmpty()) {
         name = tagValue;
       }
     }
@@ -178,7 +178,7 @@ public class DefaultConfigurationInjector implements ConfigurationInjector
{
   }
 
   private static String getBindName( Object target, String name, ConfigurationBinding binding
) {
-    String bind = null;
+    String bind;
     try {
       bind = binding.getConfigurationName( name );
     } catch( Exception e ) {
@@ -202,7 +202,7 @@ public class DefaultConfigurationInjector implements ConfigurationInjector
{
         if( tag != null && tag instanceof Alias ) {
           Alias aliasTag = (Alias) tag;
           String aliasValue = aliasTag.value().trim();
-          if( aliasValue.length() > 0 ) {
+          if(!aliasValue.isEmpty()) {
             name = aliasValue;
             break;
           }

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-util-configinjector/src/test/java/org/apache/knox/gateway/config/FuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/test/java/org/apache/knox/gateway/config/FuncTest.java
b/gateway-util-configinjector/src/test/java/org/apache/knox/gateway/config/FuncTest.java
index 06cb670..7e40212 100755
--- a/gateway-util-configinjector/src/test/java/org/apache/knox/gateway/config/FuncTest.java
+++ b/gateway-util-configinjector/src/test/java/org/apache/knox/gateway/config/FuncTest.java
@@ -40,7 +40,7 @@ public class FuncTest {
     int intMember = 1;
 
     @Configure
-    Integer integerMember = Integer.valueOf( 1 );
+    Integer integerMember = 1;
 
     @Configure
     public void setStringProp( String s ) {
@@ -96,7 +96,7 @@ public class FuncTest {
 
     assertThat( testBean.stringMember, is( "stringValue" ) );
     assertThat( testBean.intMember, is( 2 ) );
-    assertThat( testBean.integerMember, is( Integer.valueOf(2) ) );
+    assertThat( testBean.integerMember, is(2) );
     assertThat( testBean.stringPropField, is( "stringValue" ) );
     assertThat( testBean.stringPropFieldAlt, is( "stringValue" ) );
     assertThat( testBean.stringPropFieldAltArg, is( "stringValue" ) );
@@ -125,7 +125,7 @@ public class FuncTest {
 
     assertThat( testBean.stringMember, is( "stringValue" ) );
     assertThat( testBean.intMember, is( 2 ) );
-    assertThat( testBean.integerMember, is( Integer.valueOf(2) ) );
+    assertThat( testBean.integerMember, is(2) );
     assertThat( testBean.stringPropField, is( "stringValue" ) );
     assertThat( testBean.stringPropFieldAlt, is( "stringValue" ) );
     assertThat( testBean.stringPropFieldAltArg, is( "stringValue" ) );
@@ -169,7 +169,7 @@ public class FuncTest {
 
     assertThat( testBean.stringMember, is( "stringValue" ) );
     assertThat( testBean.intMember, is( 2 ) );
-    assertThat( testBean.integerMember, is( Integer.valueOf(2) ) );
+    assertThat( testBean.integerMember, is(2) );
     assertThat( testBean.stringPropField, is( "stringValue" ) );
     assertThat( testBean.stringPropFieldAlt, is( "stringValue" ) );
     assertThat( testBean.stringPropFieldAltArg, is( "stringValue" ) );
@@ -184,12 +184,12 @@ public class FuncTest {
     Map<Object,Object> testConfig = new HashMap<>();
     testConfig.put( "stringMember", "stringValue" );
     testConfig.put( "intMember", 42 );
-    testConfig.put( "integerMember", Integer.valueOf(42) );
+    testConfig.put( "integerMember", 42);
     testConfig.put( "stringProp", "stringValue" );
     testConfig.put( "altStringProp", "stringValue" );
     testConfig.put( "altArgStringProp", "stringValue" );
     testConfig.put( "multiArg1", "stringValue" );
-    testConfig.put( "multiArg2", Integer.valueOf(42) );
+    testConfig.put( "multiArg2", 42);
     testConfig.put( "multiArg3", "42" );
 
     TestBean testBean = new TestBean();
@@ -198,7 +198,7 @@ public class FuncTest {
 
     assertThat( testBean.stringMember, is( "stringValue" ) );
     assertThat( testBean.intMember, is( 42 ) );
-    assertThat( testBean.integerMember, is( Integer.valueOf(42) ) );
+    assertThat( testBean.integerMember, is(42) );
     assertThat( testBean.stringPropField, is( "stringValue" ) );
     assertThat( testBean.stringPropFieldAlt, is( "stringValue" ) );
     assertThat( testBean.stringPropFieldAltArg, is( "stringValue" ) );

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-util-configinjector/src/test/java/org/apache/knox/gateway/config/OptionalTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/test/java/org/apache/knox/gateway/config/OptionalTest.java
b/gateway-util-configinjector/src/test/java/org/apache/knox/gateway/config/OptionalTest.java
index 005875e..a805a90 100644
--- a/gateway-util-configinjector/src/test/java/org/apache/knox/gateway/config/OptionalTest.java
+++ b/gateway-util-configinjector/src/test/java/org/apache/knox/gateway/config/OptionalTest.java
@@ -33,7 +33,7 @@ public class OptionalTest {
   class SetterTarget {
     private int num = -1;
     @Configure
-    public void setNum( @Default("-1") int n ) { this.num = n; };
+    public void setNum( @Default("-1") int n ) { this.num = n; }
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-util-configinjector/src/test/java/org/apache/knox/gateway/config/impl/BeanConfigurationAdapterDescriptorTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/test/java/org/apache/knox/gateway/config/impl/BeanConfigurationAdapterDescriptorTest.java
b/gateway-util-configinjector/src/test/java/org/apache/knox/gateway/config/impl/BeanConfigurationAdapterDescriptorTest.java
index edee20a..a114ba1 100755
--- a/gateway-util-configinjector/src/test/java/org/apache/knox/gateway/config/impl/BeanConfigurationAdapterDescriptorTest.java
+++ b/gateway-util-configinjector/src/test/java/org/apache/knox/gateway/config/impl/BeanConfigurationAdapterDescriptorTest.java
@@ -21,7 +21,6 @@ import org.apache.knox.gateway.config.ConfigurationAdapter;
 import org.apache.knox.gateway.config.spi.ConfigurationAdapterDescriptor;
 import org.junit.Test;
 
-import java.util.Iterator;
 import java.util.Map;
 import java.util.ServiceLoader;
 
@@ -34,9 +33,8 @@ public class BeanConfigurationAdapterDescriptorTest {
   @Test
   public void testServiceLoader() {
     ServiceLoader<ConfigurationAdapterDescriptor> loader = ServiceLoader.load( ConfigurationAdapterDescriptor.class
);
-    Iterator<ConfigurationAdapterDescriptor> i = loader.iterator();
-    while( i.hasNext() ) {
-      if( i.next() instanceof BeanConfigurationAdapterDescriptor ) {
+    for (ConfigurationAdapterDescriptor configurationAdapterDescriptor : loader) {
+      if (configurationAdapterDescriptor instanceof BeanConfigurationAdapterDescriptor) {
         return;
       }
     }

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-util-configinjector/src/test/java/org/apache/knox/gateway/config/impl/BeanConfigurationAdapterTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/test/java/org/apache/knox/gateway/config/impl/BeanConfigurationAdapterTest.java
b/gateway-util-configinjector/src/test/java/org/apache/knox/gateway/config/impl/BeanConfigurationAdapterTest.java
index 5f95651..fde44b3 100755
--- a/gateway-util-configinjector/src/test/java/org/apache/knox/gateway/config/impl/BeanConfigurationAdapterTest.java
+++ b/gateway-util-configinjector/src/test/java/org/apache/knox/gateway/config/impl/BeanConfigurationAdapterTest.java
@@ -27,7 +27,7 @@ public class BeanConfigurationAdapterTest {
   public static class Bean {
     public String getValue() {
       return "beanValue";
-    };
+    }
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-util-launcher/src/main/java/org/apache/knox/gateway/launcher/Config.java
----------------------------------------------------------------------
diff --git a/gateway-util-launcher/src/main/java/org/apache/knox/gateway/launcher/Config.java
b/gateway-util-launcher/src/main/java/org/apache/knox/gateway/launcher/Config.java
index 8e932f8..20a26ff 100644
--- a/gateway-util-launcher/src/main/java/org/apache/knox/gateway/launcher/Config.java
+++ b/gateway-util-launcher/src/main/java/org/apache/knox/gateway/launcher/Config.java
@@ -49,7 +49,7 @@ public class Config {
       String line = input.readLine();
       while( line != null ) {
         line = line.trim();
-        if( line.length() == 0 ) {
+        if(line.isEmpty()) {
           // Ignore blank lines.
         } else if( line.startsWith( COMMENT_PREFIX ) ) {
           // Ignore comments.
@@ -84,7 +84,7 @@ public class Config {
       PrintWriter output = new PrintWriter( writer );
       Map<String,String> map = sections.get( DEFAULT_NAME );
       if( map != null ) {
-        empty &= ( map.size() == 0 );
+        empty &= (map.isEmpty());
         saveMap( output, map );
       }
       for( Map.Entry<String,Map<String,String>> entry : sections.entrySet() )
{

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-util-launcher/src/main/java/org/apache/knox/gateway/launcher/Invoker.java
----------------------------------------------------------------------
diff --git a/gateway-util-launcher/src/main/java/org/apache/knox/gateway/launcher/Invoker.java
b/gateway-util-launcher/src/main/java/org/apache/knox/gateway/launcher/Invoker.java
index 74b227f..c302ac1 100644
--- a/gateway-util-launcher/src/main/java/org/apache/knox/gateway/launcher/Invoker.java
+++ b/gateway-util-launcher/src/main/java/org/apache/knox/gateway/launcher/Invoker.java
@@ -56,13 +56,11 @@ class Invoker {
   }
 
   private static Class loadMainClass( ClassLoader loader, String className ) throws ClassNotFoundException
{
-    Class mainClass = loader.loadClass( className );
-    return mainClass;
+    return loader.loadClass( className );
   }
 
   private static Method findMainMethod( Class mainClass, String methodName ) throws NoSuchMethodException
{
-    Method method = mainClass.getMethod( methodName, STRING_ARRAY_CLASS );
-    return method;
+    return mainClass.getMethod( methodName, STRING_ARRAY_CLASS );
   }
 
   private static void invokeMainMethod( ClassLoader loader, Method method, String[] args
) throws InvocationTargetException, IllegalAccessException {

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-util-launcher/src/main/java/org/apache/knox/gateway/launcher/Launcher.java
----------------------------------------------------------------------
diff --git a/gateway-util-launcher/src/main/java/org/apache/knox/gateway/launcher/Launcher.java
b/gateway-util-launcher/src/main/java/org/apache/knox/gateway/launcher/Launcher.java
index 2c26be1..92092dc 100644
--- a/gateway-util-launcher/src/main/java/org/apache/knox/gateway/launcher/Launcher.java
+++ b/gateway-util-launcher/src/main/java/org/apache/knox/gateway/launcher/Launcher.java
@@ -77,19 +77,7 @@ public class Launcher {
 
   private static URL findLauncherJar() throws IOException {
     URL jarUrl;
-    try {
-      jarUrl = Launcher.class.getProtectionDomain().getCodeSource().getLocation();
-    } catch( SecurityException e ) {
-      throw e;
-//      URL classUrl = Launcher.class.getResource( Launcher.class.getSimpleName() + ".class"
);
-//      if( classUrl != null ) {
-//        URLConnection urlConnection = classUrl.openConnection();
-//        if( urlConnection instanceof JarURLConnection ) {
-//          JarURLConnection jarUrlConnection = (JarURLConnection)urlConnection;
-//          jarUrl = jarUrlConnection.getJarFileURL();
-//        }
-//      }
-    }
+    jarUrl = Launcher.class.getProtectionDomain().getCodeSource().getLocation();
     //System.out.println( "main.lib=" + url );
     return jarUrl;
   }
@@ -128,11 +116,8 @@ public class Launcher {
   private static void createExternalConfig( File file, Properties config, URL src ) throws
IOException {
     try {
       if( file.createNewFile() ){
-        OutputStream output = new FileOutputStream( file );
-        try {
-          config.store( output, "Created from " + src );
-        } finally {
-          output.close();
+        try (OutputStream output = new FileOutputStream(file)) {
+          config.store(output, "Created from " + src);
         }
       }
     } catch ( IOException e ) {
@@ -154,11 +139,8 @@ public class Launcher {
 
   private static Properties loadProperties( Properties properties, URL url ) throws IOException
{
     if( url != null ) {
-      InputStream stream = url.openStream();
-      try {
-        properties.load( stream );
-      } finally {
-        stream.close();
+      try (InputStream stream = url.openStream()) {
+        properties.load(stream);
       }
     }
     return properties;
@@ -176,5 +158,4 @@ public class Launcher {
     int i = fullName.lastIndexOf( '.' );
     return i < 0 ? fullName : fullName.substring( 0, i );
   }
-
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-util-launcher/src/test/java/org/apache/knox/gateway/launcher/ConfigTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-launcher/src/test/java/org/apache/knox/gateway/launcher/ConfigTest.java
b/gateway-util-launcher/src/test/java/org/apache/knox/gateway/launcher/ConfigTest.java
index 9d9e386..0fd6249 100644
--- a/gateway-util-launcher/src/test/java/org/apache/knox/gateway/launcher/ConfigTest.java
+++ b/gateway-util-launcher/src/test/java/org/apache/knox/gateway/launcher/ConfigTest.java
@@ -60,8 +60,8 @@ public class ConfigTest {
 
   @Test
   public void testSave() throws Exception {
-    Config c = null;
-    StringWriter w = null;
+    Config c;
+    StringWriter w;
 
     c = new Config();
     c.save( null );

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Builder.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Builder.java
b/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Builder.java
index ec8ce55..791ba03 100644
--- a/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Builder.java
+++ b/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Builder.java
@@ -330,8 +330,7 @@ public class Builder {
   public Builder addQuery( String queryName, String paramName, String valuePattern, boolean
literal ) {
     if( Segment.STAR_PATTERN.equals( queryName ) || Segment.GLOB_PATTERN.equals( queryName
) ) {
       if( extra == null ) {
-        Query segment = new Query( queryName, paramName, valuePattern, literal );
-        extra = segment;
+        extra = new Query( queryName, paramName, valuePattern, literal );
       } else {
         // Can't have two extras: ?{*}&{**}
         //TODO throw new URISyntaxException()? because
@@ -355,8 +354,7 @@ public class Builder {
   Builder addQuery( String queryName, Token token ) {
     if( Segment.STAR_PATTERN.equals( queryName ) || Segment.GLOB_PATTERN.equals( queryName
) ) {
       if( extra == null ) {
-        Query segment = new Query( queryName, token );
-        extra = segment;
+        extra = new Query( queryName, token );
       } else {
         // Can't have two extras: ?{*}&{**}
         //TODO throw new URISyntaxException()? because

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Expander.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Expander.java
b/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Expander.java
index ad14321..abf9b6b 100644
--- a/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Expander.java
+++ b/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Expander.java
@@ -25,7 +25,6 @@ import java.nio.charset.StandardCharsets;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -167,37 +166,35 @@ public class Expander {
   private static void expandExplicitQuery( Template template, Set<String> names, Params
params, Evaluator evaluator, StringBuilder builder, AtomicInteger index ) {
     Collection<Query> query = template.getQuery().values();
     if( !query.isEmpty() ) {
-      Iterator<Query> iterator = query.iterator();
-      while( iterator.hasNext() ) {
+      for (Query query1 : query) {
         int i = index.incrementAndGet();
-        if( i == 1 ) {
-          builder.append( "?" );
+        if (i == 1) {
+          builder.append("?");
         } else {
-          builder.append( "&" );
+          builder.append("&");
         }
-        Query segment = iterator.next();
-        String queryName = segment.getQueryName();
-        String paramName = segment.getParamName();
-        Function function = new Function( paramName );
-        names.remove( function.getParameterName() );
-        for( Segment.Value value: segment.getValues() ) {
-          switch( value.getType() ) {
-            case( Segment.STATIC ):
-              builder.append( queryName );
-              String pattern = value.getOriginalPattern();
-              if( pattern != null ) {
-                builder.append( "=" );
-                builder.append( pattern );
-              }
-              break;
-            case( Segment.DEFAULT ):
-            case( Segment.GLOB ):
-            case( Segment.STAR ):
-            case( Segment.REGEX ):
-              List<String> values = function.evaluate( params, evaluator );
-              expandQueryValues( segment, queryName, values, builder );
-              break;
-            default:
+        String queryName = query1.getQueryName();
+        String paramName = query1.getParamName();
+        Function function = new Function(paramName);
+        names.remove(function.getParameterName());
+        for (Segment.Value value : query1.getValues()) {
+          switch (value.getType()) {
+          case (Segment.STATIC):
+            builder.append(queryName);
+            String pattern = value.getOriginalPattern();
+            if (pattern != null) {
+              builder.append("=");
+              builder.append(pattern);
+            }
+            break;
+          case (Segment.DEFAULT):
+          case (Segment.GLOB):
+          case (Segment.STAR):
+          case (Segment.REGEX):
+            List<String> values = function.evaluate(params, evaluator);
+            expandQueryValues(query1, queryName, values, builder);
+            break;
+          default:
           }
         }
       }
@@ -234,7 +231,7 @@ public class Expander {
 
   private static void expandQueryValues( Query segment, String queryName, List<String>
values, StringBuilder builder ) {
     String value;
-    if( values == null || values.size() == 0 ) {
+    if( values == null || values.isEmpty()) {
       builder.append( queryName );
     } else {
       int type = segment.getFirstValue().getType();

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Function.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Function.java
b/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Function.java
index 0ea0f98..bb13109 100644
--- a/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Function.java
+++ b/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Function.java
@@ -31,8 +31,7 @@ class Function {
 
   static List<String> evaluate( String statement, Resolver resolver, Evaluator evaluator
) {
     Function function = new Function( statement );
-    List<String> results = function.evaluate( resolver, evaluator );
-    return results;
+    return function.evaluate( resolver, evaluator );
   }
 
   Function( String statement ) {

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Matcher.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Matcher.java
b/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Matcher.java
index 20e20f6..643fb24 100644
--- a/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Matcher.java
+++ b/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Matcher.java
@@ -237,8 +237,7 @@ public class Matcher<V> {
         }
       }
     }
-    Match match = createMatch( bestMatchSegment, bestPath, bestQuery, input );
-    return match;
+    return createMatch( bestMatchSegment, bestPath, bestQuery, input );
   }
 
   private QueryNode pickBestQueryMatch( Template input, PathNode pathNode ) {
@@ -307,7 +306,7 @@ public class Matcher<V> {
         Query extra = bestQuery.template.getExtra();
         if( extra != null ) {
           String paramName = extra.getParamName();
-          if( paramName != null && paramName.length() > 0 ) {
+          if( paramName != null && !paramName.isEmpty()) {
             for( Query query: input.getQuery().values() ) {
               String queryName = query.getQueryName();
               if( matchParams.resolve( queryName ) == null ) {
@@ -334,7 +333,7 @@ public class Matcher<V> {
   private void extractSegmentParams( Segment extractSegment, Segment inputSegment, MatchParams
params ) {
     if( extractSegment != null && inputSegment != null ) {
       String paramName = extractSegment.getParamName();
-      if( paramName.length() > 0 ) {
+      if(!paramName.isEmpty()) {
         for( Segment.Value value: inputSegment.getValues() ) {
           params.insertValue( paramName, value.getEffectivePattern() );
         }

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Parser.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Parser.java
b/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Parser.java
index 26e51dc..ba21eba 100644
--- a/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Parser.java
+++ b/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Parser.java
@@ -184,20 +184,20 @@ public class Parser {
         hostPort = split( userAddr[ 1 ], ':' );
       }
       if( usernamePassword != null ) {
-        if( usernamePassword[ 0 ].length() > 0 ) {
+        if(!usernamePassword[0].isEmpty()) {
           paramPattern = makeTokenSingular( parseTemplateToken( builder, usernamePassword[
0 ], Segment.STAR_PATTERN ) );
           builder.setUsername( paramPattern );
         }
-        if( usernamePassword.length > 1 && usernamePassword[ 1 ].length() >
0 ) {
+        if( usernamePassword.length > 1 && !usernamePassword[1].isEmpty()) {
           paramPattern = makeTokenSingular( parseTemplateToken( builder, usernamePassword[
1 ], Segment.STAR_PATTERN ) );
           builder.setPassword( paramPattern );
         }
       }
-      if( hostPort[ 0 ].length() > 0 ) {
+      if(!hostPort[0].isEmpty()) {
         paramPattern = makeTokenSingular( parseTemplateToken( builder, hostPort[ 0 ], Segment.STAR_PATTERN
) );
         builder.setHost( paramPattern );
       }
-      if( hostPort.length > 1 && hostPort[ 1 ].length() > 0 ) {
+      if( hostPort.length > 1 && !hostPort[1].isEmpty()) {
         paramPattern = makeTokenSingular( parseTemplateToken( builder, hostPort[ 1 ], Segment.STAR_PATTERN
) );
         builder.setPort( paramPattern );
       }
@@ -250,7 +250,7 @@ public class Parser {
   }
 
   private static void consumeQuerySegment( final Builder builder, String token ) {
-    if( token != null && token.length() > 0 ) {
+    if( token != null && !token.isEmpty()) {
       // Shorthand format {queryParam} == queryParam={queryParam=*}
       if( TEMPLATE_OPEN_MARKUP == token.charAt( 0 ) ) {
         Token paramPattern = parseTemplateToken( builder, token, Segment.GLOB_PATTERN );
@@ -287,13 +287,13 @@ public class Parser {
   }
 
   private static void consumeFragmentToken( final Builder builder, String token ) {
-    if( token != null && token.length() > 0 ) {
+    if( token != null && !token.isEmpty()) {
       Token t = parseTemplateToken( builder, token, Segment.STAR_PATTERN );
       builder.setFragment( t );
     }
   }
 
-  static final Token parseTemplateToken( final Builder builder, final String s, final String
defaultEffectivePattern ) {
+  static Token parseTemplateToken(final Builder builder, final String s, final String defaultEffectivePattern
) {
     String paramName, actualPattern, effectivePattern;
     final int l = s.length();
     // If the token isn't the empty string, then
@@ -330,8 +330,7 @@ public class Parser {
       actualPattern = s;
       effectivePattern = actualPattern;
     }
-    final Token token = new Token( paramName, actualPattern, effectivePattern, builder.isLiteral()
);
-    return token;
+    return new Token( paramName, actualPattern, effectivePattern, builder.isLiteral() );
   }
 
   // Using this because String.split is very inefficient.

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Segment.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Segment.java
b/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Segment.java
index 6e563b3..04dd89f 100644
--- a/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Segment.java
+++ b/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Segment.java
@@ -318,7 +318,7 @@ abstract class Segment {
   }
 
   // Escape .\${ and turn * into .*
-  static final String createRegex( final String segment ) {
+  static String createRegex(final String segment ) {
     StringBuilder regex = new StringBuilder( segment );
     int len = regex.length();
     for( int i=len-1; i>=0; i-- ) {
@@ -342,7 +342,7 @@ abstract class Segment {
   }
 
   // Creates a pattern for a simplified filesystem style wildcard '*' syntax.
-  static final Pattern compileRegex( String segment ) {
+  static Pattern compileRegex(String segment ) {
 //    // Turn '*' into '/' to keep it safe.
 //    // Chose '/' because that can't exist in a segment.
 //    segment = segment.replaceAll( "\\*", "/" );

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Template.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Template.java
b/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Template.java
index f284438..ca830f1 100644
--- a/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Template.java
+++ b/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Template.java
@@ -185,7 +185,7 @@ public class Template {
 
   private void buildSegmentValue( StringBuilder b, Segment s, Segment.Value v ) {
     String paramName = s.getParamName();
-    if( paramName != null && paramName.length() > 0 ) {
+    if( paramName != null && !paramName.isEmpty()) {
       b.append( "{" );
       b.append( s.getParamName() );
       String actualPattern = v.getToken().originalPattern;
@@ -212,7 +212,7 @@ public class Template {
       }
       String paramName = segment.getParamName();
       Segment.Value firstValue = segment.getFirstValue();
-      if( paramName != null && paramName.length() > 0 ) {
+      if( paramName != null && !paramName.isEmpty()) {
         b.append( "{" );
         b.append( segment.getParamName() );
         String pattern = firstValue.getOriginalPattern();
@@ -281,7 +281,7 @@ public class Template {
     String paramName = segment.getParamName();
     String queryName = segment.getQueryName();
     String valuePattern = value.getOriginalPattern();
-    if( paramName != null && paramName.length() > 0 ) {
+    if( paramName != null && !paramName.isEmpty()) {
       if( !Segment.GLOB_PATTERN.equals( queryName ) && !Segment.STAR_PATTERN.equals(
queryName ) ) {
         b.append( segment.getQueryName() );
         b.append( "=" );
@@ -313,7 +313,7 @@ public class Template {
 
   @Override
   public String toString() {
-    String s = null;
+    String s;
     StringBuilder b = new StringBuilder();
     buildScheme( b );
     buildAuthority( b );
@@ -331,7 +331,7 @@ public class Template {
       hc = toString().hashCode();
       hash = hc;
     }
-    return hc.intValue();
+    return hc;
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Token.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Token.java
b/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Token.java
index 7850e35..58217f1 100644
--- a/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Token.java
+++ b/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Token.java
@@ -19,10 +19,10 @@ package org.apache.knox.gateway.util.urltemplate;
 
 final class Token {
 
-  String parameterName = null;
-  String originalPattern = null;
-  String effectivePattern = null;
-  boolean literal = false;
+  String parameterName;
+  String originalPattern;
+  String effectivePattern;
+  boolean literal;
 
   Token( String parameterName, String originalPattern, String effectivePattern, boolean literal
) {
     this.parameterName = parameterName;

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-util-urltemplate/src/test/java/org/apache/knox/gateway/util/urltemplate/ExpanderTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/test/java/org/apache/knox/gateway/util/urltemplate/ExpanderTest.java
b/gateway-util-urltemplate/src/test/java/org/apache/knox/gateway/util/urltemplate/ExpanderTest.java
index c04ffb2..ba95056 100644
--- a/gateway-util-urltemplate/src/test/java/org/apache/knox/gateway/util/urltemplate/ExpanderTest.java
+++ b/gateway-util-urltemplate/src/test/java/org/apache/knox/gateway/util/urltemplate/ExpanderTest.java
@@ -24,7 +24,7 @@ import org.junit.experimental.categories.Category;
 
 import java.net.URI;
 import java.net.URISyntaxException;
-import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 
 import static org.hamcrest.CoreMatchers.equalTo;
@@ -421,7 +421,7 @@ public class ExpanderTest {
     evaluator = new Evaluator() {
       @Override
       public List<String> evaluate( String function, List<String> parameters
) {
-        return Arrays.asList( "https://webhcatTestHost.com:50111/templeton" );
+        return Collections.singletonList("https://webhcatTestHost.com:50111/templeton");
       }
     };
 
@@ -453,7 +453,7 @@ public class ExpanderTest {
     evaluator = new Evaluator() {
       @Override
       public List<String> evaluate( String function, List<String> parameters
) {
-        return Arrays.asList( "https://gateway-host:9443/gateway/default" );
+        return Collections.singletonList("https://gateway-host:9443/gateway/default");
       }
     };
 
@@ -475,7 +475,7 @@ public class ExpanderTest {
     evaluator = new Evaluator() {
       @Override
       public List<String> evaluate( String function, List<String> parameters
) {
-        return Arrays.asList( "https://gateway-host:9443/gateway/default" );
+        return Collections.singletonList("https://gateway-host:9443/gateway/default");
       }
     };
 

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-util-urltemplate/src/test/java/org/apache/knox/gateway/util/urltemplate/FunctionTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/test/java/org/apache/knox/gateway/util/urltemplate/FunctionTest.java
b/gateway-util-urltemplate/src/test/java/org/apache/knox/gateway/util/urltemplate/FunctionTest.java
index 4721546..33cc924 100644
--- a/gateway-util-urltemplate/src/test/java/org/apache/knox/gateway/util/urltemplate/FunctionTest.java
+++ b/gateway-util-urltemplate/src/test/java/org/apache/knox/gateway/util/urltemplate/FunctionTest.java
@@ -20,7 +20,7 @@ package org.apache.knox.gateway.util.urltemplate;
 import org.junit.Test;
 
 import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 
 import static org.hamcrest.MatcherAssert.assertThat;
@@ -146,7 +146,7 @@ public class FunctionTest {
 
     @Override
     public List<String> resolve( String name ) {
-      return Arrays.asList( "resolve(" + name + ")" );
+      return Collections.singletonList("resolve(" + name + ")");
     }
 
   }

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-util-urltemplate/src/test/java/org/apache/knox/gateway/util/urltemplate/RewriterTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/test/java/org/apache/knox/gateway/util/urltemplate/RewriterTest.java
b/gateway-util-urltemplate/src/test/java/org/apache/knox/gateway/util/urltemplate/RewriterTest.java
index 5431193..91e44d3 100644
--- a/gateway-util-urltemplate/src/test/java/org/apache/knox/gateway/util/urltemplate/RewriterTest.java
+++ b/gateway-util-urltemplate/src/test/java/org/apache/knox/gateway/util/urltemplate/RewriterTest.java
@@ -103,10 +103,10 @@ public class RewriterTest {
   @Test
   public void testServiceRegistryHostmapUserCase() throws Exception {
     Resolver resolver = EasyMock.createNiceMock( Resolver.class );
-    EasyMock.expect( resolver.resolve( "internal-host" ) ).andReturn( Arrays.asList( "internal-host"
) ).anyTimes();
+    EasyMock.expect( resolver.resolve( "internal-host" ) ).andReturn(Collections.singletonList("internal-host")).anyTimes();
 
     Evaluator evaluator = EasyMock.createNiceMock( Evaluator.class );
-    EasyMock.expect( evaluator.evaluate( "hostmap", Arrays.asList( "internal-host" ) ) ).andReturn(
Arrays.asList( "external-host" ) ).anyTimes();
+    EasyMock.expect( evaluator.evaluate( "hostmap", Collections.singletonList("internal-host"))
).andReturn(Collections.singletonList("external-host")).anyTimes();
 
     EasyMock.replay( resolver, evaluator );
 


Mime
View raw message