Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.Iterator;

import java.util.Map;

public class Main {
    /**
     * Calculates a value case insensitive hash code for a String v String map. Method placed here to
     * reduce .NET translation overhead
     * @param map
     * @return
     */
    public static int calculateCaseInsensitiveValueStringVsStringMapHash(Map<String, String> map) {
        if (map == null) {
            throw new NullPointerException();
        }

        int result = 0;
        Iterator<Map.Entry<String, String>> iter = map.entrySet().iterator();

        while (iter.hasNext()) {
            Map.Entry<String, String> next = iter.next();
            int entryHash = (next.getKey() == null ? 0 : next.getKey().hashCode())
                    ^ (next.getValue() == null ? 0 : next.getValue().toLowerCase().hashCode());
            result += entryHash;
        }
        return result;
    }
}