
com.indoqa.lang.util.StringUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of indoqa-lang Show documentation
Show all versions of indoqa-lang Show documentation
Stuff that would be expected being part of the Java standard library or Apache Commons Lang | IO.
The newest version!
/*
* Licensed to the Indoqa Software Design und Beratung GmbH (Indoqa) under
* one or more contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright ownership.
* Indoqa licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.indoqa.lang.util;
import java.io.IOException;
import java.io.LineNumberReader;
import java.io.StringReader;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.Iterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.indoqa.lang.collection.ArrayIterable;
/**
* Utility functions that are not available in any of the popular StringUtils classes. (
* org.apache.
* commons.lang3.StringUtils,
* org.springframework.util.
* StringUtils)
*/
public class StringUtils {
/**
* 210 bytes (aka 1 Kibibyte).
*/
public static final long ONE_KIB = (long) Math.pow(2, 10);
/**
* 220 bytes (aka 1 Mebibyte)
*/
public static final long ONE_MIB = (long) Math.pow(2, 20);
/**
* 230 bytes (aka 1 Gibibyte)
*/
public static final long ONE_GIB = (long) Math.pow(2, 30);
private static final DecimalFormat GIBI_BYTE_FORMAT = new DecimalFormat("#,##0.00 GiB");
private static final DecimalFormat MEBI_BYTE_FORMAT = new DecimalFormat("#,##0.00 MiB");
private static final DecimalFormat KIBI_BYTE_FORMAT = new DecimalFormat("#,##0.0 KiB");
private static final DecimalFormat BYTE_FORMAT = new DecimalFormat("#,##0 B");
private static final Pattern CONTROL_CHARACTERS_PATTERN = Pattern.compile("[\\p{Cntrl}&&[^ \\t\\n\\r]]");
private static final char[] CHARACTERS_TO_BE_ESCAPED_FOR_SOLR = {'"', '(', ')', ':', '[', ']', '+', '-', '*', '~', ' ', '^', '{',
'}', '!', '/'};
private static final char[] ILLEGAL_HTML_ID_CHARACTERS = {'"', '\'', ':', ';', ',', '+', 'ä', 'Ä', 'ö', 'Ö', 'ü', 'Ü', '&', '$'};
private static final int INITIAL_STRING_BUILDER_CAPACITY = 200;
static {
Arrays.sort(CHARACTERS_TO_BE_ESCAPED_FOR_SOLR);
Arrays.sort(ILLEGAL_HTML_ID_CHARACTERS);
}
/**
*
* StringUtils
instances should NOT be constructed in standard programming. Instead, the class should be used as
* StringUtils.countLines("foo");
.
*
*
*
* This constructor is public to permit tools that require a JavaBean instance to operate.
*
*/
public StringUtils() {
super();
}
public static void append(StringBuilder stringBuilder, Iterable> values, String separator) {
for (Iterator> i = values.iterator(); i.hasNext();) {
stringBuilder.append(String.valueOf(i.next()));
if (i.hasNext()) {
stringBuilder.append(separator);
}
}
}
public static void append(StringBuilder stringBuilder, Object[] values, String separator) {
append(stringBuilder, new ArrayIterable
© 2015 - 2025 Weber Informatics LLC | Privacy Policy