com.hp.octane.integrations.utils.SdkStringUtils Maven / Gradle / Ivy
/**
* Copyright 2017-2023 Open Text
*
* The only warranties for products and services of Open Text and
* its affiliates and licensors (“Open Text”) are as may be set forth
* in the express warranty statements accompanying such products and services.
* Nothing herein should be construed as constituting an additional warranty.
* Open Text shall not be liable for technical or editorial errors or
* omissions contained herein. The information contained herein is subject
* to change without notice.
*
* Except as specifically indicated otherwise, this document contains
* confidential information and a valid license is required for possession,
* use or copying. If this work is provided to the U.S. Government,
* consistent with FAR 12.211 and 12.212, Commercial Computer Software,
* Computer Software Documentation, and Technical Data for Commercial Items are
* licensed to the U.S. Government under vendor's standard commercial license.
*
* Licensed 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.hp.octane.integrations.utils;
import java.time.Instant;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
public class SdkStringUtils {
public static String strip(String str, String stripChars) {
if (isEmpty(str)) {
return str;
} else {
return stripEnd(stripStart(str, stripChars), stripChars);
}
}
public static String stripStart(String str, String stripChars) {
int strLen;
if (str != null && (strLen = str.length()) != 0) {
int start = 0;
if (stripChars == null) {
while (start != strLen && Character.isWhitespace(str.charAt(start))) {
++start;
}
} else {
if (stripChars.length() == 0) {
return str;
}
while (start != strLen && stripChars.indexOf(str.charAt(start)) != -1) {
++start;
}
}
return str.substring(start);
} else {
return str;
}
}
public static String stripEnd(String str, String stripChars) {
int end;
if (str != null && (end = str.length()) != 0) {
if (stripChars == null) {
while (end != 0 && Character.isWhitespace(str.charAt(end - 1))) {
--end;
}
} else {
if (stripChars.length() == 0) {
return str;
}
while (end != 0 && stripChars.indexOf(str.charAt(end - 1)) != -1) {
--end;
}
}
return str.substring(0, end);
} else {
return str;
}
}
public static boolean isEmpty(String str) {
return str == null || str.length() == 0;
}
public static boolean isNotEmpty(String str) {
return !isEmpty(str);
}
public static String join(Collection collection, String separator) {
if (collection == null) {
return null;
}
StringBuffer buffer = new StringBuffer();
for (Iterator iterator = collection.iterator(); iterator.hasNext(); buffer.append(iterator.next().toString())) {
if (buffer.length() != 0) {
buffer.append(separator);
}
}
return buffer.toString();
}
public static String join(String[] collection, String separator) {
return join(Arrays.asList(collection), separator);
}
public static boolean equals(String str1, String str2) {
return str1 == null ? str2 == null : str1.equals(str2);
}
public static boolean equalsIgnoreCase(String str1, String str2) {
return str1 == null ? str2 == null : str1.equalsIgnoreCase(str2);
}
}