Skip to content

Commit b4d5959

Browse files
committed
♻️ refactor: refactor codebase #3
1 parent eee2d15 commit b4d5959

4 files changed

Lines changed: 57 additions & 2 deletions

File tree

plugin/src/main/groovy/org/unify4j/common/Auth4j.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import org.unify4j.model.builder.HttpWrapBuilder;
44
import org.unify4j.model.c.HttpHeaders;
55
import org.unify4j.model.enums.AuthType;
6-
import org.unify4j.model.onlyrd.AbstractAuthClass;
6+
import org.unify4j.model.rd.AbstractAuthClass;
77
import org.unify4j.model.response.WrapResponse;
88

99
import java.util.Base64;

plugin/src/main/groovy/org/unify4j/common/Collection4j.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
5+
import org.unify4j.model.c.Pair;
56

67
import java.lang.reflect.Array;
78
import java.util.*;
9+
import java.util.concurrent.ConcurrentHashMap;
810
import java.util.function.Predicate;
911
import java.util.stream.Collectors;
1012
import java.util.stream.Stream;
@@ -649,6 +651,29 @@ public static String toString(Collection<?> collections, String delimiter) {
649651
return builder.substring(delimiter.length());
650652
}
651653

654+
/**
655+
* Creates an unmodifiable map from an array of Pair objects.
656+
* <p>
657+
* This method takes a variable number of Pair objects and constructs
658+
* a thread-safe map (using ConcurrentHashMap) from these pairs. The
659+
* resulting map is then wrapped with Collections.unmodifiableMap to
660+
* ensure it cannot be modified after creation.
661+
*
662+
* @param <KeyT> the type of keys maintained by the returned map
663+
* @param <ValueT> the type of mapped values
664+
* @param pairs an array of Pair objects from which the map will be created
665+
* @return an unmodifiable map containing the key-value pairs from the pairs array
666+
* @throws NullPointerException if any of the keys or values in the pairs are null
667+
*/
668+
@SafeVarargs
669+
public static <KeyT, ValueT> Map<KeyT, ValueT> mapOf(Pair<KeyT, ValueT>... pairs) {
670+
Map<KeyT, ValueT> map = new ConcurrentHashMap<>(pairs.length);
671+
for (Pair<KeyT, ValueT> pair : pairs) {
672+
map.put(pair.getKey(), pair.getValue());
673+
}
674+
return Collections.unmodifiableMap(map);
675+
}
676+
652677
/**
653678
* Throws UnsupportedOperationException if the list is not of type ArrayList.
654679
*
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.unify4j.model.c;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
5+
import java.io.Serializable;
6+
7+
@SuppressWarnings({"ClassCanBeRecord"})
8+
@JsonIgnoreProperties(ignoreUnknown = true)
9+
public class Pair<K, V> implements Serializable {
10+
public Pair(K key, V value) {
11+
super();
12+
this.key = key;
13+
this.value = value;
14+
}
15+
16+
private final K key;
17+
private final V value;
18+
19+
public K getKey() {
20+
return key;
21+
}
22+
23+
public V getValue() {
24+
return value;
25+
}
26+
27+
public static <K, V> Pair<K, V> of(K key, V value) {
28+
return new Pair<>(key, value);
29+
}
30+
}

plugin/src/main/groovy/org/unify4j/model/onlyrd/AbstractAuthClass.java renamed to plugin/src/main/groovy/org/unify4j/model/rd/AbstractAuthClass.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.unify4j.model.onlyrd;
1+
package org.unify4j.model.rd;
22

33
import org.unify4j.model.enums.AuthType;
44
import org.unify4j.model.response.WrapResponse;

0 commit comments

Comments
 (0)