You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2014/09/15 01:27:07 UTC

[18/21] git commit: Move EnumConverter to top level class.

Move EnumConverter to top level class.


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/5fea1daf
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/5fea1daf
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/5fea1daf

Branch: refs/heads/master
Commit: 5fea1dafab4c507dbcc5b20d677228826a920966
Parents: 798c3a5
Author: Matt Sicker <ma...@apache.org>
Authored: Sun Sep 14 18:19:38 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Sun Sep 14 18:19:38 2014 -0500

----------------------------------------------------------------------
 .../config/plugins/convert/EnumConverter.java   | 38 ++++++++++++++++++++
 1 file changed, 38 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/5fea1daf/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/convert/EnumConverter.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/convert/EnumConverter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/convert/EnumConverter.java
new file mode 100644
index 0000000..15a162c
--- /dev/null
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/convert/EnumConverter.java
@@ -0,0 +1,38 @@
+/*
+ * 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.logging.log4j.core.config.plugins.convert;
+
+import org.apache.logging.log4j.util.EnglishEnums;
+
+/**
+ * Converts a {@link String} into a {@link Enum}. Returns {@code null} for invalid enum names.
+ *
+ * @param <E> the enum class to parse.
+ * @since 2.1 moved from TypeConverters
+ */
+public class EnumConverter<E extends Enum<E>> implements TypeConverter<E> {
+    private final Class<E> clazz;
+
+    public EnumConverter(final Class<E> clazz) {
+        this.clazz = clazz;
+    }
+
+    @Override
+    public E convert(final String s) {
+        return EnglishEnums.valueOf(clazz, s);
+    }
+}