List of usage examples for java.lang Boolean parseBoolean
public static boolean parseBoolean(String s)
From source file:net.sf.zekr.engine.search.SearchScopeItem.java
public static SearchScopeItem parse(String ssi) { if (StringUtils.isBlank(ssi)) { return null; }//from w w w . ja v a 2 s . c o m String[] s = StringUtils.split(ssi, "-"); if (s.length < 4) { return null; } else { boolean exclusive = false; if (s.length >= 5) { exclusive = Boolean.parseBoolean(s[4]); } return new SearchScopeItem(Integer.parseInt(s[0]), Integer.parseInt(s[1]), Integer.parseInt(s[2]), Integer.parseInt(s[3]), exclusive); } }
From source file:Main.java
public static boolean getBooleanAttribute(@NonNull Context context, @NonNull AttributeSet attrs, @NonNull String name, boolean defaultValue) { String boolText = getAttribute(context, attrs, name, null); if (boolText != null) return Boolean.parseBoolean(boolText); else//w w w . j av a 2 s.co m return defaultValue; }
From source file:Main.java
/** * Get the value of "io.branch.sdk.TestMode" entry in application manifest or from String res. * * @return value of "io.branch.sdk.TestMode" entry in application manifest or String res. * false if "io.branch.sdk.TestMode" is not added in the manifest or String res. *//* ww w .ja va 2 s . co m*/ public static boolean isTestModeEnabled(Context context) { if (isCustomDebugEnabled_) { return isCustomDebugEnabled_; } boolean isTestMode_ = false; String testModeKey = "io.branch.sdk.TestMode"; try { final ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); if (ai.metaData != null && ai.metaData.containsKey(testModeKey)) { isTestMode_ = ai.metaData.getBoolean(testModeKey, false); } else { Resources resources = context.getResources(); isTestMode_ = Boolean.parseBoolean(resources .getString(resources.getIdentifier(testModeKey, "string", context.getPackageName()))); } } catch (Exception ignore) { } return isTestMode_; }
From source file:Main.java
/** * Retrieves an attribute as a boolean.//from w ww .j a v a 2 s . c o m * * @param node * @param attr * @param def * @return True if the attribute exists and is not equal to "false" * false if equal to "false", and def if not present. */ public static boolean getBoolAttribute(Node node, String attr, boolean def) { String value = getAttribute(node, attr); if (value == null) { return def; } return Boolean.parseBoolean(value); }
From source file:com.act.biointerpretation.mechanisminspection.ReactionRenderer.java
public static void main(String[] args) throws IOException { Options opts = new Options(); for (Option.Builder b : OPTION_BUILDERS) { opts.addOption(b.build());/*from w w w. j a va 2 s . c o m*/ } CommandLine cl = null; try { CommandLineParser parser = new DefaultParser(); cl = parser.parse(opts, args); } catch (ParseException e) { System.err.format("Argument parsing failed: %s\n", e.getMessage()); HELP_FORMATTER.printHelp(ReactionRenderer.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } if (cl.hasOption("help")) { HELP_FORMATTER.printHelp(ReactionRenderer.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); return; } Integer height = Integer.parseInt(cl.getOptionValue(OPTION_HEIGHT, "1000")); Integer width = Integer.parseInt(cl.getOptionValue(OPTION_WIDTH, "1000")); Boolean representCofactors = cl.hasOption(OPTION_COFACTOR) && Boolean.parseBoolean(cl.getOptionValue(OPTION_COFACTOR)); NoSQLAPI api = new NoSQLAPI(cl.getOptionValue(OPTION_READ_DB), cl.getOptionValue(OPTION_READ_DB)); for (String val : cl.getOptionValues(OPTION_RXN_IDS)) { Long reactionId = Long.parseLong(val); ReactionRenderer renderer = new ReactionRenderer(cl.getOptionValue(OPTION_FILE_FORMAT), width, height); renderer.drawReaction(api.getReadDB(), reactionId, cl.getOptionValue(OPTION_DIR_PATH), representCofactors); LOGGER.info(renderer.getSmartsForReaction(api.getReadDB(), reactionId, representCofactors)); } }
From source file:com.whizzosoftware.hobson.json.TypedPropertyValueSerializer.java
static public Object createValueObject(TypedProperty.Type type, Object jsonValue, PropertyContextProvider cp) { switch (type) { case BOOLEAN: if (jsonValue instanceof Boolean) { return jsonValue; } else if (jsonValue instanceof String) { if ("true".equalsIgnoreCase((String) jsonValue) || "false".equalsIgnoreCase((String) jsonValue)) { return Boolean.parseBoolean((String) jsonValue); } else { throw new HobsonInvalidRequestException( "Boolean property is not a JSON string with \"true\" or \"false\":" + jsonValue); }/* ww w .j a v a 2s. c o m*/ } else { throw new HobsonInvalidRequestException( "Boolean property is not a valid JSON boolean: " + jsonValue); } case NUMBER: if (jsonValue instanceof Double || jsonValue instanceof Integer) { return jsonValue; } else if (jsonValue instanceof String) { try { return Double.parseDouble((String) jsonValue); } catch (NumberFormatException e) { throw new HobsonInvalidRequestException("Number property is not a valid number: " + jsonValue); } } else { throw new HobsonInvalidRequestException("Number property is not a valid JSON number: " + jsonValue); } case STRING: if (jsonValue instanceof String) { return jsonValue; } else if (jsonValue instanceof Integer || jsonValue instanceof Double || jsonValue instanceof Boolean) { return jsonValue.toString(); } else if (JSONObject.NULL.equals(jsonValue)) { return null; } else { throw new HobsonInvalidRequestException("String property is not a valid JSON string: " + jsonValue); } case DEVICE: if (jsonValue instanceof JSONObject) { return createDeviceValueObject((JSONObject) jsonValue, cp); } else { throw new HobsonInvalidRequestException("Device property is not a JSON object: " + jsonValue); } case DEVICES: if (jsonValue instanceof JSONArray) { return createDevicesValueObject((JSONArray) jsonValue, cp); } else { throw new HobsonInvalidRequestException("Devices property is not a JSON array: " + jsonValue); } case PRESENCE_ENTITY: if (jsonValue instanceof JSONObject) { JSONObject json = (JSONObject) jsonValue; return cp.createPresenceEntityContext(json.getString(JSONAttributes.AID)); } else { throw new HobsonInvalidRequestException( "Presence entity property is not a JSON object: " + jsonValue); } case LOCATION: if (jsonValue instanceof JSONObject) { JSONObject json = (JSONObject) jsonValue; return cp.createPresenceLocationContext(json.getString(JSONAttributes.AID)); } else { throw new HobsonInvalidRequestException( "Presence location property is not a JSON object: " + jsonValue); } default: return jsonValue.toString(); } }
From source file:com.zotoh.core.util.DataUte.java
/** * @param obj/*from ww w. ja v a 2 s.co m*/ * @return */ public static boolean toBoolean(Object obj) { if (isNull(obj)) throw new RuntimeException("Null object conversion not allowed"); if (obj instanceof Boolean) { return (Boolean) obj; } else { return Boolean.parseBoolean(obj.toString()); } }
From source file:Main.java
public static boolean getBooleanAttribute(Node n, String s) { return Boolean.parseBoolean(getAttribute(n, s)); }
From source file:Main.java
@TargetApi(4) public static boolean isTabletDevice(android.content.Context activityContext) { if (!androidAPIover(4)) //VERSION return false; //If there is a tablet running 1.5.....GOD HELP YOU try {//from w ww .j av a2s. c om // Verifies if the Generalized Size of the device is XLARGE to be // considered a Tablet Configuration config = activityContext.getResources().getConfiguration(); Log.i("screenlayout", Integer.parseInt( Configuration.class.getDeclaredField("SCREENLAYOUT_SIZE_LARGE").get(config).toString()) + "!!!"); boolean xlarge = //activityContext.getResources().getConfiguration().screenLayout & Boolean.parseBoolean(config.getClass().getField("screenLayout").get(config).toString()) & getStaticInt(config, "SCREENLAYOUT_SIZE_MASK") >= //Changed this from == to >= because my tablet was returning 8 instead of 4. Integer.parseInt(Configuration.class.getDeclaredField("SCREENLAYOUT_SIZE_LARGE") .get(config).toString()); getStaticInt(config, "SCREENLAYOUT_SIZE_MASK"); // If XLarge, checks if the Generalized Density is at least MDPI (160dpi) if (xlarge) { android.util.DisplayMetrics metrics = new android.util.DisplayMetrics(); Activity activity = (Activity) activityContext; activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); //This next block lets us get constants that are not available in lower APIs. // If they aren't available, it's safe to assume that the device is not a tablet. // If you have a tablet or TV running Android 1.5, what the fuck is wrong with you. int xhigh = -1, tv = -1; try { Field f = android.util.DisplayMetrics.class.getDeclaredField("DENSITY_XHIGH"); xhigh = (Integer) f.get(null); f = android.util.DisplayMetrics.class.getDeclaredField("DENSITY_TV"); xhigh = (Integer) f.get(null); } catch (Exception e) { } // MDPI=160, DEFAULT=160, DENSITY_HIGH=240, DENSITY_MEDIUM=160, DENSITY_TV=213, DENSITY_XHIGH=320 int densityDpi = Integer .parseInt(metrics.getClass().getDeclaredField("densityDpi").get(metrics).toString()); if (densityDpi == 240 || //DENSITY_HIGH densityDpi == 160 || //DENSITY_MEDIUM //densityDpi == android.util.DisplayMetrics.DENSITY_DEFAULT || //densityDpi == android.util.DisplayMetrics.DENSITY_HIGH || //densityDpi == android.util.DisplayMetrics.DENSITY_MEDIUM || densityDpi == tv || densityDpi == xhigh) { return true; } } } catch (Exception e) { } return false; }
From source file:Main.java
/** * Returns the boolean value of the text content for the child element with the specified name * for the specified element./*from w w w.j a v a 2 s . com*/ * * @param element the parent element * @param name the name of the child element to return * * @return the boolean value of the text content for the child element or <code>null</code> if a * child element with the specified name could not be found */ public static Boolean getChildElementBoolean(Element element, String name) { NodeList nodeList = element.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node instanceof Element) { Element childElement = (Element) node; if (childElement.getNodeName().equals(name)) { try { return Boolean.parseBoolean(childElement.getTextContent()); } catch (Throwable e) { throw new RuntimeException("Failed to parse the invalid boolean value (" + childElement.getTextContent() + ")"); } } } } return null; }