VerificationResult.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  *  Unless required by applicable law or agreed to in writing, software
  12.  *  distributed under the License is distributed on an "AS IS" BASIS,
  13.  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  *  See the License for the specific language governing permissions and
  15.  *  limitations under the License.
  16.  */
  17. package org.apache.bcel.verifier;

  18. /**
  19.  * A VerificationResult is what a PassVerifier returns after verifying.
  20.  */
  21. public class VerificationResult {

  22.     /**
  23.      * Constant to indicate verification has not been tried yet. This happens if some earlier verification pass did not
  24.      * return VERIFIED_OK.
  25.      */
  26.     public static final int VERIFIED_NOTYET = 0;

  27.     /** Constant to indicate verification was passed. */
  28.     public static final int VERIFIED_OK = 1;

  29.     /** Constant to indicate verfication failed. */
  30.     public static final int VERIFIED_REJECTED = 2;

  31.     /**
  32.      * This string is the canonical message for verifications that have not been tried yet. This happens if some earlier
  33.      * verification pass did not return {@link #VERIFIED_OK}.
  34.      */
  35.     private static final String VERIFIED_NOTYET_MSG = "Not yet verified.";

  36.     /** This string is the canonical message for passed verification passes. */
  37.     private static final String VERIFIED_OK_MSG = "Passed verification.";

  38.     /**
  39.      * Canonical VerificationResult for not-yet-tried verifications. This happens if some earlier verification pass did not
  40.      * return {@link #VERIFIED_OK}.
  41.      */
  42.     public static final VerificationResult VR_NOTYET = new VerificationResult(VERIFIED_NOTYET, VERIFIED_NOTYET_MSG);

  43.     /** Canonical VerificationResult for passed verifications. */
  44.     public static final VerificationResult VR_OK = new VerificationResult(VERIFIED_OK, VERIFIED_OK_MSG);

  45.     /** The numeric status. */
  46.     private final int numeric;

  47.     /** The detailed message. */
  48.     private final String detailMessage;

  49.     /** The usual constructor. */
  50.     public VerificationResult(final int status, final String message) {
  51.         numeric = status;
  52.         detailMessage = message;
  53.     }

  54.     /**
  55.      * Returns if two VerificationResult instances are equal.
  56.      */
  57.     @Override
  58.     public boolean equals(final Object o) {
  59.         if (!(o instanceof VerificationResult)) {
  60.             return false;
  61.         }
  62.         final VerificationResult other = (VerificationResult) o;
  63.         return other.numeric == this.numeric && other.detailMessage.equals(this.detailMessage);
  64.     }

  65.     /** Returns a detailed message. */
  66.     public String getMessage() {
  67.         return detailMessage;
  68.     }

  69.     /**
  70.      * Returns one of the {@link #VERIFIED_OK}, {@link #VERIFIED_NOTYET}, {@link #VERIFIED_REJECTED} constants.
  71.      */
  72.     public int getStatus() {
  73.         return numeric;
  74.     }

  75.     /**
  76.      * @return a hash code value for the object.
  77.      */
  78.     @Override
  79.     public int hashCode() {
  80.         return numeric ^ detailMessage.hashCode();
  81.     }

  82.     /**
  83.      * Returns a String representation of the VerificationResult.
  84.      */
  85.     @Override
  86.     public String toString() {
  87.         String ret = "";
  88.         if (numeric == VERIFIED_NOTYET) {
  89.             ret = "VERIFIED_NOTYET";
  90.         }
  91.         if (numeric == VERIFIED_OK) {
  92.             ret = "VERIFIED_OK";
  93.         }
  94.         if (numeric == VERIFIED_REJECTED) {
  95.             ret = "VERIFIED_REJECTED";
  96.         }
  97.         ret += "\n" + detailMessage + "\n";
  98.         return ret;
  99.     }
  100. }