Skip to content

Commit

Permalink
Sort checksums inside archives
Browse files Browse the repository at this point in the history
  • Loading branch information
dwalluck committed Jun 14, 2024
1 parent 27393a7 commit 0d0c71a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
34 changes: 33 additions & 1 deletion core/src/main/java/org/jboss/pnc/build/finder/core/Checksum.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;

import org.apache.commons.codec.binary.Hex;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.vfs2.FileContent;
import org.apache.commons.vfs2.FileName;
import org.apache.commons.vfs2.FileObject;
Expand All @@ -50,7 +52,7 @@

import com.fasterxml.jackson.annotation.JsonIgnore;

public class Checksum implements Serializable {
public class Checksum implements Comparable<Checksum>, Serializable {
private static final Logger LOGGER = LoggerFactory.getLogger(Checksum.class);

private static final long serialVersionUID = -7347509034711302799L;
Expand All @@ -64,6 +66,7 @@ public class Checksum implements Serializable {
@JsonIgnore
private String filename;

@JsonIgnore
private long fileSize;

public Checksum() {
Expand Down Expand Up @@ -297,6 +300,35 @@ public void setFileSize(long fileSize) {
this.fileSize = fileSize;
}

@Override
public int compareTo(Checksum o) {
if (o == null) {
return 1;
}

int i = Integer.compare(type.ordinal(), o.getType().ordinal());
return i != 0 ? i : StringUtils.compare(value, o.value);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}

if (o == null || getClass() != o.getClass()) {
return false;
}

Checksum checksum = (Checksum) o;
return type == checksum.type && Objects.equals(value, checksum.value);
}

@Override
public int hashCode() {
return Objects.hash(type, value);
}

@Override
public String toString() {
return "Checksum{" + "type=" + type + ", value='" + value + '\'' + ", filename='" + filename + '\''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package org.jboss.pnc.build.finder.koji;

import java.util.Collection;
import java.util.HashSet;
import java.util.TreeSet;

import org.jboss.pnc.build.finder.core.Checksum;
Expand All @@ -41,21 +40,21 @@ public class KojiLocalArchive {

public KojiLocalArchive() {
this.filenames = new TreeSet<>();
this.checksums = new HashSet<>();
this.checksums = new TreeSet<>();
this.unmatchedFilenames = new TreeSet<>();
}

public KojiLocalArchive(KojiArchiveInfo archive, Collection<String> filenames, Collection<Checksum> checksums) {
this.archive = archive;
this.filenames = new TreeSet<>(filenames);
this.checksums = checksums;
this.checksums = new TreeSet<>(checksums);
this.unmatchedFilenames = new TreeSet<>();
}

public KojiLocalArchive(KojiRpmInfo rpm, Collection<String> filenames, Collection<Checksum> checksums) {
this.rpm = rpm;
this.filenames = new TreeSet<>(filenames);
this.checksums = checksums;
this.checksums = new TreeSet<>(checksums);
this.unmatchedFilenames = new TreeSet<>();
}

Expand Down Expand Up @@ -112,7 +111,7 @@ public Collection<Checksum> getChecksums() {
}

public void setChecksums(Collection<Checksum> checksums) {
this.checksums = checksums;
this.checksums = new TreeSet<>(checksums);
}

@JsonIgnore
Expand Down

0 comments on commit 0d0c71a

Please sign in to comment.