Gridarta Editor
Size2D.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2023 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.utils;
21 
22 import java.io.Serializable;
23 import org.jetbrains.annotations.Nullable;
24 
30 public class Size2D implements Serializable {
31 
35  private static final long serialVersionUID = 1L;
36 
40  public static final Size2D ONE = new Size2D(1, 1);
41 
47  private final int width;
48 
54  private final int height;
55 
63  public Size2D(final int width, final int height) {
64  if (width < 1) {
65  throw new IllegalArgumentException("Width must be > 0");
66  }
67  if (height < 1) {
68  throw new IllegalArgumentException("Height must be > 0");
69  }
70 
71  this.width = width;
72  this.height = height;
73  }
74 
75  @Override
76  public boolean equals(@Nullable final Object obj) {
77  if (obj == this) {
78  return true;
79  }
80  if (obj == null || obj.getClass() != getClass()) {
81  return false;
82  }
83  final Size2D other = (Size2D) obj;
84  return height == other.height && width == other.width;
85  }
86 
87  @Override
88  public int hashCode() {
89  return height ^ width << 16 ^ width >> 16;
90  }
91 
96  public int getWidth() {
97  return width;
98  }
99 
104  public int getHeight() {
105  return height;
106  }
107 
108  @Override
109  public String toString() {
110  return width + "x" + height;
111  }
112 
113 }
net.sf.gridarta.utils.Size2D.getWidth
int getWidth()
Returns the width of the area.
Definition: Size2D.java:96
net.sf.gridarta.utils.Size2D.serialVersionUID
static final long serialVersionUID
Serial Version.
Definition: Size2D.java:35
net.sf.gridarta.utils.Size2D.height
final int height
The height of the area.
Definition: Size2D.java:54
net.sf.gridarta.utils.Size2D.toString
String toString()
Definition: Size2D.java:109
net.sf.gridarta.utils.Size2D.getHeight
int getHeight()
Returns the height of the area.
Definition: Size2D.java:104
net.sf.gridarta.utils.Size2D.Size2D
Size2D(final int width, final int height)
Creates a new instance.
Definition: Size2D.java:63
net.sf.gridarta.utils.Size2D.ONE
static final Size2D ONE
One size object.
Definition: Size2D.java:40
net.sf.gridarta.utils.Size2D.width
final int width
The width of the area.
Definition: Size2D.java:47
net.sf.gridarta.utils.Size2D.equals
boolean equals(@Nullable final Object obj)
Definition: Size2D.java:76
net.sf.gridarta.utils.Size2D.hashCode
int hashCode()
Definition: Size2D.java:88
net.sf.gridarta.utils.Size2D
The class Size2D represents a 2d rectangular area.
Definition: Size2D.java:30