1 7 package com.sun.java.swing.plaf.gtk; 8 9 import java.util.*; 10 11 18 class CircularIdentityList implements Cloneable { 19 private Property property; 20 21 24 public synchronized void set(Object key, Object value) { 25 if (property == null) { 26 property = new Property(key, value, null); 27 } 28 else { 29 Property p = property; 30 Property last = p; 31 32 do { 33 if (p.key == key) { 34 p.value = value; 35 property = p; 36 return; 37 } 38 last = p; 39 p = p.next; 40 } while (p != property && p != null); 41 if (value != null) { 43 if (p == null) { 44 p = property; 46 } 47 property = new Property(key, value, p); 48 last.next = property; 49 } 50 } 51 } 52 53 56 public synchronized Object get() { 57 if (property == null) { 58 return null; 59 } 60 return property.value; 61 } 62 63 66 public synchronized Object get(Object key) { 67 if (property == null) { 68 return null; 69 } 70 Property p = property; 71 72 do { 73 if (p.key == key) { 74 return p.value; 75 } 76 p = p.next; 77 } while (p != property && p != null); 78 return null; 79 } 80 81 85 public synchronized Object next() { 86 if (property == null) { 87 return null; 88 } 89 if (property.next == null) { 90 return property.key; 91 } 92 property = property.next; 93 return property.key; 94 } 95 96 public synchronized Object clone() { 97 try { 98 CircularIdentityList list = (CircularIdentityList)super.clone(); 99 100 if (property != null) { 101 list.property = (Property)property.clone(); 102 103 Property last = list.property; 104 105 while (last.next != null && last.next != property) { 106 last.next = (Property)last.next.clone(); 107 last = last.next; 108 } 109 last.next = list.property; 110 } 111 return list; 112 } catch (CloneNotSupportedException cnse) { 113 } 114 return null; 115 } 116 117 118 static class Property implements Cloneable { 119 Object key; 120 Object value; 121 Property next; 122 123 Property(Object key, Object value, Property next) { 124 this.key = key; 125 this.value = value; 126 this.next = next; 127 } 128 129 public Object clone() { 130 try { 131 return super.clone(); 132 } catch (CloneNotSupportedException cnse) { 133 } 134 return null; 135 } 136 } 137 } 138 | Popular Tags |