DefineAndInstallElements.java

  1. // @formatter:off
  2.  /*******************************************************************************
  3.  *
  4.  * This file is part of JMad.
  5.  *
  6.  * Copyright (c) 2008-2011, CERN. All rights reserved.
  7.  *
  8.  * Licensed under the Apache License, Version 2.0 (the "License");
  9.  * you may not use this file except in compliance with the License.
  10.  * You may obtain a copy of the License at
  11.  *
  12.  *     http://www.apache.org/licenses/LICENSE-2.0
  13.  *
  14.  * Unless required by applicable law or agreed to in writing, software
  15.  * distributed under the License is distributed on an "AS IS" BASIS,
  16.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17.  * See the License for the specific language governing permissions and
  18.  * limitations under the License.
  19.  *
  20.  ******************************************************************************/
  21. // @formatter:on

  22. package cern.accsoft.steering.jmad.kernel.task;

  23. import java.util.ArrayList;
  24. import java.util.List;

  25. import cern.accsoft.steering.jmad.domain.elem.Element;
  26. import cern.accsoft.steering.jmad.kernel.cmd.Command;
  27. import cern.accsoft.steering.jmad.kernel.cmd.DefineElement;
  28. import cern.accsoft.steering.jmad.kernel.cmd.seqedit.EndeditCommand;
  29. import cern.accsoft.steering.jmad.kernel.cmd.seqedit.FlattenCommand;
  30. import cern.accsoft.steering.jmad.kernel.cmd.seqedit.InstallCommand;
  31. import cern.accsoft.steering.jmad.kernel.cmd.seqedit.SeqeditCommand;

  32. /**
  33.  * Define a list of element and add them to the sequence This class has not been tested for usage online.
  34.  *
  35.  * @author xbuffat
  36.  */

  37. public class DefineAndInstallElements extends AbstractTask {

  38.     private String sequence;
  39.     private List<Element> toInstall;

  40.     public DefineAndInstallElements(String sequ, List<Element> toInstall) {
  41.         this.sequence = sequ;
  42.         this.toInstall = toInstall;
  43.     }

  44.     @Override
  45.     protected List<Command> getCommands() {
  46.         List<Command> commands = new ArrayList<Command>();
  47.         for (int i = 0; i < this.toInstall.size(); ++i) {
  48.             commands.add(new DefineElement(this.toInstall.get(i)));
  49.         }
  50.         commands.add(new SeqeditCommand(this.sequence));
  51.         for (int i = 0; i < this.toInstall.size(); ++i) {
  52.             commands.add(new InstallCommand(this.toInstall.get(i)));
  53.         }
  54.         commands.add(new FlattenCommand());
  55.         commands.add(new EndeditCommand());
  56.         return commands;
  57.     }

  58. }