extensions to library classes
authorjjenista <jjenista>
Thu, 26 Feb 2009 23:21:27 +0000 (23:21 +0000)
committerjjenista <jjenista>
Thu, 26 Feb 2009 23:21:27 +0000 (23:21 +0000)
Robust/src/ClassLibrary/Character.java
Robust/src/ClassLibrary/HashMapIterator.java
Robust/src/ClassLibrary/LinkedList.java
Robust/src/ClassLibrary/String.java
Robust/src/Tests/StringTest.java

index f1ca673a85bbfd09b670ed3f6d2ec778ff3fec73..2a12c8c1d9b4b8f5cfba9ee33442e2e2269b310a 100644 (file)
@@ -14,4 +14,18 @@ public class Character {
     }
     return -1;
   }
+
+  char value;
+  
+  public Character( char c ) {
+    value = c;
+  }
+
+  public Character( Character c ) {
+    value = c.value;
+  }
+
+  public String toString() {
+    return ""+value;
+  }
 }
index 48dc913711c4d2ef0feec5c0b558638ea8361016..e297cf5f948760ff8bee10b308fe11ceb52767fe 100644 (file)
@@ -1,4 +1,4 @@
-class HashMapIterator {
+class HashMapIterator extends Iterator {
   HashMap map;
   int type;
   int bin;
@@ -43,4 +43,9 @@ class HashMapIterator {
       return o;
     } else System.error();
   }
+
+  public void remove() {
+    System.out.println( "HashMapIterator.remove() not implemented." );
+    System.exit( -1 );
+  }
 }
index b4f26e69a5e935d3527ef3a45014c06af7215c60..98701fba4a47145d36fbdd734e5b474e7a391b03 100644 (file)
@@ -59,6 +59,10 @@ public class LinkedList {
     return size;
   }
 
+  public boolean isEmpty() {
+    return size == 0;
+  }
+
   public Object clone() {
     System.out.println( "LinkedList.clone() not implemented." );
     System.exit(-1);
@@ -105,11 +109,12 @@ public class LinkedList {
     getLast();
   }
 
-  public void removeFirst() {
+  public Object removeFirst() {
     if( head == null ) {
       System.out.println( "LinkedList: illegal removeFirst()" );
       System.exit(-1);
     }
+    Object o = head.element;
     head = head.next;
     if( head != null ) {
       head.prev = null;
@@ -117,13 +122,15 @@ public class LinkedList {
       tail = null;
     }
     size--;
+    return o;
   }
 
-  public void removeLast() {
+  public Object removeLast() {
     if( tail == null ) {
       System.out.println( "LinkedList: illegal removeLast()" );
       System.exit(-1);
     }
+    Object o = tail.element;
     tail = tail.prev;
     if( tail != null ) {
       tail.next = null;
@@ -131,6 +138,7 @@ public class LinkedList {
       head = null;
     }
     size--;
+    return o;
   }
 
   public void remove( Object o ) {
index a06028bff66f6f76bf8c5c7bcdb097bcc9576000..dab2feeb26c6c36ff3cbf1b55bc73b6f0704182e 100644 (file)
@@ -135,6 +135,18 @@ public class String {
     return new String(buffer);
   }
 
+  public String toLowerCase() {
+    char[] buffer=new char[count];
+    for(int i=0; i<count; i++) {
+      char x=charAt(i);
+      if (x>='A'&&x<='Z') {
+       x=(char) ((x-'A')+'a');
+      }
+      buffer[i]=x;
+    }
+    return new String(buffer);
+  }
+
   public int indexOf(int ch) {
     return this.indexOf(ch, 0);
   }
index 30d4ecd0d3758226f4764c7de6fe257538ca7970..2bc805df65070f32244f96ce1c855e65ee998c7d 100644 (file)
@@ -9,5 +9,10 @@ class StringTest {
        System.printString(a.subString(3));
        System.printString(a.subString(3,6));
        System.printString("\n");
+
+       String b = "Danger iN cAVErn_coVE";
+       System.out.println( "normal: "+b );
+       System.out.println( "upper:  "+b.toUpperCase() );
+       System.out.println( "lower:  "+b.toLowerCase() );
     }
 }