/** * Create a binary exception classifier with the provided classes and their * subclasses. The mapped value for these exceptions will be the one * provided (which will be the opposite of the default). * * @param exceptionClasses the exceptions to classify among * @param value the value to classify */ public BinaryExceptionClassifier(Collection<Class<? extends Throwable>> exceptionClasses, boolean value) { this(!value); if (exceptionClasses != null) { Map<Class<? extends Throwable>, Boolean> map = new HashMap<Class<? extends Throwable>, Boolean>(); for (Class<? extends Throwable> type : exceptionClasses) { map.put(type, !getDefault()); } setTypeMap(map); } }
@Override public Boolean classify(Throwable classifiable) { Boolean classified = super.classify(classifiable); if (!this.traverseCauses) { return classified; } /* * If the result is the default, we need to find out if it was by default * or so configured; if default, try the cause(es). */ if (classified.equals(this.getDefault())) { Throwable cause = classifiable; do { if (this.getClassified().containsKey(cause.getClass())) { return classified; // non-default classification } cause = cause.getCause(); classified = super.classify(cause); } while (cause != null && classified.equals(this.getDefault())); } return classified; }
/** * Create a binary exception classifier with the provided classes and their * subclasses. The mapped value for these exceptions will be the one * provided (which will be the opposite of the default). * * @param exceptionClasses the exceptions to classify among * @param value the value to classify */ public BinaryExceptionClassifier(Collection<Class<? extends Throwable>> exceptionClasses, boolean value) { this(!value); if (exceptionClasses != null) { Map<Class<? extends Throwable>, Boolean> map = new HashMap<Class<? extends Throwable>, Boolean>(); for (Class<? extends Throwable> type : exceptionClasses) { map.put(type, !getDefault()); } setTypeMap(map); } }
@Override public Boolean classify(Throwable classifiable) { Boolean classified = super.classify(classifiable); if (!this.traverseCauses) { return classified; } /* * If the result is the default, we need to find out if it was by default * or so configured; if default, try the cause(es). */ if (classified.equals(this.getDefault())) { Throwable cause = classifiable; do { if (this.getClassified().containsKey(cause.getClass())) { return classified; // non-default classification } cause = cause.getCause(); classified = super.classify(cause); } while (cause != null && classified.equals(this.getDefault())); } return classified; }