当前位置: 首页>>代码示例>>Java>>正文


Java EnumMap类代码示例

本文整理汇总了Java中java.util.EnumMap的典型用法代码示例。如果您正苦于以下问题:Java EnumMap类的具体用法?Java EnumMap怎么用?Java EnumMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


EnumMap类属于java.util包,在下文中一共展示了EnumMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getRelativeUnitPattern

import java.util.EnumMap; //导入依赖的package包/类
private String getRelativeUnitPattern(
        Style style, RelativeUnit unit, int pastFutureIndex, StandardPlural pluralForm) {
    int pluralIndex = pluralForm.ordinal();
    do {
        EnumMap<RelativeUnit, String[][]> unitMap = patternMap.get(style);
        if (unitMap != null) {
            String[][] spfCompiledPatterns = unitMap.get(unit);
            if (spfCompiledPatterns != null) {
                if (spfCompiledPatterns[pastFutureIndex][pluralIndex] != null) {
                    return spfCompiledPatterns[pastFutureIndex][pluralIndex];
                }
            }

        }

        // Consider other styles from alias fallback.
        // Data loading guaranteed no endless loops.
    } while ((style = fallbackCache[style.ordinal()]) != null);
    return null;
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:21,代码来源:RelativeDateTimeFormatter.java

示例2: createNodes

import java.util.EnumMap; //导入依赖的package包/类
/**
 * For a given Enum type, creates an immutable map from each of the Enum's values to a
 * corresponding LockGraphNode, with the {@code allowedPriorLocks} and
 * {@code disallowedPriorLocks} prepopulated with nodes according to the natural ordering of the
 * associated Enum values.
 */
@VisibleForTesting
static <E extends Enum<E>> Map<E, LockGraphNode> createNodes(Class<E> clazz) {
  EnumMap<E, LockGraphNode> map = Maps.newEnumMap(clazz);
  E[] keys = clazz.getEnumConstants();
  final int numKeys = keys.length;
  ArrayList<LockGraphNode> nodes = Lists.newArrayListWithCapacity(numKeys);
  // Create a LockGraphNode for each enum value.
  for (E key : keys) {
    LockGraphNode node = new LockGraphNode(getLockName(key));
    nodes.add(node);
    map.put(key, node);
  }
  // Pre-populate all allowedPriorLocks with nodes of smaller ordinal.
  for (int i = 1; i < numKeys; i++) {
    nodes.get(i).checkAcquiredLocks(Policies.THROW, nodes.subList(0, i));
  }
  // Pre-populate all disallowedPriorLocks with nodes of larger ordinal.
  for (int i = 0; i < numKeys - 1; i++) {
    nodes.get(i).checkAcquiredLocks(Policies.DISABLED, nodes.subList(i + 1, numKeys));
  }
  return Collections.unmodifiableMap(map);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:29,代码来源:CycleDetectingLockFactory.java

示例3: testConstructorAcceptAsiListMap

import java.util.EnumMap; //导入依赖的package包/类
@Test
public void testConstructorAcceptAsiListMap() {
	Map<Gene, List<Asi>> asiListMap = new EnumMap<>(Gene.class);
	MutationSet mutations = new MutationSet("PR46I,PR54V,PR73T,RT103N,RT41L,RT215E,RT181C,RT190A,IN66I");
	for (Gene gene : Gene.values()) {
		asiListMap.put(gene, new ArrayList<>());
		MutationSet geneMuts = mutations.getGeneMutations(gene);
		asiListMap.get(gene).add(new AsiHivdb(gene, geneMuts));
		asiListMap.get(gene).add(new AsiAnrs(gene, geneMuts));
		asiListMap.get(gene).add(new AsiRega(gene, geneMuts));
	}
	AlgorithmComparison cmp = new AlgorithmComparison(asiListMap);
	List<ComparableDrugScore> r = cmp.getComparisonResults();
	assertEquals(SIREnum.I, getComparableDrugScore(r, Drug.ABC, "ANRS").SIR);
	assertEquals("Possible resistance", getComparableDrugScore(r, Drug.ABC, "ANRS").interpretation);
	assertEquals(SIREnum.R, getComparableDrugScore(r, Drug.EFV, "ANRS").SIR);
	assertEquals("Resistance", getComparableDrugScore(r, Drug.EFV, "ANRS").interpretation);
	assertEquals(SIREnum.R, getComparableDrugScore(r, Drug.EFV, "HIVDB").SIR);
	assertEquals("High-Level Resistance", getComparableDrugScore(r, Drug.EFV, "HIVDB").interpretation);
	assertEquals(SIREnum.R, getComparableDrugScore(r, Drug.EFV, "REGA").SIR);
	assertEquals("Resistant GSS 0", getComparableDrugScore(r, Drug.EFV, "REGA").interpretation);
	assertEquals(asiListMap.get(Gene.IN), cmp.getAsiList(Gene.IN));
}
 
开发者ID:hivdb,项目名称:sierra,代码行数:24,代码来源:AlgorithmComparisonTest.java

示例4: main

import java.util.EnumMap; //导入依赖的package包/类
public static void main(String[] args) {
	Herb[] garden = {new Herb("Basic", Type.ANNUAL),
			new Herb("Carroway",Type.BIENNIAL),
			new Herb("Dill", Type.ANNUAL),
			new Herb("Lavendar", Type.PERENNIAL),
			new Herb("Parsley", Type.BIENNIAL),
			new Herb("Rosemary", Type.PERENNIAL)	
	};
	
	//Using an EnumMap to associate data with an enum
	Map<Herb.Type, Set<Herb>> herbByType = new EnumMap<Herb.Type,Set<Herb>>(
			Herb.Type.class);
	for (Herb.Type t : Herb.Type.values()){
		herbByType.put(t, new HashSet<Herb>());
	}
	for (Herb h : garden) {
		herbByType.get(h.type).add(h);
	}
	System.out.println(herbByType);
}
 
开发者ID:turoDog,项目名称:effectiveJava,代码行数:21,代码来源:Herb.java

示例5: consumeTimeDetail

import java.util.EnumMap; //导入依赖的package包/类
public void consumeTimeDetail(UResource.Key key, UResource.Value value) {
    UResource.Table unitTypesTable = value.getTable();

    EnumMap<RelativeUnit, String[][]> unitPatterns  = styleRelUnitPatterns.get(style);
    if (unitPatterns == null) {
        unitPatterns = new EnumMap<RelativeUnit, String[][]>(RelativeUnit.class);
        styleRelUnitPatterns.put(style, unitPatterns);
    }
    String[][] patterns = unitPatterns.get(unit.relUnit);
    if (patterns == null) {
        patterns = new String[2][StandardPlural.COUNT];
        unitPatterns.put(unit.relUnit, patterns);
    }

    // Stuff the pattern for the correct plural index with a simple formatter.
    for (int i = 0; unitTypesTable.getKeyAndValue(i, key, value); i++) {
        if (value.getType() == ICUResourceBundle.STRING) {
            int pluralIndex = StandardPlural.indexFromString(key.toString());
            if (patterns[pastFutureIndex][pluralIndex] == null) {
                patterns[pastFutureIndex][pluralIndex] =
                        SimpleFormatterImpl.compileToStringMinMaxArguments(
                                value.getString(), sb, 0, 1);
            }
        }
    }
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:27,代码来源:RelativeDateTimeFormatter.java

示例6: get

import java.util.EnumMap; //导入依赖的package包/类
/**
 * Retrieves the connectivity that has been collected up until this call. This method fills in
 * {@link ConnectivityCheckResult#UNKNOWN} for results that have not been retrieved yet.
 *
 * @return the {@link FeedbackData}.
 */
public FeedbackData get() {
    ThreadUtils.assertOnUiThread();
    Map<Type, Integer> result = new EnumMap<Type, Integer>(Type.class);
    // Ensure the map is filled with a result for all {@link Type}s.
    for (Type type : Type.values()) {
        if (mResult.containsKey(type)) {
            result.put(type, mResult.get(type));
        } else {
            result.put(type, ConnectivityCheckResult.UNKNOWN);
        }
    }
    long elapsedTimeMs = SystemClock.elapsedRealtime() - mStartCheckTimeMs;
    int connectionType = NetworkChangeNotifier.getInstance().getCurrentConnectionType();
    return new FeedbackData(result, mTimeoutMs, elapsedTimeMs, connectionType);
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:22,代码来源:ConnectivityTask.java

示例7: immutableEnumMap

import java.util.EnumMap; //导入依赖的package包/类
/**
 * Returns an immutable map instance containing the given entries.
 * Internally, the returned map will be backed by an {@link EnumMap}.
 *
 * <p>The iteration order of the returned map follows the enum's iteration
 * order, not the order in which the elements appear in the given map.
 *
 * @param map the map to make an immutable copy of
 * @return an immutable map containing those entries
 * @since 14.0
 */
@GwtCompatible(serializable = true)
@Beta
public static <K extends Enum<K>, V> ImmutableMap<K, V> immutableEnumMap(
    Map<K, ? extends V> map) {
  if (map instanceof ImmutableEnumMap) {
    @SuppressWarnings("unchecked") // safe covariant cast
    ImmutableEnumMap<K, V> result = (ImmutableEnumMap<K, V>) map;
    return result;
  } else if (map.isEmpty()) {
    return ImmutableMap.of();
  } else {
    for (Map.Entry<K, ? extends V> entry : map.entrySet()) {
      checkNotNull(entry.getKey());
      checkNotNull(entry.getValue());
    }
    return ImmutableEnumMap.asImmutable(new EnumMap<K, V>(map));
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:30,代码来源:Maps.java

示例8: generateLevel

import java.util.EnumMap; //导入依赖的package包/类
private static TileType[][] generateLevel(Random seedPicker, int width, int height) {
	TileType[][] tiles = new TileType[width][height];
	
	float[][] landData = generateTerrain(seedPicker.nextLong(), width, height, landGen.samplePeriods, landGen.postSmoothing);
	float[][] biomeData = generateTerrain(seedPicker.nextLong(), width, height, biomeSample, biomeSmooth);
	
	EnumMap<Biome, float[][]> biomeTerrain = new EnumMap<>(Biome.class);
	for(Biome b: Biome.values)
		biomeTerrain.put(b, b.generateTerrain(seedPicker.nextLong(), width, height));
	
	for (int x = 0; x < tiles.length; x++) {
		for (int y = 0; y < tiles[x].length; y++) {
			tiles[x][y] = landGen.getTile(landData[x][y]);
			if(tiles[x][y] == TileType.GRASS) {
				Biome biome = biomeGen[getIndex(biomeGen.length, biomeData[x][y])];
				tiles[x][y] = biome.getTile(biomeTerrain.get(biome)[x][y]);
			}
		}
	}
	
	return tiles;
}
 
开发者ID:chrisj42,项目名称:miniventure,代码行数:23,代码来源:LevelGenerator.java

示例9: load

import java.util.EnumMap; //导入依赖的package包/类
@Override
public Map<DrugClass, List<MutationPattern>> load() throws SQLException {
	String sql =
		"SELECT SequenceID, Pos, AA " +
		"FROM tblMutations WHERE Gene = ? " +
		// no stop codon
		"AND AA != '.' ORDER BY SequenceID, Pos, AA";

	Map<DrugClass, List<MutationPattern>> allResult = new EnumMap<>(DrugClass.class);
	for (Gene gene : Gene.values()) {
		Map<Integer, MutationSet> allMutations = db.iterateMap(
			sql,
			(rs, map) -> {
				Integer seqId = rs.getInt("SequenceID");
				Integer pos = rs.getInt("Pos");
				String aa = rs.getString("AA");
				MutationSet muts = map.getOrDefault(seqId, new MutationSet());
				muts = muts.mergesWith(new Mutation(gene, pos, aa));
				map.put(seqId, muts);
				return null;
			},
			gene.toString());
		allResult.putAll(calcGenePatterns(gene, allMutations.values()));
	}
	return allResult;
}
 
开发者ID:hivdb,项目名称:sierra,代码行数:27,代码来源:MutationPatterns.java

示例10: getDrugClassDrugMutScores

import java.util.EnumMap; //导入依赖的package包/类
public Map<DrugClass, Map<Drug, Map<Mutation, Double>>> getDrugClassDrugMutScores() {
	Map<DrugClass, Map<Drug, Map<Mutation, Double>>> result = new EnumMap<>(DrugClass.class);
	for (DrugClass drugClass : gene.getDrugClasses()) {
		result.put(drugClass, new EnumMap<>(Drug.class));
		Map<Drug, Map<Mutation, Double>> drugClassResult = result.get(drugClass);
		for (Drug drug : drugClass.getDrugsForHivdbTesting()) {
			drugClassResult.put(drug, new LinkedHashMap<>());
			Map<Mutation, Double> drugResult = drugClassResult.get(drug);
			Map<String, Double> drugScores = separatedScores.getOrDefault(drug, Collections.emptyMap());
			for (String key : drugScores.keySet()) {
				if (StringUtils.countMatches(key, "+") > 1) {
					continue;
				}
				Mutation mut = triggeredMuts.get(drug).get(key).first();
				drugResult.put(mut, drugScores.get(key));
			}
		}
	}
	return result;
}
 
开发者ID:hivdb,项目名称:sierra,代码行数:21,代码来源:FastHivdb.java

示例11: main

import java.util.EnumMap; //导入依赖的package包/类
public static void main(String[] args) {
    EnumMap<Test, String> map1 = new EnumMap<Test, String>(Test.class);
    map1.put(Test.ONE, "1");
    map1.put(Test.TWO, "2");

    // We need to force creation of the map1.entrySet
    int size = map1.entrySet().size();
    if (size != 2) {
        throw new RuntimeException(
                "Invalid size in original map. Expected: 2 was: " + size);
    }

    EnumMap<Test, String> map2 = map1.clone();
    map2.remove(Test.ONE);
    size = map2.entrySet().size();
    if (size != 1) {
        throw new RuntimeException(
                "Invalid size in cloned instance. Expected: 1 was: " + size);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:ProperEntrySetOnClone.java

示例12: maxStats

import java.util.EnumMap; //导入依赖的package包/类
public void maxStats() {
    Map<MapleStat, Integer> statup = new EnumMap<>(MapleStat.class);
    c.getPlayer().getStat().str = (short) 999;
    c.getPlayer().getStat().dex = (short) 999;
    c.getPlayer().getStat().int_ = (short) 999;
    c.getPlayer().getStat().luk = (short) 999;

    int overrDemon = GameConstants.isDemonSlayer(c.getPlayer().getJob())
            ? GameConstants.getMPByJob(c.getPlayer().getJob()) : 500000;
    c.getPlayer().getStat().maxhp = 500000;
    c.getPlayer().getStat().maxmp = overrDemon;
    c.getPlayer().getStat().setHp(500000, c.getPlayer());
    c.getPlayer().getStat().setMp(overrDemon, c.getPlayer());

    statup.put(MapleStat.STR, Integer.valueOf(999));
    statup.put(MapleStat.DEX, Integer.valueOf(999));
    statup.put(MapleStat.LUK, Integer.valueOf(999));
    statup.put(MapleStat.INT, Integer.valueOf(999));
    statup.put(MapleStat.HP, Integer.valueOf(500000));
    statup.put(MapleStat.MAXHP, Integer.valueOf(500000));
    statup.put(MapleStat.MP, Integer.valueOf(overrDemon));
    statup.put(MapleStat.MAXMP, Integer.valueOf(overrDemon));
    c.getPlayer().getStat().recalcLocalStats(c.getPlayer());
    // c.getSession().write(CWvsContext.updatePlayerStats(statup,
    // c.getPlayer().getJob()));
}
 
开发者ID:ergothvs,项目名称:Lucid2.0,代码行数:27,代码来源:NPCConversationManager.java

示例13: handleLivingEntityDamageEvent

import java.util.EnumMap; //导入依赖的package包/类
public static EntityDamageEvent handleLivingEntityDamageEvent(Entity damagee, DamageSource source, double rawDamage, double hardHatModifier, double blockingModifier, double armorModifier, double resistanceModifier, double magicModifier, double absorptionModifier, Function<Double, Double> hardHat, Function<Double, Double> blocking, Function<Double, Double> armor, Function<Double, Double> resistance, Function<Double, Double> magic, Function<Double, Double> absorption) {
    Map<DamageModifier, Double> modifiers = new EnumMap<DamageModifier, Double>(DamageModifier.class);
    Map<DamageModifier, Function<? super Double, Double>> modifierFunctions = new EnumMap<DamageModifier, Function<? super Double, Double>>(DamageModifier.class);
    modifiers.put(DamageModifier.BASE, rawDamage);
    modifierFunctions.put(DamageModifier.BASE, ZERO);
    if (source == DamageSource.fallingBlock || source == DamageSource.anvil) {
        modifiers.put(DamageModifier.HARD_HAT, hardHatModifier);
        modifierFunctions.put(DamageModifier.HARD_HAT, hardHat);
    }
    if (damagee instanceof EntityPlayer) {
        modifiers.put(DamageModifier.BLOCKING, blockingModifier);
        modifierFunctions.put(DamageModifier.BLOCKING, blocking);
    }
    modifiers.put(DamageModifier.ARMOR, armorModifier);
    modifierFunctions.put(DamageModifier.ARMOR, armor);
    modifiers.put(DamageModifier.RESISTANCE, resistanceModifier);
    modifierFunctions.put(DamageModifier.RESISTANCE, resistance);
    modifiers.put(DamageModifier.MAGIC, magicModifier);
    modifierFunctions.put(DamageModifier.MAGIC, magic);
    modifiers.put(DamageModifier.ABSORPTION, absorptionModifier);
    modifierFunctions.put(DamageModifier.ABSORPTION, absorption);
    return handleEntityDamageEvent(damagee, source, modifiers, modifierFunctions);
}
 
开发者ID:UraniumMC,项目名称:Uranium,代码行数:24,代码来源:CraftEventFactory.java

示例14: getModeAction

import java.util.EnumMap; //导入依赖的package包/类
/**
 * Lazily creates and returns an action setting the mode of this
 * JGraph. The actual setting is done by a call to {@link #setMode(JGraphMode)}.
 */
public Action getModeAction(JGraphMode mode) {
    if (this.modeActionMap == null) {
        this.modeActionMap = new EnumMap<>(JGraphMode.class);
        for (final JGraphMode any : JGraphMode.values()) {
            Action action = new AbstractAction(any.getName(), any.getIcon()) {
                @Override
                public void actionPerformed(ActionEvent e) {
                    setMode(any);
                }
            };

            if (any.getAcceleratorKey() != null) {
                action.putValue(Action.ACCELERATOR_KEY, any.getAcceleratorKey());
                addAccelerator(action);
            }
            this.modeActionMap.put(any, action);
        }
    }
    return this.modeActionMap.get(mode);
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:25,代码来源:JGraph.java

示例15: makeStateMachineTable

import java.util.EnumMap; //导入依赖的package包/类
private void makeStateMachineTable() {
  Stack<ApplicableTransition<OPERAND, STATE, EVENTTYPE, EVENT>> stack =
    new Stack<ApplicableTransition<OPERAND, STATE, EVENTTYPE, EVENT>>();

  Map<STATE, Map<EVENTTYPE, Transition<OPERAND, STATE, EVENTTYPE, EVENT>>>
    prototype = new HashMap<STATE, Map<EVENTTYPE, Transition<OPERAND, STATE, EVENTTYPE, EVENT>>>();

  prototype.put(defaultInitialState, null);

  // I use EnumMap here because it'll be faster and denser.  I would
  //  expect most of the states to have at least one transition.
  stateMachineTable
     = new EnumMap<STATE, Map<EVENTTYPE,
                         Transition<OPERAND, STATE, EVENTTYPE, EVENT>>>(prototype);

  for (TransitionsListNode cursor = transitionsListNode;
       cursor != null;
       cursor = cursor.next) {
    stack.push(cursor.transition);
  }

  while (!stack.isEmpty()) {
    stack.pop().apply(this);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:26,代码来源:StateMachineFactory.java


注:本文中的java.util.EnumMap类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。