Example usage for java.util EnumMap get

List of usage examples for java.util EnumMap get

Introduction

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

Prototype

public V get(Object key) 

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:org.libreplan.web.calendars.BaseCalendarEditionController.java

private static String asString(EffortDuration duration) {
    if (duration == null) {
        return "";
    }//w ww. j a va2  s.c  o  m
    EnumMap<Granularity, Integer> decomposed = duration.decompose();

    String result = decomposed.get(Granularity.HOURS) + ":";
    result += decomposed.get(Granularity.MINUTES);

    if (decomposed.get(Granularity.SECONDS) > 0) {
        result += " " + decomposed.get(Granularity.SECONDS) + "s";
    }

    return result;
}

From source file:org.libreplan.business.workingday.EffortDuration.java

public EffortDuration atNearestMinute() {
    EnumMap<Granularity, Integer> decompose = this.decompose();
    int seconds = decompose.get(Granularity.SECONDS);

    return seconds >= 30 ? this.plus(EffortDuration.seconds(60 - seconds))
            : this.minus(EffortDuration.seconds(seconds));
}

From source file:org.libreplan.business.workingday.EffortDuration.java

public String toString() {
    EnumMap<Granularity, Integer> valuesForEachUnit = decompose();
    Integer hours = valuesForEachUnit.get(Granularity.HOURS);
    Integer minutes = valuesForEachUnit.get(Granularity.MINUTES);
    Integer seconds = valuesForEachUnit.get(Granularity.SECONDS);

    return String.format("%d:%02d:%02d", hours, minutes, seconds);
}

From source file:org.libreplan.business.workingday.EffortDuration.java

public String toFormattedString() {
    EnumMap<Granularity, Integer> byGranularity = this.atNearestMinute().decompose();
    int hours = byGranularity.get(Granularity.HOURS);
    int minutes = byGranularity.get(Granularity.MINUTES);

    return minutes == 0 ? String.format("%d", hours) : String.format("%d:%02d", hours, minutes);
}

From source file:org.jgrades.config.service.UserPreferencesUpdater.java

private void updateRoleData(EnumMap<JgRole, RoleDetails> updatedRoles,
        EnumMap<JgRole, RoleDetails> persistRoles) throws IllegalAccessException {
    if (!persistRoles.containsKey(JgRole.ADMINISTRATOR)
            && !CollectionUtils.isEqualCollection(updatedRoles.keySet(), persistRoles.keySet())) {
        throw new UserPreferencesException("Roles cannot be modified by user itself");
    }/*ww  w  . j  av  a2 s.  co m*/
    Set<Map.Entry<JgRole, RoleDetails>> entries = updatedRoles.entrySet();
    for (Map.Entry<JgRole, RoleDetails> entry : entries) {
        mapNewValues(entry.getValue().getClass(), updatedRoles.get(entry.getKey()), entry.getValue());
    }

}

From source file:org.omnaest.utils.structure.map.MapUtilsTest.java

/**
 * @see TestEnum//from   ww  w . j a v a2s  . com
 */
@SuppressWarnings("javadoc")
@Test
public void testInitializedEnumMap() {
    //
    final Class<TestEnum> enumType = TestEnum.class;
    final Factory<Set<String>> factory = new Factory<Set<String>>() {
        @Override
        public Set<String> newInstance() {
            return SetUtils.valueOf("a", "b");
        }
    };

    final EnumMap<TestEnum, Set<String>> enumMapWithFilledDefaultValues = MapUtils.initializedEnumMap(enumType,
            factory);
    assertNotNull(enumMapWithFilledDefaultValues);
    assertEquals(2, enumMapWithFilledDefaultValues.size());
    assertEquals(SetUtils.valueOf("a", "b"), enumMapWithFilledDefaultValues.get(TestEnum.key1));
    assertEquals(SetUtils.valueOf("a", "b"), enumMapWithFilledDefaultValues.get(TestEnum.key2));
}

From source file:com.glowinteractive.reforger.Item.java

public HashSet<StatKVMap> candidates(EnumMap<Stat, EnumSet<Stat>> mappings) {
    parse();/*  w w  w.ja va  2 s  . co m*/

    final HashSet<StatKVMap> result = new HashSet<StatKVMap>(Stat.TYPE_COUNT);

    for (Stat decrease : Stat.values()) {
        for (Stat increase : Stat.values()) {
            if (_mutableStats.value(increase) == 0 && _mutableStats.value(decrease) != 0
                    && mappings.containsKey(decrease) && mappings.get(decrease).contains(increase)) {
                int delta = Math.round((float) Math.floor(0.4 * _mutableStats.value(decrease)));
                StatKVMap deltaMap = new StatKVMap(decrease, increase, delta);
                result.add(deltaMap);
            }
        }
    }

    return result;
}

From source file:org.helios.netty.jmx.MetricCollector.java

/**
 * Collects the number of threads in each thread state
 * @return an EnumMap with Thread states as the key and the number of threads in that state as the value
 *//*from   w w  w  .  j av  a  2 s. co  m*/
public EnumMap<Thread.State, AtomicInteger> getThreadStates() {
    EnumMap<Thread.State, AtomicInteger> map = new EnumMap<State, AtomicInteger>(Thread.State.class);
    for (ThreadInfo ti : threadMxBean.getThreadInfo(threadMxBean.getAllThreadIds())) {
        State st = ti.getThreadState();
        AtomicInteger ai = map.get(st);
        if (ai == null) {
            ai = new AtomicInteger(0);
            map.put(st, ai);
        }
        ai.incrementAndGet();
    }
    return map;
}

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);
        }// ww w .j a v a 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();
        }
    };
}