嗨,我发现以下代码用于比较一组指纹:

public float compare(Fingerprint fingerprint) {
    float result = 0f;

    HashMap<String, Integer> fingerprintMeasurements = fingerprint.getMeasurements();
    TreeSet<String> keys = new TreeSet<String>();
    keys.addAll(mMeasurements.keySet());
    keys.addAll(fingerprintMeasurements.keySet());

    for (String key : keys) {
        int value = 0;
        Integer fValue = fingerprintMeasurements.get(key);
        Integer mValue = mMeasurements.get(key);
        value = (fValue == null) ? -119 : (int) fValue;
        value -= (mValue == null) ? -119 : (int) mValue;
        result += value * value;
    }

    //result = FloatMath.sqrt(result); // squared euclidean distance is enough, this is not needed

    return result;
}

    /** compares the fingerprint to a set of fingerprints and returns the fingerprint with the smallest euclidean distance to it */
    public Fingerprint getClosestMatch(ArrayList<Fingerprint> fingerprints) {
        //long time = System.currentTimeMillis();
        Fingerprint closest = null;
        float bestScore = -1;

        if(fingerprints != null) {
            for(Fingerprint fingerprint : fingerprints) {
                float score = compare(fingerprint);
                if(bestScore == -1 || bestScore > score) {
                    bestScore = score;
                    closest = fingerprint;
                }
            }
        }

        //time = System.currentTimeMillis() - time;
        //Log.d("time", "\n\n\n\n\n\ncalculation location took " + time + " milliseconds.");
        return closest;
    }


1)
循环如何工作。
据我了解,我们将扫描存储在TreeSet的键引用中的所有值

问题主要在网上

value = (fValue == null) ? -119 : (int) fValue;
value -= (mValue == null) ? -119 : (int) mValue;


这些代码行上的问号是做什么的?

2)为什么我们在下面的代码行中需要减一来提取最佳指纹参数

if(bestScore == -1 || bestScore > score) {


3)有没有办法查看eclipse中的值分配(出于调试目的)?

最佳答案

1)那是Java Ternary Operator。这是带有赋值的if / else语句的等效简写。

2)bestScore正在被初始化为特定于应用程序的无效值,以指示尚未为其分配有效值。在这种情况下,当第一次通过循环时,将为其分配第一个得分值。

3)是的,您可以在Eclipse中逐步浏览您的应用程序。有许多Tutorials on the web

10-06 09:52