@Override public String toString() { return "join \"" + StringUtilities.escape(delimiter, '"') + "\""; }
private Set<String> toHostnameSet(String hostnamesString) { Set<String> hostnames = new HashSet<>(); for (String hostname : StringUtilities.split(hostnamesString)) { if ( ! hostname.trim().isEmpty()) hostnames.add(hostname.trim()); } return hostnames; }
final public String string() throws ParseException { jj_consume_token(STRING); {if ("" != null) return StringUtilities.unescape(token.image.substring(1, token.image.length() - 1));} throw new IllegalStateException ("Missing return statement in function"); }
private Path nestedResource(final com.yahoo.path.Path nestedPath, final String name, final String fileType) { String nameWithoutSuffix = StringUtilities.stripSuffix(name, fileType); return path.resolve(nestedPath.getRelative()).resolve(nameWithoutSuffix + fileType); }
/** * Checks what this is a producer of, instantiate that and export to writer */ // TODO move to ReflectionUtil, and move that to unexported pkg private void exportBuilderConfig(Writer writer) throws ReflectiveOperationException, SecurityException, IllegalArgumentException, IOException { for (Class<?> intf : getClass().getInterfaces()) { if (ConfigInstance.Producer.class.isAssignableFrom(intf)) { Class<?> configClass = intf.getEnclosingClass(); String builderClassName = configClass.getCanonicalName()+"$Builder"; Class<?> builderClass = Class.forName(builderClassName); ConfigInstance.Builder builder = (Builder) builderClass.getDeclaredConstructor().newInstance(); Method getConfig = getClass().getMethod("getConfig", builderClass); getConfig.invoke(this, builder); ConfigInstance inst = (ConfigInstance) configClass.getConstructor(builderClass).newInstance(builder); List<String> payloadL = ConfigInstance.serialize(inst); String payload = StringUtilities.implodeMultiline(payloadL); writer.write(payload); } } }
/** * Returns the given list flattened to one with newline between * * @return flattened string */ public static String implodeMultiline(List<String> lines) { if (lines==null) return null; return implode(lines.toArray(new String[0]), "\n"); }
/** * This will truncate sequences in a string of the same character that exceed the maximum * allowed length. * * @return The same string or a new one if truncation is done. */ public static String truncateSequencesIfNecessary(String text, int maxConsecutiveLength) { char prev = 0; int sequenceCount = 1; for (int i = 0, m = text.length(); i < m ; i++) { char curr = text.charAt(i); if (prev == curr) { sequenceCount++; if (sequenceCount > maxConsecutiveLength) { return truncateSequences(text, maxConsecutiveLength, i); } } else { sequenceCount = 1; prev = curr; } } return text; }
private static void populateConfigBuilder(Builder builder, ConfigProducer configProducer) { boolean found = configProducer.cascadeConfig(builder); boolean foundOverride = configProducer.addUserConfig(builder); log.log(LogLevel.DEBUG, () -> "Trying to get config for " + builder.getClass().getDeclaringClass().getName() + " for config id " + quote(configProducer.getConfigId()) + ", found=" + found + ", foundOverride=" + foundOverride); }
private Path nestedResource(com.yahoo.path.Path nestedPath, String name, String fileType) { ensureNotAlreadyBuild(); String nameWithoutSuffix = StringUtilities.stripSuffix(name, fileType); return applicationDir.resolve(nestedPath.getRelative()).resolve(nameWithoutSuffix + fileType); }
private static void writeConfig(String dir, String configName, ConfigInstance config) throws IOException { IOUtils.writeFile(dir + configName, StringUtilities.implodeMultiline(ConfigInstance.serialize(config)), false); }
public ReplacementCharacters() { for (int i=0; i<256; ++i) { if (i >= 32 && i <= 126) { needEscape[i] = 0; } else { needEscape[i] = 3; replacement1[i] = toHex((i >> 4) & 0xF); replacement2[i] = toHex(i & 0xF); } } makeSimpleEscape('"', '"'); makeSimpleEscape('\\', '\\'); makeSimpleEscape('\t', 't'); makeSimpleEscape('\n', 'n'); makeSimpleEscape('\r', 'r'); makeSimpleEscape('\f', 'f'); }
public static String escape(String source) { return escape(source, '\0'); }
/** Returns a host filter from three comma and-or space separated string lists. The strings may be null or empty. */ public static HostFilter from(String hostNames, String flavors, String clusterTypes, String clusterIds) { return new HostFilter( StringUtilities.split(hostNames), StringUtilities.split(flavors), StringUtilities.split(clusterTypes).stream().map(ClusterSpec.Type::from).collect(Collectors.toSet()), StringUtilities.split(clusterIds).stream().map(ClusterSpec.Id::from).collect(Collectors.toSet())); }
case 'm': if (key.length() > 1) break; description = StringUtilities.unescape(value); continue; default:
@Override public String toString() { return "split \"" + StringUtilities.escape(splitPattern.toString(), '"') + "\""; }
/** Returns a node filter which matches a comma or space-separated list of types */ public static NodeTypeFilter from(String types, NodeFilter next) { return new NodeTypeFilter(StringUtilities.split(types).stream().map(NodeType::valueOf).collect(Collectors.toSet()), next); }
case 'm': if (key.length() > 1) break; setDescription(StringUtilities.unescape(value)); continue; case 'd':
@Override public String toString() { StringBuilder ret = new StringBuilder(); ret.append("switch { "); for (Map.Entry<String, Expression> entry : cases.entrySet()) { ret.append("case \"").append(StringUtilities.escape(entry.getKey(), '"')).append("\": "); Expression exp = entry.getValue(); ret.append(exp).append("; "); } if (defaultExp != null) { ret.append("default: ").append(defaultExp).append("; "); } ret.append("}"); return ret.toString(); }
/** Returns a copy of the given filter which only matches for the given parent */ public static ParentHostFilter from(String parentNames, NodeFilter filter) { return new ParentHostFilter(StringUtilities.split(parentNames).stream().collect(Collectors.toSet()), filter); }