1// BEGIN LICENSE BLOCK
2// Version: CMPL 1.1
3//
4// The contents of this file are subject to the Cisco-style Mozilla Public
5// License Version 1.1 (the "License"); you may not use this file except
6// in compliance with the License.  You may obtain a copy of the License
7// at www.eclipse-clp.org/license.
8//
9// Software distributed under the License is distributed on an "AS IS"
10// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See
11// the License for the specific language governing rights and limitations
12// under the License.
13//
14// The Original Code is  CPViz Constraint Visualization System
15// The Initial Developer of the Original Code is  Helmut Simonis
16// Portions created by the Initial Developer are
17// Copyright (C) 2009-2010 Helmut Simonis
18//
19// Contributor(s): 	Helmut Simonis, 4C, Univerity College Cork, Cork
20//
21//
22// END LICENSE BLOCK
23// ----------------------------------------------------------------------
24package ie.ucc.cccc.viz;
25
26import java.util.*;
27
28/**
29 * A class to represent a full domain as a collection of all its elements.
30 * @author hsimonis
31 *
32 */
33
34public class FullDomain extends ArrayList<Integer> {
35
36	/**
37	 * This seems required to make eclipse shut up
38	 */
39	private static final long serialVersionUID = 4229969495363870266L;
40
41	/**
42	 * get the minimal value in a domain
43	 * @return int
44	 */
45	public int getMin(){
46		Iterator<Integer> li = iterator();
47		int res = li.next();
48		while (li.hasNext()) {
49			res = Math.min(res,li.next());
50		}
51		return res;
52	}
53	/**
54	 * get the maximal value in a domain
55	 * @return int
56	 */
57	public int getMax(){
58		Iterator<Integer> li = iterator();
59		int res = li.next();
60		while (li.hasNext()) {
61			res = Math.max(res,li.next());
62		}
63		return res;
64	}
65	/**
66	 * get the unique value in the domain; assumes that the domain has
67	 * only one element, otherwise an assertion fails
68	 * @return int
69	 */
70	public int getIntValue() {
71		assert size() == 1;
72		return get(0);
73	}
74
75	/**
76	 * check if a value v is in the domain
77	 * @param v int
78	 * @return boolean true if the value is in the domain
79	 */
80	public boolean isInDomain(int v){
81		return contains(v);
82	}
83
84	/**
85	 * check if a domain is a singleton, i.e. contains only one value
86	 * @return boolean, true if domain has only one value
87	 */
88	public boolean isFixed() {
89		return size() == 1;
90	}
91
92	public FullDomain getRemovedValues(FullDomain current){
93		FullDomain removed = new FullDomain();
94		if (current != null) {
95		for(int value: this){
96			if (!current.isInDomain(value)){
97				removed.add(value);
98			}
99		}
100		}
101//		System.out.println("Removed: "+removed);
102		return removed;
103	}
104}
105