Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/java/src/org/openqa/selenium/Rectangle.java
3991 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.Nullable;
23
24
public class Rectangle {
25
26
public final int x;
27
public final int y;
28
public final int height;
29
public final int width;
30
31
public Rectangle(int x, int y, int height, int width) {
32
this.x = x;
33
this.y = y;
34
this.height = height;
35
this.width = width;
36
}
37
38
public Rectangle(Point p, Dimension d) {
39
x = p.x;
40
y = p.y;
41
height = d.height;
42
width = d.width;
43
}
44
45
public int getX() {
46
return x;
47
}
48
49
public int getY() {
50
return y;
51
}
52
53
public int getHeight() {
54
return height;
55
}
56
57
public int getWidth() {
58
return width;
59
}
60
61
public Point getPoint() {
62
return new Point(x, y);
63
}
64
65
public Dimension getDimension() {
66
return new Dimension(width, height);
67
}
68
69
private Map<String, Object> toJson() {
70
return Map.of("width", width, "height", height, "x", x, "y", y);
71
}
72
73
@Override
74
public boolean equals(@Nullable Object o) {
75
if (this == o) {
76
return true;
77
}
78
if (o == null || getClass() != o.getClass()) {
79
return false;
80
}
81
82
Rectangle rectangle = (Rectangle) o;
83
84
return x == rectangle.x
85
&& y == rectangle.y
86
&& height == rectangle.height
87
&& width == rectangle.width;
88
}
89
90
@Override
91
public int hashCode() {
92
return Objects.hash(x, y, height, width);
93
}
94
}
95
96