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

Refactor messages by subclasses #1621

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
106 changes: 51 additions & 55 deletions adminapi/src/main/java/io/minio/admin/MinioAdminClient.java

Large diffs are not rendered by default.

49 changes: 4 additions & 45 deletions api/src/main/java/io/minio/BaseArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,75 +60,34 @@ public abstract static class Builder<B extends Builder<B, A>, A extends BaseArgs

protected abstract void validate(A args);

protected void validateNotNull(Object arg, String argName) {
if (arg == null) {
throw new IllegalArgumentException(argName + " must not be null.");
}
}

protected void validateNotEmptyString(String arg, String argName) {
validateNotNull(arg, argName);
if (arg.isEmpty()) {
throw new IllegalArgumentException(argName + " must be a non-empty string.");
}
}

protected void validateNullOrNotEmptyString(String arg, String argName) {
if (arg != null && arg.isEmpty()) {
throw new IllegalArgumentException(argName + " must be a non-empty string.");
}
}

protected void validateNullOrPositive(Number arg, String argName) {
if (arg != null && arg.longValue() < 0) {
throw new IllegalArgumentException(argName + " cannot be non-negative.");
}
}

public Builder() {
this.operations = new ArrayList<>();
}

protected Multimap<String, String> copyMultimap(Multimap<String, String> multimap) {
Multimap<String, String> multimapCopy = HashMultimap.create();
if (multimap != null) {
multimapCopy.putAll(multimap);
}
return Multimaps.unmodifiableMultimap(multimapCopy);
}

protected Multimap<String, String> toMultimap(Map<String, String> map) {
Multimap<String, String> multimap = HashMultimap.create();
if (map != null) {
multimap.putAll(Multimaps.forMap(map));
}
return Multimaps.unmodifiableMultimap(multimap);
}

@SuppressWarnings("unchecked") // Its safe to type cast to B as B extends this class.
public B extraHeaders(Multimap<String, String> headers) {
final Multimap<String, String> extraHeaders = copyMultimap(headers);
final Multimap<String, String> extraHeaders = Utils.newMultimap(headers);
operations.add(args -> args.extraHeaders = extraHeaders);
return (B) this;
}

@SuppressWarnings("unchecked") // Its safe to type cast to B as B extends this class.
public B extraQueryParams(Multimap<String, String> queryParams) {
final Multimap<String, String> extraQueryParams = copyMultimap(queryParams);
final Multimap<String, String> extraQueryParams = Utils.newMultimap(queryParams);
operations.add(args -> args.extraQueryParams = extraQueryParams);
return (B) this;
}

@SuppressWarnings("unchecked") // Its safe to type cast to B as B extends this class.
public B extraHeaders(Map<String, String> headers) {
final Multimap<String, String> extraHeaders = toMultimap(headers);
final Multimap<String, String> extraHeaders = Utils.newMultimap(headers);
operations.add(args -> args.extraHeaders = extraHeaders);
return (B) this;
}

@SuppressWarnings("unchecked") // Its safe to type cast to B as B extends this class.
public B extraQueryParams(Map<String, String> queryParams) {
final Multimap<String, String> extraQueryParams = toMultimap(queryParams);
final Multimap<String, String> extraQueryParams = Utils.newMultimap(queryParams);
operations.add(args -> args.extraQueryParams = extraQueryParams);
return (B) this;
}
Expand Down
8 changes: 3 additions & 5 deletions api/src/main/java/io/minio/BucketArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package io.minio;

import io.minio.http.HttpUtils;
import io.minio.org.apache.commons.validator.routines.InetAddressValidator;
import java.util.Objects;
import java.util.regex.Pattern;

Expand All @@ -42,7 +40,7 @@ public abstract static class Builder<B extends Builder<B, A>, A extends BucketAr
protected boolean skipValidation = false;

protected void validateBucketName(String name) {
validateNotNull(name, "bucket name");
Utils.validateNotNull(name, "bucket name");
if (skipValidation) {
return;
}
Expand All @@ -55,7 +53,7 @@ protected void validateBucketName(String name) {
+ "https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html");
}

if (InetAddressValidator.getInstance().isValidInet4Address(name)) {
if (Utils.isValidIPv4(name)) {
throw new IllegalArgumentException(
"bucket name '" + name + "' must not be formatted as an IP address");
}
Expand All @@ -67,7 +65,7 @@ protected void validateBucketName(String name) {
}

private void validateRegion(String region) {
if (!skipValidation && region != null && !HttpUtils.REGION_REGEX.matcher(region).find()) {
if (!skipValidation && region != null && !Utils.REGION_REGEX.matcher(region).find()) {
throw new IllegalArgumentException("invalid region " + region);
}
}
Expand Down
Loading