List of usage examples for java.lang Package getName
public String getName()
From source file:org.kie.test.util.compare.ComparePair.java
private static void compareValues(Object origFieldVal, Object copyFieldVal, String objectFieldName, String[] skipFields) {//w ww . j av a 2 s . co m assertNotNull(objectFieldName + " is null in the copy!", copyFieldVal); assertNotNull(objectFieldName + " is null in the original!", origFieldVal); Package pkg = origFieldVal.getClass().getPackage(); if (pkg == null || pkg.getName().startsWith("java.")) { if (origFieldVal.getClass().isArray()) { if (origFieldVal instanceof byte[]) { assertArrayEquals(objectFieldName, (byte[]) origFieldVal, (byte[]) copyFieldVal); } } else if (origFieldVal instanceof Map<?, ?> && copyFieldVal instanceof Map<?, ?>) { Collection shouldBeEmpty = CollectionUtils.disjunction(((Map) origFieldVal).values(), ((Map) copyFieldVal).values()); assertTrue("Comparison of Map values failed on " + objectFieldName, shouldBeEmpty.isEmpty()); } else if (origFieldVal instanceof Collection) { assertEquals("Different collection sizes on " + objectFieldName, ((Collection) origFieldVal).size(), ((Collection) copyFieldVal).size()); for (Object elem : ((Collection) origFieldVal)) { boolean match = false; for (Object copyElem : ((Collection) copyFieldVal)) { try { compareObjectsViaFields(elem, copyElem, skipFields); match = true; break; } catch (Throwable t) { logger.debug(t.getMessage()); // ignore } } assertTrue("Different collection values on " + objectFieldName, match); } } else { assertEquals(objectFieldName, origFieldVal, copyFieldVal); } } }
From source file:com.rdm.common.util.ClassPathUtils.java
/** * Returns the fully qualified name for the resource with name {@code resourceName} relative to the given context. * * <p>Note that this method does not check whether the resource actually exists. * It only constructs the name./* w w w . ja v a 2s . c o m*/ * Null inputs are not allowed.</p> * * <pre> * ClassPathUtils.toFullyQualifiedName(StringUtils.class.getPackage(), "StringUtils.properties") = "org.apache.commons.lang3.StringUtils.properties" * </pre> * * @param context The context for constructing the name. * @param resourceName the resource name to construct the fully qualified name for. * @return the fully qualified name of the resource with name {@code resourceName}. * @throws java.lang.NullPointerException if either {@code context} or {@code resourceName} is null. */ public static String toFullyQualifiedName(final Package context, final String resourceName) { Validate.notNull(context, "Parameter '%s' must not be null!", "context"); Validate.notNull(resourceName, "Parameter '%s' must not be null!", "resourceName"); StringBuilder sb = new StringBuilder(); sb.append(context.getName()); sb.append("."); sb.append(resourceName); return sb.toString(); }
From source file:com.rdm.common.util.ClassPathUtils.java
/** * Returns the fully qualified path for the resource with name {@code resourceName} relative to the given context. * * <p>Note that this method does not check whether the resource actually exists. * It only constructs the path./*from w w w . j a v a2 s . c o m*/ * Null inputs are not allowed.</p> * * <pre> * ClassPathUtils.toFullyQualifiedPath(StringUtils.class.getPackage(), "StringUtils.properties") = "org/apache/commons/lang3/StringUtils.properties" * </pre> * * @param context The context for constructing the path. * @param resourceName the resource name to construct the fully qualified path for. * @return the fully qualified path of the resource with name {@code resourceName}. * @throws java.lang.NullPointerException if either {@code context} or {@code resourceName} is null. */ public static String toFullyQualifiedPath(final Package context, final String resourceName) { Validate.notNull(context, "Parameter '%s' must not be null!", "context"); Validate.notNull(resourceName, "Parameter '%s' must not be null!", "resourceName"); StringBuilder sb = new StringBuilder(); sb.append(context.getName().replace('.', '/')); sb.append("/"); sb.append(resourceName); return sb.toString(); }
From source file:com.haulmont.cuba.core.config.ConfigUtil.java
/** * Get the prefix associated with a configuration interface. * If the interface has an enclosing class, the * fully-qualified name of that class is used, or else the name of the * package containing the interface. In either of the latter two * cases, a '.' is appended to the name. * * @param configInterface The configuration interface. * @return The interface prefix.//from ww w. j a v a 2s .c o m */ public static String getPropertyPrefix(Class<?> configInterface) { // Foo -> "" // foo.Bar -> "foo." // foo.Bar$Baz -> "foo.Bar." Class<?> enclosingClass = configInterface.getEnclosingClass(); if (enclosingClass != null) { return enclosingClass.getName() + '.'; } else { Package pkg = configInterface.getPackage(); if (pkg != null) { return pkg.getName() + '.'; } else { return ""; } } }
From source file:de.fu_berlin.inf.dpp.misc.pico.DotGraphMonitor.java
public static String getColorOld(Class<?> clazz, HashMap<String, String> colors) { String name;/*from www . ja va2 s . c om*/ Package myPackage = clazz.getPackage(); if (myPackage == null) { name = "misc"; } else { name = myPackage.getName(); } while (name != null && name.length() > 0) { String color = colors.get(name); if (color != null) { return " \"" + clazz.getSimpleName() + "\" [color=" + color + "];\n"; } int index = name.lastIndexOf('.'); if (index == -1) break; name = name.substring(0, index); } return null; }
From source file:org.jnetstream.protocol.ProtocolRegistry.java
/** * @param protocol//from ww w. j a va 2 s . c o m */ private static void fillInFromClassInfo(DefaultProtocolEntry entry, Protocol protocol) { Class<? extends Protocol> c = protocol.getClass(); if (c.isEnum() == false) { return; } Enum<?> constant = null; for (Enum<?> e : (Enum[]) c.getEnumConstants()) { if (e == protocol) { constant = e; } } Package pkg = c.getPackage(); String suite = c.getSimpleName(); String name = constant.name(); String headeri = pkg.getName() + "." + name; String headerc = pkg.getName() + "." + name + "Header"; String headercdc = pkg.getName() + "." + name + "Codec"; // System.out.printf("suite=%s,\n name=%s,\n headeri=%s,\n headerc=%s\n", // suite, name, headeri, headerc); entry.setSuite(suite); entry.setName(name); try { entry.setProtocolClass((Class<? extends Header>) Class.forName(headeri)); } catch (Exception e) { logger.warn("missing header: " + headeri); logger.debug(e); } try { entry.setCodec((Class<HeaderCodec<? extends Header>>) Class.forName(headercdc)); HeaderCodec<? extends Header> codec = entry.getCodecClass().newInstance(); entry.setCodec(codec); } catch (Exception e) { logger.warn("missing codec: " + headercdc); logger.debug(e); } }
From source file:org.dcm4chee.xds2.src.tool.pnrsnd.PnRSnd.java
private static CommandLine parseComandLine(String[] args) throws ParseException { Options opts = new Options(); opts.addOption("h", "help", false, rb.getString("help")); opts.addOption("V", "version", false, rb.getString("version")); opts.addOption("c", "showCodes", false, "Show defined codes for affinity domain"); opts.addOption("a", "audit", false, "Send a dummy audit message"); addURLOption(opts);// w w w.j a va2 s. c om addPropertyOption(opts); CommandLineParser parser = new PosixParser(); CommandLine cl = parser.parse(opts, args); if (cl.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(rb.getString("usage"), rb.getString("description"), opts, rb.getString("example")); System.exit(0); } if (cl.hasOption("V")) { Package p = PnRSnd.class.getPackage(); String s = p.getName(); System.out.println(s.substring(s.lastIndexOf('.') + 1) + ": " + p.getImplementationVersion()); System.exit(0); } if (cl.hasOption("c")) { showCodes(cl); System.exit(0); } if (cl.hasOption("a")) { new PnRSnd().audit(); System.exit(0); } if (cl.hasOption("u")) { props.setProperty("URL", cl.getOptionValue("u")); } if (cl.hasOption("p")) { String[] codes = cl.getOptionValues("p"); int pos; for (int i = 0; i < codes.length; i++) { pos = codes[i].indexOf('='); props.setProperty(codes[i].substring(0, pos), codes[i].substring(++pos)); } } return cl; }
From source file:com.github.dozermapper.core.util.MappingUtils.java
public static String getClassNameWithoutPackage(Class<?> clazz) { // TODO Replace with Apache implementation Package pckage = clazz.getPackage(); int pckageIndex = 0; if (pckage != null) { pckageIndex = pckage.getName().length() + 1; }/* w ww .j a v a2 s . co m*/ return clazz.getName().substring(pckageIndex); }
From source file:net.sourceforge.cobertura.metrics.api.location.SourceLocationFilter.java
/** * Convenience method to generate a Java Regular Expression pattern string which includes the * supplied Package, and optionally all subpackages to it. * * @param thePackage The Package to acquire a filter for. Cannot be {@code null}. * @param includeSubPackages if {@code true}, generates a pattern string which accepts/hits * subpackages of the supplied Package in addition to the given Package. * @return a Java Regular Expression pattern string which includes the * supplied Package, and optionally all subpackages to it. *///www . j av a 2 s.c o m public static String getPattern(final Package thePackage, boolean includeSubPackages) { // Check sanity Validate.notNull(thePackage, "Cannot handle null thePackage argument."); // Ensure that subpackages can be included if so requested. final String exactPackagePattern = escapeDots(thePackage.getName()); return includeSubPackages ? exactPackagePattern + "(\\.\\w*)*" : exactPackagePattern; }
From source file:uk.gov.gchq.koryphe.serialisation.json.SimpleClassNameCache.java
public static String getSimpleClassNameOrNull(final Class<?> clazz) { String id;//from ww w . ja v a 2 s . com if (null == clazz || useFullNameForSerialisation) { id = null; } else { initialise(); // If the class is an array, use the component type and we will // add the array brackets at the end. final boolean isArray = null != clazz.getComponentType(); final Class<?> nonArrayClass = isArray ? clazz.getComponentType() : clazz; id = nonArrayClass.getSimpleName(); final Set<Class> classesForId = getClassesFromId(id); if (null == classesForId || classesForId.isEmpty()) { // If the class is unknown, check if the class is in one of the core packages final Package classPackage = nonArrayClass.getPackage(); if (null != classPackage && corePackages.contains(classPackage.getName())) { // Found the class, so cache the result for next time. addIdClasses(id, Sets.newHashSet(nonArrayClass)); } else { id = null; } } else if (1 != classesForId.size()) { // If there are multiple classes with the same class name then // we can't return a simple class name. id = null; } if (isArray && null != id) { id = id + "[]"; } } return id; }