Author: tchemit Date: 2010-02-20 16:12:34 +0100 (Sat, 20 Feb 2010) New Revision: 1749 Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/decorator/DecoratorUtils.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/decorator/JXPathDecorator.java Log: reformat code Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/decorator/DecoratorUtils.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/decorator/DecoratorUtils.java 2010-02-18 15:55:04 UTC (rev 1748) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/decorator/DecoratorUtils.java 2010-02-20 15:12:34 UTC (rev 1749) @@ -60,7 +60,9 @@ * - a ${ was found in a jxpath token. * @throws NullPointerException if internalClass parameter is null. */ - public static <O> PropertyDecorator<O> newPropertyDecorator(Class<O> internalClass, String property) + public static <O> PropertyDecorator<O> newPropertyDecorator( + Class<O> internalClass, + String property) throws IllegalArgumentException, NullPointerException { return new PropertyDecorator<O>(internalClass, property); } @@ -69,9 +71,11 @@ * Factory method to instanciate a new {@link JXPathDecorator} for the * given class {@code internalClass} and expression. * - * @param internalClass the class of the objects decorated by the new decorator + * @param internalClass the class of the objects decorated by the new + * decorator * @param expression the expression to use to decorated objects - * @param <O> the generic type of class to be decorated by the new decorator + * @param <O> the generic type of class to be decorated by the + * new decorator * @return the new instanciated decorator * @throws IllegalArgumentException if the expression is not valid, says: * <p/> @@ -80,30 +84,47 @@ * - a ${ was found in a jxpath token. * @throws NullPointerException if internalClass parameter is null. */ - public static <O> JXPathDecorator<O> newJXPathDecorator(Class<O> internalClass, String expression) + public static <O> JXPathDecorator<O> newJXPathDecorator( + Class<O> internalClass, + String expression) throws IllegalArgumentException, NullPointerException { Context<O> context = createJXPathContext(expression); return new JXPathDecorator<O>(internalClass, expression, context); } - public static <O> MultiJXPathDecorator<O> newMultiJXPathDecorator(Class<O> internalClass, - String expression, - String separator) + public static <O> MultiJXPathDecorator<O> newMultiJXPathDecorator( + Class<O> internalClass, + String expression, + String separator) throws IllegalArgumentException, NullPointerException { - return newMultiJXPathDecorator(internalClass, expression, separator, separator); + MultiJXPathDecorator<O> decorator = newMultiJXPathDecorator( + internalClass, + expression, + separator, + separator); + return decorator; } - public static <O> MultiJXPathDecorator<O> newMultiJXPathDecorator(Class<O> internalClass, - String expression, - String separator, - String separatorReplacement) + public static <O> MultiJXPathDecorator<O> newMultiJXPathDecorator( + Class<O> internalClass, + String expression, + String separator, + String separatorReplacement) throws IllegalArgumentException, NullPointerException { - Context<O>[] contexts = createMultiJXPathContext(expression, separator, separatorReplacement); + Context<O>[] contexts = createMultiJXPathContext( + expression, + separator, + separatorReplacement); - return new MultiJXPathDecorator<O>(internalClass, expression, separator, separatorReplacement, contexts); + return new MultiJXPathDecorator<O>( + internalClass, + expression, + separator, + separatorReplacement, + contexts); } /** @@ -113,9 +134,12 @@ * @param <O> type of data to sort * @param decorator the decorator to use to sort * @param datas the list of data to sort - * @param pos the index of context to used in decorator to obtain sorted property. + * @param pos the index of context to used in decorator to obtain + * sorted property. */ - public static <O> void sort(JXPathDecorator<O> decorator, List<O> datas, int pos) { + public static <O> void sort(JXPathDecorator<O> decorator, + List<O> datas, + int pos) { Comparator<O> c = null; boolean cachedComparator = false; try { @@ -147,26 +171,34 @@ // seek end of jxpath end = expression.indexOf("}", start + 1); if (end == -1) { - throw new IllegalArgumentException("could not find the rigth brace starting at car " + start + " : " + expression.substring(start + 2)); + throw new IllegalArgumentException("could not find the rigth " + + "brace starting at car " + start + " : " + + expression.substring(start + 2)); } String jxpath = expression.substring(start + 2, end); // not allowed ${ inside a jxpath token if (jxpath.indexOf("${") > -1) { - throw new IllegalArgumentException("could not find a ${ inside a jxpath expression at car " + (start + 2) + " : " + jxpath); + throw new IllegalArgumentException("could not find a ${ " + + "inside a jxpath expression at car " + + (start + 2) + " : " + jxpath); } // save the jxpath token lTokens.add(jxpath); // replace jxpath token in expresion with a string format variable - buffer.append("%").append(lTokens.size()); + buffer.append('%').append(lTokens.size()); } if (size > (end + 1)) { // suffix after end jxpath (or all expression if no jxpath) buffer.append(expression.substring(end + 1)); } - return new Context<O>(buffer.toString(), lTokens.toArray(new String[lTokens.size()])); + return new Context<O>(buffer.toString(), lTokens.toArray( + new String[lTokens.size()])); } - public static <O> Context<O>[] createMultiJXPathContext(String expression, String separator, String separatorReplacement) { + public static <O> Context<O>[] createMultiJXPathContext( + String expression, + String separator, + String separatorReplacement) { int sep = expression.indexOf(separator); if (sep == -1) { Context<O>[] result = newInstance(1); @@ -190,7 +222,8 @@ //todo replace %index with %j buffer.append(separatorReplacement).append(str); } - contexts[i] = createJXPathContext(buffer.substring(separatorReplacement.length())); + contexts[i] = createJXPathContext( + buffer.substring(separatorReplacement.length())); } return contexts; } Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/decorator/JXPathDecorator.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/decorator/JXPathDecorator.java 2010-02-18 15:55:04 UTC (rev 1748) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/decorator/JXPathDecorator.java 2010-02-20 15:12:34 UTC (rev 1749) @@ -29,13 +29,16 @@ /** * JXPath decorator based on {@link String#format(String, Object...)} method. * <p/> - * To use it, give to him a expression where all jxpath to apply on bean are boxed in <code>${}</code>. + * To use it, give to him a expression where all jxpath to apply on bean are + * boxed in <code>${}</code>. * <p/> - * After the jxpath token you must specifiy the formatter to apply of the jxpath token. + * After the jxpath token you must specifiy the formatter to apply of the + * jxpath token. * <p/> * For example : * <pre> - * Decorator<Object> d = DecoratorUtils.newJXPathDecorator(JXPathDecorator.class,"expr = ${expressions}$s"); + * Decorator<Object> d = DecoratorUtils.newJXPathDecorator( + * JXPathDecorator.class,"expr = ${expressions}$s"); * assert "expr = %1$s" == d.getExpression(); * assert 1 == d.getNbToken(); * assert java.util.Arrays.asList("expression") == d.getTokens(); @@ -67,7 +70,10 @@ */ protected String initialExpression; - protected JXPathDecorator(Class<O> internalClass, String expression, Context<O> context) throws IllegalArgumentException, NullPointerException { + protected JXPathDecorator(Class<O> internalClass, + String expression, + Context<O> context) + throws IllegalArgumentException, NullPointerException { super(internalClass); this.initialExpression = expression; if (context != null) { @@ -87,7 +93,9 @@ try { args[i] = getTokenValue(jxcontext, context.tokens[i]); } catch (Exception e) { - log.error("can not obtain token " + context.tokens[i] + "on object " + bean + " for reason " + e.getMessage(), e); + log.error("can not obtain token " + context.tokens[i] + + "on object " + bean + " for reason " + + e.getMessage(), e); } } @@ -117,7 +125,7 @@ @Override public String toString() { - return super.toString() + "<" + context + ">"; + return super.toString() + '<' + context + '>'; } public void setContext(Context<O> context) { @@ -137,7 +145,8 @@ } @SuppressWarnings({"unchecked"}) - protected Comparable<Comparable<?>> getTokenValue(JXPathContext jxcontext, String token) { + protected Comparable<Comparable<?>> getTokenValue(JXPathContext jxcontext, + String token) { // assume all values are comparable return (Comparable<Comparable<?>>) jxcontext.getValue(token); } @@ -176,7 +185,8 @@ clear(); for (O data : datas) { JXPathContext jxcontext = JXPathContext.newContext(data); - Comparable<Comparable<?>> key = decorator.getTokenValue(jxcontext, expression); + Comparable<Comparable<?>> key; + key = decorator.getTokenValue(jxcontext, expression); valueCache.put(data, key); } } @@ -185,8 +195,8 @@ public static class Context<O> implements java.io.Serializable { /** - * expression to format using {@link String#format(String, Object...)}, all variables are compute - * using using the jxpath tokens. + * expression to format using {@link String#format(String, Object...)}, + * all variables are compute using using the jxpath tokens. */ protected String expression; /** @@ -218,13 +228,16 @@ @Override public String toString() { - return "<expression:" + expression + ", tokens:" + Arrays.toString(tokens) + ">"; + return "<expression:" + expression + ", tokens:" + + Arrays.toString(tokens) + '>'; } } protected static void ensureTokenIndex(JXPathDecorator<?> decorator, int pos) { if (pos < -1 || pos > decorator.getNbToken()) { - throw new ArrayIndexOutOfBoundsException("token index " + pos + " is out of bound, can be inside [" + 0 + "," + decorator.nbToken + "]"); + throw new ArrayIndexOutOfBoundsException("token index " + pos + + " is out of bound, can be inside [" + + 0 + ',' + decorator.nbToken + ']'); } } }
participants (1)
-
tchemit@users.nuiton.org