Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 package org.ros.message;
00018
00019 import com.google.common.base.Preconditions;
00020
00026 public class MessageIdentifier {
00027
00028 private String type;
00029 private String pkg;
00030 private String name;
00031
00032 public static MessageIdentifier of(String pkg, String name) {
00033 Preconditions.checkNotNull(pkg);
00034 Preconditions.checkNotNull(name);
00035 return new MessageIdentifier(pkg, name);
00036 }
00037
00038 public static MessageIdentifier of(String type) {
00039 Preconditions.checkNotNull(type);
00040
00041
00042
00043 if (!type.contains("/")) {
00044 throw new IllegalArgumentException(String.format(
00045 "Type name is invalid or not fully qualified: \"%s\"", type));
00046 }
00047 return new MessageIdentifier(type);
00048 }
00049
00050 private MessageIdentifier(String type) {
00051 this.type = type;
00052 }
00053
00054 private MessageIdentifier(String pkg, String name) {
00055 this.pkg = pkg;
00056 this.name = name;
00057 }
00058
00059 public String getType() {
00060 if (type == null) {
00061
00062
00063 StringBuilder stringBuilder = new StringBuilder(pkg.length() + name.length() + 1);
00064 stringBuilder.append(pkg);
00065 stringBuilder.append("/");
00066 stringBuilder.append(name);
00067 type = stringBuilder.toString();
00068 }
00069 return type;
00070 }
00071
00072 private void splitType() {
00073 String[] packageAndName = type.split("/", 2);
00074 pkg = packageAndName[0];
00075 name = packageAndName[1];
00076 }
00077
00078 public String getPackage() {
00079 if (pkg == null) {
00080 splitType();
00081 }
00082 return pkg;
00083 }
00084
00085 public String getName() {
00086 if (name == null) {
00087 splitType();
00088 }
00089 return name;
00090 }
00091
00092 @Override
00093 public String toString() {
00094 return String.format("MessageIdentifier<%s>", type);
00095 }
00096
00097 @Override
00098 public int hashCode() {
00099 final int prime = 31;
00100 int result = 1;
00101 result = prime * result + ((type == null) ? 0 : type.hashCode());
00102 return result;
00103 }
00104
00105 @Override
00106 public boolean equals(Object obj) {
00107 if (this == obj)
00108 return true;
00109 if (obj == null)
00110 return false;
00111 if (getClass() != obj.getClass())
00112 return false;
00113 MessageIdentifier other = (MessageIdentifier) obj;
00114 if (type == null) {
00115 if (other.type != null)
00116 return false;
00117 } else if (!type.equals(other.type))
00118 return false;
00119 return true;
00120 }
00121 }