1 11 package org.eclipse.ui.internal.menus; 12 13 import org.eclipse.jface.util.Util; 14 15 38 public final class SOrder { 39 40 44 static final int NO_POSITION = -1; 45 46 50 public static final int POSITION_START = 0; 51 52 56 public static final int POSITION_END = 1; 57 58 62 public static final int POSITION_BEFORE = 2; 63 64 68 public static final int POSITION_AFTER = 3; 69 70 75 private final int position; 76 77 82 private final String relativeTo; 83 84 97 public SOrder(final int position) { 98 this(position, null); 99 } 100 101 119 public SOrder(final int position, final String relativeTo) { 120 if ((position < POSITION_START) || (position > POSITION_AFTER)) { 121 throw new IllegalArgumentException ( 122 "A location needs a valid position. Got: " + position); } 124 125 if ((position == POSITION_AFTER) || (position == POSITION_BEFORE)) { 126 if (relativeTo == null) { 127 throw new NullPointerException ( 128 "A location positioned before or after needs an identifier of the menu element to which the position is relative"); } 130 } else if (relativeTo != null) { 131 throw new IllegalArgumentException ( 132 "A relative identifier was provided for a non-relative position"); } 134 135 this.position = position; 136 this.relativeTo = relativeTo; 137 } 138 139 146 public final int getPosition() { 147 return position; 148 } 149 150 160 public final String getRelativeTo() { 161 return relativeTo; 162 } 163 164 public final String toString() { 165 final StringBuffer buffer = new StringBuffer (); 166 buffer.append("SOrder("); switch (position) { 168 case POSITION_AFTER: 169 buffer.append("after"); break; 171 case POSITION_BEFORE: 172 buffer.append("before"); break; 174 case POSITION_END: 175 buffer.append("end"); break; 177 case POSITION_START: 178 buffer.append("start"); break; 180 default: 181 buffer.append("unknown"); } 183 buffer.append(','); 184 buffer.append(relativeTo); 185 buffer.append(')'); 186 return buffer.toString(); 187 } 188 189 192 public boolean equals(Object obj) { 193 if (this == obj) { 194 return true; 195 } 196 if (obj instanceof SOrder) { 197 SOrder order = (SOrder) obj; 198 return position == order.position 199 && Util.equals(relativeTo, order.relativeTo); 200 } 201 return false; 202 } 203 204 207 public int hashCode() { 208 return position + Util.hashCode(relativeTo); 209 } 210 } 211 | Popular Tags |