List of usage examples for java.lang Short valueOf
@HotSpotIntrinsicCandidate public static Short valueOf(short s)
From source file:com.beaucoralk.bukkit.labplugin.commands.CpEnchant.java
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (sender instanceof Player) { if (sender.hasPermission("cp.enchant") && !sender.isOp()) { sender.sendMessage(ChatColor.RED + "Don't have permission."); return true; }/* w w w .ja va2 s . c om*/ } if ((args.length < 3) || (args.length > 4)) { sender.sendMessage(ChatColor.RED + "'/cpenchant' command must have between 3 and 4 argument."); sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage); return true; } //Dfinition de l'item vis par la commande String[] _material_data = args[0].split(":"); Material _material = Material.matchMaterial(_material_data[0]); if (_material == null) { sender.sendMessage(ChatColor.RED + "Item '" + _material_data[0] + "' not found."); sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage); return true; } Integer _amount = 1; if (args.length == 4) { _amount = VariablesUtils.getInteger(args[3]); } Short _data = 0; if (_material_data.length == 2) { _data = Short.valueOf(_material_data[1]); } ItemStack _item = new ItemStack(_material, _amount, _data); if (_material == null) { sender.sendMessage(ChatColor.RED + "Item '" + _material_data[0] + "' not found."); sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage); return true; } //Dfinition du joueur vis par la commande Player _player = Bukkit.getPlayerExact(args[1]); if (_player == null) { sender.sendMessage(ChatColor.RED + "Player '" + args[1] + "' not found."); sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage); return true; } //Dfinition des diffrents enchantement Map<Enchantment, String> listEnchantments = new HashMap<>(); if (args.length >= 3) { for (String _enchant_level : args[2].split(",")) { String _enchant = _enchant_level.split(":")[0]; String _level = _enchant_level.split(":")[1]; Enchantment _enchantment = getEnchantment(_enchant.toUpperCase()); if (_enchantment != null) { listEnchantments.put(_enchantment, _level); } } } if (listEnchantments.isEmpty()) { sender.sendMessage(ChatColor.RED + "Enchantments list error retry."); sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage); return true; } StringBuilder _nameitem = new StringBuilder(); //Dfinition du nom de l'item if (args.length >= 5) { for (int i = 4; i < args.length; i++) { _nameitem.append(args[i]); if (i < (args.length - 1)) { _nameitem.append(" "); } } } //Ajout des enchantement l'item for (Map.Entry<Enchantment, String> entry : listEnchantments.entrySet()) { Enchantment enchantment = entry.getKey(); Integer level = -1; int minLevel = enchantment.getStartLevel(); int maxLevel = enchantment.getMaxLevel(); Boolean conflicts = false; if ("max".equals(entry.getValue())) { level = maxLevel; } else { level = VariablesUtils.getInteger(entry.getValue()); } if (level != null) { if (level < minLevel || level > maxLevel) { sender.sendMessage(String.format("Level for enchantment %s must be between %d and %d", WordUtils.capitalizeFully(enchantment.getName().replaceAll("_", " ")), minLevel, maxLevel)); sender.sendMessage("Specify 0 for level to remove an enchantment"); return true; } } Map<Enchantment, Integer> enchantments = _item.getEnchantments(); for (Map.Entry<Enchantment, Integer> _entry : enchantments.entrySet()) { Enchantment _enchant = _entry.getKey(); if (_enchant.equals(enchantment)) { continue; } if (_enchant.conflictsWith(enchantment)) { sender.sendMessage( String.format("Can't apply the enchantment %s on an item with the enchantment %s", WordUtils.capitalizeFully(enchantment.getName().replaceAll("_", " ")), WordUtils.capitalizeFully(_enchant.getName().replaceAll("_", " ")))); conflicts = true; break; } } if (!conflicts && enchantment.canEnchantItem(_item)) { _item.addUnsafeEnchantment(enchantment, level); _item.getItemMeta().setDisplayName(_nameitem.toString()); } } _player.getInventory().addItem(_item); return true; }
From source file:org.lwes.serializer.StringParser.java
public static Object fromStringINT16(String string) throws EventSystemException { Object toReturn = null;//from ww w . j a va 2 s.c o m log.trace("Parsing int16"); if (Pattern.matches(HEX_SHORT_REGEX, string)) { if (string.startsWith("0x")) { string = string.substring(2); } byte[] bytes = NumberCodec.hexStringToByteArray(string); toReturn = NumberCodec.decodeShort(bytes, 0, bytes.length); } else { try { toReturn = Short.valueOf(string); } catch (NumberFormatException nfe) { throw new EventSystemException("Probably not a short, " + "got exception " + nfe); } short shortValue = (Short) toReturn; if (shortValue < -32768 || shortValue > 32767) { throw new EventSystemException("Signed Short must be in the " + "range [-32768 - 32767] "); } } log.trace("received '" + toReturn + "'"); return toReturn; }
From source file:org.locationtech.udig.ui.BasicTypeCellEditor.java
private Object convertToType(String value) { if (type == Short.class) { return Short.valueOf(value); } else if (type == String.class) { return StringUtils.trimToNull(value); } else if (type == Integer.class) { return Integer.valueOf(value); } else if (type == Byte.class) { return Byte.valueOf(value); } else if (type == Character.class) { return value.charAt(0); } else if (type == Long.class) { return Long.valueOf(value); } else if (type == Double.class) { return Double.valueOf(value); } else if (type == Float.class) { return Float.valueOf(value); } else if (type == BigDecimal.class) { return new BigDecimal(value); } else if (type == BigInteger.class) { return new BigInteger(value); }/* w ww . j a v a 2 s. c om*/ return null; }
From source file:org.locationtech.udig.ui.NumberCellEditor.java
private Number convertToNumber() { if (cls == Integer.class) { return NumberUtils.createInteger(StringUtils.isNotEmpty(text.getText()) ? text.getText() : null); } else if (cls == Long.class) { return NumberUtils.createLong(StringUtils.isNotEmpty(text.getText()) ? text.getText() : null); } else if (cls == BigInteger.class) { return NumberUtils.createBigInteger(StringUtils.isNotEmpty(text.getText()) ? text.getText() : null); } else if (cls == BigDecimal.class) { return NumberUtils.createBigDecimal(StringUtils.isNotEmpty(text.getText()) ? text.getText() : null); } else if (cls == Double.class) { return NumberUtils.createDouble(StringUtils.isNotEmpty(text.getText()) ? text.getText() : null); } else if (cls == Float.class) { return NumberUtils.createFloat(StringUtils.isNotEmpty(text.getText()) ? text.getText() : null); } else if (cls == Short.class) { if (StringUtils.isNotEmpty(text.getText())) { return Short.valueOf(text.getText()); } else {//from w w w.jav a 2s . com return null; } } return null; }
From source file:me.rojo8399.placeholderapi.impl.utils.TypeUtils.java
@SuppressWarnings("unchecked") public static <T> T convertPrimitive(String val, Class<T> primitiveClass) { val = val.toLowerCase().trim(); if (primitiveClass.equals(char.class) || primitiveClass.equals(Character.class)) { return (T) (Character) val.charAt(0); }/*from w w w. ja v a2 s . c o m*/ if (primitiveClass.equals(int.class) || primitiveClass.equals(Integer.class)) { return (T) Integer.valueOf(val); } if (primitiveClass.equals(long.class) || primitiveClass.equals(Long.class)) { return (T) Long.valueOf(val); } if (primitiveClass.equals(short.class) || primitiveClass.equals(Short.class)) { return (T) Short.valueOf(val); } if (primitiveClass.equals(byte.class) || primitiveClass.equals(Byte.class)) { return (T) Byte.valueOf(val); } if (primitiveClass.equals(double.class) || primitiveClass.equals(Double.class)) { return (T) Double.valueOf(val); } if (primitiveClass.equals(float.class) || primitiveClass.equals(Float.class)) { return (T) Float.valueOf(val); } if (primitiveClass.equals(boolean.class) || primitiveClass.equals(Boolean.class)) { return (T) (Boolean) isTrue(val); } throw new IllegalArgumentException("Class is not primitive or a wrapper!"); }
From source file:org.mifos.accounts.fees.struts.actionforms.FeeActionForm.java
public FeeCategory getCategoryTypeValue() throws PropertyNotFoundException { return StringUtils.isNotBlank(categoryType) ? FeeCategory.getFeeCategory(Short.valueOf(categoryType)) : null;//from www .j a v a 2 s .c o m }
From source file:com.alibaba.doris.admin.service.impl.ValueParseUtil.java
/** * ?String ?://www. j a v a 2 s.c o m * * <pre> * short, int, long, float : 0 * char, byte: 0 * String: null * Map, List: null * Integer, Long, Float : null * Date: null * array: null * </pre> * * @param strValue * @param clazz * @return */ @SuppressWarnings("unchecked") public static <T> T parseStringValue(String strValue, Class<T> clazz, boolean autoDefault) { if (DEF_NULL.equals(strValue)) { if (!clazz.isPrimitive()) { return null; } if (autoDefault) { return (T) getInternalDefaultValue(clazz); } else { return null; } } if (DEF_EMPTY.equals(strValue)) { if (clazz.isArray()) { return (T) Array.newInstance(clazz.getComponentType(), 0); } if (Map.class.isAssignableFrom(clazz)) { return (T) Collections.EMPTY_MAP; } if (List.class.isAssignableFrom(clazz)) { return (T) new ArrayList<Object>(); } if (Set.class.isAssignableFrom(clazz)) { return (T) new HashSet<Object>(); } if (String.class.equals(clazz)) { return (T) StringUtils.EMPTY; } if (Character.TYPE.equals(clazz) || Character.class.equals(clazz)) { return (T) Character.valueOf(' '); } if (autoDefault) { return (T) getInternalDefaultValue(clazz); } else { return null; } } if (StringUtils.isBlank(strValue)) {// ? if (autoDefault) { return (T) getInternalDefaultValue(clazz); } else { return null; } } else { if (String.class.equals(clazz)) { return (T) strValue; } if (Short.TYPE.equals(clazz) || Short.class.equals(clazz)) { return (T) Short.valueOf(strValue); } if (Integer.TYPE.equals(clazz) || Integer.class.equals(clazz)) { return (T) Integer.valueOf(strValue); } if (Long.TYPE.equals(clazz) || Long.class.equals(clazz)) { return (T) Long.valueOf(strValue); } if (Boolean.TYPE.equals(clazz) || Boolean.class.equals(clazz)) { return (T) Boolean.valueOf(strValue); } if (Float.TYPE.equals(clazz) || Float.class.equals(clazz)) { return (T) Float.valueOf(strValue); } if (Double.TYPE.equals(clazz) || Double.class.equals(clazz)) { return (T) Double.valueOf(strValue); } if (Byte.TYPE.equals(clazz) || Byte.class.equals(clazz)) { return (T) Byte.valueOf(strValue); } if (Character.TYPE.equals(clazz) || Character.class.equals(clazz)) { return (T) Character.valueOf(strValue.charAt(0)); } if (clazz.isArray()) { final Class<?> componentType = clazz.getComponentType(); // String[] if (String.class.equals(componentType)) { return (T) StringUtils.split(strValue, ','); } // ?char[] if (Character.TYPE.equals(componentType)) { return (T) strValue.toCharArray(); } if (Character.class.equals(componentType)) { final char[] tmp = strValue.toCharArray(); final Character[] result = new Character[tmp.length]; for (int i = 0; i < result.length; i++) { result[i] = tmp[i]; } return (T) result; } if (Byte.TYPE.equals(componentType) || Byte.class.equals(componentType)) { return (T) (strValue == null ? null : strValue.getBytes()); } } } return null; }
From source file:com.ning.arecibo.util.timeline.samples.TestSampleCoder.java
@Test(groups = "fast") public void testScan() throws Exception { final DateTime startTime = new DateTime(DateTimeZone.UTC); final DateTime endTime = startTime.plusSeconds(5); final List<DateTime> dateTimes = ImmutableList.<DateTime>of(startTime.plusSeconds(1), startTime.plusSeconds(2), startTime.plusSeconds(3), startTime.plusSeconds(4)); final byte[] compressedTimes = timelineCoder.compressDateTimes(dateTimes); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); final DataOutputStream dataOutputStream = new DataOutputStream(outputStream); final ScalarSample<Short> sample = new ScalarSample<Short>(SampleOpcode.SHORT, (short) 4); sampleCoder.encodeSample(dataOutputStream, sample); sampleCoder.encodeSample(dataOutputStream, new RepeatSample<Short>(3, sample)); dataOutputStream.close();/*from w w w .java 2s .c o m*/ sampleCoder.scan(outputStream.toByteArray(), compressedTimes, dateTimes.size(), new TimeRangeSampleProcessor(startTime, endTime) { @Override public void processOneSample(final DateTime time, final SampleOpcode opcode, final Object value) { Assert.assertTrue(time.isAfter(startTime)); Assert.assertTrue(time.isBefore(endTime)); Assert.assertEquals(Short.valueOf(value.toString()), sample.getSampleValue()); } }); }
From source file:Main.java
/** * <p>Converts an array of primitive shorts to objects.</p> * * <p>This method returns {@code null} for a {@code null} input array.</p> * * @param array a {@code short} array/*from w w w .j a v a 2 s .co m*/ * @return a {@code Short} array, {@code null} if null array input */ public static Short[] toObject(short[] array) { if (array == null) { return null; } else if (array.length == 0) { return EMPTY_SHORT_OBJECT_ARRAY; } final Short[] result = new Short[array.length]; for (int i = 0; i < array.length; i++) { result[i] = Short.valueOf(array[i]); } return result; }
From source file:Main.java
/** * <p>Converts an array of primitive shorts to objects.</p> * * <p>This method returns {@code null} for a {@code null} input array.</p> * * @param array a {@code short} array//from ww w . j av a 2 s . c o m * @return a {@code Short} array, {@code null} if null array input */ public static Short[] toObject(final short[] array) { if (array == null) { return null; } else if (array.length == 0) { return EMPTY_SHORT_OBJECT_ARRAY; } final Short[] result = new Short[array.length]; for (int i = 0; i < array.length; i++) { result[i] = Short.valueOf(array[i]); } return result; }