Example usage for java.util Arrays fill

List of usage examples for java.util Arrays fill

Introduction

In this page you can find the example usage for java.util Arrays fill.

Prototype

public static void fill(Object[] a, Object val) 

Source Link

Document

Assigns the specified Object reference to each element of the specified array of Objects.

Usage

From source file:au.org.ala.delta.intkey.WriteOnceIntkeyItemsFile.java

private int updateCharacterIndex(int charNumber) {
    int next = 0;
    if (_attributeIndex == null) {
        _attributeIndex = new int[_header.getNChar()];
        Arrays.fill(_attributeIndex, 0);
    }//from  w  w w .j  ava2s .  c om
    next = nextAvailableRecord();
    _attributeIndex[charNumber - 1] = next;

    return next;
}

From source file:me.ronghai.sa.dao.impl.AbstractModelDAOWithJDBCImpl.java

@Override
public E persistent(E entity) {
    if (delegate != null) {
        delegate.beforePersistent(entity);
    }/*from  w ww . j a  v a2  s. c om*/
    List<?>[] columnsAndValues = findColumnsAndValues(true, entity);
    @SuppressWarnings("unchecked")
    List<String> columnNames = columnsAndValues == null ? null : (List<String>) columnsAndValues[0];
    @SuppressWarnings("unchecked")
    List<Object> values = columnsAndValues == null ? null : (List<Object>) columnsAndValues[1];

    logger.log(Level.INFO, "values\n{0}", values);

    if (columnNames != null && !columnNames.isEmpty()) {
        String[] ph = new String[columnNames.size()];
        Arrays.fill(ph, "?");
        final String sql = " INSERT INTO " + table(entityClass) + "( "
                + org.apache.commons.lang.StringUtils.join(columnNames, " , ") + " ) VALUES ( "
                + org.apache.commons.lang.StringUtils.join(ph, " , ") + ")";
        this.databaseHandler.update(sql, values.toArray());

        E ne = this.find(" ORDER BY ID DESC LIMIT 1 ").get(0);
        entity.setId(ne.getId());
        return ne;
    }
    if (delegate != null) {
        delegate.afterPersistent(entity);
    }
    return entity;

}

From source file:edu.byu.nlp.util.Matrices.java

public static void fill(double[][] matrix, double x) {
    for (double[] row : matrix) {
        Arrays.fill(row, x);
    }/*  www  .jav a  2s . co m*/
}

From source file:msi.gama.util.matrix.GamaFloatMatrix.java

@Override
protected void _clear() {
    Arrays.fill(getMatrix(), 0d);
}

From source file:clus.statistic.ClassificationStat.java

/**
 * Used for combining weighted predictions.
 *///from  w  ww.j  a v  a 2 s.c  o m
public ClassificationStat normalizedCopy() {
    ClassificationStat copy = (ClassificationStat) cloneStat();
    copy.copy(this);
    for (int i = 0; i < m_NbTarget; i++) {
        for (int j = 0; j < m_ClassCounts[i].length; j++) {
            copy.m_ClassCounts[i][j] /= m_SumWeights[i];
        }
    }
    Arrays.fill(copy.m_SumWeights, 1.0);
    copy.m_SumWeight = 1.0;
    return copy;
}

From source file:com.yahoo.semsearch.fastlinking.DPSearch.java

/**
 * Run forward-backward algorithm on multiple entity candidates and returns a filtered list of coherent entities
 * Takes nbest list and/*  w  ww  .  ja va  2 s. c  om*/
 * @param nBestList an array of arraylists of wiki entities; for each entity span we have a list of candidate
 *                       wikilinks (nbest list)
 * @param entitySurfaceForms an array of entity spans
 * @return DPSearch object that contains lattice of paths and likelihood scores
 */
public DPSearch dynamicProgrammingSearch(List<String>[] nBestList, String[] entitySurfaceForms) {

    int sequenceLength = entitySurfaceForms.length;
    int nBestLength = MAXNBEST;
    double[][] logSimilarityOverall = new double[sequenceLength][nBestLength];
    for (int i = 0; i < logSimilarityOverall.length; i++) {
        Arrays.fill(logSimilarityOverall[i], DEFAULT_LOG_LIKELIHOOD);
    }
    String[][] path = new String[sequenceLength][nBestLength];
    for (int i = 0; i < path.length; i++) {
        Arrays.fill(path[i], "");
    }
    ListIterator<String> it = nBestList[0].listIterator();
    while (it.hasNext()) {
        //MAKE SURE to call NextIndex before Next

        int index = it.nextIndex();
        String currentCandidate = it.next();

        double entity2WordSim = gensimEntityEmbeddings.entity2WordSimilarity(prependWiki(currentCandidate),
                entitySurfaceForms[0].replace(" ", "_"));
        double lexicalSim = gensimEntityEmbeddings.lexicalSimilarity(currentCandidate.replace("_", " "),
                entitySurfaceForms[0]);

        logSimilarityOverall[0][index] = Math.max(
                Math.log((1 - LEXSIM_LAMBDA) * entity2WordSim + LEXSIM_LAMBDA * lexicalSim),
                DEFAULT_LOG_LIKELIHOOD);

        path[0][index] = currentCandidate;
    }

    ListIterator<String> currentCandidateIterator, previousCandidateIterator;
    for (int i = 1; i < sequenceLength; i++) {
        currentCandidateIterator = nBestList[i].listIterator();

        while (currentCandidateIterator.hasNext()) {

            //MAKE SURE to call NextIndex before Next
            int currentCandidateIndex = currentCandidateIterator.nextIndex();
            String currentCandidate = currentCandidateIterator.next();

            double entity2WordSim = gensimEntityEmbeddings.entity2WordSimilarity(prependWiki(currentCandidate),
                    entitySurfaceForms[i].replace(" ", "_"));
            double lexicalSim = gensimEntityEmbeddings.lexicalSimilarity(currentCandidate.replace("_", " "),
                    entitySurfaceForms[i]);

            double candidateNBestSimilarity = Math
                    .log((1 - LEXSIM_LAMBDA) * entity2WordSim + LEXSIM_LAMBDA * lexicalSim);

            double bestSimilarity = 0.0;
            double interCandidateSimilarity = 0.0;
            int previousBestCandidateIndex = -1;
            previousCandidateIterator = nBestList[i - 1].listIterator();
            while (previousCandidateIterator.hasNext()) {

                //MAKE SURE to call NextIndex before Next

                int index = previousCandidateIterator.nextIndex();
                String previousCandidate = previousCandidateIterator.next();

                double entity2EntitySimilarity = gensimEntityEmbeddings
                        .entity2EntitySimilarity(prependWiki(previousCandidate), prependWiki(currentCandidate));

                double entity2EntityLexicalSimilarity = gensimEntityEmbeddings.lexicalSimilarity(
                        previousCandidate.replace("_", " "), currentCandidate.replace("_", " "));

                double jointSimilarity = (1 - LEXSIM_LAMBDA) * entity2EntitySimilarity
                        + LEXSIM_LAMBDA * entity2EntityLexicalSimilarity;
                interCandidateSimilarity = Math.log(jointSimilarity);

                if (bestSimilarity == 0.0) {
                    bestSimilarity = interCandidateSimilarity + logSimilarityOverall[i - 1][index];
                    previousBestCandidateIndex = index;

                } else if (interCandidateSimilarity + logSimilarityOverall[i - 1][index] > bestSimilarity) {
                    bestSimilarity = interCandidateSimilarity + logSimilarityOverall[i - 1][index];
                    previousBestCandidateIndex = index;

                }
            }
            try {
                logSimilarityOverall[i][currentCandidateIndex] = Math
                        .max(bestSimilarity + candidateNBestSimilarity, DEFAULT_LOG_LIKELIHOOD);

                path[i][currentCandidateIndex] = path[i - 1][previousBestCandidateIndex] + CANDIDATE_DELIMITER
                        + currentCandidate;

            } catch (ArrayIndexOutOfBoundsException e) {
                e.getMessage();
            }
        }

    }
    RealVector realVector = new ArrayRealVector(logSimilarityOverall[sequenceLength - 1]);
    int bestPathIndex = realVector.getMaxIndex();

    DPSearch dpSearch = new DPSearch(logSimilarityOverall, path);
    return dpSearch;
}

From source file:cz.paulrz.montecarlo.random.ParallelPercentile.java

/** {@inheritDoc} */
@Override// w  ww.  j  a  v  a2 s.  co m
public void setData(final double[] values) {
    if (values == null) {
        cachedPivots = null;
    } else {
        cachedPivots = new int[(0x1 << MAX_CACHED_LEVELS) - 1];
        Arrays.fill(cachedPivots, -1);
    }
    super.setData(values);
}

From source file:de.tudarmstadt.ukp.dkpro.argumentation.io.writer.json.JCasTextSpanAnnotationGraphFactory.java

@Override
public SpanAnnotationGraph<SpanTextLabel> apply(final JCas jCas) {
    final ReverseLookupOrderedSet<SpanTextLabel> spanAnnotationVector;
    final Sparse3DObjectMatrix<String, SpanTextLabel> spanAnnotationMatrix;
    {//  www. j a  v  a 2s. c  o  m
        final Collection<ArgumentComponent> argumentComponents = JCasUtil.select(jCas, ArgumentComponent.class);

        {
            final int argumentComponentCount = argumentComponents.size();
            LOG.info(String.format("Processing %d argument components.", argumentComponentCount));
            // The list of all annotations, their index in the list serving
            // as
            // their
            // ID
            spanAnnotationVector = new ReverseLookupOrderedSet<>(
                    new ArrayList<SpanTextLabel>(argumentComponentCount));
            // Just use the size "argumentComponentCount" directly here
            // because
            // it
            // is assumed that spans
            // don't overlap
            spanAnnotationMatrix = new Sparse3DObjectMatrix<>(
                    new Int2ObjectOpenHashMap<>(argumentComponentCount + 1),
                    ESTIMATED_SPAN_BEGIN_TO_END_MAP_MAX_CAPACITY, ESTIMATED_ANNOTATION_MAP_MAX_CAPACITY);
        }

        for (final ArgumentComponent argumentComponent : argumentComponents) {
            final SpanTextLabel spanAnnotation = SpanTextAnnotationFactory.getInstance()
                    .apply(argumentComponent);
            final Span span = spanAnnotation.getSpanText().getSpan();
            final int begin = span.getBegin();
            final int end = span.getEnd();
            final String label = spanAnnotation.getLabel();
            final Map<String, SpanTextLabel> spanAnnotations = spanAnnotationMatrix.fetch3DMap(begin, end);
            final SpanTextLabel oldSpanAnnotation = spanAnnotations.put(label, spanAnnotation);
            if (oldSpanAnnotation != null) {
                LOG.warn(String.format("Annotation label \"%s\" already exists for span [%d, %d]; Overwriting.",
                        label, begin, end));
            }
            spanAnnotationVector.add(spanAnnotation);
        }
    }

    final Collection<ArgumentRelation> argumentRelations = JCasUtil.select(jCas, ArgumentRelation.class);
    final Object2IntMap<SpanTextLabel> spanAnnotationIds = spanAnnotationVector.getReverseLookupMap();
    LOG.info(String.format("Processing %d argument relations.", argumentRelations.size()));

    final int initialTableRelationValue = -1;
    final Supplier<int[]> transitionTableArraySupplier = () -> {
        final int[] result = new int[spanAnnotationIds.size()];
        // Pre-fill the array in the case that there is no transition for a
        // given annotation
        Arrays.fill(result, initialTableRelationValue);
        return result;
    };
    final ArgumentTransitionTableCollector argTransitionTableCollector = new ArgumentTransitionTableCollector(
            transitionTableArraySupplier, initialTableRelationValue,
            annot -> getAnnotationId(annot, spanAnnotationMatrix, spanAnnotationIds));

    final Stream<ArgumentRelation> argumentRelationStream = argumentRelations.stream().map(argumentRelation -> {
        final ArgumentUnit source = argumentRelation.getSource();
        final Map<Attribute, Object> sourceAnnotAttrs = getSpanTextLabel(source, spanAnnotationMatrix)
                .getAttributes();
        // If the source annotation doesn't have its own category already set, set it to
        // the type label of the relation between it and its target
        sourceAnnotAttrs.putIfAbsent(Attribute.CATEGORY, argumentRelation.getType().getShortName());
        return argumentRelation;
    });
    final int[] argumentTransitionTable = argumentRelationStream.collect(argTransitionTableCollector);

    return new SpanAnnotationGraph<>(spanAnnotationVector, argumentTransitionTable);
}

From source file:kr.co.bitnine.octopus.engine.QueryEngine.java

@Override
protected CachedQuery processParse(String queryString, PostgresType[] paramTypes) throws PostgresException {
    /*//from  w w w.  j  ava  2s.c  o  m
     * Format of PostgreSQL's parameter is $n (starts from 1)
     * Format of Calcite's parameter is ? (same as JDBC)
     */
    String refinedQuery = queryString.replaceAll("\\$\\d+", "?");
    LOG.debug("refined queryString='" + refinedQuery + "'");

    // DDL

    List<OctopusSqlCommand> commands = null;
    try {
        commands = OctopusSql.parse(refinedQuery);
    } catch (RecognitionException e) {
        LOG.debug(ExceptionUtils.getStackTrace(e));
    }

    if (commands != null && commands.size() > 0) {
        TupleDesc tupDesc;
        switch (commands.get(0).getType()) {
        case SHOW_TX_ISOLATION_LEVEL:
            PostgresAttribute[] attrs = new PostgresAttribute[] {
                    new PostgresAttribute("transaction_isolation", PostgresType.VARCHAR, 32), };
            FormatCode[] resultFormats = new FormatCode[attrs.length];
            Arrays.fill(resultFormats, FormatCode.TEXT);
            tupDesc = new TupleDesc(attrs, resultFormats);
            break;
        case SHOW_DATASOURCES:
            attrs = new PostgresAttribute[] { new PostgresAttribute("TABLE_CAT", PostgresType.VARCHAR, 128),
                    new PostgresAttribute("REMARKS", PostgresType.VARCHAR, 1024) };
            resultFormats = new FormatCode[attrs.length];
            Arrays.fill(resultFormats, FormatCode.TEXT);
            tupDesc = new TupleDesc(attrs, resultFormats);
            break;
        case SHOW_SCHEMAS:
            attrs = new PostgresAttribute[] { new PostgresAttribute("TABLE_SCHEM", PostgresType.VARCHAR, 128),
                    new PostgresAttribute("TABLE_CATALOG", PostgresType.VARCHAR, 128),
                    new PostgresAttribute("REMARKS", PostgresType.VARCHAR, 1024),
                    new PostgresAttribute("TABLE_CAT_REMARKS", PostgresType.VARCHAR, 1024) };
            resultFormats = new FormatCode[attrs.length];
            Arrays.fill(resultFormats, FormatCode.TEXT);
            tupDesc = new TupleDesc(attrs, resultFormats);
            break;
        case SHOW_TABLES:
            attrs = new PostgresAttribute[] { new PostgresAttribute("TABLE_CAT", PostgresType.VARCHAR, 128),
                    new PostgresAttribute("TABLE_SCHEM", PostgresType.VARCHAR, 128),
                    new PostgresAttribute("TABLE_NAME", PostgresType.VARCHAR, 128),
                    new PostgresAttribute("TABLE_TYPE", PostgresType.VARCHAR, 16),
                    new PostgresAttribute("REMARKS", PostgresType.VARCHAR, 1024),
                    new PostgresAttribute("TYPE_CAT", PostgresType.VARCHAR, 16),
                    new PostgresAttribute("TYPE_SCHEM", PostgresType.VARCHAR, 16),
                    new PostgresAttribute("TYPE_NAME", PostgresType.VARCHAR, 16),
                    new PostgresAttribute("SELF_REFERENCING_COL_NAME", PostgresType.VARCHAR, 16),
                    new PostgresAttribute("REF_GENERATION", PostgresType.VARCHAR, 16),
                    new PostgresAttribute("TABLE_CAT_REMARKS", PostgresType.VARCHAR, 1024),
                    new PostgresAttribute("TABLE_SCHEM_REMARKS", PostgresType.VARCHAR, 1024) };
            resultFormats = new FormatCode[attrs.length];
            Arrays.fill(resultFormats, FormatCode.TEXT);
            tupDesc = new TupleDesc(attrs, resultFormats);
            break;
        case SHOW_COLUMNS:
            attrs = new PostgresAttribute[] { new PostgresAttribute("TABLE_CAT", PostgresType.VARCHAR, 128),
                    new PostgresAttribute("TABLE_SCHEM", PostgresType.VARCHAR, 128),
                    new PostgresAttribute("TABLE_NAME", PostgresType.VARCHAR, 128),
                    new PostgresAttribute("COLUMN_NAME", PostgresType.VARCHAR, 128),
                    new PostgresAttribute("DATA_TYPE", PostgresType.VARCHAR, 16),
                    new PostgresAttribute("TYPE_NAME", PostgresType.VARCHAR, 16),
                    new PostgresAttribute("COLUMN_SIZE", PostgresType.VARCHAR, 16),
                    new PostgresAttribute("BUFFER_LENGTH", PostgresType.VARCHAR, 16),
                    new PostgresAttribute("DECIMAL_DIGITS", PostgresType.VARCHAR, 16),
                    new PostgresAttribute("NUM_PREC_RADIX", PostgresType.VARCHAR, 16),
                    new PostgresAttribute("NULLABLE", PostgresType.VARCHAR, 16),
                    new PostgresAttribute("REMARKS", PostgresType.VARCHAR, 1024),
                    new PostgresAttribute("COLUMN_DEF", PostgresType.VARCHAR, 16),
                    new PostgresAttribute("SQL_DATA_TYPE", PostgresType.VARCHAR, 16),
                    new PostgresAttribute("SQL_DATETIME_SUB", PostgresType.VARCHAR, 16),
                    new PostgresAttribute("CHAR_OCTET_LENGTH", PostgresType.VARCHAR, 16),
                    new PostgresAttribute("ORDINAL_POSITION", PostgresType.VARCHAR, 16),
                    new PostgresAttribute("IS_NULLABLE", PostgresType.VARCHAR, 16),
                    new PostgresAttribute("SCOPE_CATALOG", PostgresType.VARCHAR, 16),
                    new PostgresAttribute("SCOPE_SCHEMA", PostgresType.VARCHAR, 16),
                    new PostgresAttribute("SCOPE_TABLE", PostgresType.VARCHAR, 16),
                    new PostgresAttribute("SOURCE_DATA_TYPE", PostgresType.VARCHAR, 16),
                    new PostgresAttribute("IS_AUTOINCREMENT", PostgresType.VARCHAR, 16),
                    new PostgresAttribute("IS_GENERATEDCOLUMN", PostgresType.VARCHAR, 16),
                    new PostgresAttribute("DATA_CATEGORY", PostgresType.VARCHAR, 64),
                    new PostgresAttribute("TABLE_CAT_REMARKS", PostgresType.VARCHAR, 1024),
                    new PostgresAttribute("TABLE_SCHEM_REMARKS", PostgresType.VARCHAR, 1024),
                    new PostgresAttribute("TABLE_NAME_REMARKS", PostgresType.VARCHAR, 1024) };
            resultFormats = new FormatCode[attrs.length];
            Arrays.fill(resultFormats, FormatCode.TEXT);
            tupDesc = new TupleDesc(attrs, resultFormats);
            break;
        case SHOW_ALL_USERS:
            attrs = new PostgresAttribute[] { new PostgresAttribute("USER_NAME", PostgresType.VARCHAR, 128),
                    new PostgresAttribute("REMARKS", PostgresType.VARCHAR, 1024) };
            resultFormats = new FormatCode[attrs.length];
            Arrays.fill(resultFormats, FormatCode.TEXT);
            tupDesc = new TupleDesc(attrs, resultFormats);
            break;
        case SHOW_OBJ_PRIVS_FOR:
            attrs = new PostgresAttribute[] { new PostgresAttribute("TABLE_CAT", PostgresType.VARCHAR, 128),
                    new PostgresAttribute("TABLE_SCHEM", PostgresType.VARCHAR, 128),
                    new PostgresAttribute("PRIVILEGE", PostgresType.VARCHAR, 16) };
            resultFormats = new FormatCode[attrs.length];
            Arrays.fill(resultFormats, FormatCode.TEXT);
            tupDesc = new TupleDesc(attrs, resultFormats);
            break;
        case SHOW_COMMENTS:
            attrs = new PostgresAttribute[] { new PostgresAttribute("OBJECT_TYPE", PostgresType.VARCHAR, 8),
                    new PostgresAttribute("TABLE_CAT", PostgresType.VARCHAR, 128),
                    new PostgresAttribute("TABLE_SCHEM", PostgresType.VARCHAR, 128),
                    new PostgresAttribute("TABLE_NAME", PostgresType.VARCHAR, 128),
                    new PostgresAttribute("COLUMN_NAME", PostgresType.VARCHAR, 128),
                    new PostgresAttribute("TABLE_CAT_REMARKS", PostgresType.VARCHAR, 1024),
                    new PostgresAttribute("TABLE_SCHEM_REMARKS", PostgresType.VARCHAR, 1024),
                    new PostgresAttribute("TABLE_NAME_REMARKS", PostgresType.VARCHAR, 1024),
                    new PostgresAttribute("COLUMN_NAME_REMARKS", PostgresType.VARCHAR, 1024) };
            resultFormats = new FormatCode[attrs.length];
            Arrays.fill(resultFormats, FormatCode.TEXT);
            tupDesc = new TupleDesc(attrs, resultFormats);
            break;
        default:
            tupDesc = null;
        }
        return new CachedStatement(commands, tupDesc);
    }

    // Query

    try {
        SchemaPlus rootSchema = schemaManager.getCurrentSchema();

        SqlParser.Config parserConf = SqlParser.configBuilder().setUnquotedCasing(Casing.TO_LOWER).build();
        FrameworkConfig config = Frameworks.newConfigBuilder().defaultSchema(rootSchema)
                .parserConfig(parserConf).build();
        Planner planner = Frameworks.getPlanner(config);

        SqlNode parse = planner.parse(refinedQuery);

        TableNameTranslator.toFQN(schemaManager, parse);
        LOG.debug("FQN translated: " + parse.toString());

        schemaManager.lockRead();
        try {
            SqlNode validated = planner.validate(parse);
            RelRoot relRoot = planner.rel(validated);
            LOG.info(RelOptUtil.dumpPlan("Generated plan: ", relRoot.rel, false,
                    SqlExplainLevel.ALL_ATTRIBUTES));
            return new CachedStatement(validated, refinedQuery, paramTypes);
        } finally {
            schemaManager.unlockRead();
        }
    } catch (SqlParseException e) {
        PostgresErrorData edata = new PostgresErrorData(PostgresSeverity.ERROR, PostgresSQLState.SYNTAX_ERROR,
                "syntax error " + e.getMessage());
        throw new PostgresException(edata, e);
    } catch (ValidationException e) {
        LOG.info(ExceptionUtils.getStackTrace(e));
        PostgresErrorData edata = new PostgresErrorData(PostgresSeverity.ERROR,
                "validation failed. " + e.toString());
        throw new PostgresException(edata, e);
    } catch (RelConversionException e) {
        LOG.debug(ExceptionUtils.getStackTrace(e));
        PostgresErrorData edata = new PostgresErrorData(PostgresSeverity.ERROR, "plan generation failed");
        throw new PostgresException(edata, e);
    }
}

From source file:com.hmsoft.libcommon.gopro.GoProController.java

public byte[] getRawStatus() {
    byte[] response = execCameraCommand("se", null);
    if (response == RESPONSE_NOT_FOUND) {
        response = new byte[GoProStatus.RAW_STATUS_LEN];
        Arrays.fill(response, GoProStatus.UNKNOW);
        response[GoProStatus.Fields.CAMERA_MODE_FIELD] = GoProStatus.CAMERA_MODE_OFF_WIFION;
    }/*from www. j  a va 2  s .c  o  m*/
    GoProStatus.LastCameraStatus = response;
    return response;
}