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, int fromIndex, int toIndex, Object val) 

Source Link

Document

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

Usage

From source file:com.antsdb.saltedfish.sql.vdm.KeyUtil.java

static void toBytes(List<ColumnMeta> columns, byte[] bytes, List<Object> values, byte filler) {
    int pos = 0;/* w  ww  .j a v a 2  s .  c  o m*/
    for (int i = 0; i < columns.size(); i++) {
        ColumnMeta column = columns.get(i);
        if (i < values.size()) {
            Object value = values.get(i);
            pos += write(column, bytes, pos, value);
        } else {
            Arrays.fill(bytes, pos, bytes.length, filler);
        }
    }
}

From source file:Main.java

/**
 * Ensures the given array has a given size.
 * @param array        the array.//w  w w .  jav  a2s . c  o m
 * @param size         the target size of the array.
 * @param initialValue the initial value of the elements.
 * @return             the original array, or a copy if it had to be
 *                     extended.
 */
public static byte[] ensureArraySize(byte[] array, int size, byte initialValue) {
    // Is the existing array large enough?
    if (array.length >= size) {
        // Reinitialize the existing array.
        Arrays.fill(array, 0, size, initialValue);
    } else {
        // Otherwise create and initialize a new array.
        array = new byte[size];

        if (initialValue != 0) {
            Arrays.fill(array, 0, size, initialValue);
        }
    }

    return array;
}

From source file:com.bc.util.ObjectArray.java

public void clear() {
    Arrays.fill(_objects, 0, _objects.length, null);
}

From source file:io.milton.common.RangeUtilsTest.java

public void xtestWriteRanges() throws IOException {
    long length = 5000;
    byte[] buf = new byte[10000];
    for (int i = 0; i < 5; i++) {
        char ch = (char) (65 + i);
        Arrays.fill(buf, i * 1000, (i + 1) * 1000, (byte) ch);
    }//  w w w  .  ja v  a 2s. c o m
    ByteArrayInputStream in = new ByteArrayInputStream(buf);
    ByteArrayOutputStream out = new ByteArrayOutputStream();

    List<Range> ranges = new ArrayList<Range>();
    ranges.add(new Range(501l, 1000l));
    ranges.add(new Range(2001l, 2500l));
    ranges.add(new Range(3001l, 3500l));

    RangeUtils.writeRanges(in, ranges, out);

    assertEquals(1500, out.toByteArray().length);

}

From source file:Main.java

/**
 * Ensures the given array has a given size.
 * @param array        the array./*  www  .  j  a  v  a  2  s  .  co m*/
 * @param size         the target size of the array.
 * @param initialValue the initial value of the elements.
 * @return             the original array, or a copy if it had to be
 *                     extended.
 */
public static short[] ensureArraySize(short[] array, int size, short initialValue) {
    // Is the existing array large enough?
    if (array.length >= size) {
        // Reinitialize the existing array.
        Arrays.fill(array, 0, size, initialValue);
    } else {
        // Otherwise create and initialize a new array.
        array = new short[size];

        if (initialValue != 0) {
            Arrays.fill(array, 0, size, initialValue);
        }
    }

    return array;
}

From source file:com.lightboxtechnologies.spectrum.FsEntryUtilsTest.java

@Test
public void nextFsEntryKeyTestCarry() {
    final byte[] expected = new byte[36];
    expected[0] = 1;//from  w  w w  . j a  v a2  s  . c o m

    final byte[] key = new byte[36];
    Arrays.fill(key, 1, key.length, (byte) 0xFF);

    assertArrayEquals(expected, nextFsEntryKey(key));
}

From source file:hivemall.common.DenseModel.java

private void ensureCapacity(final int index) {
    if (index >= size) {
        int bits = MathUtils.bitsRequired(index);
        int newSize = (1 << bits) + 1;
        int oldSize = size;
        logger.info("Expands internal array size from " + oldSize + " to " + newSize + " (" + bits + " bits)");
        this.size = newSize;
        this.weights = Arrays.copyOf(weights, newSize);
        if (covars != null) {
            this.covars = Arrays.copyOf(covars, newSize);
            Arrays.fill(covars, oldSize, newSize, 1f);
        }//from w  w  w.ja  v  a  2s. c om
    }
}

From source file:org.sample.nonblocking.MyWriteListener.java

@Override
public void onWritePossible() {
    if (output.isReady()) {
        try {//www  .  j a v  a 2s .  co  m
            byte[] b = new byte[100];
            Arrays.fill(b, 0, 100, (byte) 'a');
            output.write(b);
        } catch (IOException ex) {
            Logger.getLogger(MyWriteListener.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:com.eryansky.common.utils.SysUtils.java

/**
  * /* w  w  w.  j a va  2  s. c om*/
  * 
  * @param text
  * @param length
  * @param c
  * @param charsetName
  * @return
  * @throws Exception
  */

 public static String rightPad(String text, int length, byte c, String charsetName) throws Exception {
     if (null == text)
         text = "";
     byte[] array = new byte[length];
     byte[] reference = text.getBytes(charsetName);
     Arrays.fill(array, reference.length, length, c);
     System.arraycopy(reference, 0, array, 0, reference.length);
     return new String(array, charsetName);
 }

From source file:org.tamacat.httpd.util.IpAddressMatcher.java

public boolean matches(String address) {
    InetAddress remoteAddress = parseAddress(address);
    if (!requiredAddress.getClass().equals(remoteAddress.getClass())) {
        return false;
    }/*from www.  j  ava2 s. c o  m*/

    if (nMaskBits < 0) {
        return remoteAddress.equals(requiredAddress);
    }

    byte[] remAddr = remoteAddress.getAddress();
    byte[] reqAddr = requiredAddress.getAddress();

    int oddBits = nMaskBits % 8;
    int nMaskBytes = nMaskBits / 8 + (oddBits == 0 ? 0 : 1);
    byte[] mask = new byte[nMaskBytes];

    Arrays.fill(mask, 0, oddBits == 0 ? mask.length : mask.length - 1, (byte) 0xFF);

    if (oddBits != 0) {
        int finalByte = (1 << oddBits) - 1;
        finalByte <<= 8 - oddBits;
        mask[mask.length - 1] = (byte) finalByte;
    }

    for (int i = 0; i < mask.length; i++) {
        if ((remAddr[i] & mask[i]) != (reqAddr[i] & mask[i])) {
            return false;
        }
    }
    return true;
}