All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.rethinkdb.model.Arguments Maven / Gradle / Ivy

There is a newer version: 2.3.2.20160729
Show newest version
package com.rethinkdb.model;


import com.rethinkdb.ast.ReqlAst;
import com.rethinkdb.ast.Util;

import java.util.*;
import java.util.stream.Collectors;

public class Arguments extends ArrayList {

    public Arguments() {}

    public Arguments(Object arg){
        if(arg instanceof List){
            coerceAndAddAll((List) arg);
        } else {
            coerceAndAdd(arg);
        }
    }
    public Arguments(Arguments args) {
        addAll(args);
    }
    public Arguments(ReqlAst arg) {
        add(arg);
    }

    public Arguments(Object[] args) {
        coerceAndAddAll(args);
    }

    public Arguments(List args) {
        addAll(Collections.singletonList(args).stream()
                .map(Util::toReqlAst)
                .collect(Collectors.toList()));
    }

    public static Arguments make(Object... args){
        return new Arguments(args);
    }

    public void coerceAndAdd(Object obj) {
        add(Util.toReqlAst(obj));
    }

    public void coerceAndAddAll(Object[] args) {
        coerceAndAddAll(Arrays.asList(args));
    }

    public void coerceAndAddAll(List args){
        addAll(args.stream()
                .map(Util::toReqlAst)
                .collect(Collectors.toList()));
    }
}