ServiceDeclaration.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.service;
00018 
00019 import com.google.common.base.Preconditions;
00020 
00021 import org.ros.internal.message.service.ServiceDescription;
00022 import org.ros.internal.transport.ConnectionHeader;
00023 import org.ros.internal.transport.ConnectionHeaderFields;
00024 import org.ros.namespace.GraphName;
00025 
00026 import java.net.URI;
00027 
00031 public class ServiceDeclaration {
00032 
00033   private final ServiceIdentifier identifier;
00034   private final ServiceDescription description;
00035 
00036   public ServiceDeclaration(ServiceIdentifier identifier, ServiceDescription description) {
00037     Preconditions.checkNotNull(identifier);
00038     Preconditions.checkNotNull(description);
00039     this.identifier = identifier;
00040     this.description = description;
00041   }
00042 
00043   public ConnectionHeader toConnectionHeader() {
00044     ConnectionHeader connectionHeader = new ConnectionHeader();
00045     connectionHeader.addField(ConnectionHeaderFields.SERVICE, getName().toString());
00046     connectionHeader.addField(ConnectionHeaderFields.TYPE, description.getType());
00047     connectionHeader.addField(ConnectionHeaderFields.MESSAGE_DEFINITION,
00048         description.getDefinition());
00049     connectionHeader.addField(ConnectionHeaderFields.MD5_CHECKSUM, description.getMd5Checksum());
00050     return connectionHeader;
00051   }
00052 
00053   public String getType() {
00054     return description.getType();
00055   }
00056 
00057   public String getDefinition() {
00058     return description.getDefinition();
00059   }
00060 
00061   public GraphName getName() {
00062     return identifier.getName();
00063   }
00064 
00065   @Override
00066   public String toString() {
00067     return "ServiceDeclaration<" + getName().toString() + ", " + description.toString() + ">";
00068   }
00069 
00070   public String getMd5Checksum() {
00071     return description.getMd5Checksum();
00072   }
00073 
00074   public URI getUri() {
00075     return identifier.getUri();
00076   }
00077 
00078   @Override
00079   public int hashCode() {
00080     final int prime = 31;
00081     int result = 1;
00082     result = prime * result + ((identifier == null) ? 0 : identifier.hashCode());
00083     result = prime * result + ((description == null) ? 0 : description.hashCode());
00084     return result;
00085   }
00086 
00087   @Override
00088   public boolean equals(Object obj) {
00089     if (this == obj)
00090       return true;
00091     if (obj == null)
00092       return false;
00093     if (getClass() != obj.getClass())
00094       return false;
00095     ServiceDeclaration other = (ServiceDeclaration) obj;
00096     if (identifier == null) {
00097       if (other.identifier != null)
00098         return false;
00099     } else if (!identifier.equals(other.identifier))
00100       return false;
00101     if (description == null) {
00102       if (other.description != null)
00103         return false;
00104     } else if (!description.equals(other.description))
00105       return false;
00106     return true;
00107   }
00108 }


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