1 /*
2 * Hibernate Validator, declare and validate application constraints
3 *
4 * License: Apache License, Version 2.0
5 * See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
6 */
7 package org.hibernate.validator.internal.metadata.raw;
8
9 /**
10 * The source of constraint meta data.
11 *
12 * @author Gunnar Morling
13 */
14 public enum ConfigurationSource {
15
16 /**
17 * The source of configuration are annotation in the source code
18 */
19 ANNOTATION( 0 ),
20 /**
21 * The source of configuration is XML configuration
22 */
23 XML( 1 ),
24 /**
25 * The source of configuration is the programmatic API
26 */
27 API( 2 );
28
29 private int priority;
30
31 private ConfigurationSource(int priority) {
32 this.priority = priority;
33 }
34
35 /**
36 * Returns this sources priority. Can be used to determine which
37 * configuration shall apply in case of conflicting configurations by
38 * several providers.
39 *
40 * @return This source's priority.
41 */
42 public int getPriority() {
43 return priority;
44 }
45
46 /**
47 * Returns that configuration source from the given two sources, which has
48 * the higher priority.
49 *
50 * @param a
51 * A configuration source.
52 * @param b
53 * Another configuration source.
54 *
55 * @return The source with the higher priority. Will be source {@code a} if
56 * both have the same priority.
57 */
58 public static ConfigurationSource max(ConfigurationSource a, ConfigurationSource b) {
59 return a.getPriority() >= b.getPriority() ? a : b;
60 }
61 }
62