001 /*
002 * $Id: PrimaryComponent.java 3155 2010-05-25 20:10:18Z kredel $
003 */
004
005 package edu.jas.application;
006
007
008 import java.io.Serializable;
009
010 import edu.jas.structure.GcdRingElem;
011
012
013 /**
014 * Container for primary components of ideals.
015 * @author Heinz Kredel
016 */
017 public class PrimaryComponent<C extends GcdRingElem<C>> implements Serializable {
018
019
020 /**
021 * The primary ideal.
022 */
023 public final Ideal<C> primary;
024
025
026 /**
027 * The associated prime ideal.
028 */
029 public final IdealWithUniv<C> prime;
030
031
032 /**
033 * The exponent of prime for primary.
034 */
035 protected int exponent;
036
037
038 /**
039 * Constructor not for use.
040 */
041 protected PrimaryComponent() {
042 throw new IllegalArgumentException("do not use this constructor");
043 }
044
045
046 /**
047 * Constructor.
048 * @param q the primary ideal
049 * @param p the prime ideal.
050 */
051 protected PrimaryComponent(Ideal<C> q, IdealWithUniv<C> p) {
052 this(q, p, -1);
053 }
054
055
056 /**
057 * Constructor.
058 * @param q the primary ideal
059 * @param p the prime ideal.
060 * @param e the exponent of p for q.
061 */
062 protected PrimaryComponent(Ideal<C> q, IdealWithUniv<C> p, int e) {
063 primary = q;
064 prime = p;
065 exponent = e;
066 }
067
068
069 /**
070 * Get exponent.
071 * @return exponent.
072 */
073 public int getExponent() {
074 return exponent;
075 }
076
077
078 /**
079 * Set exponent.
080 * @param e the exponent.
081 */
082 public void setExponent(int e) {
083 exponent = e;
084 }
085
086
087 /**
088 * String representation of the ideal.
089 * @see java.lang.Object#toString()
090 */
091 @Override
092 public String toString() {
093 String s = "\nprimary:\n" + primary.toString() + "\nprime:\n" + prime.toString();
094 if (exponent < 0) {
095 return s;
096 } else {
097 return s + "\nexponent:\n" + exponent;
098 }
099 }
100
101
102 /**
103 * Get a scripting compatible string representation.
104 * @return script compatible representation for this Element.
105 * @see edu.jas.structure.Element#toScript()
106 */
107 public String toScript() {
108 // Python case
109 String s = primary.toScript() + ", " + prime.toString();
110 if (exponent < 0) {
111 return s;
112 } else {
113 return s + ", " + exponent;
114 }
115 }
116
117 }