1 /*
2 * Copyright (c) 2011-2024 Qulice.com
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 @SuppressWarnings("PMD.TooManyMethods")
42 public interface Violation extends Comparable<Violation> {
43
44 /**
45 * Name of the validator that generated this violation information.
46 * @return Name of the validator
47 */
48 String validator();
49
50 /**
51 * Name of the failed check.
52 * @return Name of the failed check
53 */
54 String name();
55
56 /**
57 * Validated file.
58 * @return Validated file.
59 */
60 String file();
61
62 /**
63 * Lines with the problem.
64 * @return Lines with the problem
65 */
66 String lines();
67
68 /**
69 * Validation message.
70 * @return Validation message.
71 */
72 String message();
73
74 /**
75 * Default validation result.
76 *
77 * @since 0.1
78 */
79 @EqualsAndHashCode
80 @ToString
81 final class Default implements Violation {
82
83 /**
84 * Name of the validator that generated this violation information.
85 */
86 private final String vldtr;
87
88 /**
89 * Name of the failed check.
90 */
91 private final String nam;
92
93 /**
94 * Lines with the problem.
95 */
96 private final String lns;
97
98 /**
99 * Validated file.
100 */
101 private final String fle;
102
103 /**
104 * Validation message.
105 */
106 private final String msg;
107
108 /**
109 * Constructor.
110 * @param vldtr Name of the validator
111 * @param nam Name of the failed check
112 * @param fle Validated file
113 * @param lns Lines with the problem
114 * @param msg Validation message
115 * @checkstyle ParameterNumber (3 lines)
116 */
117 public Default(final String vldtr, final String nam, final String fle,
118 final String lns, final String msg) {
119 this.vldtr = vldtr;
120 this.nam = nam;
121 this.fle = fle;
122 this.lns = lns;
123 this.msg = msg;
124 }
125
126 @Override
127 public String validator() {
128 return this.vldtr;
129 }
130
131 @Override
132 public String name() {
133 return this.nam;
134 }
135
136 @Override
137 public String file() {
138 return this.fle;
139 }
140
141 @Override
142 public String lines() {
143 return this.lns;
144 }
145
146 @Override
147 public String message() {
148 return this.msg;
149 }
150
151 @Override
152 public int compareTo(final Violation other) {
153 return this.vldtr.compareToIgnoreCase(other.validator());
154 }
155 }
156
157 }