From 6bf4b90c90f15f4ab60833bddf5b5756d1a6b1f6 Mon Sep 17 00:00:00 2001 From: Elizabeth Alexander Hunt Date: Thu, 2 Jul 2026 11:55:17 -0700 Subject: Init --- .../parser/util/SymbolComparator.java | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Homework/cs5300/project-three/parser/util/SymbolComparator.java (limited to 'Homework/cs5300/project-three/parser/util') diff --git a/Homework/cs5300/project-three/parser/util/SymbolComparator.java b/Homework/cs5300/project-three/parser/util/SymbolComparator.java new file mode 100644 index 0000000..e131c79 --- /dev/null +++ b/Homework/cs5300/project-three/parser/util/SymbolComparator.java @@ -0,0 +1,38 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package parser.util; + +import java.util.Comparator; +import java.util.HashSet; + +/** + * + * @author edwajohn + */ +public class SymbolComparator implements Comparator { + + private final HashSet terminals; + + public SymbolComparator(HashSet terminals) { + this.terminals = terminals; + } + + @Override + public int compare(String o1, String o2) { + // Slightly less efficient code for clarity. + if (terminals.contains(o1) && terminals.contains(o2)) { + return o1.compareTo(o2); + } + if (terminals.contains(o1)) { + return 1; + } + if (terminals.contains(o2)) { + return -1; + } + return o1.compareTo(o2); + } + +} -- cgit v1.3