|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.javacore.parser; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.List; /** * * @author mm109185 */ class ArrayMeasure implements Measure { private final Measure measure; ArrayMeasure(Measure elementsMeasure) { measure = elementsMeasure; } public int getDistance(Object first, Object second) { int maxLength=Math.max(((Object[]) first).length, ((Object[]) second).length); if (maxLength!=0) { List array1 = new ArrayList(Arrays.asList((Object[]) first)); List array2 = new ArrayList(Arrays.asList((Object[]) second)); int minDistance = INFINITE_DISTANCE; Object minDistanceElement = null; int error = 0; for (Iterator it1 = array1.iterator(); it1.hasNext();) { Object element1 = it1.next(); for (Iterator it2 = array2.iterator(); it2.hasNext();) { Object element2 = it2.next(); int distance = measure.getDistance(element1, element2); if (distance == 0) { it1.remove(); it2.remove(); break; } } } for (Iterator it1 = array1.iterator(); it1.hasNext();) { Object element1 = it1.next(); for (Iterator it2 = array2.iterator(); it2.hasNext();) { Object element2 = it2.next(); int distance = measure.getDistance(element1, element2); if (distance < minDistance) { minDistance = distance; minDistanceElement = element2; } } if (minDistanceElement != null) { array2.remove(minDistanceElement); it1.remove(); minDistanceElement = null; error += minDistance; } } error += INFINITE_DISTANCE * Math.max(array1.size(), array2.size()); error = 2 * error / maxLength; return error > INFINITE_DISTANCE ? INFINITE_DISTANCE : error; } return 0; } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.