Example usage for java.util Arrays copyOf

List of usage examples for java.util Arrays copyOf

Introduction

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

Prototype

public static boolean[] copyOf(boolean[] original, int newLength) 

Source Link

Document

Copies the specified array, truncating or padding with false (if necessary) so the copy has the specified length.

Usage

From source file:uk.co.caprica.brue.core.domain.bridge.GroupAction.java

public Float[] xy() {
    return xy != null ? Arrays.copyOf(xy, 2) : null;
}

From source file:libepg.ts.packet.TsPacket.java

/**
 * TS???/* w  w w  .j  a  v a  2  s. c  om*/
 *
 * @param data TS?
 * @throws IllegalArgumentException ?188??????
 */
public TsPacket(final byte[] data) throws IllegalArgumentException {
    byte[] temp = Arrays.copyOf(data, data.length);
    if (temp.length != TsPacket.TS_PACKET_BYTE_LENGTH.PACKET_LENGTH.getByteLength()) {
        MessageFormat msg = new MessageFormat(
                "????????={0} ?={1}");
        Object[] parameters = { temp.length, Hex.encodeHexString(temp) };
        throw new IllegalArgumentException(msg.format(parameters));
    }
    this.data = new ByteDataBlock(temp);
}

From source file:fr.eoit.util.dumper.DumperTest.java

@Test
public void testCompression() {

    byte[] strBytes = COPYRIGHTS.getBytes();

    byte[] output = new byte[8096];
    Deflater compresser = new Deflater(Deflater.BEST_COMPRESSION, true);
    compresser.setInput(strBytes);/* w  w  w  .j a va 2 s  . com*/
    compresser.finish();
    int compressedDataLength = compresser.deflate(output);
    compresser.end();

    String inputString = new String(Hex.encodeHex(strBytes));
    String hexString = new String(Arrays.copyOf(output, compressedDataLength));

    int i = 0;
    i++;
}

From source file:cat.albirar.framework.dynabean.impl.models.test.ModelImpl.java

/**
 * Copy constructor./*from   w ww .ja v a2  s.c om*/
 * @param origin The origin of data
 */
public ModelImpl(IModel origin) {
    if (origin != null) {
        name = origin.getName();
        lastName = origin.getLastName();
        birthDate = origin.getBirthDate() == null ? null : new Date(origin.getBirthDate().getTime());
        gender = origin.getGender();
        id = origin.getId();
        numberOfChildren = origin.getNumberOfChildren();
        incomingYear = origin.getIncomingYear();
        if (origin.getNames() != null) {
            names = Arrays.copyOf(origin.getNames(), origin.getNames().length);
        }
    }
}

From source file:com.linkedin.pinot.controller.helix.core.rebalance.DefaultRebalanceStrategyTest.java

private List<String> getInstanceList(final int nServers) {
    Assert.assertTrue(nServers <= serverNames.length);
    String[] instanceArray = Arrays.copyOf(serverNames, nServers);
    return Lists.newArrayList(instanceArray);
}

From source file:org.geopublishing.atlasStyler.classification.RasterClassification.java

@Override
public BufferedImage createHistogramImage(boolean showMean, boolean showSd, int histogramBins,
        String label_xachsis) throws InterruptedException, IOException {
    HistogramDataset hds = new HistogramDataset();

    DoubleArrayList valuesAL;/*from w  w w  . j ava 2  s .  c  o m*/
    valuesAL = getStatistics().elements();
    double[] elements = Arrays.copyOf(valuesAL.elements(), getStatistics().size());
    hds.addSeries(1, elements, histogramBins);

    /** Statically label the Y Axis **/
    String label_yachsis = ASUtil.R("QuantitiesClassificationGUI.Histogram.YAxisLabel");

    JFreeChart chart = org.jfree.chart.ChartFactory.createHistogram(null, label_xachsis, label_yachsis, hds,
            PlotOrientation.VERTICAL, false, true, true);

    /***********************************************************************
     * Paint the classes into the JFreeChart
     */
    int countLimits = 0;
    for (Double cLimit : getClassLimits()) {
        ValueMarker marker = new ValueMarker(cLimit);
        XYPlot plot = chart.getXYPlot();
        marker.setPaint(Color.orange);
        marker.setLabel(String.valueOf(countLimits));
        marker.setLabelAnchor(RectangleAnchor.TOP_LEFT);
        marker.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        plot.addDomainMarker(marker);

        countLimits++;
    }

    /***********************************************************************
     * Optionally painting SD and MEAN into the histogram
     */
    try {
        if (showSd) {
            ValueMarker marker;
            marker = new ValueMarker(getSD(), Color.green.brighter(), new BasicStroke(1.5f));
            XYPlot plot = chart.getXYPlot();
            marker.setLabel(ASUtil.R("QuantitiesClassificationGUI.Histogram.SD.ShortLabel"));
            marker.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT);
            marker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
            plot.addDomainMarker(marker);
        }

        if (showMean) {
            ValueMarker marker;
            marker = new ValueMarker(getMean(), Color.green.darker(), new BasicStroke(1.5f));
            XYPlot plot = chart.getXYPlot();
            marker.setLabel(ASUtil.R("QuantitiesClassificationGUI.Histogram.Mean.ShortLabel"));
            marker.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT);
            marker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
            plot.addDomainMarker(marker);
        }

    } catch (Exception e) {
        LOGGER.error("Painting SD and MEAN into the histogram", e);
    }

    /***********************************************************************
     * Render the Chart
     */
    BufferedImage image = chart.createBufferedImage(400, 200);

    return image;
}

From source file:com.cloudera.sqoop.lib.BlobRef.java

@Override
protected BytesWritable deepCopyData(BytesWritable data) {
    return new BytesWritable(Arrays.copyOf(data.getBytes(), data.getLength()));
}

From source file:com.qcadoo.report.api.ReportException.java

public String[] getArgs() {
    return Arrays.copyOf(args, args.length);
}

From source file:edu.oregonstate.eecs.mcplan.domains.yahtzee2.KeepMostAction.java

@Override
public void doAction(final RandomGenerator rng, final YahtzeeState s) {
    assert (old_hand_ == null);
    assert (s.rerolls > 0);
    old_hand_ = s.hand();/*from w w w. jav a2  s  . co  m*/

    int most_n = -1;
    int most_i = 0;
    // Loop from 6 down, to prefer higher-scoring multiples
    for (int i = Hand.Nfaces - 1; i >= 0; --i) {
        final int n = old_hand_.dice[i];
        if (n > most_n) {
            most_i = i;
            most_n = n;
        }
    }
    final int[] r;
    if (most_n < Hand.Ndice) {
        r = s.roll(rng, Hand.Ndice - most_n);
        r[most_i] += most_n;
    } else {
        r = Arrays.copyOf(old_hand_.dice, old_hand_.dice.length);
    }
    final Hand h = new Hand(r);
    s.setHand(h, s.rerolls - 1);
}

From source file:com.opengamma.analytics.math.function.RealPolynomialFunction1D.java

/**
 * Adds a function to the polynomial. If the function is not a {@link RealPolynomialFunction1D} then the addition takes
 * place as in {@link DoubleFunction1D}, otherwise the result will also be a polynomial.
 * @param f The function to add/*  ww  w.ja  va2 s. com*/
 * @return $P+f$
 * @throws IllegalArgumentException If the function is null
 */
@Override
public DoubleFunction1D add(final DoubleFunction1D f) {
    Validate.notNull(f, "function");
    if (f instanceof RealPolynomialFunction1D) {
        final RealPolynomialFunction1D p1 = (RealPolynomialFunction1D) f;
        final double[] c1 = p1.getCoefficients();
        final double[] c = _coefficients;
        final int n = c1.length;
        final boolean longestIsNew = n > _n;
        final double[] c3 = longestIsNew ? Arrays.copyOf(c1, n) : Arrays.copyOf(c, _n);
        for (int i = 0; i < (longestIsNew ? _n : n); i++) {
            c3[i] += longestIsNew ? c[i] : c1[i];
        }
        return new RealPolynomialFunction1D(c3);
    }
    return super.add(f);
}