diff --git a/src/main/java/org/apache/commons/lang3/builder/Builder.java b/src/main/java/org/apache/commons/lang3/builder/Builder.java new file mode 100644 index 000000000..10da0b35c --- /dev/null +++ b/src/main/java/org/apache/commons/lang3/builder/Builder.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.lang3.builder; + +/** + *
+ * The Builder interface is designed to designate a class as a builder + * object in the Builder design pattern. Builders are capable of creating and + * configuring objects or results that normally take multiple steps to construct + * or are very complex to derive. + *
+ * + *+ * The builder interface defines a single method, {@link #build()}, that + * classes must implement. The result of this method should be the final + * configured object or result after all building operations are performed. + *
+ * + *
+ * It is a recommended practice that the methods supplied to configure the
+ * object or result being built return a reference to this
so that
+ * method calls can be chained together.
+ *
+ * Example Builder:
+ *
+ *
+ * Example Builder Usage:
+ *
+ * class FontBuilder implements Builder<Font> {
+ * private Font font;
+ *
+ * public FontBuilder(String fontName) {
+ * this.font = new Font(fontName, Font.PLAIN, 12);
+ * }
+ *
+ * public FontBuilder bold() {
+ * this.font = this.font.deriveFont(Font.BOLD);
+ * return this; // Reference returned so calls can be chained
+ * }
+ *
+ * public FontBuilder size(float pointSize) {
+ * this.font = this.font.deriveFont(pointSize);
+ * return this; // Reference returned so calls can be chained
+ * }
+ *
+ * // Other Font construction methods
+ *
+ * public Font build() {
+ * return this.font;
+ * }
+ * }
+ *
+ *
+ * Font bold14ptSansSerifFont = new FontBuilder(Font.SANS_SERIF).bold()
+ * .size(14.0f)
+ * .build();
+ *
builder
has judged the "left-hand" side
+ * as less than, greater than, or equal to the "right-hand"
+ * side.
+ *
+ * @return final comparison result
+ *
+ * @since 3.0
+ */
+ public Integer build() {
+ return toComparison();
+ }
}
diff --git a/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java b/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java
index c725cfffd..7db4a0708 100644
--- a/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java
+++ b/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java
@@ -86,7 +86,7 @@ import org.apache.commons.lang3.Pair;
* @since 1.0
* @version $Id$
*/
-public class EqualsBuilder {
+public class EqualsBuilder implements Builder@@ -968,6 +968,19 @@ public class EqualsBuilder { public boolean isEquals() { return this.isEquals; } + + /** + *
Returns true
if the fields that have been checked
+ * are all equal.
true
if all of the fields that have been checked
+ * are equal, false
otherwise.
+ *
+ * @since 3.0
+ */
+ public Boolean build() {
+ return isEquals();
+ }
/**
* Sets the isEquals
value.
diff --git a/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java b/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java
index c6fe82c27..290e70936 100644
--- a/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java
+++ b/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java
@@ -93,7 +93,7 @@ import org.apache.commons.lang3.ArrayUtils;
* @since 1.0
* @version $Id$
*/
-public class HashCodeBuilder {
+public class HashCodeBuilder implements Builder
* A registry of objects used by reflection methods to detect cyclical object references and avoid infinite loops.
@@ -976,6 +976,17 @@ public class HashCodeBuilder {
public int toHashCode() {
return iTotal;
}
+
+ /**
+ * Returns the computed hashCode
.
+ *
+ * @return hashCode
based on the fields appended
+ *
+ * @since 3.0
+ */
+ public Integer build() {
+ return toHashCode();
+ }
/**
*
diff --git a/src/main/java/org/apache/commons/lang3/builder/ToStringBuilder.java b/src/main/java/org/apache/commons/lang3/builder/ToStringBuilder.java
index c368126b6..cc360c670 100644
--- a/src/main/java/org/apache/commons/lang3/builder/ToStringBuilder.java
+++ b/src/main/java/org/apache/commons/lang3/builder/ToStringBuilder.java
@@ -89,7 +89,7 @@ import org.apache.commons.lang3.ObjectUtils;
* @since 1.0
* @version $Id$
*/
-public class ToStringBuilder {
+public class ToStringBuilder implements BuildertoString
+ *
+ * @see #toString()
+ *
+ * @since 3.0
+ */
+ public String build() {
+ return toString();
+ }
}
diff --git a/src/main/java/org/apache/commons/lang3/concurrent/BasicThreadFactory.java b/src/main/java/org/apache/commons/lang3/concurrent/BasicThreadFactory.java
index 7ba8cf206..e2441334a 100644
--- a/src/main/java/org/apache/commons/lang3/concurrent/BasicThreadFactory.java
+++ b/src/main/java/org/apache/commons/lang3/concurrent/BasicThreadFactory.java
@@ -250,7 +250,9 @@ public class BasicThreadFactory implements ThreadFactory {
*
* @version $Id: $
*/
- public static class Builder {
+ public static class Builder
+ implements org.apache.commons.lang3.builder.Builder