Java Number Sum Sum(Object in, int min, int max)

Here you can find the source of Sum(Object in, int min, int max)

Description

Sum

License

Open Source License

Declaration

public static final int Sum(Object in, int min, int max) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static final int Sum(Object in, int min, int max) {
        // END BOOL ONLY */
        if (in instanceof boolean[]) {
            boolean[] inn = (boolean[]) in;
            if (max >= inn.length)
                max = inn.length - 1;/*from w  w  w . j  a va 2 s.  c om*/
            /* NO BOOL
             boolean out = 0; for ( int i = min; i <= max; i ++ ) out += inn[ i ]; return out; 
            END NO BOOL */
            // BOOL ONLY
            int out = 0;
            for (int i = min; i <= max; i++)
                out += inn[i] ? 1 : 0;
            return out;
            // END BOOL ONLY */
        } else {
            /* NO BOOL
             boolean out = 0; 
            END NO BOOL */
            // BOOL ONLY
            int out = 0;
            // END BOOL ONLY */
            for (int i = 0, s = ((Object[]) in).length; i < s; i++)
                out += Sum(((Object[]) in)[i], min, max);
            return out;
        }
    }

    public static final int Sum(Object in) {
        // END BOOL ONLY */
        if (in instanceof boolean[])
            return Sum((boolean[]) in, 0, ((boolean[]) in).length);
        else {
            /* NO BOOL
             boolean out = 0; 
            END NO BOOL */
            // BOOL ONLY
            int out = 0;
            // END BOOL ONLY */
            for (int i = 0, s = ((Object[]) in).length; i < s; i++)
                out += Sum(((Object[]) in)[i]);
            return out;
        }
    }
}

Related

  1. sum(Iterable as)
  2. sum(Iterable iterable)
  3. sum(long space1, String space2)
  4. sum(long x, int c)
  5. sum(Number n1, Number n2)
  6. sum(String fieldName)
  7. sum(String str11, String str22)
  8. sum0ToN(int n)
  9. sum_quad(long max)