Extract function for toString() function
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 24 Jul 2015 04:30:58 +0000 (06:30 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 24 Jul 2015 04:30:58 +0000 (06:30 +0200)
src/main/java/net/pterodactylus/sone/template/ImageLinkFilter.java

index 458d40f..1ac7360 100644 (file)
@@ -80,12 +80,7 @@ public class ImageLinkFilter implements Filter {
                if (image == null) {
                        return null;
                }
-               String imageClass = Optional.fromNullable(parameters.get("class")).transform(new Function<Object, String>() {
-                       @Override
-                       public String apply(Object input) {
-                               return (input != null) ? input.toString() : null;
-                       }
-               }).orNull();
+               String imageClass = Optional.fromNullable(parameters.get("class")).transform(getStringValue()).orNull();
                int maxWidth = parseInt(valueOf(parameters.get("max-width")), MAX_VALUE);
                int maxHeight = parseInt(valueOf(parameters.get("max-height")), MAX_VALUE);
                String mode = valueOf(parameters.get("mode"));
@@ -123,4 +118,13 @@ public class ImageLinkFilter implements Filter {
                return stringWriter.toString();
        }
 
+       private Function<Object, String> getStringValue() {
+               return new Function<Object, String>() {
+                       @Override
+                       public String apply(Object input) {
+                               return (input != null) ? input.toString() : null;
+                       }
+               };
+       }
+
 }