Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.Collections;

import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class Main {
    public static void setIfNull(int i, List list, String value) {
        if (i >= list.size()) {
            resize(list, i + 1);
        }
        if (list.get(i) != null) {
            return;
        }
        list.set(i, value);
    }

    public static void resize(List list, int newSize) {
        if (newSize < list.size()) {
            list.subList(newSize, list.size()).clear();
        } else {
            list.addAll(Collections.nCopies(newSize - list.size(), null));
        }
    }

    public static Object get(Class c, Map map) {
        if (map.keySet().contains(c)) {
            return map.get(c);
        }
        for (Iterator i = map.keySet().iterator(); i.hasNext();) {
            Class candidateClass = (Class) i.next();
            if (candidateClass.isAssignableFrom(c)) {
                return map.get(candidateClass);
            }
        }

        return null;
    }
}