Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
5fd84411
Commit
5fd84411
authored
Aug 21, 2019
by
liujiahua123123
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
YAML supported
parent
23663e58
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
34 deletions
+58
-34
mirai-core/src/main/java/net/mamoe/mirai/MiraiServer.java
mirai-core/src/main/java/net/mamoe/mirai/MiraiServer.java
+13
-9
mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiConfig.java
...c/main/java/net/mamoe/mirai/utils/config/MiraiConfig.java
+4
-8
mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiConfigSection.java
...java/net/mamoe/mirai/utils/config/MiraiConfigSection.java
+25
-12
mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiSynchronizedLInkedListMap.java
...oe/mirai/utils/config/MiraiSynchronizedLInkedListMap.java
+16
-5
No files found.
mirai-core/src/main/java/net/mamoe/mirai/MiraiServer.java
View file @
5fd84411
...
...
@@ -114,16 +114,20 @@ public class MiraiServer {
getLogger
().
info
(
"ready to connect"
);
/*
this.qqs.put("test",new MiraiConfigSection<String>(){{
put("1","2");
put("11","2");
put("111","2");
put("1111","2");
}});
MiraiConfigSection
section
=
new
MiraiConfigSection
<
MiraiConfigSection
<
String
>>(){{
put
(
"1"
,
new
MiraiConfigSection
<>(){{
put
(
"1"
,
"0"
);
}});
}};
this
.
qqs
.
put
(
"test"
,
section
);
this
.
qqs
.
save
();
*/
System
.
out
.
println
(
this
.
qqs
.
get
());
MiraiConfigSection
<
MiraiConfigSection
>
x
=
this
.
qqs
.
getTypedSection
(
"test"
);
System
.
out
.
println
(
x
.
getSection
(
"1"
).
getInt
(
"1"
));
/*
System.out.println(v);
...
...
mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiConfig.java
View file @
5fd84411
...
...
@@ -8,9 +8,7 @@ import org.yaml.snakeyaml.Yaml;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.*
;
/**
* YAML-TYPE CONFIG
...
...
@@ -51,7 +49,7 @@ public class MiraiConfig extends MiraiConfigSection<Object> {
DumperOptions
dumperOptions
=
new
DumperOptions
();
dumperOptions
.
setDefaultFlowStyle
(
DumperOptions
.
FlowStyle
.
BLOCK
);
Yaml
yaml
=
new
Yaml
(
dumperOptions
);
String
content
=
yaml
.
dump
(
this
);
String
content
=
yaml
.
dump
(
this
.
sortedMap
);
try
{
Utils
.
writeFile
(
this
.
root
,
content
);
}
catch
(
IOException
e
)
{
...
...
@@ -64,12 +62,10 @@ public class MiraiConfig extends MiraiConfigSection<Object> {
DumperOptions
dumperOptions
=
new
DumperOptions
();
dumperOptions
.
setDefaultFlowStyle
(
DumperOptions
.
FlowStyle
.
BLOCK
);
Yaml
yaml
=
new
Yaml
(
dumperOptions
);
this
.
clear
();
try
{
Map
<
String
,
Object
>
content
=
yaml
.
loadAs
(
Utils
.
readFile
(
this
.
root
),
LinkedHashMap
.
class
);
LinkedHash
Map
<
String
,
Object
>
content
=
yaml
.
loadAs
(
Utils
.
readFile
(
this
.
root
),
LinkedHashMap
.
class
);
if
(
content
!=
null
)
{
this
.
putAll
(
content
);
System
.
out
.
println
(
this
.
keySet
().
toString
());
setContent
(
content
);
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
...
...
mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiConfigSection.java
View file @
5fd84411
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
;
import
java.util.concurrent.ConcurrentSkipListMap
;
public
class
MiraiConfigSection
<
T
>
extends
Mirai
AbstractConfigSection
<
String
,
T
>
{
public
class
MiraiConfigSection
<
T
>
extends
Mirai
SynchronizedLInkedListMap
<
String
,
T
>
{
public
MiraiConfigSection
(){
...
...
@@ -27,20 +29,31 @@ public class MiraiConfigSection<T> extends MiraiAbstractConfigSection<String, T>
return
String
.
valueOf
(
this
.
get
(
key
));
}
@SuppressWarnings
(
"unchecked"
)
public
<
D
extends
T
>
MiraiConfigSection
<
D
>
getTypedSection
(
String
key
){
var
content
=
(
SortedMap
<
String
,
D
>)
this
.
get
(
key
);
return
new
MiraiConfigSection
<>(){{
setContent
(
Collections
.
synchronizedSortedMap
(
content
));
}};
@Nullable
@Override
public
T
put
(
String
key
,
T
value
)
{
return
super
.
put
(
key
,
value
);
}
@SuppressWarnings
(
"unchecked"
)
public
<
D
>
MiraiConfigSection
<
D
>
getTypedSection
(
String
key
){
var
content
=
this
.
get
(
key
);
if
(
content
instanceof
MiraiConfigSection
){
return
(
MiraiConfigSection
<
D
>)
content
;
}
if
(
content
instanceof
Map
){
return
new
MiraiConfigSection
<>(){{
setContent
((
LinkedHashMap
<
String
,
D
>)
content
);
}};
}
return
null
;
}
public
MiraiConfigSection
<
Object
>
getSection
(
String
key
){
var
content
=
(
SortedMap
<
String
,
Object
>)
this
.
get
(
key
);
return
new
MiraiConfigSection
<>(){{
setContent
(
Collections
.
synchronizedSortedMap
(
content
));
}};
return
this
.
getTypedSection
(
key
);
}
}
mirai-core/src/main/java/net/mamoe/mirai/utils/config/Mirai
AbstractConfigSection
.java
→
mirai-core/src/main/java/net/mamoe/mirai/utils/config/Mirai
SynchronizedLInkedListMap
.java
View file @
5fd84411
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
Mirai
AbstractConfigSection
<
K
,
V
>
implements
Map
<
K
,
V
>
{
public
class
Mirai
SynchronizedLInkedListMap
<
K
,
V
>
extends
Abstract
Map
<
K
,
V
>
{
public
MiraiSynchronizedLInkedListMap
(){
this
.
sortedMap
=
Collections
.
synchronizedMap
(
new
LinkedHashMap
<>());
}
pr
ivate
Sorted
Map
<
K
,
V
>
sortedMap
;
pr
otected
Map
<
K
,
V
>
sortedMap
;
protected
void
setContent
(
Sorted
Map
<
K
,
V
>
map
){
this
.
sortedMap
=
map
;
protected
void
setContent
(
LinkedHash
Map
<
K
,
V
>
map
){
this
.
sortedMap
=
Collections
.
synchronizedMap
(
map
)
;
}
@Override
public
int
size
()
{
return
sortedMap
.
size
();
...
...
@@ -79,4 +82,12 @@ public class MiraiAbstractConfigSection<K,V> implements Map<K,V> {
public
Set
<
Entry
<
K
,
V
>>
entrySet
()
{
return
sortedMap
.
entrySet
();
}
@Override
public
String
toString
()
{
return
this
.
sortedMap
.
toString
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment