summaryrefslogtreecommitdiffstats
blob: af298042ac70ef4192ea0422a6f518076931b459 (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
 * Copyright (c) 2010 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */
/*
 * Copyright (c) 2015 Tarun Gupta.
 * Licensed under the simplified BSD license.
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 */

package com.isode.stroke.elements;

import com.isode.stroke.base.NotNull;
import java.lang.Comparable;

public class CapsInfo extends Payload implements Comparable<CapsInfo> {

	private String node_;
	private String version_;
	private String hash_;

	/**
	* Initialize private variables
	*/
	public void init(String node, String version, String hash) {
		NotNull.exceptIfNull(node, "node");
		NotNull.exceptIfNull(version, "version");
		NotNull.exceptIfNull(hash, "hash");
		this.node_ = node;
		this.version_ = version;
		this.hash_ = hash;
	}

	/**
	* CapsInfo();
	*/
	public CapsInfo() {
		init("", "", "sha-1");
	}

	/**
	* CapsInfo(node, "", "sha-1");
	*/
	public CapsInfo(String node) {
		init(node, "", "sha-1");
	}

	/**
	* CapsInfo(node, version, "sha-1");
	*/
	public  CapsInfo(String node, String version) {
		init(node, version, "sha-1");
	}

	/**
	 *
	 * @param node CapsInfo node, notnull.
	 * @param node CapsInfo version, notnull.
	 * @param node CapsInfo hash, notnull.
	 */
	public CapsInfo(String node, String version, String hash) {
		init(node, version, hash);
	}

	@Override
	public boolean equals(Object other) {
		
		if ((!(other instanceof CapsInfo)) || other == null) {
			return false;
		}
			
		CapsInfo guest = (CapsInfo) other;
		return 	(node_.equals(guest.node_)) && (version_.equals(guest.version_)) && (hash_.equals(guest.hash_));
	}

	@Override	 
	public int compareTo(CapsInfo other) {
		if(other == null) {
			return -1;
		}
		if (node_.equals(other.node_)) {
			if (version_.equals(other.version_)) {
				return hash_.compareTo(other.hash_);
			}
			else {
				return version_.compareTo(other.version_);
			}
		}
		else {
			return node_.compareTo(other.node_);
		}
	}

	/**
	*
	* @return Node, notnull.
	*/
	public String getNode() {
		return node_;
	}

	/**
	*
	* @param node, notnull.
	*/
	public void setNode(String node) {
		NotNull.exceptIfNull(node, "node");
		this.node_ = node;
	}

	/**
	*
	* @return version, notnull.
	*/
	public String getVersion() {
		return version_;
	}

	/**
	*
	* @param version, notnull.
	*/
	public void setVersion(String version) {
		NotNull.exceptIfNull(version, "version");
		this.version_ = version;
	}

	/**
	*
	* @return hash, notnull.
	*/
	public String getHash() {
		return hash_;
	}

	/**
	*
	* @param hash, notnull.
	*/
	public void setHash(String hash) {
		NotNull.exceptIfNull(hash, "hash");		
		this.hash_ = hash;
	}
}