Author: tchemit Date: 2014-03-26 10:08:46 +0100 (Wed, 26 Mar 2014) New Revision: 1754 Url: http://forge.codelutin.com/projects/wao/repository/revisions/1754 Log: filter must be serializable + implements equals + hashcode for contactsFilter Modified: trunk/wao-persistence/src/main/java/fr/ifremer/wao/ContactsFilter.java trunk/wao-persistence/src/main/java/fr/ifremer/wao/SampleRowsFilter.java trunk/wao-persistence/src/main/java/fr/ifremer/wao/WaoUtils.java Modified: trunk/wao-persistence/src/main/java/fr/ifremer/wao/ContactsFilter.java =================================================================== --- trunk/wao-persistence/src/main/java/fr/ifremer/wao/ContactsFilter.java 2014-03-25 18:39:11 UTC (rev 1753) +++ trunk/wao-persistence/src/main/java/fr/ifremer/wao/ContactsFilter.java 2014-03-26 09:08:46 UTC (rev 1754) @@ -7,11 +7,15 @@ import fr.ifremer.wao.entity.SamplingStrategy; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import java.io.Serializable; import java.util.Date; +import java.util.Objects; import java.util.Set; -public class ContactsFilter { +public class ContactsFilter implements Serializable { + private static final long serialVersionUID = 1L; + protected SampleRowsFilter sampleRowFilter; /** @@ -247,6 +251,66 @@ } @Override + public boolean equals(Object o) { + + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ContactsFilter that = (ContactsFilter) o; + + boolean equals = Objects.equals(sampleRowFilter, that.sampleRowFilter) + && Objects.equals(periodFrom, that.periodFrom) + && Objects.equals(periodTo, that.periodTo) + && WaoUtils.isEqualCollection(contactIds, that.contactIds) + && WaoUtils.isEqualCollection(contactStates, that.contactStates) + && WaoUtils.isEqualCollection(dataReliabilities, that.dataReliabilities) + && WaoUtils.isEqualCollection(actualSamplingStrategies, that.actualSamplingStrategies) + && WaoUtils.isEqualCollection(observationTypes, that.observationTypes) + && WaoUtils.isEqualCollection(observedDataControls, that.observedDataControls) + && WaoUtils.isEqualCollection(observerIds, that.observerIds) + && WaoUtils.isEqualCollection(terrestrialLocationIds, that.terrestrialLocationIds) + && WaoUtils.isEqualCollection(contactStateMotiveIds, that.contactStateMotiveIds) + && Objects.equals(mammalsCaptureOnly, that.mammalsCaptureOnly) + && Objects.equals(mammalsObservationOnly, that.mammalsObservationOnly) + && Objects.equals(commentDefinedOnly, that.commentDefinedOnly) + && Objects.equals(commentAdminDefinedOnly, that.commentAdminDefinedOnly) + && Objects.equals(commentCompanyDefinedOnly, that.commentCompanyDefinedOnly) + && WaoUtils.isEqualCollection(companyAcceptations, that.companyAcceptations) + && WaoUtils.isEqualCollection(programAcceptations, that.programAcceptations) + && WaoUtils.isEqualCollection(completeSamplings, that.completeSamplings) + && Objects.equals(filterOnObservationBeginDate, that.filterOnObservationBeginDate) + && Objects.equals(sortedByBoardingDate, that.sortedByBoardingDate); + return equals; + } + + @Override + public int hashCode() { + int hashCode = Objects.hashCode(sampleRowFilter); + hashCode = 31 * hashCode + Objects.hashCode(periodFrom); + hashCode = 31 * hashCode + Objects.hashCode(periodFrom); + hashCode = 31 * hashCode + WaoUtils.collectionHashcode(contactIds); + hashCode = 31 * hashCode + WaoUtils.collectionHashcode(contactStates); + hashCode = 31 * hashCode + WaoUtils.collectionHashcode(dataReliabilities); + hashCode = 31 * hashCode + WaoUtils.collectionHashcode(actualSamplingStrategies); + hashCode = 31 * hashCode + WaoUtils.collectionHashcode(observationTypes); + hashCode = 31 * hashCode + WaoUtils.collectionHashcode(observedDataControls); + hashCode = 31 * hashCode + WaoUtils.collectionHashcode(observerIds); + hashCode = 31 * hashCode + WaoUtils.collectionHashcode(terrestrialLocationIds); + hashCode = 31 * hashCode + WaoUtils.collectionHashcode(contactStateMotiveIds); + hashCode = 31 * hashCode + Objects.hashCode(mammalsCaptureOnly); + hashCode = 31 * hashCode + Objects.hashCode(mammalsObservationOnly); + hashCode = 31 * hashCode + Objects.hashCode(commentDefinedOnly); + hashCode = 31 * hashCode + Objects.hashCode(commentAdminDefinedOnly); + hashCode = 31 * hashCode + Objects.hashCode(commentCompanyDefinedOnly); + hashCode = 31 * hashCode + WaoUtils.collectionHashcode(companyAcceptations); + hashCode = 31 * hashCode + WaoUtils.collectionHashcode(programAcceptations); + hashCode = 31 * hashCode + WaoUtils.collectionHashcode(completeSamplings); + hashCode = 31 * hashCode + Objects.hashCode(filterOnObservationBeginDate); + hashCode = 31 * hashCode + Objects.hashCode(sortedByBoardingDate); + return hashCode; + } + + @Override public String toString() { return ReflectionToStringBuilder.reflectionToString(this); } Modified: trunk/wao-persistence/src/main/java/fr/ifremer/wao/SampleRowsFilter.java =================================================================== --- trunk/wao-persistence/src/main/java/fr/ifremer/wao/SampleRowsFilter.java 2014-03-25 18:39:11 UTC (rev 1753) +++ trunk/wao-persistence/src/main/java/fr/ifremer/wao/SampleRowsFilter.java 2014-03-26 09:08:46 UTC (rev 1754) @@ -25,12 +25,15 @@ import fr.ifremer.wao.entity.SamplingStrategy; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import java.io.Serializable; import java.util.Date; import java.util.Objects; import java.util.Set; -public class SampleRowsFilter { +public class SampleRowsFilter implements Serializable { + private static final long serialVersionUID = 1L; + protected ObsProgram obsProgram; protected Set<String> sampleRowIds; @@ -209,16 +212,16 @@ @Override public int hashCode() { int hashCode = obsProgram.hashCode(); - hashCode = 31 * hashCode + (sampleRowIds == null ? 0 : sampleRowIds.size()); - hashCode = 31 * hashCode + (fishingZoneFacadeNames == null ? 0 : fishingZoneFacadeNames.size()); - hashCode = 31 * hashCode + (fishingZoneSectorNames == null ? 0 : fishingZoneSectorNames.size()); - hashCode = 31 * hashCode + (sampleRowCodes == null ? 0 : sampleRowCodes.size()); - hashCode = 31 * hashCode + (programNames == null ? 0 : programNames.size()); - hashCode = 31 * hashCode + (fishingGearDcfIds == null ? 0 : fishingGearDcfIds.size()); - hashCode = 31 * hashCode + (targetSpeciesDcfIds == null ? 0 : targetSpeciesDcfIds.size()); - hashCode = 31 * hashCode + (samplingStrategies == null ? 0 : samplingStrategies.size()); - hashCode = 31 * hashCode + (terrestrialDistrictIds == null ? 0 : terrestrialDistrictIds.size()); - hashCode = 31 * hashCode + (companyIds == null ? 0 : companyIds.size()); + hashCode = 31 * hashCode + WaoUtils.collectionHashcode(sampleRowIds); + hashCode = 31 * hashCode + WaoUtils.collectionHashcode(fishingZoneFacadeNames); + hashCode = 31 * hashCode + WaoUtils.collectionHashcode(fishingZoneSectorNames); + hashCode = 31 * hashCode + WaoUtils.collectionHashcode(sampleRowCodes); + hashCode = 31 * hashCode + WaoUtils.collectionHashcode(programNames); + hashCode = 31 * hashCode + WaoUtils.collectionHashcode(fishingGearDcfIds); + hashCode = 31 * hashCode + WaoUtils.collectionHashcode(targetSpeciesDcfIds); + hashCode = 31 * hashCode + WaoUtils.collectionHashcode(samplingStrategies); + hashCode = 31 * hashCode + WaoUtils.collectionHashcode(terrestrialDistrictIds); + hashCode = 31 * hashCode + WaoUtils.collectionHashcode(companyIds); return hashCode; } Modified: trunk/wao-persistence/src/main/java/fr/ifremer/wao/WaoUtils.java =================================================================== --- trunk/wao-persistence/src/main/java/fr/ifremer/wao/WaoUtils.java 2014-03-25 18:39:11 UTC (rev 1753) +++ trunk/wao-persistence/src/main/java/fr/ifremer/wao/WaoUtils.java 2014-03-26 09:08:46 UTC (rev 1754) @@ -111,4 +111,7 @@ return isEqualCollection; } + public static int collectionHashcode(Collection<?> a) { + return a == null ? 0 : a.size(); + } }