diff --git a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/network/protocol/tim/handler/PacketHandler.kt b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/network/protocol/tim/handler/PacketHandler.kt index 8c3db56d5..1e2b98100 100644 --- a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/network/protocol/tim/handler/PacketHandler.kt +++ b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/network/protocol/tim/handler/PacketHandler.kt @@ -2,7 +2,6 @@ package net.mamoe.mirai.network.protocol.tim.handler import net.mamoe.mirai.network.LoginSession import net.mamoe.mirai.network.protocol.tim.packet.ServerPacket -import net.mamoe.mirai.utils.MiraiSynchronizedLinkedList import java.io.Closeable /** @@ -27,7 +26,7 @@ fun PacketHandler.asNode(): PacketHandlerNode { return PacketHandlerNode(this.javaClass, this) } -class PacketHandlerList : MiraiSynchronizedLinkedList>() { +class PacketHandlerList : MutableList> by mutableListOf() { fun get(clazz: Class): T { this.forEach { diff --git a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/network/protocol/tim/packet/PacketId.kt b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/network/protocol/tim/packet/PacketId.kt index c53cad733..8ede36192 100644 --- a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/network/protocol/tim/packet/PacketId.kt +++ b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/network/protocol/tim/packet/PacketId.kt @@ -1,18 +1,13 @@ -package net.mamoe.mirai.network.protocol.tim.packet; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; +package net.mamoe.mirai.network.protocol.tim.packet /** * @author Him188moe */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface PacketId { - /** - * 获取用于识别的包 ID - */ - String value(); -} +@Retention(AnnotationRetention.RUNTIME) +@Target(AnnotationTarget.CLASS, AnnotationTarget.FILE) +annotation class PacketId( + /** + * 用于识别的包 ID + */ + val value: String +) diff --git a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/ContactList.kt b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/ContactList.kt index b4df58a6a..3332e0bfb 100644 --- a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/ContactList.kt +++ b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/ContactList.kt @@ -5,4 +5,4 @@ import net.mamoe.mirai.contact.Contact /** * @author Him188moe */ -class ContactList : MiraiSynchronizedLinkedHashMap() \ No newline at end of file +class ContactList : MutableMap by mutableMapOf() \ No newline at end of file diff --git a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/MiraiSynchronizedLinkedHashMap.java b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/MiraiSynchronizedLinkedHashMap.java deleted file mode 100644 index 6c5795f84..000000000 --- a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/MiraiSynchronizedLinkedHashMap.java +++ /dev/null @@ -1,158 +0,0 @@ -package net.mamoe.mirai.utils; - -import java.util.*; -import java.util.function.BiConsumer; -import java.util.function.BiFunction; -import java.util.function.Function; - -/** - * 实现了可以直接被继承的 SynchronizedLinkedListMap - * - * @param the type of key - * @param the type of value - * - * @author NaturalHG - */ -public class MiraiSynchronizedLinkedHashMap extends AbstractMap { - - public MiraiSynchronizedLinkedHashMap() { - this.sortedMap = Collections.synchronizedMap(new LinkedHashMap<>()); - } - - protected final Map sortedMap; - - public MiraiSynchronizedLinkedHashMap(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); - } - - @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(Map m) { - sortedMap.putAll(m); - } - - @Override - public void clear() { - sortedMap.clear(); - } - - @Override - public Set keySet() { - return sortedMap.keySet(); - } - - @Override - public Collection values() { - return sortedMap.values(); - } - - @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); - } - - @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(); - } - - @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); - } - - public boolean equals(MiraiSynchronizedLinkedHashMap o) { - return this.sortedMap.equals(o.sortedMap); - } - - @Override - public boolean equals(Object o) { - return o instanceof MiraiSynchronizedLinkedHashMap ? this.equals((MiraiSynchronizedLinkedHashMap) o) : super.equals(o); - } - -} diff --git a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/MiraiSynchronizedLinkedList.java b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/MiraiSynchronizedLinkedList.java deleted file mode 100644 index 10691f929..000000000 --- a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/MiraiSynchronizedLinkedList.java +++ /dev/null @@ -1,187 +0,0 @@ -package net.mamoe.mirai.utils; - -import java.util.*; -import java.util.function.Consumer; -import java.util.function.IntFunction; -import java.util.function.Predicate; -import java.util.function.UnaryOperator; -import java.util.stream.Stream; - -/** - * @author Him188moe - */ -public class MiraiSynchronizedLinkedList extends AbstractList { - @SuppressWarnings("WeakerAccess") - protected final List syncList; - - public MiraiSynchronizedLinkedList() { - this.syncList = Collections.synchronizedList(new LinkedList<>()); - } - - public MiraiSynchronizedLinkedList(Collection collection) { - this.syncList = Collections.synchronizedList(new LinkedList<>(collection)); - } - - - @Override - public E get(int index) { - return this.syncList.get(index); - } - - @Override - public void forEach(Consumer action) { - this.syncList.forEach(action); - } - - @Override - public Spliterator spliterator() { - return this.syncList.spliterator(); - } - - @Override - public Stream stream() { - return this.syncList.stream(); - } - - @Override - public Stream parallelStream() { - return this.syncList.parallelStream(); - } - - @Override - public int size() { - return this.syncList.size(); - } - - @SuppressWarnings("SuspiciousToArrayCall") - @Override - public T[] toArray(IntFunction generator) { - return this.syncList.toArray(generator); - } - - @Override - public boolean removeIf(Predicate filter) { - return this.syncList.removeIf(filter); - } - - @Override - public void replaceAll(UnaryOperator operator) { - this.syncList.replaceAll(operator); - } - - @Override - public void sort(Comparator c) { - this.syncList.sort(c); - } - - @Override - public boolean add(E e) { - return this.syncList.add(e); - } - - @Override - public E set(int index, E element) { - return this.syncList.set(index, element); - } - - @Override - public void add(int index, E element) { - this.syncList.add(index, element); - } - - @Override - public E remove(int index) { - return this.syncList.remove(index); - } - - @Override - public int indexOf(Object o) { - return this.syncList.indexOf(o); - } - - @Override - public int lastIndexOf(Object o) { - return this.syncList.lastIndexOf(o); - } - - @Override - public void clear() { - this.syncList.clear(); - } - - @Override - public boolean addAll(int index, Collection c) { - return this.syncList.addAll(index, c); - } - - @Override - public Iterator iterator() { - return this.syncList.iterator(); - } - - @Override - public ListIterator listIterator() { - return this.syncList.listIterator(); - } - - @Override - public ListIterator listIterator(int index) { - return this.syncList.listIterator(index); - } - - @Override - public List subList(int fromIndex, int toIndex) { - return this.syncList.subList(fromIndex, toIndex); - } - - @Override - public int hashCode() { - return this.syncList.hashCode(); - } - - @Override - public boolean isEmpty() { - return this.syncList.isEmpty(); - } - - @Override - public boolean contains(Object o) { - return this.syncList.contains(o); - } - - @Override - public Object[] toArray() { - return this.syncList.toArray(); - } - - @SuppressWarnings("SuspiciousToArrayCall") - @Override - public T[] toArray(T[] a) { - return this.syncList.toArray(a); - } - - @Override - public boolean remove(Object o) { - return this.syncList.remove(o); - } - - @Override - public boolean containsAll(Collection c) { - return this.syncList.containsAll(c); - } - - @Override - public boolean addAll(Collection c) { - return this.syncList.addAll(c); - } - - @Override - public boolean removeAll(Collection c) { - return this.syncList.removeAll(c); - } - - @Override - public boolean retainAll(Collection c) { - return this.syncList.retainAll(c); - } -} diff --git a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/config/MiraiConfig.kt b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/config/MiraiConfig.kt index aa8062ee3..5e9cf3171 100644 --- a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/config/MiraiConfig.kt +++ b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/config/MiraiConfig.kt @@ -22,7 +22,7 @@ class MiraiConfig(private val root: File) : MiraiConfigSection(parse(Object val dumperOptions = DumperOptions() dumperOptions.defaultFlowStyle = DumperOptions.FlowStyle.BLOCK val yaml = Yaml(dumperOptions) - val content = yaml.dump(this.sortedMap) + val content = yaml.dump(this) try { ByteArrayInputStream(content.toByteArray()).transferTo(FileOutputStream(this.root)) } catch (e: IOException) { diff --git a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/config/MiraiConfigSection.java b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/config/MiraiConfigSection.java index 10a83d414..1e1236c5b 100644 --- a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/config/MiraiConfigSection.java +++ b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/config/MiraiConfigSection.java @@ -1,7 +1,5 @@ package net.mamoe.mirai.utils.config; -import net.mamoe.mirai.utils.MiraiSynchronizedLinkedHashMap; - import java.util.LinkedHashMap; import java.util.Map; import java.util.concurrent.Callable; @@ -10,7 +8,7 @@ import java.util.function.Supplier; /** * @author NaturalHG */ -public class MiraiConfigSection extends MiraiSynchronizedLinkedHashMap { +public class MiraiConfigSection extends LinkedHashMap { public MiraiConfigSection(){ super();