001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.camel.component.extension.verifier; 018 019import java.io.Serializable; 020import java.util.Arrays; 021import java.util.Collection; 022import java.util.HashSet; 023import java.util.LinkedHashSet; 024import java.util.Set; 025 026/** 027 * A named group of options. A group of options requires that a set of 028 * component parameters is given as a whole. 029 * 030 * <a id="#syntax">The option syntax can be 031 * {@code "propertyName"} to denote required property and 032 * {@code "!propertyName"} to denote required absence of a property. 033 */ 034public final class OptionsGroup implements Serializable { 035 private final String name; 036 private final Set<String> options; 037 038 /** 039 * Creates new named {@link OptionsGroup}. 040 * 041 * @param name the name of the group 042 */ 043 public OptionsGroup(String name) { 044 this.name = name; 045 this.options = new HashSet<>(); 046 } 047 048 /** 049 * Creates new named {@link OptionsGroup} with a set of option 050 * definitions. 051 * 052 * @param name the name of the group 053 * @param options names of properties in the syntax mentioned in {@link OptionsGroup} 054 */ 055 public OptionsGroup(String name, Collection<String> options) { 056 this.name = name; 057 this.options = new LinkedHashSet<>(options); 058 } 059 060 /** 061 * Adds a option definition to this group. The option syntax can be 062 * {@code "propertyName"} to denote required property and 063 * {@code "!propertyName"} to denote required absence of a property. 064 * 065 * @param option definition. 066 */ 067 public void addOption(String option) { 068 this.options.add(option); 069 } 070 071 /** 072 * The name of the group. 073 */ 074 public String getName() { 075 return name; 076 } 077 078 /** 079 * The option definitions in this group. 080 */ 081 public Set<String> getOptions() { 082 return this.options; 083 } 084 085 /** 086 * Adds a option definition to this group. The option syntax can be 087 * {@code "propertyName"} to denote required property and 088 * {@code "!propertyName"} to denote required absence of a property. 089 * 090 * @param option definition. 091 */ 092 public OptionsGroup option(String option) { 093 this.options.add(option); 094 return this; 095 } 096 097 /** 098 * Adds a number of option definitions to this group. The option 099 * syntax can be {@code "propertyName"} to denote required 100 * property and {@code "!propertyName"} to denote required absence 101 * of a property. 102 * 103 * @param options options definition 104 */ 105 public OptionsGroup options(String... options) { 106 for (String option : options) { 107 addOption(option); 108 } 109 110 return this; 111 } 112 113 /** 114 * Creates new group with the specified name. 115 * 116 * @param name the name of the group 117 */ 118 public static OptionsGroup withName(String name) { 119 return new OptionsGroup(name); 120 } 121 122 /** 123 * Creates new group with the specified name of the given 124 * {@link Enum} name. 125 * 126 * @param enumItem the name of the group 127 * @see Enum#name() 128 */ 129 public static OptionsGroup withName(Enum<?> enumItem) { 130 return new OptionsGroup(enumItem.name()); 131 } 132 133 /** 134 * Creates new group with the specified name and option definitions. 135 * 136 * @param name the name of the group 137 * @param options options definition 138 */ 139 public static OptionsGroup withNameAndOptions(String name, String... options) { 140 return new OptionsGroup(name, Arrays.asList(options)); 141 } 142}