Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ziqian zhang
Grasscutter
Commits
aa292b1f
Commit
aa292b1f
authored
May 06, 2022
by
KingRainbow44
Browse files
Update `Utils.java`
parent
0d7f58fc
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/utils/Utils.java
View file @
aa292b1f
...
...
@@ -5,6 +5,8 @@ import java.nio.file.Files;
import
java.nio.file.StandardCopyOption
;
import
java.time.*
;
import
java.time.temporal.TemporalAdjusters
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Random
;
import
emu.grasscutter.Config
;
...
...
@@ -260,4 +262,41 @@ public final class Utils {
Grasscutter
.
getLogger
().
warn
(
"Failed to read from input stream."
);
}
return
stringBuilder
.
toString
();
}
/**
* Switch properties from upper case to lower case?
*/
public
static
Map
<
String
,
Object
>
switchPropertiesUpperLowerCase
(
Map
<
String
,
Object
>
objMap
,
Class
<?>
cls
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>(
objMap
.
size
());
for
(
String
key
:
objMap
.
keySet
())
{
try
{
char
c
=
key
.
charAt
(
0
);
if
(
c
>=
'a'
&&
c
<=
'z'
)
{
try
{
cls
.
getDeclaredField
(
key
);
map
.
put
(
key
,
objMap
.
get
(
key
));
}
catch
(
NoSuchFieldException
e
)
{
String
s1
=
String
.
valueOf
(
c
).
toUpperCase
();
String
after
=
key
.
length
()
>
1
?
s1
+
key
.
substring
(
1
)
:
s1
;
cls
.
getDeclaredField
(
after
);
map
.
put
(
after
,
objMap
.
get
(
key
));
}
}
else
if
(
c
>=
'A'
&&
c
<=
'Z'
)
{
try
{
cls
.
getDeclaredField
(
key
);
map
.
put
(
key
,
objMap
.
get
(
key
));
}
catch
(
NoSuchFieldException
e
)
{
String
s1
=
String
.
valueOf
(
c
).
toLowerCase
();
String
after
=
key
.
length
()
>
1
?
s1
+
key
.
substring
(
1
)
:
s1
;
cls
.
getDeclaredField
(
after
);
map
.
put
(
after
,
objMap
.
get
(
key
));
}
}
}
catch
(
NoSuchFieldException
e
)
{
map
.
put
(
key
,
objMap
.
get
(
key
));
}
}
return
map
;
}
}
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