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

eu.stratosphere.core.testing.fuzzy.NaiveFuzzyValueMatcher Maven / Gradle / Ivy

The newest version!
/***********************************************************************************************************************
 *
 * Copyright (C) 2010-2013 by the Stratosphere project (http://stratosphere.eu)
 *
 * 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 eu.stratosphere.core.testing.fuzzy;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import eu.stratosphere.core.testing.TypeConfig;

/**
 * Simple matching algorithm that returns unmatched values but allows a value from one bag to be matched several times
 * against items from another bag.
 * 
 * @param 
 *        the record type
 */
public class NaiveFuzzyValueMatcher implements FuzzyValueMatcher {
	private final TypeDistance typeDistance;

	/**
	 * Initializes NaiveFuzzyValueMatcher.
	 * 
	 * @param typeDistance
	 */
	public NaiveFuzzyValueMatcher(final TypeDistance typeDistance) {
		this.typeDistance = typeDistance;
	}

	/**
	 * Returns the typeDistance.
	 * 
	 * @return the typeDistance
	 */
	public TypeDistance getTypeDistance() {
		return this.typeDistance;
	}

	/*
	 * (non-Javadoc)
	 * @see eu.stratosphere.core.testing.FuzzyValueMatcher#removeMatchingValues(eu.stratosphere.core.testing.TypeConfig,
	 * java.util.Collection, java.util.Collection)
	 */
	@Override
	public void removeMatchingValues(final TypeConfig typeConfig, final Collection expectedValues,
			final Collection actualValues) {
		final Iterator expectedIterator = expectedValues.iterator();
		final List matchedActualValues = new ArrayList();
		while (expectedIterator.hasNext()) {
			final T expected = expectedIterator.next();
			boolean matched = false;
			for (final T actual : actualValues)
				if (this.typeDistance.getDistance(typeConfig, expected, actual) >= 0) {
					matched = true;
					matchedActualValues.add(actual);
				}
			if (matched)
				expectedIterator.remove();
		}

		actualValues.removeAll(matchedActualValues);
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy