summaryrefslogtreecommitdiffstats
blob: fa4b5ed1791254ff707ea0040b68a0f932c935c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/***************************************************************************
 * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *    Eike Stepper - initial API and implementation
 **************************************************************************/
package org.eclipse.internal.net4j.transport.tcp;

import org.eclipse.net4j.transport.tcp.TCPConnectorDescription;
import org.eclipse.net4j.util.ObjectUtil;

import java.io.Serializable;
import java.text.MessageFormat;

/**
 * @author Eike Stepper
 */
public class TCPConnectorDescriptionImpl implements TCPConnectorDescription, Cloneable, Serializable
{
  private static final long serialVersionUID = 1L;

  private String host;

  private int port = DEFAULT_PORT;

  public TCPConnectorDescriptionImpl()
  {
  }

  public String getHost()
  {
    return host;
  }

  public void setHost(String host)
  {
    this.host = host;
  }

  public int getPort()
  {
    return port;
  }

  public void setPort(int port)
  {
    this.port = port;
  }

  public String getDisplayName()
  {
    return MessageFormat.format("{0}:{1}", host, port);
  }

  @Override
  protected Object clone() throws CloneNotSupportedException
  {
    TCPConnectorDescriptionImpl description = new TCPConnectorDescriptionImpl();
    description.setHost(host);
    description.setPort(port);
    return description;
  }

  @Override
  public boolean equals(Object obj)
  {
    if (obj instanceof TCPConnectorDescription)
    {
      TCPConnectorDescription that = (TCPConnectorDescription)obj;
      return this.port == that.getPort() && ObjectUtil.equals(this.host, that.getHost());
    }

    return false;
  }

  @Override
  public int hashCode()
  {
    return port ^ host.hashCode();
  }

  @Override
  public String toString()
  {
    return getDisplayName();
  }
}