private ArrayList < Unit > unit ( CssFormatter formatter , ArrayList < Unit > list ) { for ( int i = 0 ; i < operands . size ( ) ; i ++ ) { Expression exp = operands . get ( i ) ; if ( exp . getClass ( ) == Operation . class ) { Operation op = ( Operation ) exp ; switch ( op . operator ) { case ' ' : case ' ' : list = op . unit ( formatter , list ) ; break ; default : } } else { String unitStr = exp . unit ( formatter ) ; if ( ! unitStr . isEmpty ( ) ) { if ( list == null ) { list = new ArrayList <> ( ) ; } Unit unit = null ; for ( int j = 0 ; j < list . size ( ) ; j ++ ) { Unit unitLoop = list . get ( j ) ; if ( unitLoop . unit . equals ( unitStr ) ) { unit = unitLoop ; break ; } } if ( unit == null ) { unit = new Unit ( unitStr ) ; list . add ( unit ) ; } if ( i == 0 || operator == ' ' ) { unit . numerator ++ ; } else { unit . denominator ++ ; } } } } return list ; }
Calculate the unit if there are different units . It use the numerator and denominator count .