SubscriberIdentifier.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.node.server.NodeIdentifier;
00022 import org.ros.internal.transport.ConnectionHeader;
00023 import org.ros.namespace.GraphName;
00024 
00025 import java.net.URI;
00026 
00030 public class SubscriberIdentifier {
00031 
00032   private final NodeIdentifier nodeIdentifier;
00033   private final TopicIdentifier topicIdentifier;
00034 
00035   public SubscriberIdentifier(NodeIdentifier nodeIdentifier, TopicIdentifier topicIdentifier) {
00036     Preconditions.checkNotNull(nodeIdentifier);
00037     Preconditions.checkNotNull(topicIdentifier);
00038     this.nodeIdentifier = nodeIdentifier;
00039     this.topicIdentifier = topicIdentifier;
00040   }
00041 
00042   public ConnectionHeader toConnectionHeader() {
00043     ConnectionHeader connectionHeader = new ConnectionHeader();
00044     connectionHeader.merge(nodeIdentifier.toConnectionHeader());
00045     connectionHeader.merge(topicIdentifier.toConnectionHeader());
00046     return connectionHeader;
00047   }
00048 
00049   public NodeIdentifier getNodeIdentifier() {
00050     return nodeIdentifier;
00051   }
00052 
00053   public URI getUri() {
00054     return nodeIdentifier.getUri();
00055   }
00056 
00057   public TopicIdentifier getTopicIdentifier() {
00058     return topicIdentifier;
00059   }
00060 
00061   public GraphName getTopicName() {
00062     return topicIdentifier.getName();
00063   }
00064 
00065   @Override
00066   public String toString() {
00067     return "SubscriberIdentifier<" + nodeIdentifier + ", " + topicIdentifier + ">";
00068   }
00069 
00070   @Override
00071   public int hashCode() {
00072     final int prime = 31;
00073     int result = 1;
00074     result = prime * result + ((nodeIdentifier == null) ? 0 : nodeIdentifier.hashCode());
00075     result = prime * result + ((topicIdentifier == null) ? 0 : topicIdentifier.hashCode());
00076     return result;
00077   }
00078 
00079   @Override
00080   public boolean equals(Object obj) {
00081     if (this == obj)
00082       return true;
00083     if (obj == null)
00084       return false;
00085     if (getClass() != obj.getClass())
00086       return false;
00087     SubscriberIdentifier other = (SubscriberIdentifier) obj;
00088     if (nodeIdentifier == null) {
00089       if (other.nodeIdentifier != null)
00090         return false;
00091     } else if (!nodeIdentifier.equals(other.nodeIdentifier))
00092       return false;
00093     if (topicIdentifier == null) {
00094       if (other.topicIdentifier != null)
00095         return false;
00096     } else if (!topicIdentifier.equals(other.topicIdentifier))
00097       return false;
00098     return true;
00099   }
00100 }


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