Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.util.Arrays;

import java.util.Collections;

import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

public class Main {
    public static <T> void incrementValueByIndex(final Map<T, Integer> map, final List<Integer> keys) {
        incrementValueByIndex(map, keys, 0x01);
    }

    public static <T> void incrementValueByIndex(final Map<T, Integer> map, final List<Integer> keys,
            final int delta) {
        for (Entry<T, Integer> entry : map.entrySet()) {
            int val = entry.getValue();
            entry.setValue(val + delta * getLowestInsertionPoint(keys, val));
        }
    }

    public static <T extends Comparable<T>> int getLowestInsertionPoint(final List<T> list, final T key) {
        int index = Collections.binarySearch(list, key);
        if (index >= 0x00) {
            return index;
        } else {
            return ~index;
        }
    }

    public static int getLowestInsertionPoint(final double[] list, final double key) {
        int index = Arrays.binarySearch(list, key);
        if (index >= 0x00) {
            return index;
        } else {
            return ~index;
        }
    }
}