[platform] moves some methods back into 'util'

This commit is contained in:
Roman Shevchenko
2018-08-13 19:31:21 +02:00
parent 153292c5cb
commit cb9257cb5f
2 changed files with 27 additions and 75 deletions
@@ -1,28 +1,12 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* 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.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.util.text;
import com.intellij.util.Function;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
@@ -341,16 +325,6 @@ public class StringUtilRt {
return true;
}
@NotNull
@Contract(pure = true)
public static <T> Function<T, String> createToStringFunction() {
return new Function<T, String>() {
public String fun(@NotNull T o) {
return o.toString();
}
};
}
@NotNull
@Contract(pure = true)
public static String notNullize(@Nullable String s) {
@@ -363,44 +337,6 @@ public class StringUtilRt {
return s == null ? defaultValue : s;
}
@NotNull
@Contract(pure = true)
public static <T> String join(@NotNull Collection<? extends T> items,
@NotNull Function<? super T, String> f,
@NotNull String separator) {
if (items.isEmpty()) return "";
if (items.size() == 1) return notNullize(f.fun(items.iterator().next()));
return join((Iterable<? extends T>)items, f, separator);
}
@NotNull
@Contract(pure = true)
public static <T> String join(@NotNull Iterable<? extends T> items,
@NotNull Function<? super T, String> f,
@NotNull String separator) {
final StringBuilder result = new StringBuilder();
join(items, f, separator, result);
return result.toString();
}
public static <T> void join(@NotNull Iterable<? extends T> items,
@NotNull Function<? super T, String> f,
@NotNull String separator,
@NotNull StringBuilder result) {
boolean isFirst = true;
for (T item : items) {
String string = f.fun(item);
if (string != null && string.length() > 0) {
if (isFirst) {
isFirst = false;
} else {
result.append(separator);
}
result.append(string);
}
}
}
@NotNull
@Contract(pure = true)
public static List<String> splitHonorQuotes(@NotNull String s, char separator) {
@@ -523,14 +459,11 @@ public class StringUtilRt {
return sb.toString();
}
private static boolean isQuoteAt(@NotNull String s, int ind) {
char ch = s.charAt(ind);
return ch == '\'' || ch == '\"';
}
@Contract(pure = true)
public static boolean isQuotedString(@NotNull String s) {
return s.length() > 1 && isQuoteAt(s, 0) && s.charAt(0) == s.charAt(s.length() - 1);
return s.length() > 1 &&
(s.charAt(0) == '\'' || s.charAt(0) == '\"') &&
s.charAt(0) == s.charAt(s.length() - 1);
}
@NotNull
@@ -121,7 +121,11 @@ public class StringUtil extends StringUtilRt {
@NotNull
@Contract(pure = true)
public static <T> Function<T, String> createToStringFunction(@SuppressWarnings("unused") @NotNull Class<T> cls) {
return StringUtilRt.createToStringFunction();
return new Function<T, String>() {
public String fun(@NotNull T o) {
return o.toString();
}
};
}
@NotNull
@@ -1429,7 +1433,9 @@ public class StringUtil extends StringUtilRt {
public static <T> String join(@NotNull Collection<? extends T> items,
@NotNull Function<? super T, String> f,
@NotNull String separator) {
return StringUtilRt.join(items, f, separator);
if (items.isEmpty()) return "";
if (items.size() == 1) return notNullize(f.fun(items.iterator().next()));
return join((Iterable<? extends T>)items, f, separator);
}
@Contract(pure = true)
@@ -1449,14 +1455,27 @@ public class StringUtil extends StringUtilRt {
public static <T> String join(@NotNull Iterable<? extends T> items,
@NotNull Function<? super T, String> f,
@NotNull String separator) {
return StringUtilRt.join(items, f, separator);
StringBuilder result = new StringBuilder();
join(items, f, separator, result);
return result.toString();
}
public static <T> void join(@NotNull Iterable<? extends T> items,
@NotNull Function<? super T, String> f,
@NotNull String separator,
@NotNull StringBuilder result) {
StringUtilRt.join(items, f, separator, result);
boolean isFirst = true;
for (T item : items) {
String string = f.fun(item);
if (string != null && string.length() > 0) {
if (isFirst) {
isFirst = false;
} else {
result.append(separator);
}
result.append(string);
}
}
}
@NotNull