1 /* 2 * Copyright (c) 2011-2025 Yegor Bugayenko 3 * 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 1) Redistributions of source code must retain the above 9 * copyright notice, this list of conditions and the following 10 * disclaimer. 2) Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following 12 * disclaimer in the documentation and/or other materials provided 13 * with the distribution. 3) Neither the name of the Qulice.com nor 14 * the names of its contributors may be used to endorse or promote 15 * products derived from this software without specific prior written 16 * permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 20 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 21 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 * OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 package com.qulice.spi; 32 33 import lombok.EqualsAndHashCode; 34 import lombok.ToString; 35 36 /** 37 * Validation result. 38 * 39 * @since 0.17 40 */ 41 public interface Violation extends Comparable<Violation> { 42 43 /** 44 * Name of the validator that generated this violation information. 45 * @return Name of the validator 46 */ 47 String validator(); 48 49 /** 50 * Name of the failed check. 51 * @return Name of the failed check 52 */ 53 String name(); 54 55 /** 56 * Validated file. 57 * @return Validated file. 58 */ 59 String file(); 60 61 /** 62 * Lines with the problem. 63 * @return Lines with the problem 64 */ 65 String lines(); 66 67 /** 68 * Validation message. 69 * @return Validation message. 70 */ 71 String message(); 72 73 /** 74 * Default validation result. 75 * 76 * @since 0.1 77 */ 78 @EqualsAndHashCode 79 @ToString 80 final class Default implements Violation { 81 82 /** 83 * Name of the validator that generated this violation information. 84 */ 85 private final String vldtr; 86 87 /** 88 * Name of the failed check. 89 */ 90 private final String nam; 91 92 /** 93 * Lines with the problem. 94 */ 95 private final String lns; 96 97 /** 98 * Validated file. 99 */ 100 private final String fle; 101 102 /** 103 * Validation message. 104 */ 105 private final String msg; 106 107 /** 108 * Constructor. 109 * @param vldtr Name of the validator 110 * @param nam Name of the failed check 111 * @param fle Validated file 112 * @param lns Lines with the problem 113 * @param msg Validation message 114 * @checkstyle ParameterNumber (3 lines) 115 */ 116 public Default(final String vldtr, final String nam, final String fle, 117 final String lns, final String msg) { 118 this.vldtr = vldtr; 119 this.nam = nam; 120 this.fle = fle; 121 this.lns = lns; 122 this.msg = msg; 123 } 124 125 @Override 126 public String validator() { 127 return this.vldtr; 128 } 129 130 @Override 131 public String name() { 132 return this.nam; 133 } 134 135 @Override 136 public String file() { 137 return this.fle; 138 } 139 140 @Override 141 public String lines() { 142 return this.lns; 143 } 144 145 @Override 146 public String message() { 147 return this.msg; 148 } 149 150 @Override 151 public int compareTo(final Violation other) { 152 return this.vldtr.compareToIgnoreCase(other.validator()); 153 } 154 } 155 156 }