XMLResources implements Comparator<Object> { @Override @SuppressWarnings({"checkstyle:cyclomaticcomplexity", "checkstyle:npathcomplexity"}) @Pure public int compare(Object o1, Object o2) { if (o1 == o2) { return 0; } if (o1 == null) { return Integer.MIN_VALUE; } if (o2 == null) { return Integer.MAX_VALUE; } if (o1 instanceof byte[] && o2 instanceof byte[]) { return compareArrays((byte[]) o1, (byte[]) o2); } else if (o1 instanceof byte[]) { return Integer.MAX_VALUE; } else if (o2 instanceof byte[]) { return Integer.MIN_VALUE; } final URL a1; final URL a2; if (this.pathBuilder != null) { if (o1 instanceof URL) { a1 = this.pathBuilder.makeAbsolute((URL) o1); } else if (o1 instanceof File) { a1 = this.pathBuilder.makeAbsolute((File) o1); } else { throw new IllegalStateException(); } if (o2 instanceof URL) { a2 = this.pathBuilder.makeAbsolute((URL) o2); } else if (o2 instanceof File) { a2 = this.pathBuilder.makeAbsolute((File) o2); } else { throw new IllegalStateException(); } } else { if (o1 instanceof URL) { a1 = (URL) o1; } else if (o1 instanceof File) { try { a1 = ((File) o1).toURI().toURL(); } catch (MalformedURLException e) { throw new IllegalStateException(e); } } else { throw new IllegalStateException(); } if (o2 instanceof URL) { a2 = (URL) o2; } else if (o2 instanceof File) { try { a2 = ((File) o2).toURI().toURL(); } catch (MalformedURLException e) { throw new IllegalStateException(e); } } else { throw new IllegalStateException(); } } return a1.toString().compareTo(a2.toString()); } XMLResources(PathBuilder pathBuilder); @Override @SuppressWarnings({"checkstyle:cyclomaticcomplexity", "checkstyle:npathcomplexity"}) @Pure int compare(Object o1, Object o2); @Pure static String getStringIdentifier(long identifier); @Pure static boolean isStringIdentifier(String str); @SuppressWarnings("checkstyle:magicnumber") @Pure static long getNumericalIdentifier(String identifier); synchronized String add(long identifier, URL url, String mimeType); synchronized String add(long identifier, File file, String mimeType); synchronized String add(long identifier, byte[] rawData, String mimeType); @Inline(value = "add($1, null)") final String add(URL url); @Inline(value = "add(-1, $1, $2)") final String add(URL url, String mimeType); @Inline(value = "add($1, null)") final String add(File file); @Inline(value = "add(-1, $1, $2)") final String add(File file, String mimeType); @Inline(value = "add($1, null)") final String add(byte[] rawData); @Inline(value = "add(-1, $1, $2)") final String add(byte[] rawData, String mimeType); synchronized long computeNextIdentifier(); @Pure final long getIdentifier(URL url); @Pure final long getIdentifier(File file); @Pure final long getIdentifier(byte[] rawData); @Pure final URL getResourceURL(long identifier); @Pure @Inline(value = "getResourceFromIdentifier($1)") final Entry getResource(long identifier); synchronized void remove(URL url); synchronized void remove(File file); synchronized void remove(byte[] rawData); synchronized void remove(long identifier); @Pure Map<Long, Entry> getPairs(); synchronized void clear(); static final String IDENTIFIER_PREFIX; }
@Test public void compareObjectObject() throws Exception { assertZero(this.xml.compare(null, null)); assertStrictlyPositive(this.xml.compare(new Object(), null)); assertStrictlyNegative(this.xml.compare(null, new Object())); assertZero(this.xml.compare(new File("a"), new File("a"))); assertStrictlyNegative(this.xml.compare(new File("a"), new File("b"))); assertZero(this.xml.compare(new URL("file:a"), new URL("file:a"))); assertStrictlyNegative(this.xml.compare(new URL("file:a"), new URL("file:b"))); assertZero(this.xml.compare(new File("a"), new URL("file:a"))); assertStrictlyNegative(this.xml.compare(new File("a"), new URL("file:b"))); }