Skip to content

Commit b3f78b9

Browse files
committed
refactored references api
1 parent f752eaa commit b3f78b9

37 files changed

Lines changed: 668 additions & 1587 deletions

rlib-common/src/main/java/com/ss/rlib/common/Monitoring.java

Lines changed: 0 additions & 171 deletions
This file was deleted.

rlib-common/src/main/java/com/ss/rlib/common/util/VarTable.java

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,30 @@ public int getInt(@NotNull String key, int def) {
802802
throw new IllegalStateException("the value: " + object + " can't be presented as int, key: " + key);
803803
}
804804

805+
/**
806+
* Get an int array value by the key.
807+
*
808+
* @param key the key.
809+
* @return the int array value.
810+
* @throws IllegalStateException if the value can't be presented as int array.
811+
* @throws IllegalArgumentException if the value isn't exist.
812+
* @since 9.2.1
813+
*/
814+
public @NotNull int[] getIntArray(@NotNull String key) {
815+
816+
var object = values.get(key);
817+
818+
if(object == null) {
819+
throw new IllegalArgumentException("not found " + key);
820+
} else if (object instanceof int[]) {
821+
return (int[]) object;
822+
} else if (object instanceof Integer[]) {
823+
return ArrayUtils.toIntArray((Integer[]) object);
824+
}
825+
826+
throw new IllegalStateException("the value: " + object + " can't be presented as int array, key: " + key);
827+
}
828+
805829
/**
806830
* Get an int array value by the key.
807831
*
@@ -836,24 +860,12 @@ public int getInt(@NotNull String key, int def) {
836860
} else if (object instanceof int[]) {
837861
return (int[]) object;
838862
} else if (object instanceof String) {
839-
return parseIntArray(regex, object);
863+
return ArrayUtils.toIntArray((String) object, regex);
840864
}
841865

842866
throw new IllegalStateException("the value: " + object + " can't be presented as int array, key: " + key);
843867
}
844868

845-
private @NotNull int[] parseIntArray(@NotNull String regex, @NotNull Object object) {
846-
847-
var strings = object.toString().split(regex);
848-
var result = new int[strings.length];
849-
850-
for (int i = 0, length = strings.length; i < length; i++) {
851-
result[i] = Integer.parseInt(strings[i]);
852-
}
853-
854-
return result;
855-
}
856-
857869
/**
858870
* Get an int array value by the key.
859871
*
@@ -888,7 +900,7 @@ public int getInt(@NotNull String key, int def) {
888900
} else if (object instanceof int[]) {
889901
return (int[]) object;
890902
} else if (object instanceof String) {
891-
return parseIntArray(regex, object);
903+
return ArrayUtils.toIntArray((String) object, regex);
892904
}
893905

894906
throw new IllegalStateException("the value: " + object + " can't be presented as int array, key: " + key);

rlib-common/src/main/java/com/ss/rlib/common/util/XmlUtils.java

Lines changed: 0 additions & 150 deletions
This file was deleted.

0 commit comments

Comments
 (0)