00001 /* 00002 * Copyright (C) 2012 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.server.master; 00018 00019 import com.google.common.collect.ImmutableSet; 00020 import com.google.common.collect.Sets; 00021 00022 import org.ros.namespace.GraphName; 00023 00024 import java.net.URI; 00025 import java.util.Set; 00026 00032 public class NodeRegistrationInfo { 00033 00037 private final GraphName nodeName; 00038 00042 private final URI nodeSlaveUri; 00043 00047 private final Set<TopicRegistrationInfo> publishers; 00048 00052 private final Set<TopicRegistrationInfo> subscribers; 00053 00057 private final Set<ServiceRegistrationInfo> services; 00058 00059 public NodeRegistrationInfo(GraphName nodeName, URI nodeSlaveUri) { 00060 this.nodeName = nodeName; 00061 this.nodeSlaveUri = nodeSlaveUri; 00062 this.publishers = Sets.newHashSet(); 00063 this.subscribers = Sets.newHashSet(); 00064 this.services = Sets.newHashSet(); 00065 } 00066 00070 public GraphName getNodeName() { 00071 return nodeName; 00072 } 00073 00077 public URI getNodeSlaveUri() { 00078 return nodeSlaveUri; 00079 } 00080 00086 public boolean hasRegistrations() { 00087 return !publishers.isEmpty() || !subscribers.isEmpty() || !services.isEmpty(); 00088 } 00089 00095 public Set<TopicRegistrationInfo> getPublishers() { 00096 return ImmutableSet.copyOf(publishers); 00097 } 00098 00105 public void addPublisher(TopicRegistrationInfo publisherTopic) { 00106 publishers.add(publisherTopic); 00107 } 00108 00117 public boolean removePublisher(TopicRegistrationInfo publisherTopic) { 00118 return publishers.remove(publisherTopic); 00119 } 00120 00126 public Set<TopicRegistrationInfo> getSubscribers() { 00127 return ImmutableSet.copyOf(subscribers); 00128 } 00129 00136 public void addSubscriber(TopicRegistrationInfo subscriberTopic) { 00137 subscribers.add(subscriberTopic); 00138 } 00139 00148 public boolean removeSubscriber(TopicRegistrationInfo subscriberTopic) { 00149 return subscribers.remove(subscriberTopic); 00150 } 00151 00157 public Set<ServiceRegistrationInfo> getServices() { 00158 return ImmutableSet.copyOf(services); 00159 } 00160 00167 public void addService(ServiceRegistrationInfo service) { 00168 services.add(service); 00169 } 00170 00179 public boolean removeService(ServiceRegistrationInfo service) { 00180 return services.remove(service); 00181 } 00182 00183 @Override 00184 public int hashCode() { 00185 final int prime = 31; 00186 int result = 1; 00187 result = prime * result + nodeName.hashCode(); 00188 return result; 00189 } 00190 00191 @Override 00192 public boolean equals(Object obj) { 00193 if (this == obj) 00194 return true; 00195 if (obj == null) 00196 return false; 00197 if (getClass() != obj.getClass()) 00198 return false; 00199 NodeRegistrationInfo other = (NodeRegistrationInfo) obj; 00200 if (!nodeName.equals(other.nodeName)) 00201 return false; 00202 return true; 00203 } 00204 }