org.ojai.Value - java examples

Here are the examples of the java api org.ojai.Value taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

100 Examples 7

19 View Complete Implementation : HDocumentCollection.java
Copyright Apache License 2.0
Author : rayokota
public Doreplacedent findById(Value _id, QueryCondition c) throws StoreException {
    return findById(_id, c, (String[]) null);
}

19 View Complete Implementation : Values.java
Copyright Apache License 2.0
Author : ojai
/**
 * @return The specified value as a <code>byte</code>.
 * This may involve rounding or truncation.
 * @throws IllegalArgumentException if the specified value is
 * not one of the number types
 */
public static byte asByte(@NonNullable Value value) {
    return asNumber(value).byteValue();
}

19 View Complete Implementation : Values.java
Copyright Apache License 2.0
Author : ojai
/**
 * @return The specified value as a <code>double</code>.
 * This may involve rounding or truncation.
 * @throws IllegalArgumentException if the specified value is
 * not one of the number types
 */
public static double asDouble(Value value) {
    return asNumber(value).doubleValue();
}

19 View Complete Implementation : ValueByteIterator.java
Copyright Apache License 2.0
Author : brianfrankcooper
/**
 * OJAI Value byte iterator.
 *
 * Used for parsing the doreplacedent fetched MapR JSON DB
 */
public clreplaced ValueByteIterator extends ByteIterator {

    private Value value;

    public ValueByteIterator(Value value) {
        this.value = value;
    }

    @Override
    public boolean hasNext() {
        return false;
    }

    @Override
    public byte nextByte() {
        return 0;
    }

    @Override
    public long bytesLeft() {
        return 0;
    }

    @Override
    public String toString() {
        return Values.asJsonString(value);
    }
}

19 View Complete Implementation : HDocumentBuilder.java
Copyright Apache License 2.0
Author : rayokota
/**
 * Appends the {@code Value} to the current array.
 *
 * @param value the {@code Value} to append
 * @return {@code this} for chained invocation
 * @throws IllegalStateException if the builder is not in an ARRAY segment
 */
public HDoreplacedentBuilder add(Value value) {
    getCurrentList().set(getAndIncrArrayIndex(), value);
    return this;
}

19 View Complete Implementation : Values.java
Copyright Apache License 2.0
Author : ojai
/**
 * @return The specified value as an <code>int</code>.
 * This may involve rounding or truncation.
 * @throws IllegalArgumentException if the specified value is
 * not one of the number types
 */
public static int asInt(@NonNullable Value value) {
    return asNumber(value).intValue();
}

19 View Complete Implementation : Types.java
Copyright Apache License 2.0
Author : ojai
/**
 * @param value a <code>Value</code> whose tag name should be returned
 * @return A {@code String} representing the extended tag name of the
 *         {@code Type} of the given value, if the type is not of an
 *         intrinsic JSON type, otherwise {@code null}
 */
public static String getTypeTag(@NonNullable Value value) {
    return getTypeTag(value.getType());
}

19 View Complete Implementation : JsonValueBuilder.java
Copyright Apache License 2.0
Author : ojai
public static JsonValue initFrom(Value value) {
    if (value instanceof JsonValue) {
        return ((JsonValue) value).shallowCopy();
    }
    return initFromObject(value.getObject());
}

19 View Complete Implementation : Values.java
Copyright Apache License 2.0
Author : ojai
/**
 * @return The specified value as a <code>short</code>.
 * This may involve rounding or truncation.
 * @throws IllegalArgumentException if the specified value is
 * not one of the number types
 */
public static short replacedhort(@NonNullable Value value) {
    return asNumber(value).shortValue();
}

19 View Complete Implementation : Values.java
Copyright Apache License 2.0
Author : ojai
/**
 * @return The specified value as a <code>BigDecimal</code>.
 * This may involve rounding or truncation.
 * @throws IllegalArgumentException uf the specified value is
 * not one of the number types
 */
public static BigDecimal asDecimal(Value value) {
    Number val = asNumber(value);
    return (val instanceof BigDecimal) ? (BigDecimal) val : ((val instanceof Long) ? new BigDecimal(val.longValue()) : new BigDecimal(val.doubleValue()));
}

19 View Complete Implementation : HDocumentCollection.java
Copyright Apache License 2.0
Author : rayokota
/**
 * Returns a Doreplacedent with the given {@code "_id"} field
 * The Doreplacedent will contain only those field paths that are specified in the
 * argument. If no path parameter is specified then it returns a full doreplacedent.
 *
 * @param _id value to be used as the _id for this doreplacedent
 * @param paths list of fields that should be returned in the read doreplacedent
 * @return The Doreplacedent with the given id that can be used to requested paths.
 * @throws StoreException
 */
public Doreplacedent findById(Value _id, String... paths) throws StoreException {
    return findById(_id, true, paths);
}

19 View Complete Implementation : HDocumentBuilder.java
Copyright Apache License 2.0
Author : rayokota
public HDoreplacedentBuilder put(String field, Value value) {
    getCurrentDoreplacedent().set(field, value);
    return this;
}

19 View Complete Implementation : HDocumentCollection.java
Copyright Apache License 2.0
Author : rayokota
public Doreplacedent findById(Value _id, QueryCondition c, FieldPath... fields) throws StoreException {
    return findById(_id, c, Paths.asPathStrings(fields));
}

19 View Complete Implementation : Values.java
Copyright Apache License 2.0
Author : ojai
/**
 * @return The specified value as a <code>float</code>.
 * This may involve rounding or truncation.
 * @throws IllegalArgumentException if the specified value is
 * not one of the number types
 */
public static float asFloat(Value value) {
    return asNumber(value).floatValue();
}

19 View Complete Implementation : HDocumentCollection.java
Copyright Apache License 2.0
Author : rayokota
/**
 * Returns a Doreplacedent with the given {@code "_id"} field
 *
 * @param _id value to be used as the _id for this doreplacedent
 * @return The Doreplacedent with the given id
 * @throws StoreException
 */
public Doreplacedent findById(Value _id) throws StoreException {
    return findById(_id, (String[]) null);
}

19 View Complete Implementation : HDocumentCollection.java
Copyright Apache License 2.0
Author : rayokota
public Doreplacedent findById(Value _id, FieldPath... paths) throws StoreException {
    return findById(_id, Paths.asPathStrings(paths));
}

19 View Complete Implementation : Values.java
Copyright Apache License 2.0
Author : ojai
/**
 * @return The specified value as a <code>long</code>.
 * This may involve rounding or truncation.
 * @throws IllegalArgumentException if the specified value is
 * not one of the number types
 */
public static long asLong(Value value) {
    return asNumber(value).longValue();
}

19 View Complete Implementation : Types.java
Copyright Apache License 2.0
Author : ojai
/**
 * @param value a <code>Value</code> that should tested.
 * @return {@code true} if the given value is not of an intrinsic
 *         JSON type.
 */
public static boolean isExtendedType(@NonNullable Value value) {
    return isExtendedType(value.getType());
}

19 View Complete Implementation : MutationOp.java
Copyright Apache License 2.0
Author : ojai
public void setOpValue(@NonNullable Value opValue) {
    this.opValue = opValue;
}

19 View Complete Implementation : HDocumentStream.java
Copyright Apache License 2.0
Author : rayokota
private HDoreplacedent project(HDoreplacedent doc) {
    if (paths == null)
        return doc;
    HDoreplacedent newDoc = doc.shallowCopy();
    newDoc.clear();
    newDoc.setId(doc.getId());
    for (String path : paths) {
        Value value = doc.getValue(path);
        if (value != null && value.getType() != Value.Type.NULL) {
            newDoc.set(path, doc.getValue(path));
        }
    }
    return newDoc;
}

18 View Complete Implementation : HDocumentCollection.java
Copyright Apache License 2.0
Author : rayokota
public void insert(Doreplacedent doc) throws StoreException {
    if (doc == null)
        throw new IllegalArgumentException("doc is null");
    Value id = doc.getId();
    if (id == null)
        throw new IllegalStateException("id is null");
    insert(id, doc);
}

18 View Complete Implementation : HDocumentCollection.java
Copyright Apache License 2.0
Author : rayokota
protected Doreplacedent findById(Value _id, boolean reindexArrays, String... paths) throws StoreException {
    QueryPlan plan = new QueryOneCompiler(table, family, reindexArrays, _id, null, paths).compile();
    DoreplacedentStream stream = plan.execute();
    Iterator<Doreplacedent> doreplacedents = stream.iterator();
    return doreplacedents.hasNext() ? doreplacedents.next() : null;
}

18 View Complete Implementation : HDocumentCollection.java
Copyright Apache License 2.0
Author : rayokota
/**
 * Inserts or replace a new doreplacedent in this DoreplacedentStore with the value of
 * the specified Field as the {@code _id}.
 *
 * If the doreplacedent with the given _id exists in the DoreplacedentStore then that
 * doreplacedent will be replaced by the specified doreplacedent.
 *
 * @param doc        The Doreplacedent to be inserted or replaced in the DoreplacedentStore.
 * @param fieldAsKey doreplacedent's field to be used as the key when an id is not
 *                   preplaceded in and the doreplacedent doesn't have an "_id" field or
 *                   a different field is desired to be used as _id.
 * @throws StoreException
 */
public void insertOrReplace(Doreplacedent doc, String fieldAsKey) throws StoreException {
    if (doc == null)
        throw new IllegalArgumentException("doc is null");
    Value id = doc.getValue(fieldAsKey);
    if (id == null)
        throw new IllegalStateException("id is null");
    insertOrReplace(id, doc);
}

18 View Complete Implementation : HDocumentCollection.java
Copyright Apache License 2.0
Author : rayokota
public Doreplacedent findById(Value _id, QueryCondition c, String... paths) throws StoreException {
    QueryPlan plan = new QueryOneCompiler(table, family, true, _id, c, paths).compile();
    DoreplacedentStream stream = plan.execute();
    Iterator<Doreplacedent> doreplacedents = stream.iterator();
    return doreplacedents.hasNext() ? doreplacedents.next() : null;
}

18 View Complete Implementation : HDocumentCollection.java
Copyright Apache License 2.0
Author : rayokota
public void replace(Doreplacedent doc, String fieldAsKey) throws StoreException {
    if (doc == null)
        throw new IllegalArgumentException("doc is null");
    Value id = doc.getValue(fieldAsKey);
    if (id == null)
        throw new IllegalStateException("id is null");
    replace(id, doc);
}

18 View Complete Implementation : HDocumentCollection.java
Copyright Apache License 2.0
Author : rayokota
/**
 * Inserts or replace a new doreplacedent in this DoreplacedentStore.
 *
 * The specified Doreplacedent must contain an {@code "_id"} field or the operation
 * will fail.
 *
 * If the doreplacedent with the given _id exists in the DoreplacedentStore then that
 * doreplacedent will be replaced by the specified doreplacedent.
 *
 * @param doc The Doreplacedent to be inserted or replaced in the DoreplacedentStore.
 * @throws StoreException
 */
public void insertOrReplace(Doreplacedent doc) throws StoreException {
    if (doc == null)
        throw new IllegalArgumentException("doc is null");
    Value id = doc.getId();
    if (id == null)
        throw new IllegalStateException("id is null");
    insertOrReplace(id, doc);
}

18 View Complete Implementation : HDocumentCollection.java
Copyright Apache License 2.0
Author : rayokota
public void delete(Doreplacedent doc, String fieldAsKey) throws StoreException {
    if (doc == null)
        throw new IllegalArgumentException("doc is null");
    Value id = doc.getValue(fieldAsKey);
    if (id == null)
        throw new IllegalStateException("id is null");
    delete(id);
}

18 View Complete Implementation : HDocumentCollection.java
Copyright Apache License 2.0
Author : rayokota
public void replace(Doreplacedent doc) throws StoreException {
    if (doc == null)
        throw new IllegalArgumentException("doc is null");
    Value id = doc.getId();
    if (id == null)
        throw new IllegalStateException("id is null");
    replace(id, doc);
}

18 View Complete Implementation : JsonDocument.java
Copyright Apache License 2.0
Author : ojai
@Override
public JsonDoreplacedent setId(Value value) {
    set(ID_FIELD, value);
    return this;
}

18 View Complete Implementation : JsonDocument.java
Copyright Apache License 2.0
Author : ojai
@Override
public JsonDoreplacedent set(FieldPath field, Value value) {
    return setCommon(field, JsonValueBuilder.initFrom(value));
}

18 View Complete Implementation : ForwardingStore.java
Copyright Apache License 2.0
Author : ojai
@Override
public boolean checkAndDelete(final Value _id, final QueryCondition condition) throws StoreException {
    return store.checkAndDelete(_id, condition);
}

18 View Complete Implementation : HDocumentCollection.java
Copyright Apache License 2.0
Author : rayokota
/**
 * Deletes a doreplacedent with the given id. This operation is successful even
 * when the doreplacedent with the given id doesn't exist.
 *
 * If the parameter {@code fieldAsKey} is provided, its value will be used as
 * the "_id" to delete the doreplacedent.
 *
 * @param _id        doreplacedent id
 * @throws StoreException
 */
public void delete(Value _id) throws StoreException {
    MutationPlan plan = new DeleteCompiler(table, family, _id, null).compile();
    if (!plan.execute()) {
        throw new StoreException("Could not delete, it may have changed: " + _id);
    }
}

18 View Complete Implementation : MutationOp.java
Copyright Apache License 2.0
Author : ojai
public clreplaced MutationOp {

    public enum Type {

        SET,
        SET_OR_REPLACE,
        DELETE,
        INCREMENT,
        APPEND,
        MERGE
    }

    private Type type;

    private FieldPath fieldPath;

    private Value opValue;

    public Type getType() {
        return type;
    }

    public void setType(Type type) {
        this.type = type;
    }

    public FieldPath getFieldPath() {
        return fieldPath;
    }

    public void setFieldPath(@NonNullable FieldPath fieldPath) {
        this.fieldPath = fieldPath;
    }

    public Value getOpValue() {
        return opValue;
    }

    public void setOpValue(@NonNullable Value opValue) {
        this.opValue = opValue;
    }
}

18 View Complete Implementation : Documents.java
Copyright Apache License 2.0
Author : ojai
/**
 * Returns the value at the specified fieldPath as a {@link Value} or the
 * specified {@code defaultValue} if the specified {@code FieldPath} does not
 * exist in the doreplacedent.
 */
public static Value getValue(@NonNullable Doreplacedent doreplacedent, @NonNullable FieldPath fieldPath, @Nullable Value defaultValue) {
    Value docValue = doreplacedent.getValue(fieldPath);
    return docValue != null ? docValue : defaultValue;
}

18 View Complete Implementation : ReadOnlyDocument.java
Copyright Apache License 2.0
Author : ojai
@Override
public Doreplacedent set(String fieldPath, Value value) {
    throw readOnly();
}

18 View Complete Implementation : ReadOnlyDocument.java
Copyright Apache License 2.0
Author : ojai
@Override
public Doreplacedent set(FieldPath fieldPath, Value value) {
    throw readOnly();
}

18 View Complete Implementation : HDocumentCollection.java
Copyright Apache License 2.0
Author : rayokota
public void delete(Doreplacedent doc) throws StoreException {
    if (doc == null)
        throw new IllegalArgumentException("doc is null");
    Value id = doc.getId();
    if (id == null)
        throw new IllegalStateException("id is null");
    delete(id);
}

18 View Complete Implementation : ReadOnlyDocument.java
Copyright Apache License 2.0
Author : ojai
@Override
public Doreplacedent setId(Value _id) {
    throw readOnly();
}

18 View Complete Implementation : HValue.java
Copyright Apache License 2.0
Author : rayokota
public static HValue initFromValue(Value value) {
    if (value == null) {
        return HValue.NULL;
    } else if (value instanceof HValue) {
        return ((HValue) value).shallowCopy();
    } else {
        return initFromObject(value.getObject());
    }
}

18 View Complete Implementation : HDocumentCollection.java
Copyright Apache License 2.0
Author : rayokota
private Value getKeyField(Doreplacedent doc, String fieldAsKey) throws StoreException {
    if (doc == null)
        throw new IllegalArgumentException("doc is null");
    if (fieldAsKey == null)
        throw new IllegalArgumentException("fieldAsKey is null");
    Value value = doc.getValue(fieldAsKey);
    if (value == null)
        throw new IllegalArgumentException("key's value is null");
    return value;
}

18 View Complete Implementation : HDocumentCollection.java
Copyright Apache License 2.0
Author : rayokota
public void insert(Doreplacedent doc, String fieldAsKey) throws StoreException {
    if (doc == null)
        throw new IllegalArgumentException("doc is null");
    Value id = doc.getValue(fieldAsKey);
    if (id == null)
        throw new IllegalStateException("id is null");
    insert(id, doc);
}

17 View Complete Implementation : DocumentBase.java
Copyright Apache License 2.0
Author : ojai
@Override
public Doreplacedent set(String fieldPath, Value value) {
    return set(FieldPath.parseFrom(fieldPath), value);
}

17 View Complete Implementation : JsonDocument.java
Copyright Apache License 2.0
Author : ojai
@Override
public JsonDoreplacedent set(String field, Value value) {
    return setCommon(FieldPath.parseFrom(field), JsonValueBuilder.initFrom(value));
}

17 View Complete Implementation : ForwardingStore.java
Copyright Apache License 2.0
Author : ojai
@Override
public Doreplacedent findById(final Value _id, final FieldPath... fieldPaths) throws StoreException {
    return store.findById(_id, fieldPaths);
}

17 View Complete Implementation : ForwardingStore.java
Copyright Apache License 2.0
Author : ojai
@Override
public void delete(final Value _id) throws StoreException {
    store.delete(_id);
}

17 View Complete Implementation : ForwardingStore.java
Copyright Apache License 2.0
Author : ojai
@Override
public void increment(final Value _id, final String field, final short inc) throws StoreException {
    store.increment(_id, field, inc);
}

17 View Complete Implementation : ForwardingStore.java
Copyright Apache License 2.0
Author : ojai
@Override
public void increment(final Value _id, final String field, final int inc) throws StoreException {
    store.increment(_id, field, inc);
}

17 View Complete Implementation : ForwardingStore.java
Copyright Apache License 2.0
Author : ojai
@Override
public Doreplacedent findById(final Value id) throws StoreException {
    return store.findById(id);
}

17 View Complete Implementation : ForwardingStore.java
Copyright Apache License 2.0
Author : ojai
@Override
public Doreplacedent findById(final Value _id, final String... fieldPaths) throws StoreException {
    return store.findById(_id, fieldPaths);
}

17 View Complete Implementation : ForwardingStore.java
Copyright Apache License 2.0
Author : ojai
@Override
public Doreplacedent findById(final Value _id, final QueryCondition condition) throws StoreException {
    return store.findById(_id, condition);
}