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.message; 00018 00019 import com.google.common.base.Preconditions; 00020 00028 public class MessageDeclaration { 00029 00030 private final MessageIdentifier messageIdentifier; 00031 private final String definition; 00032 00033 public static MessageDeclaration of(String type, String definition) { 00034 Preconditions.checkNotNull(type); 00035 Preconditions.checkNotNull(definition); 00036 return new MessageDeclaration(MessageIdentifier.of(type), definition); 00037 } 00038 00045 public MessageDeclaration(MessageIdentifier messageIdentifier, String definition) { 00046 Preconditions.checkNotNull(messageIdentifier); 00047 Preconditions.checkNotNull(definition); 00048 this.messageIdentifier = messageIdentifier; 00049 this.definition = definition; 00050 } 00051 00052 public MessageIdentifier getMessageIdentifier() { 00053 return messageIdentifier; 00054 } 00055 00056 public String getType() { 00057 return messageIdentifier.getType(); 00058 } 00059 00060 public String getPackage() { 00061 return messageIdentifier.getPackage(); 00062 } 00063 00064 public String getName() { 00065 return messageIdentifier.getName(); 00066 } 00067 00068 public String getDefinition() { 00069 Preconditions.checkNotNull(definition); 00070 return definition; 00071 } 00072 00073 @Override 00074 public String toString() { 00075 return String.format("MessageDeclaration<%s>", messageIdentifier.toString()); 00076 } 00077 00078 @Override 00079 public int hashCode() { 00080 final int prime = 31; 00081 int result = 1; 00082 result = prime * result + ((definition == null) ? 0 : definition.hashCode()); 00083 result = prime * result + ((messageIdentifier == null) ? 0 : messageIdentifier.hashCode()); 00084 return result; 00085 } 00086 00087 @Override 00088 public boolean equals(Object obj) { 00089 if (this == obj) 00090 return true; 00091 if (obj == null) 00092 return false; 00093 if (getClass() != obj.getClass()) 00094 return false; 00095 MessageDeclaration other = (MessageDeclaration) obj; 00096 if (definition == null) { 00097 if (other.definition != null) 00098 return false; 00099 } else if (!definition.equals(other.definition)) 00100 return false; 00101 if (messageIdentifier == null) { 00102 if (other.messageIdentifier != null) 00103 return false; 00104 } else if (!messageIdentifier.equals(other.messageIdentifier)) 00105 return false; 00106 return true; 00107 } 00108 }