MadxRange.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. /**
  23.  *
  24.  */
  25. package cern.accsoft.steering.jmad.domain.machine;

  26. import com.thoughtworks.xstream.annotations.XStreamAlias;
  27. import com.thoughtworks.xstream.annotations.XStreamAsAttribute;

  28. /**
  29.  * the definition of a range
  30.  *
  31.  * @author muellerg
  32.  */
  33. @XStreamAlias("madx-range")
  34. public class MadxRange {

  35.     public static final String ELEMENT_SEPARATOR = "/";

  36.     /*
  37.      * the names of the first and the last element in the range. by default we use the whole sequence, which corresponds
  38.      * to #s/#e.
  39.      */
  40.     @XStreamAlias("first")
  41.     @XStreamAsAttribute
  42.     private String firstElementName = "#s";

  43.     @XStreamAlias("last")
  44.     @XStreamAsAttribute
  45.     private String lastElementName = "#e";

  46.     /**
  47.      * Create a new FullRange of Sequence
  48.      */
  49.     public MadxRange() {
  50.         /* nothing to do --> see init */
  51.     }

  52.     public MadxRange(String elementName) {
  53.         this(elementName, null);
  54.     }

  55.     public MadxRange(String firstElementName, String lastElementName) {
  56.         this.firstElementName = firstElementName;
  57.         this.lastElementName = lastElementName;
  58.     }

  59.     public String getMadxString() {
  60.         if (this.lastElementName == null) {
  61.             return this.firstElementName;
  62.         }

  63.         return this.firstElementName + ELEMENT_SEPARATOR + this.lastElementName;
  64.     }

  65.     public boolean isElement() {
  66.         return this.lastElementName == null;
  67.     }

  68.     public String getFirstElementName() {
  69.         return this.firstElementName;
  70.     }

  71.     public String getLastElementName() {
  72.         return this.lastElementName;
  73.     }

  74.     @Override
  75.     public String toString() {
  76.         return "MadxRange [firstElementName=" + firstElementName + ", lastElementName=" + lastElementName + "]";
  77.     }
  78. }