@Test public void Lang() { Set<Integer> seen = new HashSet<Integer>(); for (Locale locale : Locale.getAvailableLocales()) { Integer id = idFactory.getId(locale); if (seen.contains(id)) { throw new IllegalStateException(id + " already used"); } seen.add(id); } }
@Override public Long getId(NODE node) { int mask; String value; if (node.isLiteral()) { LIT literal = node.asLiteral(); if (literal.getLang() != null) { mask = 0; value = literal.getValue() + literal.getLang(); } else { mask = 1; value = literal.getValue() + getReadableURI(literal.getDatatype()); } } else if (node.isBNode()) { mask = 2; value = node.getValue(); } else { mask = 3; value = getReadableURI(node.asURI()); } try { MessageDigest digest = MessageDigest.getInstance("MD5"); digest.update(value.getBytes("UTF-8")); byte[] hash = digest.digest(); byte[] longBytes = new byte[8]; System.arraycopy(hash, 0, longBytes, 0, longBytes.length); longBytes[0] = (byte) (mask(longBytes[0], mask)); return new BigInteger(longBytes).longValue(); } catch (NoSuchAlgorithmException e) { throw new RepositoryException(e); } catch (UnsupportedEncodingException e) { throw new RepositoryException(e); } }
MD5IdFactory implements IdFactory { @Override public Long getId(NODE node) { int mask; String value; if (node.isLiteral()) { LIT literal = node.asLiteral(); if (literal.getLang() != null) { mask = 0; value = literal.getValue() + literal.getLang(); } else { mask = 1; value = literal.getValue() + getReadableURI(literal.getDatatype()); } } else if (node.isBNode()) { mask = 2; value = node.getValue(); } else { mask = 3; value = getReadableURI(node.asURI()); } try { MessageDigest digest = MessageDigest.getInstance("MD5"); digest.update(value.getBytes("UTF-8")); byte[] hash = digest.digest(); byte[] longBytes = new byte[8]; System.arraycopy(hash, 0, longBytes, 0, longBytes.length); longBytes[0] = (byte) (mask(longBytes[0], mask)); return new BigInteger(longBytes).longValue(); } catch (NoSuchAlgorithmException e) { throw new RepositoryException(e); } catch (UnsupportedEncodingException e) { throw new RepositoryException(e); } } }
MD5IdFactory implements IdFactory { @Override public Long getId(NODE node) { int mask; String value; if (node.isLiteral()) { LIT literal = node.asLiteral(); if (literal.getLang() != null) { mask = 0; value = literal.getValue() + literal.getLang(); } else { mask = 1; value = literal.getValue() + getReadableURI(literal.getDatatype()); } } else if (node.isBNode()) { mask = 2; value = node.getValue(); } else { mask = 3; value = getReadableURI(node.asURI()); } try { MessageDigest digest = MessageDigest.getInstance("MD5"); digest.update(value.getBytes("UTF-8")); byte[] hash = digest.digest(); byte[] longBytes = new byte[8]; System.arraycopy(hash, 0, longBytes, 0, longBytes.length); longBytes[0] = (byte) (mask(longBytes[0], mask)); return new BigInteger(longBytes).longValue(); } catch (NoSuchAlgorithmException e) { throw new RepositoryException(e); } catch (UnsupportedEncodingException e) { throw new RepositoryException(e); } } MD5IdFactory(); }
MD5IdFactory implements IdFactory { @Override public Long getId(NODE node) { int mask; String value; if (node.isLiteral()) { LIT literal = node.asLiteral(); if (literal.getLang() != null) { mask = 0; value = literal.getValue() + literal.getLang(); } else { mask = 1; value = literal.getValue() + getReadableURI(literal.getDatatype()); } } else if (node.isBNode()) { mask = 2; value = node.getValue(); } else { mask = 3; value = getReadableURI(node.asURI()); } try { MessageDigest digest = MessageDigest.getInstance("MD5"); digest.update(value.getBytes("UTF-8")); byte[] hash = digest.digest(); byte[] longBytes = new byte[8]; System.arraycopy(hash, 0, longBytes, 0, longBytes.length); longBytes[0] = (byte) (mask(longBytes[0], mask)); return new BigInteger(longBytes).longValue(); } catch (NoSuchAlgorithmException e) { throw new RepositoryException(e); } catch (UnsupportedEncodingException e) { throw new RepositoryException(e); } } MD5IdFactory(); @Override Long getId(NODE node); @Override Integer getId(Locale locale); }
MD5IdFactory implements IdFactory { @Override public Long getId(NODE node) { int mask; String value; if (node.isLiteral()) { LIT literal = node.asLiteral(); if (literal.getLang() != null) { mask = 0; value = literal.getValue() + literal.getLang(); } else { mask = 1; value = literal.getValue() + getReadableURI(literal.getDatatype()); } } else if (node.isBNode()) { mask = 2; value = node.getValue(); } else { mask = 3; value = getReadableURI(node.asURI()); } try { MessageDigest digest = MessageDigest.getInstance("MD5"); digest.update(value.getBytes("UTF-8")); byte[] hash = digest.digest(); byte[] longBytes = new byte[8]; System.arraycopy(hash, 0, longBytes, 0, longBytes.length); longBytes[0] = (byte) (mask(longBytes[0], mask)); return new BigInteger(longBytes).longValue(); } catch (NoSuchAlgorithmException e) { throw new RepositoryException(e); } catch (UnsupportedEncodingException e) { throw new RepositoryException(e); } } MD5IdFactory(); @Override Long getId(NODE node); @Override Integer getId(Locale locale);  }