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.

преди 21 години
преди 21 години
преди 21 години
преди 14 години
преди 21 години
преди 14 години
преди 21 години
преди 21 години
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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.DataOutputStream;
  14. import java.io.IOException;
  15. public class TypeSafeEnum {
  16. private byte key;
  17. private String name;
  18. public TypeSafeEnum(String name, int key) {
  19. this.name = name;
  20. if (key > Byte.MAX_VALUE || key < Byte.MIN_VALUE) {
  21. throw new IllegalArgumentException("key doesn't fit into a byte: " + key);
  22. }
  23. this.key = (byte) key;
  24. }
  25. public String toString() {
  26. return name;
  27. }
  28. public String getName() {
  29. return name;
  30. }
  31. public byte getKey() {
  32. return key;
  33. }
  34. public void write(DataOutputStream s) throws IOException {
  35. s.writeByte(key);
  36. }
  37. @Override
  38. public int hashCode() {
  39. return name.hashCode()*37+key;
  40. }
  41. @Override
  42. public boolean equals(Object o) {
  43. return (o instanceof TypeSafeEnum) &&
  44. ((TypeSafeEnum)o).key == key &&
  45. ((TypeSafeEnum)o).name.equals(name);
  46. }
  47. }