Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.HashSet;

public class Main {
    public static HashSet<String> reservedWords;

    public static boolean isLegalName(String n) {
        if (n.length() == 0)
            return false;
        if (!Character.isLetter(n.charAt(0)))
            return false;
        for (int i = 0; i < n.length(); i++) {
            char c = n.charAt(i);
            if (Character.isLetterOrDigit(c))
                continue;
            if (c == '_')
                continue;
            if (c == '.')
                continue;
            return false;
        }
        if (n.length() > 1) {
            String n2 = n.substring(0, 2);
            if (n2.equalsIgnoreCase("JS"))
                return false;
        }
        if (n.indexOf("__") >= 0)
            return false;
        if (reservedWords.contains(n))
            return false;
        return true;
    }
}