|
23 | 23 | */
|
24 | 24 | package com.github.underscore;
|
25 | 25 |
|
26 |
| -import java.io.File; |
27 | 26 | import java.io.FileInputStream;
|
28 | 27 | import java.io.FileOutputStream;
|
29 | 28 | import java.io.IOException;
|
@@ -91,23 +90,23 @@ public class U<T> extends Underscore<T> {
|
91 | 90 | private static final int BUFFER_LENGTH_1024 = 1024;
|
92 | 91 | private static final int RESPONSE_CODE_400 = 400;
|
93 | 92 | private static final String ROOT = "root";
|
94 |
| - private static String upper = "[A-Z\\xc0-\\xd6\\xd8-\\xde\\u0400-\\u04FF]"; |
95 |
| - private static String lower = "[a-z\\xdf-\\xf6\\xf8-\\xff]+"; |
96 |
| - private static String selfClosing = "-self-closing"; |
97 |
| - private static String nilKey = "-nil"; |
98 |
| - private static java.util.regex.Pattern reWords = |
| 93 | + private static final String UPPER = "[A-Z\\xc0-\\xd6\\xd8-\\xde\\u0400-\\u04FF]"; |
| 94 | + private static final String LOWER = "[a-z\\xdf-\\xf6\\xf8-\\xff]+"; |
| 95 | + private static final String SELF_CLOSING = "-self-closing"; |
| 96 | + private static final String NIL_KEY = "-nil"; |
| 97 | + private static final java.util.regex.Pattern RE_WORDS = |
99 | 98 | java.util.regex.Pattern.compile(
|
100 |
| - upper |
| 99 | + UPPER |
101 | 100 | + "+(?="
|
102 |
| - + upper |
103 |
| - + lower |
| 101 | + + UPPER |
| 102 | + + LOWER |
104 | 103 | + ")|"
|
105 |
| - + upper |
| 104 | + + UPPER |
106 | 105 | + "?"
|
107 |
| - + lower |
| 106 | + + LOWER |
108 | 107 | + "|"
|
109 |
| - + upper |
110 |
| - + "+|[0-9]+"); |
| 108 | + + UPPER |
| 109 | + + "+|\\d+"); |
111 | 110 |
|
112 | 111 | static {
|
113 | 112 | String[] deburredLetters =
|
@@ -1460,7 +1459,7 @@ public static String deburr(final String string) {
|
1460 | 1459 | public static List<String> words(final String string) {
|
1461 | 1460 | final String localString = baseToString(string);
|
1462 | 1461 | final List<String> result = new ArrayList<>();
|
1463 |
| - final java.util.regex.Matcher matcher = reWords.matcher(localString); |
| 1462 | + final java.util.regex.Matcher matcher = RE_WORDS.matcher(localString); |
1464 | 1463 | while (matcher.find()) {
|
1465 | 1464 | result.add(matcher.group());
|
1466 | 1465 | }
|
@@ -2069,7 +2068,7 @@ public static long downloadUrl(final String url, final String fileName)
|
2069 | 2068 | public static void decompressGzip(final String sourceFileName, final String targetFileName)
|
2070 | 2069 | throws IOException {
|
2071 | 2070 | try (GZIPInputStream gis =
|
2072 |
| - new GZIPInputStream(new FileInputStream(new File(sourceFileName)))) { |
| 2071 | + new GZIPInputStream(new FileInputStream(sourceFileName))) { |
2073 | 2072 | Files.copy(gis, Paths.get(targetFileName));
|
2074 | 2073 | }
|
2075 | 2074 | }
|
@@ -2523,6 +2522,14 @@ public static <T> String join(final Iterable<T> iterable, final String separator
|
2523 | 2522 | return Underscore.join(iterable, separator);
|
2524 | 2523 | }
|
2525 | 2524 |
|
| 2525 | + public static <T> String joinToString(final Iterable<T> iterable, final String separator, |
| 2526 | + final String prefix, final String postfix, |
| 2527 | + final int limit, |
| 2528 | + final String truncated, |
| 2529 | + final Function<T, String> transform) { |
| 2530 | + return Underscore.joinToString(iterable, separator, prefix, postfix, limit, truncated, transform); |
| 2531 | + } |
| 2532 | + |
2526 | 2533 | public static String toJson(Collection collection) {
|
2527 | 2534 | return Json.toJson(collection);
|
2528 | 2535 | }
|
@@ -2877,7 +2884,7 @@ public static Map<String, Object> removeMinusesAndConvertNumbers(Map<String, Obj
|
2877 | 2884 | } else {
|
2878 | 2885 | newKey = entry.getKey();
|
2879 | 2886 | }
|
2880 |
| - if (!entry.getKey().equals(selfClosing) |
| 2887 | + if (!entry.getKey().equals(SELF_CLOSING) |
2881 | 2888 | && !entry.getKey().equals("#omit-xml-declaration")) {
|
2882 | 2889 | outMap.put(newKey, makeObject(entry.getValue()));
|
2883 | 2890 | }
|
@@ -2955,7 +2962,7 @@ public static Map<String, Object> replaceSelfClosingWithEmpty(Map<String, Object
|
2955 | 2962 | public static Object replaceSelfClosingWithValue(Map<String, Object> map, String value) {
|
2956 | 2963 | Object outMap = new LinkedHashMap<>();
|
2957 | 2964 | for (Map.Entry<String, Object> entry : map.entrySet()) {
|
2958 |
| - if (selfClosing.equals(entry.getKey()) && "true".equals(entry.getValue())) { |
| 2965 | + if (SELF_CLOSING.equals(entry.getKey()) && "true".equals(entry.getValue())) { |
2959 | 2966 | if (map.size() == 1) {
|
2960 | 2967 | outMap = value;
|
2961 | 2968 | break;
|
@@ -3218,9 +3225,9 @@ public static Map<String, Object> replaceFirstLevel(Map<String, Object> map, int
|
3218 | 3225 | }
|
3219 | 3226 | if (level == 0 && Xml.XmlValue.getMapValue(outMap) instanceof Map) {
|
3220 | 3227 | Map<String, Object> outMap2 = (Map<String, Object>) Xml.XmlValue.getMapValue(outMap);
|
3221 |
| - if (selfClosing.equals(Xml.XmlValue.getMapKey(outMap2)) |
| 3228 | + if (SELF_CLOSING.equals(Xml.XmlValue.getMapKey(outMap2)) |
3222 | 3229 | && "true".equals(Xml.XmlValue.getMapValue(outMap2))) {
|
3223 |
| - outMap2.remove(selfClosing); |
| 3230 | + outMap2.remove(SELF_CLOSING); |
3224 | 3231 | }
|
3225 | 3232 | return outMap2;
|
3226 | 3233 | }
|
@@ -3249,11 +3256,11 @@ public static Map<String, Object> replaceNilWithNull(Map<String, Object> map) {
|
3249 | 3256 | for (Map.Entry<String, Object> entry : map.entrySet()) {
|
3250 | 3257 | Object outValue = makeReplaceNilWithNull(entry.getValue());
|
3251 | 3258 | if (outValue instanceof Map
|
3252 |
| - && (nilKey.equals(Xml.XmlValue.getMapKey(outValue)) |
| 3259 | + && (NIL_KEY.equals(Xml.XmlValue.getMapKey(outValue)) |
3253 | 3260 | || Xml.XmlValue.getMapKey(outValue).endsWith(":nil"))
|
3254 | 3261 | && "true".equals(Xml.XmlValue.getMapValue(outValue))
|
3255 |
| - && ((Map) outValue).containsKey(selfClosing) |
3256 |
| - && "true".equals(((Map) outValue).get(selfClosing))) { |
| 3262 | + && ((Map) outValue).containsKey(SELF_CLOSING) |
| 3263 | + && "true".equals(((Map) outValue).get(SELF_CLOSING))) { |
3257 | 3264 | outValue = null;
|
3258 | 3265 | }
|
3259 | 3266 | outMap.put(entry.getKey(), outValue);
|
@@ -3397,7 +3404,7 @@ public Builder addNull(final String key) {
|
3397 | 3404 |
|
3398 | 3405 | @SuppressWarnings("unchecked")
|
3399 | 3406 | public Map<String, Object> build() {
|
3400 |
| - return (Map<String, Object>) ((LinkedHashMap) data).clone(); |
| 3407 | + return (Map<String, Object>) ((LinkedHashMap<?, ?>) data).clone(); |
3401 | 3408 | }
|
3402 | 3409 |
|
3403 | 3410 | public String toXml() {
|
@@ -3503,13 +3510,13 @@ public ArrayBuilder add(final Builder builder) {
|
3503 | 3510 |
|
3504 | 3511 | @SuppressWarnings("unchecked")
|
3505 | 3512 | public ArrayBuilder merge(final List<Object> list) {
|
3506 |
| - U.merge(data, (List<Object>) ((ArrayList) list).clone()); |
| 3513 | + U.merge(data, (List<Object>) ((ArrayList<?>) list).clone()); |
3507 | 3514 | return this;
|
3508 | 3515 | }
|
3509 | 3516 |
|
3510 | 3517 | @SuppressWarnings("unchecked")
|
3511 | 3518 | public List<Object> build() {
|
3512 |
| - return (List<Object>) ((ArrayList) data).clone(); |
| 3519 | + return (List<Object>) ((ArrayList<?>) data).clone(); |
3513 | 3520 | }
|
3514 | 3521 |
|
3515 | 3522 | public String toXml() {
|
|
0 commit comments