View Javadoc
1   /*
2    * #%L
3    * wcm.io
4    * %%
5    * Copyright (C) 2014 wcm.io
6    * %%
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   *
11   *      http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * #L%
19   */
20  package io.wcm.handler.media;
21  
22  import org.apache.commons.lang3.builder.EqualsBuilder;
23  import org.apache.commons.lang3.builder.HashCodeBuilder;
24  import org.apache.commons.lang3.builder.ToStringBuilder;
25  import org.apache.commons.lang3.builder.ToStringStyle;
26  import org.osgi.annotation.versioning.ProviderType;
27  
28  /**
29   * Dimension with width and height as integer.
30   * This class is used instead of {@link java.awt.Dimension} because the latter converts the dimensions to double.
31   */
32  @ProviderType
33  public class Dimension {
34  
35    private final long width;
36    private final long height;
37  
38    /**
39     * @param width Width in pixels
40     * @param height Height in pixels
41     */
42    public Dimension(long width, long height) {
43      this.width = width;
44      this.height = height;
45    }
46  
47    /**
48     * @return Width in pixels
49     */
50    public final long getWidth() {
51      return this.width;
52    }
53  
54    /**
55     * @return Height in pixels
56     */
57    public final long getHeight() {
58      return this.height;
59    }
60  
61    @Override
62    public int hashCode() {
63      return HashCodeBuilder.reflectionHashCode(this);
64    }
65  
66    @Override
67    public boolean equals(Object obj) {
68      return EqualsBuilder.reflectionEquals(this, obj);
69    }
70  
71    @Override
72    public String toString() {
73      return new ToStringBuilder(this, ToStringStyle.NO_CLASS_NAME_STYLE)
74          .append("width", getWidth())
75          .append("height", getHeight())
76          .build();
77    }
78  
79  }