Skip to content

Commit 92bf9a4

Browse files
authored
fix: Implemented arrayRemoveDuplicates (casbin#263)
fix: Implemented a method which returned "true" without doing anything, used in Policy.java class
1 parent 5b7bfe0 commit 92bf9a4

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/main/java/org/casbin/jcasbin/model/Policy.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ public List<String> getValuesForFieldInPolicy(String sec, String ptype, int fiel
357357
values.add(rule.get(fieldIndex));
358358
}
359359

360-
Util.arrayRemoveDuplicates(values);
360+
values = Util.arrayRemoveDuplicates(values);
361361

362362
return values;
363363
}

src/main/java/org/casbin/jcasbin/util/Util.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import java.util.ArrayList;
3030
import java.util.Collections;
3131
import java.util.List;
32+
import java.util.Set;
33+
import java.util.LinkedHashSet;
3234
import java.util.regex.Matcher;
3335
import java.util.regex.Pattern;
3436

@@ -199,13 +201,14 @@ public static boolean array2DEquals(List<List<String>> a, List<List<String>> b)
199201
}
200202

201203
/**
202-
* arrayRemoveDuplicates removes any duplicated elements in a string array.
204+
* arrayRemoveDuplicates removes any duplicated elements in a string array preserving the order.
203205
*
204206
* @param s the array.
205207
* @return the array without duplicates.
206208
*/
207-
public static boolean arrayRemoveDuplicates(List<String> s) {
208-
return true;
209+
public static List<String> arrayRemoveDuplicates(List<String> s) {
210+
Set<String> set = new LinkedHashSet<>(s);
211+
return new ArrayList<String>(set);
209212
}
210213

211214
/**

0 commit comments

Comments
 (0)