SequenceImpl.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.domain.machine;

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

  25. import cern.accsoft.steering.jmad.domain.beam.Beam;

  26. /**
  27.  * Represents a <a href="http://mad.web.cern.ch/mad/Introduction/sequence.html">SEQUENCE</a> in the MadX-model. This
  28.  * class also manages the its ranges and knows about its own {@link SequenceDefinition}.
  29.  *
  30.  * @author Kajetan Fuchsberger (kajetan.fuchsberger at cern.ch)
  31.  */
  32. public class SequenceImpl implements Sequence {

  33.     /** The definition from which this sequence is derived */
  34.     private final SequenceDefinition sequenceDefinition;

  35.     /** the available ranges of the sequence */
  36.     private final List<Range> ranges = new ArrayList<Range>();

  37.     /**
  38.      * simple constructor, just give the sequenceDefinition.
  39.      *
  40.      * @param sequenceDefinition the {@link SequenceDefinition} to use to create this sequence
  41.      */
  42.     public SequenceImpl(SequenceDefinition sequenceDefinition) {
  43.         this.sequenceDefinition = sequenceDefinition;
  44.         for (RangeDefinition rangeDefinition : this.sequenceDefinition.getRangeDefinitions()) {
  45.             this.ranges.add(new Range(rangeDefinition));
  46.         }
  47.     }

  48.     @Override
  49.     public String getName() {
  50.         return getSequenceDefinition().getName();
  51.     }

  52.     @Override
  53.     public List<Range> getRanges() {
  54.         return ranges;
  55.     }

  56.     @Override
  57.     public Range getDefaultRange() {
  58.         /*
  59.          * we just return the first entry, if available.
  60.          */
  61.         if (ranges.isEmpty()) {
  62.             return null;
  63.         } else {
  64.             return ranges.get(0);
  65.         }
  66.     }

  67.     @Override
  68.     public String toString() {
  69.         return getName();
  70.     }

  71.     @Override
  72.     public final Beam getBeam() {
  73.         return getSequenceDefinition().getBeam();
  74.     }

  75.     public SequenceDefinition getSequenceDefinition() {
  76.         return sequenceDefinition;
  77.     }
  78. }