Skip to content

Commit

Permalink
Reformatted Range.java
Browse files Browse the repository at this point in the history
  • Loading branch information
khmarbaise committed Apr 28, 2019
1 parent 52d9d99 commit 86c8081
Showing 1 changed file with 80 additions and 75 deletions.
155 changes: 80 additions & 75 deletions jenkins-client/src/main/java/com/offbytwo/jenkins/helper/Range.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,122 +16,127 @@
* The same as {0,N}.</li>
* <li>{N}: Just retrieve the N-th element. The same as {N,N+1}.</li>
* </ul>
*
* <p>
* You can use the {@link Range} class like this:
*
*
* <pre>
* Range fromAndTo = Range.build().from(1).to(5);
* Range fromOnly = Range.build().from(3).build();
* Range toOnly = Range.build().to(5).build();
* Range only = Range.build().only(3);
* </pre>
*
* @author Karl Heinz Marbaise
*
* @author Karl Heinz Marbaise
*/
public final class Range {

public static final String CURLY_BRACKET_OPEN = "%7B"; // {
public static final String CURLY_BRACKET_CLOSE = "%7D"; // }
/**
* This represents {@code &#123;} (left curly bracket).
*/
public static final String CURLY_BRACKET_OPEN = "%7B";
/**
* This represents {@code &#125;} (right curly bracket).
*/
public static final String CURLY_BRACKET_CLOSE = "%7D";

private Integer from;
private Integer to;

private Range() {
this.from = null;
this.to = null;
this.from = null;
this.to = null;
}

private Range setFrom(int from) {
if (from < 0) {
throw new IllegalArgumentException("from value must be greater or equal null.");
}
this.from = new Integer(from);
return this;
if (from < 0) {
throw new IllegalArgumentException("from value must be greater or equal null.");
}
this.from = new Integer(from);
return this;
}

private Range setTo(int to) {
if (to < 0) {
throw new IllegalArgumentException("to must be greater or equal null.");
}
this.to = new Integer(to);
return this;
if (to < 0) {
throw new IllegalArgumentException("to must be greater or equal null.");
}
this.to = new Integer(to);
return this;
}

public String getRangeString() {
StringBuilder sb = new StringBuilder();
sb.append(CURLY_BRACKET_OPEN);
if (this.from != null) {
sb.append(String.format("%d", this.from));
}
StringBuilder sb = new StringBuilder();
sb.append(CURLY_BRACKET_OPEN);
if (this.from != null) {
sb.append(String.format("%d", this.from));
}

sb.append(',');
sb.append(',');

if (this.to != null) {
sb.append(String.format("%d", this.to));
}
if (this.to != null) {
sb.append(String.format("%d", this.to));
}

sb.append(CURLY_BRACKET_CLOSE);
return sb.toString();
sb.append(CURLY_BRACKET_CLOSE);
return sb.toString();
}

public static final class FromBuilder {
private Range range;

public FromBuilder(Range range) {
this.range = range;
}

public Range to(int t) {
this.range.setTo(t);
if (range.to <= range.from) {
throw new IllegalArgumentException("to must be greater than from");
}
return this.range;
}

public Range build() {
return this.range;
}
private Range range;

public FromBuilder(Range range) {
this.range = range;
}

public Range to(int t) {
this.range.setTo(t);
if (range.to <= range.from) {
throw new IllegalArgumentException("to must be greater than from");
}
return this.range;
}

public Range build() {
return this.range;
}
}

public static final class ToBuilder {
private Range range;
private Range range;

public ToBuilder(Range range) {
this.range = range;
}
public ToBuilder(Range range) {
this.range = range;
}

public Range build() {
return this.range;
}
public Range build() {
return this.range;
}
}

public static final class Builder {
private Range range;

protected Builder() {
this.range = new Range();
}

public FromBuilder from(int f) {
this.range.setFrom(f);
return new FromBuilder(this.range);
}

public ToBuilder to(int t) {
this.range.setTo(t);
return new ToBuilder(this.range);
}

public Range only(int only) {
this.range.from = new Integer(only);
this.range.to = new Integer(only + 1);
return this.range;
}
private Range range;

protected Builder() {
this.range = new Range();
}

public FromBuilder from(int f) {
this.range.setFrom(f);
return new FromBuilder(this.range);
}

public ToBuilder to(int t) {
this.range.setTo(t);
return new ToBuilder(this.range);
}

public Range only(int only) {
this.range.from = new Integer(only);
this.range.to = new Integer(only + 1);
return this.range;
}
}

public static Builder build() {
return new Builder();
return new Builder();
}
}

0 comments on commit 86c8081

Please sign in to comment.