Example usage for java.util EnumMap EnumMap

List of usage examples for java.util EnumMap EnumMap

Introduction

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

Prototype

public EnumMap(Map<K, ? extends V> m) 

Source Link

Document

Creates an enum map initialized from the specified map.

Usage

From source file:org.libreplan.web.planner.tabs.TabOnModeType.java

public static WithType forMode(Mode mode) {
    return new WithType(mode, new EnumMap<>(ModeType.class));
}

From source file:cmusv.mr.carbon.utils.QRCodeGenerator.java

public static Bitmap encodeAsBitmap(String contentsToEncode, int dimension, boolean isEncoded)
        throws WriterException {
    if (contentsToEncode == null) {
        return null;
    }/*  w ww .ja  va  2s . c o m*/
    if (isEncoded) {
        Base64 base64 = new Base64();
        contentsToEncode = new String(base64.encode(contentsToEncode.getBytes()));
    }

    Map<EncodeHintType, Object> hints = null;
    String encoding = guessAppropriateEncoding(contentsToEncode);
    if (encoding != null) {
        hints = new EnumMap<EncodeHintType, Object>(EncodeHintType.class);
        hints.put(EncodeHintType.CHARACTER_SET, encoding);
    }
    MultiFormatWriter writer = new MultiFormatWriter();
    BitMatrix result = writer.encode(contentsToEncode, format, dimension, dimension, hints);
    int width = result.getWidth();
    int height = result.getHeight();
    int[] pixels = new int[width * height];
    for (int y = 0; y < height; y++) {
        int offset = y * width;
        for (int x = 0; x < width; x++) {
            pixels[offset + x] = result.get(x, y) ? BLACK : WHITE;
        }
    }

    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return bitmap;
}

From source file:org.syphr.mythtv.data.Load.java

public Load(Pair<LoadCategory, Double>... loads) {
    map = new EnumMap<LoadCategory, Double>(LoadCategory.class);

    for (Pair<LoadCategory, Double> load : loads) {
        map.put(load.getLeft(), load.getRight());
    }//from  w  w w .j  av a 2 s  .c  o m
}

From source file:org.syphr.mythtv.data.MemStats.java

public MemStats(Pair<MemStatCategory, Integer>... memStats) {
    map = new EnumMap<MemStatCategory, Integer>(MemStatCategory.class);

    for (Pair<MemStatCategory, Integer> memStat : memStats) {
        map.put(memStat.getLeft(), memStat.getRight());
    }/*  w ww . ja v a2  s. com*/
}

From source file:org.syphr.mythtv.data.TunerStatus.java

public TunerStatus(Pair<TunerStatusCategory, TunerData>... dataArray) {
    map = new EnumMap<TunerStatusCategory, TunerData>(TunerStatusCategory.class);

    for (Pair<TunerStatusCategory, TunerData> data : dataArray) {
        map.put(data.getLeft(), data.getRight());
    }// w  ww. jav a2  s .co  m
}

From source file:org.odk.collect.android.utilities.QRCodeUtils.java

public static String decodeFromBitmap(Bitmap bitmap) {
    BinaryBitmap binaryBitmap = getBinaryBitmap(bitmap);

    Map<DecodeHintType, Object> tmpHintsMap = new EnumMap<DecodeHintType, Object>(DecodeHintType.class);

    tmpHintsMap.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
    tmpHintsMap.put(DecodeHintType.POSSIBLE_FORMATS, BarcodeFormat.QR_CODE);
    tmpHintsMap.put(DecodeHintType.PURE_BARCODE, Boolean.FALSE);

    Reader reader = new QRCodeMultiReader();
    try {/* ww w.ja va 2s. c  o m*/
        Result result = reader.decode(binaryBitmap, tmpHintsMap);
        return result.getText();
    } catch (FormatException | NotFoundException | ChecksumException e) {
        Timber.i(e);
        ToastUtils.showLongToast("QR Code not found in the selected image");
    }
    return null;
}

From source file:com.opengamma.masterdb.security.hibernate.EnumUserType.java

protected EnumUserType(final Class<E> clazz, final E[] values) {
    _clazz = clazz;//w  w  w.j a  v a  2  s  . com
    _stringToEnum = new HashMap<String, E>();
    _enumToString = new EnumMap<E, String>(clazz);
    for (final E value : values) {
        final String string = enumToStringNoCache(value);
        _stringToEnum.put(string, value);
        _enumToString.put(value, string);
    }
}

From source file:org.github.aenygmatic.payroll.usecases.postprocessors.PaymentComponentEnumPostProcessor.java

@Override
protected Map<PayType, Object> newEnumMap() {
    return new EnumMap<>(PayType.class);
}

From source file:com.espertech.esper.schedule.TestScheduleSpec.java

public void testValidate() {
    // Test all units missing
    EnumMap<ScheduleUnit, SortedSet<Integer>> unitValues = new EnumMap<ScheduleUnit, SortedSet<Integer>>(
            ScheduleUnit.class);
    assertInvalid(unitValues);//from   w  w  w  .j a v a  2s.c  o  m

    // Test one unit missing
    unitValues = (new ScheduleSpec()).getUnitValues();
    unitValues.remove(ScheduleUnit.HOURS);
    assertInvalid(unitValues);

    // Test all units are wildcards
    unitValues = (new ScheduleSpec()).getUnitValues();
    new ScheduleSpec(unitValues, null, null, null);

    // Test invalid value in month
    SortedSet<Integer> values = new TreeSet<Integer>();
    values.add(0);
    unitValues.put(ScheduleUnit.MONTHS, values);
    assertInvalid(unitValues);

    // Test valid value in month
    values = new TreeSet<Integer>();
    values.add(1);
    values.add(5);
    unitValues.put(ScheduleUnit.MONTHS, values);
    new ScheduleSpec(unitValues, null, null, null);
}

From source file:eu.crisis_economics.utilities.EnumDistribution.java

public static <T extends Enum<T>> EnumDistribution<T> // Immutable
        create(Class<T> token, String sourceFile) throws IOException {
    if (token == null)
        throw new NullArgumentException();
    if (!token.isEnum())
        throw new IllegalArgumentException("EnumDistribution: " + token.getSimpleName() + " is not an enum.");
    if (token.getEnumConstants().length == 0)
        throw new IllegalArgumentException("EnumDistribution: " + token.getSimpleName() + " is an empty enum.");
    EnumDistribution<T> result = new EnumDistribution<T>();
    result.values = token.getEnumConstants();
    result.probabilities = new EnumMap<T, Double>(token);
    Map<String, T> converter = new HashMap<String, T>();
    final int numberOfValues = result.values.length;
    int[] valueIndices = new int[numberOfValues];
    double[] valueProbabilities = new double[numberOfValues];
    BitSet valueIsComitted = new BitSet(numberOfValues);
    {//from   www.  j  a v a 2 s .co  m
        int counter = 0;
        for (T value : result.values) {
            valueIndices[counter] = counter++;
            result.probabilities.put(value, 0.);
            converter.put(value.name(), value);
        }
    }
    BufferedReader reader = new BufferedReader(new FileReader(sourceFile));
    try {
        String newLine;
        while ((newLine = reader.readLine()) != null) {
            if (newLine.isEmpty())
                continue;
            StringTokenizer tokenizer = new StringTokenizer(newLine);
            final String name = tokenizer.nextToken(" ,:\t"), pStr = tokenizer.nextToken(" ,:\t");
            if (tokenizer.hasMoreTokens())
                throw new ParseException(
                        "EnumDistribution: " + newLine + " is not a valid entry in " + sourceFile + ".", 0);
            final double p = Double.parseDouble(pStr);
            if (p < 0. || p > 1.)
                throw new IOException(pStr + " is not a valid probability for the value " + name);
            result.probabilities.put(converter.get(name), p);
            final int ordinal = converter.get(name).ordinal();
            if (valueIsComitted.get(ordinal))
                throw new ParseException("The value " + name + " appears twice in " + sourceFile, 0);
            valueProbabilities[converter.get(name).ordinal()] = p;
            valueIsComitted.set(ordinal, true);
        }
        { // Check sum of probabilities
            double sum = 0.;
            for (double p : valueProbabilities)
                sum += p;
            if (Math.abs(sum - 1.) > 1e2 * Math.ulp(1.))
                throw new IllegalStateException("EnumDistribution: parser has succeeded, but the resulting "
                        + "probaility sum (value " + sum + ") is not equal to 1.");
        }
    } catch (Exception e) {
        throw new IOException(e.getMessage());
    } finally {
        reader.close();
    }
    result.dice = new EnumeratedIntegerDistribution(valueIndices, valueProbabilities);
    return result;
}