001/*
002 * $Id$
003 */
004
005package edu.jas.application;
006
007
008import java.io.Serializable;
009
010import edu.jas.structure.GcdRingElem;
011import edu.jas.poly.AlgebraicNumber;
012import edu.jas.poly.AlgebraicNumberRing;
013
014
015/**
016 * Container for primitive elements.
017 * @author Heinz Kredel
018 */
019public class PrimitiveElement<C extends GcdRingElem<C>> implements Serializable {
020
021
022    /**
023     * The primitive element.
024     */
025    public final AlgebraicNumberRing<C> primitiveElem;
026
027
028    /**
029     * The representation of the first algebraic element in the new ring.
030     */
031    public final AlgebraicNumber<C> A;
032
033
034    /**
035     * The representation of the second algebraic element in the new ring.
036     */
037    public final AlgebraicNumber<C> B;
038
039
040    /**
041     * The first original algebraic ring.
042     */
043    public final AlgebraicNumberRing<C> Aring;
044
045
046    /**
047     * The second original algebraic ring.
048     */
049    public final AlgebraicNumberRing<C> Bring;
050
051
052    /**
053     * Constructor not for use.
054     */
055    protected PrimitiveElement() {
056        throw new IllegalArgumentException("do not use this constructor");
057    }
058
059
060    /**
061     * Constructor.
062     * @param pe the primitive element
063     * @param A the first element.
064     * @param B the second element.
065     */
066    protected PrimitiveElement(AlgebraicNumberRing<C> pe, AlgebraicNumber<C> A, AlgebraicNumber<C> B) {
067        this(pe, A, B, null, null);
068    }
069
070
071    /**
072     * Constructor.
073     * @param pe the primitive element
074     * @param A the first element.
075     * @param B the second element.
076     */
077    protected PrimitiveElement(AlgebraicNumberRing<C> pe, AlgebraicNumber<C> A, AlgebraicNumber<C> B,
078                               AlgebraicNumberRing<C> ar, AlgebraicNumberRing<C> br ) {
079        primitiveElem = pe;
080        this.A = A;
081        this.B = B;
082        this.Aring = ar;
083        this.Bring = br;
084    }
085
086
087    /**
088     * String representation of the primitive element.
089     * @see java.lang.Object#toString()
090     */
091    @Override
092    public String toString() {
093        StringBuffer s = new StringBuffer("PrimitiveElement[");
094        s.append(primitiveElem.toString());
095        s.append(", " + A.toString());
096        s.append(", " + B.toString());
097        if (Aring != null) {
098            s.append(", " + Aring.toString());
099        }
100        if (Bring != null) {
101            s.append(", " + Bring.toString());
102        }
103        return s + "]";
104    }
105
106
107    /**
108     * Get a scripting compatible string representation.
109     * @return script compatible representation for this Element.
110     * @see edu.jas.structure.Element#toScript()
111     */
112    public String toScript() {
113        // Python case
114        StringBuffer s = new StringBuffer("PrimitiveElement(");
115        s.append(primitiveElem.toScript());
116        s.append(", " + A.toScript());
117        s.append(", " + B.toScript());
118        if (Aring != null) {
119            s.append(", " + Aring.toScript());
120        }
121        if (Bring != null) {
122            s.append(", " + Bring.toScript());
123        }
124        return s + ")";
125    }
126
127}