Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ChannelManifest.Builder #244

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -169,6 +171,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 @@ -181,6 +196,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 @@ -195,6 +223,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 @@ -210,6 +243,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 @@ -229,6 +267,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;
}
}
}
Loading