View Javadoc

1   /**
2    *
3    * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4    *
5    * ====================================================================
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   * ====================================================================
18   */
19  package org.jclouds.net;
20  
21  import java.io.Serializable;
22  
23  /**
24   * As google appengine prohibits use of java.net classes, this will serve as a replacement.
25   * 
26   * @author Adrian Cole
27   */
28  public class IPSocket implements Serializable {
29  
30     /** The serialVersionUID */
31     private static final long serialVersionUID = 2978329372952402188L;
32  
33     private final String address;
34     private final int port;
35  
36     public IPSocket(String address, int port) {
37        this.address = address;
38        this.port = port;
39     }
40  
41     public String getAddress() {
42        return address;
43     }
44  
45     public int getPort() {
46        return port;
47     }
48  
49     @Override
50     public int hashCode() {
51        final int prime = 31;
52        int result = 1;
53        result = prime * result + ((address == null) ? 0 : address.hashCode());
54        result = prime * result + port;
55        return result;
56     }
57  
58     @Override
59     public boolean equals(Object obj) {
60        if (this == obj)
61           return true;
62        if (obj == null)
63           return false;
64        if (getClass() != obj.getClass())
65           return false;
66        IPSocket other = (IPSocket) obj;
67        if (address == null) {
68           if (other.address != null)
69              return false;
70        } else if (!address.equals(other.address))
71           return false;
72        if (port != other.port)
73           return false;
74        return true;
75     }
76  
77     @Override
78     public String toString() {
79        return "[address=" + address + ", port=" + port + "]";
80     }
81  
82  }