fixed regular expressions to work properly added string parser tests
[lwes-java.git] / src / org / lwes / TypeID.java
blob794dcaf1fc6f34d74b61f558cc868b1c1a9cd46e
1 package org.lwes;
3 /**
4 * This class contains some global variables used in various parts of
5 * the event system.
6 * @author Anthony Molinaro
7 * @author Michael P. Lum
8 */
9 public class TypeID
11 /**
12 * The token used for <tt>undefined</tt> types in LWES
14 public final static byte UNDEFINED_TOKEN = (byte)0xff;
16 /**
17 * The token used by <tt>uint16</tt> in the Event Serialization Protocol
19 public final static byte UINT16_TOKEN = (byte)0x01;
21 /**
22 * The token used by <tt>int16</tt> in the Event Serialization Protocol
24 public final static byte INT16_TOKEN = (byte)0x02;
25 /**
26 * The token used by <tt>uint32</tt> in the Event Serialization Protocol
28 public final static byte UINT32_TOKEN = (byte)0x03;
29 /**
30 * The token used by <tt>int32</tt> in the Event Serialization Protocol
32 public final static byte INT32_TOKEN = (byte)0x04;
33 /**
34 * The token used by <tt>string</tt> in the Event Serialization Protocol
36 public final static byte STRING_TOKEN = (byte)0x05;
37 /**
38 * The token used by <tt>ip_addr</tt> in the Event Serialization Protocol
40 public final static byte IPADDR_TOKEN = (byte)0x06;
41 /**
42 * The token used by <tt>int64</tt> in the Event Serialization Protocol
44 public final static byte INT64_TOKEN = (byte)0x07;
45 /**
46 * The token used by <tt>uint64</tt> in the Event Serialization Protocol
48 public final static byte UINT64_TOKEN = (byte)0x08;
49 /**
50 * The token used by <tt>boolean</tt> in the Event Serialization Protocol
52 public final static byte BOOLEAN_TOKEN= (byte)0x09;
54 /**
55 * The string used by <tt>uint16</tt> in the Event Serialization Protocol
57 public final static String UINT16_STRING = "uint16";
58 /**
59 * The string used by <tt>int16</tt> in the Event Serialization Protocol
61 public final static String INT16_STRING = "int16";
62 /**
63 * The string used by <tt>uint32</tt> in the Event Serialization Protocol
65 public final static String UINT32_STRING = "uint32";
66 /**
67 * The string used by <tt>int32</tt> in the Event Serialization Protocol
69 public final static String INT32_STRING = "int32";
70 /**
71 * The string used by <tt>string</tt> in the Event Serialization Protocol
73 public final static String STRING_STRING = "string";
74 /**
75 * The string used by <tt>ip_addr</tt> in the Event Serialization Protocol
77 public final static String IPADDR_STRING= "ip_addr";
78 /**
79 * The string used by <tt>int64</tt> in the Event Serialization Protocol
81 public final static String INT64_STRING = "int64";
82 /**
83 * The string used by <tt>uint64</tt> in the Event Serialization Protocol
85 public final static String UINT64_STRING = "uint64";
86 /**
87 * The string used by <tt>boolean</tt> in the Event Serialization Protocol
89 public final static String BOOLEAN_STRING= "boolean";
91 /**
92 * This is a regular expression for parsing an integer number from a string
94 public final static String SIGNED_INTEGER_REGEX = "-?\\d+";
95 /**
96 * This is a regular expression for parsing an unsigned integer number
97 * from a string
99 public final static String UNSIGNED_INTEGER_REGEX = "\\d+(?=\\s|$)";
101 * This is a regular expression for matching a hexidecimal short from a string
103 public final static String HEX_SHORT_REGEX = "0x[0-9a-fA-F]{1,4}(?=\\s|$)";
105 * This is a regular expression for matching a hexidecimal int from a string
107 public final static String HEX_INT_REGEX = "0x[0-9a-fA-F]{5,8}(?=\\s|$)";
109 * This is a regular expression for matching a hexidecimal long from a string
111 public final static String HEX_LONG_REGEX = "0x[0-9a-fA-F]{9,16}(?=\\s|$)";
113 * This is a regular expression for matching an ip address from a string
115 public final static String IP_ADDR_REGEX
116 = "\\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b";
118 * This is a regular expression for matching a boolean from a string
120 public final static String BOOLEAN_REGEX = "true|false";
123 * Simple conversion utility
125 public static String byteIDToString(byte id)
127 switch(id)
129 case UINT16_TOKEN :
130 return UINT16_STRING;
131 case INT16_TOKEN :
132 return INT16_STRING;
133 case UINT32_TOKEN :
134 return UINT32_STRING;
135 case INT32_TOKEN :
136 return INT32_STRING;
137 case STRING_TOKEN :
138 return STRING_STRING;
139 case IPADDR_TOKEN :
140 return IPADDR_STRING;
141 case INT64_TOKEN :
142 return INT64_STRING;
143 case UINT64_TOKEN :
144 return UINT64_STRING;
145 case BOOLEAN_TOKEN:
146 return BOOLEAN_STRING;
147 default:
148 return null;
153 * Another conversion utility
155 public static byte stringToByteID(String id)
157 if ( id.equals(UINT16_STRING) )
158 return UINT16_TOKEN;
159 else if ( id.equals(INT16_STRING) )
160 return INT16_TOKEN;
161 else if ( id.equals(UINT32_STRING) )
162 return UINT32_TOKEN;
163 else if ( id.equals(INT32_STRING) )
164 return INT32_TOKEN;
165 else if ( id.equals(STRING_STRING) )
166 return STRING_TOKEN;
167 else if ( id.equals(IPADDR_STRING) )
168 return IPADDR_TOKEN;
169 else if ( id.equals(INT64_STRING) )
170 return INT64_TOKEN;
171 else if ( id.equals(UINT64_STRING) )
172 return UINT64_TOKEN;
173 else if ( id.equals(BOOLEAN_STRING) )
174 return BOOLEAN_TOKEN;
175 else
176 return UNDEFINED_TOKEN;