Checks if class in member of the package : Package « Reflection « Java






Checks if class in member of the package

        
/*
 * This file is part of aion-emu <aion-emu.com>.
 *
 * aion-emu is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * aion-emu is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with aion-emu.  If not, see <http://www.gnu.org/licenses/>.
 */
/**
 * This class contains utilities that are used when we are working with classes
 * 
 * @author SoulKeeper
 */
public class Util{

  /**
   * Checks if class in member of the package
   * 
   * @param clazz
   *            class to check
   * @param packageName
   *            package
   * @return true if is member
   */
  public static boolean isPackageMember(Class<?> clazz, String packageName)
  {
    return isPackageMember(clazz.getName(), packageName);
  }

  /**
   * Checks if classNames belongs to package
   * 
   * @param className
   *            class name
   * @param packageName
   *            package
   * @return true if belongs
   */
  public static boolean isPackageMember(String className, String packageName)
  {
    if (!className.contains("."))
    {
      return packageName == null || packageName.isEmpty();
    }
    else
    {
      String classPackage = className.substring(0, className.lastIndexOf('.'));
      return packageName.equals(classPackage);
    }
  }

}

   
    
    
    
    
    
    
    
  








Related examples in the same category

1.Show the PackagesShow the Packages
2.Demonstrates how to get declaration information on a Class
3.Get package by name
4.Get all information about a package
5.Get full package name
6.Get the class name with or without the package
7.Get package name of a class
8.Detect if a package is available
9.Getting the Package of a Class
10.getPackage() returns null for a class in the unnamed package
11.getPackage() returns null for a primitive type or array
12.Package Utils
13.Get Package Names From Dir
14.To Package Path
15.Attempt to find the given className within any of the packages.