Example usage for java.lang Short MIN_VALUE

List of usage examples for java.lang Short MIN_VALUE

Introduction

In this page you can find the example usage for java.lang Short MIN_VALUE.

Prototype

short MIN_VALUE

To view the source code for java.lang Short MIN_VALUE.

Click Source Link

Document

A constant holding the minimum value a short can have, -215.

Usage

From source file:net.ymate.platform.commons.lang.TreeObject.java

/**
 * 
 *
 * @param s
 */
public TreeObject(Short s) {
    _object = s != null ? s.shortValue() : Short.MIN_VALUE;
    _type = TYPE_SHORT;
}

From source file:net.dv8tion.jda.core.audio.AudioConnection.java

private synchronized void setupCombinedExecutor() {
    if (combinedAudioExecutor == null) {
        combinedAudioExecutor = Executors.newSingleThreadScheduledExecutor(
                r -> new Thread(AudioManagerImpl.AUDIO_THREADS, r, threadIdentifier + " Combined Thread"));
        combinedAudioExecutor.scheduleAtFixedRate(() -> {
            try {
                List<User> users = new LinkedList<>();
                List<short[]> audioParts = new LinkedList<>();
                if (receiveHandler != null && receiveHandler.canReceiveCombined()) {
                    long currentTime = System.currentTimeMillis();
                    for (Map.Entry<User, Queue<Pair<Long, short[]>>> entry : combinedQueue.entrySet()) {
                        User user = entry.getKey();
                        Queue<Pair<Long, short[]>> queue = entry.getValue();

                        if (queue.isEmpty())
                            continue;

                        Pair<Long, short[]> audioData = queue.poll();
                        //Make sure the audio packet is younger than 100ms
                        while (audioData != null && currentTime - audioData.getLeft() > queueTimeout) {
                            audioData = queue.poll();
                        }/*w w w . j  a v  a 2s .c om*/

                        //If none of the audio packets were younger than 100ms, then there is nothing to add.
                        if (audioData == null) {
                            continue;
                        }
                        users.add(user);
                        audioParts.add(audioData.getRight());
                    }

                    if (!audioParts.isEmpty()) {
                        int audioLength = audioParts.get(0).length;
                        short[] mix = new short[1920]; //960 PCM samples for each channel
                        int sample;
                        for (int i = 0; i < audioLength; i++) {
                            sample = 0;
                            for (short[] audio : audioParts) {
                                sample += audio[i];
                            }
                            if (sample > Short.MAX_VALUE)
                                mix[i] = Short.MAX_VALUE;
                            else if (sample < Short.MIN_VALUE)
                                mix[i] = Short.MIN_VALUE;
                            else
                                mix[i] = (short) sample;
                        }
                        receiveHandler.handleCombinedAudio(new CombinedAudio(users, mix));
                    } else {
                        //No audio to mix, provide 20 MS of silence. (960 PCM samples for each channel)
                        receiveHandler.handleCombinedAudio(
                                new CombinedAudio(Collections.emptyList(), new short[1920]));
                    }
                }
            } catch (Exception e) {
                LOG.log(e);
            }
        }, 0, 20, TimeUnit.MILLISECONDS);
    }
}

From source file:org.apache.hive.hcatalog.pig.HCatBaseStorer.java

/**
 * Convert from Pig value object to Hive value object
 * This method assumes that {@link #validateSchema(org.apache.pig.impl.logicalLayer.schema.Schema.FieldSchema, org.apache.hive.hcatalog.data.schema.HCatFieldSchema, org.apache.pig.impl.logicalLayer.schema.Schema, org.apache.hive.hcatalog.data.schema.HCatSchema, int)}
 * which checks the types in Pig schema are compatible with target Hive table, has been called.
 *///from www.j av a 2s . c  o m
private Object getJavaObj(Object pigObj, HCatFieldSchema hcatFS) throws HCatException, BackendException {
    try {
        if (pigObj == null)
            return null;
        // The real work-horse. Spend time and energy in this method if there is
        // need to keep HCatStorer lean and go fast.
        Type type = hcatFS.getType();
        switch (type) {
        case BINARY:
            return ((DataByteArray) pigObj).get();

        case STRUCT:
            HCatSchema structSubSchema = hcatFS.getStructSubSchema();
            // Unwrap the tuple.
            List<Object> all = ((Tuple) pigObj).getAll();
            ArrayList<Object> converted = new ArrayList<Object>(all.size());
            for (int i = 0; i < all.size(); i++) {
                converted.add(getJavaObj(all.get(i), structSubSchema.get(i)));
            }
            return converted;

        case ARRAY:
            // Unwrap the bag.
            DataBag pigBag = (DataBag) pigObj;
            HCatFieldSchema tupFS = hcatFS.getArrayElementSchema().get(0);
            boolean needTuple = tupFS.getType() == Type.STRUCT;
            List<Object> bagContents = new ArrayList<Object>((int) pigBag.size());
            Iterator<Tuple> bagItr = pigBag.iterator();

            while (bagItr.hasNext()) {
                // If there is only one element in tuple contained in bag, we throw away the tuple.
                bagContents.add(getJavaObj(needTuple ? bagItr.next() : bagItr.next().get(0), tupFS));

            }
            return bagContents;
        case MAP:
            Map<?, ?> pigMap = (Map<?, ?>) pigObj;
            Map<Object, Object> typeMap = new HashMap<Object, Object>();
            for (Entry<?, ?> entry : pigMap.entrySet()) {
                // the value has a schema and not a FieldSchema
                typeMap.put(
                        // Schema validation enforces that the Key is a String
                        (String) entry.getKey(),
                        getJavaObj(entry.getValue(), hcatFS.getMapValueSchema().get(0)));
            }
            return typeMap;
        case STRING:
        case INT:
        case BIGINT:
        case FLOAT:
        case DOUBLE:
            return pigObj;
        case SMALLINT:
            if ((Integer) pigObj < Short.MIN_VALUE || (Integer) pigObj > Short.MAX_VALUE) {
                handleOutOfRangeValue(pigObj, hcatFS);
                return null;
            }
            return ((Integer) pigObj).shortValue();
        case TINYINT:
            if ((Integer) pigObj < Byte.MIN_VALUE || (Integer) pigObj > Byte.MAX_VALUE) {
                handleOutOfRangeValue(pigObj, hcatFS);
                return null;
            }
            return ((Integer) pigObj).byteValue();
        case BOOLEAN:
            if (pigObj instanceof String) {
                if (((String) pigObj).trim().compareTo("0") == 0) {
                    return Boolean.FALSE;
                }
                if (((String) pigObj).trim().compareTo("1") == 0) {
                    return Boolean.TRUE;
                }
                throw new BackendException("Unexpected type " + type + " for value " + pigObj + " of class "
                        + pigObj.getClass().getName(), PigHCatUtil.PIG_EXCEPTION_CODE);
            }
            return Boolean.parseBoolean(pigObj.toString());
        case DECIMAL:
            BigDecimal bd = (BigDecimal) pigObj;
            DecimalTypeInfo dti = (DecimalTypeInfo) hcatFS.getTypeInfo();
            if (bd.precision() > dti.precision() || bd.scale() > dti.scale()) {
                handleOutOfRangeValue(pigObj, hcatFS);
                return null;
            }
            return HiveDecimal.create(bd);
        case CHAR:
            String charVal = (String) pigObj;
            CharTypeInfo cti = (CharTypeInfo) hcatFS.getTypeInfo();
            if (charVal.length() > cti.getLength()) {
                handleOutOfRangeValue(pigObj, hcatFS);
                return null;
            }
            return new HiveChar(charVal, cti.getLength());
        case VARCHAR:
            String varcharVal = (String) pigObj;
            VarcharTypeInfo vti = (VarcharTypeInfo) hcatFS.getTypeInfo();
            if (varcharVal.length() > vti.getLength()) {
                handleOutOfRangeValue(pigObj, hcatFS);
                return null;
            }
            return new HiveVarchar(varcharVal, vti.getLength());
        case TIMESTAMP:
            DateTime dt = (DateTime) pigObj;
            return new Timestamp(dt.getMillis());//getMillis() returns UTC time regardless of TZ
        case DATE:
            /**
             * We ignore any TZ setting on Pig value since java.sql.Date doesn't have it (in any
             * meaningful way).  So the assumption is that if Pig value has 0 time component (midnight)
             * we assume it reasonably 'fits' into a Hive DATE.  If time part is not 0, it's considered
             * out of range for target type.
             */
            DateTime dateTime = ((DateTime) pigObj);
            if (dateTime.getMillisOfDay() != 0) {
                handleOutOfRangeValue(pigObj, hcatFS,
                        "Time component must be 0 (midnight) in local timezone; Local TZ val='" + pigObj + "'");
                return null;
            }
            /*java.sql.Date is a poorly defined API.  Some (all?) SerDes call toString() on it
            [e.g. LazySimpleSerDe, uses LazyUtils.writePrimitiveUTF8()],  which automatically adjusts
              for local timezone.  Date.valueOf() also uses local timezone (as does Date(int,int,int).
              Also see PigHCatUtil#extractPigObject() for corresponding read op.  This way a DATETIME from Pig,
              when stored into Hive and read back comes back with the same value.*/
            return new Date(dateTime.getYear() - 1900, dateTime.getMonthOfYear() - 1, dateTime.getDayOfMonth());
        default:
            throw new BackendException("Unexpected HCat type " + type + " for value " + pigObj + " of class "
                    + pigObj.getClass().getName(), PigHCatUtil.PIG_EXCEPTION_CODE);
        }
    } catch (BackendException e) {
        // provide the path to the field in the error message
        throw new BackendException((hcatFS.getName() == null ? " " : hcatFS.getName() + ".") + e.getMessage(),
                e);
    }
}

From source file:wa.was.blastradius.managers.TNTEffectsManager.java

public void loadEffect(File effectFile) {

    if (!(effectFile.exists())) {
        return;// w ww.j a v a2s. co m
    }

    YamlConfiguration effect = new YamlConfiguration();
    Map<String, Object> effectInfo = new HashMap<String, Object>();

    try {

        effect.load(effectFile);

        String effectName = effect.getString("effect-name", "DEFAULT").toUpperCase();

        effectInfo.put("type", effectName);
        effectInfo.put("fuseTicks", effect.getInt("fuse-ticks", 80));
        effectInfo.put("vaultCost", effect.getDouble("cost", 10.0));

        if (Double.compare(effect.getDouble("worth", 10), 0.1) > 0) {
            effectInfo.put("vaultWorth", effect.getDouble("worth", 0.1));
        } else {
            Bukkit.getServer().getLogger().warning("Vault Worth cannot be less than 0.1. Vault cost entered: "
                    + effect.get("worth") + " for TNT Effect: " + effectName + ". Defaulting...");
            effectInfo.put("vaultWorth", 0.1);
        }

        int tTexture = effect.getInt("tnt-texture-value", 1);
        int dTexture = effect.getInt("detonator-texture-value", 1);

        short ntTexture = tTexture > Short.MAX_VALUE ? Short.MAX_VALUE
                : tTexture < Short.MIN_VALUE ? Short.MIN_VALUE : (short) tTexture;
        short ndTexture = dTexture > Short.MAX_VALUE ? Short.MAX_VALUE
                : dTexture < Short.MIN_VALUE ? Short.MIN_VALUE : (short) dTexture;

        effectInfo.put("explosiveTexture", ntTexture);
        effectInfo.put("detonatorTexture", ndTexture);

        effectInfo.put("remoteDetonation", effect.getBoolean("remote-detonation", false));

        if (Material.valueOf(effect.getString("remote-detonator-material", "STONE_BUTTON")) != null) {
            effectInfo.put("remoteDetonator",
                    Material.valueOf(effect.getString("remote-detonator-material", "STONE_BUTTON")));
        } else {
            Bukkit.getServer().getLogger()
                    .warning("Remote Detonator Material Invalid: " + effect.get("remote-detonator-material")
                            + " for TNT Effect: " + effectName + ". Defaulting...");
            effectInfo.put("remoteDetonator", Material.STONE_BUTTON);
        }

        effectInfo.put("displayName",
                ChatColor.translateAlternateColorCodes('&', effect.getString("display-name", "TNT")));
        String detonatorName = effect.getString("display-name", "TNT") + " "
                + effect.getString("remote-detonator-tag", "&6Detonator");
        effectInfo.put("remoteDetonatorName", ChatColor.translateAlternateColorCodes('&', detonatorName));

        remoteDetonators.put(ChatColor.translateAlternateColorCodes('&', detonatorName), effectName);

        if (Sound.valueOf(effect.getString("detonator-effect", "BLOCK_NOTE_PLING")) != null) {
            effectInfo.put("detonatorEffect",
                    Sound.valueOf(effect.getString("detonator-effect", "BLOCK_NOTE_PLING")));
        } else {
            Bukkit.getServer().getLogger().warning("Detonator Effect Invalid: " + effect.get("detonator-effect")
                    + " for TNT Effect: " + effectName + ". Defaulting...");
            effectInfo.put("detonatorEffect", Sound.BLOCK_NOTE_PLING);
        }

        double effectDetonatorPitch = effect.getDouble("detonaor-effect-pitch", 1.5);

        if (Double.compare(effectDetonatorPitch, 2.0) > 0) {
            Bukkit.getServer().getLogger().warning("Detonator Effect Pitch is too high: " + effectDetonatorPitch
                    + " for TNT Effect: " + effectName + ". Defaulting...");
            effectInfo.put("detonatorEffectPitch", (float) 1.0);
        } else if (Double.compare(effectDetonatorPitch, 0.5) < 0) {
            Bukkit.getServer().getLogger().warning("Detonator Effect Pitch is too low: " + effectDetonatorPitch
                    + " for TNT Effect: " + effectName + ". Defaulting...");
            effectInfo.put("detonatorEffectPitch", (float) 1.5);
        } else {
            effectInfo.put("detonatorEffectPitch", (float) effectDetonatorPitch);
        }

        double effectDetonatorVolume = effect.getDouble("detonator-effect-volume", 1.0);

        if (Double.compare(effectDetonatorVolume, 12.0) > 0) {
            Bukkit.getServer().getLogger().warning("Detonator Effect Volume is too high: "
                    + effectDetonatorVolume + " for TNT Effect: " + effectName + ". Defaulting...");
            effectInfo.put("detontorEffectVolume", (float) 1.0);
        } else if (Double.compare(effectDetonatorVolume, 0.5) < 0) {
            Bukkit.getServer().getLogger().warning("Detonator Effect Volume is too high: "
                    + effectDetonatorVolume + " for TNT Effect: " + effectName + ". Defaulting...");
            effectInfo.put("detonatorEffectVolume", (float) 1.0);
        } else {
            effectInfo.put("detonatorEffectVolume", (float) effectDetonatorVolume);
        }

        effectInfo.put("tntReceivable", effect.getBoolean("tnt-receivable", true));

        displayNames.put(ChatColor.translateAlternateColorCodes('&', (String) effectInfo.get("displayName")),
                effectName);
        List<String> effectLore = effect.getStringList("lore");
        List<String> lores = new ArrayList<String>();

        if (effectLore.size() > 0) {
            for (String line : effectLore) {
                lores.add(ChatColor.translateAlternateColorCodes('&', line));
            }
            effectInfo.put("lore", lores);
        }

        if (Sound.valueOf(effect.getString("fuse-effect", "ENTITY_TNT_PRIMED")) != null) {
            effectInfo.put("fuseEffect", Sound.valueOf(effect.getString("fuse-effect", "ENTITY_TNT_PRIMED")));
        } else {
            Bukkit.getServer().getLogger().warning("Fuse Effect Invalid: " + effect.get("fuse-effect")
                    + " for TNT Effect: " + effectName + ". Defaulting...");
            effectInfo.put("fuseEffect", Sound.ENTITY_TNT_PRIMED);
        }

        double effectPitch = effect.getDouble("fuse-effect-pitch", 1.0);

        if (Double.compare(effectPitch, 2.0) > 0) {
            Bukkit.getServer().getLogger().warning("Fuse Effect Pitch is too high: " + effectPitch
                    + " for TNT Effect: " + effectName + ". Defaulting...");
            effectInfo.put("fuseEffectPitch", (float) 1.0);
        } else if (Double.compare(effectPitch, 0.5) < 0) {
            Bukkit.getServer().getLogger().warning("Fuse Effect Pitch is too low: " + effectPitch
                    + " for TNT Effect: " + effectName + ". Defaulting...");
            effectInfo.put("fuseEffectPitch", (float) 1.0);
        } else {
            effectInfo.put("fuseEffectPitch", (float) effectPitch);
        }

        double effectVolume = effect.getDouble("fuse-effect-volume", 1.0);

        if (Double.compare(effectVolume, 12.0) > 0) {
            Bukkit.getServer().getLogger().warning("Fuse Effect Volume is too high: " + effectVolume
                    + " for TNT Effect: " + effectName + ". Defaulting...");
            effectInfo.put("fuseEffectVolume", (float) 1.0);
        } else if (Double.compare(effectVolume, 0.5) < 0) {
            Bukkit.getServer().getLogger().warning("Fuse Effect Volume is too high: " + effectVolume
                    + " for TNT Effect: " + effectName + ". Defaulting...");
            effectInfo.put("fuseEffectVolume", (float) 1.0);
        } else {
            effectInfo.put("fuseEffectVolume", (float) effectVolume);
        }

        double explosionVolume = effect.getDouble("sound-explosion-volume", 2);

        if (Double.compare(explosionVolume, 12.0) > 0) {
            Bukkit.getServer().getLogger().warning("Sound Explosion volume is too high: " + explosionVolume
                    + " for TNT Effect: " + effectName + ". Defaulting...");
            effectInfo.put("explosionVolume", (float) 2);
        } else {
            effectInfo.put("explosionVolume", (float) explosionVolume);
        }

        effectInfo.put("tamperProof", effect.getBoolean("tamper-proof", false));
        effectInfo.put("doWaterDamage", effect.getBoolean("tnt-water-damage", false));
        effectInfo.put("doFires", effect.getBoolean("blast-fires", true));
        effectInfo.put("doSmoke", effect.getBoolean("blast-smoke", false));
        effectInfo.put("obliterate", effect.getBoolean("obliterate-obliterables", false));
        effectInfo.put("ellipsis", effect.getBoolean("elliptical-radius", true));

        if (Double.compare(effect.getDouble("blast-yield-multiplier", 1F), 20.0) < 0) {
            effectInfo.put("yieldMultiplier", (float) effect.getDouble("blast-yield-multiplier", 1F));
        } else {
            Bukkit.getServer().getLogger()
                    .warning("Blast Multiplier out of Range: " + effect.get("blast-yield-multiplier")
                            + " for TNT Effect: " + effectName + ". Defaulting...");
            effectInfo.put("yieldMultiplier", (float) 1F);
        }

        if (effect.getInt("blast-radius", 10) <= 50) {
            effectInfo.put("blastRadius", effect.getInt("blast-radius", 10));
        } else {
            Bukkit.getServer().getLogger().warning("Dead Zone out of Range: " + effect.get("blast-radius")
                    + " for TNT Effect: " + effectName + ". Defaulting...");
            effectInfo.put("blastRadius", (int) 10);
        }

        if (effect.getInt("fire-radius", 9) <= 50) {
            effectInfo.put("fireRadius", effect.getInt("fire-radius", 9));
        } else {
            Bukkit.getServer().getLogger().warning("Fire Radius out of Range: " + effect.get("fire-radius")
                    + " for TNT Effect: " + effectName + ". Defaulting...");
            effectInfo.put("fireRadius", (int) 9);
        }

        if (effect.getInt("smoke-count", 10) <= 100) {
            effectInfo.put("smokeCount", effect.getInt("smoke-count", 10));
        } else {
            Bukkit.getServer().getLogger().warning("Smoke Count out of Range: " + effect.get("smoke-count")
                    + " for TNT Effect: " + effectName + ". Defaulting...");
            effectInfo.put("smokeCount", (int) 10);
        }

        if (Double.compare(effect.getDouble("smoke-offset", 0.25), 10) < 0) {
            effectInfo.put("smokeOffset", effect.getDouble("smoke-offset", 0.25));
        } else {
            Bukkit.getServer().getLogger().warning("Smoke Offset out of Range: " + effect.get("smoke-offset")
                    + " for TNT Effect: " + effectName + ". Defaulting...");
            effectInfo.put("smokeOffset", (double) 0.25);
        }

        effectInfo.put("tntTossable", effect.getBoolean("tnt-tossable", false));

        if (effect.getInt("tnt-tossable-height", 3) < 256) {
            effectInfo.put("tossHeightGain", effect.getInt("tnt-tossed-height", 3));
        } else {
            Bukkit.getServer().getLogger().warning("TNT Tossable Height gain out of Range: "
                    + effect.get("tnt-tossable-height") + " for TNT Effect: " + effectName + ". Defaulting...");
            effectInfo.put("tossHeightGain", (int) 3);
        }

        if (Double.compare(effect.getDouble("tnt-tossable-force", 1.5), 5.0) < 0) {
            effectInfo.put("tossForce", effect.getDouble("tnt-tossable-force", 1.5));
        } else {
            Bukkit.getServer().getLogger().warning("TNT Force to Strong. Forced used: "
                    + effect.get("tnt-tossable-force") + " for TNT Effect: " + effectName + ". Defaulting...");
            effectInfo.put("tossForce", (double) 1.5);
        }

        if (effect.getInt("tnt-tossable-cooldown", 10) < 1) {
            Bukkit.getServer().getLogger()
                    .warning("TNT Tossable Cooldown must be above 1. Value found: "
                            + effect.get("tnt-tossable-cooldown") + " for TNT Effect: " + effectName
                            + ". Defaulting...");
            effectInfo.put("tossCooldown", (int) 10);
        } else {
            effectInfo.put("tossCooldown", effect.getInt("tnt-tossable-cooldown", 10));
        }

        effectInfo.put("doCluster", effect.getBoolean("tnt-cluster-effect", false));
        if (effect.getInt("tnt-cluster-effect-amount", 3) > 10) {
            Bukkit.getServer().getLogger()
                    .warning("TNT Cluster Effect Amount must be between 1 - 10: "
                            + effect.get("tnt-cluster-effect-amount") + " for TNT Effect: " + effectName
                            + ". Defaulting...");
            effectInfo.put("clusterAmount", (int) 3);
        } else {
            effectInfo.put("clusterAmount", effect.getInt("tnt-cluster-effect-amount", 3));
        }

        effectInfo.put("clusterType", effect.getString("tnt-cluster-effect-type", "DEFAULT"));

        if (Double.compare(effect.getDouble("tnt-cluster-effect-height-offset", 10.0), 30.0) > 0) {
            Bukkit.getServer().getLogger()
                    .warning("TNT Cluster Effect Amount must be between 1 - 10: "
                            + effect.get("tnt-cluster-effect-amount") + " for TNT Effect: " + effectName
                            + ". Defaulting...");
            effectInfo.put("clusterOffset", (double) 10.0);
        } else {
            effectInfo.put("clusterOffset", effect.getDouble("tnt-cluster-effect-height-offset", 10.0));
        }

        effectInfo.put("doPotions", effect.getBoolean("potion-effect", true));
        effectInfo.put("consecPotions", effect.getBoolean("consecutive-potion-effects", false));
        effectInfo.put("showPotionMsg", effect.getBoolean("show-potion-message", true));
        effectInfo.put("potionMsg", effect.getString("potoin-message",
                "&1You have been &2effected &1with &c{TYPE} &1for &6{TIME} &rseconds"));

        List<PotionEffect> potionEffects = new ArrayList<PotionEffect>();
        List<String> messages = new ArrayList<String>();

        if (effect.getConfigurationSection("potion-effects").getKeys(false).size() > 0) {
            for (String type : effect.getConfigurationSection("potion-effects").getKeys(false)) {
                if (effectTypes
                        .containsKey(effect.getString("potion-effects." + type + ".type").toUpperCase())) {
                    if (effect.getString("potion-effects." + type + ".color") != null
                            && colors.containsKey(effect.getString("potion-effects." + type + ".color"))) {
                        potionEffects.add(new PotionEffect(
                                effectTypes.get(
                                        effect.getString("potion-effects." + type + ".type").toUpperCase()),
                                effect.getInt("potion-effects." + type + ".duration"),
                                effect.getInt("potion-effects." + type + ".amplifier"),
                                effect.getBoolean("potion-effects." + type + ".ambient"),
                                effect.getBoolean("potion-effects." + type + ".particles"),
                                colors.get(effect.getString("potion-effects." + type + ".color"))));
                    } else {
                        potionEffects.add(new PotionEffect(
                                effectTypes.get(
                                        effect.getString("potion-effects." + type + ".type").toUpperCase()),
                                effect.getInt("potion-effects." + type + ".duration"),
                                effect.getInt("potion-effects." + type + ".amplifier"),
                                effect.getBoolean("potion-effects." + type + ".ambient"),
                                effect.getBoolean("potion-effects." + type + ".particles")));
                    }
                    messages.add(effect
                            .getString("potion-message",
                                    "&1You have been &2effected &1with &c{TYPE} &1for &6{TIME} &rseconds")
                            .replace("{TYPE}",
                                    WordUtils.capitalize(
                                            effect.getString("potion-effects." + type + ".type").toLowerCase()))
                            .replace("{TIME}",
                                    "" + (effect.getInt("potion-effects." + type + ".duration") / 20)));
                }
            }
        }

        potionEffectsManager.addMessages(effectName, messages);
        potionEffectsManager.addAllEffects(effectName, potionEffects);

        List<Material> innerMaterials = new ArrayList<Material>();
        if (effect.getStringList("inner-blast-materials").size() > 0) {
            for (String mat : effect.getStringList("inner-blast-materials")) {
                if (Material.valueOf(mat) != null) {
                    innerMaterials.add(Material.valueOf(mat));
                } else {
                    Bukkit.getServer().getLogger().warning("[BlastRadius] Invalid Inner Material: " + mat
                            + " for TNT Effect: " + effectName + ". Skipping...");
                }
            }
        }

        effectInfo.put("innerMaterials", innerMaterials);

        List<Material> outerMaterials = new ArrayList<Material>();
        if (effect.getStringList("outer-blast-materials").size() > 0) {
            for (String mat : effect.getStringList("outer-blast-materials")) {
                if (Material.valueOf(mat) != null) {
                    outerMaterials.add(Material.valueOf(mat));
                } else {
                    Bukkit.getServer().getLogger().warning("[BlastRadius] Invalid Outer Material: " + mat
                            + " for TNT Effect: " + effectName + ". Skipping...");
                }
            }
        }

        effectInfo.put("outerMaterials", outerMaterials);

        List<Material> protectedMaterials = new ArrayList<Material>();
        if (effect.getStringList("protected-materials").size() > 0) {
            for (String mat : effect.getStringList("protected-materials")) {
                if (Material.valueOf(mat) != null) {
                    protectedMaterials.add(Material.valueOf(mat));
                } else {
                    Bukkit.getServer().getLogger().warning("[BlastRadius] Invalid Protected Material: " + mat
                            + " for TNT Effect: " + effectName + ". Skipping...");
                }
            }
        }

        effectInfo.put("protectedMaterials", protectedMaterials);

        List<Material> obliterateMaterials = new ArrayList<Material>();
        if (effect.getStringList("obliterate-materials").size() > 0) {
            for (String mat : effect.getStringList("obliterate-materials")) {
                if (Material.valueOf(mat) != null) {
                    obliterateMaterials.add(Material.valueOf(mat));
                } else {
                    Bukkit.getServer().getLogger().warning("[BlastRadius] Invalid Obliterate Material: " + mat
                            + " for TNT Effect: " + effectName + ". Skipping...");
                }
            }
        }

        effectInfo.put("obliterateMaterials", obliterateMaterials);

        Bukkit.getServer().getLogger().warning("[BlastRadius] Added BlastR Brand TNT Effect: "
                + ConsoleColor.YELLOW + ConsoleColor.BOLD + effectName + ConsoleColor.RESET);
        effects.put(effectName, effectInfo);

    } catch (IOException | InvalidConfigurationException e) {
        e.printStackTrace();
    }
}

From source file:net.sf.json.TestJSONObject.java

public void testFromBean_use_wrappers() {
    JSONObject json = JSONObject.fromObject(Boolean.TRUE);
    assertTrue(json.isEmpty());/*from  w  ww .  j av a 2 s  . c o  m*/
    json = JSONObject.fromObject(new Byte(Byte.MIN_VALUE));
    assertTrue(json.isEmpty());
    json = JSONObject.fromObject(new Short(Short.MIN_VALUE));
    assertTrue(json.isEmpty());
    json = JSONObject.fromObject(new Integer(Integer.MIN_VALUE));
    assertTrue(json.isEmpty());
    json = JSONObject.fromObject(new Long(Long.MIN_VALUE));
    assertTrue(json.isEmpty());
    json = JSONObject.fromObject(new Float(Float.MIN_VALUE));
    assertTrue(json.isEmpty());
    json = JSONObject.fromObject(new Double(Double.MIN_VALUE));
    assertTrue(json.isEmpty());
    json = JSONObject.fromObject(new Character('A'));
    assertTrue(json.isEmpty());
}

From source file:com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter.java

protected boolean isInRange(Number value, String stringValue, Class toType) {
    Number bigValue = null;// w  w w  .j a  va  2s  . co  m
    Number lowerBound = null;
    Number upperBound = null;

    try {
        if (double.class == toType || Double.class == toType) {
            bigValue = new BigDecimal(stringValue);
            // Double.MIN_VALUE is the smallest positive non-zero number
            lowerBound = BigDecimal.valueOf(Double.MAX_VALUE).negate();
            upperBound = BigDecimal.valueOf(Double.MAX_VALUE);
        } else if (float.class == toType || Float.class == toType) {
            bigValue = new BigDecimal(stringValue);
            // Float.MIN_VALUE is the smallest positive non-zero number
            lowerBound = BigDecimal.valueOf(Float.MAX_VALUE).negate();
            upperBound = BigDecimal.valueOf(Float.MAX_VALUE);
        } else if (byte.class == toType || Byte.class == toType) {
            bigValue = new BigInteger(stringValue);
            lowerBound = BigInteger.valueOf(Byte.MIN_VALUE);
            upperBound = BigInteger.valueOf(Byte.MAX_VALUE);
        } else if (char.class == toType || Character.class == toType) {
            bigValue = new BigInteger(stringValue);
            lowerBound = BigInteger.valueOf(Character.MIN_VALUE);
            upperBound = BigInteger.valueOf(Character.MAX_VALUE);
        } else if (short.class == toType || Short.class == toType) {
            bigValue = new BigInteger(stringValue);
            lowerBound = BigInteger.valueOf(Short.MIN_VALUE);
            upperBound = BigInteger.valueOf(Short.MAX_VALUE);
        } else if (int.class == toType || Integer.class == toType) {
            bigValue = new BigInteger(stringValue);
            lowerBound = BigInteger.valueOf(Integer.MIN_VALUE);
            upperBound = BigInteger.valueOf(Integer.MAX_VALUE);
        } else if (long.class == toType || Long.class == toType) {
            bigValue = new BigInteger(stringValue);
            lowerBound = BigInteger.valueOf(Long.MIN_VALUE);
            upperBound = BigInteger.valueOf(Long.MAX_VALUE);
        }
    } catch (NumberFormatException e) {
        //shoult it fail here? BigInteger doesnt seem to be so nice parsing numbers as NumberFormat
        return true;
    }

    return ((Comparable) bigValue).compareTo(lowerBound) >= 0
            && ((Comparable) bigValue).compareTo(upperBound) <= 0;
}

From source file:org.apache.carbondata.core.indexstore.blockletindex.BlockletDataMap.java

/**
 * Fill the measures min values with minimum , this is needed for backward version compatability
 * as older versions don't store min values for measures
 *//*from  www. j av  a2 s .  com*/
private byte[][] updateMinValues(byte[][] minValues, int[] minMaxLen) {
    byte[][] updatedValues = minValues;
    if (minValues.length < minMaxLen.length) {
        updatedValues = new byte[minMaxLen.length][];
        System.arraycopy(minValues, 0, updatedValues, 0, minValues.length);
        List<CarbonMeasure> measures = segmentProperties.getMeasures();
        ByteBuffer buffer = ByteBuffer.allocate(8);
        for (int i = 0; i < measures.size(); i++) {
            buffer.rewind();
            DataType dataType = measures.get(i).getDataType();
            if (dataType == DataTypes.BYTE) {
                buffer.putLong(Byte.MIN_VALUE);
                updatedValues[minValues.length + i] = buffer.array().clone();
            } else if (dataType == DataTypes.SHORT) {
                buffer.putLong(Short.MIN_VALUE);
                updatedValues[minValues.length + i] = buffer.array().clone();
            } else if (dataType == DataTypes.INT) {
                buffer.putLong(Integer.MIN_VALUE);
                updatedValues[minValues.length + i] = buffer.array().clone();
            } else if (dataType == DataTypes.LONG) {
                buffer.putLong(Long.MIN_VALUE);
                updatedValues[minValues.length + i] = buffer.array().clone();
            } else if (DataTypes.isDecimal(dataType)) {
                updatedValues[minValues.length + i] = DataTypeUtil
                        .bigDecimalToByte(BigDecimal.valueOf(Long.MIN_VALUE));
            } else {
                buffer.putDouble(Double.MIN_VALUE);
                updatedValues[minValues.length + i] = buffer.array().clone();
            }
        }
    }
    return updatedValues;
}

From source file:au.org.ala.delta.editor.ui.image.ImageOverlayEditorController.java

private void configureOverlay(ImageOverlay anOverlay) {
    Point menuPoint = _selection.getSelectedPoint();
    if (menuPoint == null) {
        menuPoint = new Point(Integer.MIN_VALUE, Integer.MIN_VALUE);
    }/*from  www  .ja v a  2  s  . c om*/
    OverlayLocation newLocation;
    if (anOverlay.location.size() == 0) {
        newLocation = new OverlayLocation();
        anOverlay.location.add(newLocation);
    } else {
        newLocation = anOverlay.getLocation(0);
    }

    anOverlay.setIntegralHeight(true);
    anOverlay.setHeight(-1);

    if (menuPoint.x != Integer.MIN_VALUE) {

        newLocation.setX(menuPoint.x);
        newLocation.setY(menuPoint.y);
    } else {
        newLocation.X = 350;
        newLocation.Y = 450;
    }
    if (anOverlay.isButton()) {
        int bhClient = 30;
        int bwClient = 50;
        newLocation.W = newLocation.H = Short.MIN_VALUE;
        ButtonAlignment align = _alignment;
        if (align == ButtonAlignment.NO_ALIGN)
            align = ButtonAlignment.ALIGN_VERTICALLY;
        if (menuPoint.x == Integer.MIN_VALUE) {
            newLocation.setX(align == ButtonAlignment.ALIGN_VERTICALLY ? 800 : 500);
            newLocation.setY(align == ButtonAlignment.ALIGN_VERTICALLY ? 500 : 800);
        }
        newLocation.setX(Math.max(0, Math.min(1000 - bwClient, (int) newLocation.X)));
        newLocation.setY(Math.max(0, Math.min(1000 - bhClient, (int) newLocation.Y)));
        int okWhere = Integer.MIN_VALUE, cancelWhere = Integer.MIN_VALUE, notesWhere = Integer.MIN_VALUE;
        ImageOverlay okOverlay = _selection.getSelectedImage().getOverlay(OverlayType.OLOK);
        if (okOverlay != null) {
            if (align == ButtonAlignment.ALIGN_VERTICALLY) {
                newLocation.setX(okOverlay.getX());
                okWhere = okOverlay.getY();
            } else if (align == ButtonAlignment.ALIGN_HORIZONTALLY) {
                newLocation.setY(okOverlay.getY());
                okWhere = okOverlay.getX();
            }
        }
        ImageOverlay cancelOverlay = _selection.getSelectedImage().getOverlay(OverlayType.OLCANCEL);
        if (cancelOverlay != null) {
            if (align == ButtonAlignment.ALIGN_VERTICALLY) {
                newLocation.setX(cancelOverlay.getX());
                cancelWhere = cancelOverlay.getY();
            } else if (align == ButtonAlignment.ALIGN_HORIZONTALLY) {
                newLocation.setY(cancelOverlay.getY());
                cancelWhere = cancelOverlay.getX();
            }
        }
        ImageOverlay notesOverlay;
        if (isCharacterIllustrated())
            notesOverlay = _selection.getSelectedImage().getOverlay(OverlayType.OLNOTES);
        else
            notesOverlay = _selection.getSelectedImage().getOverlay(OverlayType.OLIMAGENOTES);
        if (notesOverlay != null) {
            if (align == ButtonAlignment.ALIGN_VERTICALLY) {
                newLocation.setX(notesOverlay.getX());
                notesWhere = notesOverlay.getY();
            } else if (align == ButtonAlignment.ALIGN_HORIZONTALLY) {
                newLocation.setY(notesOverlay.getY());
                notesWhere = notesOverlay.getX();
            }
        }
        int newWhere = Integer.MIN_VALUE;
        int size = 0;
        if (align == ButtonAlignment.ALIGN_VERTICALLY)
            size = bhClient;
        else if (align == ButtonAlignment.ALIGN_HORIZONTALLY)
            size = bwClient;
        int space = size + (size + 1) / 2;
        if (anOverlay.type == OverlayType.OLOK) {
            if (cancelWhere != Integer.MIN_VALUE && notesWhere != Integer.MIN_VALUE)
                newWhere = cancelWhere - Math.abs(notesWhere - cancelWhere);
            else if (cancelWhere != Integer.MIN_VALUE || notesWhere != Integer.MIN_VALUE)
                newWhere = Math.max(cancelWhere, notesWhere) - space;
        } else if (anOverlay.type == OverlayType.OLCANCEL) {
            if (okWhere != Integer.MIN_VALUE && notesWhere != Integer.MIN_VALUE)
                newWhere = (okWhere + notesWhere) / 2;
            else if (okWhere != Integer.MIN_VALUE)
                newWhere = okWhere + space;
            else if (notesWhere != Integer.MIN_VALUE)
                newWhere = notesWhere - space;
        }
        if (anOverlay.type == OverlayType.OLNOTES || anOverlay.type == OverlayType.OLIMAGENOTES) {
            if (okWhere != Integer.MIN_VALUE && cancelWhere != Integer.MIN_VALUE)
                newWhere = cancelWhere + Math.abs(cancelWhere - okWhere);
            else if (okWhere != Integer.MIN_VALUE || cancelWhere != Integer.MIN_VALUE)
                newWhere = Math.max(okWhere, cancelWhere) + space;
        }
        if (newWhere + size > 1000)
            newWhere = 1000 - size;
        if (newWhere != Integer.MIN_VALUE) {
            if (newWhere < 0)
                newWhere = 0;
            if (align == ButtonAlignment.ALIGN_VERTICALLY)
                newLocation.setY(newWhere);
            else if (align == ButtonAlignment.ALIGN_HORIZONTALLY)
                newLocation.setX(newWhere);
        }
    } else if (anOverlay.type == OverlayType.OLHOTSPOT)
        newLocation.setW(Math.min(200, 1000 - newLocation.X));
    else
        newLocation.setW(Math.min(300, 1000 - newLocation.X));

}

From source file:net.dv8tion.jda.audio.AudioConnection.java

private void setupCombinedExecutor() {
    if (combinedAudioExecutor == null) {
        combinedAudioExecutor = Executors.newSingleThreadScheduledExecutor(
                r -> new Thread(r, "AudioConnection CombinedAudio Guild: " + channel.getGuild().getId()));
        combinedAudioExecutor.scheduleAtFixedRate(() -> {
            try {
                List<User> users = new LinkedList<>();
                List<short[]> audioParts = new LinkedList<>();
                if (receiveHandler != null && receiveHandler.canReceiveCombined()) {
                    long currentTime = System.currentTimeMillis();
                    for (Map.Entry<User, Queue<Pair<Long, short[]>>> entry : combinedQueue.entrySet()) {
                        User user = entry.getKey();
                        Queue<Pair<Long, short[]>> queue = entry.getValue();

                        if (queue.isEmpty())
                            continue;

                        Pair<Long, short[]> audioData = queue.poll();
                        //Make sure the audio packet is younger than 100ms
                        while (audioData != null && currentTime - audioData.getLeft() > queueTimeout) {
                            audioData = queue.poll();
                        }// w ww .  j a  v a2 s.  c  o  m

                        //If none of the audio packets were younger than 100ms, then there is nothing to add.
                        if (audioData == null) {
                            continue;
                        }
                        users.add(user);
                        audioParts.add(audioData.getRight());
                    }

                    if (!audioParts.isEmpty()) {
                        int audioLength = audioParts.get(0).length;
                        short[] mix = new short[1920]; //960 PCM samples for each channel
                        int sample;
                        for (int i = 0; i < audioLength; i++) {
                            sample = 0;
                            for (short[] audio : audioParts) {
                                sample += audio[i];
                            }
                            if (sample > Short.MAX_VALUE)
                                mix[i] = Short.MAX_VALUE;
                            else if (sample < Short.MIN_VALUE)
                                mix[i] = Short.MIN_VALUE;
                            else
                                mix[i] = (short) sample;
                        }
                        receiveHandler.handleCombinedAudio(new CombinedAudio(users, mix));
                    } else {
                        //No audio to mix, provide 20 MS of silence. (960 PCM samples for each channel)
                        receiveHandler
                                .handleCombinedAudio(new CombinedAudio(new LinkedList(), new short[1920]));
                    }
                }
            } catch (Exception e) {
                LOG.log(e);
            }
        }, 0, 20, TimeUnit.MILLISECONDS);
    }
}

From source file:org.codice.ddf.libs.klv.KlvDecoderTest.java

@Test
// Example value taken from ST0601.8 Tag 7, but for some reason their example value is 3.405814,
// which is wrong.
public void testFloatingPointEncodedAsShort() throws KlvDecodingException {
    final byte[] klvBytes = { -8, 2, (byte) 0x08, (byte) 0xB8 };
    final KlvShort klvShort = new KlvShort(new byte[] { -8 }, "test");
    final KlvIntegerEncodedFloatingPoint platformRollAngle =
            // Short.MIN_VALUE is an "out of range" indicator, so it is not included in the range.
            new KlvIntegerEncodedFloatingPoint(klvShort, Short.MIN_VALUE + 1, Short.MAX_VALUE, -50, 50);
    final KlvContext decodedKlvContext = decodeKLV(KeyLength.OneByte, LengthEncoding.OneByte, platformRollAngle,
            klvBytes);//w w w .  j av a 2s . c om
    final double value = ((KlvIntegerEncodedFloatingPoint) decodedKlvContext.getDataElementByName("test"))
            .getValue();
    assertThat(value, is(closeTo(3.405865, 1e-6)));
}