![JAR search and dependency download from the Maven repository](/logo.png)
com.github.underscore.lodash.U Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of underscore8 Show documentation
Show all versions of underscore8 Show documentation
The java 8 port of Underscore.js
The newest version!
/*
* The MIT License (MIT)
*
* Copyright 2015-2020 Valentyn Kolesnikov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.github.underscore.lodash;
import com.github.underscore.Function3;
import com.github.underscore.PredicateIndexed;
import com.github.underscore.Tuple;
import com.github.underscore.Optional;
import java.util.*;
import java.util.function.BinaryOperator;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
public class U extends com.github.underscore.U {
private static final int DEFAULT_TRUNC_LENGTH = 30;
private static final String DEFAULT_TRUNC_OMISSION = "...";
private static final java.util.regex.Pattern RE_LATIN_1 = java.util.regex.Pattern.compile(
"[\\xc0-\\xd6\\xd8-\\xde\\xdf-\\xf6\\xf8-\\xff]");
private static final java.util.regex.Pattern RE_PROP_NAME = java.util.regex.Pattern.compile(
"[^.\\[\\]]+|\\[(?:(-?\\d+(?:\\.\\d+)?)|([\"'])((?:(?!\2)\\[^\\]|\\.)*?)\2)\\]|(?=(\\.|\\[\\])(?:\4|$))");
private static final Map DEBURRED_LETTERS = new LinkedHashMap();
private static final Map> DEFAULT_HEADER_FIELDS = new HashMap>();
private static final Set SUPPORTED_HTTP_METHODS = new HashSet(
Arrays.asList("GET", "POST", "PUT", "DELETE"));
private static final int BUFFER_LENGTH_1024 = 1024;
private static final int RESPONSE_CODE_400 = 400;
private static String upper = "[A-Z\\xc0-\\xd6\\xd8-\\xde\\u0400-\\u04FF]";
private static String lower = "[a-z\\xdf-\\xf6\\xf8-\\xff]+";
private static java.util.regex.Pattern reWords = java.util.regex.Pattern.compile(
upper + "+(?=" + upper + lower + ")|" + upper + "?" + lower + "|" + upper + "+|[0-9]+");
static {
String[] deburredLetters = new String[] {
"\u00c0", "A", "\u00c1", "A", "\u00c2", "A", "\u00c3", "A",
"\u00c4", "A", "\u00c5", "A",
"\u00e0", "a", "\u00e1", "a", "\u00e2", "a", "\u00e3", "a",
"\u00e4", "a", "\u00e5", "a",
"\u00c7", "C", "\u00e7", "c",
"\u00d0", "D", "\u00f0", "d",
"\u00c8", "E", "\u00c9", "E", "\u00ca", "E", "\u00cb", "E",
"\u00e8", "e", "\u00e9", "e", "\u00ea", "e", "\u00eb", "e",
"\u00cC", "I", "\u00cd", "I", "\u00ce", "I", "\u00cf", "I",
"\u00eC", "i", "\u00ed", "i", "\u00ee", "i", "\u00ef", "i",
"\u00d1", "N", "\u00f1", "n",
"\u00d2", "O", "\u00d3", "O", "\u00d4", "O", "\u00d5", "O",
"\u00d6", "O", "\u00d8", "O",
"\u00f2", "o", "\u00f3", "o", "\u00f4", "o", "\u00f5", "o",
"\u00f6", "o", "\u00f8", "o",
"\u00d9", "U", "\u00da", "U", "\u00db", "U", "\u00dc", "U",
"\u00f9", "u", "\u00fa", "u", "\u00fb", "u", "\u00fc", "u",
"\u00dd", "Y", "\u00fd", "y", "\u00ff", "y",
"\u00c6", "Ae", "\u00e6", "ae",
"\u00de", "Th", "\u00fe", "th",
"\u00df", "ss"};
for (int index = 0; index < deburredLetters.length; index += 2) {
DEBURRED_LETTERS.put(deburredLetters[index], deburredLetters[index + 1]);
}
DEFAULT_HEADER_FIELDS.put("Content-Type", Arrays.asList("application/json", "charset=utf-8"));
}
public enum Mode {
REPLACE_SELF_CLOSING_WITH_NULL,
REPLACE_SELF_CLOSING_WITH_EMPTY;
}
public U(final Iterable iterable) {
super(iterable);
}
public U(final String string) {
super(string);
}
public static class Chain extends com.github.underscore.U.Chain {
public Chain(final T item) {
super(item);
}
public Chain(final List list) {
super(list);
}
public Chain first() {
return new Chain(U.first(value()));
}
public Chain first(int n) {
return new Chain(U.first(value(), n));
}
public Chain firstOrNull() {
return new Chain(U.firstOrNull(value()));
}
public Chain firstOrNull(final Predicate pred) {
return new Chain(U.firstOrNull(value(), pred));
}
public Chain initial() {
return new Chain(U.initial(value()));
}
public Chain initial(int n) {
return new Chain(U.initial(value(), n));
}
public Chain last() {
return new Chain(U.last(value()));
}
public Chain last(int n) {
return new Chain(U.last(value(), n));
}
public Chain lastOrNull() {
return new Chain(U.lastOrNull(value()));
}
public Chain lastOrNull(final Predicate pred) {
return new Chain(U.lastOrNull(value(), pred));
}
public Chain rest() {
return new Chain(U.rest(value()));
}
public Chain rest(int n) {
return new Chain(U.rest(value(), n));
}
public Chain compact() {
return new Chain(U.compact(value()));
}
public Chain compact(final T falsyValue) {
return new Chain(U.compact(value(), falsyValue));
}
@SuppressWarnings("unchecked")
public Chain flatten() {
return new Chain(U.flatten(value()));
}
public Chain map(final Function super T, F> func) {
return new Chain(U.map(value(), func));
}
public Chain mapIndexed(final BiFunction func) {
return new Chain(U.mapIndexed(value(), func));
}
public Chain filter(final Predicate pred) {
return new Chain(U.filter(value(), pred));
}
public Chain filterIndexed(final PredicateIndexed pred) {
return new Chain(U.filterIndexed(value(), pred));
}
public Chain rejectIndexed(final PredicateIndexed pred) {
return new Chain(U.rejectIndexed(value(), pred));
}
public Chain reject(final Predicate pred) {
return new Chain(U.reject(value(), pred));
}
public Chain filterFalse(final Predicate pred) {
return new Chain(U.filterFalse(value(), pred));
}
public Chain reduce(final BiFunction func, final F zeroElem) {
return new Chain(U.reduce(value(), func, zeroElem));
}
public Chain> reduce(final BinaryOperator func) {
return new Chain>(U.reduce(value(), func));
}
public Chain reduceRight(final BiFunction func, final F zeroElem) {
return new Chain(U.reduceRight(value(), func, zeroElem));
}
public Chain> reduceRight(final BinaryOperator func) {
return new Chain>(U.reduceRight(value(), func));
}
public Chain> find(final Predicate pred) {
return new Chain>(U.find(value(), pred));
}
public Chain> findLast(final Predicate pred) {
return new Chain>(U.findLast(value(), pred));
}
@SuppressWarnings("unchecked")
public Chain max() {
return new Chain(U.max((Collection) value()));
}
public > Chain max(final Function func) {
return new Chain(U.max(value(), func));
}
@SuppressWarnings("unchecked")
public Chain min() {
return new Chain(U.min((Collection) value()));
}
public > Chain min(final Function func) {
return new Chain(U.min(value(), func));
}
@SuppressWarnings("unchecked")
public Chain sort() {
return new Chain(U.sort((List) value()));
}
@SuppressWarnings("unchecked")
public > Chain sortWith(final Comparator comparator) {
return new Chain(U.sortWith((List) value(), comparator));
}
public > Chain sortBy(final Function func) {
return new Chain(U.sortBy(value(), func));
}
@SuppressWarnings("unchecked")
public Chain