SubscriberDeclaration.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 org.ros.internal.node.server.NodeIdentifier;
00020 import org.ros.internal.transport.ConnectionHeader;
00021 import org.ros.internal.transport.ConnectionHeaderFields;
00022 import org.ros.namespace.GraphName;
00023 
00024 import java.net.URI;
00025 import java.util.Map;
00026 
00030 public class SubscriberDeclaration {
00031 
00032   private final SubscriberIdentifier subscriberIdentifier;
00033   private final TopicDeclaration topicDeclaration;
00034 
00043   public static SubscriberDeclaration newFromHeader(Map<String, String> header) {
00044     NodeIdentifier nodeIdentifier =
00045         new NodeIdentifier(GraphName.of(header.get(ConnectionHeaderFields.CALLER_ID)), null);
00046     TopicDeclaration topicDeclaration = TopicDeclaration.newFromHeader(header);
00047     return new SubscriberDeclaration(new SubscriberIdentifier(nodeIdentifier,
00048         topicDeclaration.getIdentifier()), topicDeclaration);
00049   }
00050 
00051   public SubscriberDeclaration(SubscriberIdentifier subscriberIdentifier,
00052       TopicDeclaration topicDeclaration) {
00053     this.subscriberIdentifier = subscriberIdentifier;
00054     this.topicDeclaration = topicDeclaration;
00055   }
00056 
00057   public NodeIdentifier getNodeIdentifier() {
00058     return subscriberIdentifier.getNodeIdentifier();
00059   }
00060 
00061   public URI getSlaveUri() {
00062     return subscriberIdentifier.getUri();
00063   }
00064 
00065   public GraphName getTopicName() {
00066     return topicDeclaration.getName();
00067   }
00068 
00069   public ConnectionHeader toConnectionHeader() {
00070     ConnectionHeader connectionHeader = new ConnectionHeader();
00071     connectionHeader.merge(subscriberIdentifier.toConnectionHeader());
00072     connectionHeader.merge(topicDeclaration.toConnectionHeader());
00073     return connectionHeader;
00074   }
00075 
00076   @Override
00077   public String toString() {
00078     return "SubscriberDefinition<" + subscriberIdentifier + ", " + topicDeclaration + ">";
00079   }
00080 
00081   @Override
00082   public int hashCode() {
00083     final int prime = 31;
00084     int result = 1;
00085     result =
00086         prime * result + ((subscriberIdentifier == null) ? 0 : subscriberIdentifier.hashCode());
00087     result = prime * result + ((topicDeclaration == null) ? 0 : topicDeclaration.hashCode());
00088     return result;
00089   }
00090 
00091   @Override
00092   public boolean equals(Object obj) {
00093     if (this == obj)
00094       return true;
00095     if (obj == null)
00096       return false;
00097     if (getClass() != obj.getClass())
00098       return false;
00099     SubscriberDeclaration other = (SubscriberDeclaration) obj;
00100     if (subscriberIdentifier == null) {
00101       if (other.subscriberIdentifier != null)
00102         return false;
00103     } else if (!subscriberIdentifier.equals(other.subscriberIdentifier))
00104       return false;
00105     if (topicDeclaration == null) {
00106       if (other.topicDeclaration != null)
00107         return false;
00108     } else if (!topicDeclaration.equals(other.topicDeclaration))
00109       return false;
00110     return true;
00111   }
00112 }


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