diff options
author | geno <gabriele.genovese2@studio.unibo.it> | 2024-06-27 13:08:54 +0200 |
---|---|---|
committer | geno <gabriele.genovese2@studio.unibo.it> | 2024-06-27 13:08:54 +0200 |
commit | 673117132daa9c4fdd103189b5cd9a32a3731f5a (patch) | |
tree | 5ff72841ca65e07a2c8ee70525bb8dabbc93c7d6 /src/semanticanalysis/Share.java | |
parent | 8101f3f591f025c808084093d3f84b0eca0e67e5 (diff) |
remove duplicates
Diffstat (limited to 'src/semanticanalysis/Share.java')
-rw-r--r-- | src/semanticanalysis/Share.java | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/semanticanalysis/Share.java b/src/semanticanalysis/Share.java new file mode 100644 index 0000000..c1f03c2 --- /dev/null +++ b/src/semanticanalysis/Share.java @@ -0,0 +1,37 @@ +package semanticanalysis; + +import java.util.ArrayList; + +public class Share { + + public static <T> ArrayList<T> removeDuplicates(ArrayList<T> list) { + ArrayList<T> newList = new ArrayList<T>(); + + for (T element : list) { + if (!customContains(newList, element)) { + newList.add(element); + } + } + return newList; + } + + public static <T> boolean customContains(ArrayList<T> list, T e) { + String e1 = e.toString(); + for (T element : list) { + String e2 = element.toString(); + if (e2.equals(e1)) { + return true; + } + } + return false; + } + + public static String getExtension(String fileName) { + int extensionIndex = fileName.lastIndexOf('.'); + if (extensionIndex == -1) { + return fileName; + } else { + return fileName.substring(extensionIndex + 1); + } + } +} |