You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/12/31 14:12:49 UTC
(commons-compress) branch master updated (8593fee0c -> fdddfaa0f)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
from 8593fee0c Javadoc: English, not Latin
new 44c1fa2da Make new classes ExtraField and ExtraField.SubField
new fdddfaa0f Add org.apache.commons.compress.compressors.gzip.ExtraField.SubField hashCode() and equals()
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../compress/compressors/gzip/ExtraField.java | 29 +++++++++++-
.../compress/compressors/gzip/SubFieldTest.java | 53 ++++++++++++++++++++++
2 files changed, 80 insertions(+), 2 deletions(-)
create mode 100644 src/test/java/org/apache/commons/compress/compressors/gzip/SubFieldTest.java
(commons-compress) 01/02: Make new classes ExtraField and ExtraField.SubField
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
commit 44c1fa2da1f8bb169502ca330bc470d39e38a0ca
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Tue Dec 31 09:03:36 2024 -0500
Make new classes ExtraField and ExtraField.SubField
---
.../java/org/apache/commons/compress/compressors/gzip/ExtraField.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/commons/compress/compressors/gzip/ExtraField.java b/src/main/java/org/apache/commons/compress/compressors/gzip/ExtraField.java
index fc3109ef6..c31d07d0c 100644
--- a/src/main/java/org/apache/commons/compress/compressors/gzip/ExtraField.java
+++ b/src/main/java/org/apache/commons/compress/compressors/gzip/ExtraField.java
@@ -51,7 +51,7 @@ import org.apache.commons.compress.compressors.gzip.ExtraField.SubField;
* @see <a href="https://datatracker.ietf.org/doc/html/rfc1952">RFC 1952 GZIP File Format Specification</a>
* @since 1.28.0
*/
-public class ExtraField implements Iterable<SubField> {
+public final class ExtraField implements Iterable<SubField> {
/**
* If the {@code FLG.FEXTRA} bit is set, an "extra field" is present in the header, with total length XLEN bytes. It consists of a series of subfields, each
@@ -80,7 +80,7 @@ public class ExtraField implements Iterable<SubField> {
*
* @see <a href="https://datatracker.ietf.org/doc/html/rfc1952">RFC 1952 GZIP File Format Specification</a>
*/
- public static class SubField {
+ public static final class SubField {
private final byte si1;
private final byte si2;
(commons-compress) 02/02: Add org.apache.commons.compress.compressors.gzip.ExtraField.SubField hashCode() and equals()
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
commit fdddfaa0fb408bdafae8e4bdf32436883f8c6409
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Tue Dec 31 09:12:40 2024 -0500
Add org.apache.commons.compress.compressors.gzip.ExtraField.SubField
hashCode() and equals()
---
.../compress/compressors/gzip/ExtraField.java | 25 ++++++++++
.../compress/compressors/gzip/SubFieldTest.java | 53 ++++++++++++++++++++++
2 files changed, 78 insertions(+)
diff --git a/src/main/java/org/apache/commons/compress/compressors/gzip/ExtraField.java b/src/main/java/org/apache/commons/compress/compressors/gzip/ExtraField.java
index c31d07d0c..9b4e694af 100644
--- a/src/main/java/org/apache/commons/compress/compressors/gzip/ExtraField.java
+++ b/src/main/java/org/apache/commons/compress/compressors/gzip/ExtraField.java
@@ -21,6 +21,7 @@ package org.apache.commons.compress.compressors.gzip;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@@ -92,6 +93,21 @@ public final class ExtraField implements Iterable<SubField> {
this.payload = payload;
}
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final SubField other = (SubField) obj;
+ return Arrays.equals(payload, other.payload) && si1 == other.si1 && si2 == other.si2;
+ }
+
/**
* The 2 character ISO-8859-1 string made from the si1 and si2 bytes of the sub field id.
*
@@ -109,6 +125,15 @@ public final class ExtraField implements Iterable<SubField> {
public byte[] getPayload() {
return payload;
}
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + Arrays.hashCode(payload);
+ result = prime * result + Objects.hash(si1, si2);
+ return result;
+ }
}
private static final int MAX_SIZE = 0xFFFF;
diff --git a/src/test/java/org/apache/commons/compress/compressors/gzip/SubFieldTest.java b/src/test/java/org/apache/commons/compress/compressors/gzip/SubFieldTest.java
new file mode 100644
index 000000000..e5cb21582
--- /dev/null
+++ b/src/test/java/org/apache/commons/compress/compressors/gzip/SubFieldTest.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.commons.compress.compressors.gzip;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+import org.apache.commons.compress.compressors.gzip.ExtraField.SubField;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link ExtraField.SubField}.
+ */
+public class SubFieldTest {
+
+ @Test
+ public void testEquals() {
+ assertEquals(new SubField((byte) 0, (byte) 0, new byte[0]), new SubField((byte) 0, (byte) 0, new byte[0]));
+ assertEquals(new SubField((byte) 9, (byte) 9, new byte[9]), new SubField((byte) 9, (byte) 9, new byte[9]));
+ // not equals
+ assertNotEquals(new SubField((byte) 0, (byte) 9, new byte[9]), new SubField((byte) 9, (byte) 9, new byte[9]));
+ assertNotEquals(new SubField((byte) 9, (byte) 0, new byte[9]), new SubField((byte) 9, (byte) 9, new byte[9]));
+ assertNotEquals(new SubField((byte) 9, (byte) 9, new byte[0]), new SubField((byte) 9, (byte) 9, new byte[9]));
+ assertNotEquals(new SubField((byte) 9, (byte) 9, new byte[9]), new SubField((byte) 9, (byte) 9, new byte[] { 9 }));
+ }
+
+ @Test
+ public void testHashCode() {
+ assertEquals(new SubField((byte) 0, (byte) 0, new byte[0]).hashCode(), new SubField((byte) 0, (byte) 0, new byte[0]).hashCode());
+ assertEquals(new SubField((byte) 9, (byte) 9, new byte[9]).hashCode(), new SubField((byte) 9, (byte) 9, new byte[9]).hashCode());
+ // not equals
+ assertNotEquals(new SubField((byte) 0, (byte) 9, new byte[9]).hashCode(), new SubField((byte) 9, (byte) 9, new byte[9]).hashCode());
+ assertNotEquals(new SubField((byte) 9, (byte) 0, new byte[9]).hashCode(), new SubField((byte) 9, (byte) 9, new byte[9]).hashCode());
+ assertNotEquals(new SubField((byte) 9, (byte) 9, new byte[0]).hashCode(), new SubField((byte) 9, (byte) 9, new byte[9]).hashCode());
+ assertNotEquals(new SubField((byte) 9, (byte) 9, new byte[9]).hashCode(), new SubField((byte) 9, (byte) 9, new byte[] { 9 }).hashCode());
+ }
+}