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 26 27import java.util.Scanner; 28 29/** 30 * Store the information about a domain variable in a visualizer 31 * @author hsimonis 32 * 33 */ 34public class VizDVar extends VizEntry { 35 private String domain; 36 37 @Override public String toString() { 38 return "DVar "+index+" Domain "+domain; 39 } 40 41 /** 42 * the index is held as a String, it might be an integer or a list of integers, 43 * depending on the visualizer 44 * @param index String, holds integer or list of integers 45 * @param domain String, holds domain description increasing sequence of integers 46 * or a .. b integer intervals, not spaces around .. 47 * 48 */ 49 public VizDVar(String index,String domain){ 50 this.index = index; 51 this.domain = domain; 52 } 53 54 /** 55 * get the domain as an integer list 56 */ 57 public FullDomain getDomainAsList(){ 58// System.out.println(domain); 59 FullDomain list = new FullDomain(); 60 Scanner s = new Scanner(domain); 61 while (s.hasNext()) { 62 int low = s.nextInt(); 63 if (s.hasNextInt()) { 64 list.add(low); 65 } else if (s.hasNext()) { 66 String next = s.next(); 67 if (next.equals("..")) { 68 int high = s.nextInt(); 69 for(int i=low; i <= high; i++){ 70 list.add(i); 71 } 72 } else { 73 System.out.println("Syntax error in domain: "+ domain); 74 // syntax error 75 return list; 76 } 77 } else { 78 list.add(low); 79 } 80 } 81 return list; 82 } 83} 84