Skip to content

Commit

Permalink
Merge pull request #244 from spyrkob/manifest_builder
Browse files Browse the repository at this point in the history
Add ChannelManifest.Builder
  • Loading branch information
jmesnil authored Sep 13, 2024
2 parents bc1c537 + e20bf0f commit 4c6b7bb
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
43 changes: 43 additions & 0 deletions core/src/main/java/org/wildfly/channel/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY;
import java.util.ArrayList;
import java.util.Objects;

import static java.util.Collections.emptyList;

public class Channel {
Expand Down Expand Up @@ -171,6 +173,19 @@ public String toString() {
'}';
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Channel channel = (Channel) o;
return Objects.equals(schemaVersion, channel.schemaVersion) && Objects.equals(name, channel.name) && Objects.equals(description, channel.description) && Objects.equals(vendor, channel.vendor) && Objects.equals(repositories, channel.repositories) && Objects.equals(blocklistCoordinate, channel.blocklistCoordinate) && Objects.equals(manifestCoordinate, channel.manifestCoordinate) && noStreamStrategy == channel.noStreamStrategy;
}

@Override
public int hashCode() {
return Objects.hash(schemaVersion, name, description, vendor, repositories, blocklistCoordinate, manifestCoordinate, noStreamStrategy);
}

/**
* Builder for channel class
*/
Expand All @@ -183,6 +198,19 @@ public static class Builder {
private String description;
private Vendor vendor;

public Builder() {
}

public Builder(Channel from) {
this.name = from.getName();
this.repositories = new ArrayList<>(from.getRepositories());
this.manifestCoordinate = from.getManifestCoordinate();
this.blocklistCoordinate = from.getBlocklistCoordinate();
this.strategy = from.getNoStreamStrategy();
this.description = from.getDescription();
this.vendor = from.getVendor();
}

public Channel build() {
return new Channel(name, description, vendor, repositories, manifestCoordinate, blocklistCoordinate, strategy);
}
Expand All @@ -197,6 +225,11 @@ public Builder setDescription(String description) {
return this;
}

public Builder setRepositories(List<Repository> repositories) {
this.repositories = repositories;
return this;
}

public Builder setVendor(Vendor vendor) {
this.vendor = vendor;
return this;
Expand All @@ -212,6 +245,11 @@ public Builder setManifestCoordinate(String groupId, String artifactId, String v
return this;
}

public Builder setManifestCoordinate(String groupId, String artifactId) {
this.manifestCoordinate = new ChannelManifestCoordinate(groupId, artifactId);
return this;
}

public Builder setManifestUrl(URL url) {
this.manifestCoordinate = new ChannelManifestCoordinate(url);
return this;
Expand All @@ -231,6 +269,11 @@ public Builder setBlocklist(String groupId, String artifactId, String version) {
return this;
}

public Builder setBlocklistCoordinate(BlocklistCoordinate blocklistCoordinate) {
this.blocklistCoordinate = blocklistCoordinate;
return this;
}

public Builder setResolveStrategy(NoStreamStrategy strategy) {
this.strategy = strategy;
return this;
Expand Down
69 changes: 69 additions & 0 deletions core/src/main/java/org/wildfly/channel/ChannelManifest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
Expand Down Expand Up @@ -192,4 +194,71 @@ public String toString() {
", manifestRequirements=" + manifestRequirements +
'}';
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ChannelManifest that = (ChannelManifest) o;
return Objects.equals(schemaVersion, that.schemaVersion) && Objects.equals(name, that.name) && Objects.equals(id, that.id) && Objects.equals(description, that.description) && Objects.equals(streams, that.streams) && Objects.equals(manifestRequirements, that.manifestRequirements);
}

@Override
public int hashCode() {
return Objects.hash(schemaVersion, name, id, description, streams, manifestRequirements);
}

public static class Builder {
private String schemaVersion;
private String name;
private String id;
private String description;
private List<Stream> streams;
private List<ManifestRequirement> manifestRequirements;

public ChannelManifest build() {
return new ChannelManifest(
schemaVersion,
id,
description,
manifestRequirements,
streams);
}

public Builder setSchemaVersion(String schemaVersion) {
this.schemaVersion = schemaVersion;
return this;
}

public Builder setName(String name) {
this.name = name;
return this;
}

public Builder setId(String id) {
this.id = id;
return this;
}

public Builder setDescription(String description) {
this.description = description;
return this;
}

public Builder addStreams(Stream... stream) {
if (this.streams == null) {
this.streams = new ArrayList<>();
}
this.streams.addAll(Arrays.asList(stream));
return this;
}

public Builder addManifestRequirements(ManifestRequirement... manifestRequirements) {
if (this.manifestRequirements == null) {
this.manifestRequirements = new ArrayList<>();
}
this.manifestRequirements.addAll(Arrays.asList(manifestRequirements));
return this;
}
}
}

0 comments on commit 4c6b7bb

Please sign in to comment.