You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TypeSafeEnum.java 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* *******************************************************************
  2. * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Xerox/PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.util;
  13. import java.io.*;
  14. public class TypeSafeEnum {
  15. private byte key;
  16. private String name;
  17. public TypeSafeEnum(String name, int key) {
  18. this.name = name;
  19. if (key > Byte.MAX_VALUE || key < Byte.MIN_VALUE) {
  20. throw new IllegalArgumentException("key doesn't fit into a byte: " + key);
  21. }
  22. this.key = (byte) key;
  23. }
  24. public String toString() {
  25. return name;
  26. }
  27. public String getName() {
  28. return name;
  29. }
  30. public byte getKey() {
  31. return key;
  32. }
  33. public void write(DataOutputStream s) throws IOException {
  34. s.writeByte(key);
  35. }
  36. }