Example usage for org.apache.lucene.util IntsRef deepCopyOf

List of usage examples for org.apache.lucene.util IntsRef deepCopyOf

Introduction

In this page you can find the example usage for org.apache.lucene.util IntsRef deepCopyOf.

Prototype

public static IntsRef deepCopyOf(IntsRef other) 

Source Link

Document

Creates a new IntsRef that points to a copy of the ints from other

The returned IntsRef will have a length of other.length and an offset of zero.

Usage

From source file:com.sindicetech.siren.analysis.filter.DatatypeAnalyzerFilter.java

License:Open Source License

/**
 * Copy the inner's stream attributes values to the main stream's ones. This filter
 * uses an inner stream, therefore it needs to be cleared so that other filters
 * have clean attributes data. Because of that, the attributes datatypeURI and
 * node have to saved in order to be restored after.
 */// w w  w  .  jav  a  2s  . c o  m
private void copyInnerStreamAttributes() {
    // backup datatype, node identifier and path
    final IntsRef nodeId = IntsRef.deepCopyOf(nodeAtt.node());
    final char[] dt = dtypeAtt.datatypeURI();
    final String[] path = pathAtt.path();

    // clear attributes
    input.clearAttributes();

    // copy inner attributes
    final int len = tokenTermAtt.length();
    termAtt.copyBuffer(tokenTermAtt.buffer(), 0, len);
    offsetAtt.setOffset(tokenOffsetAtt.startOffset(), tokenOffsetAtt.endOffset());
    posIncrAtt.setPositionIncrement(tokenPosIncrAtt.getPositionIncrement());
    typeAtt.setType(tokenTypeAtt.type());
    // TupleTokenizer handles the setting of tuple/cell values and the datatype URI

    // restore datatype, node and path attributes
    nodeAtt.copyNode(nodeId);
    dtypeAtt.setDatatypeURI(dt);
    pathAtt.setPath(path);
}

From source file:com.sindicetech.siren.util.JsonGenerator.java

License:Open Source License

/**
 * Return the next element of the json document
 */// w  w w  .j a  va 2 s .co  m
private String getNextNode() {
    final int popState;

    switch (states.peek()) {
    case ARRAY:
        switch (rand.nextInt(9)) {
        case 0: // String case
            final String val = "stepha" + this.getWhitespace() + "n" + this.getWhitespace() + "e";
            this.addToLastNode(1);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            images.add(val);
            types.add(ExtendedJsonTokenizer.getTokenTypes()[LITERAL]);
            incr.add(1);
            datatypes.add(XSDDatatype.XSD_STRING);
            return "\"" + val + "\"" + this.getWhitespace() + ",";
        case 1: // DOUBLE case
            this.addToLastNode(1);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            images.add("34.560e-9");
            types.add(ExtendedJsonTokenizer.getTokenTypes()[NUMBER]);
            incr.add(1);
            datatypes.add(XSDDatatype.XSD_DOUBLE);
            return "34.560e-9" + this.getWhitespace() + ",";
        case 2: // LONG case
            this.addToLastNode(1);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            images.add("34560e-9");
            types.add(ExtendedJsonTokenizer.getTokenTypes()[NUMBER]);
            incr.add(1);
            datatypes.add(XSDDatatype.XSD_LONG);
            return "34560e-9" + this.getWhitespace() + ",";
        case 3: // true case
            this.addToLastNode(1);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            images.add("true");
            types.add(ExtendedJsonTokenizer.getTokenTypes()[TRUE]);
            incr.add(1);
            datatypes.add(XSDDatatype.XSD_BOOLEAN);
            return "true" + this.getWhitespace() + ",";
        case 4: // false case
            this.addToLastNode(1);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            images.add("false");
            types.add(ExtendedJsonTokenizer.getTokenTypes()[FALSE]);
            incr.add(1);
            datatypes.add(XSDDatatype.XSD_BOOLEAN);
            return "false" + this.getWhitespace() + ",";
        case 5: // null case
            this.addToLastNode(1);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            images.add("null");
            types.add(ExtendedJsonTokenizer.getTokenTypes()[NULL]);
            incr.add(1);
            datatypes.add(XSDDatatype.XSD_STRING);
            return "null" + this.getWhitespace() + ",";
        case 6: // nested array case
            if (states.size() <= MAX_DEPTH) {
                this.addToLastNode(1);
                this.incrNodeObjectPath();
                states.add(ARRAY);
                return "[";
            }
            return "";
        case 7: // nested object case
            if (states.size() <= MAX_DEPTH) {
                this.addToLastNode(1);
                this.incrNodeObjectPath();
                states.add(ARRAY_OBJECT);
                return "{";
            }
            return "";
        case 8: // closing array case
            this.decrNodeObjectPath();
            popState = states.pop();
            if (popState != ARRAY) {
                shouldFail = true;
            }
            // Remove previous comma, this is not allowed
            final int comma = sb.lastIndexOf(",");
            if (comma != -1 && sb.substring(comma + 1).matches("\\s*")) {
                sb.deleteCharAt(comma);
            }
            return "],";
        }
    case ARRAY_OBJECT:
    case OBJECT_ATT:
        switch (rand.nextInt(3)) {
        case 0: // new object field
            types.add(ExtendedJsonTokenizer.getTokenTypes()[LITERAL]);
            images.add("ste ph ane");
            incr.add(1);
            this.addToLastNode(1);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            datatypes.add(JSONDatatype.JSON_FIELD);

            states.push(OBJECT_VAL);
            return "\"ste ph ane\"" + this.getWhitespace() + ":";
        case 1: // close object
            if (states.peek() == OBJECT_ATT && nestedObjs > 0) {
                this.decrNodeObjectPath();
                nestedObjs--;
            }
            this.decrNodeObjectPath();
            popState = states.pop();
            if (popState != OBJECT_ATT && popState != ARRAY_OBJECT) {
                shouldFail = true;
            }
            // Remove previous comma, this is not allowed
            final int comma = sb.lastIndexOf(",");
            if (comma != -1 && sb.substring(comma + 1).matches("\\s*")) {
                sb.deleteCharAt(comma);
            }
            return states.empty() ? "}" : "},";
        case 2: // Datatype
            if (getLastNode() >= 0) {
                // this nested object cannot be a datatype object because other things have been added to it
                return "";
            }
            final String field;
            if (states.isEmpty()) {
                // datatype object at the root are not possible
                shouldFail = true;
                field = "{";
            } else if (states.peek() == OBJECT_ATT) {
                // field name
                this.addToLastNode(1);
                field = "\"field\":{";
                types.add(ExtendedJsonTokenizer.getTokenTypes()[LITERAL]);
                images.add("field");
                incr.add(1);
                nodes.add(IntsRef.deepCopyOf(curNodePath));
                datatypes.add(JSONDatatype.JSON_FIELD);
                // value
                this.incrNodeObjectPath();
                this.setLastNode(0);
            } else if (states.peek() == ARRAY) {
                this.addToLastNode(1);
                field = "{";
            } else if (states.peek() == ARRAY_OBJECT) {
                this.decrNodeObjectPath();
                field = "";
            } else {
                // should not happen
                throw new IllegalStateException("Received unknown state=" + states.peek());
            }

            types.add(ExtendedJsonTokenizer.getTokenTypes()[LITERAL]);
            images.add("Luke Skywalker");
            incr.add(1);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            datatypes.add("jedi");
            // close datatype object
            if (states.peek() == ARRAY_OBJECT) {
                popState = states.pop();
            } else {
                this.decrNodeObjectPath();
            }
            return field + this.getWhitespace() + "\"" + ExtendedJsonTokenizer.DATATYPE_LABEL + "\":"
                    + this.getWhitespace() + "\"jedi\"," + "\"" + ExtendedJsonTokenizer.DATATYPE_VALUES + "\":"
                    + this.getWhitespace() + "\"Luke Skywalker\"" + this.getWhitespace() + "},";
        }
    case OBJECT_VAL:
        switch (rand.nextInt(8)) {
        case 0: // String
            return this.doValString("stepha" + this.getWhitespace() + "n" + this.getWhitespace() + "e");
        case 1: // DOUBLE case
            images.add("34.560e-9");
            types.add(ExtendedJsonTokenizer.getTokenTypes()[NUMBER]);
            incr.add(1);
            this.incrNodeObjectPath();
            this.setLastNode(0);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            this.decrNodeObjectPath();
            datatypes.add(XSDDatatype.XSD_DOUBLE);

            states.pop(); // remove OBJECT_VAL state
            return "34.560e-9" + this.getWhitespace() + ",";
        case 2: // LONG case
            images.add("34560e-9");
            types.add(ExtendedJsonTokenizer.getTokenTypes()[NUMBER]);
            incr.add(1);
            this.incrNodeObjectPath();
            this.setLastNode(0);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            this.decrNodeObjectPath();
            datatypes.add(XSDDatatype.XSD_LONG);

            states.pop(); // remove OBJECT_VAL state
            return "34560e-9" + this.getWhitespace() + ",";
        case 3: // True
            images.add("true");
            types.add(ExtendedJsonTokenizer.getTokenTypes()[TRUE]);
            incr.add(1);
            this.incrNodeObjectPath();
            this.setLastNode(0);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            this.decrNodeObjectPath();
            datatypes.add(XSDDatatype.XSD_BOOLEAN);

            states.pop(); // remove OBJECT_VAL state
            return "true" + this.getWhitespace() + ",";
        case 4: // False
            images.add("false");
            types.add(ExtendedJsonTokenizer.getTokenTypes()[FALSE]);
            incr.add(1);
            this.incrNodeObjectPath();
            this.setLastNode(0);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            this.decrNodeObjectPath();
            datatypes.add(XSDDatatype.XSD_BOOLEAN);

            states.pop(); // remove OBJECT_VAL state
            return "false" + this.getWhitespace() + ",";
        case 5: // NULL
            images.add("null");
            types.add(ExtendedJsonTokenizer.getTokenTypes()[NULL]);
            incr.add(1);
            this.incrNodeObjectPath();
            this.setLastNode(0);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            this.decrNodeObjectPath();
            datatypes.add(XSDDatatype.XSD_STRING);

            states.pop(); // remove OBJECT_VAL state
            return "null" + this.getWhitespace() + ",";
        case 6: // New array
            if (states.size() <= MAX_DEPTH) {
                states.pop(); // remove OBJECT_VAL state
                this.incrNodeObjectPath();
                states.add(ARRAY);
                return "[";
            }
            return this.doValString("");
        case 7: // new Object
            if (states.size() <= MAX_DEPTH) {
                states.pop(); // remove OBJECT_VAL state
                // Two incrementations, because the object introduce a "blank" node
                nestedObjs++;
                this.incrNodeObjectPath();
                this.setLastNode(0);
                this.incrNodeObjectPath();
                states.add(OBJECT_ATT);
                return "{";
            }
            return this.doValString("");
        }
    default:
        throw new IllegalStateException("Got unknown lexical state: " + states.peek());
    }
}

From source file:com.sindicetech.siren.util.JsonGenerator.java

License:Open Source License

/**
 * Add a string value to an object entry
 *///from w  w  w .j a  v  a  2s.c o  m
private String doValString(final String val) {
    images.add(val);
    types.add(ExtendedJsonTokenizer.getTokenTypes()[LITERAL]);
    incr.add(1);
    this.incrNodeObjectPath();
    this.setLastNode(0);
    nodes.add(IntsRef.deepCopyOf(curNodePath));
    this.decrNodeObjectPath();
    datatypes.add(XSDDatatype.XSD_STRING);

    states.pop(); // remove OBJECT_VAL state
    return "\"" + val + "\"" + this.getWhitespace() + ",";
}

From source file:org.sindice.siren.util.JsonGenerator.java

License:Apache License

/**
 * Return the next element of the json document
 *//*from ww  w .  j av a  2s . c  o m*/
private String getNextNode() {
    final int popState;

    switch (states.peek()) {
    case ARRAY:
        switch (rand.nextInt(9)) {
        case 0: // String case
            final String val = "stepha" + this.getWhitespace() + "n" + this.getWhitespace() + "e";
            this.addToLastNode(1);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            images.add(val);
            types.add(JsonTokenizer.getTokenTypes()[LITERAL]);
            incr.add(1);
            datatypes.add(XSDDatatype.XSD_STRING);
            return "\"" + val + "\"" + this.getWhitespace() + ",";
        case 1: // DOUBLE case
            this.addToLastNode(1);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            images.add("34.560e-9");
            types.add(JsonTokenizer.getTokenTypes()[NUMBER]);
            incr.add(1);
            datatypes.add(XSDDatatype.XSD_DOUBLE);
            return "34.560e-9" + this.getWhitespace() + ",";
        case 2: // LONG case
            this.addToLastNode(1);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            images.add("34560e-9");
            types.add(JsonTokenizer.getTokenTypes()[NUMBER]);
            incr.add(1);
            datatypes.add(XSDDatatype.XSD_LONG);
            return "34560e-9" + this.getWhitespace() + ",";
        case 3: // true case
            this.addToLastNode(1);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            images.add("true");
            types.add(JsonTokenizer.getTokenTypes()[TRUE]);
            incr.add(1);
            datatypes.add(XSDDatatype.XSD_BOOLEAN);
            return "true" + this.getWhitespace() + ",";
        case 4: // false case
            this.addToLastNode(1);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            images.add("false");
            types.add(JsonTokenizer.getTokenTypes()[FALSE]);
            incr.add(1);
            datatypes.add(XSDDatatype.XSD_BOOLEAN);
            return "false" + this.getWhitespace() + ",";
        case 5: // null case
            this.addToLastNode(1);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            images.add("null");
            types.add(JsonTokenizer.getTokenTypes()[NULL]);
            incr.add(1);
            datatypes.add(XSDDatatype.XSD_STRING);
            return "null" + this.getWhitespace() + ",";
        case 6: // nested array case
            if (states.size() <= MAX_DEPTH) {
                this.addToLastNode(1);
                this.incrNodeObjectPath();
                states.add(ARRAY);
                return "[";
            }
            return "";
        case 7: // nested object case
            if (states.size() <= MAX_DEPTH) {
                this.addToLastNode(1);
                this.incrNodeObjectPath();
                states.add(OBJECT_ATT);
                return "{";
            }
            return "";
        case 8: // closing array case
            this.decrNodeObjectPath();
            popState = states.pop();
            if (popState != ARRAY) {
                shouldFail = true;
            }
            // Remove previous comma, this is not allowed
            final int comma = sb.lastIndexOf(",");
            if (comma != -1 && sb.substring(comma + 1).matches("\\s*")) {
                sb.deleteCharAt(comma);
            }
            return "],";
        }
    case OBJECT_ATT:
        switch (rand.nextInt(3)) {
        case 0:
            types.add(JsonTokenizer.getTokenTypes()[LITERAL]);
            images.add("ste ph ane");
            incr.add(1);
            this.addToLastNode(1);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            datatypes.add(JSONDatatype.JSON_FIELD);

            states.push(OBJECT_VAL);
            return "\"ste ph ane\"" + this.getWhitespace() + ":";
        case 1:
            if (nestedObjs > 0) {
                this.decrNodeObjectPath();
                nestedObjs--;
            }
            this.decrNodeObjectPath();
            popState = states.pop();
            if (popState != OBJECT_ATT) {
                shouldFail = true;
            }
            return states.empty() ? "}" : "},";
        case 2:
            final String field;
            if (states.isEmpty()) {
                // datatype object at the root are not possible
                shouldFail = true;
                field = "";
            } else if (states.peek() == OBJECT_ATT) {
                // field name
                this.addToLastNode(1);
                field = "\"field\":";
                types.add(JsonTokenizer.getTokenTypes()[LITERAL]);
                images.add("field");
                incr.add(1);
                nodes.add(IntsRef.deepCopyOf(curNodePath));
                datatypes.add(JSONDatatype.JSON_FIELD);
                // value
                this.incrNodeObjectPath();
                this.setLastNode(0);
            } else if (states.peek() == ARRAY) {
                this.addToLastNode(1);
                field = "";
            } else {
                // should not happen
                throw new IllegalStateException();
            }

            types.add(JsonTokenizer.getTokenTypes()[LITERAL]);
            images.add("Luke Skywalker");
            incr.add(1);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            datatypes.add("jedi");
            // close datatype object
            this.decrNodeObjectPath();

            return field + "{" + this.getWhitespace() + "\"" + JsonTokenizer.DATATYPE_LABEL + "\":"
                    + this.getWhitespace() + "\"jedi\"," + "\"" + JsonTokenizer.DATATYPE_VALUES + "\":"
                    + this.getWhitespace() + "\"Luke Skywalker\"" + this.getWhitespace() + "},";
        }
    case OBJECT_VAL:
        switch (rand.nextInt(8)) {
        case 0:
            return this.doValString("stepha" + this.getWhitespace() + "n" + this.getWhitespace() + "e");
        case 1: // DOUBLE case
            images.add("34.560e-9");
            types.add(JsonTokenizer.getTokenTypes()[NUMBER]);
            incr.add(1);
            this.incrNodeObjectPath();
            this.setLastNode(0);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            this.decrNodeObjectPath();
            datatypes.add(XSDDatatype.XSD_DOUBLE);

            states.pop(); // remove OBJECT_VAL state
            return "34.560e-9" + this.getWhitespace() + ",";
        case 2: // LONG case
            images.add("34560e-9");
            types.add(JsonTokenizer.getTokenTypes()[NUMBER]);
            incr.add(1);
            this.incrNodeObjectPath();
            this.setLastNode(0);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            this.decrNodeObjectPath();
            datatypes.add(XSDDatatype.XSD_LONG);

            states.pop(); // remove OBJECT_VAL state
            return "34560e-9" + this.getWhitespace() + ",";
        case 3:
            images.add("true");
            types.add(JsonTokenizer.getTokenTypes()[TRUE]);
            incr.add(1);
            this.incrNodeObjectPath();
            this.setLastNode(0);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            this.decrNodeObjectPath();
            datatypes.add(XSDDatatype.XSD_BOOLEAN);

            states.pop(); // remove OBJECT_VAL state
            return "true" + this.getWhitespace() + ",";
        case 4:
            images.add("false");
            types.add(JsonTokenizer.getTokenTypes()[FALSE]);
            incr.add(1);
            this.incrNodeObjectPath();
            this.setLastNode(0);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            this.decrNodeObjectPath();
            datatypes.add(XSDDatatype.XSD_BOOLEAN);

            states.pop(); // remove OBJECT_VAL state
            return "false" + this.getWhitespace() + ",";
        case 5:
            images.add("null");
            types.add(JsonTokenizer.getTokenTypes()[NULL]);
            incr.add(1);
            this.incrNodeObjectPath();
            this.setLastNode(0);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            this.decrNodeObjectPath();
            datatypes.add(XSDDatatype.XSD_STRING);

            states.pop(); // remove OBJECT_VAL state
            return "null" + this.getWhitespace() + ",";
        case 6:
            if (states.size() <= MAX_DEPTH) {
                states.pop(); // remove OBJECT_VAL state
                this.incrNodeObjectPath();
                states.add(ARRAY);
                return "[";
            }
            return this.doValString("");
        case 7:
            if (states.size() <= MAX_DEPTH) {
                states.pop(); // remove OBJECT_VAL state
                // Two incrementations, because the object introduce a "blank" node
                nestedObjs++;
                this.incrNodeObjectPath();
                this.setLastNode(0);
                this.incrNodeObjectPath();
                states.add(OBJECT_ATT);
                return "{";
            }
            return this.doValString("");
        }
    default:
        throw new IllegalStateException("Got unknown lexical state: " + states.peek());
    }
}

From source file:org.sindice.siren.util.JsonGenerator.java

License:Apache License

/**
 * Add a string value to an object entry
 *//*  ww w.jav  a 2 s.co  m*/
private String doValString(final String val) {
    images.add(val);
    types.add(JsonTokenizer.getTokenTypes()[LITERAL]);
    incr.add(1);
    this.incrNodeObjectPath();
    this.setLastNode(0);
    nodes.add(IntsRef.deepCopyOf(curNodePath));
    this.decrNodeObjectPath();
    datatypes.add(XSDDatatype.XSD_STRING);

    states.pop(); // remove OBJECT_VAL state
    return "\"" + val + "\"" + this.getWhitespace() + ",";
}