1
|
|
|
/* |
2
|
|
|
* This file is part of ArakneUtils. |
3
|
|
|
* |
4
|
|
|
* ArakneUtils is free software: you can redistribute it and/or modify |
5
|
|
|
* it under the terms of the GNU Lesser General Public License as published by |
6
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
7
|
|
|
* (at your option) any later version. |
8
|
|
|
* |
9
|
|
|
* ArakneUtils is distributed in the hope that it will be useful, |
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12
|
|
|
* GNU Lesser General Public License for more details. |
13
|
|
|
* |
14
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
15
|
|
|
* along with ArakneUtils. If not, see <https://www.gnu.org/licenses/>. |
16
|
|
|
* |
17
|
|
|
* Copyright (c) 2017-2020 Vincent Quatrevieux |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
package fr.arakne.utils.value; |
21
|
|
|
|
22
|
|
|
import org.checkerframework.checker.index.qual.Positive; |
23
|
|
|
import org.checkerframework.checker.nullness.qual.Nullable; |
24
|
|
|
import org.checkerframework.dataflow.qual.Pure; |
25
|
|
|
|
26
|
|
|
import java.util.Objects; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Dimensions for 2D object |
30
|
|
|
*/ |
31
|
|
|
public final class Dimensions { |
32
|
|
|
private final @Positive int width; |
33
|
|
|
private final @Positive int height; |
34
|
|
|
|
35
|
1 |
|
public Dimensions(@Positive int width, @Positive int height) { |
36
|
1 |
|
this.width = width; |
37
|
1 |
|
this.height = height; |
38
|
1 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Get the width |
42
|
|
|
* |
43
|
|
|
* @return The width |
44
|
|
|
*/ |
45
|
|
|
@Pure |
46
|
|
|
public @Positive int width() { |
47
|
1 |
|
return width; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Get the height |
52
|
|
|
* |
53
|
|
|
* @return The height |
54
|
|
|
*/ |
55
|
|
|
@Pure |
56
|
|
|
public @Positive int height() { |
57
|
1 |
|
return height; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
@Override |
61
|
|
|
public boolean equals(@Nullable Object o) { |
62
|
1 |
|
if (this == o) { |
63
|
1 |
|
return true; |
64
|
|
|
} |
65
|
|
|
|
66
|
1 |
|
if (o == null || getClass() != o.getClass()) { |
67
|
1 |
|
return false; |
68
|
|
|
} |
69
|
|
|
|
70
|
1 |
|
final Dimensions other = (Dimensions) o; |
71
|
|
|
|
72
|
1 |
|
return other.height == height && other.width == width; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
@Override |
76
|
|
|
public int hashCode() { |
77
|
1 |
|
return Objects.hash(width, height); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
@Override |
81
|
|
|
public String toString() { |
82
|
1 |
|
return "Dimensions(" + width + "x" + height + ')'; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|