001 /*
002 * LAPIS lightweight structured text processing system
003 *
004 * Copyright (C) 1998-2002 Carnegie Mellon University,
005 * Copyright (C) 2003 Massachusetts Institute of Technology.
006 * All rights reserved.
007 *
008 * This library is free software; you can redistribute it
009 * and/or modify it under the terms of the GNU General
010 * Public License as published by the Free Software
011 * Foundation, version 2.
012 *
013 * LAPIS homepage: http://graphics.lcs.mit.edu/lapis/
014 */
015
016 package lapisx.sort;
017
018 public class StringSortableList implements SortableList {
019 String value;
020 SortableList nextPtr;
021
022 public StringSortableList (String value, SortableList nextPtr) {
023 this.value = value;
024 this.nextPtr = nextPtr;
025 }
026
027 public Object get () { return value; }
028
029 public SortableList next () { return nextPtr; }
030
031 public void setNext (SortableList l) { nextPtr = l; }
032
033 public int compareTo (SortableList l) {
034 return value.compareTo ((String)l.get ());
035 }
036
037 public void dump () {
038 System.out.print (value + " ");
039 if (nextPtr != null)
040 ((StringSortableList)nextPtr).dump ();
041 }
042
043 public static StringSortableList make (String[] words) {
044 return make (words, 0);
045 }
046
047 private static StringSortableList make (String[] words, int i) {
048 if (i >= words.length)
049 return null;
050 return new StringSortableList (words[i], make (words, i+1));
051 }
052
053 }