1 /*
2  * JasperReports - Free Java Reporting Library.
3  * Copyright (C) 2001 - 2019 TIBCO Software Inc. All rights reserved.
4  * http://www.jaspersoft.com
5  *
6  * Unless you have purchased a commercial license agreement from Jaspersoft,
7  * the following license terms apply:
8  *
9  * This program is part of JasperReports.
10  *
11  * JasperReports is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * JasperReports is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * along with JasperReports. If not, see <http://www.gnu.org/licenses/>.
23  */

24 package net.sf.jasperreports.engine;
25
26 import java.io.IOException;
27 import java.io.ObjectInputStream;
28 import java.io.Serializable;
29
30 import net.sf.jasperreports.engine.type.BandTypeEnum;
31
32
33 /**
34  * @author Teodor Danciu (teodord@users.sourceforge.net)
35  */

36 public class JROrigin implements JRCloneable, Serializable
37 {
38
39     /**
40      *
41      */

42     private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
43
44     private BandTypeEnum bandTypeValue = BandTypeEnum.UNKNOWN;
45     private String groupName;
46     private String reportName;
47     
48     private transient Integer hashCode;
49     
50     /**
51      * 
52      */

53     public JROrigin(
54         BandTypeEnum bandType
55         )
56     {
57         this(nullnull, bandType);
58     }
59
60     /**
61      * 
62      */

63     public JROrigin(
64         String reportName,
65         BandTypeEnum bandType
66         )
67     {
68         this(reportName, null, bandType);
69     }
70
71     /**
72      * 
73      */

74     public JROrigin(
75         String reportName,
76         String groupName,
77         BandTypeEnum bandTypeValue
78         )
79     {
80         this.reportName = reportName;
81         this.groupName = groupName;
82         this.bandTypeValue = bandTypeValue;
83     }
84
85     /**
86      * 
87      */

88     public String getReportName()
89     {
90         return reportName;
91     }
92
93     /**
94      * 
95      */

96     public String getGroupName()
97     {
98         return groupName;
99     }
100
101     /**
102      * 
103      */

104     public BandTypeEnum getBandTypeValue()
105     {
106         return bandTypeValue;
107     }
108     
109     @Override
110     public boolean equals(Object obj) 
111     {
112         if (obj instanceof JROrigin)
113         {
114             JROrigin origin = (JROrigin)obj;
115             String groupName2 = origin.getGroupName();
116             String reportName2 = origin.getReportName();
117             return
118                 origin.getBandTypeValue() == bandTypeValue
119                 && (groupName == null ? groupName2 == null : groupName2 != null && groupName.equals(groupName2))
120                 && (reportName == null ? reportName2 == null : reportName2 != null && reportName.equals(reportName2));
121         }
122         return false;
123     }
124     
125     @Override
126     public int hashCode() 
127     {
128         if (hashCode == null)
129         {
130             int hash = 17;
131             hash = 31 * hash + (reportName == null ? 0 : reportName.hashCode());
132             hash = 31 * hash + (groupName == null ? 0 : groupName.hashCode());
133             hash = 31 * hash + bandTypeValue.hashCode();
134             hashCode = hash;
135         }
136         return hashCode;
137     }
138
139
140     @Override
141     public Object clone() 
142     {
143         try
144         {
145             return super.clone();
146         }
147         catch (CloneNotSupportedException e)
148         {
149             throw new JRRuntimeException(e);
150         }
151     }
152     
153     @Override
154     public String toString()
155     {
156         return "{reportName: " + reportName 
157                 + ", groupName: " + groupName 
158                 + ",bandType: " + bandTypeValue + "}";
159     }
160
161
162
163     /*
164      * These fields are only for serialization backward compatibility.
165      */

166     private int PSEUDO_SERIAL_VERSION_UID = JRConstants.PSEUDO_SERIAL_VERSION_UID; //NOPMD
167     /**
168      * @deprecated
169      */

170     private byte bandType;
171     
172     @SuppressWarnings("deprecation")
173     private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
174     {
175         in.defaultReadObject();
176         
177         if (PSEUDO_SERIAL_VERSION_UID < JRConstants.PSEUDO_SERIAL_VERSION_UID_3_7_2)
178         {
179             bandTypeValue = BandTypeEnum.getByValue(bandType);
180         }
181     }
182
183 }
184