
zebra4j.AttributeType Maven / Gradle / Ivy
/*-
* #%L
* zebra4j
* %%
* Copyright (C) 2020 Marin Nozhchev
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
package zebra4j;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Set;
/**
* A type attribute for a person like a "name", "pet" or if the person is a
* criminal
*
*
* AttributeType is used as members of sets and as keys in maps so
* implementations must implement equals and hashCode. Singleton implementations
* are fine because {@link Object#equals(Object)} and {@link Object#hashCode()}
* work correctly for singletons.
*
*
* When defining custom attributes, consider using {@link BasicAttributeType} or
* extending the abstract {@link AllDifferentType}.
*
* @see Attribute
*/
public interface AttributeType {
/**
* Adds rules related to the subset of attributes of this type used in a puzzle
* to the model describing the puzzle
*
* @param model
* @param attributesOfType
* @param numPeople
*/
void addToModel(ZebraModel model, Set attributesOfType, int numPeople);
/**
* Returns the pattern for questions "about" this attribute type
*
* @param locale
* @return a pattern for {@link String#format} with a single placeholder for the
* attribute of the person the question is towards.
*
* @see Question
*/
String questionSentencePart(Locale locale);
/**
* Return some attributes of this type.
*
*
* Used when generating solutions.
*
* @param count how many attributes to return
* @return A subset of the attributes of this type
* @throws IllegalArgumentException if count is larger than the number of all
* possible attributes of this type
*/
List getAttributes(int count);
/**
* Describe the given set of attributes in the form of sentence, in the given
* locale, describing a rule for solving a puzzle.
*
*
* The sentence is in the form: People's names are Mary, Jane and Steve.
*
* @param subset the set of attributes of this type, used in a puzzle
* @param locale
* @return a sentence string, not null.
*/
String describeSet(Collection subset, Locale locale);
}