TopicIdentifier.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.node.topic;
00018 
00019 import com.google.common.base.Preconditions;
00020 
00021 import org.ros.internal.transport.ConnectionHeader;
00022 import org.ros.internal.transport.ConnectionHeaderFields;
00023 import org.ros.namespace.GraphName;
00024 
00030 public class TopicIdentifier {
00031   
00032   private final GraphName name;
00033   
00034   public static TopicIdentifier forName(String name) {
00035     return new TopicIdentifier(GraphName.of(name));
00036   }
00037 
00038   public TopicIdentifier(GraphName name) {
00039     Preconditions.checkNotNull(name);
00040     Preconditions.checkArgument(name.isGlobal());
00041     this.name = name;
00042   }
00043   
00044   public ConnectionHeader toConnectionHeader() {
00045     ConnectionHeader connectionHeader = new ConnectionHeader();
00046     connectionHeader.addField(ConnectionHeaderFields.TOPIC, name.toString());
00047     return connectionHeader;
00048   }
00049 
00050   public GraphName getName() {
00051     return name;
00052   }
00053   
00054   @Override
00055   public String toString() {
00056     return "TopicIdentifier<" + name + ">";
00057   }
00058 
00059   @Override
00060   public int hashCode() {
00061     final int prime = 31;
00062     int result = 1;
00063     result = prime * result + ((name == null) ? 0 : name.hashCode());
00064     return result;
00065   }
00066 
00067   @Override
00068   public boolean equals(Object obj) {
00069     if (this == obj) return true;
00070     if (obj == null) return false;
00071     if (getClass() != obj.getClass()) return false;
00072     TopicIdentifier other = (TopicIdentifier) obj;
00073     if (name == null) {
00074       if (other.name != null) return false;
00075     } else if (!name.equals(other.name)) return false;
00076     return true;
00077   }
00078 }


rosjava_core
Author(s):
autogenerated on Wed Aug 26 2015 16:06:49