Example usage for org.apache.lucene.util ArrayUtil parseInt

List of usage examples for org.apache.lucene.util ArrayUtil parseInt

Introduction

In this page you can find the example usage for org.apache.lucene.util ArrayUtil parseInt.

Prototype

public static int parseInt(char[] chars, int offset, int len) throws NumberFormatException 

Source Link

Document

Parses a char array into an int.

Usage

From source file:edu.cmu.lti.oaqa.annographix.solr.AnnotEncoderVer3.java

License:Apache License

@Override
public BytesRef encode(char[] buffer, int offset, int length) {
    int sep1pos = -1, sep2pos = -1, sep3pos = -1, sepQty = 0;

    for (int i = 0; i < length; ++i) {
        char c = buffer[offset + i];
        if (c == UtilConst.PAYLOAD_ID_SEP_CHAR) {
            ++sepQty;//from   w  ww.ja  v  a2  s . co  m
            if (1 == sepQty)
                sep1pos = i;
            else if (2 == sepQty)
                sep2pos = i;
            else if (3 == sepQty)
                sep3pos = i;
            else {
                String errData = new String(buffer, offset, length);
                throw new RuntimeException("Cannot parse payload input: " + errData);
            }
        }
    }

    int wordStartPos = ArrayUtil.parseInt(buffer, offset, sep1pos);
    int wordEndPos = ArrayUtil.parseInt(buffer, offset + sep1pos + 1, sep2pos - sep1pos - 1);
    int annotId = ArrayUtil.parseInt(buffer, offset + sep2pos + 1, sep3pos - sep2pos - 1);
    int parentId = ArrayUtil.parseInt(buffer, offset + sep3pos + 1, length - sep3pos - 1);

    BytesRef result = new BytesRef(PayloadHelper.encodeInt(wordStartPos));
    result.append(new BytesRef(PayloadHelper.encodeInt(wordEndPos)));
    result.append(new BytesRef(PayloadHelper.encodeInt(annotId)));
    result.append(new BytesRef(PayloadHelper.encodeInt(parentId)));
    return result;
}