isac-java/src/java/isac/util/Variant.java
author Walther Neuper <walther.neuper@jku.at>
Fri, 26 Mar 2021 10:45:05 +0100
changeset 5239 b4e3883d7b66
parent 5229 6bf0e95981e3
permissions -rw-r--r--
reset mathematics-engine to Isabelle2015

note: for this version libisabelle was available,
which connects front-end (Java) and back-end (Isabelle/ML)
     1 /****************************************************************** 
     2  * Copyright (c) 2003, Mario Hochreiter, Student of 
     3  * Software Engineering at FH-Hagenberg, Austria. 
     4  * Project member of the isac team at the Institute for 
     5  * Software-Technologie, Graz University of Technology, Austria. 
     6  * 
     7  * Use is subject to license terms.
     8  ******************************************************************/
     9 
    10 package isac.util;
    11 
    12 import isac.util.formulae.Specification;
    13 import isac.bridge.xml.DataTypes; //.scala
    14 
    15 import edu.tum.cs.isabelle.api.XML; // from libisabelle-full.jar
    16 
    17 import java.io.Serializable;
    18 import java.util.ArrayList;
    19 
    20 /**
    21  * Describes a way how a specific calculation will be calculated (which method
    22  * will be used to solve this calculation).
    23  * 
    24  * @author Mario Hochreiter
    25  * @version 0.1
    26  *  
    27  */
    28 public class Variant implements Serializable {
    29 
    30     static final long serialVersionUID = 4983770207782569120L;
    31 
    32 	/** strings betweend the isa tags */
    33     protected ArrayList<String> isa_strings_;
    34 
    35     protected Specification spec_;
    36 
    37     public Variant() {
    38         isa_strings_ = new ArrayList<String>();
    39     }
    40 
    41     /**
    42      * Add a new isa string
    43      * 
    44      * @param isa
    45      *            The isa string
    46      */
    47     public void addNewIsaString(String isa) {
    48         isa_strings_.add(isa);
    49     }
    50 
    51     public String toString() {
    52         String content = "<TERMLIST>";
    53         for (int index = 0; index < isa_strings_.size(); index++)
    54             content += "<MATHML>\n<ISA>\n" + isa_strings_.get(index)
    55                     + "\n</ISA>\n</MATHML>\n";
    56 
    57         if (spec_ != null) {
    58             content += spec_;
    59         }
    60         content += "</TERMLIST>\n";
    61         return content;
    62     }
    63 
    64     /**
    65      * Format the object in a way that the bridge can handle it
    66      * 
    67      * @return SML representation of this Variant
    68      */
    69     public String toSMLString() {
    70         StringBuffer sb = new StringBuffer();
    71 
    72         int size = isa_strings_.size();
    73         sb.append("[");
    74         for (int i = 0; i < size; i++) {
    75             sb.append("\"" + (String) isa_strings_.get(i) + "\"");
    76             if (i < size - 1) sb.append(", ");
    77         }
    78         sb.append("],");
    79         sb.append("(" + spec_.toSMLString() + ")");
    80         return sb.toString();
    81     }
    82     /**
    83      * Format the object in a way that libisabelle/PIDE can handle it
    84      * @return XML representation of this Variant
    85      */
    86     // conversion is done in Scala, because it is much simpler there
    87     public XML.Tree toXML() {
    88     	return DataTypes.xml_of_Variant(this);
    89     }
    90 
    91     public void setSpecification(Specification spec) {
    92         this.spec_ = spec;
    93     }
    94 
    95     public Specification getSpecification() {
    96         return spec_;
    97     }
    98     public ArrayList<String> getIsaStrings() {
    99         return isa_strings_;
   100     }
   101 
   102 }