Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ public interface FSBuilder<S, B extends FSBuilder<S, B>> {
* @return generic type B.
* @see #opt(String, String)
*/
B opt(@Nonnull String key, boolean value);
default B opt(@Nonnull String key, boolean value) {
return opt(key, Boolean.toString(value));
}

/**
* Set optional int parameter for the Builder.
Expand All @@ -88,7 +90,9 @@ public interface FSBuilder<S, B extends FSBuilder<S, B>> {
* @return generic type B.
* @see #opt(String, String)
*/
B opt(@Nonnull String key, int value);
default B opt(@Nonnull String key, int value) {
return optLong(key, value);
}

/**
* This parameter is converted to a long and passed
Expand All @@ -102,7 +106,9 @@ public interface FSBuilder<S, B extends FSBuilder<S, B>> {
* @deprecated use {@link #optDouble(String, double)}
*/
@Deprecated
B opt(@Nonnull String key, float value);
default B opt(@Nonnull String key, float value) {
return optLong(key, (long) value);
}

/**
* Set optional long parameter for the Builder.
Expand All @@ -112,7 +118,9 @@ public interface FSBuilder<S, B extends FSBuilder<S, B>> {
* @return generic type B.
* @deprecated use {@link #optLong(String, long)} where possible.
*/
B opt(@Nonnull String key, long value);
default B opt(@Nonnull String key, long value) {
return optLong(key, value);
}

/**
* Pass an optional double parameter for the Builder.
Expand All @@ -126,7 +134,9 @@ public interface FSBuilder<S, B extends FSBuilder<S, B>> {
* @deprecated use {@link #optDouble(String, double)}
*/
@Deprecated
B opt(@Nonnull String key, double value);
default B opt(@Nonnull String key, double value) {
return optLong(key, (long) value);
}

/**
* Set an array of string values as optional parameter for the Builder.
Expand All @@ -146,7 +156,9 @@ public interface FSBuilder<S, B extends FSBuilder<S, B>> {
* @return generic type B.
* @see #opt(String, String)
*/
B optLong(@Nonnull String key, long value);
default B optLong(@Nonnull String key, long value) {
return opt(key, Long.toString(value));
}

/**
* Set optional double parameter for the Builder.
Expand All @@ -156,7 +168,9 @@ public interface FSBuilder<S, B extends FSBuilder<S, B>> {
* @return generic type B.
* @see #opt(String, String)
*/
B optDouble(@Nonnull String key, double value);
default B optDouble(@Nonnull String key, double value) {
return opt(key, Double.toString(value));
}

/**
* Set mandatory option to the Builder.
Expand All @@ -178,7 +192,9 @@ public interface FSBuilder<S, B extends FSBuilder<S, B>> {
* @return generic type B.
* @see #must(String, String)
*/
B must(@Nonnull String key, boolean value);
default B must(@Nonnull String key, boolean value) {
return must(key, Boolean.toString(value));
}

/**
* Set mandatory int option.
Expand All @@ -188,7 +204,9 @@ public interface FSBuilder<S, B extends FSBuilder<S, B>> {
* @return generic type B.
* @see #must(String, String)
*/
B must(@Nonnull String key, int value);
default B must(@Nonnull String key, int value) {
return mustLong(key, value);
}

/**
* This parameter is converted to a long and passed
Expand All @@ -201,7 +219,9 @@ public interface FSBuilder<S, B extends FSBuilder<S, B>> {
* @deprecated use {@link #mustDouble(String, double)} to set floating point.
*/
@Deprecated
B must(@Nonnull String key, float value);
default B must(@Nonnull String key, float value) {
return mustLong(key, (long) value);
}

/**
* Set mandatory long option.
Expand All @@ -212,7 +232,9 @@ public interface FSBuilder<S, B extends FSBuilder<S, B>> {
* @see #must(String, String)
*/
@Deprecated
B must(@Nonnull String key, long value);
default B must(@Nonnull String key, long value) {
return mustLong(key, (long) value);
}

/**
* Set mandatory long option, despite passing in a floating
Expand All @@ -224,7 +246,9 @@ public interface FSBuilder<S, B extends FSBuilder<S, B>> {
* @see #must(String, String)
*/
@Deprecated
B must(@Nonnull String key, double value);
default B must(@Nonnull String key, double value) {
return mustLong(key, (long) value);
}

/**
* Set a string array as mandatory option.
Expand All @@ -244,7 +268,9 @@ public interface FSBuilder<S, B extends FSBuilder<S, B>> {
* @return generic type B.
* @see #opt(String, String)
*/
B mustLong(@Nonnull String key, long value);
default B mustLong(@Nonnull String key, long value) {
return must(key, Long.toString(value));
}

/**
* Set mandatory double parameter for the Builder.
Expand All @@ -254,7 +280,9 @@ public interface FSBuilder<S, B extends FSBuilder<S, B>> {
* @return generic type B.
* @see #opt(String, String)
*/
B mustDouble(@Nonnull String key, double value);
default B mustDouble(@Nonnull String key, double value) {
return must(key, Double.toString(value));
}

/**
* Instantiate the object which was being built.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,12 @@ public B opt(@Nonnull final String key, boolean value) {
* @see #opt(String, String)
*/
@Override
public final B opt(@Nonnull final String key, int value) {
public B opt(@Nonnull final String key, int value) {
return optLong(key, value);
}

@Override
public final B opt(@Nonnull final String key, final long value) {
public B opt(@Nonnull final String key, final long value) {
return optLong(key, value);
}

Expand All @@ -210,7 +210,7 @@ public B optLong(@Nonnull final String key, final long value) {
* @see #opt(String, String)
*/
@Override
public final B opt(@Nonnull final String key, float value) {
public B opt(@Nonnull final String key, float value) {
return optLong(key, (long) value);
}

Expand All @@ -220,7 +220,7 @@ public final B opt(@Nonnull final String key, float value) {
* @see #opt(String, String)
*/
@Override
public final B opt(@Nonnull final String key, double value) {
public B opt(@Nonnull final String key, double value) {
return optLong(key, (long) value);
}

Expand Down Expand Up @@ -291,22 +291,22 @@ public B mustDouble(@Nonnull final String key, double value) {
* @see #must(String, String)
*/
@Override
public final B must(@Nonnull final String key, int value) {
public B must(@Nonnull final String key, int value) {
return mustLong(key, value);
}

@Override
public final B must(@Nonnull final String key, final long value) {
public B must(@Nonnull final String key, final long value) {
return mustLong(key, value);
}

@Override
public final B must(@Nonnull final String key, final float value) {
public B must(@Nonnull final String key, final float value) {
return mustLong(key, (long) value);
}

@Override
public final B must(@Nonnull final String key, double value) {
public B must(@Nonnull final String key, double value) {
return mustLong(key, (long) value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@

import java.io.IOException;

import javax.annotation.Nonnull;

import org.junit.Test;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSBuilder;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.impl.AbstractFSBuilderImpl;
import org.apache.hadoop.fs.impl.FSBuilderSupport;
import org.apache.hadoop.test.AbstractHadoopTestBase;

Expand Down Expand Up @@ -127,18 +128,45 @@ private interface SimpleBuilder
extends FSBuilder<FSBuilderSupport, SimpleBuilder> {
}

/**
* This is a minimal builder which relies on default implementations of the interface.
* If it ever stops compiling, it means a new interface has been added which
* is not backwards compatible with external implementations, such as that
* in HBoss (see HBASE-26483).
*
*/
private static final class BuilderImpl
extends AbstractFSBuilderImpl<FSBuilderSupport, SimpleBuilder>
implements SimpleBuilder {
private final Configuration options = new Configuration(false);

private BuilderImpl() {
super(new Path("/"));
@Override
public SimpleBuilder opt(@Nonnull final String key, @Nonnull final String value) {
options.set(key, value);
return this;
}

@Override
public SimpleBuilder opt(@Nonnull final String key, @Nonnull final String... values) {
options.setStrings(key, values);
return this;
}

@Override
public SimpleBuilder must(@Nonnull final String key, @Nonnull final String value) {
return opt(key, value);
}

@Override
public SimpleBuilder must(@Nonnull final String key, @Nonnull final String... values) {
return opt(key, values);
}

@Override
public FSBuilderSupport build()
throws IOException {
return new FSBuilderSupport(getOptions());
throws IllegalArgumentException, UnsupportedOperationException, IOException {
return new FSBuilderSupport(options);
}
}


}