summaryrefslogtreecommitdiffstats
blob: 7145fb334ed0520a013cbee98ea1903d9011e8c1 (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
/*
 * Copyright (c) 2010 Remko Tronçon
 * Licensed under the GNU General Public License v3.
 * See Documentation/Licenses/GPLv3.txt for more information.
 */
/*
 * Copyright (c) 2010, Isode Limited, London, England.
 * All rights reserved.
 */
package com.isode.stroke.network;

import java.net.InetAddress;

public class HostAddress {

    public HostAddress() {
        address_ = null;
    }

    public HostAddress(InetAddress address) {
        address_ = address;
    }
    /*			public HostAddress(const String&);
    public 			HostAddress(const unsigned char* address, int length);
    public 		HostAddress(const boost::asio::ip::address& address);*/

    @Override
    public String toString() {
        // toString() should always be callable without risking 
        // NullPointerException
        if (address_ == null) {
            return "<no address>";
        }
        return address_.getHostAddress();
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 29 * hash + (this.address_ != null ? this.address_.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object other) {
        if (other instanceof HostAddress) {
            return address_.equals(((HostAddress)other).getInetAddress());
        }
        return false;
    }

    public boolean isValid() {
        return address_ != null;
    }

    InetAddress getInetAddress() {
        return address_;
    }
    
    private final InetAddress address_;
}