List of usage examples for java.lang String isEmpty
public boolean isEmpty()
From source file:Main.java
public static String GetChildElementText(Element element, String name, String defaultValue) { if (element != null && name != null && !name.isEmpty()) { NodeList nodes = element.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node instanceof Element && name.equals(node.getNodeName())) { return node.getTextContent(); }/* www. ja v a 2 s .com*/ } } return defaultValue; }
From source file:com.lecaddyfute.utils.security.AESCrypto.java
public static Key generateKey() throws Exception { String cle = CLE; try {/*w w w . j a va 2 s . co m*/ if (cle.isEmpty()) { InetAddress adrLocale; adrLocale = InetAddress.getLocalHost(); cle = adrLocale.getHostName(); } if (cle.length() > 16) { cle = cle.substring(0, 16); } if (cle.length() < 16) { int chartocomplete = 16 - cle.length(); for (int i = 0; i < chartocomplete; i++) { cle = cle + i; } } logger.log(Level.INFO, "cle par defaut {0}", cle); keyValue = cle.getBytes(); } catch (Exception e) { e.printStackTrace(); } Key key = new SecretKeySpec(keyValue, ALGO); return key; }
From source file:Main.java
public static String getMiddleString(String source, String start, String end) { int start_idx = source.indexOf(start) + start.length(); int end_idx = 0; if (end.isEmpty()) { end_idx = source.length();/*from ww w . j a v a2 s . c o m*/ } else { end_idx = source.indexOf(end, start_idx); if (end_idx <= 0) { end_idx = source.length(); } } if (start_idx <= 0 || end_idx <= 0 || end_idx <= start_idx) { return null; } return source.substring(start_idx, end_idx); }
From source file:Main.java
private static String getFileExtensionFromUrl(String url) { if (!TextUtils.isEmpty(url)) { int fragment = url.lastIndexOf('#'); if (fragment > 0) { url = url.substring(0, fragment); }//from ww w .j a v a 2 s.co m int query = url.lastIndexOf('?'); if (query > 0) { url = url.substring(0, query); } int filenamePos = url.lastIndexOf('/'); String filename = 0 <= filenamePos ? url.substring(filenamePos + 1) : url; if (!filename.isEmpty()) { int dotPos = filename.lastIndexOf('.'); if (0 <= dotPos) { return filename.substring(dotPos + 1); } } } return ""; }
From source file:Main.java
/** * string convert to set//from ww w .j a va2s. c om */ public static Set<String> stringConvertToSet(String values, String separate) { if (values == null) { return null; } if (values.isEmpty()) { return Collections.EMPTY_SET; } String sp = TextUtils.isEmpty(separate) ? COMMA : separate; String[] sV = values.split(sp); Set<String> set = new HashSet<>(); for (String v : sV) { set.add(v); } return set; }
From source file:Main.java
public static List<String> createListFromDelimitedText(String delimitedText, String delimiter) { if (delimitedText == null) { return null; }// w w w .j av a2 s. com if (delimitedText.isEmpty() || delimiter == null || delimiter.isEmpty() || !delimitedText.contains(delimiter)) { return Arrays.asList(delimitedText); } else { return Arrays.asList(delimitedText.split(delimiter)); } }
From source file:fr.gael.dhus.olingo.v1.map.impl.ConnectionMap.java
/** * Returns a sub Map of the given map containing only AccessInformation about * the given user./*from ww w .jav a 2s.c o m*/ * @param map Access info map. * @param username to filter. * @return a new, filtered map. */ private static Map<UUID, AccessInformation> filterUser(Map<UUID, AccessInformation> map, String username) { if (username == null || username.isEmpty()) { return map; } Map<UUID, AccessInformation> res = new HashMap<>(); for (Entry<UUID, AccessInformation> ent : map.entrySet()) { String accessuser = ent.getValue().getUsername(); if (accessuser != null && accessuser.equals(username)) { res.put(ent.getKey(), ent.getValue()); } } return res; }
From source file:io.micrometer.core.instrument.util.StringUtils.java
/** * Check if the String is null or empty. * * @param string String to check//from ww w . j av a2 s .c o m * @return {@code true} if the String is null or empty */ public static boolean isEmpty(@Nullable String string) { return string == null || string.isEmpty(); }
From source file:Validation.java
public static Integer parseInt(String s) { if (s == null || s.isEmpty()) { return null; } else {//from ww w. jav a 2s .com return Integer.parseInt(s); } }
From source file:Main.java
public static Date parse(String dateFormatted, SimpleDateFormat dateFormat, boolean useUtc) { Date date = null;//from w w w.j a v a 2 s . c o m if (!dateFormatted.isEmpty()) { try { if (useUtc) { dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); } date = dateFormat.parse(dateFormatted); } catch (Exception e) { throw new RuntimeException( "Error parsing the dateFormatted: " + dateFormatted + " pattern: " + dateFormat.toPattern(), e); } } return date; }