Skip to content

Instantly share code, notes, and snippets.

@bertag
Created June 1, 2016 20:48
Show Gist options
  • Save bertag/d371d3c3e59592fd5ccbf90d42cf1053 to your computer and use it in GitHub Desktop.
Save bertag/d371d3c3e59592fd5ccbf90d42cf1053 to your computer and use it in GitHub Desktop.
Call Number Ordering/Sorting
String first = "BF 637 .C6 A88 vol.24";
String second = "BF 637 .C6 A88x vol.24";
String third = "BF 637 .C6 A888 vol.24";
//Initialize a CallNumberParser. Since we know we're only parsing LCCallNumbers, we'll keep it simple.
CallNumberParser parser = new CallNumberParser(LCCallNumber.class);
//Parse the 3 call numbers and add them to a list (deliberately out of order).
List<CallNumber> list = new ArrayList<>();
list.add(parser.parse(third));
list.add(parser.parse(first));
list.add(parser.parse(second));
//Just to prove that call number sorting works correctly, shuffle the list before sorting it according to its
//natural order (which we can do easily, since the CallNumber interface extends Comparable.
Collections.shuffle(list);
Collections.sort(list);
for(CallNumber callNumber : list) {
//Output to show that sorting worked.
System.out.println(callNumber.getClass().getSimpleName());
System.out.println("\tNormalized: " + callNumber.toString());
System.out.println("\tOrderable: " + callNumber.sortKey());
}
LCCallNumber
Normalized: BF 637 .C6 A88 vol.24
Orderable: bf000637 c6/ a88/ vol.000024
LCCallNumber
Normalized: BF 637 .C6 A88x vol.24
Orderable: bf000637 c6/ a88/x vol.000024
LCCallNumber
Normalized: BF 637 .C6 A888 vol.24
Orderable: bf000637 c6/ a888/ vol.000024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment