PublisherDeclaration.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 PublisherDeclaration {
00031 
00032   private final PublisherIdentifier publisherIdentifier;
00033   private final TopicDeclaration topicDeclaration;
00034 
00035   public static PublisherDeclaration newFromNodeIdentifier(NodeIdentifier nodeIdentifier,
00036       TopicDeclaration topicDeclaration) {
00037     Preconditions.checkNotNull(nodeIdentifier);
00038     Preconditions.checkNotNull(topicDeclaration);
00039     return new PublisherDeclaration(new PublisherIdentifier(nodeIdentifier,
00040         topicDeclaration.getIdentifier()), topicDeclaration);
00041   }
00042 
00043   public PublisherDeclaration(PublisherIdentifier publisherIdentifier,
00044       TopicDeclaration topicDeclaration) {
00045     Preconditions.checkNotNull(publisherIdentifier);
00046     Preconditions.checkNotNull(topicDeclaration);
00047     Preconditions.checkArgument(publisherIdentifier.getTopicIdentifier().equals(
00048         topicDeclaration.getIdentifier()));
00049     this.publisherIdentifier = publisherIdentifier;
00050     this.topicDeclaration = topicDeclaration;
00051   }
00052   
00053   public ConnectionHeader toConnectionHeader() {
00054     ConnectionHeader connectionHeader = publisherIdentifier.toConnectionHeader();
00055     connectionHeader.merge(topicDeclaration.toConnectionHeader());
00056     return connectionHeader;
00057   }
00058 
00059   public NodeIdentifier getSlaveIdentifier() {
00060     return publisherIdentifier.getNodeIdentifier();
00061   }
00062 
00063   public GraphName getSlaveName() {
00064     return publisherIdentifier.getNodeIdentifier().getName();
00065   }
00066 
00067   public URI getSlaveUri() {
00068     return publisherIdentifier.getNodeUri();
00069   }
00070 
00071   public GraphName getTopicName() {
00072     return topicDeclaration.getName();
00073   }
00074 
00075   public String getTopicMessageType() {
00076     return topicDeclaration.getMessageType();
00077   }
00078 
00079   @Override
00080   public String toString() {
00081     return "PublisherDefinition<" + publisherIdentifier + ", " + topicDeclaration + ">";
00082   }
00083 
00084   @Override
00085   public int hashCode() {
00086     final int prime = 31;
00087     int result = 1;
00088     result = prime * result + ((publisherIdentifier == null) ? 0 : publisherIdentifier.hashCode());
00089     result = prime * result + ((topicDeclaration == null) ? 0 : topicDeclaration.hashCode());
00090     return result;
00091   }
00092 
00093   @Override
00094   public boolean equals(Object obj) {
00095     if (this == obj)
00096       return true;
00097     if (obj == null)
00098       return false;
00099     if (getClass() != obj.getClass())
00100       return false;
00101     PublisherDeclaration other = (PublisherDeclaration) obj;
00102     if (publisherIdentifier == null) {
00103       if (other.publisherIdentifier != null)
00104         return false;
00105     } else if (!publisherIdentifier.equals(other.publisherIdentifier))
00106       return false;
00107     if (topicDeclaration == null) {
00108       if (other.topicDeclaration != null)
00109         return false;
00110     } else if (!topicDeclaration.equals(other.topicDeclaration))
00111       return false;
00112     return true;
00113   }
00114 }


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