001/* 002 * $Id: PrimaryComponent.java 4058 2012-07-26 21:03:53Z kredel $ 003 */ 004 005package edu.jas.application; 006 007 008import java.io.Serializable; 009 010import edu.jas.structure.GcdRingElem; 011 012 013/** 014 * Container for primary components of ideals. 015 * @author Heinz Kredel 016 */ 017public 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 } 097 return s + "\nexponent:\n" + exponent; 098 } 099 100 101 /** 102 * Get a scripting compatible string representation. 103 * @return script compatible representation for this Element. 104 * @see edu.jas.structure.Element#toScript() 105 */ 106 public String toScript() { 107 // Python case 108 String s = primary.toScript() + ", " + prime.toString(); 109 if (exponent < 0) { 110 return s; 111 } 112 return s + ", " + exponent; 113 } 114 115}