From 155d883b5868403ccb4650f27561f8ed05e72904 Mon Sep 17 00:00:00 2001 From: liujiahua123123 Date: Wed, 21 Aug 2019 12:50:17 +0800 Subject: [PATCH] SynchronizedLinkedListMap --- .../utils/config/MiraiConfigSection.java | 4 +- .../MiraiSynchronizedLInkedListMap.java | 93 ----------- .../MiraiSynchronizedLinkedListMap.java | 155 ++++++++++++++++++ 3 files changed, 156 insertions(+), 96 deletions(-) delete mode 100644 mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiSynchronizedLInkedListMap.java create mode 100644 mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiSynchronizedLinkedListMap.java diff --git a/mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiConfigSection.java b/mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiConfigSection.java index bff5fd328..6fdb973c1 100644 --- a/mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiConfigSection.java +++ b/mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiConfigSection.java @@ -1,12 +1,10 @@ package net.mamoe.mirai.utils.config; import org.jetbrains.annotations.Nullable; -import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; -import java.util.SortedMap; -public class MiraiConfigSection extends MiraiSynchronizedLInkedListMap { +public class MiraiConfigSection extends MiraiSynchronizedLinkedListMap { public MiraiConfigSection(){ diff --git a/mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiSynchronizedLInkedListMap.java b/mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiSynchronizedLInkedListMap.java deleted file mode 100644 index f389620c9..000000000 --- a/mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiSynchronizedLInkedListMap.java +++ /dev/null @@ -1,93 +0,0 @@ -package net.mamoe.mirai.utils.config; - -import lombok.Getter; -import lombok.Setter; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.*; - -public class MiraiSynchronizedLInkedListMap extends AbstractMap { - - public MiraiSynchronizedLInkedListMap(){ - this.sortedMap = Collections.synchronizedMap(new LinkedHashMap<>()); - } - - protected Map sortedMap; - - protected void setContent(LinkedHashMap map){ - this.sortedMap = Collections.synchronizedMap(map); - } - - @Override - public int size() { - return sortedMap.size(); - } - - @Override - public boolean isEmpty() { - return sortedMap.isEmpty(); - } - - @Override - public boolean containsKey(Object key) { - return sortedMap.containsKey(key); - } - - @Override - public boolean containsValue(Object value) { - return sortedMap.containsValue(value); - } - - @Override - public V get(Object key) { - return sortedMap.get(key); - } - - @Nullable - @Override - public V put(K key, V value) { - return sortedMap.put(key,value); - } - - @Override - public V remove(Object key) { - return sortedMap.remove(key); - } - - @Override - public void putAll(@NotNull Map m) { - sortedMap.putAll(m); - } - - @Override - public void clear() { - sortedMap.clear(); - } - - @NotNull - @Override - public Set keySet() { - return sortedMap.keySet(); - } - - @NotNull - @Override - public Collection values() { - return sortedMap.values(); - } - - @NotNull - @Override - public Set> entrySet() { - return sortedMap.entrySet(); - } - - @Override - public String toString() { - return this.sortedMap.toString(); - } - - - -} diff --git a/mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiSynchronizedLinkedListMap.java b/mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiSynchronizedLinkedListMap.java new file mode 100644 index 000000000..eae72e393 --- /dev/null +++ b/mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiSynchronizedLinkedListMap.java @@ -0,0 +1,155 @@ +package net.mamoe.mirai.utils.config; + +import lombok.Getter; +import lombok.Setter; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.*; +import java.util.function.BiConsumer; +import java.util.function.BiFunction; +import java.util.function.Function; + +public class MiraiSynchronizedLinkedListMap extends AbstractMap { + + public MiraiSynchronizedLinkedListMap(){ + this.sortedMap = Collections.synchronizedMap(new LinkedHashMap<>()); + } + + protected Map sortedMap; + + protected void setContent(LinkedHashMap map){ + this.sortedMap = Collections.synchronizedMap(map); + } + + @Override + public int size() { + return sortedMap.size(); + } + + @Override + public boolean isEmpty() { + return sortedMap.isEmpty(); + } + + @Override + public boolean containsKey(Object key) { + return sortedMap.containsKey(key); + } + + @Override + public boolean containsValue(Object value) { + return sortedMap.containsValue(value); + } + + @Override + public V get(Object key) { + return sortedMap.get(key); + } + + @Nullable + @Override + public V put(K key, V value) { + return sortedMap.put(key,value); + } + + @Override + public V remove(Object key) { + return sortedMap.remove(key); + } + + @Override + public void putAll(@NotNull Map m) { + sortedMap.putAll(m); + } + + @Override + public void clear() { + sortedMap.clear(); + } + + @NotNull + @Override + public Set keySet() { + return sortedMap.keySet(); + } + + @NotNull + @Override + public Collection values() { + return sortedMap.values(); + } + + @NotNull + @Override + public Set> entrySet() { + return sortedMap.entrySet(); + } + + @Override + public String toString() { + return this.sortedMap.toString(); + } + + @Override + public V getOrDefault(Object key, V defaultValue) { + return this.sortedMap.getOrDefault(key,defaultValue); + } + + @Override + public void forEach(BiConsumer action) { + this.sortedMap.forEach(action); + } + + @Override + public boolean replace(K key, V oldValue, V newValue) { + return this.sortedMap.replace(key,oldValue,newValue); + } + + @Nullable + @Override + public V replace(K key, V value) { + return this.sortedMap.replace(key,value); + } + + @Override + public void replaceAll(BiFunction function) { + this.sortedMap.replaceAll(function); + } + + @Override + public V compute(K key, BiFunction remappingFunction) { + return this.sortedMap.compute(key,remappingFunction); + } + + @Override + public V computeIfAbsent(K key, Function mappingFunction) { + return this.sortedMap.computeIfAbsent(key,mappingFunction); + } + + @Override + public V computeIfPresent(K key, BiFunction remappingFunction) { + return this.sortedMap.computeIfPresent(key,remappingFunction); + } + + @Override + public int hashCode() { + return this.sortedMap.hashCode(); + } + + @Nullable + @Override + public V putIfAbsent(K key, V value) { + return this.sortedMap.putIfAbsent(key,value); + } + + @Override + public V merge(K key, V value, BiFunction remappingFunction) { + return this.sortedMap.merge(key,value,remappingFunction); + } + + @Override + public boolean equals(Object o) { + return this.sortedMap.equals(o); + } +}