[jsemver] 74/95: Create a wrapper exception for UnexpectedElementException

Alexandre Viau reazem-guest at moszumanska.debian.org
Mon Feb 16 14:58:32 UTC 2015


This is an automated email from the git hooks/post-receive script.

reazem-guest pushed a commit to branch master
in repository jsemver.

commit 2233bdf5032a3af5cbb08ed4262de50bc536367f
Author: Zafar Khaja <zafarkhaja at gmail.com>
Date:   Tue Jan 28 11:20:02 2014 +0400

    Create a wrapper exception for UnexpectedElementException
---
 ...tion.java => UnexpectedCharacterException.java} | 57 ++++++++++++++--------
 .../semver/util/UnexpectedElementException.java    | 18 +++++++
 2 files changed, 56 insertions(+), 19 deletions(-)

diff --git a/src/main/java/com/github/zafarkhaja/semver/util/UnexpectedElementException.java b/src/main/java/com/github/zafarkhaja/semver/UnexpectedCharacterException.java
similarity index 54%
copy from src/main/java/com/github/zafarkhaja/semver/util/UnexpectedElementException.java
copy to src/main/java/com/github/zafarkhaja/semver/UnexpectedCharacterException.java
index a85e005..657bca5 100644
--- a/src/main/java/com/github/zafarkhaja/semver/util/UnexpectedElementException.java
+++ b/src/main/java/com/github/zafarkhaja/semver/UnexpectedCharacterException.java
@@ -1,7 +1,7 @@
 /*
  * The MIT License
  *
- * Copyright 2013 Zafar Khaja <zafarkhaja at gmail.com>.
+ * Copyright 2014 Zafar Khaja <zafarkhaja at gmail.com>.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -21,40 +21,59 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
-package com.github.zafarkhaja.semver.util;
+package com.github.zafarkhaja.semver;
 
-import com.github.zafarkhaja.semver.util.Stream.ElementType;
+import com.github.zafarkhaja.semver.VersionParser.CharType;
+import com.github.zafarkhaja.semver.util.UnexpectedElementException;
 import java.util.Arrays;
 
 /**
- * Thrown when attempting to consume a stream element of unexpected types.
+ * Thrown when attempting to consume a character of unexpected types.
+ *
+ * This exception is a wrapper exception extending {@code ParseException}.
  *
  * @author Zafar Khaja <zafarkhaja at gmail.com>
- * @see Stream#consume(Stream.ElementType...)
- * @since 0.7.0
+ * @since 0.8.0
  */
-public class UnexpectedElementException extends RuntimeException {
+public class UnexpectedCharacterException extends ParseException {
+
+    /**
+     * The unexpected character.
+     */
+    private final Character unexpected;
 
     /**
-     * The unexpected element in the stream.
+     * The array of expected character types.
      */
-    private final Object unexpected;
+    private final CharType[] expected;
 
     /**
-     * The array of the expected element types.
+     * Constructs a {@code UnexpectedCharacterException} instance
+     * with the unexpected character and the expected types.
+     *
+     * @param cause the wrapped exception
      */
-    private final ElementType<?>[] expected;
+    UnexpectedCharacterException(UnexpectedElementException cause) {
+        unexpected = (Character) cause.getUnexpectedElement();
+        expected = (CharType[]) cause.getExpectedElementTypes();
+    }
+
+    /**
+     * Gets the unexpected character.
+     *
+     * @return the unexpected character
+     */
+    Character getUnexpectedCharacter() {
+        return unexpected;
+    }
 
     /**
-     * Constructs a {@code UnexpectedElementException} instance
-     * with the unexpected element and the expected types.
+     * Gets the expected character types.
      *
-     * @param element the unexpected element in the stream
-     * @param expected an array of the expected element types
+     * @return an array of expected character types
      */
-    UnexpectedElementException(Object element, ElementType<?>... expected) {
-        unexpected = element;
-        this.expected = expected;
+    CharType[] getExpectedCharTypes() {
+        return expected;
     }
 
     /**
@@ -66,7 +85,7 @@ public class UnexpectedElementException extends RuntimeException {
      */
     @Override
     public String toString() {
-        String message = "Unexpected element '" + unexpected + "'";
+        String message = "Unexpected character '" + unexpected + "'";
         if (expected.length > 0) {
             message += ", expecting '" + Arrays.toString(expected) + "'";
         }
diff --git a/src/main/java/com/github/zafarkhaja/semver/util/UnexpectedElementException.java b/src/main/java/com/github/zafarkhaja/semver/util/UnexpectedElementException.java
index a85e005..f8b56c9 100644
--- a/src/main/java/com/github/zafarkhaja/semver/util/UnexpectedElementException.java
+++ b/src/main/java/com/github/zafarkhaja/semver/util/UnexpectedElementException.java
@@ -58,6 +58,24 @@ public class UnexpectedElementException extends RuntimeException {
     }
 
     /**
+     * Gets the unexpected element.
+     *
+     * @return the unexpected element
+     */
+    public Object getUnexpectedElement() {
+        return unexpected;
+    }
+
+    /**
+     * Gets the expected element types.
+     *
+     * @return an array of expected element types
+     */
+    public ElementType<?>[] getExpectedElementTypes() {
+        return expected;
+    }
+
+    /**
      * Returns the string representation of this exception
      * containing the information about the unexpected
      * element and, if available, about the expected types.

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/jsemver.git



More information about the pkg-java-commits mailing list