ClimateFilter.java
/*
* Copyright 2018 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.genesys.server.service.filter;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import org.apache.commons.collections4.CollectionUtils;
import org.genesys.blocks.model.filters.Filter;
import org.genesys.blocks.model.filters.NumberFilter;
import org.genesys.blocks.util.FilterUtils;
import org.genesys.server.model.impl.QTileClimate;
import com.querydsl.core.types.Predicate;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
/**
* The Class ClimateFilter.
*/
@Getter
@Setter
@EqualsAndHashCode
@Accessors(fluent = true)
public class ClimateFilter implements Filter {
private static final long serialVersionUID = -8738935142977143553L;
/** The latitude. */
public Set<Long> tileIndex;
public NumberFilter<Double> alt;
public NumberFilter<Double> bio1;
public NumberFilter<Double> bio2;
public NumberFilter<Double> bio3;
public NumberFilter<Double> bio4;
public NumberFilter<Double> bio5;
public NumberFilter<Double> bio6;
public NumberFilter<Double> bio7;
public NumberFilter<Double> bio8;
public NumberFilter<Double> bio9;
public NumberFilter<Double> bio10;
public NumberFilter<Double> bio11;
public NumberFilter<Double> bio12;
public NumberFilter<Double> bio13;
public NumberFilter<Double> bio14;
public NumberFilter<Double> bio15;
public NumberFilter<Double> bio16;
public NumberFilter<Double> bio17;
public NumberFilter<Double> bio18;
public NumberFilter<Double> bio19;
public NumberFilter<Double> prec1;
public NumberFilter<Double> prec2;
public NumberFilter<Double> prec3;
public NumberFilter<Double> prec4;
public NumberFilter<Double> prec5;
public NumberFilter<Double> prec6;
public NumberFilter<Double> prec7;
public NumberFilter<Double> prec8;
public NumberFilter<Double> prec9;
public NumberFilter<Double> prec10;
public NumberFilter<Double> prec11;
public NumberFilter<Double> prec12;
public NumberFilter<Double> tmax1;
public NumberFilter<Double> tmax2;
public NumberFilter<Double> tmax3;
public NumberFilter<Double> tmax4;
public NumberFilter<Double> tmax5;
public NumberFilter<Double> tmax6;
public NumberFilter<Double> tmax7;
public NumberFilter<Double> tmax8;
public NumberFilter<Double> tmax9;
public NumberFilter<Double> tmax10;
public NumberFilter<Double> tmax11;
public NumberFilter<Double> tmax12;
public NumberFilter<Double> tmean1;
public NumberFilter<Double> tmean2;
public NumberFilter<Double> tmean3;
public NumberFilter<Double> tmean4;
public NumberFilter<Double> tmean5;
public NumberFilter<Double> tmean6;
public NumberFilter<Double> tmean7;
public NumberFilter<Double> tmean8;
public NumberFilter<Double> tmean9;
public NumberFilter<Double> tmean10;
public NumberFilter<Double> tmean11;
public NumberFilter<Double> tmean12;
public NumberFilter<Double> tmin1;
public NumberFilter<Double> tmin2;
public NumberFilter<Double> tmin3;
public NumberFilter<Double> tmin4;
public NumberFilter<Double> tmin5;
public NumberFilter<Double> tmin6;
public NumberFilter<Double> tmin7;
public NumberFilter<Double> tmin8;
public NumberFilter<Double> tmin9;
public NumberFilter<Double> tmin10;
public NumberFilter<Double> tmin11;
public NumberFilter<Double> tmin12;
@Override
public boolean isEmpty() {
return FilterUtils.isEmpty(tileIndex)
&& FilterUtils.isEmpty(prec1, prec2, prec3, prec4, prec5, prec6, prec7, prec8, prec9, prec10, prec11, prec12)
&& FilterUtils.isEmpty(tmax1, tmax2, tmax3, tmax4, tmax5, tmax6, tmax7, tmax8, tmax9, tmax10, tmax11, tmax12)
&& FilterUtils.isEmpty(tmean1, tmean2, tmean3, tmean4, tmean5, tmean6, tmean7, tmean8, tmean9, tmean10, tmean11, tmean12)
&& FilterUtils.isEmpty(tmin1, tmin2, tmin3, tmin4, tmin5, tmin6, tmin7, tmin8, tmin9, tmin10, tmin11, tmin12)
&& FilterUtils.isEmpty(alt, bio1, bio2, bio3, bio4, bio5, bio6, bio7, bio8, bio9, bio10, bio11, bio12, bio13, bio14, bio15, bio16, bio17, bio18, bio19)
;
}
/**
* Builds the query.
*
* @param qtileClimate the qtile climate
* @return the predicate
*/
public List<Predicate> collectPredicates(QTileClimate qtileClimate) {
final List<Predicate> predicates = new LinkedList<>();
if (!CollectionUtils.isEmpty(tileIndex)) {
predicates.add(qtileClimate.tileIndex.in(tileIndex));
}
if (alt != null) {
predicates.add(alt.buildQuery(qtileClimate.alt));
}
if (bio1 != null) {
predicates.add(bio1.buildQuery(qtileClimate.bio1));
}
if (bio2 != null) {
predicates.add(bio2.buildQuery(qtileClimate.bio2));
}
if (bio3 != null) {
predicates.add(bio3.buildQuery(qtileClimate.bio3));
}
if (bio4 != null) {
predicates.add(bio4.buildQuery(qtileClimate.bio4));
}
if (bio5 != null) {
predicates.add(bio5.buildQuery(qtileClimate.bio5));
}
if (bio6 != null) {
predicates.add(bio6.buildQuery(qtileClimate.bio6));
}
if (bio7 != null) {
predicates.add(bio7.buildQuery(qtileClimate.bio7));
}
if (bio8 != null) {
predicates.add(bio8.buildQuery(qtileClimate.bio8));
}
if (bio9 != null) {
predicates.add(bio9.buildQuery(qtileClimate.bio9));
}
if (bio10 != null) {
predicates.add(bio10.buildQuery(qtileClimate.bio10));
}
if (bio11 != null) {
predicates.add(bio11.buildQuery(qtileClimate.bio11));
}
if (bio12 != null) {
predicates.add(bio12.buildQuery(qtileClimate.bio12));
}
if (bio13 != null) {
predicates.add(bio13.buildQuery(qtileClimate.bio13));
}
if (bio14 != null) {
predicates.add(bio14.buildQuery(qtileClimate.bio14));
}
if (bio15 != null) {
predicates.add(bio15.buildQuery(qtileClimate.bio15));
}
if (bio16 != null) {
predicates.add(bio16.buildQuery(qtileClimate.bio16));
}
if (bio17 != null) {
predicates.add(bio17.buildQuery(qtileClimate.bio17));
}
if (bio18 != null) {
predicates.add(bio18.buildQuery(qtileClimate.bio18));
}
if (bio19 != null) {
predicates.add(bio19.buildQuery(qtileClimate.bio19));
}
if (prec1 != null) {
predicates.add(prec1.buildQuery(qtileClimate.prec1));
}
if (prec2 != null) {
predicates.add(prec2.buildQuery(qtileClimate.prec2));
}
if (prec3 != null) {
predicates.add(prec3.buildQuery(qtileClimate.prec3));
}
if (prec4 != null) {
predicates.add(prec4.buildQuery(qtileClimate.prec4));
}
if (prec5 != null) {
predicates.add(prec5.buildQuery(qtileClimate.prec5));
}
if (prec6 != null) {
predicates.add(prec6.buildQuery(qtileClimate.prec6));
}
if (prec7 != null) {
predicates.add(prec7.buildQuery(qtileClimate.prec7));
}
if (prec8 != null) {
predicates.add(prec8.buildQuery(qtileClimate.prec8));
}
if (prec9 != null) {
predicates.add(prec9.buildQuery(qtileClimate.prec9));
}
if (prec10 != null) {
predicates.add(prec10.buildQuery(qtileClimate.prec10));
}
if (prec11 != null) {
predicates.add(prec11.buildQuery(qtileClimate.prec11));
}
if (prec12 != null) {
predicates.add(prec12.buildQuery(qtileClimate.prec12));
}
if (tmax1 != null) {
predicates.add(tmax1.buildQuery(qtileClimate.tmax1));
}
if (tmax2 != null) {
predicates.add(tmax2.buildQuery(qtileClimate.tmax2));
}
if (tmax3 != null) {
predicates.add(tmax3.buildQuery(qtileClimate.tmax3));
}
if (tmax4 != null) {
predicates.add(tmax4.buildQuery(qtileClimate.tmax4));
}
if (tmax5 != null) {
predicates.add(tmax5.buildQuery(qtileClimate.tmax5));
}
if (tmax6 != null) {
predicates.add(tmax6.buildQuery(qtileClimate.tmax6));
}
if (tmax7 != null) {
predicates.add(tmax7.buildQuery(qtileClimate.tmax7));
}
if (tmax8 != null) {
predicates.add(tmax8.buildQuery(qtileClimate.tmax8));
}
if (tmax9 != null) {
predicates.add(tmax9.buildQuery(qtileClimate.tmax9));
}
if (tmax10 != null) {
predicates.add(tmax10.buildQuery(qtileClimate.tmax10));
}
if (tmax11 != null) {
predicates.add(tmax11.buildQuery(qtileClimate.tmax11));
}
if (tmax12 != null) {
predicates.add(tmax12.buildQuery(qtileClimate.tmax12));
}
if (tmean1 != null) {
predicates.add(tmean1.buildQuery(qtileClimate.tmean1));
}
if (tmean2 != null) {
predicates.add(tmean2.buildQuery(qtileClimate.tmean2));
}
if (tmean3 != null) {
predicates.add(tmean3.buildQuery(qtileClimate.tmean3));
}
if (tmean4 != null) {
predicates.add(tmean4.buildQuery(qtileClimate.tmean4));
}
if (tmean5 != null) {
predicates.add(tmean5.buildQuery(qtileClimate.tmean5));
}
if (tmean6 != null) {
predicates.add(tmean6.buildQuery(qtileClimate.tmean6));
}
if (tmean7 != null) {
predicates.add(tmean7.buildQuery(qtileClimate.tmean7));
}
if (tmean8 != null) {
predicates.add(tmean8.buildQuery(qtileClimate.tmean8));
}
if (tmean9 != null) {
predicates.add(tmean9.buildQuery(qtileClimate.tmean9));
}
if (tmean10 != null) {
predicates.add(tmean10.buildQuery(qtileClimate.tmean10));
}
if (tmean11 != null) {
predicates.add(tmean11.buildQuery(qtileClimate.tmean11));
}
if (tmean12 != null) {
predicates.add(tmean12.buildQuery(qtileClimate.tmean12));
}
if (tmin1 != null) {
predicates.add(tmin1.buildQuery(qtileClimate.tmin1));
}
if (tmin2 != null) {
predicates.add(tmin2.buildQuery(qtileClimate.tmin2));
}
if (tmin3 != null) {
predicates.add(tmin3.buildQuery(qtileClimate.tmin3));
}
if (tmin4 != null) {
predicates.add(tmin4.buildQuery(qtileClimate.tmin4));
}
if (tmin5 != null) {
predicates.add(tmin5.buildQuery(qtileClimate.tmin5));
}
if (tmin6 != null) {
predicates.add(tmin6.buildQuery(qtileClimate.tmin6));
}
if (tmin7 != null) {
predicates.add(tmin7.buildQuery(qtileClimate.tmin7));
}
if (tmin8 != null) {
predicates.add(tmin8.buildQuery(qtileClimate.tmin8));
}
if (tmin9 != null) {
predicates.add(tmin9.buildQuery(qtileClimate.tmin9));
}
if (tmin10 != null) {
predicates.add(tmin10.buildQuery(qtileClimate.tmin10));
}
if (tmin11 != null) {
predicates.add(tmin11.buildQuery(qtileClimate.tmin11));
}
if (tmin12 != null) {
predicates.add(tmin12.buildQuery(qtileClimate.tmin12));
}
return predicates;
}
}