-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
174 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/main/java/nova/commands/exception/CommandException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (c) 2017 NOVA, All rights reserved. | ||
* This library is free software, licensed under GNU Lesser General Public License version 3 | ||
* | ||
* This file is part of NOVA. | ||
* | ||
* NOVA is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* NOVA is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with NOVA. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package nova.commands.exception; | ||
|
||
import nova.core.util.exception.NovaException; | ||
|
||
import java.util.Arrays; | ||
import java.util.Optional; | ||
|
||
/** | ||
* @author ExE Boss | ||
*/ | ||
public class CommandException extends NovaException { | ||
|
||
private static final long serialVersionUID = 1L; | ||
private final Object[] arguments; | ||
|
||
public CommandException() { | ||
this.arguments = null; | ||
} | ||
|
||
public CommandException(String message, Object... parameters) { | ||
super(message, parameters); | ||
this.arguments = Arrays.copyOf(parameters, parameters.length); | ||
} | ||
|
||
public CommandException(String message) { | ||
super(message); | ||
this.arguments = null; | ||
} | ||
|
||
public CommandException(String message, Throwable cause) { | ||
super(message, cause); | ||
this.arguments = null; | ||
} | ||
|
||
public CommandException(String message, Throwable cause, Object... parameters) { | ||
super(message, parameters); | ||
this.initCause(cause); | ||
this.arguments = Arrays.copyOf(parameters, parameters.length); | ||
} | ||
|
||
public CommandException(Throwable cause) { | ||
super(cause); | ||
this.arguments = null; | ||
} | ||
|
||
public Optional<Object[]> getArguments() { | ||
return Optional.ofNullable(Arrays.copyOf(arguments, arguments.length)); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
src/main/java/nova/commands/exception/CommandParseException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright (c) 2017 NOVA, All rights reserved. | ||
* This library is free software, licensed under GNU Lesser General Public License version 3 | ||
* | ||
* This file is part of NOVA. | ||
* | ||
* NOVA is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* NOVA is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with NOVA. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package nova.commands.exception; | ||
|
||
import nova.commands.ArgsParser; | ||
import nova.core.util.EnumSelector; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.EnumSet; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
/** | ||
* @author ExE Boss | ||
*/ | ||
public class CommandParseException extends CommandException { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
private final Set<ArgsParser.Errors> errors; | ||
|
||
public CommandParseException(String message) { | ||
super(message); | ||
this.errors = null; | ||
} | ||
|
||
public CommandParseException(String message, Throwable cause) { | ||
super(message, cause); | ||
this.errors = null; | ||
} | ||
|
||
private CommandParseException(String message, Set<ArgsParser.Errors> errors) { | ||
super(message + ": " + errors); | ||
this.errors = errors; | ||
} | ||
|
||
public CommandParseException(String message, ArgsParser.Errors... errors) { | ||
this(message, toEnumSet(errors)); | ||
} | ||
|
||
public CommandParseException(String message, EnumSet<ArgsParser.Errors> errors) { | ||
this(message, Collections.unmodifiableSet(errors)); | ||
} | ||
|
||
public CommandParseException(String message, EnumSelector<ArgsParser.Errors> errors) { | ||
this(message, errors.toSet()); | ||
} | ||
|
||
public Optional<Set<ArgsParser.Errors>> getErrors() { | ||
return Optional.ofNullable(errors); | ||
} | ||
|
||
private static EnumSet<ArgsParser.Errors> toEnumSet(ArgsParser.Errors... errors) { | ||
EnumSet<ArgsParser.Errors> set = EnumSet.noneOf(ArgsParser.Errors.class); | ||
set.addAll(Arrays.asList(errors)); | ||
return set; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters