11/*
2- * Copyright 2002-2009 the original author or authors.
2+ * Copyright 2002-2012 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
2222import org .springframework .expression .spel .ExpressionState ;
2323
2424/**
25- * Implements the multiply operator. Conversions and promotions:
26- * http://java.sun.com/docs/books/jls/third_edition/html/conversions.html Section 5.6.2:
25+ * Implements the {@code multiply} operator.
2726 *
28- * <p>If any of the operands is of a reference type, unboxing conversion (¤5.1.8) is performed. Then:<br>
27+ * <p>Conversions and promotions are handled as defined in
28+ * <a href="http://java.sun.com/docs/books/jls/third_edition/html/conversions.html">Section 5.6.2
29+ * of the Java Language Specification</a>:
30+ *
31+ * <p>If any of the operands is of a reference type, unboxing conversion (Section 5.1.8) is performed. Then:<br>
2932 * If either operand is of type double, the other is converted to double.<br>
3033 * Otherwise, if either operand is of type float, the other is converted to float.<br>
3134 * Otherwise, if either operand is of type long, the other is converted to long.<br>
3235 * Otherwise, both operands are converted to type int.
3336 *
34- * <p>
35- *
3637 * @author Andy Clement
38+ * @author Sam Brannen
3739 * @since 3.0
3840 */
3941public class OpMultiply extends Operator {
4042
41-
4243 public OpMultiply (int pos , SpelNodeImpl ... operands ) {
4344 super ("*" , pos , operands );
4445 }
4546
4647 /**
47- * Implements multiply directly here for some types of operand, otherwise delegates to any registered overloader for
48- * types it does not recognize. Supported types here are:
48+ * Implements the {@code multiply} operator directly here for certain types
49+ * of supported operands and otherwise delegates to any registered overloader
50+ * for types not supported here.
51+ * <p>Supported operand types:
4952 * <ul>
50- * <li>integers
5153 * <li>doubles
52- * <li>string and int ('abc' * 2 == 'abcabc')
54+ * <li>longs
55+ * <li>integers
56+ * <li>String and int ('abc' * 2 == 'abcabc')
5357 * </ul>
5458 */
5559 @ Override
@@ -61,12 +65,15 @@ public TypedValue getValueInternal(ExpressionState state) throws EvaluationExcep
6165 Number rightNumber = (Number ) operandTwo ;
6266 if (leftNumber instanceof Double || rightNumber instanceof Double ) {
6367 return new TypedValue (leftNumber .doubleValue () * rightNumber .doubleValue ());
64- } else if (leftNumber instanceof Long || rightNumber instanceof Long ) {
68+ }
69+ else if (leftNumber instanceof Long || rightNumber instanceof Long ) {
6570 return new TypedValue (leftNumber .longValue () * rightNumber .longValue ());
66- } else {
71+ }
72+ else {
6773 return new TypedValue (leftNumber .intValue () * rightNumber .intValue ());
6874 }
69- } else if (operandOne instanceof String && operandTwo instanceof Integer ) {
75+ }
76+ else if (operandOne instanceof String && operandTwo instanceof Integer ) {
7077 int repeats = (Integer ) operandTwo ;
7178 StringBuilder result = new StringBuilder ();
7279 for (int i = 0 ; i < repeats ; i ++) {
0 commit comments