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 SortableArray implements Sortable {
019 protected Object[] array;
020 protected int n;
021
022 public SortableArray (Object[] array) {
023 this.array = array;
024 this.n = array.length;
025 }
026
027 public SortableArray (Object[] array, int n) {
028 this.array = array;
029 this.n = n;
030 }
031
032 public Object get (int i) {
033 return array[i];
034 }
035
036 public void set (int i, Object o) {
037 array[i] = o;
038 }
039
040 public int size () {
041 return n;
042 }
043
044 public void swap (int i, int j) {
045 Object tmp = array[i];
046 array[i] = array[j];
047 array[j] = tmp;
048 }
049
050 public int compare (Object o1, Object o2) {
051 return o1.toString().compareTo (o2.toString ());
052 }
053 }