private String consumeKey() { if (s.consumeOptional('"')) { String key=s.consumeTo('"'); s.consume('"'); return key; } else if (s.consumeOptional('\'')) { String key=s.consumeTo('\''); s.consume('\''); return key; } else { int keyEnd=findEndOfKey(); if (keyEnd<0) throw new IllegalArgumentException("Expected a key followed by ':' " + s.at()); return s.consumeToPosition(keyEnd); } }
/** * Adds attributes with the specified bitmap to normalizer. * @param attribute Attribute to add * @param value Value of attribute * @param bitmap Bitmap as a list of bits, e.g. '[0, 3, 45]' */ private void parseBitmapList(String attribute, String value, String bitmap) { PositionedString s = new PositionedString(bitmap); s.consume('['); BigInteger mask = BigInteger.ZERO; while (!s.peek(']')) { s.consumeSpaces(); int pos = findNextButSkipLists(new char[]{',',']'}, s.string(), s.position()); if (pos == -1) { break; } int subqueryIndex = Integer.parseUnsignedInt(s.substring(pos).trim()); if (subqueryIndex > 63 || subqueryIndex < 0) { throw new IllegalArgumentException("Subquery index must be in the range 0-63"); } mask = mask.or(BigInteger.ONE.shiftLeft(subqueryIndex)); s.setPosition(pos); s.consumeOptional(','); s.consumeSpaces(); } addAttribute(attribute, value, mask); }
/** * Parses a list of values for a given attribute. When calling this * function, string() must point to the start of the list. */ private void parseMultiValue(String attribute) { // string() will point to the start of value. string().consume('['); while (!string().peek(']')) { string().consumeSpaces(); consumeValue(attribute); string().consumeOptional(','); string().consumeSpaces(); } }
/** * Parses a map on the form <code>{key1:value1,key2:value2 ...}</code> * * @param string the textual representation of the map */ public void parse(String string) { try { this.s=new PositionedString(string); s.consumeSpaces(); s.consume('{'); while ( ! s.peek('}')) { s.consumeSpaces(); String key=consumeKey(); s.consume(':'); s.consumeSpaces(); consumeValue(key); s.consumeOptional(','); s.consumeSpaces(); } s.consume('}'); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("'" + s + "' is not a legal sparse vector string",e); } }