All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.appng.api.support.OptionOwner Maven / Gradle / Ivy

There is a newer version: 1.24.5
Show newest version
/*
 * Copyright 2011-2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.appng.api.support;

import java.util.List;

import org.appng.xml.platform.Option;

public interface OptionOwner {

	List getOptions();

	void addOption(org.appng.xml.platform.Option option);

	org.appng.xml.platform.Option addOption(String name, String value, boolean selected);

	/**
	 * A selector decides whether or not a given {@link Option} should be selected. Also implements {@link HitCounter},
	 * using the options's value and returning {@code null} by default.
	 * 
	 * @see Option#isSelected()
	 */
	public interface Selector extends HitCounter {
		/**
		 * Selects or de-selects an option by calling {@link Option#setSelected(Boolean)}.
		 * 
		 * @param o
		 *            the {@link Option} which might be selected
		 */
		void select(Option o);

		default Integer count(String optionValue) {
			return null;
		}
	}

	/**
	 * Counts the hits for {@link Option}s.
	 * 
	 * @param 
	 *            the type of the elements to count
	 * @see Option#getHits()
	 */
	public interface HitCounter {
		/**
		 * Counts the hits for the option created from the given element.
		 * 
		 * @param element
		 *            the element to count the hits for
		 * @return the number of hits for this option
		 */
		Integer count(T element);
	}

	class OptionOwnerBase implements OptionOwner {

		private List




© 2015 - 2025 Weber Informatics LLC | Privacy Policy