當前位置: 首頁>>代碼示例>>Java>>正文


Java EnumMap.put方法代碼示例

本文整理匯總了Java中java.util.EnumMap.put方法的典型用法代碼示例。如果您正苦於以下問題:Java EnumMap.put方法的具體用法?Java EnumMap.put怎麽用?Java EnumMap.put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.EnumMap的用法示例。


在下文中一共展示了EnumMap.put方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:29,代碼來源:CycleDetectingLockFactory.java

示例2: handleNonLivingEntityDamageEvent

import java.util.EnumMap; //導入方法依賴的package包/類
public static boolean handleNonLivingEntityDamageEvent(Entity entity, DamageSource source, double damage) {
    if (entity instanceof EntityEnderCrystal && !(source instanceof EntityDamageSource)) {
        return false;
    }

    final EnumMap<DamageModifier, Double> modifiers = new EnumMap<DamageModifier, Double>(DamageModifier.class);
    final EnumMap<DamageModifier, Function<? super Double, Double>> functions = new EnumMap(DamageModifier.class);

    modifiers.put(DamageModifier.BASE, damage);
    functions.put(DamageModifier.BASE, ZERO);

    final EntityDamageEvent event = handleEntityDamageEvent(entity, source, modifiers, functions);
    if (event == null) {
        return false;
    }
    return event.isCancelled() || (event.getDamage() == 0 && !(entity instanceof EntityItemFrame)); // Cauldron - fix frame removal
}
 
開發者ID:UraniumMC,項目名稱:Uranium,代碼行數:18,代碼來源:CraftEventFactory.java

示例3: getAllBuffs

import java.util.EnumMap; //導入方法依賴的package包/類
public List<PlayerBuffValueHolder> getAllBuffs() {
    final List<PlayerBuffValueHolder> ret = new ArrayList<>();
    final Map<Pair<Integer, Byte>, Integer> alreadyDone = new HashMap<>();
    final LinkedList<Entry<CharacterTemporaryStat, MapleBuffStatValueHolder>> allBuffs = new LinkedList<>(effects.entrySet());
    for (Entry<CharacterTemporaryStat, MapleBuffStatValueHolder> mbsvh : allBuffs) {
        final Pair<Integer, Byte> key = new Pair<>(mbsvh.getValue().effect.getSourceId(), mbsvh.getValue().effect.getLevel());
        if (alreadyDone.containsKey(key)) {
            ret.get(alreadyDone.get(key)).statup.put(mbsvh.getKey(), mbsvh.getValue().value);
        } else {
            alreadyDone.put(key, ret.size());
            final EnumMap<CharacterTemporaryStat, Integer> list = new EnumMap<>(CharacterTemporaryStat.class);
            list.put(mbsvh.getKey(), mbsvh.getValue().value);
            ret.add(new PlayerBuffValueHolder(mbsvh.getValue().startTime, mbsvh.getValue().effect, list, mbsvh.getValue().localDuration, mbsvh.getValue().cid));
        }
    }
    return ret;
}
 
開發者ID:ergothvs,項目名稱:Lucid2.0,代碼行數:18,代碼來源:MapleCharacter.java

示例4: 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:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:ProperEntrySetOnClone.java

示例5: newChannel

import java.util.EnumMap; //導入方法依賴的package包/類
/**
 * INTERNAL Create a new channel pair with the specified name and channel handlers.
 * This is used internally in forge and FML
 *
 * @param container The container to associate the channel with
 * @param name The name for the channel
 * @param handlers Some {@link ChannelHandler} for the channel
 * @return an {@link EnumMap} of the pair of channels. keys are {@link Side}. There will always be two entries.
 */
public EnumMap<Side,FMLEmbeddedChannel> newChannel(ModContainer container, String name, ChannelHandler... handlers)
{
    if (channels.get(Side.CLIENT).containsKey(name) || channels.get(Side.SERVER).containsKey(name) || name.startsWith("MC|") || name.startsWith("\u0001") || (name.startsWith("FML") && !("FML".equals(container.getModId()))))
    {
        throw new RuntimeException("That channel is already registered");
    }
    EnumMap<Side,FMLEmbeddedChannel> result = Maps.newEnumMap(Side.class);

    for (Side side : Side.values())
    {
        FMLEmbeddedChannel channel = new FMLEmbeddedChannel(container, name, side, handlers);
        channels.get(side).put(name,channel);
        result.put(side, channel);
    }
    return result;
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:26,代碼來源:NetworkRegistry.java

示例6: initBarcodeReader

import java.util.EnumMap; //導入方法依賴的package包/類
/**
 * Initialize the barcode decoder.
 */
private void initBarcodeReader(List<String> barCodeTypes) {
    EnumMap<DecodeHintType, Object> hints = new EnumMap<>(DecodeHintType.class);
    EnumSet<BarcodeFormat> decodeFormats = EnumSet.noneOf(BarcodeFormat.class);

    if (barCodeTypes != null) {
        for (String code : barCodeTypes) {
            BarcodeFormat format = parseBarCodeString(code);
            if (format != null) {
                decodeFormats.add(format);
            }
        }
    }

    hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);
    _multiFormatReader.setHints(hints);
}
 
開發者ID:jonathan68,項目名稱:react-native-camera,代碼行數:20,代碼來源:RCTCameraViewFinder.java

示例7: parseExecOutput

import java.util.EnumMap; //導入方法依賴的package包/類
private static EnumMap<SysProp, String> parseExecOutput(String probeResult) {
    String[] split = probeResult.split(System.getProperty("line.separator"));
    if (split.length != SysProp.values().length - 1) { // -1 because of Z_ERROR
        return error("Unexpected command output: \n" + probeResult);
    }
    EnumMap<SysProp, String> result = new EnumMap<SysProp, String>(SysProp.class);
    for (SysProp type : SysProp.values()) {
        if (type != SysProp.Z_ERROR) {
            result.put(type, split[type.ordinal()]);
        }
    }
    return result;
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:14,代碼來源:JavaInstallationProbe.java

示例8: getLTSLabels

import java.util.EnumMap; //導入方法依賴的package包/類
/** Returns the LTS labelling specification. */
public LTSLabels getLTSLabels() {
    EnumMap<Flag,String> flags = new EnumMap<>(Flag.class);
    for (Flag flag : Flag.values()) {
        if (getFlagCheckBox(flag).isSelected()) {
            flags.put(flag, getFlagTextField(flag).getText());
        }
    }
    return new LTSLabels(flags);
}
 
開發者ID:meteoorkip,項目名稱:JavaGraph,代碼行數:11,代碼來源:SaveLTSAsDialog.java

示例9: create

import java.util.EnumMap; //導入方法依賴的package包/類
/**
 * Create and return your Image here.
 * NOTE: make sure, your class is public and has a public default constructor!
 *
 * @param tag    The dialog-fragments tag
 * @param extras The extras supplied to {@link SimpleImageDialog#extra(Bundle)}
 * @return the image to be shown
 */
@Override
public Bitmap create(@Nullable String tag, @NonNull Bundle extras) {
    String content = extras.getString(QR_CONTENT);
    if (content == null) return null;

    // Generate
    try {
        EnumMap<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
        hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.Q);
        hints.put(EncodeHintType.CHARACTER_SET, "UTF8");
        BitMatrix bitMatrix = new QRCodeWriter().encode(content, BarcodeFormat.QR_CODE,
                1024, 1024, hints);
        int width = bitMatrix.getWidth(), height = bitMatrix.getHeight();
        int[] pixels = new int[width * height];
        for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
                pixels[y*width + x] = bitMatrix.get(x, y) ? Color.BLACK : Color.WHITE;
            }
        }
        Bitmap qr = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
        qr.setPixels(pixels, 0, width, 0, 0, width, height);
        return qr;

    } catch (WriterException ignored) {}

    return null;
}
 
開發者ID:eltos,項目名稱:SimpleDialogFragments,代碼行數:36,代碼來源:MainActivity.java

示例10: applyComboBuff

import java.util.EnumMap; //導入方法依賴的package包/類
public final void applyComboBuff(MapleCharacter applyto, short combo) {
    EnumMap<CharacterTemporaryStat, Integer> stat = new EnumMap<CharacterTemporaryStat, Integer>(CharacterTemporaryStat.class);
    stat.put(CharacterTemporaryStat.ComboAbilityBuff, (int) combo);
    applyto.getClient().getSession().write(CWvsContext.BuffPacket.giveBuff(this.sourceid, 99999, stat, this));

    long starttime = System.currentTimeMillis();

    applyto.registerEffect(this, starttime, null, applyto.getId());
}
 
開發者ID:ergothvs,項目名稱:Lucid2.0,代碼行數:10,代碼來源:MapleStatEffect.java

示例11: handleOrbconsume

import java.util.EnumMap; //導入方法依賴的package包/類
public void handleOrbconsume(int howmany) {
    Skill normalcombo;

    switch (getJob()) {
        case 1110:
        case 1111:
        case 1112:
            normalcombo = SkillFactory.getSkill(11111001);
            break;
        default:
            normalcombo = SkillFactory.getSkill(1111002);
            break;
    }
    if (getSkillLevel(normalcombo) <= 0) {
        return;
    }
    MapleStatEffect ceffect = getStatForBuff(CharacterTemporaryStat.ComboCounter);
    if (ceffect == null) {
        return;
    }
    EnumMap<CharacterTemporaryStat, Integer> stat = new EnumMap<>(CharacterTemporaryStat.class);
    stat.put(CharacterTemporaryStat.ComboCounter, Math.max(1, getBuffedValue(CharacterTemporaryStat.ComboCounter) - howmany));
    setBuffedValue(CharacterTemporaryStat.ComboCounter, Math.max(1, getBuffedValue(CharacterTemporaryStat.ComboCounter) - howmany));
    int duration = ceffect.getDuration();
    duration += (int) ((getBuffedStarttime(CharacterTemporaryStat.ComboCounter) - System.currentTimeMillis()));

    client.getSession().write(BuffPacket.giveBuff(normalcombo.getId(), duration, stat, ceffect));
    map.broadcastMessage(this, BuffPacket.giveForeignBuff(getId(), stat, ceffect), false);
}
 
開發者ID:ergothvs,項目名稱:Lucid2.0,代碼行數:30,代碼來源:MapleCharacter.java

示例12: create

import java.util.EnumMap; //導入方法依賴的package包/類
@Override
protected Map<AnEnum, String> create(Entry<AnEnum, String>[] entries) {
  EnumMap<AnEnum, String> map = new EnumMap<AnEnum, String>(AnEnum.class);
  for (Entry<AnEnum, String> entry : entries) {
    map.put(entry.getKey(), entry.getValue());
  }
  return ImmutableMap.copyOf(map);
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:9,代碼來源:MapGenerators.java

示例13: addBuffStatPairToListIfNotZero

import java.util.EnumMap; //導入方法依賴的package包/類
private static void addBuffStatPairToListIfNotZero(final EnumMap<CharacterTemporaryStat, Integer> list, final CharacterTemporaryStat buffstat, final Integer val) {
    if (val != 0) {
        list.put(buffstat, val);
    }
}
 
開發者ID:ergothvs,項目名稱:Lucid2.0,代碼行數:6,代碼來源:MapleStatEffect.java

示例14: testEnumMap

import java.util.EnumMap; //導入方法依賴的package包/類
public void testEnumMap() {
  EnumMap<SomeEnum, Integer> map = Maps.newEnumMap(SomeEnum.class);
  assertEquals(Collections.emptyMap(), map);
  map.put(SomeEnum.SOME_INSTANCE, 0);
  assertEquals(Collections.singletonMap(SomeEnum.SOME_INSTANCE, 0), map);
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:7,代碼來源:MapsTest.java

示例15: testEnumMapWithInitialEnumMap

import java.util.EnumMap; //導入方法依賴的package包/類
public void testEnumMapWithInitialEnumMap() {
  EnumMap<SomeEnum, Integer> original = Maps.newEnumMap(SomeEnum.class);
  original.put(SomeEnum.SOME_INSTANCE, 0);
  EnumMap<SomeEnum, Integer> copy = Maps.newEnumMap(original);
  assertEquals(original, copy);
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:7,代碼來源:MapsTest.java


注:本文中的java.util.EnumMap.put方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。