List of usage examples for java.lang String isEmpty
public boolean isEmpty()
From source file:Main.java
public static String getElementText(Element namedElement) { if (namedElement == null) { return null; }/*ww w .j av a 2 s . co m*/ String text = namedElement.getTextContent(); return (text.isEmpty()) ? null : text; }
From source file:Main.java
/** * Creates a flag for the given ABI.// ww w . j a va 2 s . co m * @param abi the ABI to create the flag for. * @return a string which can be add to a command sent to ADB. */ public static String createAbiFlag(String abi) { if (abi == null || abi.isEmpty() || !isAbiSupportedByCts(abi)) { return ""; } return String.format("--abi %s ", abi); }
From source file:Main.java
/** * Extracts the enum constant of the specified enum class with the * specified name. The name must match exactly an identifier used * to declare an enum constant in the given class. * * @param clazz the {@code Class} object of the enum type from which * to return a constant.//from w w w .j a v a 2s .c o m * @param name the name of the constant to return. * @return the enum constant of the specified enum type with the * specified name. * * @throws IllegalArgumentException if the specified enum type has * no constant with the specified name, or the specified * class object does not represent an enum type. * * @see {@link Enum#valueOf(Class, String)} */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static Object getEnumConstant(Class<?> clazz, String name) { if (clazz == null || name == null || name.isEmpty()) { return null; } return Enum.valueOf((Class<Enum>) clazz, name); }
From source file:Main.java
/** * Read a file and return as a String//from www . j av a2s . c om * * @param path the filepath to append the extension to * @param extension the extension to be appended * @return the string representing the filename with extension * @since 0.11.0 */ public static String addExtension(String path, String extension) { if (path == null || path.isEmpty()) { return ""; } if (extension == null || extension.isEmpty()) { return path; } return path + "." + extension; }
From source file:Main.java
/** * Checks if the passed String is null or empty * @param t object to check/*from w w w .ja v a 2 s . c o m*/ * @return boolean, true if it is null or empty, false if it is not. */ public static <T> boolean isNullOrEmpty(T t) { if (t == null) { return true; } String str = t.toString(); if (str.isEmpty()) { return true; } if (str.length() == 0) { return true; } return false; }
From source file:Main.java
public static <T> String concat(Collection<T> col, String separator) { StringBuilder result = new StringBuilder(); for (T e : col) { String s = e.toString(); if (!s.isEmpty()) { if (result.length() > 0) result.append(separator); result.append(s);/*from w ww . ja v a 2 s .c o m*/ } } return result.toString(); }
From source file:Main.java
public static String prettyFormat(String xml) { if (xml == null || xml.isEmpty() || !xml.contains("<")) { // System.out.println("Why?"+xml.startsWith("<", 0)); return xml; }// w w w . j ava 2 s . c o m try { Transformer serializer = SAXTransformerFactory.newInstance().newTransformer(); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); //serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); Source xmlSource = new SAXSource(new InputSource(new ByteArrayInputStream(xml.getBytes()))); StreamResult res = new StreamResult(new ByteArrayOutputStream()); serializer.transform(xmlSource, res); return new String(((ByteArrayOutputStream) res.getOutputStream()).toByteArray()).replace("><", ">\n<"); } catch (Exception e) { System.out.println("prettyFormat: Error.." + e.getMessage()); //TODO log error return xml.replace("<", "\n<"); // return xml.replace("><", ">\n<"); } }
From source file:Main.java
/** check if string is valid ipv4 */ public static boolean validIP(String ip) { if (ip == null || ip.isEmpty()) return false; ip = ip.trim();// w w w. j av a2 s.c o m if ((ip.length() < 6) & (ip.length() > 15)) return false; try { Pattern pattern = Pattern.compile( "^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"); Matcher matcher = pattern.matcher(ip); return matcher.matches(); } catch (Exception e) { return false; } }
From source file:Main.java
public static String serializeNamespaces(Map<String, String> namespaces) { String serialization = ""; for (Entry<String, String> entry : namespaces.entrySet()) { String localPart = entry.getKey(); String namespace = localPart.isEmpty() ? "xmlns" : ("xmlns:" + localPart); serialization = concatKeyValue(serialization, namespace, entry.getValue()); }/*w w w. j a va 2s . c om*/ return serialization; }
From source file:org.eclipse.dirigible.cli.utils.Utils.java
public static boolean isEmpty(String property) { return property == null || property.isEmpty(); }