Java Vector to toPercent(Vector members, HashMap mapMemberToValue)

Here you can find the source of toPercent(Vector members, HashMap mapMemberToValue)

Description

Turns the mapped values into relative values (percentages) for easy use by the general topOrBottom function.

License

Common Public License

Declaration

static void toPercent(Vector members, HashMap mapMemberToValue) 

Method Source Code

//package com.java2s;
/*//  w w w .j a  va  2  s  . c om
 // $Id: //open/mondrian/src/main/mondrian/olap/fun/FunUtil.java#18 $
 // (C) Copyright 2002 Kana Software, Inc.
 // This software is subject to the terms of the Common Public License
 // Agreement, available at the following URL:
 // http://www.opensource.org/licenses/cpl.html.
 // (C) Copyright 2002 Kana Software, Inc. and others.
 // All Rights Reserved.
 // You must accept the terms of that agreement to use this software.
 //
 // jhyde, 3 March, 2002
 */

import java.util.*;

public class Main {
    /**
     * Turns the mapped values into relative values (percentages) for easy
     * use by the general topOrBottom function. This might also be a useful
     * function in itself.
     */
    static void toPercent(Vector members, HashMap mapMemberToValue) {
        double total = 0;
        int numMembers = members.size();
        for (int i = 0; i < numMembers; i++) {
            Object o = mapMemberToValue.get(members.elementAt(i));
            if (o instanceof Number) {
                total += ((Number) o).doubleValue();
            }
        }
        for (int i = 0; i < numMembers; i++) {
            Object member = members.elementAt(i);
            Object o = mapMemberToValue.get(member);
            if (o instanceof Number) {
                double d = ((Number) o).doubleValue();
                mapMemberToValue.put(member, new Double(d / total * 100));
            }
        }

    }
}

Related

  1. toEnumeration(Vector options)
  2. toHashSet(Vector vector)
  3. toHashSetD(Vector vec)
  4. toIntArray(Vector vec)
  5. toIntArray(Vector vect)
  6. vector2doubles(Vector _v)
  7. vectorToColor(float x, float y, float z)
  8. vectorTolatLonDegrees(double X, double Y, double Z)
  9. vectorToMatrixArray(int M, int N, float[] a, float[][] b)