/** * Return true if the the string is not empty. * * @param _in The string to test * @return true if the string is not null and not an empty string */ public static boolean isSet(String _in) { return !isEmpty(_in); }
private String toName(String component, String name) { if (MString.isEmpty(name)) return component; return component + "." + name; }
/** * Append the item to the end of the list using the separator. * If list is empty the item will be the first element. * * @param list The list of items * @param separator The item separator * @param item New item to append * @return The new list */ public static String append(String list, char separator, String item) { if (item == null) return list; if (MString.isEmpty(list)) return item; return list + separator + item; }
/** {@inheritDoc} */ @Override public boolean validate(FormControl control, LayoutElement element, Object value) { return (value != null && !MString.isEmpty(value.toString())); }
public static boolean isPhoneNumber(String phone, Locale locale) { if (MString.isEmpty(phone)) return false; //validate phone numbers of format "+123-456 7890" // 49 1234 123456 1234 => 19 Digits (max to 20) if (phone.startsWith("+")) phone = phone.substring(1); if (phone.length() < 4 || phone.length() > 20) return false; if (locale != null) { if ("US".equals(locale.getCountry())) { return phone.matches("^(\\([0-9]{3}\\) |[0-9]{3}-)[0-9]{3}-[0-9]{4}$"); } } return phone.matches("^[0-9| |\\-|/]*$"); }
public static File getFile(File parent, String path) { if (MString.isEmpty(path)) return null; path = path.trim(); if (path.startsWith("/")) return new File(path); if (path.startsWith("~")) return new File(getUserHome(), path); if (parent.isFile()) parent = parent.getParentFile(); return new File(parent, path); }
@Override public void doConfigureTrail(String config) { //if (backup == null) return; if (MString.isEmpty(config)) config = ThreadMapperConfig.MAP_LABEL; set(config); }
/** {@inheritDoc} */ @Override public void doConfigureTrail(String config) { //if (backup == null) return; if (MString.isEmpty(config)) config = ThreadMapperConfig.MAP_LABEL; set(config); }
public void showInformation(String msg) { if (MString.isEmpty(msg)) return; Notification.show(msg, Notification.Type.HUMANIZED_MESSAGE); }
/** * Append the item to the end of the list using the separator if not already exists. * If list is empty the item will be the first element. * * @param list The list of items * @param separator The item separator * @param item New item to append * @return The new list */ public static String set(String list, char separator, String item) { if (item == null) return list; if (MString.isEmpty(list)) return item; if (contains(list, separator, item)) return list; return list + separator + item; }
/** * Read a file into a list line by line * * @param file * @param removeLastEmpty If you have written line by line the last ENTER will produce an empty line, set true to remove this line. * @return the file content as list of lines * @throws IOException */ public static List<String> readLines(File file, boolean removeLastEmpty) throws IOException { if (file == null) return null; final LinkedList<String> out = new LinkedList<>(); readLines(file, new Observer() { @Override public void update(Observable o, Object arg) { out.add((String)arg); } }); if (removeLastEmpty && out.size() > 0 && MString.isEmpty(out.getLast())) out.removeLast(); return out; }
/** * Read an stream into a list line by line. The stream will not be closed. * * @param is * @param removeLastEmpty If you have written line by line the last ENTER will produce an empty line, set true to remove this line. * @return the file content as list of lines * @throws IOException */ public static List<String> readLines(InputStream is, boolean removeLastEmpty) throws IOException { if (is == null) return null; final LinkedList<String> out = new LinkedList<>(); readLines(is, new Observer() { @Override public void update(Observable o, Object arg) { out.add((String)arg); } }); if (removeLastEmpty && out.size() > 0 && MString.isEmpty(out.getLast())) out.removeLast(); return out; }
@Override public void setErrorMessage(String msg) { layout.setComponentError(MString.isEmpty(msg) ? null : new UserError(msg)); }
public static byte[] decode(String base64) { if (MString.isEmpty(base64)) { return new byte[0]; } int pad = 0; for (int i = base64.length() - 1; base64.charAt(i) == '='; i--) { pad++; } int length = (base64.length() * 6) / 8 - pad; byte[] raw = new byte[length]; int rawindex = 0; for (int i = 0; i < base64.length(); i += 4) { int block = getValue(base64.charAt(i)) << 18; block += getValue(base64.charAt(i + 1)) << 12; block += getValue(base64.charAt(i + 2)) << 6; block += getValue(base64.charAt(i + 3)); for (int j = 0; j < 3 && rawindex + j < raw.length; j++) { raw[rawindex + j] = (byte)(block >> 8 * (2 - j) & 0xff); } rawindex += 3; } return raw; }
@Override public void doInitialize(IApiInternal internal, CfgManager manager, IConfig config) { ResourceNode<?> system = manager.getCfg("system"); try { String key = MConstants.PROP_BASE_DIR; String name = system.getString(key); if (MString.isEmpty(name)) name = System.getProperty(MConstants.PROP_PREFIX + key); if (MString.isSet(name)) internal.setBaseDir( new File(name) ); } catch (Throwable t) {MApi.dirtyLog(t);} }
@Override protected IProperties loadValue() { ResourceNode<?> node = MApi.getCfg(getOwner(), null); if (node == null) return getDefault(); if (MString.isEmpty(getPath())) return node; return new PropertiesSubset(node, getPath()); }
protected void addToCurrent(VaadinFormBuilder builder) { if (!MString.isEmpty(getElement().getTitle())) { panel = new Panel(getElement().getTitle()); panel.setContent(layout); panel.setWidth("100%"); builder.addComposite((LayoutComposite)getElement(), panel); } else super.addToCurrent(builder); }
@Override public InternalDbConnection createConnection() throws Exception { // ResourceNode concon = config.getNode("connection"); String driver = config.getExtracted("driver"); String url = config.getExtracted("url"); String user = config.getExtracted("user"); String pass = config.getExtracted("pass"); if (!MString.isEmpty(driver)) { if (activator != null) activator.getClazz(driver); else Class.forName(driver); } log().t(driver,url,user); Connection con = DriverManager.getConnection(url,user,MPassword.decode(pass)); getDialect().prepareConnection(con); JdbcConnection dbCon = new JdbcConnection(this,con); long timeoutUnused = MPeriod.toMilliseconds( config.getExtracted("timeout_unused"), 0 ); long timeoutLifetime = MPeriod.toMilliseconds( config.getExtracted("timeout_lifetime"), 0 ); if (timeoutUnused > 0) dbCon.setTimeoutUnused(timeoutUnused); if (timeoutLifetime > 0) dbCon.setTimeoutLifetime(timeoutLifetime); return dbCon; }
/** * <p>doBuildUi.</p> * * @param element a {@link de.mhus.lib.form.LayoutElement} object. * @return a {@link de.mhus.lib.form.UiElement} object. * @throws java.lang.Exception if any. */ public UiElement doBuildUi(LayoutElement element) throws Exception { try { UiElement out = null; if (MString.isEmpty(element.getType())) { try { out = getActivator().createObject(UiElement.class,element.getConfig().getName()); } catch (ClassNotFoundException | InstantiationException cnf) { log().i(element.getConfig().getName(),cnf.toString()); } } else { out = getActivator().createObject(UiElement.class,element.getType()); } return out; } catch (Throwable t) { throw new MException("build failed", element.getConfig().getName(), element.getType(), t); } } }