/** * The inverse of {@link #isBlank(CharSequence)}. * * @param s the String to check * @return true if non blank, false otherwise. * * @see #isEmpty(CharSequence) * @see #isNonEmpty(CharSequence) * @see #isBlank(CharSequence) */ public static boolean isNonBlank(CharSequence s) { return !isBlank(s); }
public void setName(String name) { if (Strings.isBlank(name)) { throw new IllegalArgumentException("Invalid name "+(name == null ? "null" : "'"+name+"'")+"; name must be non-empty and not just white space"); } this.name = name; this.simpleName = toSimpleName(name); snapshotValid.set(false); }
@Override public String getHostname() { String result = getAttribute(MANAGED_DOMAIN); return (Strings.isBlank(result)) ? null : result; }
private String toSimpleName(String name) { String simpleName = name.substring(name.lastIndexOf(".")+1); if (Strings.isBlank(simpleName)) simpleName = name.trim(); return Strings.makeValidFilename(simpleName); }
@Override public String apply(@Nullable DownloadRequirement req) { DownloadTargets targets = producer.apply(req); List<String> primaryTargets = targets.getPrimaryLocations(); for (String primaryTarget : primaryTargets) { String result = inferFilename(primaryTarget); if (!Strings.isBlank(result)) return result; } return null; } };
/** returns a simplified name of the class, just the simple name if it seems useful, else the full name */ public static String simpleClassName(Class<?> t) { int arrayCount = 0; while (t.isArray()) { arrayCount++; t = t.getComponentType(); } Class<?> ct = componentType(t); String result = ct.getSimpleName(); if (Strings.isBlank(result) || result.length()<=4) { if (ct.isPrimitive()) { // TODO unbox } else { result = ct.getName(); } } return result+Strings.repeat("[]", arrayCount); }
public Cidr(String cidr) { if (Strings.isBlank(cidr)) // useful e.g. if user leaves it blank in gui cidr = "0.0.0.0/0"; int slash = cidr.indexOf('/'); if (slash==-1) throw new IllegalArgumentException("CIDR should be of form 192.168.0.0/16 (missing slash)"); String subnet = cidr.substring(0, slash); String lengthS = cidr.substring(slash+1); this.length = Integer.parseInt(lengthS); String[] bytes = subnet.split("\\."); int i=0; for (; i<this.length/8; i++) subnetBytes[i] = Integer.parseInt(bytes[i]); for (; i<(this.length+7)/8; i++) // for fractional parts: reverse significance, trim, reverse back subnetBytes[i] = BitUtils.unsigned( BitUtils.reverseBitSignificanceInByte( BitList.newInstanceFromBytes(BitUtils.reverseBitSignificanceInByte(Integer.parseInt(bytes[i]))). resized(this.length % 8).intValue() )); }
for (Function<? super DownloadRequirement, String> filenameProducer : filenameProducers) { filename = filenameProducer.apply(req); if (!Strings.isBlank(filename)) break; for (String target : result) { filename = FilenameProducers.inferFilename(target); if (!Strings.isBlank(filename)) break; if (Strings.isBlank(filename)) { throw new IllegalArgumentException("No filenames matched for "+req+" (targets "+result+")");
public String getSocketUid() { String result = getAttribute(MySqlNode.SOCKET_UID); if (Strings.isBlank(result)) { result = Identifiers.makeRandomId(6); setAttribute(MySqlNode.SOCKET_UID, result); } return result; }
public String getSocketUid() { String result = getAttribute(MariaDbNode.SOCKET_UID); if (Strings.isBlank(result)) setAttribute(MariaDbNode.SOCKET_UID, (result = Identifiers.makeRandomId(6))); return result; }
public String getPassword() { String result = getAttribute(MySqlNode.PASSWORD); if (Strings.isBlank(result)) { result = Identifiers.makeRandomId(6); setAttribute(MySqlNode.PASSWORD, result); } return result; }
public String getPassword() { String result = getAttribute(MariaDbNode.PASSWORD); if (Strings.isBlank(result)) setAttribute(MariaDbNode.PASSWORD, (result = Identifiers.makeRandomId(6))); return result; }
private void copyDatabaseCreationScript() { newScript(CUSTOMIZING). body.append("echo copying creation script"). execute(); //create the directory Reader creationScript; String url = entity.getConfig(MySqlNode.CREATION_SCRIPT_URL); if (!Strings.isBlank(url)) creationScript = new InputStreamReader(resource.getResourceFromUrl(url)); else creationScript = new StringReader((String) elvis(entity.getConfig(MySqlNode.CREATION_SCRIPT_CONTENTS), "")); getMachine().copyTo(creationScript, getRunDir() + "/creation-script.cnf"); }
private void copyDatabaseCreationScript() { newScript(CUSTOMIZING). body.append("echo copying creation script"). execute(); //create the directory Reader creationScript; String url = entity.getConfig(MariaDbNode.CREATION_SCRIPT_URL); if (!Strings.isBlank(url)) creationScript = new InputStreamReader(new ResourceUtils(entity).getResourceFromUrl(url)); else creationScript = new StringReader((String) elvis(entity.getConfig(MariaDbNode.CREATION_SCRIPT_CONTENTS), "")); getMachine().copyTo(creationScript, getRunDir() + "/creation-script.cnf"); }
if (Strings.isBlank(locations)) { if (app != null) { System.err.println("Locations parameter not supplied: assuming localhost"); .webconsole(!noConsole) .shutdownOnExit(!noShutdownOnExit) .locations(Strings.isBlank(locations) ? ImmutableList.<String>of() : ImmutableList.of(locations)); if (noConsoleSecurity) { launcher.installSecurityFilter(false);
@Override protected void preStart() { String reverse = getConfig(REVERSE_LOOKUP_NETWORK); if (Strings.isBlank(reverse)) reverse = getAttribute(ADDRESS); setAttribute(REVERSE_LOOKUP_CIDR, new Cidr(reverse + "/24")); String reverseLookupDomain = Joiner.on('.').join(Iterables.skip(Lists.reverse(Lists.newArrayList(Splitter.on('.').split(reverse))), 1)) + ".in-addr.arpa"; setAttribute(REVERSE_LOOKUP_DOMAIN, reverseLookupDomain); Map<?, ?> flags = MutableMap.builder() .put("name", "Address tracker") .put("sensorsToTrack", ImmutableSet.of(getConfig(HOSTNAME_SENSOR))) .build(); policy = new AbstractMembershipTrackingPolicy(flags) { @Override protected void onEntityChange(Entity member) { added(member); } @Override protected void onEntityAdded(Entity member) { if (Strings.isNonBlank(member.getAttribute(getConfig(HOSTNAME_SENSOR)))) added(member); // Ignore, unless hostname set } @Override protected void onEntityRemoved(Entity member) { removed(member); } }; // For any entities that have already come up for (Entity member : entities.getMembers()) { if (Strings.isNonBlank(member.getAttribute(getConfig(HOSTNAME_SENSOR)))) added(member); // Ignore, unless hostname set } addPolicy(policy); policy.setGroup(entities); }
if (isMac) withLdOpt = format("-L%s/pcre-dist/lib", getInstallDir()) + (Strings.isBlank(withLdOpt) ? "" : " " + withLdOpt); String withCcOpt = entity.getConfig(NginxController.WITH_CC_OPT); " --with-http_ssl_module" + (sticky ? format(" --add-module=%s ", stickyModuleExpandedInstallDir) : "") + (!Strings.isBlank(withLdOpt) ? format(" --with-ld-opt=\"%s\"", withLdOpt) : "") + (!Strings.isBlank(withCcOpt) ? format(" --with-cc-opt=\"%s\"", withCcOpt) : "") , "make install"));