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:com.att.aro.ui.view.diagnostictab.plot.UserEventPlot.java

@Override
public void populate(XYPlot plot, AROTraceData analysis) {
    if (analysis != null) {
        userInputData.removeAllSeries();
        // create the dataset...
        Map<UserEvent.UserEventType, XYIntervalSeries> seriesMap = new EnumMap<UserEvent.UserEventType, XYIntervalSeries>(
                UserEvent.UserEventType.class);
        for (UserEvent.UserEventType eventType : UserEvent.UserEventType.values()) {
            XYIntervalSeries series = new XYIntervalSeries(eventType);
            seriesMap.put(eventType, series);
            userInputData.addSeries(series);
        }/*from   www . j ava  2s  .  c  om*/
        // Populate the data set
        //need to add something here
        for (UserEvent event : analysis.getAnalyzerResult().getTraceresult().getUserEvents()) {
            seriesMap.get(event.getEventType()).add(event.getPressTime(), event.getPressTime(),
                    event.getReleaseTime(), 0.5, 0, 1);
        }

        // Assign ToolTip to renderer
        XYItemRenderer renderer = plot.getRenderer();
        renderer.setSeriesPaint(userInputData.indexOf(UserEventType.SCREEN_LANDSCAPE), Color.BLUE);
        renderer.setSeriesPaint(userInputData.indexOf(UserEventType.SCREEN_PORTRAIT), Color.BLUE);
        renderer.setBaseToolTipGenerator(new XYToolTipGenerator() {

            @Override
            public String generateToolTip(XYDataset dataset, int series, int item) {
                UserEvent.UserEventType eventType = (UserEvent.UserEventType) userInputData.getSeries(series)
                        .getKey();
                return ResourceBundleHelper.getEnumString(eventType);
            }
        });

    }

    plot.setDataset(userInputData);
    //      return plot;
}

From source file:cc.aileron.accessor.PojoAccessorMixerImpl.java

@Override
public PojoAccessor<?> mixin(final List<PojoAccessor<?>> accessors, final List<Object> parents) {
    final InstanceManager i = accessors.get(0).instanceManager();

    final HashMap<String, PojoAccessor<?>> map = new HashMap<String, PojoAccessor<?>>();
    final EnumMap<PojoAccessorMethod, List<String>> keys = new EnumMap<PojoAccessorMethod, List<String>>(
            PojoAccessorMethod.class);
    keys.put(PojoAccessorMethod.GET, new SkipList<String>());
    keys.put(PojoAccessorMethod.SET, new SkipList<String>());

    final HashMap<String, PojoAccessor<?>> setmap = new HashMap<String, PojoAccessor<?>>();
    for (final PojoAccessor<?> accessor : accessors) {
        for (final PojoAccessorMethod method : PojoAccessorMethod.values()) {
            final List<String> methodKeys = accessor.keys(method);
            keys.get(method).addAll(methodKeys);
        }/*w  ww  .j  a va 2 s .c  o  m*/
        for (final String key : accessor.keys(PojoAccessorMethod.GET)) {
            map.put(key, accessor);
        }
        for (final String key : accessor.keys(PojoAccessorMethod.SET)) {
            setmap.put(key, accessor);
        }
    }
    final PojoAccessorManagerLocal manager = this.manager;
    return new PojoAccessor<Object>() {
        @Override
        public boolean exist(final String key) {
            for (final PojoAccessor<?> accessor : accessors) {
                if (accessor.exist(key)) {
                    return true;
                }
            }
            return false;
        }

        @Override
        public InstanceManager instanceManager() {
            return i;
        }

        @Override
        public List<String> keys(final PojoAccessorMethod method) {
            return keys.get(method);
        }

        @Override
        public PojoAccessor<?> mixin(final Object... objects) {
            final SkipList<PojoAccessor<?>> list = new SkipList<PojoAccessor<?>>();
            list.add(this);
            for (final Object object : objects) {
                list.add(manager.from(object, parents));
            }
            return PojoAccessorMixerImpl.this.mixin(list, parents);
        }

        @Override
        public Iterable<PojoAccessorValue> set(final PojoAccessorMethod method) {
            final HashMap<String, PojoAccessor<?>> m = method == PojoAccessorMethod.GET ? map : setmap;
            return new Iterable<PojoAccessorValue>() {

                @Override
                public Iterator<PojoAccessorValue> iterator() {
                    final Iterator<Entry<String, PojoAccessor<?>>> ite = m.entrySet().iterator();
                    return new Iterator<PojoAccessorValue>() {
                        @Override
                        public boolean hasNext() {
                            return ite.hasNext();
                        }

                        @Override
                        public PojoAccessorValue next() {
                            final Entry<String, PojoAccessor<?>> e = ite.next();
                            try {
                                return e.getValue().to(e.getKey());
                            } catch (final PojoAccessorValueNotFoundException e1) {
                                throw new Error(e1);
                            } catch (final PojoPropertiesNotFoundException e1) {
                                throw new Error(e1);
                            }
                        }

                        @Override
                        public void remove() {
                            throw new UnsupportedOperationException();
                        }
                    };
                }
            };
        }

        @Override
        public PojoAccessorValue to(final String key)
                throws PojoAccessorValueNotFoundException, PojoPropertiesNotFoundException {
            {
                final PojoAccessor<?> a = map.get(key);
                if (a != null) {
                    return a.to(key);
                }
            }
            for (final PojoAccessor<?> a : accessors) {
                if (a.exist(key)) {
                    return a.to(key);
                }
            }
            for (final PojoAccessor<?> a : accessors) {
                try {
                    final PojoAccessorValue result = a.to(key);
                    if (result != null) {
                        return result;
                    }
                } catch (final PojoAccessorValueNotFoundException e) {
                } catch (final PojoPropertiesNotFoundException e) {
                }
            }
            throw new PojoAccessorValueNotFoundException(accessors, key);
        }

        @Override
        public String toString() {
            return ReflectionToStringBuilder.toString(this);
        }

        @Override
        public Object toTarget() {
            throw new UnsupportedOperationException();
        }
    };
}

From source file:org.matsim.contrib.util.LongEnumAdder.java

public LongEnumAdder(Class<K> clazz) {
    super(clazz);
    sums = new EnumMap<>(clazz);
    for (K e : keys) {
        sums.put(e, new MutableLong());
    }/*from  ww w . j  ava2s  . c  o m*/
}

From source file:org.matsim.contrib.util.DoubleEnumAdder.java

public DoubleEnumAdder(Class<K> clazz) {
    super(clazz);
    sums = new EnumMap<>(clazz);
    for (K e : keys) {
        sums.put(e, new MutableDouble());
    }/*  w  w  w  . j a v a 2 s .  com*/
}

From source file:io.lavagna.service.ConfigurationRepository.java

public Map<Key, String> findConfigurationFor(Set<Key> keys) {
    Set<String> s = new HashSet<>();
    Map<Key, String> res = new EnumMap<Key, String>(Key.class);
    for (Key k : keys) {
        s.add(k.toString());/*from www  . j  av  a2 s.  com*/
        res.put(k, null);
    }

    for (ConfigurationKeyValue kv : queries.findConfigurationFor(s)) {
        res.put(kv.getFirst(), kv.getSecond());
    }
    return res;
}

From source file:fr.avianey.androidsvgdrawable.QualifiedResource.java

public File getOutputFor(final Density density, final File to, final OutputType outputType) {
    StringBuilder builder = new StringBuilder(outputType.name());
    EnumMap<Type, String> qualifiers = new EnumMap<>(typedQualifiers);
    qualifiers.remove(Type.density);
    qualifiers.put(Type.density, density.name());
    builder.append(Qualifier.toQualifiedString(qualifiers));
    return new File(to, builder.toString());
}

From source file:com.relicum.ipsum.Menus.SimpleMenu.java

/**
 * Instantiates a new Simple menu./*from w  w w .  j ava 2s .co m*/
 *
 * @param menuTitle the menu title
 * @param size the size
 * @param uniqueName the unique name
 */
public SimpleMenu(String menuTitle, int size, String uniqueName) {
    super(menuTitle, size, uniqueName);
    this.items = new EnumMap<>(Slot.class);

}

From source file:com.att.aro.ui.view.diagnostictab.plot.BurstPlot.java

public void populate(XYPlot plot, AROTraceData analysis) {

    if (analysis != null) {
        burstDataCollection.removeAllSeries();
        Map<BurstCategory, XYIntervalSeries> seriesMap = new EnumMap<BurstCategory, XYIntervalSeries>(
                BurstCategory.class);
        final Map<BurstCategory, List<Burst>> burstMap = new HashMap<BurstCategory, List<Burst>>();
        for (BurstCategory eventType : BurstCategory.values()) {
            XYIntervalSeries series = new XYIntervalSeries(eventType);
            seriesMap.put(eventType, series);
            burstDataCollection.addSeries(series);
            burstMap.put(eventType, new ArrayList<Burst>());
        }/*from ww w .  ja  v a  2s .  c o m*/
        final List<Burst> burstStates = analysis.getAnalyzerResult().getBurstcollectionAnalysisData()
                .getBurstCollection();
        Iterator<Burst> iter = burstStates.iterator();
        while (iter.hasNext()) {
            Burst currEvent = iter.next();
            if (currEvent != null) {
                BurstCategory burstState = currEvent.getBurstCategory();
                if (burstState != null) {
                    seriesMap.get(burstState).add(currEvent.getBeginTime(), currEvent.getBeginTime(),
                            currEvent.getEndTime(), 0.5, 0, 1);
                    burstMap.get(burstState).add(currEvent);
                }
            }
        }

        Color myGreen = new Color(34, 177, 76);
        Color lightGreen = new Color(134, 232, 162);

        XYItemRenderer renderer = plot.getRenderer();
        renderer.setSeriesPaint(burstDataCollection.indexOf(BurstCategory.TCP_PROTOCOL), Color.blue);
        renderer.setSeriesPaint(burstDataCollection.indexOf(BurstCategory.TCP_LOSS_OR_DUP), Color.black);
        renderer.setSeriesPaint(burstDataCollection.indexOf(BurstCategory.USER_INPUT), myGreen);
        renderer.setSeriesPaint(burstDataCollection.indexOf(BurstCategory.SCREEN_ROTATION), lightGreen);
        renderer.setSeriesPaint(burstDataCollection.indexOf(BurstCategory.CLIENT_APP), Color.red);
        renderer.setSeriesPaint(burstDataCollection.indexOf(BurstCategory.SERVER_NET_DELAY), Color.yellow);
        renderer.setSeriesPaint(burstDataCollection.indexOf(BurstCategory.LONG), Color.gray);
        renderer.setSeriesPaint(burstDataCollection.indexOf(BurstCategory.PERIODICAL), Color.magenta);
        renderer.setSeriesPaint(burstDataCollection.indexOf(BurstCategory.CPU), Color.cyan);
        renderer.setSeriesPaint(burstDataCollection.indexOf(BurstCategory.UNKNOWN), Color.darkGray);

        // Assign ToolTip to renderer
        renderer.setBaseToolTipGenerator(new XYToolTipGenerator() {
            @Override
            public String generateToolTip(XYDataset dataset, int series, int item) {
                BurstCategory eventType = (BurstCategory) burstDataCollection.getSeries(series).getKey();
                Burst b;
                int size = burstMap.get(eventType).size();
                if (size > item) {
                    b = burstMap.get(eventType).get(item);
                } else {
                    b = burstMap.get(eventType).get(size);
                }
                final String PREFIX = "BurstCategory.";
                return MessageFormat.format(ResourceBundleHelper.getMessageString(PREFIX + eventType.ordinal()),
                        b.getPackets().size(), b.getBurstBytes(), b.getBurstThroughPut());
            }
        });

    }

    plot.setDataset(burstDataCollection);

    //      return plot;

}

From source file:io.digibyte.tools.qrcode.QRUtils.java

public static Bitmap encodeAsBitmap(String content, int dimension) {

    if (content == null) {
        return null;
    }//www  .  j  ava2  s.  c o m
    Map<EncodeHintType, Object> hints = null;
    String encoding = guessAppropriateEncoding(content);
    hints = new EnumMap<>(EncodeHintType.class);
    if (encoding != null) {
        hints.put(EncodeHintType.CHARACTER_SET, encoding);
    }
    hints.put(EncodeHintType.MARGIN, 1);
    BitMatrix result = null;
    try {
        result = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, dimension, dimension, hints);
    } catch (IllegalArgumentException iae) {
        // Unsupported format
        return null;
    } catch (WriterException e) {
        e.printStackTrace();
    }
    if (result == null)
        return null;
    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:ch.jeda.platform.android.SensorManager.java

SensorManager() {
    this.enabledSensors = EnumSet.noneOf(SensorType.class);
    this.sensorMap = new EnumMap<SensorType, Sensor>(SensorType.class);
    this.sensorListenerMap = new EnumMap<SensorType, SensorEventListener>(SensorType.class);
    this.sensorInfoMap = new HashMap<Sensor, SensorInfo>();
    this.setRetainInstance(true);
}