Example usage for com.google.common.primitives Booleans toArray

List of usage examples for com.google.common.primitives Booleans toArray

Introduction

In this page you can find the example usage for com.google.common.primitives Booleans toArray.

Prototype

public static boolean[] toArray(Collection<Boolean> collection) 

Source Link

Document

Copies a collection of Boolean instances into a new array of primitive boolean values.

Usage

From source file:xfel.mods.arp.base.peripheral.bind.AbstractAnnotatedPeripheral.java

private static BindingData getBindingData(Class<? extends AbstractAnnotatedPeripheral> cls) {
    BindingData bdata = computedData.get(cls);
    if (bdata != null) {
        return bdata;
    }//from   w  ww  . java 2  s .  c om

    ArrayList<String> names = new ArrayList<String>();
    ArrayList<Method> methods = new ArrayList<Method>();
    ArrayList<Boolean> async = new ArrayList<Boolean>();

    for (Method method : cls.getMethods()) {
        if (method.isAnnotationPresent(PeripheralMethod.class)) {
            PeripheralMethod ann = method.getAnnotation(PeripheralMethod.class);

            String name = ann.name();
            if (name.equals(PeripheralMethod.DEFAULT_NAME)) {
                name = method.getName();
            }

            names.add(name);
            methods.add(method);
            async.add(ann.async());
        }
    }

    bdata = new BindingData();
    bdata.methods = (Method[]) methods.toArray(new Method[methods.size()]);
    bdata.mnames = (String[]) names.toArray(new String[names.size()]);
    bdata.async = Booleans.toArray(async);

    computedData.put(cls, bdata);

    return bdata;
}

From source file:org.terasology.persistence.typeHandling.coreTypes.BooleanTypeHandler.java

@Override
public PersistedData serializeCollection(Collection<Boolean> value, SerializationContext context) {
    return context.create(Booleans.toArray(value));
}

From source file:xfel.mods.arp.base.utils.reflection.PrimitiveTypeHelper.java

@Override
public Object convertToTypeArray(Collection<?> collection) {
    return Booleans.toArray((Collection<Boolean>) collection);
}

From source file:org.eyeseetea.malariacare.layout.utils.AutoTabInVisibilityState.java

public int countInvisible() {
    return Booleans.countTrue(Booleans.toArray(elementInvisibility.values()));
}

From source file:org.apache.hive.service.cli.Column.java

public Column(TColumn colValues) {
    if (colValues.isSetBoolVal()) {
        type = Type.BOOLEAN_TYPE;
        nulls = toBitset(colValues.getBoolVal().getNulls());
        boolVars = Booleans.toArray(colValues.getBoolVal().getValues());
        size = boolVars.length;/* w w w .  j  a v  a2 s .  c o  m*/
    } else if (colValues.isSetByteVal()) {
        type = Type.TINYINT_TYPE;
        nulls = toBitset(colValues.getByteVal().getNulls());
        byteVars = Bytes.toArray(colValues.getByteVal().getValues());
        size = byteVars.length;
    } else if (colValues.isSetI16Val()) {
        type = Type.SMALLINT_TYPE;
        nulls = toBitset(colValues.getI16Val().getNulls());
        shortVars = Shorts.toArray(colValues.getI16Val().getValues());
        size = shortVars.length;
    } else if (colValues.isSetI32Val()) {
        type = Type.INT_TYPE;
        nulls = toBitset(colValues.getI32Val().getNulls());
        intVars = Ints.toArray(colValues.getI32Val().getValues());
        size = intVars.length;
    } else if (colValues.isSetI64Val()) {
        type = Type.BIGINT_TYPE;
        nulls = toBitset(colValues.getI64Val().getNulls());
        longVars = Longs.toArray(colValues.getI64Val().getValues());
        size = longVars.length;
    } else if (colValues.isSetDoubleVal()) {
        type = Type.DOUBLE_TYPE;
        nulls = toBitset(colValues.getDoubleVal().getNulls());
        doubleVars = Doubles.toArray(colValues.getDoubleVal().getValues());
        size = doubleVars.length;
    } else if (colValues.isSetBinaryVal()) {
        type = Type.BINARY_TYPE;
        nulls = toBitset(colValues.getBinaryVal().getNulls());
        binaryVars = colValues.getBinaryVal().getValues();
        size = binaryVars.size();
    } else if (colValues.isSetStringVal()) {
        type = Type.STRING_TYPE;
        nulls = toBitset(colValues.getStringVal().getNulls());
        stringVars = colValues.getStringVal().getValues();
        size = stringVars.size();
    } else {
        throw new IllegalStateException("invalid union object");
    }
}

From source file:org.apache.hadoop.hive.serde2.thrift.ColumnBuffer.java

public ColumnBuffer(TColumn colValues) {
    if (colValues.isSetBoolVal()) {
        type = Type.BOOLEAN_TYPE;
        nulls = toBitset(colValues.getBoolVal().getNulls());
        boolVars = Booleans.toArray(colValues.getBoolVal().getValues());
        size = boolVars.length;/*from  w  ww  .ja v a  2 s  .com*/
    } else if (colValues.isSetByteVal()) {
        type = Type.TINYINT_TYPE;
        nulls = toBitset(colValues.getByteVal().getNulls());
        byteVars = Bytes.toArray(colValues.getByteVal().getValues());
        size = byteVars.length;
    } else if (colValues.isSetI16Val()) {
        type = Type.SMALLINT_TYPE;
        nulls = toBitset(colValues.getI16Val().getNulls());
        shortVars = Shorts.toArray(colValues.getI16Val().getValues());
        size = shortVars.length;
    } else if (colValues.isSetI32Val()) {
        type = Type.INT_TYPE;
        nulls = toBitset(colValues.getI32Val().getNulls());
        intVars = Ints.toArray(colValues.getI32Val().getValues());
        size = intVars.length;
    } else if (colValues.isSetI64Val()) {
        type = Type.BIGINT_TYPE;
        nulls = toBitset(colValues.getI64Val().getNulls());
        longVars = Longs.toArray(colValues.getI64Val().getValues());
        size = longVars.length;
    } else if (colValues.isSetDoubleVal()) {
        type = Type.DOUBLE_TYPE;
        nulls = toBitset(colValues.getDoubleVal().getNulls());
        doubleVars = Doubles.toArray(colValues.getDoubleVal().getValues());
        size = doubleVars.length;
    } else if (colValues.isSetBinaryVal()) {
        type = Type.BINARY_TYPE;
        nulls = toBitset(colValues.getBinaryVal().getNulls());
        binaryVars = colValues.getBinaryVal().getValues();
        size = binaryVars.size();
    } else if (colValues.isSetStringVal()) {
        type = Type.STRING_TYPE;
        nulls = toBitset(colValues.getStringVal().getNulls());
        stringVars = colValues.getStringVal().getValues();
        size = stringVars.size();
    } else {
        throw new IllegalStateException("invalid union object");
    }
}

From source file:org.eyeseetea.malariacare.layout.utils.AutoTabInVisibilityState.java

/**
 * Get the number of elements that are hidden until a given position
 * @param position// ww w.  ja  va 2 s .  c o m
 * @return number of elements hidden (true in elementInvisibility Map)
 */
private int getHiddenCountUpTo(int position) {
    boolean[] upper = Arrays.copyOfRange(Booleans.toArray(elementInvisibility.values()), 0, position + 1);
    return Booleans.countTrue(upper);
}

From source file:io.crate.analyze.OrderBy.java

public OrderBy merge(@Nullable OrderBy otherOrderBy) {
    if (otherOrderBy != null) {
        List<Symbol> newOrderBySymbols = otherOrderBy.orderBySymbols();
        List<Boolean> newReverseFlags = new ArrayList<>(Booleans.asList(otherOrderBy.reverseFlags()));
        List<Boolean> newNullsFirst = new ArrayList<>(Arrays.asList(otherOrderBy.nullsFirst()));

        for (int i = 0; i < orderBySymbols.size(); i++) {
            Symbol orderBySymbol = orderBySymbols.get(i);
            int idx = newOrderBySymbols.indexOf(orderBySymbol);
            if (idx == -1) {
                newOrderBySymbols.add(orderBySymbol);
                newReverseFlags.add(reverseFlags[i]);
                newNullsFirst.add(nullsFirst[i]);
            } else {
                if (newReverseFlags.get(idx) != reverseFlags[i]) {
                    throw new AmbiguousOrderByException(orderBySymbol);
                }//w w w.j a v a2 s .  co  m
                if (newNullsFirst.get(idx) != nullsFirst[i]) {
                    throw new AmbiguousOrderByException(orderBySymbol);
                }
            }
        }

        this.orderBySymbols = newOrderBySymbols;
        this.reverseFlags = Booleans.toArray(newReverseFlags);
        this.nullsFirst = newNullsFirst.toArray(new Boolean[0]);
    }
    return this;
}

From source file:org.apache.pig.newplan.logical.visitor.ProjectStarExpander.java

@Override
public void visit(LOForEach foreach) throws FrontendException {
    //in case of LOForeach , expand when inner plan has a single project-star
    // and its input LOInnerLoad also is a project-star
    // then Reset the input number in project expressions

    LogicalPlan innerPlan = foreach.getInnerPlan();

    //visit the inner plan first
    PlanWalker newWalker = currentWalker.spawnChildWalker(innerPlan);
    pushWalker(newWalker);/*  w w w .ja v a2 s. c o m*/
    currentWalker.walk(this);
    popWalker();

    //get the LOGenerate
    List<Operator> feOutputs = innerPlan.getSinks();
    LOGenerate gen = null;
    for (Operator op : feOutputs) {
        if (op instanceof LOGenerate) {
            if (gen != null) {
                String msg = "Expected single LOGenerate output in innerplan of foreach";
                throw new VisitorException(foreach, msg, 2266, PigException.BUG);
            }
            gen = (LOGenerate) op;
        }
    }

    //work on the generate plan, flatten and user schema
    List<LogicalExpressionPlan> expPlans = gen.getOutputPlans();
    List<LogicalExpressionPlan> newExpPlans = new ArrayList<LogicalExpressionPlan>();

    List<Operator> loGenPreds = innerPlan.getPredecessors(gen);

    if (loGenPreds == null) {
        // there are no LOInnerLoads , must be working on just constants
        // no project-star expansion to be done
        return;
    }

    List<LogicalSchema> userSchema = gen.getUserDefinedSchema();
    List<LogicalSchema> newUserSchema = null;
    if (userSchema != null) {
        newUserSchema = new ArrayList<LogicalSchema>();
    }

    boolean[] flattens = gen.getFlattenFlags();
    List<Boolean> newFlattens = new ArrayList<Boolean>(flattens.length);

    //get mapping of LOGenerate predecessor current position to object
    Map<Integer, LogicalRelationalOperator> oldPos2Rel = new HashMap<Integer, LogicalRelationalOperator>();

    for (int i = 0; i < loGenPreds.size(); i++) {
        oldPos2Rel.put(i, (LogicalRelationalOperator) loGenPreds.get(i));
    }

    //get schema of predecessor, project-star expansion needs a schema
    LogicalRelationalOperator pred = (LogicalRelationalOperator) foreach.getPlan().getPredecessors(foreach)
            .get(0);
    LogicalSchema inpSch = pred.getSchema();

    //store mapping between the projection in inner plans of
    // of LOGenerate to the input relation object
    Map<ProjectExpression, LogicalRelationalOperator> proj2InpRel = new HashMap<ProjectExpression, LogicalRelationalOperator>();

    for (int i = 0; i < expPlans.size(); i++) {
        LogicalExpressionPlan expPlan = expPlans.get(i);
        ProjectExpression projStar = getProjectLonelyStar(expPlan, oldPos2Rel);

        boolean foundExpandableProject = false;
        if (projStar != null) {
            //there is a project-star to be expanded

            LogicalSchema userStarSch = null;
            if (userSchema != null && userSchema.get(i) != null) {
                userStarSch = userSchema.get(i);
            }

            //the range values are set in the project in LOInnerLoad
            ProjectExpression loInnerProj = ((LOInnerLoad) oldPos2Rel.get(projStar.getInputNum()))
                    .getProjection();

            int firstProjCol = 0;
            int lastProjCol = 0;

            if (loInnerProj.isRangeProject()) {
                loInnerProj.setColumnNumberFromAlias();
                firstProjCol = loInnerProj.getStartCol();
                lastProjCol = loInnerProj.getEndCol();
            }

            boolean isProjectToEnd = loInnerProj.isProjectStar()
                    || (loInnerProj.isRangeProject() && lastProjCol == -1);

            //can't expand if there is no input schema, and this is
            // as project star or project-range-to-end
            if (!(inpSch == null && isProjectToEnd)) {

                foundExpandableProject = true;

                if (isProjectToEnd)
                    lastProjCol = inpSch.size() - 1;

                //replacing the existing project star with new ones
                expPlan.remove(projStar);

                //remove the LOInnerLoad with star
                LOInnerLoad oldLOInnerLoad = (LOInnerLoad) oldPos2Rel.get(projStar.getInputNum());
                innerPlan.disconnect(oldLOInnerLoad, gen);
                innerPlan.remove(oldLOInnerLoad);

                //generate new exp plan, inner load for each field in schema
                for (int j = firstProjCol; j <= lastProjCol; j++) {

                    //add new LOInnerLoad
                    LOInnerLoad newInLoad = new LOInnerLoad(innerPlan, foreach, j);
                    innerPlan.add(newInLoad);
                    innerPlan.connect(newInLoad, gen);

                    // new expression plan and proj
                    LogicalExpressionPlan newExpPlan = new LogicalExpressionPlan();
                    newExpPlans.add(newExpPlan);

                    ProjectExpression newProj = new ProjectExpression(newExpPlan, -2, -1, gen);

                    proj2InpRel.put(newProj, newInLoad);

                    newFlattens.add(flattens[i]);
                    if (newUserSchema != null) {
                        //index into user specified schema
                        int schIdx = j - firstProjCol;
                        if (userStarSch != null && userStarSch.getFields().size() > schIdx
                                && userStarSch.getField(schIdx) != null) {

                            //if the project-star field has user specified schema, use the
                            // j'th field for this column
                            LogicalSchema sch = new LogicalSchema();
                            sch.addField(new LogicalFieldSchema(userStarSch.getField(schIdx)));
                            newUserSchema.add(sch);
                        } else {
                            newUserSchema.add(null);
                        }
                    }
                }
            }
        }

        if (!foundExpandableProject) { //no project-star that could be expanded

            //get all projects in here 
            FindProjects findProjs = new FindProjects(expPlan);
            findProjs.visit();
            List<ProjectExpression> projs = findProjs.getProjs();

            //create a mapping of project expression to their inputs
            for (ProjectExpression proj : projs) {
                proj2InpRel.put(proj, oldPos2Rel.get(proj.getInputNum()));
            }

            newExpPlans.add(expPlan);

            newFlattens.add(flattens[i]);
            if (newUserSchema != null)
                newUserSchema.add(userSchema.get(i));

        }
    }

    //get mapping of LoGenerate input relation to current position
    Map<LogicalRelationalOperator, Integer> rel2pos = new HashMap<LogicalRelationalOperator, Integer>();
    List<Operator> newGenPreds = innerPlan.getPredecessors(gen);
    int numNewGenPreds = 0;
    if (newGenPreds != null)
        numNewGenPreds = newGenPreds.size();

    for (int i = 0; i < numNewGenPreds; i++) {
        rel2pos.put((LogicalRelationalOperator) newGenPreds.get(i), i);
    }

    //correct the input num for projects
    for (Entry<ProjectExpression, LogicalRelationalOperator> projAndInp : proj2InpRel.entrySet()) {
        ProjectExpression proj = projAndInp.getKey();
        LogicalRelationalOperator rel = projAndInp.getValue();
        proj.setInputNum(rel2pos.get(rel));
    }

    // set the new lists
    gen.setOutputPlans(newExpPlans);
    gen.setFlattenFlags(Booleans.toArray(newFlattens));
    gen.setUserDefinedSchema(newUserSchema);

    gen.resetSchema();
    foreach.resetSchema();

}

From source file:org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl.java

private Object toArrayOfType(final Iterable<?> iterable, final Class<?> componentType) {
    Collection<?> _xifexpression = null;
    if ((iterable instanceof Collection<?>)) {
        _xifexpression = ((Collection<?>) iterable);
    } else {/*from w w  w . j  a v a2  s. c  om*/
        _xifexpression = IterableExtensions.toList(iterable);
    }
    final Collection<?> collection = _xifexpression;
    Object _switchResult = null;
    boolean _matched = false;
    if (Objects.equal(componentType, int.class)) {
        _matched = true;
        _switchResult = Ints.toArray(((List<Integer>) collection));
    }
    if (!_matched) {
        if (Objects.equal(componentType, long.class)) {
            _matched = true;
            _switchResult = Longs.toArray(((List<Long>) collection));
        }
    }
    if (!_matched) {
        if (Objects.equal(componentType, char.class)) {
            _matched = true;
            _switchResult = Chars.toArray(((List<Character>) collection));
        }
    }
    if (!_matched) {
        if (Objects.equal(componentType, boolean.class)) {
            _matched = true;
            _switchResult = Booleans.toArray(((List<Boolean>) collection));
        }
    }
    if (!_matched) {
        if (Objects.equal(componentType, byte.class)) {
            _matched = true;
            _switchResult = Bytes.toArray(((List<Byte>) collection));
        }
    }
    if (!_matched) {
        if (Objects.equal(componentType, short.class)) {
            _matched = true;
            _switchResult = Shorts.toArray(((List<Short>) collection));
        }
    }
    if (!_matched) {
        if (Objects.equal(componentType, float.class)) {
            _matched = true;
            _switchResult = Floats.toArray(((List<Float>) collection));
        }
    }
    if (!_matched) {
        if (Objects.equal(componentType, double.class)) {
            _matched = true;
            _switchResult = Doubles.toArray(((List<Double>) collection));
        }
    }
    if (!_matched) {
        _switchResult = Iterables.<Object>toArray(collection, ((Class<Object>) componentType));
    }
    return _switchResult;
}