From d674b0b7de2ba6f76dd2928ef3f7927b10f18444 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Thu, 28 Jun 2018 19:07:04 +0300 Subject: [PATCH] Add some missing stdlib methods --- .../org/teavm/classlib/java/lang/TString.java | 45 +++++++++++++++++++ .../java/nio/charset/TStandardCharsets.java | 25 +++++++++++ .../org/teavm/classlib/java/util/TMap.java | 9 ++++ 3 files changed, 79 insertions(+) create mode 100644 classlib/src/main/java/org/teavm/classlib/java/nio/charset/TStandardCharsets.java diff --git a/classlib/src/main/java/org/teavm/classlib/java/lang/TString.java b/classlib/src/main/java/org/teavm/classlib/java/lang/TString.java index 422416a27..fe0b43238 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/lang/TString.java +++ b/classlib/src/main/java/org/teavm/classlib/java/lang/TString.java @@ -15,6 +15,7 @@ */ package org.teavm.classlib.java.lang; +import java.util.Iterator; import java.util.Locale; import org.teavm.classlib.java.io.TSerializable; import org.teavm.classlib.java.io.TUnsupportedEncodingException; @@ -666,4 +667,48 @@ public class TString extends TObject implements TSerializable, TComparable elements) { + Iterator iter = elements.iterator(); + if (!iter.hasNext()) { + return ""; + } + + StringBuilder sb = new StringBuilder(); + sb.append(iter.next()); + while (iter.hasNext()) { + sb.append(delimiter); + sb.append(iter.next()); + } + return sb.toString(); + } } diff --git a/classlib/src/main/java/org/teavm/classlib/java/nio/charset/TStandardCharsets.java b/classlib/src/main/java/org/teavm/classlib/java/nio/charset/TStandardCharsets.java new file mode 100644 index 000000000..d2a5dcb6c --- /dev/null +++ b/classlib/src/main/java/org/teavm/classlib/java/nio/charset/TStandardCharsets.java @@ -0,0 +1,25 @@ +/* + * Copyright 2018 Alexey Andreev. + * + * 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 org.teavm.classlib.java.nio.charset; + +import org.teavm.classlib.java.nio.charset.impl.TUTF8Charset; + +public final class TStandardCharsets { + private TStandardCharsets() { + } + + public static final TCharset UTF_8 = new TUTF8Charset(); +} diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/TMap.java b/classlib/src/main/java/org/teavm/classlib/java/util/TMap.java index b1ceca084..a97ef4243 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/TMap.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/TMap.java @@ -74,6 +74,15 @@ public interface TMap { } } + default V putIfAbsent(K key, V value) { + V v = get(key); + if (v == null) { + v = put(key, value); + } + + return v; + } + default V computeIfAbsent(K key, Function mappingFunction) { V v = get(key); if (v == null) {