Java Code Examples for java.util.StringJoiner#add()

The following examples show how to use java.util.StringJoiner#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnalysisResult.java    From macrobase with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
    String ret = String.format("outliers: %f\n" +
                               "inliers: %f\n" +
                               "load time %dms\n" +
                               "execution time: %dms\n" +
                               "summarization time: %dms\n\n",
                               numOutliers,
                               numInliers,
                               loadTime,
                               executionTime,
                               summarizationTime);

    final String sep = "-----\n\n";
    StringJoiner joiner = new StringJoiner(sep);
    for (ItemsetResult result : itemSets) {
        joiner.add(result.prettyPrint());
    }

    return ret + sep + joiner.toString() + sep;
}
 
Example 2
Source File: XACMLProperties.java    From XACML with MIT License 6 votes vote down vote up
/**
 * Set the properties to ensure it points to correct referenced policy files. This will overwrite
 * any previous properties set for referenced policies.
 *
 * @param properties Properties object that will get updated with referenced policy details
 * @param referencedPolicies list of Paths to referenced Policies
 * @return Properties object passed in
 */
public static Properties setXacmlReferencedProperties(Properties properties, Path... referencedPolicies) {
    //
    // Clear out the old entries
    //
    clearPolicyProperties(properties, XACMLProperties.PROP_REFERENCEDPOLICIES);
    //
    // Rebuild the list
    //
    int id = 1;
    StringJoiner joiner = new StringJoiner(",");
    for (Path policy : referencedPolicies) {
        String ref = "ref" + id++;
        joiner.add(ref);
        properties.setProperty(ref + FILE_APPEND, policy.toAbsolutePath().toString());
    }
    properties.setProperty(XACMLProperties.PROP_REFERENCEDPOLICIES, joiner.toString());
    return properties;
}
 
Example 3
Source File: EquipmentTypeLookupTest.java    From megamek with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void allLookupKeysValid() throws IllegalAccessException {
    // Collect all failed fields so the test results will show which field(s) failed
    final StringJoiner sj = new StringJoiner(", ");

    for (Field field : EquipmentTypeLookup.class.getFields()) {
        if (field.isAnnotationPresent(EquipmentTypeLookup.EquipmentName.class)
                && ((field.getModifiers() & Modifier.STATIC) == Modifier.STATIC)) {
            String eqName = field.get(null).toString();
            if (EquipmentType.get(eqName) == null) {
                sj.add(eqName);
            }
        }
    }

    assertEquals("", sj.toString());
}
 
Example 4
Source File: ObjectJoiner.java    From GreenSummer with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Join.
 *
 * @param separator the string to use as separator
 * @param arguments the array of objects (varargs) to join
 * @return the string resulting from joining the arguments (.toString()) together separated by the separator
 */
public static String join(CharSequence separator, Object... arguments) {
    StringJoiner st = new StringJoiner(separator);
    if (arguments != null) {
        for (Object object : arguments) {
            if (object != null) {
                if (object instanceof String) {
                    st.add((String) object);
                } else {
                    st.add(object.toString());
                }
            }
        }
    }
    return st.toString();
}
 
Example 5
Source File: CRSBuilder.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Removes and returns a {@link GeoKeys} value as a character string, or {@code null} if none.
 * Value for the given key should be a sequence of characters. If it is one or more numbers instead,
 * then this method formats those numbers in a comma-separated list. Such sequence of numbers would
 * be unusual, but we do see strange GeoTIFF files in practice.
 *
 * <p>See {@link #getSingleton(short)} for a discussion about why the value is removed from the map.</p>
 *
 * @param  key  the GeoTIFF key for which to get a value.
 * @return a string representation of the value for the given key, or {@code null} if the key was not found.
 */
private String getAsString(final short key) {
    Object value = geoKeys.remove(key);
    if (value != null) {
        if (value.getClass().isArray()) {
            final int length = Array.getLength(value);
            final StringJoiner buffer = new StringJoiner(", ");
            for (int i=0; i<length; i++) {
                buffer.add(String.valueOf(Array.get(value, i)));
            }
            value = buffer;
        }
        return value.toString();
    }
    return null;
}
 
Example 6
Source File: CodeGenerator.java    From avro-util with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Schema createEnumSchema(Class<? extends Enum> clazz) {
    String fqcn = clazz.getCanonicalName();

    StringJoiner csv = new StringJoiner(", ");
    for (Enum value : clazz.getEnumConstants()) {
        csv.add("\"" + value.name() + "\"");
    }

    String template;
    Map<String, String> params = new HashMap<>();
    params.put("symbols", csv.toString());
    if (fqcn.contains(".")) {
        //has namespace (package name)
        template = ENUM_SCHEMA_TEMPLATE;
        params.put("name", fqcn.substring(fqcn.lastIndexOf('.') + 1));
        params.put("namespace", fqcn.substring(0, fqcn.lastIndexOf('.')));
    } else {
        template = ENUM_SCHEMA_NO_NAMESPACE_TEMPLATE;
        params.put("name", fqcn);
    }
    String avsc = TemplateUtil.populateTemplate(template, params);
    return AvroCompatibilityHelper.parse(avsc);
}
 
Example 7
Source File: Constructor.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
@Override
String toShortString() {
    StringBuilder sb = new StringBuilder("constructor ");
    sb.append(getDeclaringClass().getTypeName());
    sb.append('(');
    StringJoiner sj = new StringJoiner(",");
    for (Class<?> parameterType : getParameterTypes()) {
        sj.add(parameterType.getTypeName());
    }
    sb.append(sj);
    sb.append(')');
    return sb.toString();
}
 
Example 8
Source File: LuZoneState.java    From theta with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
	final StringJoiner sj = new StringJoiner("\n");
	sj.add(zone.toString());
	if (!boundFunc.getLowerVars().isEmpty()) {
		sj.add("L:");
		boundFunc.getLowerVars().forEach(c -> sj.add(c.getName() + " <- " + boundFunc.getLower(c).get()));
	}
	if (!boundFunc.getUpperVars().isEmpty()) {
		sj.add("U:");
		boundFunc.getUpperVars().forEach(c -> sj.add(c.getName() + " <- " + boundFunc.getUpper(c).get()));
	}
	return sj.toString();
}
 
Example 9
Source File: EventHandlerChain.java    From disruptor-spring-manager with MIT License 5 votes vote down vote up
/**
 * Print event processor dependency graph.
 * 
 */
public String printDependencyGraph() {
	StringJoiner str = new StringJoiner(" | ", "{", "}");
	//print current Event handlers
	printEventHandlers(str, getCurrentEventHandlers());
	
	//print dependent Event handlers
	if(! ArrayUtils.isEmpty(getNextEventHandlers())){
		str.add(" -> ");	
		printEventHandlers(str, getNextEventHandlers());
	}
	return str.toString();
}
 
Example 10
Source File: CloudSpannerArray.java    From spanner-jdbc with MIT License 5 votes vote down vote up
@Override
public String toString() {
  StringJoiner joiner = new StringJoiner(",", "{", "}");
  if (data != null) {
    for (Object o : (Object[]) data) {
      if (o == null) {
        joiner.add("null");
      } else {
        joiner.add(o.toString());
      }
    }
  }
  return joiner.toString();
}
 
Example 11
Source File: Joined.java    From cactoos with MIT License 5 votes vote down vote up
/**
 * Ctor.
 * @param delimit Delimit among texts
 * @param txts Texts to be joined
 */
public Joined(final Text delimit, final Iterable<? extends Text> txts) {
    super((Scalar<String>) () -> {
        final StringJoiner joint =
            new StringJoiner(delimit.asString());
        for (final Text text : txts) {
            joint.add(text.asString());
        }
        return joint.toString();
    });
}
 
Example 12
Source File: TypesJavaValidator.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected String prettyPrintTypes(List<TypeParameter> typeParameters) {
	StringJoiner joiner = new StringJoiner(", ");
	for (TypeParameter typeParameter : typeParameters) {
		joiner.add(typeParameter.getName());
	}
	return "<" + joiner.toString() + ">";
}
 
Example 13
Source File: StringJoinerTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
void addAlladd() {
    StringJoiner sj = new StringJoiner(DASH, "{", "}");

    ArrayList<String> firstOne = new ArrayList<>();
    firstOne.add(ONE);
    firstOne.add(TWO);
    firstOne.stream().forEachOrdered(sj::add);

    sj.add(THREE);

    String expected = "{"+ONE+DASH+TWO+DASH+THREE+"}";
    assertEquals(sj.toString(), expected);
}
 
Example 14
Source File: TetheringConfiguration.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public String toString() {
    final StringJoiner sj = new StringJoiner(" ");
    sj.add(String.format("tetherableUsbRegexs:%s", makeString(tetherableUsbRegexs)));
    sj.add(String.format("tetherableWifiRegexs:%s", makeString(tetherableWifiRegexs)));
    sj.add(String.format("tetherableBluetoothRegexs:%s",
            makeString(tetherableBluetoothRegexs)));
    sj.add(String.format("isDunRequired:%s", isDunRequired));
    sj.add(String.format("chooseUpstreamAutomatically:%s", chooseUpstreamAutomatically));
    sj.add(String.format("preferredUpstreamIfaceTypes:%s",
            makeString(preferredUpstreamNames(preferredUpstreamIfaceTypes))));
    sj.add(String.format("provisioningApp:%s", makeString(provisioningApp)));
    sj.add(String.format("provisioningAppNoUi:%s", provisioningAppNoUi));
    return String.format("TetheringConfiguration{%s}", sj.toString());
}
 
Example 15
Source File: JAXPPolicyManager.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String toString() {
    StringJoiner sj = new StringJoiner("\n", "policy: ", "");
    Enumeration<Permission> perms = permissions.elements();
    while (perms.hasMoreElements()) {
        sj.add(perms.nextElement().toString());
    }
    return sj.toString();

}
 
Example 16
Source File: EventTypeInfo.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a string description of this {@link EventTypeInfo}.
 *
 * @return description, not {@code null}
 */
@Override
public String toString() {
    Stringifier s = new Stringifier();
    s.add("id", id);
    s.add("name", name);
    s.add("label", label);
    s.add("description", description);
    StringJoiner sj = new StringJoiner(", ", "{", "}");
    for (String categoryName : categoryNames) {
        sj.add(categoryName);
    }
    s.add("category", sj.toString());
    return s.toString();
}
 
Example 17
Source File: BaseLNPTestCase.java    From teammates with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Converts the list of {@code values} to a CSV row.
 * @return A single string containing {@code values} separated by pipelines and ending with newline.
 */
private String convertToCsv(List<String> values) {
    StringJoiner csvRow = new StringJoiner("|", "", "\n");
    for (String value : values) {
        csvRow.add(value);
    }
    return csvRow.toString();
}
 
Example 18
Source File: MetricNames.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
/**
 * Build a Metric name for the given Module, Type and optional fragments.
 *
 * @param module Module
 * @param type Type
 * @param fragments Name fragments
 * @return Metric name
 */
public static String nameFor( Module module, Class<?> type, String... fragments )
{
    StringJoiner joiner = new StringJoiner( "." )
            .add( module.layer().name() )
            .add( module.name() )
            .add( className( type ) );
    for( String fragment : fragments )
    {
        joiner.add( fragment );
    }
    return joiner.toString();
}
 
Example 19
Source File: AbstractSqlParameterSource.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Enumerate the parameter names and values with their corresponding SQL type if available,
 * or just return the simple {@code SqlParameterSource} implementation class name otherwise.
 * @since 5.2
 * @see #getParameterNames()
 */
@Override
public String toString() {
	String[] parameterNames = getParameterNames();
	if (parameterNames != null) {
		StringJoiner result = new StringJoiner(", ", getClass().getSimpleName() + " {", "}");
		for (String parameterName : parameterNames) {
			Object value = getValue(parameterName);
			if (value instanceof SqlParameterValue) {
				value = ((SqlParameterValue) value).getValue();
			}
			String typeName = getTypeName(parameterName);
			if (typeName == null) {
				int sqlType = getSqlType(parameterName);
				if (sqlType != TYPE_UNKNOWN) {
					typeName = JdbcUtils.resolveTypeName(sqlType);
					if (typeName == null) {
						typeName = String.valueOf(sqlType);
					}
				}
			}
			StringBuilder entry = new StringBuilder();
			entry.append(parameterName).append('=').append(value);
			if (typeName != null) {
				entry.append(" (type:").append(typeName).append(')');
			}
			result.add(entry);
		}
		return result.toString();
	}
	else {
		return getClass().getSimpleName();
	}
}
 
Example 20
Source File: Modifier.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Return a string describing the access modifier flags in
 * the specified modifier. For example:
 * <blockquote><pre>
 *    public final synchronized strictfp
 * </pre></blockquote>
 * The modifier names are returned in an order consistent with the
 * suggested modifier orderings given in sections 8.1.1, 8.3.1, 8.4.3, 8.8.3, and 9.1.1 of
 * <cite>The Java&trade; Language Specification</cite>.
 * The full modifier ordering used by this method is:
 * <blockquote> {@code
 * public protected private abstract static final transient
 * volatile synchronized native strictfp
 * interface } </blockquote>
 * The {@code interface} modifier discussed in this class is
 * not a true modifier in the Java language and it appears after
 * all other modifiers listed by this method.  This method may
 * return a string of modifiers that are not valid modifiers of a
 * Java entity; in other words, no checking is done on the
 * possible validity of the combination of modifiers represented
 * by the input.
 *
 * Note that to perform such checking for a known kind of entity,
 * such as a constructor or method, first AND the argument of
 * {@code toString} with the appropriate mask from a method like
 * {@link #constructorModifiers} or {@link #methodModifiers}.
 *
 * @param   mod a set of modifiers
 * @return  a string representation of the set of modifiers
 * represented by {@code mod}
 */
public static String toString(int mod) {
    StringJoiner sj = new StringJoiner(" ");

    if ((mod & PUBLIC) != 0)        sj.add("public");
    if ((mod & PROTECTED) != 0)     sj.add("protected");
    if ((mod & PRIVATE) != 0)       sj.add("private");

    /* Canonical order */
    if ((mod & ABSTRACT) != 0)      sj.add("abstract");
    if ((mod & STATIC) != 0)        sj.add("static");
    if ((mod & FINAL) != 0)         sj.add("final");
    if ((mod & TRANSIENT) != 0)     sj.add("transient");
    if ((mod & VOLATILE) != 0)      sj.add("volatile");
    if ((mod & SYNCHRONIZED) != 0)  sj.add("synchronized");
    if ((mod & NATIVE) != 0)        sj.add("native");
    if ((mod & STRICT) != 0)        sj.add("strictfp");
    if ((mod & INTERFACE) != 0)     sj.add("interface");

    return sj.toString();
}