BowlerKernel
BowlerDataType.java
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright 2010 Neuron Robotics, LLC
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  ******************************************************************************/
15 package com.neuronrobotics.sdk.common;
16 
17 import java.util.EnumSet;
18 import java.util.HashMap;
19 import java.util.Map;
20 
21 // TODO: Auto-generated Javadoc
25 public enum BowlerDataType implements ISendable {
26 
28  I08(8),
29 
31  I16(16),
32 
34  I32(32),
35 
37  STR(37),
38 
40  I32STR(38),
41 
43  ASCII(39),
44 
46  FIXED100(41),
47 
49  FIXED1k(42),
50 
52  BOOL(43),
53 
56 
58  INVALID(0);
59 
60 
62  private static final Map<Byte,BowlerDataType> lookup = new HashMap<Byte,BowlerDataType>();
64  private byte value=0;
65 
66  static {
67  for(BowlerDataType cm : EnumSet.allOf(BowlerDataType.class)) {
68  lookup.put(cm.getValue(), cm);
69  }
70  }
71 
72 
78  private BowlerDataType(int val) {
79  value = (byte) val;
80  }
81 
87  public byte getValue() {
88  return value;
89  }
90 
97  public static BowlerDataType get(byte code) {
98  try{
99  BowlerDataType tmp =lookup.get(code);
100  if(tmp == null){
101  throw new RuntimeException("Unrecognized Bowler data type "+code);
102  }
103  return tmp;
104  }catch(Exception ex){
105  ex.printStackTrace();
106  }
107 
108  return BowlerDataType.INVALID;
109 
110  }
111 
112  /* (non-Javadoc)
113  * @see com.neuronrobotics.sdk.common.ISendable#getBytes()
114  */
115  public byte[] getBytes() {
116  byte [] b = {getValue()};
117  return b;
118  }
119 
120  /* (non-Javadoc)
121  * @see java.lang.Enum#toString()
122  */
123  public String toString(){
124  String s="(NOT VALID)";
125  switch (value){
126  case 8:
127  return "(char)";
128  case 16:
129  return "(short)";
130  case 32:
131  return "(int)";
132  case 37:
133  return "(char [])";
134  case 38:
135  return "(int [])";
136  case 39:
137  return "(String)";
138  case 41:
139  return "(Fixed 100)";
140  case 42:
141  return "(Fixed 1k)";
142  case 43:
143  return "(Boolean)";
144  }
145  return s;
146  }
147 }
static BowlerDataType get(byte code)