List of usage examples for java.lang Byte parseByte
public static byte parseByte(String s) throws NumberFormatException
From source file:admincommands.Gameshop.java
@Override public void execute(Player admin, String... params) { if (params.length == 0) { onFail(admin, null);//from w ww . ja va2s. com return; } int itemId = 0; int list; byte category, subCategory, itemType, gift; long count, price, toll; Player player = null; String titleDescription; if ("delete".startsWith(params[0])) { try { itemId = Integer.parseInt(params[1]); category = Byte.parseByte(params[2]); subCategory = Byte.parseByte(params[3]); list = Integer.parseInt(params[4]); } catch (NumberFormatException e) { PacketSendUtility.sendMessage(admin, "<itemId, category, subCategory, list> values must be int, byte, byte, int."); return; } DAOManager.getDAO(InGameShopDAO.class).deleteIngameShopItem(itemId, category, subCategory, list - 1); PacketSendUtility.sendMessage(admin, "You remove [item:" + itemId + "]"); } else if ("add".startsWith(params[0])) { try { itemId = Integer.parseInt(params[1]); count = Long.parseLong(params[2]); price = Long.parseLong(params[3]); category = Byte.parseByte(params[4]); subCategory = Byte.parseByte(params[5]); itemType = Byte.parseByte(params[6]); gift = Byte.parseByte(params[7]); list = Integer.parseInt(params[8]); titleDescription = Util.convertName(params[9]); } catch (NumberFormatException e) { PacketSendUtility.sendMessage(admin, "<itemId, count, price, category, subCategory, itemType, gift, list, description> values must be int, long, long, byte, byte, byte, byte, int, string, Object... ."); return; } ItemTemplate itemTemplate = DataManager.ITEM_DATA.getItemTemplate(itemId); if (itemTemplate == null) { PacketSendUtility.sendMessage(admin, "Item id is incorrect: " + itemId); return; } String description = ""; for (int i = 10; i < params.length; i++) { description += Util.convertName(params[i]) + " "; } description = description.trim(); if (list < 1) { PacketSendUtility.sendMessage(admin, "<list> : minium is 1."); return; } if (gift < 0 || gift > 1) { PacketSendUtility.sendMessage(admin, "<gift> : minimum is 0, maximum is 1."); return; } if (itemType < 0 || itemType > 2) { PacketSendUtility.sendMessage(admin, "<itemType> : minimum is 0, maximum is 2."); return; } if (subCategory < 3 || subCategory > 19) { PacketSendUtility.sendMessage(admin, "<category> : minimum is 3, maximum is 19."); return; } if (titleDescription.length() > 20) { PacketSendUtility.sendMessage(admin, "<title description> : maximum length is 20."); return; } if (titleDescription.equals("empty")) { titleDescription = StringUtils.EMPTY; } DAOManager.getDAO(InGameShopDAO.class).saveIngameShopItem(IDFactory.getInstance().nextId(), itemId, count, price, category, subCategory, list - 1, 1, itemType, gift, titleDescription, description); PacketSendUtility.sendMessage(admin, "You add [item:" + itemId + "]"); } else if ("deleteranking".startsWith(params[0])) { try { itemId = Integer.parseInt(params[1]); } catch (NumberFormatException e) { PacketSendUtility.sendMessage(admin, "<itemId> value must be an integer."); } DAOManager.getDAO(InGameShopDAO.class).deleteIngameShopItem(itemId, (byte) -1, (byte) -1, -1); PacketSendUtility.sendMessage(admin, "You remove from Ranking Sales [item:" + itemId + "]"); } else if ("addranking".startsWith(params[0])) { try { itemId = Integer.parseInt(params[1]); count = Long.parseLong(params[2]); price = Long.parseLong(params[3]); itemType = Byte.parseByte(params[4]); gift = Byte.parseByte(params[5]); titleDescription = Util.convertName(params[6]); } catch (NumberFormatException e) { PacketSendUtility.sendMessage(admin, "<itemId, count, price, itemType, gift, description> value must be int, long, long, byte, byte, string, Object... ."); return; } String description = ""; for (int i = 7; i < params.length; i++) { description += Util.convertName(params[i]) + " "; } description = description.trim(); ItemTemplate itemTemplate = DataManager.ITEM_DATA.getItemTemplate(itemId); if (itemTemplate == null) { PacketSendUtility.sendMessage(admin, "Item id is incorrect: " + itemId); return; } if (titleDescription.equals("empty")) { titleDescription = StringUtils.EMPTY; } DAOManager.getDAO(InGameShopDAO.class).saveIngameShopItem(IDFactory.getInstance().nextId(), itemId, count, price, (byte) -1, (byte) -1, -1, 0, itemType, gift, titleDescription, description); PacketSendUtility.sendMessage(admin, "You remove from Ranking Sales [item:" + itemId + "]"); } else if ("settoll".startsWith(params[0])) { if (params.length == 3) { try { toll = Integer.parseInt(params[2]); } catch (NumberFormatException e) { PacketSendUtility.sendMessage(admin, "<toll> value must be an integer."); return; } String name = Util.convertName(params[1]); player = World.getInstance().findPlayer(name); if (player == null) { PacketSendUtility.sendMessage(admin, "The specified player is not online."); return; } if (LoginServer.getInstance().sendPacket(new SM_ACCOUNT_TOLL_INFO(toll, player.getAcountName()))) { player.getClientConnection().getAccount().setToll(toll); PacketSendUtility.sendPacket(player, new SM_TOLL_INFO(toll)); PacketSendUtility.sendMessage(admin, "Tolls setted to " + toll + "."); } else { PacketSendUtility.sendMessage(admin, "ls communication error."); } } if (params.length == 2) { try { toll = Integer.parseInt(params[1]); } catch (NumberFormatException e) { PacketSendUtility.sendMessage(admin, "<toll> value must be an integer."); return; } if (toll < 0) { PacketSendUtility.sendMessage(admin, "<toll> must > 0."); return; } VisibleObject target = admin.getTarget(); if (target == null) { PacketSendUtility.sendMessage(admin, "You should select a target first!"); return; } if (target instanceof Player) { player = (Player) target; } if (LoginServer.getInstance().sendPacket(new SM_ACCOUNT_TOLL_INFO(toll, player.getAcountName()))) { player.getClientConnection().getAccount().setToll(toll); PacketSendUtility.sendPacket(player, new SM_TOLL_INFO(toll)); PacketSendUtility.sendMessage(admin, "Tolls setted to " + toll + "."); } else { PacketSendUtility.sendMessage(admin, "ls communication error."); } } } else if ("addtoll".startsWith(params[0])) { if (params.length == 3) { try { toll = Integer.parseInt(params[2]); } catch (NumberFormatException e) { PacketSendUtility.sendMessage(admin, "<toll> value must be an integer."); return; } if (toll < 0) { PacketSendUtility.sendMessage(admin, "<toll> must > 0."); return; } String name = Util.convertName(params[1]); player = World.getInstance().findPlayer(name); if (player == null) { PacketSendUtility.sendMessage(admin, "The specified player is not online."); return; } PacketSendUtility.sendMessage(admin, "You added " + toll + " tolls to Player: " + name); InGameShopEn.getInstance().addToll(player, toll); } if (params.length == 2) { try { toll = Integer.parseInt(params[1]); } catch (NumberFormatException e) { PacketSendUtility.sendMessage(admin, "<toll> value must be an integer."); return; } VisibleObject target = admin.getTarget(); if (target == null) { PacketSendUtility.sendMessage(admin, "You should select a target first!"); return; } if (target instanceof Player) { player = (Player) target; } PacketSendUtility.sendMessage(admin, "You added " + toll + " tolls to Player: " + player.getName()); InGameShopEn.getInstance().addToll(player, toll); } } else { PacketSendUtility.sendMessage(admin, "You can use only, addtoll, settoll, deleteranking, addranking, delete or add."); } }
From source file:hu.bme.mit.sette.common.model.runner.xml.ParameterElement.java
@Override protected void validate2(final GeneralValidator validator) { switch (getType()) { case BYTE:/*from ww w . jav a2 s . c o m*/ // TODO validator exception Byte.parseByte(value); break; case SHORT: // TODO validator exception Short.parseShort(value); break; case INT: // TODO validator exception Integer.parseInt(value); break; case LONG: // TODO validator exception Long.parseLong(value); break; case FLOAT: // TODO validator exception Float.parseFloat(value); break; case DOUBLE: // TODO validator exception Double.parseDouble(value); break; case BOOLEAN: if (!value.equals("true") && !value.equals("false")) { // TODO error handling throw new RuntimeException("Bad boolean: " + value); } break; case CHAR: if (value.length() != 1) { // TODO error handling throw new RuntimeException("Bad char: " + value); } break; case EXPRESSION: if (StringUtils.isBlank(value)) { // TODO error handling throw new RuntimeException("Blank expression"); } break; default: // TODO error handling throw new RuntimeException("Unhandled parameter type: " + getType()); } }
From source file:com.junly.common.util.ReflectUtils.java
/** * <p class="detail">/*from w ww. j av a2 s .c om*/ * * </p> * @author wan.Dong * @date 20161112 * @param obj * @param name ?? * @param value (?)??false * @return */ public static boolean setProperty(Object obj, String name, Object value) { if (obj != null) { Class<?> clazz = obj.getClass(); while (clazz != null) { Field field = null; try { field = clazz.getDeclaredField(name); } catch (Exception e) { clazz = clazz.getSuperclass(); continue; } try { Class<?> type = field.getType(); if (type.isPrimitive() == true && value != null) { if (value instanceof String) { if (type.equals(int.class) == true) { value = Integer.parseInt((String) value); } else if (type.equals(double.class) == true) { value = Double.parseDouble((String) value); } else if (type.equals(boolean.class) == true) { value = Boolean.parseBoolean((String) value); } else if (type.equals(long.class) == true) { value = Long.parseLong((String) value); } else if (type.equals(byte.class) == true) { value = Byte.parseByte((String) value); } else if (type.equals(char.class) == true) { value = Character.valueOf(((String) value).charAt(0)); } else if (type.equals(float.class) == true) { value = Float.parseFloat((String) value); } else if (type.equals(short.class) == true) { value = Short.parseShort((String) value); } } field.setAccessible(true); field.set(obj, value); field.setAccessible(false); } if (value == null || type.equals(value.getClass()) == true) { field.setAccessible(true); field.set(obj, value); field.setAccessible(false); } return true; } catch (Exception e) { return false; } } } return false; }
From source file:com.bt.download.android.gui.httpserver.DownloadHandler.java
public void internalHandler(HttpExchange exchange) throws IOException { assertUPnPActive();//ww w . j ava2 s .co m OutputStream os = null; FileInputStream fis = null; byte type = -1; int id = -1; PeerHttpUpload upload = null; try { List<NameValuePair> query = URLEncodedUtils.parse(exchange.getRequestURI(), "UTF-8"); for (NameValuePair item : query) { if (item.getName().equals("type")) { type = Byte.parseByte(item.getValue()); } if (item.getName().equals("id")) { id = Integer.parseInt(item.getValue()); } } if (type == -1 || id == -1) { exchange.sendResponseHeaders(Code.HTTP_BAD_REQUEST, 0); return; } if (TransferManager.instance().getActiveUploads() >= ConfigurationManager.instance() .maxConcurrentUploads()) { sendBusyResponse(exchange); return; } FileDescriptor fd = Librarian.instance().getFileDescriptor(type, id); if (fd == null) { throw new IOException("There is no such file shared"); } upload = TransferManager.instance().upload(fd); exchange.getResponseHeaders().add("Content-Type", fd.mime); exchange.sendResponseHeaders(Code.HTTP_OK, fd.fileSize); os = exchange.getResponseBody(); fis = new FileInputStream(fd.filePath); byte[] buffer = new byte[4 * 1024]; int n; int count = 0; while ((n = fis.read(buffer, 0, buffer.length)) != -1) { os.write(buffer, 0, n); upload.addBytesSent(n); if (upload.isCanceled()) { try { throw new IOException("Upload cancelled"); } finally { os.close(); } } count += n; if (count > 4096) { count = 0; Thread.yield(); } } } catch (IOException e) { LOG.log(Level.INFO, "Error uploading file type=" + type + ", id=" + id); throw e; } finally { close(os); close(fis); try { exchange.close(); } catch (Throwable e) { // ignore } if (upload != null) { upload.complete(); } } }
From source file:org.kordamp.ezmorph.primitive.ByteMorpher.java
/** * Morphs the input object into an output object of the supported type. * * @param value The input value to be morphed * @throws MorphException if conversion cannot be performed successfully */// w w w.ja va2 s .c o m public byte morph(Object value) { if (value == null) { if (isUseDefault()) { return defaultValue; } else { throw new MorphException("value is null"); } } if (value instanceof Number) { return ((Number) value).byteValue(); } else { byte i = 0; try { i = Byte.parseByte(getIntegerValue(value)); return i; } catch (NumberFormatException nfe) { if (isUseDefault()) { return defaultValue; } else { throw new MorphException(nfe); } } } }
From source file:gemlite.core.internal.domain.utilClass.MqDataSource.java
@Override public byte getByte(String name) { String str = map.get(name);/*ww w.j a v a2 s . c om*/ if (str == null) return 0; byte b = Byte.parseByte(str); return b; }
From source file:org.jolokia.converter.object.StringToObjectConverterTest.java
@Test public void simpleConversions() { Object obj = converter.convertFromString(int.class.getCanonicalName(), "10"); assertEquals("Int conversion", 10, obj); obj = converter.convertFromString(Integer.class.getCanonicalName(), "10"); assertEquals("Integer conversion", 10, obj); obj = converter.convertFromString(Short.class.getCanonicalName(), "10"); assertEquals("Short conversion", (short) 10, obj); obj = converter.convertFromString(short.class.getCanonicalName(), "10"); assertEquals("short conversion", Short.parseShort("10"), obj); obj = converter.convertFromString(Long.class.getCanonicalName(), "10"); assertEquals("long conversion", 10L, obj); obj = converter.convertFromString(long.class.getCanonicalName(), "10"); assertEquals("Long conversion", 10L, obj); obj = converter.convertFromString(Byte.class.getCanonicalName(), "10"); assertEquals("Byte conversion", (byte) 10, obj); obj = converter.convertFromString(byte.class.getCanonicalName(), "10"); assertEquals("byte conversion", Byte.parseByte("10"), obj); obj = converter.convertFromString(Float.class.getCanonicalName(), "10.5"); assertEquals("Float conversion", 10.5f, obj); obj = converter.convertFromString(float.class.getCanonicalName(), "21.3"); assertEquals("float conversion", new Float(21.3f), obj); obj = converter.convertFromString(Double.class.getCanonicalName(), "10.5"); assertEquals("Double conversion", 10.5d, obj); obj = converter.convertFromString(double.class.getCanonicalName(), "21.3"); assertEquals("double conversion", 21.3d, obj); obj = converter.convertFromString(BigDecimal.class.getCanonicalName(), "83.4e+4"); assertEquals("BigDecimal conversion", new BigDecimal("8.34e+5"), obj); obj = converter.convertFromString(BigInteger.class.getCanonicalName(), "47110815471108154711"); assertEquals("BigInteger conversion", new BigInteger("47110815471108154711"), obj); obj = converter.convertFromString(Boolean.class.getCanonicalName(), "false"); assertEquals("Boolean conversion", false, obj); obj = converter.convertFromString(boolean.class.getCanonicalName(), "true"); assertEquals("boolean conversion", true, obj); obj = converter.convertFromString(char.class.getCanonicalName(), "a"); assertEquals("Char conversion", 'a', obj); obj = converter.convertFromString("java.lang.String", "10"); assertEquals("String conversion", "10", obj); }
From source file:com.suarez.cordova.mapsforge.MapsforgePlugin.java
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if ("global-status".equals(action)) { this.status(); callbackContext.success();// ww w .j a va2s . c o m return true; } else if (action.contains("native-")) { if ("native-set-center".equals(action)) { try { MapsforgeNative.INSTANCE.setCenter(args.getDouble(0), args.getDouble(1)); callbackContext.success(); } catch (JSONException je) { callbackContext.error(je.getMessage()); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } else if ("native-set-zoom".equals(action)) { try { MapsforgeNative.INSTANCE.setZoom(Byte.parseByte(args.getString(0))); callbackContext.success(); } catch (NumberFormatException nfe) { callbackContext.error("Incorrect argument format. Should be: (byte zoom)"); } catch (JSONException je) { callbackContext.error(je.getMessage()); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } else if ("native-show".equals(action)) { try { MapsforgeNative.INSTANCE.show(); callbackContext.success(); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } else if ("native-hide".equals(action)) { MapsforgeNative.INSTANCE.hide(); return true; } else if ("native-marker".equals(action)) { try { Activity context = this.cordova.getActivity(); int markerId = context.getResources().getIdentifier(args.getString(0), "drawable", context.getPackageName()); if (markerId == 0) { Log.i(MapsforgePlugin.TAG, "Marker not found...using default marker: marker_green"); markerId = context.getResources().getIdentifier("marker_green", "drawable", context.getPackageName()); } int markerKey = MapsforgeNative.INSTANCE.addMarker(markerId, args.getDouble(1), args.getDouble(2)); callbackContext.success(markerKey); } catch (JSONException je) { callbackContext.error(je.getMessage()); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } else if ("native-polyline".equals(action)) { try { JSONArray points = args.getJSONArray(2); if (points.length() % 2 != 0) throw new JSONException("Invalid array of coordinates. Length should be multiple of 2"); int polylineKey = MapsforgeNative.INSTANCE.addPolyline(args.getInt(0), args.getInt(1), points); callbackContext.success(polylineKey); } catch (JSONException je) { callbackContext.error(je.getMessage()); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } else if ("native-delete-layer".equals(action)) { try { MapsforgeNative.INSTANCE.deleteLayer(args.getInt(0)); callbackContext.success(); } catch (JSONException je) { callbackContext.error(je.getMessage()); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } else if ("native-initialize".equals(action)) { try { MapsforgeNative.createInstance(this.cordova.getActivity(), args.getString(0), args.getInt(1), args.getInt(2)); callbackContext.success(); } catch (JSONException je) { callbackContext.error(je.getMessage()); } catch (IllegalArgumentException e) { callbackContext.error(e.getMessage()); } catch (IOException e) { callbackContext.error(e.getMessage()); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } else if ("native-set-max-zoom".equals(action)) { try { MapsforgeNative.INSTANCE.setMaxZoom(Byte.parseByte(args.getString(0))); callbackContext.success(); } catch (NumberFormatException nfe) { callbackContext.error("Incorrect argument format. Should be: (byte zoom)"); } catch (JSONException je) { callbackContext.error(je.getMessage()); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } else if ("native-set-min-zoom".equals(action)) { try { MapsforgeNative.INSTANCE.setMinZoom(Byte.parseByte(args.getString(0))); callbackContext.success(); } catch (NumberFormatException nfe) { callbackContext.error("Incorrect argument format. Should be: (byte zoom)"); } catch (JSONException je) { callbackContext.error(je.getMessage()); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } else if ("native-show-controls".equals(action)) { try { MapsforgeNative.INSTANCE.setBuiltInZoomControls(args.getBoolean(0)); callbackContext.success(); } catch (JSONException je) { callbackContext.error(je.getMessage()); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } else if ("native-clickable".equals(action)) { try { MapsforgeNative.INSTANCE.setClickable(args.getBoolean(0)); callbackContext.success(); } catch (JSONException je) { callbackContext.error(je.getMessage()); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } else if ("native-show-scale".equals(action)) { try { MapsforgeNative.INSTANCE.showScaleBar(args.getBoolean(0)); callbackContext.success(); } catch (JSONException je) { callbackContext.error(je.getMessage()); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } else if ("native-destroy-cache".equals(action)) { try { MapsforgeNative.INSTANCE.destroyCache(args.getBoolean(0)); callbackContext.success(); } catch (JSONException je) { callbackContext.error(je.getMessage()); } return true; } else if ("native-map-path".equals(action)) { try { MapsforgeNative.INSTANCE.setMapFilePath(args.getString(0)); callbackContext.success(); } catch (JSONException je) { callbackContext.error(je.getMessage()); } catch (IllegalArgumentException iae) { callbackContext.error(iae.getMessage()); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } else if ("native-cache-name".equals(action)) { try { MapsforgeNative.INSTANCE.setCacheName(args.getString(0)); callbackContext.success(); } catch (JSONException je) { callbackContext.error(je.getMessage()); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } else if ("native-theme-path".equals(action)) { try { MapsforgeNative.INSTANCE.setRenderThemePath(args.getString(0)); callbackContext.success(); } catch (JSONException je) { callbackContext.error(je.getMessage()); } catch (IllegalArgumentException e) { callbackContext.error(e.getMessage()); } catch (IOException e) { callbackContext.error(e.getMessage()); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } else if ("native-stop".equals(action)) { try { MapsforgeNative.INSTANCE.onStop(); callbackContext.success(); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } else if ("native-start".equals(action)) { try { MapsforgeNative.INSTANCE.onStart(); callbackContext.success(); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } else if ("native-destroy".equals(action)) { try { MapsforgeNative.INSTANCE.onDestroy(); callbackContext.success(); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } else if ("native-online".equals(action)) { try { MapsforgeNative.INSTANCE.setOnline(args.getString(0), args.getString(1), args.getString(2), args.getString(3), args.getInt(4)); callbackContext.success(); } catch (JSONException je) { callbackContext.error(je.getMessage()); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } else if ("native-offline".equals(action)) { try { MapsforgeNative.INSTANCE.setOffline(args.getString(0), args.getString(1)); callbackContext.success(); } catch (JSONException je) { callbackContext.error(je.getMessage()); } catch (IllegalArgumentException e) { callbackContext.error(e.getMessage()); } catch (IOException e) { callbackContext.error(e.getMessage()); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } } else if (action.contains("cache-")) { if ("cache-get-tile".equals(action)) { try { final long x = args.getLong(0); final long y = args.getLong(1); final byte z = Byte.parseByte(args.getString(2)); final CallbackContext callbacks = callbackContext; cordova.getThreadPool().execute(new Runnable() { public void run() { try { String path = MapsforgeCache.INSTANCE.getTilePath(x, y, z); callbacks.success(path); } catch (IOException e) { callbacks.error(e.getMessage()); } catch (Exception e) { callbacks.error(e.getMessage()); } } }); } catch (JSONException je) { callbackContext.error(je.getMessage()); } catch (NumberFormatException nfe) { callbackContext.error(nfe.getMessage()); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } else if ("cache-initialize".equals(action)) { try { MapsforgeCache.createInstance(cordova.getActivity(), args.getString(0)); callbackContext.success(); } catch (JSONException je) { callbackContext.error(je.getMessage()); } catch (IllegalArgumentException e) { callbackContext.error(e.getMessage()); } catch (IOException e) { callbackContext.error(e.getMessage()); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } else if ("cache-map-path".equals(action)) { try { final String mapFile = args.getString(0); final CallbackContext callbacks = callbackContext; cordova.getThreadPool().execute(new Runnable() { @Override public void run() { try { MapsforgeCache.INSTANCE.setMapFilePath(mapFile); callbacks.success(); } catch (IllegalArgumentException e) { callbacks.error(e.getMessage()); } catch (FileNotFoundException e) { callbacks.error(e.getMessage()); } catch (Exception e) { callbacks.error(e.getMessage()); } } }); } catch (JSONException je) { callbackContext.error(je.getMessage()); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } else if ("cache-max-size".equals(action)) { try { MapsforgeCache.INSTANCE.setMaxCacheSize(args.getInt(0)); callbackContext.success(); } catch (JSONException je) { callbackContext.error(je.getMessage()); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } else if ("cache-max-age".equals(action)) { try { MapsforgeCache.INSTANCE.setMaxCacheAge(args.getLong(0)); callbackContext.success(); } catch (JSONException je) { callbackContext.error(je.getMessage()); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } else if ("cache-cleaning-trigger".equals(action)) { try { MapsforgeCache.INSTANCE.setCleanCacheTrigger(args.getInt(0)); callbackContext.success(); } catch (JSONException je) { callbackContext.error(je.getMessage()); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } else if ("cache-enabled".equals(action)) { try { MapsforgeCache.INSTANCE.setCacheEnabled(args.getBoolean(0)); callbackContext.success(); } catch (JSONException je) { callbackContext.error(je.getMessage()); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } else if ("cache-external".equals(action)) { try { MapsforgeCache.INSTANCE.setExternalCache(args.getBoolean(0)); callbackContext.success(); } catch (JSONException je) { callbackContext.error(je.getMessage()); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } else if ("cache-name".equals(action)) { try { MapsforgeCache.INSTANCE.setCacheName(args.getString(0)); callbackContext.success(); } catch (JSONException je) { callbackContext.error(je.getMessage()); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } else if ("cache-tile-size".equals(action)) { try { MapsforgeCache.INSTANCE.setTileSize(args.getInt(0)); callbackContext.success(); } catch (JSONException je) { callbackContext.error(je.getMessage()); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } else if ("cache-clean-destroy".equals(action)) { try { MapsforgeCache.INSTANCE.setCleanOnDestroy(args.getBoolean(0)); callbackContext.success(); } catch (JSONException je) { callbackContext.error(je.getMessage()); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } else if ("cache-theme-path".equals(action)) { try { final CallbackContext callbacks = callbackContext; final String themePath = args.getString(0); cordova.getThreadPool().execute(new Runnable() { @Override public void run() { try { MapsforgeCache.INSTANCE.setRenderTheme(themePath); callbacks.success(); } catch (IllegalArgumentException e) { callbacks.error(e.getMessage()); } catch (FileNotFoundException e) { callbacks.error(e.getMessage()); } catch (Exception e) { callbacks.error(e.getMessage()); } } }); } catch (JSONException je) { callbackContext.error(je.getMessage()); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } else if ("cache-screen-ratio".equals(action)) { try { MapsforgeCache.INSTANCE.setScreenRatio(Float.parseFloat(args.getString(0))); callbackContext.success(); } catch (JSONException je) { callbackContext.error(je.getMessage()); } catch (NumberFormatException nfe) { callbackContext.error(nfe.getMessage()); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } else if ("cache-overdraw".equals(action)) { try { MapsforgeCache.INSTANCE.setOverdrawFactor(Float.parseFloat(args.getString(0))); callbackContext.success(); } catch (JSONException je) { callbackContext.error(je.getMessage()); } catch (NumberFormatException nfe) { callbackContext.error(nfe.getMessage()); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } else if ("cache-destroy".equals(action)) { try { MapsforgeCache.INSTANCE.onDestroy(); callbackContext.success(); } catch (Exception e) { callbackContext.error(e.getMessage()); } return true; } } return false; // Returning false results in a "MethodNotFound" error. }
From source file:jcurl.core.io.OldConfigReader.java
private static boolean parseRock(final OldConfigReader ret, final Reader in) throws IOException { String tok = readToken(in);//from w ww . ja v a 2 s . c om if (tok == null) return false; if (!"ROCK".equals(tok)) throw new IllegalStateException("Invalid token: [" + tok + "]"); final boolean isDark; { tok = readToken(in); if ("light".equals(tok)) isDark = false; else if ("dark".equals(tok)) isDark = true; else throw new IllegalStateException("Invalid token: [" + tok + "]"); } final int no = Byte.parseByte(readToken(in)) - 1; for (;;) { tok = readToken(in); if ("from".equals(tok)) { tok = readToken(in); if ("OUT".equals(tok)) ret.setOut(ret, isDark, no); else if ("RELEASE".equals(tok)) ret.setRelease(ret, isDark, no); else ret.setFrom(ret, isDark, no, tok, readToken(in)); } else if ("to".equals(tok)) { tok = readToken(in); if ("OUT".equals(tok)) { ret.setOut(ret, isDark, no); } else ret.setTo(ret, isDark, no, tok, readToken(in)); } else if ("speed".equals(tok)) ret.setSpeed(ret, isDark, no, readToken(in)); else if ("and".equals(tok)) ; else if ("with".equals(tok)) ; else if ("spin".equals(tok)) ret.setSpin(ret, isDark, no, readToken(in)); else if ("angle".equals(tok)) ret.setAngle(isDark, no, readToken(in)); else if ("DONE".equals(tok)) return true; else throw new IllegalStateException("Invalid token: [" + tok + "]"); } }
From source file:org.voltdb.CLIConfig.java
private void assignValueToField(Field field, String value) throws Exception { if ((value == null) || (value.length() == 0)) { return;//ww w .j a va 2s .c om } field.setAccessible(true); Class<?> cls = field.getType(); if ((cls == boolean.class) || (cls == Boolean.class)) field.set(this, Boolean.parseBoolean(value)); else if ((cls == byte.class) || (cls == Byte.class)) field.set(this, Byte.parseByte(value)); else if ((cls == short.class) || (cls == Short.class)) field.set(this, Short.parseShort(value)); else if ((cls == int.class) || (cls == Integer.class)) field.set(this, Integer.parseInt(value)); else if ((cls == long.class) || (cls == Long.class)) field.set(this, Long.parseLong(value)); else if ((cls == float.class) || (cls == Float.class)) field.set(this, Float.parseFloat(value)); else if ((cls == double.class) || (cls == Double.class)) field.set(this, Double.parseDouble(value)); else if ((cls == String.class)) field.set(this, value); else if (value.length() == 1 && ((cls == char.class) || (cls == Character.class))) field.set(this, value.charAt(0)); else { System.err.println( "Parsing failed. Reason: can not assign " + value + " to " + cls.toString() + " class"); printUsage(); System.exit(-1); } }