Example usage for java.util Arrays equals

List of usage examples for java.util Arrays equals

Introduction

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

Prototype

public static boolean equals(Object[] a, Object[] a2) 

Source Link

Document

Returns true if the two specified arrays of Objects are equal to one another.

Usage

From source file:io.github.dsheirer.record.wave.MonoWaveReader.java

/**
 * Opens the file//www  .j  a va2  s.  c o m
 */
private void open() throws IOException {
    if (!Files.exists(mPath)) {
        throw new IOException("File not found");
    }

    mInputStream = Files.newInputStream(mPath, StandardOpenOption.READ);

    //Check for RIFF header
    byte[] buffer = new byte[4];
    mInputStream.read(buffer);

    if (!Arrays.equals(buffer, WaveUtils.RIFF_CHUNK)) {
        throw new IOException("File is not .wav format - missing RIFF chunk");
    }

    //Get file size
    mInputStream.read(buffer);
    int fileSize = ByteBuffer.wrap(buffer).order(ByteOrder.LITTLE_ENDIAN).asIntBuffer().get();

    //Check for WAVE format
    mInputStream.read(buffer);

    if (!Arrays.equals(buffer, WaveUtils.WAV_FORMAT)) {
        throw new IOException("File is not .wav format - missing WAVE format");
    }

    //Check for format chunk
    mInputStream.read(buffer);

    if (!Arrays.equals(buffer, WaveUtils.CHUNK_FORMAT)) {
        throw new IOException("File is not .wav format - missing format chunk");
    }

    //Get chunk size
    mInputStream.read(buffer);
    int chunkSize = ByteBuffer.wrap(buffer).order(ByteOrder.LITTLE_ENDIAN).asIntBuffer().get();

    //Get format
    mInputStream.read(buffer);

    ShortBuffer shortBuffer = ByteBuffer.wrap(buffer).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer();
    short format = shortBuffer.get();
    if (format != WaveUtils.PCM_FORMAT) {
        throw new IOException("File format not supported - expecting PCM format");
    }

    //Get number of channels
    short channels = shortBuffer.get();
    if (channels != 1) {
        throw new IOException("Unsupported channel count - mono audio only");
    }

    //Get samples per second
    mInputStream.read(buffer);
    int sampleRate = ByteBuffer.wrap(buffer).order(ByteOrder.LITTLE_ENDIAN).asIntBuffer().get();

    //Get bytes per second
    mInputStream.read(buffer);
    int bytesPerSecond = ByteBuffer.wrap(buffer).order(ByteOrder.LITTLE_ENDIAN).asIntBuffer().get();

    mInputStream.read(buffer);

    //Get frame size
    shortBuffer = ByteBuffer.wrap(buffer).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer();
    short frameSize = shortBuffer.get();
    if (frameSize != 2) {
        throw new IOException("PCM frame size not supported - expecting 2 bytes per frame");
    }

    //Get bits per sample
    short bitsPerSample = shortBuffer.get();
    if (bitsPerSample != 16) {
        throw new IOException("PCM sample size not supported - expecting 16 bits per sample");
    }

    mInputStream.read(buffer);

    if (!Arrays.equals(buffer, WaveUtils.CHUNK_DATA)) {
        throw new IOException("Unexpected chunk - expecting data chunk");
    }

    //Get data chunk size
    mInputStream.read(buffer);
    mDataByteSize = ByteBuffer.wrap(buffer).order(ByteOrder.LITTLE_ENDIAN).asIntBuffer().get();
}

From source file:ly.count.android.api.CountlyStoreTests.java

public void testConnections_prefIsEmptyString() {
    // the following two calls will result in the pref being an empty string
    final String connStr = "blah";
    store.addConnection(connStr);//w w  w . j  av a 2 s.  c o  m
    store.removeConnection(connStr);
    assertTrue(Arrays.equals(new String[0], store.connections()));
}

From source file:com.opengamma.analytics.financial.model.volatility.smile.function.SVIFormulaData.java

@Override
public boolean equals(final Object obj) {
    if (this == obj) {
        return true;
    }/*www.  j a  v  a2s . c om*/
    if (obj == null) {
        return false;
    }
    if (getClass() != obj.getClass()) {
        return false;
    }
    final SVIFormulaData other = (SVIFormulaData) obj;
    if (!Arrays.equals(_parameters, other._parameters)) {
        return false;
    }
    return true;
}

From source file:edu.oregonstate.eecs.mcplan.domains.cosmic.TripShuntSetAction.java

@Override
public boolean equals(final Object obj) {
    if (!(obj instanceof TripShuntSetAction)) {
        return false;
    }/*from   w w  w  .j a  v a  2s . co  m*/
    final TripShuntSetAction that = (TripShuntSetAction) obj;
    return Arrays.equals(shunts, that.shunts);
}

From source file:edu.oregonstate.eecs.mcplan.domains.cosmic.TripBranchSetAction.java

@Override
public boolean equals(final Object obj) {
    if (!(obj instanceof TripBranchSetAction)) {
        return false;
    }//  w ww  . j  ava2s  .c o  m
    final TripBranchSetAction that = (TripBranchSetAction) obj;
    return Arrays.equals(branch, that.branch);
}

From source file:Main.java

/**
 * Tests two polygons for equality.  If both are <code>null</code> this
 * method returns <code>true</code>.
 *
 * @param p1  path 1 (<code>null</code> permitted).
 * @param p2  path 2 (<code>null</code> permitted).
 *
 * @return A boolean.//from  w  w  w.  j  ava  2  s.c  o  m
 */
public static boolean equal(final GeneralPath p1, final GeneralPath p2) {
    if (p1 == null) {
        return (p2 == null);
    }
    if (p2 == null) {
        return false;
    }
    if (p1.getWindingRule() != p2.getWindingRule()) {
        return false;
    }
    PathIterator iterator1 = p1.getPathIterator(null);
    PathIterator iterator2 = p2.getPathIterator(null);
    double[] d1 = new double[6];
    double[] d2 = new double[6];
    boolean done = iterator1.isDone() && iterator2.isDone();
    while (!done) {
        if (iterator1.isDone() != iterator2.isDone()) {
            return false;
        }
        int seg1 = iterator1.currentSegment(d1);
        int seg2 = iterator2.currentSegment(d2);
        if (seg1 != seg2) {
            return false;
        }
        if (!Arrays.equals(d1, d2)) {
            return false;
        }
        iterator1.next();
        iterator2.next();
        done = iterator1.isDone() && iterator2.isDone();
    }
    return true;
}

From source file:com.bitbreeds.webrtc.common.SignalUtilTest.java

@Test
public void fourBytesFromInt() {
    SignalUtil.fourBytesFromInt(0);/*from   w w w.ja  v  a 2  s. c  om*/

    byte[] a = { 0, 0, 0, 0 };
    byte[] b = { 0, 0, 0, 5 };
    byte[] c = { 0, 1, 0, 5 };
    byte[] d = { 2, 1, 0, 5 };
    assertTrue(Arrays.equals(a, SignalUtil.fourBytesFromInt(0)));

    assertTrue(Arrays.equals(b, SignalUtil.fourBytesFromInt(5)));

    int num = 0x00010005;
    byte[] ts = SignalUtil.fourBytesFromInt(num);
    assertTrue(Arrays.equals(c, ts));

    num = 0x02010005;
    ts = SignalUtil.fourBytesFromInt(num);
    assertTrue(Arrays.equals(d, ts));
}

From source file:com.granita.icloudcalsync.resource.ContactTest.java

public void testReferenceVCard() throws IOException, InvalidResourceException {
    Contact c = parseVCF("reference.vcf");
    assertEquals("Gump", c.getFamilyName());
    assertEquals("Forrest", c.getGivenName());
    assertEquals("Forrest Gump", c.getDisplayName());
    assertEquals("Bubba Gump Shrimp Co.", c.getOrganization().getValues().get(0));
    assertEquals("Shrimp Man", c.getJobTitle());

    Telephone phone1 = c.getPhoneNumbers().get(0);
    assertEquals("(111) 555-1212", phone1.getText());
    assertEquals("WORK", phone1.getParameters("TYPE").get(0));
    assertEquals("VOICE", phone1.getParameters("TYPE").get(1));

    Telephone phone2 = c.getPhoneNumbers().get(1);
    assertEquals("(404) 555-1212", phone2.getText());
    assertEquals("HOME", phone2.getParameters("TYPE").get(0));
    assertEquals("VOICE", phone2.getParameters("TYPE").get(1));

    Email email = c.getEmails().get(0);/*  www  .  j a v a  2  s.c  o m*/
    assertEquals("forrestgump@example.com", email.getValue());
    assertEquals("PREF", email.getParameters("TYPE").get(0));
    assertEquals("INTERNET", email.getParameters("TYPE").get(1));

    @Cleanup
    InputStream photoStream = assetMgr.open("davdroid-logo-192.png", AssetManager.ACCESS_STREAMING);
    byte[] expectedPhoto = IOUtils.toByteArray(photoStream);
    assertTrue(Arrays.equals(c.getPhoto(), expectedPhoto));
}

From source file:net.darkmist.clf.UtilTest.java

public void testInterleavedBA() throws Exception {
    Integer[] b = new Integer[] { 1, 3, 5, 7, 9 };
    Integer[] a = new Integer[] { 2, 4, 6, 8 };
    Integer[] expected = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    Integer[] actual = new Integer[a.length + b.length];

    Util.merge(a, b, actual, comparator);
    assertTrue(Arrays.equals(actual, expected));
}

From source file:edu.oregonstate.eecs.mcplan.domains.planetwars.PwLaunchAction.java

@Override
public boolean equals(final Object obj) {
    if (!(obj instanceof PwLaunchAction)) {
        return false;
    }//from w ww  .  j  a v a2s . c o  m
    final PwLaunchAction that = (PwLaunchAction) obj;
    return player == that.player && src == that.src && route == that.route
            && Arrays.equals(population, that.population);
}