Example usage for java.util AbstractMap values

List of usage examples for java.util AbstractMap values

Introduction

In this page you can find the example usage for java.util AbstractMap values.

Prototype

Collection values

To view the source code for java.util AbstractMap values.

Click Source Link

Usage

From source file:MainClass.java

public static void main(String args[]) {
    AbstractMap map = new ArrayMap(13);
    map.put("Virginia", "Richmond");
    map.put("Massachusetts", "Boston");
    map.put("New York", "Albany");
    System.out.println(map);/*  w ww.j  a  v  a 2s .c  om*/
    System.out.println(map.keySet());
    System.out.println(map.values());
}

From source file:com.sse.abtester.VariationAssigner.java

/**
 * Generate weighted collection.//  w ww .  ja  v a2  s  .  c  o  m
 *
 * @param src the src
 * @param precision the precision
 * @return the array list
 */
ArrayList<IVariant<VariantBean>> generateWeightedCollection(AbstractMap<String, IVariant<VariantBean>> src,
        int precision) {
    ArrayList<IVariant<VariantBean>> normalizedCollection = new ArrayList<IVariant<VariantBean>>();
    ArrayList<IVariant<VariantBean>> newWeightedCollection = new ArrayList<IVariant<VariantBean>>();
    // first we normalize the targetFrequencies
    double sumTF = 0;
    for (IVariant<VariantBean> o : src.values()) {
        sumTF += o.getTargetFreq();
    }
    for (IVariant<VariantBean> o : src.values()) {
        if (o.isDispatchable()) {
            IVariant<VariantBean> temp = o.copy();
            temp.setTargetFreq(temp.getTargetFreq() / sumTF);
            normalizedCollection.add(temp);
        }
    }

    int cutoff = (int) Math.round(Math.pow(10, Math.max(precision, MAX_PRECISION)));
    for (IVariant<VariantBean> targetable : normalizedCollection) {
        long replicaCount = Math.round(targetable.getTargetFreq() * cutoff);
        for (int x = 0; x < replicaCount; x++) {
            newWeightedCollection.add(targetable);
        }
    }
    return newWeightedCollection;
}

From source file:com.sse.abtester.VariationAssignerTest.java

/**
 * Test n variants.// w  w w  . j ava 2  s.c o m
 *
 * @param num_variants the num_variants
 */
public void testNVariants(int num_variants) {
    // make up some variants
    AbstractMap<String, IVariant<VariantBean>> coll = new HashMap<String, IVariant<VariantBean>>();

    for (int i = 0; i < num_variants; i++) {
        String name = "Bean_" + i;
        IVariant<VariantBean> vb = new VariantBean(name);
        vb.setDispatchable(true); // else non of the bean is
        // copied into normalized/weighted collections
        vb.setTargetFreq(1.0 / num_variants);
        vb.setVariationStrategy(new Default());
        coll.put(name, vb);
    }
    VariationAssigner<VariantBean> va = new VariationAssigner<VariantBean>();

    va.setIVariantCollection(coll);
    Frequency f = new Frequency();
    MockHttpServletRequest req = new MockHttpServletRequest();
    int TEST_LOOPS = 1000;
    double ALLOWABLE_DELTA = 100.0 / TEST_LOOPS; // rough check
    for (int i = 0; i < TEST_LOOPS; i++) {
        IVariant<VariantBean> assigned = va.enrollRequest(req);
        if (assigned != null)
            f.addValue(assigned.getName());
    }
    for (IVariant<VariantBean> vrb : coll.values()) {
        assertEquals(1.0 / num_variants, f.getPct(vrb.getName()), // NaN here can mean unknown name
                ALLOWABLE_DELTA);
    }
}