1 46 package org.mr.core.net; 47 48 import java.util.HashMap ; 49 import java.util.Map ; 50 51 59 public class TransportType { 60 61 private final String type; 62 private final byte priority; 63 private static Map typeMap = new HashMap (); 64 65 public static final TransportType TCP = new TransportType("TCP", (byte) 0); 66 public static final TransportType HTTP = new TransportType("HTTP", (byte) 1); 67 public static final TransportType SSL = new TransportType("SSL", (byte) 2); 68 public static final TransportType MWB = new TransportType("MWB", (byte) 3); 69 public static final TransportType UNKNOWN = new TransportType("UNKNOWN", (byte) 4); 70 71 72 static { 73 typeMap.put("TCP", TCP); 74 typeMap.put("HTTP", HTTP); 75 typeMap.put("UNKNOWN", UNKNOWN); 76 typeMap.put("SSL", SSL); 77 typeMap.put("MWB", MWB); 78 } 80 81 private TransportType(String type, byte priority) { 82 this.type = type; 83 this.priority = priority; 84 } 86 public String toString() { 87 return type; 88 } 90 91 95 public byte getPriority() { 96 return this.priority; 97 } 98 99 105 public static TransportType getTransportTypeFromString(String type) { 106 TransportType result = UNKNOWN; 107 Object obj = typeMap.get(type); 108 109 if (obj != null) 110 result = (TransportType) obj; 111 112 return result; 113 } 115 116 public boolean equals (Object o) { 117 if (o == null) 118 return false; 119 if (this == o) 120 return true; 121 return o instanceof TransportType ? this.type == ((TransportType)o).type: false; 122 } 124 127 public int hashCode(){ 128 return this.type.hashCode(); 129 } 130 131 } | Popular Tags |