Field.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011 Google Inc.
00003  * 
00004  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
00005  * use this file except in compliance with the License. You may obtain a copy of
00006  * the License at
00007  * 
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00012  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
00013  * License for the specific language governing permissions and limitations under
00014  * the License.
00015  */
00016 
00017 package org.ros.internal.message.field;
00018 
00019 import org.jboss.netty.buffer.ChannelBuffer;
00020 
00021 
00025 public abstract class Field {
00026 
00027   protected final FieldType type;
00028   protected final String name;
00029   protected final boolean isConstant;
00030 
00031   protected Field(FieldType type, String name, boolean isConstant) {
00032     this.name = name;
00033     this.type = type;
00034     this.isConstant = isConstant;
00035   }
00036 
00040   public String getName() {
00041     return name;
00042   }
00043 
00047   public FieldType getType() {
00048     return type;
00049   }
00050 
00054   public boolean isConstant() {
00055     return isConstant;
00056   }
00057 
00062   public String getMd5String() {
00063     if (isConstant()) {
00064       return String.format("%s %s=%s\n", getType().getMd5String(), getName(), getValue());
00065     }
00066     return String.format("%s %s\n", getType().getMd5String(), getName());
00067   }
00068 
00069   public abstract void serialize(ChannelBuffer buffer);
00070 
00071   public abstract void deserialize(ChannelBuffer buffer);
00072 
00073   public abstract <T> T getValue();
00074 
00075   // TODO(damonkohler): Why not make Field generic?
00076   public abstract void setValue(Object value);
00077 
00078   public abstract String getJavaTypeName();
00079 
00080   @Override
00081   public int hashCode() {
00082     final int prime = 31;
00083     int result = 1;
00084     result = prime * result + (isConstant ? 1231 : 1237);
00085     result = prime * result + ((name == null) ? 0 : name.hashCode());
00086     result = prime * result + ((type == null) ? 0 : type.hashCode());
00087     return result;
00088   }
00089 
00090   @Override
00091   public boolean equals(Object obj) {
00092     if (this == obj)
00093       return true;
00094     if (obj == null)
00095       return false;
00096     if (getClass() != obj.getClass())
00097       return false;
00098     Field other = (Field) obj;
00099     if (isConstant != other.isConstant)
00100       return false;
00101     if (name == null) {
00102       if (other.name != null)
00103         return false;
00104     } else if (!name.equals(other.name))
00105       return false;
00106     if (type == null) {
00107       if (other.type != null)
00108         return false;
00109     } else if (!type.equals(other.type))
00110       return false;
00111     return true;
00112   }
00113 }


rosjava_bootstrap
Author(s): Daniel Stonier , Damon Kohler
autogenerated on Fri Aug 28 2015 12:41:44