uk.gov.gchq.gaffer.sketches.clearspring.cardinality.predicate.HyperLogLogPlusIsLessThan Maven / Gradle / Ivy
/*
* Copyright 2016-2023 Crown Copyright
*
* 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 uk.gov.gchq.gaffer.sketches.clearspring.cardinality.predicate;
import com.clearspring.analytics.stream.cardinality.HyperLogLogPlus;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import uk.gov.gchq.gaffer.commonutil.ToStringBuilder;
import uk.gov.gchq.koryphe.Since;
import uk.gov.gchq.koryphe.Summary;
import uk.gov.gchq.koryphe.predicate.KoryphePredicate;
/**
* An {@code HyperLogLogPlus} is a {@link java.util.function.Predicate} that simply checks that the input
* {@link HyperLogLogPlus} cardinality is less than a control value.
*/
@Since("1.0.0")
@Summary("Tests a HyperLogLogPlus cardinality is less than a provided value")
@Deprecated
public class HyperLogLogPlusIsLessThan extends KoryphePredicate {
private long controlValue;
private boolean orEqualTo;
public HyperLogLogPlusIsLessThan() {
// Required for serialisation
}
public HyperLogLogPlusIsLessThan(final long controlValue) {
this(controlValue, false);
}
public HyperLogLogPlusIsLessThan(final long controlValue, final boolean orEqualTo) {
this.controlValue = controlValue;
this.orEqualTo = orEqualTo;
}
@JsonProperty("value")
public long getControlValue() {
return controlValue;
}
public void setControlValue(final long controlValue) {
this.controlValue = controlValue;
}
public boolean getOrEqualTo() {
return orEqualTo;
}
public void setOrEqualTo(final boolean orEqualTo) {
this.orEqualTo = orEqualTo;
}
@Override
public boolean test(final HyperLogLogPlus input) {
if (null == input) {
return false;
}
final long cardinality = input.cardinality();
if (orEqualTo) {
if (cardinality <= controlValue) {
return true;
}
} else {
if (cardinality < controlValue) {
return true;
}
}
return false;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (null == obj || getClass() != obj.getClass()) {
return false;
}
final HyperLogLogPlusIsLessThan that = (HyperLogLogPlusIsLessThan) obj;
return new EqualsBuilder()
.append(controlValue, that.controlValue)
.append(orEqualTo, that.orEqualTo)
.isEquals();
}
@Override
public int hashCode() {
return new HashCodeBuilder(79, 23)
.append(controlValue)
.append(orEqualTo)
.toHashCode();
}
@Override
public String toString() {
return new ToStringBuilder(this)
.append("controlValue", controlValue)
.append("orEqualTo", orEqualTo)
.toString();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy