
com.araguacaima.commons.utils.PackageClassUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of commons-utils Show documentation
Show all versions of commons-utils Show documentation
Common utilities is a set of java utilities for managing typical actions when working with enums,
files, exceptions, zip/jar files, classes (via Reflection), maps, numbers and so on.
Most of the utilities extend functionalities offered by amazing libraries such as:
* commons-beanutils (apache)
* commons-lang3 (apache)
* commons-io (apache)
* commons-math3 (apache)
* commons-collections4 (apache)
* jreversepro (akkumar)
package com.araguacaima.commons.utils;
import java.io.File;
public class PackageClassUtils {
private static final FileUtils fileUtils = new FileUtils();
private String id;
private String className;
private String packageName;
private String fullyQualifiedClassName;
private PackageClassUtils(String id) {
this.id = id;
if (this.id != null) {
if (this.id.startsWith(".") || this.id.startsWith("\\") || this.id.startsWith("/")) {
this.id = this.id.substring(1);
}
if (this.id.endsWith(".java") || this.id.endsWith(".class")) {
this.id = this.id.substring(0, this.id.length() - 5);
}
this.id = this.id.replaceAll("/", ".").replaceAll("\\\\", ".");
}
}
public static PackageClassUtils instance(String id) {
return new PackageClassUtils(id).invoke();
}
public static PackageClassUtils instance(File root, File relative, String suffix) {
return instance(fileUtils.getRelativePathFrom(root, relative).substring(1) + File.separator + relative.getName().replace(suffix, StringUtils.EMPTY));
}
public String getClassName() {
return className;
}
public String getPackageName() {
return packageName;
}
public String getFullyQualifiedClassName() {
return fullyQualifiedClassName;
}
public PackageClassUtils invoke() {
if (id.contains(".")) {
className = id.substring(id.lastIndexOf('.') + 1);
packageName = id.substring(0, id.lastIndexOf('.'));
} else {
className = id;
packageName = StringUtils.EMPTY;
}
fullyQualifiedClassName = packageName + "." + className;
return this;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy