@@ -42,7 +42,7 @@ class Operation extends Expression {
4242
4343 private int type ;
4444
45- private static final HashMap <String , HashMap <String , Double >> unitConversions = new HashMap <>();
45+ private static final HashMap <String , HashMap <String , Double >> UNIT_CONVERSIONS = new HashMap <>();
4646 static {
4747 HashMap <String , Double > length = new HashMap <>();
4848 putConvertion ( length , "m" , 1 );
@@ -64,31 +64,50 @@ class Operation extends Expression {
6464 putConvertion ( angle , "turn" , 1 );
6565 }
6666
67+ /**
68+ * Helper for creating static unit conversions.
69+ *
70+ * @param group the unit group like length, duration or angles. Units of one group can convert in another.
71+ * @param unit the unit name
72+ * @param factor the convert factor
73+ */
6774 private static void putConvertion ( HashMap <String , Double > group , String unit , double factor ) {
68- unitConversions .put (unit , group );
75+ UNIT_CONVERSIONS .put (unit , group );
6976 group .put ( unit , factor );
7077 }
7178
72- Operation ( LessObject reader , Expression left , char operator ) {
73- this ( reader , operator );
79+ /**
80+ * Create a new instance.
81+ *
82+ * @param obj another LessObject with parse position.
83+ * @param left left operand
84+ * @param operator the operator like +, -, *, etc.
85+ */
86+ Operation ( LessObject obj , Expression left , char operator ) {
87+ this ( obj , operator );
7488 if ( left != null ) {
7589 this .operands .add ( left );
7690 }
7791 }
7892
7993 /**
80- * Empty parameter list
94+ * Create a new instance with an empty parameter list.
95+ *
96+ * @param obj another LessObject with parse position.
97+ * @param operator the operator like +, -, *, etc.
8198 */
82- Operation ( LessObject reader , char operator ) {
83- super ( reader , String .valueOf ( operator ) );
99+ Operation ( LessObject obj , char operator ) {
100+ super ( obj , String .valueOf ( operator ) );
84101 this .operator = operator ;
85102 }
86103
87104 /**
88- * Empty parameter list
105+ * Create a new instance with an empty parameter list and a comma as operation.
106+ *
107+ * @param obj another LessObject with parse position.
89108 */
90- Operation ( LessObject reader ) {
91- super ( reader , "," );
109+ Operation ( LessObject obj ) {
110+ super ( obj , "," );
92111 this .operator = ',' ;
93112 }
94113
@@ -112,12 +131,18 @@ ArrayList<Expression> getOperands() {
112131
113132 /**
114133 * Add the next operand. It must use the same operator like this operation.
134+ *
115135 * @param right the next operand
116136 */
117137 void addOperand ( Expression right ) {
118138 this .operands .add ( right );
119139 }
120140
141+ /**
142+ * Add an operand on the top position to the operand list.
143+ *
144+ * @param left operand the new operand
145+ */
121146 void addLeftOperand ( Expression left ) {
122147 this .operands .add ( 0 , left );
123148 }
@@ -149,6 +174,11 @@ public int getDataType( CssFormatter formatter ) {
149174 return type ;
150175 }
151176
177+ /**
178+ * Get the highest data type of different operands
179+ * @param formatter current formatter
180+ * @return the data type
181+ */
152182 private int maxOperadType ( CssFormatter formatter ) {
153183 int dataType = operands .get ( 0 ).getDataType ( formatter );
154184 for ( int i = 1 ; i < operands .size (); i ++ ) {
@@ -251,18 +281,20 @@ public void appendTo( CssFormatter formatter ) {
251281
252282 /**
253283 * Calculate the factor between 2 units.
284+ *
254285 * @param leftUnit left unit
255286 * @param rightUnit right unit
256287 * @param fail true, should be fail if units incompatible; false, return 1 is incompatible
257288 * @return the factor between the 2 units.
289+ * @throws LessException if unit are incompatible and fail is true
258290 */
259291 static double unitFactor ( String leftUnit , String rightUnit , boolean fail ) {
260292 if ( leftUnit .length () == 0 || rightUnit .length () == 0 || leftUnit .equals ( rightUnit ) ) {
261293 return 1 ;
262294 }
263- HashMap <String , Double > leftGroup = unitConversions .get ( leftUnit );
295+ HashMap <String , Double > leftGroup = UNIT_CONVERSIONS .get ( leftUnit );
264296 if ( leftGroup != null ) {
265- HashMap <String , Double > rightGroup = unitConversions .get ( rightUnit );
297+ HashMap <String , Double > rightGroup = UNIT_CONVERSIONS .get ( rightUnit );
266298 if ( leftGroup == rightGroup ) {
267299 return leftGroup .get ( leftUnit ) / leftGroup .get ( rightUnit );
268300 }
@@ -305,6 +337,13 @@ public double doubleValue( CssFormatter formatter ) {
305337 return value ;
306338 }
307339
340+ /**
341+ * Calculate the number value of two operands if possible.
342+ *
343+ * @param left the left
344+ * @param right the right
345+ * @return the result.
346+ */
308347 private double doubleValue ( double left , double right ) {
309348 switch ( operator ) {
310349 case '+' :
@@ -320,24 +359,48 @@ private double doubleValue( double left, double right ) {
320359 }
321360 }
322361
362+ /**
363+ * Calculate a color on left with a number on the right side. The calculation occur for every color channel.
364+ *
365+ * @param color the color
366+ * @param right the right
367+ * @return color value as long
368+ */
323369 private double doubleValueLeftColor ( double color , double right ) {
324370 return rgba ( doubleValue ( red ( color ), right ), //
325371 doubleValue ( green ( color ), right ), //
326372 doubleValue ( blue ( color ), right ), 1 );
327373 }
328374
375+ /**
376+ * Calculate a number on left with a color on the right side. The calculation occur for every color channel.
377+ *
378+ * @param left the left
379+ * @param color the color
380+ * @return color value as long
381+ */
329382 private double doubleValueRightColor ( double left , double color ) {
330383 return rgba ( doubleValue ( left , red ( color ) ), //
331384 doubleValue ( left , green ( color ) ), //
332385 doubleValue ( left , blue ( color ) ), 1 );
333386 }
334387
388+ /**
389+ * Calculate two colors. The calculation occur for every color channel.
390+ *
391+ * @param left the left color
392+ * @param right the right color
393+ * @return color value as long
394+ */
335395 private double doubleValue2Colors ( double left , double right ) {
336396 return rgba ( doubleValue ( red ( left ), red ( right ) ), //
337397 doubleValue ( green ( left ), green ( right ) ), //
338398 doubleValue ( blue ( left ), blue ( right ) ), 1 );
339399 }
340400
401+ /**
402+ * {@inheritDoc}
403+ */
341404 @ Override
342405 public boolean booleanValue (CssFormatter formatter ) {
343406 Expression leftOp = operands .get ( 0 );
@@ -572,17 +635,28 @@ static int level( char operator ) {
572635 return 0 ;
573636 }
574637
638+ /**
639+ * Helper class to count the resulting unit of an operation with different units
640+ */
575641 private static class Unit {
576642 private int numerator ;
577643
578644 private int denominator ;
579645
580646 private final String unit ;
581647
648+ /**
649+ * Create a new instance.
650+ * @param unit the unit to count.
651+ */
582652 Unit ( String unit ) {
583653 this .unit = unit ;
584654 }
585655
656+ /**
657+ * The resulting usage count of the unit.
658+ * @return the count
659+ */
586660 int useCount () {
587661 return numerator - denominator ;
588662 }
0 commit comments