001/*
002 * $Id$
003 */
004
005package edu.jas.structure;
006
007
008import java.io.Reader;
009import java.io.Serializable;
010import java.math.BigInteger;
011import java.util.List;
012import java.util.Random;
013
014
015/**
016 * Element factory interface. Defines embedding of integers, parsing and random
017 * element construction.
018 * @author Heinz Kredel
019 */
020
021public interface ElemFactory<C extends Element<C>> extends Serializable {
022
023
024    /**
025     * Get a list of the generating elements.
026     * @return list of generators for the algebraic structure.
027     */
028    public List<C> generators();
029
030
031    /**
032     * Is this structure finite or infinite.
033     * @return true if this structure is finite, else false.
034     */
035    public boolean isFinite();
036
037
038    /**
039     * Get the Element for a.
040     * @param a long
041     * @return element corresponding to a.
042     */
043    public C fromInteger(long a);
044
045
046    /**
047     * Get the Element for a.
048     * @param a java.math.BigInteger.
049     * @return element corresponding to a.
050     */
051    public C fromInteger(BigInteger a);
052
053
054    /**
055     * Generate a random Element with size less equal to n.
056     * @param n
057     * @return a random element.
058     */
059    public C random(int n);
060
061
062    /**
063     * Generate a random Element with size less equal to n.
064     * @param n
065     * @param random is a source for random bits.
066     * @return a random element.
067     */
068    public C random(int n, Random random);
069
070
071    /**
072     * Create a copy of Element c.
073     * @param c
074     * @return a copy of c.
075     */
076    public C copy(C c);
077
078
079    /**
080     * Value from String.
081     * @param s String.
082     * @return a Element corresponding to s.
083     */
084    default public C valueOf(String s) {
085        return parse(s);
086    }
087
088
089    /**
090     * Parse from String.
091     * @param s String.
092     * @return a Element corresponding to s.
093     */
094    public C parse(String s);
095
096
097    /**
098     * Parse from Reader.
099     * @param r Reader.
100     * @return the next Element found on r.
101     */
102    public C parse(Reader r);
103
104
105    /**
106     * Get a scripting compatible string representation.
107     * @return script compatible representation for this ElemFactory.
108     */
109    public String toScript();
110
111}