本文整理了Java中java.util.Arrays.equals()
方法的一些代码示例,展示了Arrays.equals()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Arrays.equals()
方法的具体详情如下:
包路径:java.util.Arrays
类名称:Arrays
方法名:equals
[英]Compares the two arrays.
[中]比较两个数组。
代码示例来源:origin: spring-projects/spring-framework
private void doTestCommaDelimitedListToStringArrayLegalMatch(String[] components) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < components.length; i++) {
if (i != 0) {
sb.append(",");
}
sb.append(components[i]);
}
String[] sa = StringUtils.commaDelimitedListToStringArray(sb.toString());
assertTrue("String array isn't null with legal match", sa != null);
assertEquals("String array length is correct with legal match", components.length, sa.length);
assertTrue("Output equals input", Arrays.equals(sa, components));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void copyFromInputStream() throws IOException {
byte[] content = "content".getBytes();
ByteArrayInputStream in = new ByteArrayInputStream(content);
ByteArrayOutputStream out = new ByteArrayOutputStream(content.length);
int count = FileCopyUtils.copy(in, out);
assertEquals(content.length, count);
assertTrue(Arrays.equals(content, out.toByteArray()));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testCDependencies() {
String[] deps = this.dependentBeansFactory.getDependentBeans("c");
assertTrue(Arrays.equals(new String[] { "int", "long" }, deps));
}
代码示例来源:origin: apache/incubator-druid
@Test
@Parameters
public void testGetCacheKey(DimensionSpec dimensionSpec, boolean expectedResult)
{
Assert.assertEquals(expectedResult, Arrays.equals(lookupDimSpec.getCacheKey(), dimensionSpec.getCacheKey()));
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public Object generate(Object target, Method method, Object... params) {
assertTrue("Unexpected parameters: expected: "
+ Arrays.toString(this.expectedParams) + " but got: " + Arrays.toString(params),
Arrays.equals(expectedParams, params));
return new SimpleKey(params);
}
}
代码示例来源:origin: commons-codec/commons-codec
@Test
public void testPairs() {
assertEquals("AAA=", new String(Base64.encodeBase64(new byte[] { 0, 0 })));
for (int i = -128; i <= 127; i++) {
final byte test[] = { (byte) i, (byte) i };
assertTrue(Arrays.equals(test, Base64.decodeBase64(Base64.encodeBase64(test))));
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testCanonicalPropertyNames() {
String[] original =
new String[] {"map", "map[key1]", "map['key1']", "map[\"key1\"]", "map[key1][key2]",
"map['key1'][\"key2\"]", "map[key1].name", "map['key1'].name", "map[\"key1\"].name"};
String[] canonical =
new String[] {"map", "map[key1]", "map[key1]", "map[key1]", "map[key1][key2]",
"map[key1][key2]", "map[key1].name", "map[key1].name", "map[key1].name"};
assertTrue(Arrays.equals(canonical, PropertyAccessorUtils.canonicalPropertyNames(original)));
}
代码示例来源:origin: commons-io/commons-io
@SuppressWarnings("resource") // 'in' is deliberately not closed
private void testCopy_inputStreamToOutputStreamWithBufferSize(final int bufferSize) throws Exception {
InputStream in = new ByteArrayInputStream(inData);
in = new YellOnCloseInputStream(in);
final ByteArrayOutputStream baout = new ByteArrayOutputStream();
final OutputStream out = new YellOnFlushAndCloseOutputStream(baout, false, true);
final long count = IOUtils.copy(in, out, bufferSize);
assertEquals("Not all bytes were read", 0, in.available());
assertEquals("Sizes differ", inData.length, baout.size());
assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray()));
assertEquals(inData.length,count);
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testShuffleBoolean() {
final boolean[] array1 = new boolean[]{true, false, true, true, false, false, true, false, false, true};
final boolean[] array2 = ArrayUtils.clone(array1);
ArrayUtils.shuffle(array1, new Random(SEED));
assertFalse(Arrays.equals(array1, array2));
assertEquals(5, ArrayUtils.removeAllOccurences(array1, true).length);
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testAddObjectArrayBoolean() {
boolean[] newArray;
newArray = ArrayUtils.add(null, false);
assertTrue(Arrays.equals(new boolean[]{false}, newArray));
assertEquals(Boolean.TYPE, newArray.getClass().getComponentType());
newArray = ArrayUtils.add(null, true);
assertTrue(Arrays.equals(new boolean[]{true}, newArray));
assertEquals(Boolean.TYPE, newArray.getClass().getComponentType());
final boolean[] array1 = new boolean[]{true, false, true};
newArray = ArrayUtils.add(array1, false);
assertTrue(Arrays.equals(new boolean[]{true, false, true, false}, newArray));
assertEquals(Boolean.TYPE, newArray.getClass().getComponentType());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testBDependencies() {
String[] deps = this.dependentBeansFactory.getDependentBeans("b");
assertTrue(Arrays.equals(new String[] { "c" }, deps));
}
代码示例来源:origin: apache/kafka
static void assertHeader(String key, String value, Header actual) {
assertEquals(key, actual.key());
assertTrue(Arrays.equals(value.getBytes(), actual.value()));
}
代码示例来源:origin: bumptech/glide
@Test
public void testDecode() throws IOException {
byte[] expected = Base64
.decode(VALID_PNG.substring(VALID_PNG.indexOf(',') + 1), Base64.DEFAULT);
CallBack callback = new CallBack();
fetcher.loadData(Priority.HIGH, callback);
byte[] result = new byte[((ByteArrayInputStream) callback.data).available()];
assertEquals(result.length, ((ByteArrayInputStream) callback.data).read(result));
assertTrue(Arrays.equals(result, expected));
assertNull(callback.exception);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testIntDependencies() {
String[] deps = this.dependentBeansFactory.getDependentBeans("int");
assertTrue(Arrays.equals(new String[] { "buffer" }, deps));
}
代码示例来源:origin: commons-io/commons-io
private static void checkXmlContent(final String xml, final String encoding, final String defaultEncoding)
throws IOException {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final XmlStreamWriter writer = new XmlStreamWriter(out, defaultEncoding);
writer.write(xml);
writer.close();
final byte[] xmlContent = out.toByteArray();
assertEquals(encoding, writer.getEncoding());
assertTrue(Arrays.equals(xml.getBytes(encoding), xmlContent));
}
代码示例来源:origin: commons-io/commons-io
@Test
public void testWrite_charSequenceToWriter() throws Exception {
final CharSequence csq = new StringBuilder(new String(inData, "US-ASCII"));
final ByteArrayOutputStream baout = new ByteArrayOutputStream();
@SuppressWarnings("resource") // deliberately not closed
final YellOnFlushAndCloseOutputStream out = new YellOnFlushAndCloseOutputStream(baout, true, true);
final Writer writer = new OutputStreamWriter(baout, "US-ASCII");
IOUtils.write(csq, writer);
out.off();
writer.flush();
assertEquals("Sizes differ", inData.length, baout.size());
assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray()));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void copyToByteArray() throws IOException {
byte[] content = "content".getBytes();
ByteArrayInputStream in = new ByteArrayInputStream(content);
byte[] result = FileCopyUtils.copyToByteArray(in);
assertTrue(Arrays.equals(content, result));
}
代码示例来源:origin: neo4j/neo4j
private void assertLabels( LabelSet labels, int... expected )
{
assertEquals( expected.length, labels.numberOfLabels() );
Arrays.sort( expected );
int[] labelArray = new int[labels.numberOfLabels()];
for ( int i = 0; i < labels.numberOfLabels(); i++ )
{
labelArray[i] = labels.label( i );
}
Arrays.sort( labelArray );
assertTrue( "labels match expected", Arrays.equals( expected, labelArray ) );
}
代码示例来源:origin: commons-io/commons-io
@Test
public void testWrite_byteArrayToWriter() throws Exception {
final ByteArrayOutputStream baout = new ByteArrayOutputStream();
@SuppressWarnings("resource") // deliberately not closed
final YellOnFlushAndCloseOutputStream out = new YellOnFlushAndCloseOutputStream(baout, true, true);
final Writer writer = new OutputStreamWriter(baout, "US-ASCII");
IOUtils.write(inData, writer);
out.off();
writer.flush();
assertEquals("Sizes differ", inData.length, baout.size());
assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray()));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void copyFromByteArray() throws IOException {
byte[] content = "content".getBytes();
ByteArrayOutputStream out = new ByteArrayOutputStream(content.length);
FileCopyUtils.copy(content, out);
assertTrue(Arrays.equals(content, out.toByteArray()));
}
内容来源于网络,如有侵权,请联系作者删除!