Clover icon

Magnolia Imaging Module 3.4.2-SUPPORT-10161

  1. Project Clover database Tue Jul 16 2019 23:33:19 EEST
  2. Package info.magnolia.imaging.operations.cropresize

File Coords.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart4.png
76% of files have more coverage

Code metrics

16
33
7
1
156
94
16
0.48
4.71
7
2.29
22.2% of code in this file is excluded from these metrics.

Classes

Class Line # Actions
Coords 43 33 22.2% 16 36
0.3571428735.7%
 

Contributing tests

This file is covered by 31 tests. .

Source view

1    /**
2    * This file Copyright (c) 2007-2018 Magnolia International
3    * Ltd. (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10    * This file is distributed in the hope that it will be
11    * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12    * implied warranty of MERCHANTABILITY or FITNESS FOR A
13    * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14    * Redistribution, except as permitted by whichever of the GPL
15    * or MNA you select, is prohibited.
16    *
17    * 1. For the GPL license (GPL), you can redistribute and/or
18    * modify this file under the terms of the GNU General
19    * Public License, Version 3, as published by the Free Software
20    * Foundation. You should have received a copy of the GNU
21    * General Public License, Version 3 along with this program;
22    * if not, write to the Free Software Foundation, Inc., 51
23    * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24    *
25    * 2. For the Magnolia Network Agreement (MNA), this file
26    * and the accompanying materials are made available under the
27    * terms of the MNA which accompanies this distribution, and
28    * is available at http://www.magnolia-cms.com/mna.html
29    *
30    * Any modifications to this file must keep this entire header
31    * intact.
32    *
33    */
34    package info.magnolia.imaging.operations.cropresize;
35   
36    import java.io.Serializable;
37   
38    /**
39    * A simple bean holding the coordinates of 2 points, determining an area for cropping an image, providing
40    * helper methods calculating and validating the width and height of the area.
41    * This class is not immutable because it must be instantiable through content2bean.
42    */
 
43    public class Coords implements Serializable {
44    private int x1, y1, x2, y2;
45   
 
46  2 toggle public Coords() {
47    }
48   
 
49  55 toggle public Coords(int x1, int y1, int x2, int y2) {
50  55 this.x1 = x1;
51  55 this.y1 = y1;
52  55 this.x2 = x2;
53  55 this.y2 = y2;
54    }
55   
 
56  30 toggle public int getWidth() {
57  30 final int width = x2 - x1;
58  30 if (width <= 0) {
59  1 throw new IllegalStateException("Invalid coordinates, negative width: x1 = " + x1 + ", x2 = " + x2);
60    } else {
61  29 return width;
62    }
63    }
64   
 
65  30 toggle public int getHeight() {
66  30 final int height = y2 - y1;
67  30 if (height <= 0) {
68  1 throw new IllegalStateException("Invalid coordinates, negative height: y1 = " + y1 + ", y2 = " + y2);
69    } else {
70  29 return height;
71    }
72    }
73   
74    // regular (generated) getters and setters :
75   
 
76    toggle public int getX1() {
77    return x1;
78    }
79   
 
80    toggle public void setX1(int x1) {
81    this.x1 = x1;
82    }
83   
 
84    toggle public int getX2() {
85    return x2;
86    }
87   
 
88    toggle public void setX2(int x2) {
89    this.x2 = x2;
90    }
91   
 
92    toggle public int getY1() {
93    return y1;
94    }
95   
 
96    toggle public void setY1(int y1) {
97    this.y1 = y1;
98    }
99   
 
100    toggle public int getY2() {
101    return y2;
102    }
103   
 
104    toggle public void setY2(int y2) {
105    this.y2 = y2;
106    }
107   
108    // generated methods:
109   
 
110  0 toggle @Override
111    public boolean equals(Object o) {
112  0 if (this == o) {
113  0 return true;
114    }
115  0 if (o == null || getClass() != o.getClass()) {
116  0 return false;
117    }
118   
119  0 Coords that = (Coords) o;
120   
121  0 if (x1 != that.x1) {
122  0 return false;
123    }
124  0 if (x2 != that.x2) {
125  0 return false;
126    }
127  0 if (y1 != that.y1) {
128  0 return false;
129    }
130  0 if (y2 != that.y2) {
131  0 return false;
132    }
133   
134  0 return true;
135    }
136   
 
137  0 toggle @Override
138    public int hashCode() {
139  0 int result;
140  0 result = x1;
141  0 result = 31 * result + y1;
142  0 result = 31 * result + x2;
143  0 result = 31 * result + y2;
144  0 return result;
145    }
146   
 
147  0 toggle @Override
148    public String toString() {
149  0 return "Coords{" +
150    "x1=" + x1 +
151    ", y1=" + y1 +
152    ", x2=" + x2 +
153    ", y2=" + y2 +
154    '}';
155    }
156    }