/** * {@inheritDoc} * * @see org.jboss.shrinkwrap.api.ArchivePath#getParent() */ @Override public ArchivePath getParent() { return PathUtil.getParent(this); }
/** * {@inheritDoc} * * @see org.jboss.shrinkwrap.api.ArchivePath#getParent() */ @Override public ArchivePath getParent() { return PathUtil.getParent(this); }
/** * {@inheritDoc} * * @see java.lang.Comparable#compareTo(java.lang.Object) */ @Override public int compareTo(final ArchivePath path) { // If a null argument, we're greater if (path == null) { return 1; } /* * Check for parent relationship */ final ArchivePath parentOfSpecified = PathUtil.getParent(path); final ArchivePath parentOfThis = PathUtil.getParent(this); // If we're the parent of the specified, we're less if (this.equals(parentOfSpecified)) { return -1; } // If the specified if the parent of us, we're more if (path.equals(parentOfThis)) { return 1; } // Just delegate to underlying contexts final int comparedContexts = path.get().compareTo(this.get()); // Return the inverted value of the contents (in this ordering, less is more) final int adjusted = 0 - comparedContexts; return adjusted; }
/** * {@inheritDoc} * * @see java.lang.Comparable#compareTo(java.lang.Object) */ @Override public int compareTo(final ArchivePath path) { // If a null argument, we're greater if (path == null) { return 1; } /* * Check for parent relationship */ final ArchivePath parentOfSpecified = PathUtil.getParent(path); final ArchivePath parentOfThis = PathUtil.getParent(this); // If we're the parent of the specified, we're less if (this.equals(parentOfSpecified)) { return -1; } // If the specified if the parent of us, we're more if (path.equals(parentOfThis)) { return 1; } // Just delegate to underlying contexts final int comparedContexts = path.get().compareTo(this.get()); // Return the inverted value of the contents (in this ordering, less is more) final int adjusted = 0 - comparedContexts; return adjusted; }
/** * Ensures the contract of {@link PathProvider#parent()} is intact */ @Test public void testParent() { // Log log.info("testParent"); // Create new paths final String rootString = "/"; final String subpathString = "subpath/"; final String contextString = "context"; final String contextWithFollowingSlashString = "context/"; final ArchivePath root = ArchivePaths.create(rootString); final ArchivePath subpath = ArchivePaths.create(subpathString); final ArchivePath context = ArchivePaths.create(subpath, contextString); final ArchivePath contextWithFollowingSlash = new BasicPath(subpath, contextWithFollowingSlashString); // Test TestCase.assertEquals("The parent of the context path should be equal to the initial subpath", subpath, PathUtil.getParent(context)); TestCase.assertEquals( "The parent of the context path with a following slash should be equal to the initial subpath", subpath, PathUtil.getParent(contextWithFollowingSlash)); TestCase.assertEquals("The parent of the subpath should be the root", root, PathUtil.getParent(subpath)); TestCase.assertNull("The parent of the root should be null", PathUtil.getParent(root)); }