/** * Creates a document name from a string of the form "name" * * @param name The name string to parse. * @throws NumberFormatException if the version part of the name is present but is not a number */ public DataTypeName(String name) { this.name = new Utf8String(name); } public DataTypeName(Utf8Array name) {
/** * Creates a new routing table specification for a named protocol. * * @param protocol The name of the protocol that this belongs to. */ public RoutingTableSpec(Utf8String protocol) { this(protocol.toString(), true); }
@Override public boolean equals(Object obj) { if (obj instanceof DataTypeIdentifier) { return utf8.equals(((DataTypeIdentifier)obj).utf8); } return false; } @Override
private static byte [] createPrefixDataType(final byte [] prefix, final DataTypeIdentifier nested, final byte [] postfix) { byte [] whole = new byte[prefix.length + 2 + nested.utf8.getByteLength() + postfix.length]; for (int i=0; i < prefix.length; i++) { whole[i] = prefix[i]; } whole[prefix.length] = '<'; for (int i = 0, m=nested.utf8.getByteLength(); i < m; i++ ) { whole[prefix.length+1+i] = nested.utf8.getByte(i); } whole[prefix.length + 1 + nested.utf8.getByteLength()] = '>'; for (int i = 0; i < postfix.length; i++) { whole[prefix.length + 1 + nested.utf8.length() + 1 + i] = postfix[i]; } return whole; } private static byte [] createMapDataType(final byte [] prefix, final DataTypeIdentifier key, final DataTypeIdentifier value) {
private static byte [] createMapDataType(final byte [] prefix, final DataTypeIdentifier key, final DataTypeIdentifier value) { byte [] whole = new byte[prefix.length + 3 + key.utf8.getByteLength() + value.utf8.getByteLength()]; for (int i=0; i < prefix.length; i++) { whole[i] = prefix[i]; } whole[prefix.length] = '<'; for (int i = 0, m=key.utf8.getByteLength(); i < m; i++ ) { whole[prefix.length+1+i] = key.utf8.getByte(i); } whole[prefix.length + 1 + key.utf8.getByteLength()] = ','; for (int i = 0; i < value.utf8.getByteLength(); i++) { whole[prefix.length + 1 + key.utf8.getByteLength() + 1 + i] = value.utf8.getByte(i); } whole[whole.length-1] = '>'; return whole; } private static byte [] verify(final byte [] utf8) {
public DataTypeIdentifier(String s) { utf8 = new Utf8String(s); verify(utf8.wrap().array()); } public DataTypeIdentifier(AbstractUtf8Array utf8) {
private static boolean verifyAny(byte c, byte [] identifier) { if (!((c == '_') || (c == '.') || ((c >= 'a') && (c <= 'z')) || ((c >= '0') && (c <= '9')))) { throw new IllegalArgumentException("Illegal character '" + (char)c + "' of identifier '" + new Utf8String(new Utf8Array(identifier)).toString() +"'."); } return true; }
@Override public int hashCode() { return utf8.hashCode(); } @Override
if (sendSessionKey) { Utf8String key = query.getSessionId(serverId).asUtf8String(); sessionSize = key.getByteLength(); buffer.putInt(key.getByteLength()); buffer.put(key.getBytes());
public void write(DocumentId id) { put(null, id.getScheme().toUtf8().getBytes()); putByte(null, (byte) 0); }
/** * Constructs a new global id from a document id string. * * @param id The document id to derive from. */ public GlobalId(IdString id) { byte [] raw = MD5.md5.get().digest(id.toUtf8().wrap().array()); long location = id.getLocation(); this.raw = new byte [LENGTH]; for (int i = 0; i < 4; ++i) { this.raw[i] = (byte)((location >> (8 * i)) & 0xFF); } for (int i=4; i < LENGTH; i++) { this.raw[i] = raw[i]; } }
private static boolean verifyAny(byte c, byte [] identifier) { if ((c >= 'A') && (c <= 'Z')) { throw new IllegalArgumentException("Illegal uppercase character '" + (char)c + "' of identifier '" + new Utf8String(new Utf8Array(identifier)).toString() +"'."); } return true; }
@Override public int hashCode() { return id.hashCode(); } }
public void write(DocumentId id) { put(null, id.getScheme().toUtf8().getBytes()); putByte(null, (byte) 0); }
private static boolean verifyFirst(byte c, byte [] identifier) { if (!((c == '_') || ((c >= 'a') && (c <= 'z')))) { throw new IllegalArgumentException("Illegal starting character '" + (char)c + "' of identifier '" + new Utf8String(new Utf8Array(identifier)).toString() +"'."); } return true; } private static boolean verifyAny(byte c, byte [] identifier) {
/** * Create from a Java-type value * * @param value the value **/ public StringValue(String value) { this.value = new Utf8String(value); } public StringValue(Utf8String value) {
@Override public String toString() { return utf8.toString(); } public final Utf8String getUtf8() {
@Override public boolean equals(Object obj) { if (!(obj instanceof DataTypeName)) return false; DataTypeName datatype = (DataTypeName)obj; return this.name.equals(datatype.name); }
@Override public int hashCode() { return name.hashCode(); }
static private Slime toSlime(String rankProfile, String summaryClass, String docType, SessionId sessionId, List<FastHit> hits) { Slime slime = new Slime(); Cursor root = slime.setObject(); if (summaryClass != null) { root.setString("class", summaryClass); } if (sessionId != null) { root.setData("sessionid", sessionId.asUtf8String().getBytes()); } if (docType != null) { root.setString("doctype", docType); } if (rankProfile != null) { root.setString("ranking", rankProfile); } Cursor gids = root.setArray("gids"); for (FastHit hit : hits) { gids.addData(hit.getGlobalId().getRawId()); } return slime; }