Package org.nlogo.sdm.gui

Source Code of org.nlogo.sdm.gui.Wrapper

// (C) Uri Wilensky. https://github.com/NetLogo/NetLogo

package org.nlogo.sdm.gui;

import org.jhotdraw.util.Storable;
import org.nlogo.sdm.Converter;
import org.nlogo.sdm.ModelElement;
import org.nlogo.sdm.Rate;
import org.nlogo.sdm.Reservoir;
import org.nlogo.sdm.Stock;

import java.util.HashMap;
import java.util.Map;

strictfp final class Wrapper {
  // private constructor to enforce noninstantiability
  private Wrapper() {
  }

  static Map<ModelElement, Storable> map =
      new HashMap<ModelElement, Storable>();

  static Storable wrap(ModelElement o) {
    Storable result = map.get(o);
    if (result != null) {
      return result;
    }
    if (o instanceof Reservoir) {
      result = new WrappedReservoir((Reservoir) o);
    } else if (o instanceof Stock) {
      result = new WrappedStock((Stock) o);
    } else if (o instanceof Converter) {
      result = new WrappedConverter((Converter) o);
    } else if (o instanceof Rate) {
      result = new WrappedRate((Rate) o);
    } else {
      throw new IllegalArgumentException();
    }
    map.put(o, result);
    return result;
  }

  static void reset() {
    map = new HashMap<ModelElement, Storable>();
  }

}
TOP

Related Classes of org.nlogo.sdm.gui.Wrapper

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.