Project: bml_realizer License: BSD Dependencies:
Used by:
None |
bml_realizer/src/edu/wpi/hri/bml/net/Place.javaGo to the documentation of this file.00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2010, Worcester Polytechnic Institute 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the following 00015 * disclaimer in the documentation and/or other materials provided 00016 * with the distribution. 00017 * * Neither the name of Worcester Polytechnic Institute. nor the names 00018 * of its contributors may be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 */ 00034 package edu.wpi.hri.bml.net; 00035 00036 import java.util.HashSet; 00037 import java.util.List; 00038 import java.util.Set; 00039 00040 import edu.wpi.hri.log.Logger; 00041 00049 public abstract class Place extends PetriPart { 00050 00051 private Transition input; 00052 private Set<Transition> outputs; 00053 private boolean ready; 00054 private final String name; 00055 00066 protected Place(ThreadGroup group, Logger sublog, String name) { 00067 super(group, sublog, name); 00068 this.name = name; 00069 input = null; 00070 outputs = new HashSet<Transition>(); 00071 ready = false; 00072 } 00073 00074 public String getName() { 00075 return name; 00076 } 00077 00078 @Override 00079 protected boolean checkRequirements() { 00080 return ready; 00081 } 00082 00083 @Override 00084 protected void sendTokens() { 00085 sendTokensTo(outputs); 00086 } 00087 00088 @Override 00089 protected void tokenFrom(PetriPart from) { 00090 if (from instanceof Transition) 00091 ready = ready || (input == (Transition) from); 00092 } 00093 00094 @Override 00095 public boolean existsCycle(List<PetriPart> beento) { 00096 if (beento.contains(this)) 00097 return true; 00098 00099 beento.add(this); 00100 boolean cycle = false; 00101 for (Transition t : outputs) 00102 cycle = cycle || t.existsCycle(beento); 00103 00104 beento.remove(this); 00105 return cycle; 00106 } 00107 00115 public boolean setInput(Transition t) { 00116 if (input == null) { 00117 input = t; 00118 return true; 00119 } else 00120 return false; 00121 } 00122 00128 public Transition getInput() { 00129 return input; 00130 } 00131 00139 public boolean addOutput(Transition t) { 00140 return outputs.add(t); 00141 } 00142 00148 public Set<Transition> getOutputs() { 00149 return outputs; 00150 } 00151 00161 public boolean replaceOutput(Transition oldt, Transition newt) { 00162 if (outputs.contains(oldt)) { 00163 if (outputs.contains(newt)) 00164 return outputs.remove(oldt); 00165 else 00166 return outputs.add(newt) && outputs.remove(oldt); 00167 } else 00168 return false; 00169 } 00170 00180 public boolean replaceInput(Transition oldt, Transition newt) { 00181 if (input == oldt) { 00182 input = newt; 00183 return true; 00184 } else 00185 return false; 00186 } 00187 } |