|
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.Arrays; import java.util.Iterator; import java.util.List; /** * * @author mm109185 */ class OrderedArrayMeasure implements Measure { private final Measure measure; OrderedArrayMeasure(Measure elementsMeasure) { measure = elementsMeasure; } public int getDistance(Object first, Object second) { Object[] array1 = (Object[]) first; Object[] array2 = (Object[]) second; int minSize = Math.min(array1.length, array2.length); int difference = Math.abs(array1.length-array2.length); int result = 0; if (minSize==0) { if (difference!=0) result=INFINITE_DISTANCE; return result; } for (int i = 0; i < minSize; i++) { result += measure.getDistance(array1[i], array2[i]); } result += difference * INFINITE_DISTANCE; result /= (minSize+difference); return result > INFINITE_DISTANCE ? INFINITE_DISTANCE : result; } } |
... 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.