Example usage for java.lang Package hashCode

List of usage examples for java.lang Package hashCode

Introduction

In this page you can find the example usage for java.lang Package hashCode.

Prototype

@Override
public int hashCode() 

Source Link

Document

Return the hash code computed from the package name.

Usage

From source file:Main.java

public static void main(String[] args) {

    // get the java lang package
    Package pack = Package.getPackage("java.lang");

    System.out.println(pack.hashCode());

}

From source file:Main.java

public static List<Field> getAccessibleFields(Class<?> clazz, Class<?> limit) {
    Package topPackage = clazz.getPackage();
    List<Field> fieldList = new ArrayList<Field>();
    int topPackageHash = topPackage == null ? 0 : topPackage.hashCode();
    boolean top = true;
    do {//from   w  w  w.ja  v  a  2 s . c  o  m
        if (clazz == null) {
            break;
        }
        Field[] declaredFields = clazz.getDeclaredFields();
        for (Field field : declaredFields) {
            if (top == true) { // add all top declared fields
                fieldList.add(field);
                continue;
            }
            int modifier = field.getModifiers();
            if (Modifier.isPrivate(modifier) == true) {
                continue; // ignore super private fields
            }
            if (Modifier.isPublic(modifier) == true) {
                addFieldIfNotExist(fieldList, field); // add super public methods
                continue;
            }
            if (Modifier.isProtected(modifier) == true) {
                addFieldIfNotExist(fieldList, field); // add super protected methods
                continue;
            }
            // add super default methods from the same package
            Package pckg = field.getDeclaringClass().getPackage();
            int pckgHash = pckg == null ? 0 : pckg.hashCode();
            if (pckgHash == topPackageHash) {
                addFieldIfNotExist(fieldList, field);
            }
        }
        top = false;
    } while ((clazz = clazz.getSuperclass()) != limit);

    return fieldList;
}