This is an automated email from the ASF dual-hosted git repository.
jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git
The following commit(s) were added to refs/heads/master by this push:
new 716f493 Clean up unused code.
716f493 is described below
commit 716f493ac7b6fbd7302f7836f893f41eb92a888d
Author: JamesBognar <[email protected]>
AuthorDate: Fri Oct 15 16:32:16 2021 -0400
Clean up unused code.
---
.../main/java/org/apache/juneau/config/Config.java | 8 +-
.../java/org/apache/juneau/AnnotationApplier.java | 48 +++
.../main/java/org/apache/juneau/BeanContext.java | 5 +-
.../java/org/apache/juneau/BeanContextable.java | 4 +
.../src/main/java/org/apache/juneau/BeanMeta.java | 1 +
.../src/main/java/org/apache/juneau/ClassMeta.java | 1 +
.../main/java/org/apache/juneau/ListOperation.java | 33 +-
.../java/org/apache/juneau/PropertyConverter.java | 95 ------
.../main/java/org/apache/juneau/Streamable.java | 39 ---
.../src/main/java/org/apache/juneau/Writable.java | 40 ---
.../apache/juneau/annotation/AnnotationImpl.java | 9 +-
.../org/apache/juneau/annotation/ContextApply.java | 2 +
.../assertions/FluentThrowableAssertion.java | 3 +-
.../apache/juneau/{ => cp}/ContextBeanCreator.java | 4 +-
.../http/remote/RrpcInterfaceMethodMeta.java | 27 +-
.../org/apache/juneau/httppart/HttpPartParser.java | 1 +
.../apache/juneau/httppart/HttpPartSerializer.java | 1 +
.../juneau/httppart/SimplePartParserSession.java | 4 +-
.../juneau/httppart/SimplePartSerializer.java | 4 +-
.../httppart/SimplePartSerializerSession.java | 4 +-
.../apache/juneau/internal/AnnotationUtils.java | 78 +----
.../org/apache/juneau/internal/ArrayUtils.java | 225 -------------
.../juneau/internal/ByteArrayInOutStream.java | 30 --
.../org/apache/juneau/internal/ClassUtils.java | 81 +----
.../apache/juneau/internal/CollectionUtils.java | 85 -----
.../java/org/apache/juneau/internal/DateUtils.java | 82 -----
.../java/org/apache/juneau/internal/HttpUtils.java | 28 --
.../org/apache/juneau/internal/ObjectUtils.java | 101 ------
.../org/apache/juneau/{ => internal}/Setter.java | 4 +-
.../org/apache/juneau/internal/StringUtils.java | 356 +--------------------
.../org/apache/juneau/internal/ThrowableUtils.java | 18 +-
.../{utils => internal}/TwoKeyConcurrentCache.java | 2 +-
.../jsonschema/JsonSchemaGeneratorSession.java | 4 +-
.../java/org/apache/juneau/reflect/ClassInfo.java | 23 +-
.../java/org/apache/juneau/reflect/Mutaters.java | 39 +++
.../apache/juneau/uon/UonSerializerSession.java | 5 +-
.../main/java/org/apache/juneau/utils/BeanRef.java | 87 -----
.../org/apache/juneau/utils/StackTraceUtils.java | 40 ---
.../microservice/resources/LogEntryFormatter.java | 2 +-
.../juneau/rest/BasicSwaggerProviderSession.java | 5 +-
.../org/apache/juneau/rest/remote/RrpcServlet.java | 4 +-
.../apache/juneau/config/ConfigBuilderTest.java | 2 +-
.../java/org/apache/juneau/config/ConfigTest.java | 2 -
.../apache/juneau/rest/util/RestUtils_Test.java | 16 -
.../org/apache/juneau/utils/ArrayUtilsTest.java | 85 -----
.../juneau/utils/ByteArrayInOutStreamTest.java | 38 ---
.../org/apache/juneau/utils/StringUtilsTest.java | 80 +----
47 files changed, 210 insertions(+), 1645 deletions(-)
diff --git
a/juneau-core/juneau-config/src/main/java/org/apache/juneau/config/Config.java
b/juneau-core/juneau-config/src/main/java/org/apache/juneau/config/Config.java
index 029efe5..98a5313 100644
---
a/juneau-core/juneau-config/src/main/java/org/apache/juneau/config/Config.java
+++
b/juneau-core/juneau-config/src/main/java/org/apache/juneau/config/Config.java
@@ -46,7 +46,7 @@ import org.apache.juneau.svl.*;
* <li class='extlink'>{@source}
* </ul>
*/
-public final class Config extends Context implements ConfigEventListener,
Writable {
+public final class Config extends Context implements ConfigEventListener {
//-----------------------------------------------------------------------------------------------------------------
// Static
@@ -1806,7 +1806,6 @@ public final class Config extends Context implements
ConfigEventListener, Writab
* @return This object (for method chaining).
* @throws IOException If a problem occurred trying to send contents to
the writer.
*/
- @Override /* Writable */
public Writer writeTo(Writer w) throws IOException {
return configMap.writeTo(w);
}
@@ -1921,11 +1920,6 @@ public final class Config extends Context implements
ConfigEventListener, Writab
l.onConfigChange(events);
}
- @Override /* Writable */
- public String getMediaType() {
- return "text/plain";
- }
-
//-----------------------------------------------------------------------------------------------------------------
// Private methods
//-----------------------------------------------------------------------------------------------------------------
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/AnnotationApplier.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/AnnotationApplier.java
index afd086d..47705fc 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/AnnotationApplier.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/AnnotationApplier.java
@@ -28,6 +28,54 @@ import org.apache.juneau.svl.*;
/**
* Class used to add properties to a context builder (e.g. {@link
BeanContext.Builder}) from an annotation (e.g. {@link BeanConfig}).
*
+ * <p>
+ * Used by {@link Context.Builder#applyAnnotations(Class...)} and {@link
Context.Builder#applyAnnotations(java.lang.reflect.Method...)} to apply
+ * annotations to context beans.
+ *
+ * <p>
+ * The following code shows the general design pattern.
+ *
+ * <p class 'bcode w800'>
+ * <jc>// The annotation applied to classes and methods.</jc>
+ * <ja>@Target</ja>({METHOD,TYPE})
+ * <ja>@Retention</ja>(<jsf>RUNTIME</jsf>)
+ * <ja>@ContextApply</ja>(BeanConfigAnnotationApplier.<jk>class</jk>)
+ * <jk>public</jk> <jk>@interface </jk>BeanConfig {
+ *
+ * String sortProperties() <jk>default</jk> <js>""</js>;
+ *
+ * }
+ *
+ * <jc>// The applier that applies the annotation to the bean context
builder.</jc>
+ * <jk>public class</jk> BeanConfigAnnotationApplier <jk>extends</jk>
AnnotationApplier<<ja>BeanConfig</ja>,BeanContext.Builder> {
+ *
+ * <jc>// Required constructor. </jc>
+ * <jk>public</jk> Applier(VarResolverSession <jv>vr</jv>) {
+ * <jk>super</jk>(BeanConfig.<jk>class</jk>,
BeanContext.Builder.<jk>class</jk>, <jv>vr</jv>);
+ * }
+ *
+ * <ja>@Override</ja>
+ * <jk>public void</jk> apply(AnnotationInfo<BeanConfig>
<jv>annotationInfo</jv>, BeanContext.Builder <jv>builder</jv>) {
+ * <ja>BeanConfig</ja> <jv>beanConfig</jv> =
<jv>annotationInfo</jv>.getAnnotation();
+ *
+ * String <jv>sortProperties</jv> =
<jv>beanConfig</jv>.sortProperties();
+ * <jk>if</jk> (! <jv>sortProperties</jv>.isEmpty())
+ *
<jv>builder</jv>.sortProperties(Boolean.<jsm>parseBoolean</jsm>(<jv>sortProperties</jv>));
+ * }
+ * }
+ *
+ * <jc>// An annotated class.</jc>
+ * <ja>@BeanConfig</ja>(sortProperties=<js>"true"</js>)
+ * <jk>public class</jk> AnnotatedClass {}
+ *
+ * <jc>// Putting it together.</jc>
+ * <jk>public static void</jk> main(String[] <jv>args</jv>) {
+ *
+ * <jc>// Create a JSON serializer with sorted properties.</jc>
+ * Serializer <jv>serializer</jv> =
JsonSerializer.<jsm>create</jsm>().applyAnnotations(AnnotatedClass.<jk>class</jk>).build();
+ * }
+ * </p>
+ *
* @param <A> The annotation that this applier reads from.
* @param <B> The builder class to apply the annotation to.
*/
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanContext.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanContext.java
index e9116a9..9850c5a 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanContext.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanContext.java
@@ -41,8 +41,7 @@ import org.apache.juneau.transform.*;
import org.apache.juneau.utils.*;
/**
- * Core class of the Juneau architecture.
- * {@review}
+ * Bean context.
*
* <p class='w800'>
* This class servers multiple purposes:
@@ -55,7 +54,7 @@ import org.apache.juneau.utils.*;
* </ul>
*
* <p class='w800'>
- * All serializers and parsers extend from this context so that they can
handle POJOs using a common framework.
+ * All serializers and parsers use this context so that they can handle POJOs
using a common framework.
*
* <h5 class='topic'>Bean Contexts</h5>
*
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanContextable.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanContextable.java
index 17ba0cb..68bc742 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanContextable.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanContextable.java
@@ -31,6 +31,10 @@ import org.apache.juneau.utils.*;
/**
* Context class for classes that use {@link BeanContext} objects.
+ *
+ * <p>
+ * This abstraction exists to allow different kinds of subclasses (e.g.
JsonSerilalizer, XmlParser...) to share bean context objects since
+ * bean context objects are heavyweight objects that cache metadata about
encountered beans.
*/
public abstract class BeanContextable extends Context {
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMeta.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMeta.java
index 77d8882..bc3d00f 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMeta.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMeta.java
@@ -14,6 +14,7 @@ package org.apache.juneau;
import static org.apache.juneau.internal.CollectionUtils.*;
import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.internal.ThrowableUtils.*;
import static org.apache.juneau.internal.ObjectUtils.*;
import static org.apache.juneau.reflect.ReflectFlags.*;
import static org.apache.juneau.BeanMeta.MethodType.*;
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
index 5a98980..373af41 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
@@ -33,6 +33,7 @@ import java.util.concurrent.locks.*;
import org.apache.juneau.annotation.*;
import org.apache.juneau.collections.*;
import org.apache.juneau.http.header.*;
+import org.apache.juneau.internal.*;
import org.apache.juneau.json.*;
import org.apache.juneau.reflect.*;
import org.apache.juneau.transform.*;
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ListOperation.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ListOperation.java
index 3ccfebc..ad19f52 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ListOperation.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ListOperation.java
@@ -12,8 +12,6 @@
//
***************************************************************************************************************************
package org.apache.juneau;
-import java.util.*;
-
/**
* Identifies how to add elements to a list.
* {@reviewed}
@@ -38,34 +36,5 @@ public enum ListOperation {
/**
* Elements should be added as default values that are added to the
list if they're not already set.
*/
- DEFAULT,
-
- /**
- * Don't add the value if it's <jk>null</jk> or an empty string.
- */
- @Deprecated
- SKIP_IF_EMPTY;
-
- /**
- * Default flags.
- */
- @Deprecated
- public static final EnumSet<ListOperation> DEFAULT_FLAGS =
EnumSet.of(APPEND);
-
- /**
- * Default skip-if-empty flags.
- */
- @Deprecated
- public static final EnumSet<ListOperation> SKIP_IF_EMPTY_FLAGS =
EnumSet.of(APPEND, SKIP_IF_EMPTY);
-
- /**
- * Returns {@link #DEFAULT_FLAGS} if the enum set is <jk>null</jk> or
empty.
- *
- * @param s The set to check.
- * @return Either the same set or {@link #DEFAULT_FLAGS}. Never
<jk>null</jk>.
- */
- @Deprecated
- public static EnumSet<ListOperation> orDefault(EnumSet<ListOperation>
s) {
- return s == null || s.isEmpty() ? DEFAULT_FLAGS : s;
- }
+ DEFAULT;
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/PropertyConverter.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/PropertyConverter.java
deleted file mode 100644
index 989d0e1..0000000
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/PropertyConverter.java
+++ /dev/null
@@ -1,95 +0,0 @@
-//
***************************************************************************************************************************
-// * 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.juneau;
-
-import org.apache.juneau.internal.*;
-
-/**
- * Used to convert property values to standardized
Boolean/Integer/Class/Object values in property store builders.
- *
- * @param <T> The normalized form.
- */
-public interface PropertyConverter<T> {
-
- /**
- * Convert the value to normalized form.
- *
- * @param o The raw value.
- * @return The converted value.
- */
- T convert(Object o);
-
- /**
- * Converts objects to strings.
- */
- static final PropertyConverter<String> STRING_CONVERTER = new
PropertyConverter<String>() {
- @Override
- public String convert(Object o) {
- return ClassUtils.toString(o);
- }
- };
-
- /**
- * Converts objects to integers.
- */
- static final PropertyConverter<Integer> INTEGER_CONVERTER = new
PropertyConverter<Integer>() {
- @Override
- public Integer convert(Object o) {
- try {
- if (o instanceof Integer)
- return (Integer)o;
- return Integer.valueOf(o.toString());
- } catch (Exception e) {
- throw new ConfigException("Value ''{0}'' ({1})
cannot be converted to an Integer.", o, o.getClass().getSimpleName());
- }
- }
- };
-
- /**
- * Converts objects to booleans.
- */
- static final PropertyConverter<Boolean> BOOLEAN_CONVERTER = new
PropertyConverter<Boolean>() {
- @Override
- public Boolean convert(Object o) {
- if (o instanceof Boolean)
- return (Boolean)o;
- return Boolean.parseBoolean(o.toString());
- }
- };
-
- /**
- * Converts objects to classes.
- */
- static final PropertyConverter<Class<?>> CLASS_CONVERTER = new
PropertyConverter<Class<?>>() {
- @Override
- public Class<?> convert(Object o) {
- try {
- if (o instanceof Class)
- return (Class<?>)o;
- throw new ConfigException("Value ''{0}'' ({1})
cannot be converted to a Class.", o, o.getClass().getSimpleName());
- } catch (Exception e) {
- throw new ConfigException("Value ''{0}'' ({1})
cannot be converted to a Class.", o, o.getClass().getSimpleName());
- }
- }
- };
-
- /**
- * Converts objects to objects.
- */
- static final PropertyConverter<Object> OBJECT_CONVERTER = new
PropertyConverter<Object>() {
- @Override
- public Object convert(Object o) {
- return o;
- }
- };
-}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Streamable.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Streamable.java
deleted file mode 100644
index c6ae548..0000000
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Streamable.java
+++ /dev/null
@@ -1,39 +0,0 @@
-//
***************************************************************************************************************************
-// * 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.juneau;
-
-import java.io.*;
-
-/**
- * Interface that identifies that an object can be serialized directly to an
output stream.
- *
- * <p>
- * Instances must identify the media type of the content by implementing the
{@link #getMediaType()} method.
- */
-public interface Streamable {
-
- /**
- * Serialize this object to the specified output stream.
- *
- * @param os The output stream to stream to.
- * @throws IOException Thrown by underlying stream.
- */
- void streamTo(OutputStream os) throws IOException;
-
- /**
- * Returns the serialized media type for this resource (e.g.
<js>"text/html"</js>).
- *
- * @return The media type, or <jk>null</jk> if the media type is not
known.
- */
- String getMediaType();
-}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Writable.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Writable.java
deleted file mode 100644
index 3ef14a0..0000000
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Writable.java
+++ /dev/null
@@ -1,40 +0,0 @@
-//
***************************************************************************************************************************
-// * 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.juneau;
-
-import java.io.*;
-
-/**
- * Interface that identifies that an object can be serialized directly to a
writer.
- *
- * <p>
- * Instances must identify the media type of the content by implementing the
{@link #getMediaType()} method.
- */
-public interface Writable {
-
- /**
- * Serialize this object to the specified writer.
- *
- * @param w The writer to write to.
- * @return The same writer passed in.
- * @throws IOException Thrown by underlying stream.
- */
- Writer writeTo(Writer w) throws IOException;
-
- /**
- * Returns the serialized media type for this resource (e.g.
<js>"text/html"</js>)
- *
- * @return The media type, or <jk>null</jk> if the media type is not
known.
- */
- String getMediaType();
-}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/AnnotationImpl.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/AnnotationImpl.java
index 9e01c57..dc0bfa6 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/AnnotationImpl.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/AnnotationImpl.java
@@ -14,10 +14,12 @@ package org.apache.juneau.annotation;
import static org.apache.juneau.internal.ExceptionUtils.*;
import static org.apache.juneau.internal.ThrowableUtils.*;
-import static org.apache.juneau.internal.AnnotationUtils.*;
import static org.apache.juneau.collections.OMap.*;
+import static java.util.Arrays.*;
import java.lang.annotation.*;
+import java.lang.reflect.*;
+import java.util.*;
import org.apache.juneau.collections.*;
import org.apache.juneau.internal.*;
@@ -88,8 +90,9 @@ public class AnnotationImpl implements Annotation {
*/
public OMap toMap() {
OMap om = create();
- getSortedAnnotationMethods(annotationType())
- .stream()
+ stream(annotationType().getDeclaredMethods())
+ .filter(x->x.getParameterCount() == 0 &&
x.getDeclaringClass().isAnnotation())
+ .sorted(Comparator.comparing(Method::getName))
.forEach(x -> om.a(x.getName(),
safeSupplier(()->x.invoke(this))));
return om;
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/ContextApply.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/ContextApply.java
index 410c0eb..1730b68 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/ContextApply.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/ContextApply.java
@@ -21,6 +21,8 @@ import org.apache.juneau.*;
/**
* Applied to Config annotations to identify the class used to push the values
into a property store.
+ *
+ * @see AnnotationApplier
*/
@Documented
@Target({ANNOTATION_TYPE})
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentThrowableAssertion.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentThrowableAssertion.java
index c290aae..90f097e 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentThrowableAssertion.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentThrowableAssertion.java
@@ -14,6 +14,7 @@ package org.apache.juneau.assertions;
import static org.apache.juneau.assertions.Assertions.*;
import static java.util.Collections.*;
+import static org.apache.juneau.internal.ThrowableUtils.*;
import java.io.*;
import java.util.*;
@@ -239,7 +240,7 @@ public class FluentThrowableAssertion<T extends
Throwable,R> extends FluentObjec
* @return An assertion against the throwable stacktrace. Never
<jk>null</jk>.
*/
public FluentStringListAssertion<R> stackTrace() {
- return new FluentStringListAssertion<>(this, valueIsNull() ?
null : Arrays.asList(StringUtils.getStackTrace(value())), returns());
+ return new FluentStringListAssertion<>(this, valueIsNull() ?
null : Arrays.asList(getStackTrace(value())), returns());
}
/**
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ContextBeanCreator.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/ContextBeanCreator.java
similarity index 98%
rename from
juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ContextBeanCreator.java
rename to
juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/ContextBeanCreator.java
index b7d7d8c..8bd16e9 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ContextBeanCreator.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/ContextBeanCreator.java
@@ -10,7 +10,7 @@
// * "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.juneau;
+package org.apache.juneau.cp;
import static org.apache.juneau.internal.ExceptionUtils.*;
import static java.util.Optional.*;
@@ -18,6 +18,8 @@ import static java.util.Optional.*;
import java.util.*;
import java.util.function.*;
+import org.apache.juneau.*;
+
/**
* Utility class for instantiating a Context bean.
*
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/remote/RrpcInterfaceMethodMeta.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/remote/RrpcInterfaceMethodMeta.java
index 1748759..d283858 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/remote/RrpcInterfaceMethodMeta.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/remote/RrpcInterfaceMethodMeta.java
@@ -16,7 +16,7 @@ import static org.apache.juneau.internal.StringUtils.*;
import java.lang.reflect.*;
-import org.apache.juneau.internal.*;
+import org.apache.juneau.reflect.*;
/**
* Contains the meta-data about a Java method on a remote class.
@@ -41,11 +41,34 @@ public class RrpcInterfaceMethodMeta {
*/
public RrpcInterfaceMethodMeta(final String restUrl, Method m) {
this.method = m;
- this.path = m.getName() + '/' +
HttpUtils.getMethodArgsSignature(m, true);
+ this.path = m.getName() + '/' + getMethodArgsSignature(m);
this.url = trimSlashes(restUrl) + '/' + urlEncode(path);
}
/**
+ * Given a Java method, returns the arguments signature.
+ *
+ * @param m The Java method.
+ * @param full Whether fully-qualified names should be used for
arguments.
+ * @return The arguments signature for the specified method.
+ */
+ private static String getMethodArgsSignature(Method m) {
+ StringBuilder sb = new StringBuilder(128);
+ Class<?>[] pt = m.getParameterTypes();
+ if (pt.length == 0)
+ return "";
+ sb.append('(');
+ for (int i = 0; i < pt.length; i++) {
+ ClassInfo pti = ClassInfo.of(pt[i]);
+ if (i > 0)
+ sb.append(',');
+ pti.appendFullName(sb);
+ }
+ sb.append(')');
+ return sb.toString();
+ }
+
+ /**
* Returns the absolute URL of the REST interface invoked by this Java
method.
*
* @return The absolute URL of the REST interface, never <jk>null</jk>.
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/HttpPartParser.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/HttpPartParser.java
index 9b32131..ccc2b67 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/HttpPartParser.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/HttpPartParser.java
@@ -15,6 +15,7 @@ package org.apache.juneau.httppart;
import java.lang.reflect.*;
import org.apache.juneau.*;
+import org.apache.juneau.cp.*;
/**
* Interface used to convert HTTP headers, query parameters, form-data
parameters, and URI path variables to POJOs
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/HttpPartSerializer.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/HttpPartSerializer.java
index 8259b71..4d7c3e0 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/HttpPartSerializer.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/HttpPartSerializer.java
@@ -13,6 +13,7 @@
package org.apache.juneau.httppart;
import org.apache.juneau.*;
+import org.apache.juneau.cp.*;
import org.apache.juneau.http.annotation.*;
/**
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/SimplePartParserSession.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/SimplePartParserSession.java
index 223298b..30aa9fc 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/SimplePartParserSession.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/SimplePartParserSession.java
@@ -13,8 +13,8 @@
package org.apache.juneau.httppart;
import org.apache.juneau.*;
-import org.apache.juneau.internal.*;
import org.apache.juneau.parser.*;
+import org.apache.juneau.reflect.*;
/**
* Session object that lives for the duration of a single use of {@link
SimplePartParser}.
@@ -27,6 +27,6 @@ public class SimplePartParserSession extends
BaseHttpPartParserSession {
@Override /* HttpPartParserSession */
public <T> T parse(HttpPartType partType, HttpPartSchema schema, String
in, ClassMeta<T> toType) throws ParseException, SchemaValidationException {
- return ClassUtils.fromString(toType.getInnerClass(), in);
+ return Mutaters.fromString(toType.getInnerClass(), in);
}
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/SimplePartSerializer.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/SimplePartSerializer.java
index 022a0a8..08fd53e 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/SimplePartSerializer.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/SimplePartSerializer.java
@@ -12,13 +12,13 @@
//
***************************************************************************************************************************
package org.apache.juneau.httppart;
-import org.apache.juneau.internal.*;
+import org.apache.juneau.reflect.*;
/**
* An implementation of {@link HttpPartSerializer} that simply serializes
everything using {@link Object#toString()}.
*
* <p>
- * More precisely, uses the {@link ClassUtils#toString(Object)} method to
stringify objects.
+ * More precisely, uses the {@link Mutaters#toString(Object)} method to
stringify objects.
*/
public class SimplePartSerializer extends BaseHttpPartSerializer {
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/SimplePartSerializerSession.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/SimplePartSerializerSession.java
index 950da2d..232216c 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/SimplePartSerializerSession.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/SimplePartSerializerSession.java
@@ -12,7 +12,7 @@
//
***************************************************************************************************************************
package org.apache.juneau.httppart;
-import org.apache.juneau.internal.*;
+import org.apache.juneau.reflect.*;
/**
* Session object that lives for the duration of a single use of {@link
SimplePartSerializer}.
@@ -29,6 +29,6 @@ public class SimplePartSerializerSession extends
BaseHttpPartSerializerSession {
@Override /* PartSerializer */
public String serialize(HttpPartType type, HttpPartSchema schema,
Object value) {
- return ClassUtils.toString(value);
+ return Mutaters.toString(value);
}
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/AnnotationUtils.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/AnnotationUtils.java
index 356e562..0aa2d85 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/AnnotationUtils.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/AnnotationUtils.java
@@ -12,15 +12,13 @@
//
***************************************************************************************************************************
package org.apache.juneau.internal;
-import static org.apache.juneau.internal.ExceptionUtils.*;
+import static org.apache.juneau.internal.ThrowableUtils.*;
import java.lang.annotation.*;
import java.lang.reflect.*;
import java.util.*;
import java.util.stream.*;
-import org.apache.juneau.reflect.*;
-
/**
* Annotation utilities.
*/
@@ -45,18 +43,11 @@ public class AnnotationUtils {
if (! t1.equals(t2))
return false;
- try {
- for (Method m : getAnnotationMethods(t1)) {
- Object v1 = m.invoke(a1);
- Object v2 = m.invoke(a2);
- if (! memberEquals(m.getReturnType(), v1, v2))
- return false;
- }
- } catch (IllegalAccessException ex) {
- return false;
- } catch (InvocationTargetException ex) {
+ boolean b= getAnnotationMethods(t1)
+ .anyMatch(x -> ! memberEquals(x.getReturnType(),
safeSupplier(()->x.invoke(a1)), safeSupplier(()->x.invoke(a2))));
+ if (b)
return false;
- }
+
return true;
}
@@ -69,51 +60,18 @@ public class AnnotationUtils {
* @throws IllegalStateException if an annotation method invocation
returns {@code null}
*/
public static int hashCode(Annotation a) {
- int result = 0;
- Class<? extends Annotation> t = a.annotationType();
-
- for (Method m : getAnnotationMethods(t)) {
- try {
- Object value = m.invoke(a);
- if (value == null)
- throw new
IllegalStateException(String.format("Annotation method %s returned null", m));
- result += hashMember(m.getName(), value);
- } catch (Exception ex) {
- throw runtimeException(ex);
- }
- }
-
- return result;
+ return getAnnotationMethods(a.annotationType())
+ .mapToInt(x -> hashMember(x.getName(),
safeSupplier(()->x.invoke(a))))
+ .sum();
}
- /**
- * Returns the methods on the specified annotation type.
- *
- * @param type The annotation type.
- * @return The methods on the specified annotation type.
- */
- public static List<Method> getAnnotationMethods(Class<? extends
Annotation> type) {
+ private static Stream<Method> getAnnotationMethods(Class<? extends
Annotation> type) {
return Arrays.asList(type.getDeclaredMethods())
.stream()
.filter(x -> x.getParameterCount() == 0 &&
x.getDeclaringClass().isAnnotation())
- .collect(Collectors.toList())
;
}
- /**
- * Returns the methods on the specified annotation type ordered by
method name.
- *
- * @param type The annotation type.
- * @return The methods on the specified annotation typev.
- */
- public static List<Method> getSortedAnnotationMethods(Class<? extends
Annotation> type) {
- return Arrays.asList(type.getDeclaredMethods())
- .stream()
- .filter(x->x.getParameterCount() == 0 &&
x.getDeclaringClass().isAnnotation())
- .sorted(Comparator.comparing(Method::getName))
- .collect(Collectors.toList());
- }
-
private static int hashMember(String name, Object value) {
int part1 = name.hashCode() * 127;
if (value.getClass().isArray())
@@ -185,22 +143,4 @@ public class AnnotationUtils {
return Arrays.hashCode((boolean[]) o);
return Arrays.hashCode((Object[]) o);
}
-
- /**
- * If the annotation is an array of other annotations, returns the
inner annotations.
- *
- * @param a The annotation to split if repeated.
- * @return The nested annotations, or a singleton array of the same
annotation if it's not repeated.
- */
- public static Annotation[] splitRepeated(Annotation a) {
- try {
- ClassInfo ci = ClassInfo.ofc(a.annotationType());
- MethodInfo mi = ci.getRepeatedAnnotationMethod();
- if (mi != null)
- return mi.invoke(a);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return new Annotation[]{a};
- }
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ArrayUtils.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ArrayUtils.java
index 8891c41..dcf1da4 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ArrayUtils.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ArrayUtils.java
@@ -17,8 +17,6 @@ import static org.apache.juneau.internal.StringUtils.*;
import java.lang.reflect.*;
import java.util.*;
-import org.apache.juneau.reflect.*;
-
/**
* Quick and dirty utilities for working with arrays.
*/
@@ -47,28 +45,6 @@ public final class ArrayUtils {
}
/**
- * Appends one or more elements to an array.
- *
- * @param <T> The element type.
- * @param array The array to append to.
- * @param newElements The new elements to append to the array.
- * @return A new array with the specified elements appended.
- */
- @SuppressWarnings("unchecked")
- public static <T> T[] append(T[] array, Collection<T> newElements) {
- assertArgNotNull("array", array);
- if (newElements.size() == 0)
- return array;
- T[] a =
(T[])Array.newInstance(array.getClass().getComponentType(), array.length +
newElements.size());
- for (int i = 0; i < array.length; i++)
- a[i] = array[i];
- int l = array.length;
- for (T t : newElements)
- a[l++] = t;
- return a;
- }
-
- /**
* Combine an arbitrary number of arrays into a single array.
*
* @param arrays Collection of arrays to combine.
@@ -96,42 +72,6 @@ public final class ArrayUtils {
}
/**
- * Creates a new array with reversed entries.
- *
- * @param <T> The class type of the array.
- * @param array The array to reverse.
- * @return A new array with reversed entries, or <jk>null</jk> if the
array was <jk>null</jk>.
- */
- @SuppressWarnings("unchecked")
- public static <T> T[] reverse(T[] array) {
- if (array == null)
- return null;
- Class<T> c = (Class<T>)array.getClass().getComponentType();
- T[] a2 = (T[])Array.newInstance(c, array.length);
- for (int i = 0; i < array.length; i++)
- a2[a2.length-i-1] = array[i];
- return a2;
- }
-
- /**
- * Sorts the elements in an array without creating a new array.
- *
- * @param array The array to sort.
- * @return The same array.
- */
- public static <T> T[] reverseInline(T[] array) {
- if (array == null)
- return null;
- T t;
- for (int i = 0, j = array.length-1; i < j; i++, j--) {
- t = array[i];
- array[i] = array[j];
- array[j] = t;
- }
- return array;
- }
-
- /**
* Converts the specified array to a <c>Set</c>.
*
* <p>
@@ -276,23 +216,6 @@ public final class ArrayUtils {
}
/**
- * Shortcut for calling <c>myList.toArray(new T[myList.size()]);</c>
- *
- * @param c The collection being converted to an array.
- * @param componentType The component type of the array.
- * @return The collection converted to an array.
- */
- @SuppressWarnings("unchecked")
- public static <T> T[] toObjectArray(Collection<?> c, Class<T>
componentType) {
- Object a = Array.newInstance(componentType, c.size());
- Iterator<?> it = c.iterator();
- int i = 0;
- while (it.hasNext())
- Array.set(a, i++, it.next());
- return (T[])a;
- }
-
- /**
* Copies the specified array into the specified list.
*
* <p>
@@ -313,57 +236,6 @@ public final class ArrayUtils {
}
/**
- * Returns <jk>true</jk> if the specified array contains the specified
element using the {@link Object#equals(Object)}
- * method.
- *
- * @param element The element to check for.
- * @param array The array to check.
- * @return
- * <jk>true</jk> if the specified array contains the specified
element,
- * <jk>false</jk> if the array or element is <jk>null</jk>.
- */
- public static <T> boolean contains(T element, T[] array) {
- return indexOf(element, array) != -1;
- }
-
- /**
- * Returns <jk>true</jk> if the specified array contains the specified
integer
- *
- * @param element The element to check for.
- * @param array The array to check.
- * @return
- * <jk>true</jk> if the specified array contains the specified
element,
- * <jk>false</jk> if the array or element is <jk>null</jk>.
- */
- public static boolean contains(int element, int[] array) {
- if (array != null)
- for (int i : array)
- if (element == i)
- return true;
- return false;
- }
-
- /**
- * Returns the index position of the element in the specified array
using the {@link Object#equals(Object)} method.
- *
- * @param element The element to check for.
- * @param array The array to check.
- * @return
- * The index position of the element in the specified array, or
<c>-1</c> if the array doesn't contain the
- * element, or the array or element is <jk>null</jk>.
- */
- public static <T> int indexOf(T element, T[] array) {
- if (element == null)
- return -1;
- if (array == null)
- return -1;
- for (int i = 0; i < array.length; i++)
- if (element.equals(array[i]))
- return i;
- return -1;
- }
-
- /**
* Returns <jk>true</jk> if the specified array contains the specified
element using the {@link String#equals(Object)}
* method.
*
@@ -398,63 +270,6 @@ public final class ArrayUtils {
}
/**
- * Converts a primitive wrapper array (e.g. <c>Integer[]</c>) to a
primitive array (e.g. <code><jk>int</jk>[]</code>).
- *
- * @param o The array to convert. Must be a primitive wrapper array.
- * @return A new array.
- * @throws IllegalArgumentException If object is not a wrapper object
array.
- */
- public static Object toPrimitiveArray(Object o) {
- Class<?> c = o.getClass();
- if (! c.isArray())
- throw new IllegalArgumentException("Cannot pass
non-array objects to toPrimitiveArray()");
- int l = Array.getLength(o);
- Class<?> tc =
ClassInfo.of(c.getComponentType()).getPrimitiveForWrapper();
- if (tc == null)
- throw new IllegalArgumentException("Array type is not a
primitive wrapper array.");
- Object a = Array.newInstance(tc, l);
- for (int i = 0; i < l; i++)
- Array.set(a, i, Array.get(o, i));
- return a;
- }
-
- /**
- * Converts an Iterable to a list.
- *
- * @param i The iterable to convert.
- * @return A new list of objects copied from the iterable.
- */
- public static List<?> toList(Iterable<?> i) {
- List<Object> l = new ArrayList<>();
- Iterator<?> i2 = i.iterator();
- while (i2.hasNext())
- l.add(i2.next());
- return l;
- }
-
- /**
- * Returns the first object in the specified collection or array.
- *
- * @param val The collection or array object.
- * @return
- * The first object, or <jk>null</jk> if the collection or array
is empty or <jk>null</jk> or the value
- * isn't a collection or array.
- */
- public static Object getFirst(Object val) {
- if (val != null) {
- if (val instanceof Collection) {
- Collection<?> c = (Collection<?>)val;
- if (c.isEmpty())
- return null;
- return c.iterator().next();
- }
- if (val.getClass().isArray())
- return Array.getLength(val) == 0 ? null :
Array.get(val, 0);
- }
- return null;
- }
-
- /**
* Converts the specified collection to an array of strings.
*
* <p>
@@ -489,46 +304,6 @@ public final class ArrayUtils {
}
/**
- * Converts a collection to an array containing the elements in
reversed order.
- *
- * @param c The component type of the array.
- * @param l
- * The collection to convert.
- * <br>The collection is not modified.
- * @return
- * A new array, or <jk>null</jk> if the collection was
<jk>null</jk>.
- */
- @SuppressWarnings("unchecked")
- public static <T> T[] toReverseArray(Class<T> c, Collection<T> l) {
- if (l == null)
- return null;
- Object a = Array.newInstance(c, l.size());
- Iterator<T> i = l.iterator();
- int j = l.size();
- while (i.hasNext())
- Array.set(a, --j, i.next());
- return (T[])a;
- }
-
- /**
- * Removes the specified element from the specified array.
- *
- * @param element The element to remove from the array.
- * @param array The array to remove the element from.
- * @return A new array with the element removed, or the original array
if the array did not contain the element.
- */
- public static Object[] remove(Object element, Object[] array) {
- if (! contains(element, array))
- return array;
- List<Object> l = new ArrayList<>(array.length);
- for (Object o2 : array) {
- if (! element.equals(o2))
- l.add(o2);
- }
- return l.toArray(new Object[l.size()]);
- }
-
- /**
* Makes a copy of the specified array.
*
* @param array The array to copy.
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ByteArrayInOutStream.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ByteArrayInOutStream.java
deleted file mode 100644
index 62b9e19..0000000
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ByteArrayInOutStream.java
+++ /dev/null
@@ -1,30 +0,0 @@
-//
***************************************************************************************************************************
-// * 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.juneau.internal;
-
-import java.io.*;
-
-/**
- * Subclass of a ByteArrayOutputStream that avoids a byte array copy when
reading from an input stream.
- */
-public class ByteArrayInOutStream extends ByteArrayOutputStream {
-
- /**
- * Creates a new input stream from this object.
- *
- * @return A new input stream from this object.
- */
- public ByteArrayInputStream getInputStream() {
- return new ByteArrayInputStream(this.buf, 0, this.count);
- }
-}
\ No newline at end of file
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ClassUtils.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ClassUtils.java
index 8021767..471bd82 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ClassUtils.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ClassUtils.java
@@ -26,19 +26,6 @@ import org.apache.juneau.reflect.*;
public final class ClassUtils {
/**
- * Given the specified list of objects, return readable names for the
class types of the objects.
- *
- * @param o The objects.
- * @return An array of readable class type strings.
- */
- public static OList getFullClassNames(Object[] o) {
- OList l = new OList();
- for (int i = 0; i < o.length; i++)
- l.add(o[i] == null ? "null" :
ClassInfo.of((o[i].getClass())).getFullName());
- return l;
- }
-
- /**
* Returns the class types for the specified arguments.
*
* @param args The objects we're getting the classes of.
@@ -198,19 +185,7 @@ public final class ClassUtils {
return params;
}
- /**
- * Matches arguments to a list of parameter types.
- *
- * <p>
- * Extra parameters are ignored.
- * <br>Missing parameters are left null.
- *
- * @param paramTypes The parameter types.
- * @param args The arguments to match to the parameter types.
- * @return
- * An array of parameters.
- */
- public static Object[] getMatchingArgs(List<ClassInfo> paramTypes,
Object... args) {
+ private static Object[] getMatchingArgs(List<ClassInfo> paramTypes,
Object... args) {
Object[] params = new Object[paramTypes.size()];
for (int i = 0; i < paramTypes.size(); i++) {
ClassInfo pt =
paramTypes.get(i).getWrapperInfoIfPrimitive();
@@ -225,45 +200,6 @@ public final class ClassUtils {
}
/**
- * Constructs a new instance of the specified class from the specified
string.
- *
- * <p>
- * Class must be one of the following:
- * <ul>
- * <li>Have a public constructor that takes in a single
<c>String</c> argument.
- * <li>Have a static <c>fromString(String)</c> (or related) method.
- * <li>Be an <c>enum</c>.
- * </ul>
- *
- * @param c The class.
- * @param s The string to create the instance from.
- * @return A new object instance, or <jk>null</jk> if a method for
converting the string to an object could not be found.
- */
- public static <T> T fromString(Class<T> c, String s) {
- Mutater<String,T> t = Mutaters.get(String.class, c);
- return t == null ? null : t.mutate(s);
- }
-
- /**
- * Converts an object to a string.
- *
- * <p>
- * Normally, this is just going to call <c>toString()</c> on the object.
- * However, the {@link Locale} and {@link TimeZone} objects are treated
special so that the returned value
- * works with the {@link #fromString(Class, String)} method.
- *
- * @param o The object to convert to a string.
- * @return The stringified object, or <jk>null</jk> if the object was
<jk>null</jk>.
- */
- @SuppressWarnings({ "unchecked" })
- public static String toString(Object o) {
- if (o == null)
- return null;
- Mutater<Object,String> t =
(Mutater<Object,String>)Mutaters.get(o.getClass(), String.class);
- return t == null ? o.toString() : t.mutate(o);
- }
-
- /**
* Attempts to call <code>x.setAccessible(<jk>true</jk>)</code> and
quietly ignores security exceptions.
*
* @param x The constructor.
@@ -333,21 +269,6 @@ public final class ClassUtils {
}
/**
- * Returns <jk>true</jk> if this class is not <jk>null</jk> and isn't
abstract or an interface.
- *
- * @param c The class to check.
- * @return <jk>true</jk> if this class is not <jk>null</jk> and isn't
abstract or an interface.
- */
- public static boolean isConcrete(Class<?> c) {
- if (c == null)
- return false;
- ClassInfo ci = ClassInfo.of(c);
- if (ci.isAbstract())
- return false;
- return true;
- }
-
- /**
* Returns the class name for the specified object.
*
* @param value The object to get the class name for.
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/CollectionUtils.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/CollectionUtils.java
index 25892ed..6ccb379 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/CollectionUtils.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/CollectionUtils.java
@@ -21,72 +21,6 @@ import java.util.*;
public final class CollectionUtils {
/**
- * Returns an iterable over the specified enumeration.
- *
- * @param e The collection to iterate over.
- * @return An iterable over the enumeration.
- */
- public static <E> Iterable<E> iterable(final Enumeration<E> e) {
- if (e == null)
- return null;
- return new Iterable<E>() {
- @Override
- public Iterator<E> iterator() {
- return new Iterator<E>() {
- @Override
- public boolean hasNext() {
- return e.hasMoreElements();
- }
- @Override
- public E next() {
- return e.nextElement();
- }
- @Override
- public void remove() {
- throw new
UnsupportedOperationException();
- }
- };
- }
- };
- }
-
- /**
- * Creates an iterator over a list of iterable objects.
- *
- * @param <E> The element type.
- * @param l The iterables to iterate over.
- * @return A new iterator.
- */
- public static <E> Iterator<E> iterator(final List<Iterable<E>> l) {
- return new Iterator<E>() {
- Iterator<Iterable<E>> i1 = l.iterator();
- Iterator<E> i2 = i1.hasNext() ? i1.next().iterator() :
null;
-
- @Override /* Iterator */
- public boolean hasNext() {
- while (i2 != null && ! i2.hasNext())
- i2 = (i1.hasNext() ?
i1.next().iterator() : null);
- return (i2 != null);
- }
-
- @Override /* Iterator */
- public E next() {
- hasNext();
- if (i2 == null)
- throw new NoSuchElementException();
- return i2.next();
- }
-
- @Override /* Iterator */
- public void remove() {
- if (i2 == null)
- throw new NoSuchElementException();
- i2.remove();
- }
- };
- }
-
- /**
* Creates a new list from the specified collection.
*
* @param val The value to copy from.
@@ -200,16 +134,6 @@ public final class CollectionUtils {
return new SetBuilder<>(elementType, elementTypeArgs);
}
-
- /**
- * Simple passthrough to {@link Collections#emptySet()}
- *
- * @return A new unmodifiable empty set.
- */
- public static <T> Set<T> emptySet() {
- return Collections.emptySet();
- }
-
/**
* Simple passthrough to {@link Collections#emptyList()}
*
@@ -220,15 +144,6 @@ public final class CollectionUtils {
}
/**
- * Simple passthrough to {@link Collections#emptyMap()}
- *
- * @return A new unmodifiable empty set.
- */
- public static <K,V> Map<K,V> emptyMap() {
- return Collections.emptyMap();
- }
-
- /**
* Returns the last entry in a list.
*
* @param <T> The element type.
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/DateUtils.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/DateUtils.java
index cd2a5af..5295925 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/DateUtils.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/DateUtils.java
@@ -49,71 +49,12 @@ public final class DateUtils {
* Date format pattern used to parse HTTP date headers in ANSI C
<c>asctime()</c> format.
*/
public static final String PATTERN_ASCTIME = "EEE MMM d HH:mm:ss yyyy";
- private static final String[] DEFAULT_PATTERNS = new String[] {
PATTERN_RFC1123, PATTERN_RFC1036, PATTERN_ASCTIME };
- private static final Date DEFAULT_TWO_DIGIT_YEAR_START;
private static final TimeZone GMT = TimeZone.getTimeZone("GMT");
static {
final Calendar calendar = Calendar.getInstance();
calendar.setTimeZone(GMT);
calendar.set(2000, Calendar.JANUARY, 1, 0, 0, 0);
calendar.set(Calendar.MILLISECOND, 0);
- DEFAULT_TWO_DIGIT_YEAR_START = calendar.getTime();
- }
-
- /**
- * Parses a date value.
- *
- * <p>
- * The formats used for parsing the date value are retrieved from the
default http params.
- *
- * @param dateValue the date value to parse
- * @return the parsed date or null if input could not be parsed
- */
- public static Date parseDate(final String dateValue) {
- return parseDate(dateValue, null, null);
- }
-
- /**
- * Parses the date value using the given date formats.
- *
- * @param dateValue the date value to parse
- * @param dateFormats the date formats to use
- * @return the parsed date or null if input could not be parsed
- */
- public static Date parseDate(final String dateValue, final String[]
dateFormats) {
- return parseDate(dateValue, dateFormats, null);
- }
-
- /**
- * Parses the date value using the given date formats.
- *
- * @param dateValue the date value to parse
- * @param dateFormats the date formats to use
- * @param startDate
- * During parsing, two digit years will be placed in the range
<c>startDate</c> to
- * <c>startDate + 100 years</c>. This value may be <c>null</c>.
When
- * <c>null</c> is given as a parameter, year <c>2000</c> will be
used.
- * @return the parsed date or null if input could not be parsed
- */
- public static Date parseDate(final String dateValue, final String[]
dateFormats, final Date startDate) {
- final String[] localDateFormats = dateFormats != null ?
dateFormats : DEFAULT_PATTERNS;
- final Date localStartDate = startDate != null ? startDate :
DEFAULT_TWO_DIGIT_YEAR_START;
- String v = dateValue;
- // trim single quotes around date if present
- // see issue #5279
- if (v.length() > 1 && v.startsWith("'") && v.endsWith("'")) {
- v = v.substring(1, v.length() - 1);
- }
- for (final String dateFormat : localDateFormats) {
- final SimpleDateFormat dateParser =
DateFormatHolder.formatFor(dateFormat);
- dateParser.set2DigitYearStart(localStartDate);
- final ParsePosition pos = new ParsePosition(0);
- final Date result = dateParser.parse(v, pos);
- if (pos.getIndex() != 0) {
- return result;
- }
- }
- return null;
}
/**
@@ -129,29 +70,6 @@ public final class DateUtils {
}
/**
- * Parses an ISO8601 string and converts it to a {@link Date}.
- *
- * @param s The string to parse.
- * @return The parsed value, or <jk>null</jk> if the string was
<jk>null</jk> or empty.
- */
- public static Date parseISO8601(String s) {
- if (isEmpty(s))
- return null;
- return
DatatypeConverter.parseDateTime(toValidISO8601DT(s)).getTime();
- }
-
- /**
- * Formats the given date according to the RFC 1123 pattern.
- *
- * @param date The date to format.
- * @return An RFC 1123 formatted date string.
- * @see #PATTERN_RFC1123
- */
- public static String formatDate(final Date date) {
- return formatDate(date, PATTERN_RFC1123);
- }
-
- /**
* Formats the given date according to the specified pattern.
*
* <p>
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/HttpUtils.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/HttpUtils.java
index 63f53c5..fea1921 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/HttpUtils.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/HttpUtils.java
@@ -15,8 +15,6 @@ package org.apache.juneau.internal;
import static org.apache.juneau.internal.StringUtils.*;
import java.lang.reflect.*;
-import org.apache.juneau.reflect.*;
-
/**
* Utilities.
*/
@@ -74,30 +72,4 @@ public class HttpUtils {
}
return '/' + n;
}
-
- /**
- * Given a Java method, returns the arguments signature.
- *
- * @param m The Java method.
- * @param full Whether fully-qualified names should be used for
arguments.
- * @return The arguments signature for the specified method.
- */
- public static String getMethodArgsSignature(Method m, boolean full) {
- StringBuilder sb = new StringBuilder(128);
- Class<?>[] pt = m.getParameterTypes();
- if (pt.length == 0)
- return "";
- sb.append('(');
- for (int i = 0; i < pt.length; i++) {
- ClassInfo pti = ClassInfo.of(pt[i]);
- if (i > 0)
- sb.append(',');
- if (full)
- pti.appendFullName(sb);
- else
- pti.appendShortName(sb);
- }
- sb.append(')');
- return sb.toString();
- }
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ObjectUtils.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ObjectUtils.java
index 48cb6ce..fd1dcf8 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ObjectUtils.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ObjectUtils.java
@@ -27,17 +27,6 @@ import org.apache.juneau.utils.*;
public class ObjectUtils {
/**
- * Returns the enum names for the specified enum class.
- *
- * @param c The enum class.
- * @return A modifiable list of all names for that class.
- */
- @SuppressWarnings("unchecked")
- public static Enum<?>[] getEnumConstants(Class<?> c) {
- return ((Class<Enum<?>>)c).getEnumConstants();
- }
-
- /**
* If the specified object is an instance of the specified class, casts
it to that type.
*
* @param o The object to cast.
@@ -52,33 +41,6 @@ public class ObjectUtils {
}
/**
- * Returns the first non-zero value in the list of ints.
- *
- * @param ints The ints to check.
- * @return The first non-zero value, or <c>0</c> if they were all zero.
- */
- public static int firstNonZero(int...ints) {
- for (int i : ints)
- if (i != 0)
- return i;
- return 0;
- }
-
- /**
- * Returns the first non-empty value in the list of objects.
- *
- * @param o The objects to check.
- * @return The first object whose call to {@link
ObjectUtils#isEmpty(Object)} returns <jk>false</jk>, otherwise <jk>null</jk>.
- */
- @SafeVarargs
- public static <T> T firstNonEmpty(T...o) {
- for (T oo : o)
- if (! ObjectUtils.isEmpty(oo))
- return oo;
- return null;
- }
-
- /**
* Compares two objects for equality.
*
* <p>
@@ -191,52 +153,10 @@ public class ObjectUtils {
return ! eq(o1, o2);
}
- /**
- * Calculates the hashcode for the specified object.
- *
- * <p>
- * Unlike just calling {@link Object#hashCode()}, this method
calculates hashsums of arrays by using the contents
- * of the array instead of the hashsum of the array itself.
- *
- * @param o The object to calculate a hashsum on.
- * @return The hashsum.
- */
- public static int hashCode(Object o) {
- if (o == null)
- return 0;
- if (isArray(o)) {
- int x = 1;
- for (int i = 0; i < Array.getLength(o); i++)
- x = 31 * x + hashCode(Array.get(o, i));
- return x;
- }
- if (isCollection(o)) {
- int x = 1;
- for (Object o2 : (Collection<?>)o)
- x = 31 * x + hashCode(o2);
- return x;
- }
- if (isMap(o)) {
- int x = 1;
- for (Map.Entry<?,?> o2 : ((Map<?,?>)o).entrySet())
- x = 31 * x + (hashCode(o2.getKey()) ^
hashCode(o2.getValue()));
- return x;
- }
- return o.hashCode();
- }
-
private static boolean isArray(Object o) {
return o != null && o.getClass().isArray();
}
- private static boolean isCollection(Object o) {
- return o != null &&
o.getClass().isAssignableFrom(Collection.class);
- }
-
- private static boolean isMap(Object o) {
- return o != null && o.getClass().isAssignableFrom(Map.class);
- }
-
/**
* If the specified object is a {@link Supplier} or {@link Mutable},
returns the inner value, otherwise the same value.
*
@@ -282,27 +202,6 @@ public class ObjectUtils {
}
/**
- * Returns <jk>true</jk> if the specified object is not empty.
- *
- * <p>
- * Return <jk>false</jk> if the value is any of the following:
- * <ul>
- * <li><jk>null</jk>
- * <li>An empty Collection
- * <li>An empty Map
- * <li>An empty array
- * <li>An empty CharSequence
- * <li>An empty String when serialized to a string using {@link
Object#toString()}.
- * </ul>
- *
- * @param o The object to test.
- * @return <jk>true</jk> if the specified object is empty.
- */
- public static boolean isNotEmpty(Object o) {
- return ! isEmpty(o);
- }
-
- /**
* Returns the first non-null value in the specified array
*
* @param t The values to check.
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Setter.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/Setter.java
similarity index 97%
rename from
juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Setter.java
rename to
juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/Setter.java
index cab652d..c34a03c 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Setter.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/Setter.java
@@ -10,10 +10,12 @@
// * "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.juneau;
+package org.apache.juneau.internal;
import java.lang.reflect.*;
+import org.apache.juneau.*;
+
/**
* Encapsulate a bean setter method that may be a method or field.
*/
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/StringUtils.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/StringUtils.java
index 9ccf2bd..c1c6ccc 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/StringUtils.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/StringUtils.java
@@ -76,32 +76,6 @@ public final class StringUtils {
}
/**
- * Parses a number from the specified reader stream.
- *
- * @param r The reader to parse the string from.
- * @param type
- * The number type to created.
- * Can be any of the following:
- * <ul>
- * <li> Integer
- * <li> Double
- * <li> Float
- * <li> Long
- * <li> Short
- * <li> Byte
- * <li> BigInteger
- * <li> BigDecimal
- * </ul>
- * If <jk>null</jk>, uses the best guess.
- * @return The parsed number.
- * @throws IOException If a problem occurred trying to read from the
reader.
- * @throws ParseException Malformed input encountered.
- */
- public static Number parseNumber(ParserReader r, Class<? extends
Number> type) throws ParseException, IOException {
- return parseNumber(parseNumberString(r), type);
- }
-
- /**
* Reads a numeric string from the specified reader.
*
* @param r The reader to read form.
@@ -344,20 +318,6 @@ public final class StringUtils {
}
/**
- * Convenience method for getting a stack trace as a string.
- *
- * @param t The throwable to get the stack trace from.
- * @return The same content that would normally be rendered via
<c>t.printStackTrace()</c>
- */
- public static String getStackTrace(Throwable t) {
- StringWriter sw = new StringWriter();
- try (PrintWriter pw = new PrintWriter(sw)) {
- t.printStackTrace(pw);
- }
- return sw.toString();
- }
-
- /**
* Join the specified tokens into a delimited string.
*
* @param tokens The tokens to join.
@@ -383,25 +343,6 @@ public final class StringUtils {
* @param d The delimiter.
* @return The delimited string. If <c>tokens</c> is <jk>null</jk>,
returns <jk>null</jk>.
*/
- public static String join(int[] tokens, String d) {
- if (tokens == null)
- return null;
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < tokens.length; i++) {
- if (i > 0)
- sb.append(d);
- sb.append(tokens[i]);
- }
- return sb.toString();
- }
-
- /**
- * Join the specified tokens into a delimited string.
- *
- * @param tokens The tokens to join.
- * @param d The delimiter.
- * @return The delimited string. If <c>tokens</c> is <jk>null</jk>,
returns <jk>null</jk>.
- */
public static String join(Collection<?> tokens, String d) {
if (tokens == null)
return null;
@@ -474,19 +415,6 @@ public final class StringUtils {
return join(tokens, d, new StringBuilder()).toString();
}
- /**
- * Same as {@link #join(Object[], char)} except escapes the delimiter
character if found in the tokens.
- *
- * @param tokens The tokens to join.
- * @param d The delimiter.
- * @return The delimited string. If <c>tokens</c> is <jk>null</jk>,
returns <jk>null</jk>.
- */
- public static String joine(Object[] tokens, char d) {
- if (tokens == null)
- return null;
- return joine(tokens, d, new StringBuilder()).toString();
- }
-
private static AsciiSet getEscapeSet(char c) {
AsciiSet s = ESCAPE_SETS.get(c);
if (s == null) {
@@ -517,26 +445,6 @@ public final class StringUtils {
}
/**
- * Same as {@link #join(Object[], char, StringBuilder)} but escapes the
delimiter character if found in the tokens.
- *
- * @param tokens The tokens to join.
- * @param d The delimiter.
- * @param sb The string builder to append the response to.
- * @return The same string builder passed in as <c>sb</c>.
- */
- public static StringBuilder joine(Object[] tokens, char d,
StringBuilder sb) {
- if (tokens == null)
- return sb;
- AsciiSet as = getEscapeSet(d);
- for (int i = 0; i < tokens.length; i++) {
- if (i > 0)
- sb.append(d);
- sb.append(escapeChars(stringify(tokens[i]), as));
- }
- return sb;
- }
-
- /**
* Join the specified tokens into a delimited string.
*
* @param tokens The tokens to join.
@@ -624,16 +532,6 @@ public final class StringUtils {
}
/**
- * Joins tokens with newlines.
- *
- * @param tokens The tokens to concatenate.
- * @return A string with the specified tokens contatenated with
newlines.
- */
- public static String joinnl(List<?> tokens) {
- return join(tokens, '\n');
- }
-
- /**
* Shortcut for calling <code>split(s, <js>','</js>)</code>
*
* @param s The string to split. Can be <jk>null</jk>.
@@ -1475,7 +1373,7 @@ public final class StringUtils {
* @param numchars The number of characters in the generated UUID.
* @return A new random UUID.
*/
- public static String generateUUID(int numchars) {
+ public static String random(int numchars) {
Random r = new Random();
StringBuilder sb = new StringBuilder(numchars);
for (int i = 0; i < numchars; i++) {
@@ -1488,16 +1386,6 @@ public final class StringUtils {
}
/**
- * Shortcut for calling generateUUID(int).
- *
- * @param numchars The number of characters in the generated UUID.
- * @return A new random UUID.
- */
- public static String random(int numchars) {
- return generateUUID(numchars);
- }
-
- /**
* Same as {@link String#trim()} but prevents
<c>NullPointerExceptions</c>.
*
* @param s The string to trim.
@@ -1579,18 +1467,6 @@ public final class StringUtils {
}
/**
- * Converts the specified object to an ISO8601 date string.
- *
- * @param d The object to convert.
- * @return The converted object.
- */
- public static String toIsoDate(Date d) {
- Calendar c = new GregorianCalendar();
- c.setTime(d);
- return DatatypeConverter.printDate(c);
- }
-
- /**
* Converts the specified object to an ISO8601 date-time string.
*
* @param c The object to convert.
@@ -1601,18 +1477,6 @@ public final class StringUtils {
}
/**
- * Converts the specified object to an ISO8601 date-time string.
- *
- * @param d The object to convert.
- * @return The converted object.
- */
- public static String toIsoDateTime(Date d) {
- Calendar c = new GregorianCalendar();
- c.setTime(d);
- return DatatypeConverter.printDateTime(c);
- }
-
- /**
* Simple utility for replacing variables of the form <js>"{key}"</js>
with values in the specified map.
*
* <p>
@@ -1686,43 +1550,6 @@ public final class StringUtils {
}
/**
- * Returns <jk>true</jk> if the specified path string is prefixed with
the specified prefix.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bcode w800'>
- * pathStartsWith(<js>"foo"</js>, <js>"foo"</js>); <jc>//
true</jc>
- * pathStartsWith(<js>"foo/bar"</js>, <js>"foo"</js>); <jc>//
true</jc>
- * pathStartsWith(<js>"foo2"</js>, <js>"foo"</js>); <jc>//
false</jc>
- * pathStartsWith(<js>"foo2"</js>, <js>""</js>); <jc>// false</jc>
- * </p>
- *
- * @param path The path to check.
- * @param pathPrefix The prefix.
- * @return <jk>true</jk> if the specified path string is prefixed with
the specified prefix.
- */
- public static boolean pathStartsWith(String path, String pathPrefix) {
- if (path == null || pathPrefix == null)
- return false;
- if (path.startsWith(pathPrefix))
- return path.length() == pathPrefix.length() ||
path.charAt(pathPrefix.length()) == '/';
- return false;
- }
-
- /**
- * Same as {@link #pathStartsWith(String, String)} but returns
<jk>true</jk> if at least one prefix matches.
- *
- * @param path The path to check.
- * @param pathPrefixes The prefixes.
- * @return <jk>true</jk> if the specified path string is prefixed with
any of the specified prefixes.
- */
- public static boolean pathStartsWith(String path, String[]
pathPrefixes) {
- for (String p : pathPrefixes)
- if (pathStartsWith(path, p))
- return true;
- return false;
- }
-
- /**
* Replaces <js>"\\uXXXX"</js> character sequences with their unicode
characters.
*
* @param s The string to replace unicode sequences in.
@@ -1757,54 +1584,6 @@ public final class StringUtils {
}
/**
- * Returns the specified field in a delimited string without splitting
the string.
- *
- * <p>
- * Equivalent to the following:
- * <p class='bcode w800'>
- * String in = <js>"0,1,2"</js>;
- * String[] parts = in.split(<js>","</js>);
- * String p1 = (parts.<jk>length</jk> > 1 ? parts[1] :
<js>""</js>);
- * </p>
- *
- * @param fieldNum The field number. Zero-indexed.
- * @param s The input string.
- * @param delim The delimiter character.
- * @return The field entry in the string, or a blank string if it
doesn't exist or the string is null.
- */
- public static String getField(int fieldNum, String s, char delim) {
- return getField(fieldNum, s, delim, "");
- }
-
- /**
- * Same as {@link #getField(int, String, char)} except allows you to
specify the default value.
- *
- * @param fieldNum The field number. Zero-indexed.
- * @param s The input string.
- * @param delim The delimiter character.
- * @param def The default value if the field does not exist.
- * @return The field entry in the string, or the default value if it
doesn't exist or the string is null.
- */
- public static String getField(int fieldNum, String s, char delim,
String def) {
- if (s == null || fieldNum < 0)
- return def;
- int start = 0;
- for (int i = 0; i < s.length(); i++) {
- char c = s.charAt(i);
- if (c == delim) {
- fieldNum--;
- if (fieldNum == 0)
- start = i+1;
- }
- if (fieldNum < 0)
- return s.substring(start, i);
- }
- if (start == 0)
- return def;
- return s.substring(start);
- }
-
- /**
* Calls {@link #toString()} on the specified object if it's not null.
*
* @param o The object to convert to a string.
@@ -1843,23 +1622,6 @@ public final class StringUtils {
}
/**
- * Converts an array of objects to an array of strings.
- *
- * @param o The array of objects to convert to strings.
- * @return A new array of objects converted to strings.
- */
- public static String[] stringifyAll(Object...o) {
- if (o == null)
- return null;
- if (o instanceof String[])
- return (String[])o;
- String[] s = new String[o.length];
- for (int i = 0; i < o.length; i++)
- s[i] = stringify(o[i]);
- return s;
- }
-
- /**
* Converts a hexadecimal byte stream (e.g. "34A5BC") into a UTF-8
encoded string.
*
* @param hex The hexadecimal string.
@@ -2069,39 +1831,11 @@ public final class StringUtils {
return s;
}
- /**
- * Trims <js>'/'</js> characters from the end of the specified string.
- *
- * @param s The string to trim.
- * @return The same string buffer.
- */
- public static StringBuffer trimTrailingSlashes(StringBuffer s) {
- if (s == null)
- return null;
- while (s.length() > 0 && s.charAt(s.length()-1) == '/')
- s.setLength(s.length()-1);
- return s;
- }
-
- /**
- * Shortcut for calling
<code>URLEncoder.<jsm>encode</jsm>(o.toString(), <js>"UTF-8"</js>)</code>.
- *
- * @param o The object to encode.
- * @return The URL encoded string, or <jk>null</jk> if the object was
null.
- */
- public static String urlEncode(Object o) {
- try {
- if (o != null)
- return URLEncoder.encode(o.toString(), "UTF-8");
- } catch (UnsupportedEncodingException e) {}
- return null;
- }
-
private static final AsciiSet URL_ENCODE_PATHINFO_VALIDCHARS =
AsciiSet.create().ranges("a-z","A-Z","0-9").chars("-_.*/()").build();
/**
- * Similar to {@link #urlEncode(Object)} but doesn't encode
<js>"/"</js> characters.
+ * Similar to {@link URLEncoder#encode(String, String)} but doesn't
encode <js>"/"</js> characters.
*
* @param o The object to encode.
* @return The URL encoded string, or <jk>null</jk> if the object was
null.
@@ -2246,27 +1980,6 @@ public final class StringUtils {
}
/**
- * Splits a string into equally-sized parts.
- *
- * @param s The string to split.
- * @param size The token sizes.
- * @return The tokens, or <jk>null</jk> if the input was <jk>null</jk>.
- */
- public static List<String> splitEqually(String s, int size) {
- if (s == null)
- return null;
- if (size <= 0)
- return Collections.singletonList(s);
-
- List<String> l = new ArrayList<>((s.length() + size - 1) /
size);
-
- for (int i = 0; i < s.length(); i += size)
- l.add(s.substring(i, Math.min(s.length(), i + size)));
-
- return l;
- }
-
- /**
* Returns the first non-whitespace character in the string.
*
* @param s The string to check.
@@ -2853,16 +2566,6 @@ public final class StringUtils {
}
/**
- * Null-safe {@link String#toLowerCase()}.
- *
- * @param s The string to convert to lower case.
- * @return The string converted to lower case, or <jk>null</jk> if the
string was null.
- */
- public static String toLowerCase(String s) {
- return s == null ? null : s.toLowerCase();
- }
-
- /**
* Parses a duration string.
*
* <p>
@@ -2924,48 +2627,6 @@ public final class StringUtils {
}
/**
- * Replaces tokens in a string with a different token.
- *
- * <p>
- * replace("A and B and C", "and", "or") -> "A or B or C"
- * replace("andandand", "and", "or") -> "ororor"
- * replace(null, "and", "or") -> null
- * replace("andandand", null, "or") -> "andandand"
- * replace("andandand", "", "or") -> "andandand"
- * replace("A and B and C", "and", null) -> "A B C"
- *
- * @param s The string to replace characters in.
- * @param from The character to replace.
- * @param to The character to replace with.
- * @param ignoreEscapedChars Specify 'true' if escaped 'from'
characters should be ignored.
- * @return The string with characters replaced.
- */
- public static String replaceChars(String s, char from, char to, boolean
ignoreEscapedChars) {
- if (s == null)
- return null;
-
- if (s.indexOf(from) == -1)
- return s;
-
- char[] sArray = s.toCharArray();
-
- int escapeCount = 0;
- int singleQuoteCount = 0;
- int doubleQuoteCount = 0;
- for (int i = 0; i < sArray.length; i++) {
- char c = sArray[i];
- if (c == '\\' && ignoreEscapedChars)
- escapeCount++;
- else if (escapeCount % 2 == 0) {
- if (c == from && singleQuoteCount % 2 == 0 &&
doubleQuoteCount % 2 == 0)
- sArray[i] = to;
- }
- if (sArray[i] != '\\') escapeCount = 0;
- }
- return new String(sArray);
- }
-
- /**
* Strips invalid characters such as CTRL characters from a string
meant to be encoded
* as an HTTP header value.
*
@@ -3007,19 +2668,6 @@ public final class StringUtils {
}
/**
- * Truncates a string.
- *
- * @param in The input string.
- * @param length The max length of the resulting string.
- * @return The truncated string.
- */
- public static String truncate(String in, int length) {
- if (in == null || in.length() <= length)
- return in;
- return in.substring(0, length);
- }
-
- /**
* Splits the method arguments in the signature of a method.
*
* @param s The arguments to split.
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ThrowableUtils.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ThrowableUtils.java
index e433c68..15c0723 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ThrowableUtils.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ThrowableUtils.java
@@ -12,6 +12,8 @@
//
***************************************************************************************************************************
package org.apache.juneau.internal;
+import java.io.*;
+
/**
* Various utility methods for creating and working with throwables.
*/
@@ -58,6 +60,20 @@ public class ThrowableUtils {
@SuppressWarnings("javadoc")
@FunctionalInterface
public interface SupplierWithThrowable<T> {
- public T get() throws Throwable;
+ public T get() throws Throwable;
+ }
+
+ /**
+ * Convenience method for getting a stack trace as a string.
+ *
+ * @param t The throwable to get the stack trace from.
+ * @return The same content that would normally be rendered via
<c>t.printStackTrace()</c>
+ */
+ public static String getStackTrace(Throwable t) {
+ StringWriter sw = new StringWriter();
+ try (PrintWriter pw = new PrintWriter(sw)) {
+ t.printStackTrace(pw);
+ }
+ return sw.toString();
}
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/TwoKeyConcurrentCache.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/TwoKeyConcurrentCache.java
similarity index 98%
rename from
juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/TwoKeyConcurrentCache.java
rename to
juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/TwoKeyConcurrentCache.java
index a5d65ca..8db0916 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/TwoKeyConcurrentCache.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/TwoKeyConcurrentCache.java
@@ -10,7 +10,7 @@
// * "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.juneau.utils;
+package org.apache.juneau.internal;
import java.util.*;
import java.util.concurrent.*;
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/jsonschema/JsonSchemaGeneratorSession.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/jsonschema/JsonSchemaGeneratorSession.java
index 59c03d7..5943201 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/jsonschema/JsonSchemaGeneratorSession.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/jsonschema/JsonSchemaGeneratorSession.java
@@ -12,7 +12,6 @@
//
***************************************************************************************************************************
package org.apache.juneau.jsonschema;
-import static org.apache.juneau.internal.ObjectUtils.*;
import static org.apache.juneau.jsonschema.TypeCategory.*;
import java.lang.reflect.*;
@@ -310,9 +309,10 @@ public class JsonSchemaGeneratorSession extends
BeanTraverseSession {
return out;
}
+ @SuppressWarnings("unchecked")
private List<String> getEnums(ClassMeta<?> cm) {
List<String> l = new ArrayList<>();
- for (Enum<?> e : getEnumConstants(cm.getInnerClass()))
+ for (Enum<?> e :
((Class<Enum<?>>)cm.getInnerClass()).getEnumConstants())
l.add(cm.toString(e));
return l;
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ClassInfo.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ClassInfo.java
index 5835c85..ab34e58 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ClassInfo.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ClassInfo.java
@@ -1425,19 +1425,36 @@ public final class ClassInfo {
Package p = c.getPackage();
if (p != null)
for (Annotation a : p.getDeclaredAnnotations())
- for (Annotation a2 :
AnnotationUtils.splitRepeated(a))
+ for (Annotation a2 : splitRepeated(a))
m.add(AnnotationInfo.of(p, a2));
for (ClassInfo ci : getInterfacesParentFirst())
for (Annotation a : ci.c.getDeclaredAnnotations())
- for (Annotation a2 :
AnnotationUtils.splitRepeated(a))
+ for (Annotation a2 : splitRepeated(a))
m.add(AnnotationInfo.of(ci, a2));
for (ClassInfo ci : getParentsParentFirst())
for (Annotation a : ci.c.getDeclaredAnnotations())
- for (Annotation a2 :
AnnotationUtils.splitRepeated(a))
+ for (Annotation a2 : splitRepeated(a))
m.add(AnnotationInfo.of(ci, a2));
return m;
}
+ /**
+ * If the annotation is an array of other annotations, returns the
inner annotations.
+ *
+ * @param a The annotation to split if repeated.
+ * @return The nested annotations, or a singleton array of the same
annotation if it's not repeated.
+ */
+ private static Annotation[] splitRepeated(Annotation a) {
+ try {
+ ClassInfo ci = ClassInfo.ofc(a.annotationType());
+ MethodInfo mi = ci.getRepeatedAnnotationMethod();
+ if (mi != null)
+ return mi.invoke(a);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return new Annotation[]{a};
+ }
<T extends Annotation> T findAnnotation(Class<T> a, MetaProvider mp) {
if (a == null)
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/Mutaters.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/Mutaters.java
index 3885abc..3f16611 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/Mutaters.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/Mutaters.java
@@ -232,6 +232,45 @@ public class Mutaters {
return NULL;
}
+ /**
+ * Constructs a new instance of the specified class from the specified
string.
+ *
+ * <p>
+ * Class must be one of the following:
+ * <ul>
+ * <li>Have a public constructor that takes in a single
<c>String</c> argument.
+ * <li>Have a static <c>fromString(String)</c> (or related) method.
+ * <li>Be an <c>enum</c>.
+ * </ul>
+ *
+ * @param c The class.
+ * @param s The string to create the instance from.
+ * @return A new object instance, or <jk>null</jk> if a method for
converting the string to an object could not be found.
+ */
+ public static <T> T fromString(Class<T> c, String s) {
+ Mutater<String,T> t = get(String.class, c);
+ return t == null ? null : t.mutate(s);
+ }
+
+ /**
+ * Converts an object to a string.
+ *
+ * <p>
+ * Normally, this is just going to call <c>toString()</c> on the object.
+ * However, the {@link Locale} and {@link TimeZone} objects are treated
special so that the returned value
+ * works with the {@link #fromString(Class, String)} method.
+ *
+ * @param o The object to convert to a string.
+ * @return The stringified object, or <jk>null</jk> if the object was
<jk>null</jk>.
+ */
+ @SuppressWarnings({ "unchecked" })
+ public static String toString(Object o) {
+ if (o == null)
+ return null;
+ Mutater<Object,String> t =
(Mutater<Object,String>)get(o.getClass(), String.class);
+ return t == null ? o.toString() : t.mutate(o);
+ }
+
private static MethodInfo findToXMethod(ClassInfo ic, ClassInfo oc) {
String tn = oc.getReadableName();
for (MethodInfo m : ic.getAllMethods()) {
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonSerializerSession.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonSerializerSession.java
index b7e7b77..c4b79b4 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonSerializerSession.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonSerializerSession.java
@@ -25,6 +25,7 @@ import org.apache.juneau.*;
import org.apache.juneau.http.header.*;
import org.apache.juneau.httppart.*;
import org.apache.juneau.internal.*;
+import org.apache.juneau.reflect.*;
import org.apache.juneau.serializer.*;
import org.apache.juneau.svl.*;
import org.apache.juneau.transform.*;
@@ -434,9 +435,9 @@ public class UonSerializerSession extends
WriterSerializerSession implements Htt
ClassMeta<?> cm = getClassMetaForObject(value);
if (cm != null && (schema == null || schema.getType()
== HttpPartDataType.NO_TYPE)) {
if (cm.isNumber() || cm.isBoolean())
- return ClassUtils.toString(value);
+ return Mutaters.toString(value);
if (cm.isString()) {
- String s = ClassUtils.toString(value);
+ String s = Mutaters.toString(value);
if (s.isEmpty() || !
UonUtils.needsQuotes(s))
return s;
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/BeanRef.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/BeanRef.java
deleted file mode 100644
index 1b57906..0000000
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/BeanRef.java
+++ /dev/null
@@ -1,87 +0,0 @@
-//
***************************************************************************************************************************
-// * 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.juneau.utils;
-
-import static java.util.Optional.*;
-
-import java.util.*;
-
-/**
- * Represents a holder for a bean or bean type.
- *
- * @param <T> The bean type.
- */
-public class BeanRef<T> {
-
- private T value;
- private Class<? extends T> type;
-
- /**
- * Creator.
- *
- * @param type The bean type.
- * @return A new object.
- */
- public static <T> BeanRef<T> of(Class<T> type) {
- return new BeanRef<>();
- }
-
- /**
- * Sets the bean on this reference.
- *
- * @param value The bean.
- * @return This object (for method chaining).
- */
- public BeanRef<T> value(T value) {
- this.value = value;
- return this;
- }
-
- /**
- * Sets the bean type on this reference.
- *
- * @param value The bean type.
- * @return This object (for method chaining).
- */
- public BeanRef<T> type(Class<? extends T> value) {
- this.type = value;
- return this;
- }
-
- /**
- * Returns the bean on this reference if the reference contains an
instantiated bean.
- *
- * @return The bean on this reference if the reference contains an
instantiated bean.
- */
- public Optional<T> value() {
- return ofNullable(value);
- }
-
- /**
- * Returns the bean type on this reference if the reference contains a
bean type.
- *
- * @return The bean type on this reference if the reference contains a
bean type.
- */
- public Optional<Class<? extends T>> type() {
- return ofNullable(type);
- }
-
- /**
- * Returns <jk>true</jk> if neither the value or type is specified on
this reference.
- *
- * @return <jk>true</jk> if neither the value or type is specified on
this reference.
- */
- public boolean isEmpty() {
- return type == null && value == null;
- }
-}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/StackTraceUtils.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/StackTraceUtils.java
deleted file mode 100644
index 62f25b2..0000000
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/StackTraceUtils.java
+++ /dev/null
@@ -1,40 +0,0 @@
-//
***************************************************************************************************************************
-// * 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.juneau.utils;
-
-/**
- * Stack trace utility methods.
- */
-public class StackTraceUtils {
-
- /**
- * Calculates a 16-bit hash for the specified throwable based on it's
stack trace.
- *
- * @param t The throwable to calculate the stack trace on.
- * @param stopClass Optional stop class on which to stop calculation of
a stack trace beyond when found.
- * @return A calculated hash.
- */
- public static int hash(Throwable t, String stopClass) {
- int i = 0;
- while (t != null) {
- for (StackTraceElement e : t.getStackTrace()) {
- if (e.getClassName().equals(stopClass))
- break;
- if (e.getClassName().indexOf('$') == -1)
- i ^= e.hashCode();
- }
- t = t.getCause();
- }
- return i;
- }
-}
diff --git
a/juneau-microservice/juneau-microservice-core/src/main/java/org/apache/juneau/microservice/resources/LogEntryFormatter.java
b/juneau-microservice/juneau-microservice-core/src/main/java/org/apache/juneau/microservice/resources/LogEntryFormatter.java
index 286b001..a39748e 100644
---
a/juneau-microservice/juneau-microservice-core/src/main/java/org/apache/juneau/microservice/resources/LogEntryFormatter.java
+++
b/juneau-microservice/juneau-microservice-core/src/main/java/org/apache/juneau/microservice/resources/LogEntryFormatter.java
@@ -12,7 +12,7 @@
//
***************************************************************************************************************************
package org.apache.juneau.microservice.resources;
-import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.internal.ThrowableUtils.*;
import java.text.*;
import java.util.*;
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicSwaggerProviderSession.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicSwaggerProviderSession.java
index b700371..953cd06 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicSwaggerProviderSession.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicSwaggerProviderSession.java
@@ -713,7 +713,10 @@ public class BasicSwaggerProviderSession {
@SafeVarargs
private final <T> T firstNonEmpty(T...t) {
- return ObjectUtils.firstNonEmpty(t);
+ for (T oo : t)
+ if (! ObjectUtils.isEmpty(oo))
+ return oo;
+ return null;
}
private OMap toMap(ExternalDocs a, String location,
Object...locationArgs) throws ParseException {
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/remote/RrpcServlet.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/remote/RrpcServlet.java
index ee6d554..0b71db9 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/remote/RrpcServlet.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/remote/RrpcServlet.java
@@ -27,8 +27,8 @@ import org.apache.juneau.dto.html5.*;
import org.apache.juneau.html.annotation.*;
import org.apache.juneau.http.annotation.Header;
import org.apache.juneau.http.annotation.Path;
-import org.apache.juneau.internal.*;
import org.apache.juneau.parser.*;
+import org.apache.juneau.reflect.*;
import org.apache.juneau.rest.*;
import org.apache.juneau.rest.annotation.*;
import org.apache.juneau.http.header.*;
@@ -132,7 +132,7 @@ public abstract class RrpcServlet extends BasicRestServlet {
} else {
t.child(tr(th("Index"),th("Type"),th("Value")));
for (int i = 0; i < types.length; i++) {
- String type = ClassUtils.toString(types[i]);
+ String type = Mutaters.toString(types[i]);
t.child(tr(td(i), td(type),
td(input().name(String.valueOf(i)).type("text"))));
}
}
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/config/ConfigBuilderTest.java
b/juneau-utest/src/test/java/org/apache/juneau/config/ConfigBuilderTest.java
index 8c46b72..08f5106 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/config/ConfigBuilderTest.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/config/ConfigBuilderTest.java
@@ -31,7 +31,7 @@ public class ConfigBuilderTest {
@BeforeClass
public static void setup() {
- tempDir = new File(System.getProperty("java.io.tmpdir"),
generateUUID(12));
+ tempDir = new File(System.getProperty("java.io.tmpdir"),
random(12));
TEMP_DIR = tempDir.getAbsolutePath();
}
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/config/ConfigTest.java
b/juneau-utest/src/test/java/org/apache/juneau/config/ConfigTest.java
index cc2c0ed..78baf20 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/config/ConfigTest.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/config/ConfigTest.java
@@ -1445,8 +1445,6 @@ public class ConfigTest {
StringWriter sw = new StringWriter();
cf.writeTo(sw);
assertString(sw).replaceAll("\\r?\\n", "|").is("a = b|");
-
- assertEquals("text/plain", cf.getMediaType().toString());
}
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/rest/util/RestUtils_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/rest/util/RestUtils_Test.java
index ce1c82b..5829f60 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/rest/util/RestUtils_Test.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/rest/util/RestUtils_Test.java
@@ -171,22 +171,6 @@ public class RestUtils_Test {
}
//------------------------------------------------------------------------------------------------------------------
- // trimTrailingSlashes(StringBuffer)
-
//------------------------------------------------------------------------------------------------------------------
-
- @Test
- public void f01_testTrimTrailingSlashes2() throws Exception {
- assertNull(trimTrailingSlashes((StringBuffer)null));
- assertEquals("", trimTrailingSlashes(new
StringBuffer("")).toString());
- assertEquals("", trimTrailingSlashes(new
StringBuffer("/")).toString());
- assertEquals("", trimTrailingSlashes(new
StringBuffer("//")).toString());
- assertEquals("foo/bar", trimTrailingSlashes(new
StringBuffer("foo/bar")).toString());
- assertEquals("foo/bar", trimTrailingSlashes(new
StringBuffer("foo/bar//")).toString());
- assertEquals("/foo/bar", trimTrailingSlashes(new
StringBuffer("/foo/bar//")).toString());
- assertEquals("//foo/bar", trimTrailingSlashes(new
StringBuffer("//foo/bar//")).toString());
- }
-
-
//------------------------------------------------------------------------------------------------------------------
// Test URL-encoded strings parsed into plain-text values using
UrlEncodingParser.parseIntoSimpleMap().
//------------------------------------------------------------------------------------------------------------------
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/utils/ArrayUtilsTest.java
b/juneau-utest/src/test/java/org/apache/juneau/utils/ArrayUtilsTest.java
index 089bf61..ddbaed0 100755
--- a/juneau-utest/src/test/java/org/apache/juneau/utils/ArrayUtilsTest.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/utils/ArrayUtilsTest.java
@@ -58,91 +58,6 @@ public class ArrayUtilsTest {
}
//====================================================================================================
- // append(T[], Collection)
-
//====================================================================================================
- @Test
- public void testAppendCollectionToArray() throws Exception {
- String[] s = {};
-
- s = append(s, Arrays.asList(new String[]{"a","b"}));
- assertObject(s).asJson().is("['a','b']");
-
- s = append(s, Arrays.asList(new String[]{"c"}));
- assertObject(s).asJson().is("['a','b','c']");
-
- s = append(s, Arrays.asList(new String[0]));
- assertObject(s).asJson().is("['a','b','c']");
-
- assertThrown(()->append((Object[])null,
Collections.emptyList())).isType(IllegalArgumentException.class);
- }
-
-
//====================================================================================================
- // reverse(T[] array)
-
//====================================================================================================
- @Test
- public void testReverse() throws Exception {
- String[] s = null;
-
- assertNull(reverse(s));
-
- s = new String[]{};
- assertObject(reverse(s)).asJson().is("[]");
-
- s = new String[]{"a"};
- assertObject(reverse(s)).asJson().is("['a']");
-
- s = new String[]{"a","b"};
- assertObject(reverse(s)).asJson().is("['b','a']");
-
- s = new String[]{"a","b","c"};
- assertObject(reverse(s)).asJson().is("['c','b','a']");
-}
-
-
//====================================================================================================
- // reverseInline(T[] array)
-
//====================================================================================================
- @Test
- public void testReverseInline() throws Exception {
- String[] s = null;
-
- assertNull(reverseInline(s));
-
- s = new String[]{};
- assertObject(reverseInline(s)).asJson().is("[]");
-
- s = new String[]{"a"};
- assertObject(reverseInline(s)).asJson().is("['a']");
-
- s = new String[]{"a","b"};
- assertObject(reverseInline(s)).asJson().is("['b','a']");
-
- s = new String[]{"a","b","c"};
- assertObject(reverseInline(s)).asJson().is("['c','b','a']");
- }
-
-
//====================================================================================================
- // reverseInline(T[] array)
-
//====================================================================================================
- @Test
- public void testToReverseArray() throws Exception {
- String[] s = null;
-
- assertNull(toReverseArray(String.class, null));
-
- s = new String[]{};
- assertObject(toReverseArray(String.class,
Arrays.asList(s))).asJson().is("[]");
-
- s = new String[]{"a"};
- assertObject(toReverseArray(String.class,
Arrays.asList(s))).asJson().is("['a']");
-
- s = new String[]{"a","b"};
- assertObject(toReverseArray(String.class,
Arrays.asList(s))).asJson().is("['b','a']");
-
- s = new String[]{"a","b","c"};
- assertObject(toReverseArray(String.class,
Arrays.asList(s))).asJson().is("['c','b','a']");
- }
-
-
//====================================================================================================
// asSet(T[])
//====================================================================================================
@Test
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/utils/ByteArrayInOutStreamTest.java
b/juneau-utest/src/test/java/org/apache/juneau/utils/ByteArrayInOutStreamTest.java
deleted file mode 100755
index b0c4875..0000000
---
a/juneau-utest/src/test/java/org/apache/juneau/utils/ByteArrayInOutStreamTest.java
+++ /dev/null
@@ -1,38 +0,0 @@
-//
***************************************************************************************************************************
-// * 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.juneau.utils;
-
-import static org.apache.juneau.internal.IOUtils.*;
-import static org.junit.Assert.*;
-import static org.junit.runners.MethodSorters.*;
-import static org.apache.juneau.testutils.StreamUtils.*;
-
-import java.io.*;
-
-import org.apache.juneau.internal.*;
-import org.junit.*;
-
-@FixMethodOrder(NAME_ASCENDING)
-public class ByteArrayInOutStreamTest {
-
-
//====================================================================================================
- // testBasic
-
//====================================================================================================
- @Test
- public void testBasic() throws Exception {
- InputStream is = inputStream("foobar");
- ByteArrayInOutStream baios = new ByteArrayInOutStream();
- pipe(is, baios);
- assertEquals("foobar", read(baios.getInputStream()));
- }
-}
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/utils/StringUtilsTest.java
b/juneau-utest/src/test/java/org/apache/juneau/utils/StringUtilsTest.java
index 5e8af49..173a943 100755
--- a/juneau-utest/src/test/java/org/apache/juneau/utils/StringUtilsTest.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/utils/StringUtilsTest.java
@@ -17,10 +17,7 @@ import static org.apache.juneau.internal.StringUtils.*;
import static org.junit.Assert.*;
import static org.junit.runners.MethodSorters.*;
-import java.math.*;
import java.util.*;
-import java.util.concurrent.atomic.*;
-
import org.apache.juneau.collections.*;
import org.apache.juneau.internal.*;
import org.apache.juneau.json.*;
@@ -151,23 +148,6 @@ public class StringUtilsTest {
private abstract static class BadNumber extends Number {}
//====================================================================================================
- // parseNumber(ParserReader,Class)
-
//====================================================================================================
- @SuppressWarnings({ "rawtypes", "unchecked" })
- @Test
- public void testParseNumberFromReader() throws Exception {
- ParserReader in;
- Number n;
-
- for (Class c : new Class[]{ Integer.class, Double.class,
Float.class, Long.class, Short.class, Byte.class, BigInteger.class,
BigDecimal.class, Number.class, AtomicInteger.class, AtomicLong.class}) {
- in = new ParserReader(new ParserPipe("123'"));
- n = parseNumber(in, c);
- assertTrue(c.isInstance(n));
- assertEquals(123, n.intValue());
- }
- }
-
-
//====================================================================================================
// test - Basic tests
//====================================================================================================
@Test
@@ -434,10 +414,6 @@ public class StringUtilsTest {
assertEquals("1", join(new Object[]{1}, ","));
assertEquals("1,2", join(new Object[]{1,2}, ","));
- assertNull(join((int[])null, ","));
- assertEquals("1", join(new int[]{1}, ","));
- assertEquals("1,2", join(new int[]{1,2}, ","));
-
assertNull(join((Collection<?>)null, ","));
assertEquals("1", join(Arrays.asList(new Integer[]{1}), ","));
assertEquals("1,2", join(Arrays.asList(new Integer[]{1,2}),
","));
@@ -445,9 +421,6 @@ public class StringUtilsTest {
assertNull(join((Object[])null, ','));
assertEquals("x,y,z", join(new Object[]{"x,y","z"}, ','));
- assertNull(joine((Object[])null, ','));
- assertEquals("x\\,y,z", joine(new Object[]{"x,y","z"}, ','));
-
assertNull(join((int[])null, ','));
assertEquals("1", join(new int[]{1}, ','));
assertEquals("1,2", join(new int[]{1,2}, ','));
@@ -615,7 +588,7 @@ public class StringUtilsTest {
@Test
public void testGenerateUUID() throws Exception {
for (int i = 0; i < 10; i++) {
- String s = generateUUID(i);
+ String s = random(i);
assertEquals(i, s.length());
for (char c : s.toCharArray())
assertTrue(Character.isLowerCase(c) ||
Character.isDigit(c));
@@ -662,44 +635,6 @@ public class StringUtilsTest {
}
//====================================================================================================
- // pathStartsWith(String, String)
-
//====================================================================================================
- @Test
- public void testPathStartsWith() throws Exception {
- assertTrue(pathStartsWith("foo", "foo"));
- assertTrue(pathStartsWith("foo/bar", "foo"));
- assertFalse(pathStartsWith("foo2/bar", "foo"));
- assertFalse(pathStartsWith("foo2", "foo"));
- assertFalse(pathStartsWith("foo2", ""));
- }
-
-
//====================================================================================================
- // getField(int, String, char)
-
//====================================================================================================
- @Test
- public void testGetField() {
- String in = "0,1,2";
- assertEquals("0", getField(0, in, ','));
- assertEquals("1", getField(1, in, ','));
- assertEquals("2", getField(2, in, ','));
- assertEquals("", getField(3, in, ','));
-
- in = ",1,,3,";
- assertEquals("", getField(0, in, ','));
- assertEquals("1", getField(1, in, ','));
- assertEquals("", getField(2, in, ','));
- assertEquals("3", getField(3, in, ','));
- assertEquals("", getField(4, in, ','));
- assertEquals("", getField(5, in, ','));
-
- in = "";
- assertEquals("", getField(0, in, ','));
-
- in = null;
- assertEquals("", getField(0, in, ','));
- }
-
-
//====================================================================================================
// parseMap(String,char,char,boolean)
//====================================================================================================
@Test
@@ -799,19 +734,6 @@ public class StringUtilsTest {
}
//====================================================================================================
- // testSplitEqually(String,int)
-
//====================================================================================================
- @Test
- public void testSplitEqually() {
- assertNull(null, splitEqually(null, 3));
- assertEquals("", join(splitEqually("", 3), '|'));
- assertEquals("a", join(splitEqually("a", 3), '|'));
- assertEquals("ab", join(splitEqually("ab", 3), '|'));
- assertEquals("abc", join(splitEqually("abc", 3), '|'));
- assertEquals("abc|d", join(splitEqually("abcd", 3), '|'));
- }
-
-
//====================================================================================================
// testIsJsonObject(Object)
//====================================================================================================
@Test