Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/java/src/org/openqa/selenium/Rectangle.java
1865 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License. You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied. See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
package org.openqa.selenium;
19
20
import java.util.Map;
21
import java.util.Objects;
22
import org.jspecify.annotations.NullMarked;
23
import org.jspecify.annotations.Nullable;
24
25
@NullMarked
26
public class Rectangle {
27
28
public final int x;
29
public final int y;
30
public final int height;
31
public final int width;
32
33
public Rectangle(int x, int y, int height, int width) {
34
this.x = x;
35
this.y = y;
36
this.height = height;
37
this.width = width;
38
}
39
40
public Rectangle(Point p, Dimension d) {
41
x = p.x;
42
y = p.y;
43
height = d.height;
44
width = d.width;
45
}
46
47
public int getX() {
48
return x;
49
}
50
51
public int getY() {
52
return y;
53
}
54
55
public int getHeight() {
56
return height;
57
}
58
59
public int getWidth() {
60
return width;
61
}
62
63
public Point getPoint() {
64
return new Point(x, y);
65
}
66
67
public Dimension getDimension() {
68
return new Dimension(width, height);
69
}
70
71
private Map<String, Object> toJson() {
72
return Map.of("width", width, "height", height, "x", x, "y", y);
73
}
74
75
@Override
76
public boolean equals(@Nullable Object o) {
77
if (this == o) {
78
return true;
79
}
80
if (o == null || getClass() != o.getClass()) {
81
return false;
82
}
83
84
Rectangle rectangle = (Rectangle) o;
85
86
return x == rectangle.x
87
&& y == rectangle.y
88
&& height == rectangle.height
89
&& width == rectangle.width;
90
}
91
92
@Override
93
public int hashCode() {
94
return Objects.hash(x, y, height, width);
95
}
96
}
97
98