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:edu.harvard.med.screensaver.ui.arch.util.JSFUtils.java

/**
 * Output the hierarchical structure of a JSF component with nested children.
 */// ww  w.jav a2  s  .  c om
private void logComponentStructure(UIComponent component, int level) {
    char[] indent = new char[level];
    Arrays.fill(indent, ' ');
    log.debug(new String(indent) + component.getClass() + ": " + component.getId());
    for (Iterator iter = component.getChildren().iterator(); iter.hasNext();) {
        UIComponent child = (UIComponent) iter.next();
        logComponentStructure(child, level + 1);
    }
}

From source file:edu.cmu.cs.lti.ark.fn.identification.latentmodel.TrainBatchModelDerThreaded.java

public void trainModel() throws Exception {
    // minimum verbosity
    int[] iprint = new int[] { Lbfgs.DEBUG ? 1 : -1, 0 };
    // lbfgs sets this flag to zero when it has converged
    int[] iflag = new int[] { 0 };
    tGradients = new double[numThreads][modelSize]; // gradients for each batch/thread
    gradients = new double[modelSize]; // gradients of all threads added together
    tValues = new double[numThreads];
    int iteration = 0;
    do {/* w ww  . ja  va  2 s.co m*/
        logger.info("Starting iteration:" + iteration);
        Arrays.fill(gradients, 0.0);
        double m_value = getValuesAndGradients();
        logger.info("Function value:" + m_value);
        riso.numerical.LBFGS.lbfgs(modelSize, Lbfgs.NUM_CORRECTIONS, params, m_value, gradients, false,
                new double[modelSize], iprint, Lbfgs.STOPPING_THRESHOLD, Lbfgs.XTOL, iflag);
        logger.info("Finished iteration:" + iteration);
        iteration++;
        if (iteration % Lbfgs.SAVE_EVERY_K == 0) {
            saveModel(params, modelFile + "_" + iteration);
        }
    } while (iteration <= Lbfgs.MAX_ITERATIONS && iflag[0] != 0);
    saveModel(params, modelFile);
}

From source file:it.flavianopetrocchi.jpdfbookmarks.JPdfBookmarks.java

private byte[] askUserPassword() {
    //avoid the use of strings when dealing with passwords they remain in memomory
    Console cons;/*from w  w  w.  ja v  a  2  s.c o  m*/
    char[] passwdChars = null;
    byte[] passwdBytes = null;
    if ((cons = System.console()) != null
            && (passwdChars = cons.readPassword("[%s:]", Res.getString("PASSWORD"))) != null) {
        passwdBytes = Ut.arrayOfCharsToArrayOfBytes(passwdChars);
        Arrays.fill(passwdChars, ' ');
    } else {
        out.print("[" + Res.getString("LABEL_PASSWORD") + "]");
        out.flush();
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        passwdChars = new char[MAX_PASSWORD_LEN];
        try {
            int charsRead = in.read(passwdChars, 0, MAX_PASSWORD_LEN);
            //remove \r and \n from the password
            for (int i = charsRead - 1; i >= 0; i--) {
                if (passwdChars[i] == '\r' || passwdChars[i] == '\n') {
                    charsRead--;
                } else {
                    break;
                }
            }
            char[] trimmedPasswd = Arrays.copyOf(passwdChars, charsRead);
            Arrays.fill(passwdChars, ' ');
            passwdBytes = Ut.arrayOfCharsToArrayOfBytes(trimmedPasswd);
            Arrays.fill(trimmedPasswd, ' ');
        } catch (IOException ex) {
        }
    }
    return passwdBytes;
}

From source file:ch.unine.vauchers.fuseerasure.codes.ReedSolomonCode.java

public void decodeBulk(byte[][] readBufs, byte[][] writeBufs, int[] erasedLocation) {
    if (erasedLocation.length == 0) {
        return;/*  www  .j  a  v a  2s .c  om*/
    }

    // cleanup the write buffer
    for (int i = 0; i < writeBufs.length; i++) {
        Arrays.fill(writeBufs[i], (byte) 0);
    }

    for (int i = 0; i < erasedLocation.length; i++) {
        errSignature[i] = primitivePower[erasedLocation[i]];
        GF.substitute(readBufs, writeBufs[i], primitivePower[i]);
    }
    GF.solveVandermondeSystem(errSignature, writeBufs, erasedLocation.length, readBufs[0].length);
}

From source file:org.geowebcache.layer.MetaTile.java

/***
 * Calculates final meta tile width, height and bounding box
 * <p>/*from  w  ww  .j  a v  a  2  s  .c o m*/
 * Adding a gutter should be really easy, just add to all sides, right ?
 * 
 * But GeoServer / GeoTools, and possibly other WMS servers, can get mad if we exceed 180,90 (or
 * the equivalent for other projections), so we'lll treat those with special care.
 * </p>
 * 
 * @param strBuilder
 * @param metaTileGridBounds
 */
protected void calculateEdgeGutter() {

    Arrays.fill(this.gutter, 0);

    long[] layerCov = gridSubset.getCoverage((int) this.metaGridCov[4]);

    this.metaBbox = gridSubset.boundsFromRectangle(metaGridCov);

    this.metaTileWidth = metaX * gridSubset.getTileWidth();
    this.metaTileHeight = metaY * gridSubset.getTileHeight();

    double widthRelDelta = ((1.0 * metaTileWidth + gutterConfig) / metaTileWidth) - 1.0;
    double heightRelDelta = ((1.0 * metaTileHeight + gutterConfig) / metaTileHeight) - 1.0;

    double coordWidth = metaBbox.getWidth();
    double coordHeight = metaBbox.getHeight();

    double coordWidthDelta = coordWidth * widthRelDelta;
    double coordHeightDelta = coordHeight * heightRelDelta;

    if (layerCov[0] < metaGridCov[0]) {
        metaTileWidth += gutterConfig;
        gutter[0] = gutterConfig;
        metaBbox.setMinX(metaBbox.getMinX() - coordWidthDelta);
    }
    if (layerCov[1] < metaGridCov[1]) {
        metaTileHeight += gutterConfig;
        gutter[1] = gutterConfig;
        metaBbox.setMinY(metaBbox.getMinY() - coordHeightDelta);
    }
    if (layerCov[2] > metaGridCov[2]) {
        metaTileWidth += gutterConfig;
        gutter[2] = gutterConfig;
        metaBbox.setMaxX(metaBbox.getMaxX() + coordWidthDelta);
    }
    if (layerCov[3] > metaGridCov[3]) {
        metaTileHeight += gutterConfig;
        gutter[3] = gutterConfig;
        metaBbox.setMaxY(metaBbox.getMaxY() + coordHeightDelta);
    }
}

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

@Override
public void _clear() {
    Arrays.fill(matrix, 0);
}

From source file:com.analog.lyric.dimple.solvers.core.parameterizedMessages.DirichletParameters.java

public final void fillAlphaMinusOne(double alphaMinusOne) {
    Arrays.fill(_alphaMinusOne, alphaMinusOne); // Replicate a single value into all entries
    forgetNormalizationEnergy();//from   w  w  w.  j  av  a 2  s .  com
    _symmetric = 1;
}

From source file:com.ebay.nest.io.sede.lazy.LazyStruct.java

/**
 * Parse the byte[] and fill each field.
 *///from w  ww .  j  ava  2 s  . c om
private void parse() {

    byte separator = oi.getSeparator();
    boolean lastColumnTakesRest = oi.getLastColumnTakesRest();
    boolean isEscaped = oi.isEscaped();
    byte escapeChar = oi.getEscapeChar();

    if (fields == null) {
        List<? extends StructField> fieldRefs = ((StructObjectInspector) oi).getAllStructFieldRefs();
        fields = new LazyObject[fieldRefs.size()];
        for (int i = 0; i < fields.length; i++) {
            fields[i] = LazyFactory.createLazyObject(fieldRefs.get(i).getFieldObjectInspector());
        }
        fieldInited = new boolean[fields.length];
        // Extra element to make sure we have the same formula to compute the
        // length of each element of the array.
        startPosition = new int[fields.length + 1];
    }

    int structByteEnd = start + length;
    int fieldId = 0;
    int fieldByteBegin = start;
    int fieldByteEnd = start;
    byte[] bytes = this.bytes.getData();

    // Go through all bytes in the byte[]
    while (fieldByteEnd <= structByteEnd) {
        if (fieldByteEnd == structByteEnd || bytes[fieldByteEnd] == separator) {
            // Reached the end of a field?
            if (lastColumnTakesRest && fieldId == fields.length - 1) {
                fieldByteEnd = structByteEnd;
            }
            startPosition[fieldId] = fieldByteBegin;
            fieldId++;
            if (fieldId == fields.length || fieldByteEnd == structByteEnd) {
                // All fields have been parsed, or bytes have been parsed.
                // We need to set the startPosition of fields.length to ensure we
                // can use the same formula to calculate the length of each field.
                // For missing fields, their starting positions will all be the same,
                // which will make their lengths to be -1 and uncheckedGetField will
                // return these fields as NULLs.
                for (int i = fieldId; i <= fields.length; i++) {
                    startPosition[i] = fieldByteEnd + 1;
                }
                break;
            }
            fieldByteBegin = fieldByteEnd + 1;
            fieldByteEnd++;
        } else {
            if (isEscaped && bytes[fieldByteEnd] == escapeChar && fieldByteEnd + 1 < structByteEnd) {
                // ignore the char after escape_char
                fieldByteEnd += 2;
            } else {
                fieldByteEnd++;
            }
        }
    }

    // Extra bytes at the end?
    if (!extraFieldWarned && fieldByteEnd < structByteEnd) {
        extraFieldWarned = true;
        LOG.warn("Extra bytes detected at the end of the row! Ignoring similar " + "problems.");
    }

    // Missing fields?
    if (!missingFieldWarned && fieldId < fields.length) {
        missingFieldWarned = true;
        LOG.info("Missing fields! Expected " + fields.length + " fields but " + "only got " + fieldId
                + "! Ignoring similar problems.");
    }

    Arrays.fill(fieldInited, false);
    parsed = true;
}

From source file:dr.evomodel.epidemiology.casetocase.CaseToCaseTreeLikelihood.java

public CaseToCaseTreeLikelihood(String name, PartitionedTreeModel tree, AbstractOutbreak caseData,
        Parameter maxFirstInfToRoot) {

    super(name, caseData, tree);

    if (stateCount != treeModel.getExternalNodeCount()) {
        throw new RuntimeException("There are duplicate tip outbreak.");
    }//from w  w  w  .  j a  v a 2s.  com

    noTips = tree.getExternalNodeCount();

    //subclasses should add outbreak as a model if it contains any information that ever changes

    outbreak = caseData;

    noCases = outbreak.getCases().size();

    addModel(outbreak);

    estimatedLastSampleTime = getLatestTaxonTime();

    //map outbreak to tips

    addModel(tree.getBranchMap());

    hasLatentPeriods = outbreak.hasLatentPeriods();

    infectionTimes = new double[outbreak.size()];
    infectiousPeriods = new double[outbreak.size()];

    if (hasLatentPeriods) {
        infectiousTimes = new double[outbreak.size()];
        latentPeriods = new double[outbreak.size()];
    }

    recalculateCaseFlags = new boolean[outbreak.size()];
    Arrays.fill(recalculateCaseFlags, true);

    this.maxFirstInfToRoot = maxFirstInfToRoot;

    treeTraits.addTrait(PARTITIONS_KEY, new TreeTrait.S() {
        public String getTraitName() {
            return PARTITIONS_KEY;
        }

        public Intent getIntent() {
            return Intent.NODE;
        }

        public String getTrait(Tree tree, NodeRef node) {
            return getNodePartition(tree, node);
        }
    });

    if (DEBUG) {
        treeTraits.addTrait("NodeNumber", new TreeTrait.S() {
            public String getTraitName() {
                return "NodeNumber";
            }

            public Intent getIntent() {
                return Intent.NODE;
            }

            public String getTrait(Tree tree, NodeRef node) {
                return Integer.toString(node.getNumber());
            }
        });
    }

    likelihoodKnown = false;
}

From source file:com.ebay.nest.io.sede.lazybinary.LazyBinaryStruct.java

/**
 * Parse the byte[] and fill fieldStart, fieldLength, fieldInited and
 * fieldIsNull.//  w w w .  j a  v a 2  s .  com
 */
private void parse() {

    List<? extends StructField> fieldRefs = ((StructObjectInspector) oi).getAllStructFieldRefs();

    if (fields == null) {
        fields = new LazyBinaryObject[fieldRefs.size()];
        for (int i = 0; i < fields.length; i++) {
            ObjectInspector insp = fieldRefs.get(i).getFieldObjectInspector();
            fields[i] = insp == null ? null : LazyBinaryFactory.createLazyBinaryObject(insp);
        }
        fieldInited = new boolean[fields.length];
        fieldIsNull = new boolean[fields.length];
        fieldStart = new int[fields.length];
        fieldLength = new int[fields.length];
    }

    /**
     * Please note that one null byte is followed by eight fields, then more
     * null byte and fields.
     */

    int fieldId = 0;
    int structByteEnd = start + length;
    byte[] bytes = this.bytes.getData();

    byte nullByte = bytes[start];
    int lastFieldByteEnd = start + 1;
    // Go through all bytes in the byte[]
    for (int i = 0; i < fields.length; i++) {
        fieldIsNull[i] = true;
        if ((nullByte & (1 << (i % 8))) != 0) {
            fieldIsNull[i] = false;
            LazyBinaryUtils.checkObjectByteInfo(fieldRefs.get(i).getFieldObjectInspector(), bytes,
                    lastFieldByteEnd, recordInfo);
            fieldStart[i] = lastFieldByteEnd + recordInfo.elementOffset;
            fieldLength[i] = recordInfo.elementSize;
            lastFieldByteEnd = fieldStart[i] + fieldLength[i];
        }

        // count how many fields are there
        if (lastFieldByteEnd <= structByteEnd) {
            fieldId++;
        }
        // next byte is a null byte if there are more bytes to go
        if (7 == (i % 8)) {
            if (lastFieldByteEnd < structByteEnd) {
                nullByte = bytes[lastFieldByteEnd];
                lastFieldByteEnd++;
            } else {
                // otherwise all null afterwards
                nullByte = 0;
                lastFieldByteEnd++;
            }
        }
    }

    // Extra bytes at the end?
    if (!extraFieldWarned && lastFieldByteEnd < structByteEnd) {
        extraFieldWarned = true;
        LOG.warn("Extra bytes detected at the end of the row! Ignoring similar " + "problems.");
    }

    // Missing fields?
    if (!missingFieldWarned && lastFieldByteEnd > structByteEnd) {
        missingFieldWarned = true;
        LOG.info("Missing fields! Expected " + fields.length + " fields but " + "only got " + fieldId
                + "! Ignoring similar problems.");
    }

    Arrays.fill(fieldInited, false);
    parsed = true;
}