/* PseudoCode Interpreted Language (PCIL): Part of the algoviz@vt collection of algorithm visualizations. Copyright (C) 2008 Brandon Malone, Frank Hadlock This file is part of the PseudoCode Interpreted Language. PseudoCode Interpreted Language is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. PseudoCode Interpreted Language 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 Public License for more details. You should have received a copy of the GNU General Public License along with PseudoCode Interpreted Language. If not, see . */ /* * PrimitiveStructure.java * * Created on March 3, 2008, 9:58 PM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package dynamicmvc; import java.util.ArrayList; import java.util.HashMap; import javax.swing.JComponent; import syntacticanalysis.Function; /** * * @author Brandon */ public class PrimitiveStructure extends Primitive { public static String pseudocodeTypeName() { return "Structure"; } public String getType() { return pseudocodeTypeName(); } private String name; private ArrayList functions; private State myState; /** Creates a new instance of PrimitiveStructure */ public PrimitiveStructure() { super(); } public JComponent getReadOnlyComponent(){ return null; } public JComponent getEditComponent(){ return null; } public String getEditComponentWrapperName(){ return ""; } public void populateFromEditComponentWrapper(JComponent editComponentWrapper){} public void setName(String name){ this.name = name; } public String getName(){ return name; } public void set(String name, PrimitivePointer value) { if(myState != null) { myState.setStateVariable(name, value); } super.set(name, value); } public ArrayList getFunctions() { return functions; } public void setFunctions(ArrayList functions) { this.functions = functions; } public Primitive copy() throws DynamicMVCException { PrimitiveStructure s = new PrimitiveStructure(); for(PrimitivePointer p : getDefinedProperties().values()) { s.set(p.getName(), p); } return s; } public Primitive deepCopy(HashMap alreadyCopiedAddresses) throws DynamicMVCException { PrimitivePointer p = getPointer(); if (alreadyCopiedAddresses.containsKey(Integer.valueOf(p.getAddress()))) { return PrimitiveFactory.getFromMemory(alreadyCopiedAddresses.get(p.getAddress())); } PrimitivePointer pp = PrimitiveFactory.create(pseudocodeTypeName(), name); alreadyCopiedAddresses.put(p.getAddress(), pp.getAddress()); PrimitiveStructure s = (PrimitiveStructure)pp.dereference(); super.deepCopyDefinedProperties(s, alreadyCopiedAddresses); return s; } public boolean deepEquals(Primitive p) throws DynamicMVCException { if (!(p instanceof PrimitiveStructure)) { DynamicController.errorMessage = "Expecting Structure, but found " + p.getType(); return false; } return super.deepEqualsDefinedProperties(p); } public Object execute(String methodName, ArrayList arguments) throws DynamicMVCException{ for (Function f : functions) { if (f.getName().equals(methodName)) { return f; } } throw new DynamicMVCException ("Object: '" + name + "' does not support method '" + methodName + "'."); } public String toString() { StringBuilder sb = new StringBuilder(); sb.append(name + ": "); for(PrimitivePointer p : getDefinedProperties().values()) { sb.append("\n"); sb.append(p.toString()); } //return sb.toString(); return "state\n"; } public State getMyState() { return myState; } public void setMyState(State myState) { this.myState = myState; } }