/** * Determine name of policy from file. .xml prefix is removed, and name is converted to a PID. * Policy names must be valid PIDs. * @param policyFile * @return * @throws PolicyIndexException */ private String fileToName(File policyFile) throws PolicyIndexException { try { if (!policyFile.getName().endsWith(".xml")) throw new PolicyIndexException("Invalid policy file name. Policy files must end in .xml - " + policyFile.getName()); return PID.fromFilename(policyFile.getName().substring(0, policyFile.getName().lastIndexOf(".xml"))).toString(); } catch (MalformedPIDException e) { throw new PolicyIndexException("Invalid policy file name. Filename cannot be converted to a valid PID - " + policyFile.getName()); } }
public static PID pidFromFilename(String filename) throws MalformedPidException { try { return PID.fromFilename(filename); } catch (MalformedPIDException e) { throw new MalformedPidException(e.getMessage()); } }
public static PID pidFromFilename(String filename) throws MalformedPidException { try { return PID.fromFilename(filename); } catch (MalformedPIDException e) { throw new MalformedPidException(e.getMessage()); } }
System.out.println("To filename : " + p.toFilename()); System.out.println("From filename : " + PID.fromFilename(p.toFilename()).toString()); } else { System.out.println("--------------------------------------"); System.out.println("To filename : " + p.toFilename()); System.out.println("From filename : " + PID.fromFilename(p.toFilename()).toString());
System.out.println("To filename : " + p.toFilename()); System.out.println("From filename : " + PID.fromFilename(p.toFilename()).toString()); } else { System.out.println("--------------------------------------"); System.out.println("To filename : " + p.toFilename()); System.out.println("From filename : " + PID.fromFilename(p.toFilename()).toString());
/** * equals() should return true for lexically equivalent PIDs. */ @Test public void testEqualsSamePID() throws Exception { PID pid1 = PID.getInstance("test:somepid"); PID pid2 = new PID("test:somepid"); PID pid3 = PID.fromFilename("test_somepid"); assertEquals(pid1, pid2); assertEquals(pid2, pid3); }
/** * hashCode() should return the same value for lexically equivalent PIDs. */ @Test public void testHashCodeSamePID() throws Exception { PID pid1 = PID.getInstance("test:somepid"); PID pid2 = new PID("test:somepid"); PID pid3 = PID.fromFilename("test_somepid"); assertEquals(pid1.hashCode(), pid2.hashCode()); assertEquals(pid2.hashCode(), pid3.hashCode()); }
/** * equals() should return false for lexically distinct PIDs. */ @Test public void testEqualsDifferentPID() throws Exception { PID pid1 = PID.getInstance("test:somepid"); PID pid2 = new PID("test:someotherpid"); PID pid3 = PID.fromFilename("test_yetanotherpid"); assertFalse(pid1.equals(pid2)); assertFalse(pid2.equals(pid1)); assertFalse(pid2.equals(pid3)); assertFalse(pid3.equals(pid2)); }