Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Copyright 2010 JBoss Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

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

public class Main {
    private static final String STAR = "*";

    /**
     * Determines if a given full qualified class name matches any import style patterns.
     */
    public static boolean isMatched(Map<String, Object> patterns, String className) {
        // Array [] object class names are "[x", where x is the first letter of the array type
        // -> NO '.' in class name, thus!
        // see http://download.oracle.com/javase/6/docs/api/java/lang/Class.html#getName%28%29
        String qualifiedNamespace = className;
        String name = className;
        if (className.indexOf('.') > 0) {
            qualifiedNamespace = className.substring(0, className.lastIndexOf('.')).trim();
            name = className.substring(className.lastIndexOf('.') + 1).trim();
        } else if (className.indexOf('[') == 0) {
            qualifiedNamespace = className.substring(0, className.lastIndexOf('['));
        }
        Object object = patterns.get(qualifiedNamespace);
        if (object == null) {
            return true;
        } else if (STAR.equals(object)) {
            return false;
        } else if (patterns.containsKey("*")) {
            // for now we assume if the name space is * then we have a catchall *.* pattern
            return true;
        } else {
            List list = (List) object;
            return !list.contains(name);
        }
    }
}