All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.simmetrics.utils.CompositeStringMetric Maven / Gradle / Ivy

There is a newer version: 4.1.1
Show newest version
package org.simmetrics.utils;

import org.simmetrics.Metric;
import org.simmetrics.StringMetric;
import org.simmetrics.StringMetricBuilder;
import org.simmetrics.simplifiers.Simplifier;

import com.google.common.base.Preconditions;

/**
 * String metric composed of a simplifier and string metric. Applies
 * simplification to the input. The simplifierd strings are compared by the
 * metric.
 * 
 * 

* This class is immutable and thread-safe if its components are. * * @see StringMetricBuilder * */ public final class CompositeStringMetric implements StringMetric { private final Simplifier simplifier; private final Metric metric; /** * Constructs a new composite string metric. * * @param metric * a list metric * @param simplifier * a simplifier */ public CompositeStringMetric(Metric metric, Simplifier simplifier) { Preconditions.checkNotNull(metric); Preconditions.checkNotNull(simplifier); this.metric = metric; this.simplifier = simplifier; } @Override public float compare(String a, String b) { return metric.compare(simplifier.simplify(a), simplifier.simplify(b)); } @Override public String toString() { return metric + " [" + simplifier + "]"; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy