[#5514] Fix DiskFileUpload and MemoryFileUpload equals(...) method.
Motivation: DiskFileUpload and MemoryFileUpload.equals(...) are broken. Modifications: Fix implementation and add unit test. Result: Equals method are correct now.
This commit is contained in:
parent
6b4dbe6207
commit
f012d4c231
@ -69,16 +69,12 @@ public class DiskFileUpload extends AbstractDiskHttpData implements FileUpload {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return getName().hashCode();
|
return FileUploadUtil.hashCode(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (!(o instanceof Attribute)) {
|
return o instanceof FileUpload && FileUploadUtil.equals(this, (FileUpload) o);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Attribute attribute = (Attribute) o;
|
|
||||||
return getName().equalsIgnoreCase(attribute.getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -91,13 +87,7 @@ public class DiskFileUpload extends AbstractDiskHttpData implements FileUpload {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int compareTo(FileUpload o) {
|
public int compareTo(FileUpload o) {
|
||||||
int v;
|
return FileUploadUtil.compareTo(this, o);
|
||||||
v = getName().compareToIgnoreCase(o.getName());
|
|
||||||
if (v != 0) {
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
// TODO should we compare size ?
|
|
||||||
return v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016 The Netty Project
|
||||||
|
*
|
||||||
|
* The Netty Project 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:
|
||||||
|
*
|
||||||
|
* http://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 io.netty.handler.codec.http.multipart;
|
||||||
|
|
||||||
|
final class FileUploadUtil {
|
||||||
|
|
||||||
|
private FileUploadUtil() { }
|
||||||
|
|
||||||
|
static int hashCode(FileUpload upload) {
|
||||||
|
return upload.getName().hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean equals(FileUpload upload1, FileUpload upload2) {
|
||||||
|
return upload1.getName().equalsIgnoreCase(upload2.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
static int compareTo(FileUpload upload1, FileUpload upload2) {
|
||||||
|
return upload1.getName().compareToIgnoreCase(upload2.getName());
|
||||||
|
}
|
||||||
|
}
|
@ -63,16 +63,12 @@ public class MemoryFileUpload extends AbstractMemoryHttpData implements FileUplo
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return getName().hashCode();
|
return FileUploadUtil.hashCode(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (!(o instanceof Attribute)) {
|
return o instanceof FileUpload && FileUploadUtil.equals(this, (FileUpload) o);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Attribute attribute = (Attribute) o;
|
|
||||||
return getName().equalsIgnoreCase(attribute.getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -85,13 +81,7 @@ public class MemoryFileUpload extends AbstractMemoryHttpData implements FileUplo
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int compareTo(FileUpload o) {
|
public int compareTo(FileUpload o) {
|
||||||
int v;
|
return FileUploadUtil.compareTo(this, o);
|
||||||
v = getName().compareToIgnoreCase(o.getName());
|
|
||||||
if (v != 0) {
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
// TODO should we compare size for instance ?
|
|
||||||
return v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016 The Netty Project
|
||||||
|
*
|
||||||
|
* The Netty Project 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:
|
||||||
|
*
|
||||||
|
* http://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 io.netty.handler.codec.http.multipart;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class DiskFileUploadTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public final void testDiskFileUploadEquals() {
|
||||||
|
DiskFileUpload f2 =
|
||||||
|
new DiskFileUpload("d1", "d1", "application/json", null, null, 100);
|
||||||
|
Assert.assertEquals(f2, f2);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016 The Netty Project
|
||||||
|
*
|
||||||
|
* The Netty Project 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:
|
||||||
|
*
|
||||||
|
* http://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 io.netty.handler.codec.http.multipart;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class MemoryFileUploadTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public final void testMemoryFileUploadEquals() {
|
||||||
|
MemoryFileUpload f1 =
|
||||||
|
new MemoryFileUpload("m1", "m1", "application/json", null, null, 100);
|
||||||
|
Assert.assertEquals(f1, f1);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user