Example usage for com.google.common.collect Maps newEnumMap

List of usage examples for com.google.common.collect Maps newEnumMap

Introduction

In this page you can find the example usage for com.google.common.collect Maps newEnumMap.

Prototype

public static <K extends Enum<K>, V> EnumMap<K, V> newEnumMap(Map<K, ? extends V> map) 

Source Link

Document

Creates an EnumMap with the same mappings as the specified map.

Usage

From source file:javastory.channel.life.MobSkill.java

public void applyEffect(final ChannelCharacter player, final Monster monster, final boolean skill) {
    Disease disease = null;//from   w  w  w .  j  av  a 2  s.  c o m
    final Map<MonsterStatus, Integer> stats = Maps.newEnumMap(MonsterStatus.class);
    final List<Integer> reflection = Lists.newLinkedList();

    switch (this.skillId) {
    case 100:
    case 110:
        stats.put(MonsterStatus.WEAPON_ATTACK_UP, Integer.valueOf(this.x));
        break;
    case 101:
    case 111:
        stats.put(MonsterStatus.MAGIC_ATTACK_UP, Integer.valueOf(this.x));
        break;
    case 102:
    case 112:
        stats.put(MonsterStatus.WEAPON_DEFENSE_UP, Integer.valueOf(this.x));
        break;
    case 103:
    case 113:
        stats.put(MonsterStatus.MAGIC_DEFENSE_UP, Integer.valueOf(this.x));
        break;
    case 114:
        if (this.lt != null && this.rb != null && skill) {
            final List<GameMapObject> objects = this.getObjectsInRange(monster, GameMapObjectType.MONSTER);
            final int hp = this.getX() / 1000 * (int) (950 + 1050 * Math.random());
            for (final GameMapObject mons : objects) {
                ((Monster) mons).heal(hp, this.getY(), true);
            }
        } else {
            monster.heal(this.getX(), this.getY(), true);
        }
        break;
    case 120:
        disease = Disease.SEAL;
        break;
    case 121:
        disease = Disease.DARKNESS;
        break;
    case 122:
        disease = Disease.WEAKEN;
        break;
    case 123:
        disease = Disease.STUN;
        break;
    case 124:
        disease = Disease.CURSE;
        break;
    case 125:
        disease = Disease.POISON;
        break;
    case 126: // Slow
        disease = Disease.SLOW;
        break;
    case 127:
        if (this.lt != null && this.rb != null && skill) {
            for (final ChannelCharacter character : this.getPlayersInRange(monster, player)) {
                character.dispel();
            }
        } else {
            player.dispel();
        }
        break;
    case 128: // Seduce
        disease = Disease.SEDUCE;
        break;
    case 129: // Banish
        final BanishInfo info = monster.getStats().getBanishInfo();
        if (this.lt != null && this.rb != null && skill) {
            for (final ChannelCharacter chr : this.getPlayersInRange(monster, player)) {
                chr.changeMapBanish(info.Map, info.Portal, info.Message);
            }
        } else {
            player.changeMapBanish(info.Map, info.Portal, info.Message);
        }
        break;
    case 131: // Mist
        monster.getMap().spawnMist(
                new Mist(this.calculateBoundingBox(monster.getPosition(), true), monster, this), this.x * 10,
                false, false);
        break;
    case 132:
        disease = Disease.REVERSE_DIRECTION;
        break;
    case 133:
        disease = Disease.ZOMBIFY;
        break;
    case 140:
        if (this.makeChanceResult()) {
            stats.put(MonsterStatus.WEAPON_IMMUNITY, Integer.valueOf(this.x));
        }
        break;
    case 141:
        if (this.makeChanceResult()) {
            stats.put(MonsterStatus.MAGIC_IMMUNITY, Integer.valueOf(this.x));
        }
        break;
    case 143: // Weapon Reflect
        stats.put(MonsterStatus.WEAPON_DAMAGE_REFLECT, Integer.valueOf(this.x));
        stats.put(MonsterStatus.WEAPON_IMMUNITY, Integer.valueOf(this.x));
        reflection.add(this.x);
        break;
    case 144: // Magic Reflect
        stats.put(MonsterStatus.MAGIC_DAMAGE_REFLECT, Integer.valueOf(this.x));
        stats.put(MonsterStatus.MAGIC_IMMUNITY, Integer.valueOf(this.x));
        reflection.add(this.x);
        break;
    case 145: // Weapon / Magic reflect
        stats.put(MonsterStatus.WEAPON_DAMAGE_REFLECT, Integer.valueOf(this.x));
        stats.put(MonsterStatus.WEAPON_IMMUNITY, Integer.valueOf(this.x));
        stats.put(MonsterStatus.MAGIC_DAMAGE_REFLECT, Integer.valueOf(this.x));
        stats.put(MonsterStatus.MAGIC_IMMUNITY, Integer.valueOf(this.x));
        reflection.add(this.x);
        reflection.add(this.x);
        break;
    case 200:
        for (final Integer mobId : this.getSummons()) {
            final Monster toSpawn = LifeFactory.getMonster(mobId);
            toSpawn.setPosition(monster.getPosition());
            int ypos = (int) monster.getPosition().getY(), xpos = (int) monster.getPosition().getX();

            switch (mobId) {
            case 8500003: // Pap bomb high
                toSpawn.setFoothold((int) Math.ceil(Math.random() * 19.0));
                ypos = -590;
                break;
            case 8500004: // Pap bomb
                // Spawn between -500 and 500 from the monsters X position
                xpos = (int) (monster.getPosition().getX() + Math.ceil(Math.random() * 1000.0) - 500);
                ypos = (int) monster.getPosition().getY();
                break;
            case 8510100: // Pianus bomb
                if (Math.ceil(Math.random() * 5) == 1) {
                    ypos = 78;
                    xpos = (int) (0 + Math.ceil(Math.random() * 5))
                            + (Math.ceil(Math.random() * 2) == 1 ? 180 : 0);
                } else {
                    xpos = (int) (monster.getPosition().getX() + Math.ceil(Math.random() * 1000.0) - 500);
                }
                break;
            }
            // Get spawn coordinates (This fixes monster lock)
            // TODO get map left and right wall.
            switch (monster.getMap().getId()) {
            case 220080001: // Pap map
                if (xpos < -890) {
                    xpos = (int) (-890 + Math.ceil(Math.random() * 150));
                } else if (xpos > 230) {
                    xpos = (int) (230 - Math.ceil(Math.random() * 150));
                }
                break;
            case 230040420: // Pianus map
                if (xpos < -239) {
                    xpos = (int) (-239 + Math.ceil(Math.random() * 150));
                } else if (xpos > 371) {
                    xpos = (int) (371 - Math.ceil(Math.random() * 150));
                }
                break;
            }
            monster.getMap().spawnMonsterWithEffect(toSpawn, this.getSpawnEffect(),
                    monster.getMap().calcPointBelow(new Point(xpos, ypos - 1)));
        }
        break;
    }

    if (stats.size() > 0) {
        if (this.lt != null && this.rb != null && skill) {
            for (final GameMapObject mons : this.getObjectsInRange(monster, GameMapObjectType.MONSTER)) {
                ((Monster) mons).applyMonsterBuff(stats, this.getX(), this.getSkillId(), this.getDuration(),
                        this, reflection);
            }
        } else {
            monster.applyMonsterBuff(stats, this.getX(), this.getSkillId(), this.getDuration(), this,
                    reflection);
        }
    }
    if (disease != null) {
        if (this.lt != null && this.rb != null && skill) {
            for (final ChannelCharacter chr : this.getPlayersInRange(monster, player)) {
                chr.giveDebuff(disease, this);
            }
        } else {
            player.giveDebuff(disease, this);
        }
    }
    monster.setMp(monster.getMp() - this.getMpCon());
}

From source file:com.vmware.photon.controller.apife.clients.StatusFeClient.java

/**
 * Creating StatusFeClient with component server sets to iterate through individual servers to get their status.
 *
 * @param housekeeperServerSet/* w w w.j  a  v  a 2  s  .com*/
 * @param rootSchedulerServerSet
 * @param deployerServerSet
 * @param houseKeeperProxyFactory
 * @param houseKeeperPoolFactory
 * @param rootSchedulerProxyFactory
 * @param rootSchedulerPoolFactory
 * @param deployerProxyFactory
 * @param deployerPoolFactory
 * @param statusConfig
 */
@Inject
public StatusFeClient(@BackendTaskExecutor ExecutorService executor,
        @HousekeeperServerSet ServerSet housekeeperServerSet,
        @RootSchedulerServerSet ServerSet rootSchedulerServerSet,
        @DeployerServerSet ServerSet deployerServerSet, @CloudStoreServerSet ServerSet cloudStoreServerSet,
        ClientProxyFactory<Housekeeper.AsyncClient> houseKeeperProxyFactory,
        ClientPoolFactory<Housekeeper.AsyncClient> houseKeeperPoolFactory,
        ClientProxyFactory<RootScheduler.AsyncClient> rootSchedulerProxyFactory,
        ClientPoolFactory<RootScheduler.AsyncClient> rootSchedulerPoolFactory,
        ClientProxyFactory<Deployer.AsyncClient> deployerProxyFactory,
        ClientPoolFactory<Deployer.AsyncClient> deployerPoolFactory, StatusConfig statusConfig) {
    this.executor = executor;
    this.components = statusConfig.getComponents();

    statusProviderFactories = Maps.newEnumMap(Component.class);
    statusProviderFactories.put(Component.HOUSEKEEPER, new ThriftClientFactory(housekeeperServerSet,
            houseKeeperPoolFactory, houseKeeperProxyFactory, HousekeeperClient.class, "Housekeeper"));
    statusProviderFactories.put(Component.ROOT_SCHEDULER, new ThriftClientFactory(rootSchedulerServerSet,
            rootSchedulerPoolFactory, rootSchedulerProxyFactory, RootSchedulerClient.class, "RootScheduler"));
    statusProviderFactories.put(Component.DEPLOYER, new ThriftClientFactory(deployerServerSet,
            deployerPoolFactory, deployerProxyFactory, DeployerClient.class, "Deployer"));
    statusProviderFactories.put(Component.CLOUD_STORE,
            new DcpStatusProviderFactory(cloudStoreServerSet, this.executor));
}

From source file:com.torodb.torod.db.backends.greenplum.converters.array.GreenplumValueToArrayConverterProvider.java

private GreenplumValueToArrayConverterProvider() {
    arrayConverter = new ArrayToArrayConverter(this);
    booleanConverter = new BooleanToArrayConverter();
    dateConverter = new DateToArrayConverter();
    dateTimeConverter = new InstantToArrayConverter();
    doubleConverter = new DoubleToArrayConverter();
    integerConverter = new IntegerToArrayConverter();
    longConverter = new LongToArrayConverter();
    nullConverter = new NullToArrayConverter();
    stringConverter = new StringToArrayConverter();
    timeConverter = new TimeToArrayConverter();
    mongoObjectIdConverter = new MongoObjectIdToArrayConverter();
    mongoTimestampConverter = new MongoTimestampToArrayConverter();
    binaryConverter = new BinaryToArrayConverter();

    converters = Maps.newEnumMap(ScalarType.class);
    converters.put(ScalarType.ARRAY, arrayConverter);
    converters.put(ScalarType.BOOLEAN, booleanConverter);
    converters.put(ScalarType.DATE, dateConverter);
    converters.put(ScalarType.INSTANT, dateTimeConverter);
    converters.put(ScalarType.DOUBLE, doubleConverter);
    converters.put(ScalarType.INTEGER, integerConverter);
    converters.put(ScalarType.LONG, longConverter);
    converters.put(ScalarType.NULL, nullConverter);
    converters.put(ScalarType.STRING, stringConverter);
    converters.put(ScalarType.TIME, timeConverter);
    converters.put(ScalarType.MONGO_OBJECT_ID, mongoObjectIdConverter);
    converters.put(ScalarType.MONGO_TIMESTAMP, mongoTimestampConverter);
    converters.put(ScalarType.BINARY, binaryConverter);

}

From source file:com.torodb.torod.db.backends.postgresql.converters.array.PostgreSQLValueToArrayConverterProvider.java

private PostgreSQLValueToArrayConverterProvider() {
    arrayConverter = new ArrayToArrayConverter(this);
    booleanConverter = new BooleanToArrayConverter();
    dateConverter = new DateToArrayConverter();
    dateTimeConverter = new InstantToArrayConverter();
    doubleConverter = new DoubleToArrayConverter();
    integerConverter = new IntegerToArrayConverter();
    longConverter = new LongToArrayConverter();
    nullConverter = new NullToArrayConverter();
    stringConverter = new StringToArrayConverter();
    timeConverter = new TimeToArrayConverter();
    mongoObjectIdConverter = new MongoObjectIdToArrayConverter();
    mongoTimestampConverter = new MongoTimestampToArrayConverter();
    binaryConverter = new BinaryToArrayConverter();

    converters = Maps.newEnumMap(ScalarType.class);
    converters.put(ScalarType.ARRAY, arrayConverter);
    converters.put(ScalarType.BOOLEAN, booleanConverter);
    converters.put(ScalarType.DATE, dateConverter);
    converters.put(ScalarType.INSTANT, dateTimeConverter);
    converters.put(ScalarType.DOUBLE, doubleConverter);
    converters.put(ScalarType.INTEGER, integerConverter);
    converters.put(ScalarType.LONG, longConverter);
    converters.put(ScalarType.NULL, nullConverter);
    converters.put(ScalarType.STRING, stringConverter);
    converters.put(ScalarType.TIME, timeConverter);
    converters.put(ScalarType.MONGO_OBJECT_ID, mongoObjectIdConverter);
    converters.put(ScalarType.MONGO_TIMESTAMP, mongoTimestampConverter);
    converters.put(ScalarType.BINARY, binaryConverter);

}

From source file:com.google.cloud.translate.TranslateImpl.java

private Map<TranslateRpc.Option, ?> optionMap(Option... options) {
    Map<TranslateRpc.Option, Object> optionMap = Maps.newEnumMap(TranslateRpc.Option.class);
    for (Option option : options) {
        Object prev = optionMap.put(option.getRpcOption(), option.getValue());
        checkArgument(prev == null, "Duplicate option %s", option);
    }// ww w  . ja v a2  s .com
    return optionMap;
}

From source file:edu.udo.scaffoldhunter.view.scaffoldtree.config.MappingDialog.java

private JButton buildApplyButton() {
    return new JButton(new AbstractAction(_("Button.Apply")) {

        @Override//  ww  w . ja  v  a2 s  .c  o m
        public void actionPerformed(ActionEvent e) {
            setConfig();
            mappings = Maps.newEnumMap(VisualFeature.class);
            for (Map.Entry<VisualFeature, ConfigMapping> entry : config.getMappings().entrySet())
                mappings.put(entry.getKey(), (ConfigMapping) entry.getValue().copy());
        }
    });
}

From source file:org.kiji.schema.util.ToJson.java

/**
 * Encodes an Avro union into a JSON node.
 *
 * @param value an Avro union to encode.
 * @param schema schema of the union to encode.
 * @return the encoded value as a JSON node.
 * @throws IOException on error./*  w  w  w  .  ja va 2  s.c  o  m*/
 */
private static JsonNode toUnionJsonNode(Object value, Schema schema) throws IOException {
    Preconditions.checkArgument(schema.getType() == Schema.Type.UNION);

    final Schema optionalType = AvroUtils.getOptionalType(schema);
    if (null != optionalType) {
        return (null == value) ? JSON_NODE_FACTORY.nullNode() : toJsonNode(value, optionalType);
    }

    final Map<Schema.Type, List<Schema>> typeMap = Maps.newEnumMap(Schema.Type.class);
    for (Schema type : schema.getTypes()) {
        List<Schema> typeList = typeMap.get(type.getType());
        if (null == typeList) {
            typeList = Lists.newArrayList();
            typeMap.put(type.getType(), typeList);
        }
        typeList.add(type);
    }

    //  null is shortened as an immediate JSON null:
    if (null == value) {
        if (!typeMap.containsKey(Schema.Type.NULL)) {
            throw new IOException(String.format("Avro schema specifies '%s' but got 'null'.", schema));
        }
        return JSON_NODE_FACTORY.nullNode();
    }

    final ObjectNode union = JSON_NODE_FACTORY.objectNode();
    for (Schema type : schema.getTypes()) {
        try {
            final JsonNode actualNode = toJsonNode(value, type);
            union.put(type.getFullName(), actualNode);
            return union;
        } catch (IOException ioe) {
            // This type was not the correct union case, ignore...
        }
    }
    throw new IOException(String.format("Unable to encode '%s' as union '%s'.", value, schema));
}

From source file:de.sanandrew.mods.claysoldiers.item.ItemTurtleDoll.java

@Override
public void registerIcons(IIconRegister iconRegister) {
    Map<String, IIcon> names = Maps.newHashMap();
    this.icons = Maps.newEnumMap(EnumTurtleType.class);
    for (EnumTurtleType type : EnumTurtleType.VALUES) {
        if (type.itemData == null) {
            continue;
        }/*from ww w  .  j  a  va  2 s  .  c  o  m*/
        if (!names.containsKey(type.itemData.getValue0())) {
            names.put(type.itemData.getValue0(), iconRegister.registerIcon(type.itemData.getValue0()));
        }
        this.icons.put(type, names.get(type.itemData.getValue0()));
    }
    this.baseIcon = iconRegister.registerIcon(ClaySoldiersMod.MOD_ID + ":doll_turtle_base");
}

From source file:org.apache.hadoop.hdfs.server.namenode.AclTransformation.java

/**
 * Merges the entries of the ACL spec into the existing ACL.  If necessary,
 * recalculates the mask entries.  If necessary, default entries may be
 * inferred by copying the permissions of the corresponding access entries.
 *
 * @param existingAcl List<AclEntry> existing ACL
 * @param inAclSpec List<AclEntry> ACL spec containing entries to merge
 * @return List<AclEntry> new ACL/*from   w w  w  .  j  av a2 s  .  co m*/
 * @throws AclException if validation fails
 */
public static List<AclEntry> mergeAclEntries(List<AclEntry> existingAcl, List<AclEntry> inAclSpec)
        throws AclException {
    ValidatedAclSpec aclSpec = new ValidatedAclSpec(inAclSpec);
    ArrayList<AclEntry> aclBuilder = Lists.newArrayListWithCapacity(MAX_ENTRIES);
    List<AclEntry> foundAclSpecEntries = Lists.newArrayListWithCapacity(MAX_ENTRIES);
    EnumMap<AclEntryScope, AclEntry> providedMask = Maps.newEnumMap(AclEntryScope.class);
    EnumSet<AclEntryScope> maskDirty = EnumSet.noneOf(AclEntryScope.class);
    EnumSet<AclEntryScope> scopeDirty = EnumSet.noneOf(AclEntryScope.class);
    for (AclEntry existingEntry : existingAcl) {
        AclEntry aclSpecEntry = aclSpec.findByKey(existingEntry);
        if (aclSpecEntry != null) {
            foundAclSpecEntries.add(aclSpecEntry);
            scopeDirty.add(aclSpecEntry.getScope());
            if (aclSpecEntry.getType() == MASK) {
                providedMask.put(aclSpecEntry.getScope(), aclSpecEntry);
                maskDirty.add(aclSpecEntry.getScope());
            } else {
                aclBuilder.add(aclSpecEntry);
            }
        } else {
            if (existingEntry.getType() == MASK) {
                providedMask.put(existingEntry.getScope(), existingEntry);
            } else {
                aclBuilder.add(existingEntry);
            }
        }
    }
    // ACL spec entries that were not replacements are new additions.
    for (AclEntry newEntry : aclSpec) {
        if (Collections.binarySearch(foundAclSpecEntries, newEntry, ACL_ENTRY_COMPARATOR) < 0) {
            scopeDirty.add(newEntry.getScope());
            if (newEntry.getType() == MASK) {
                providedMask.put(newEntry.getScope(), newEntry);
                maskDirty.add(newEntry.getScope());
            } else {
                aclBuilder.add(newEntry);
            }
        }
    }
    copyDefaultsIfNeeded(aclBuilder);
    calculateMasks(aclBuilder, providedMask, maskDirty, scopeDirty);
    return buildAndValidateAcl(aclBuilder);
}

From source file:com.android.tools.lint.checks.ResourceCycleDetector.java

@Override
public void beforeCheckProject(@NonNull Context context) {
    // In incremental mode, or checking all files (full lint analysis) ? If the latter,
    // we should store state and look for deeper cycles
    if (context.getScope().contains(Scope.ALL_RESOURCE_FILES)) {
        mReferences = Maps.newEnumMap(ResourceType.class);
    }//w w w. j  a  v  a  2  s.  co  m
}