Skip to content

Commit

Permalink
Refactor AST, AST0, AST1, AST2, AST3 access
Browse files Browse the repository at this point in the history
- restrict acces to package org.matheclipse.core.expression
  • Loading branch information
axkr committed Oct 17, 2019
1 parent 899cf9b commit 35c533a
Show file tree
Hide file tree
Showing 13 changed files with 499 additions and 436 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static IExpr convert(Object obj) throws ConversionException {
return F.complexNum(cmp.getReal(), cmp.getImaginary());
}
if (obj instanceof int[]) {
return AST.newInstance(F.List, (int[]) obj);
return F.ast(F.List, (int[]) obj);
}
if (obj instanceof double[]) {
return new ASTRealVector((double[]) obj, true);
Expand All @@ -97,7 +97,7 @@ public static IExpr convert(Object obj) throws ConversionException {
// return list;
}
if (obj instanceof org.hipparchus.complex.Complex[]) {
return AST.newInstance(F.List, false, (org.hipparchus.complex.Complex[]) obj);
return F.ast(F.List, (org.hipparchus.complex.Complex[]) obj);
}
if (obj instanceof Object[]) {
final Object[] array = (Object[]) obj;
Expand Down Expand Up @@ -162,6 +162,6 @@ public static IExpr convertList(java.util.Collection<?> lst) {

public static IAST convertComplex(boolean evalComplex, org.hipparchus.complex.Complex[] array)
throws ConversionException {
return AST.newInstance(F.List, evalComplex, array);
return F.ast(F.List, evalComplex, array);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public static IAST getPeriodicParts(final IExpr expr, final IExpr period) {
// IExpr[] result = new IExpr[2];
// result[0] = F.C0;
// result[1] = F.C1;
AST2 result = new AST2(F.List, F.C0, F.C1);
IASTMutable result = F.binaryAST2(F.List, F.C0, F.C1);
if (expr.equals(period)) {
return result;
}
Expand Down Expand Up @@ -245,7 +245,7 @@ public static IAST peelOff(final IAST plusAST, EvalEngine engine) {
}
}
if (k != null) {
AST2 result = new AST2(F.List, plusAST, F.C0);
IASTMutable result = F.binaryAST2(F.List, plusAST, F.C0);
IExpr m1 = F.Times(k.mod(F.C1D2), F.Pi);
IExpr m2 = F.Subtract.of(engine, F.Times(k, F.Pi), m1);
result.set(1, F.Subtract.of(plusAST, m2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public AST() {
super(0);
}

public AST(IExpr head, IExpr... es) {
/*package private */ AST(IExpr head, IExpr... es) {
super(head, es);
}

Expand All @@ -332,7 +332,7 @@ public AST(IExpr head, IExpr... es) {
*
* @param es
*/
AST(IExpr[] es) {
/*package private */ AST(IExpr[] es) {
super(es);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public AST0() {
* @param head
* the head of the function
*/
protected AST0(IExpr head) {
/*package private */ AST0(IExpr head) {
super();
this.arg0 = head;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public AST1() {
* @param arg1
* the first argument of the function
*/
public AST1(IExpr head, IExpr arg1) {
/*package private */ AST1(IExpr head, IExpr arg1) {
super(head);
this.arg1 = arg1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public AST2() {
* @param arg2
* the second argument of the function
*/
public AST2(IExpr head, IExpr arg1, IExpr arg2) {
/*package private */ AST2(IExpr head, IExpr arg1, IExpr arg2) {
super(head, arg1);
this.arg2 = arg2;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public AST3() {
* @param arg3
* the thirs argument of the function
*/
public AST3(IExpr head, IExpr arg1, IExpr arg2, IExpr arg3) {
/* package private */ AST3(IExpr head, IExpr arg1, IExpr arg2, IExpr arg3) {
super(head, arg1, arg2);
this.arg3 = arg3;
}
Expand Down Expand Up @@ -108,11 +108,11 @@ public Set<IExpr> asSet() {
*/
@Override
public IAST clone() {
AST3 result=(AST3)super.clone();
result.arg0=arg0;
result.arg1=arg1;
result.arg2=arg2;
result.arg3=arg3;
AST3 result = (AST3) super.clone();
result.arg0 = arg0;
result.arg1 = arg1;
result.arg2 = arg2;
result.arg3 = arg3;
return result;
}

Expand Down Expand Up @@ -389,11 +389,10 @@ public void forEach(int start, int end, ObjIntConsumer<? super IExpr> action) {
}
}
}



/** {@inheritDoc} */
@Override
public int indexOf(Predicate<? super IExpr> predicate) {
public int indexOf(Predicate<? super IExpr> predicate) {
if (predicate.test(arg1)) {
return 1;
}
Expand All @@ -408,11 +407,11 @@ public int indexOf(Predicate<? super IExpr> predicate) {

/** {@inheritDoc} */
@Override
public IExpr findFirst(Function<IExpr, IExpr> function) {
public IExpr findFirst(Function<IExpr, IExpr> function) {
IExpr temp = function.apply(arg1);
if (temp.isPresent()) {
return temp;
}
}
temp = function.apply(arg2);
if (temp.isPresent()) {
return temp;
Expand Down Expand Up @@ -561,7 +560,7 @@ public int size() {
*/
@Override
public IExpr[] toArray() {
return new IExpr[] { arg0, arg1, arg2, arg3 };
return new IExpr[] { arg0, arg1, arg2, arg3 };
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import org.matheclipse.core.builtin.WXFFunctions;
import org.matheclipse.core.builtin.WindowFunctions;
import org.matheclipse.core.convert.AST2Expr;
import org.matheclipse.core.convert.ConversionException;
import org.matheclipse.core.convert.Object2Expr;
import org.matheclipse.core.eval.EvalAttributes;
import org.matheclipse.core.eval.EvalEngine;
Expand Down Expand Up @@ -5288,6 +5289,18 @@ public static IASTAppendable ast(final IExpr[] arr, final IExpr head) {
return new AST(head, arr);
}

public static IASTAppendable ast(final ISymbol head, final int[] arr) {
return AST.newInstance(head, arr);
}

public static IASTAppendable ast(final ISymbol head, final org.hipparchus.complex.Complex[] arr) {
return AST.newInstance(head, false, arr);
}

public static IASTAppendable ast(final ISymbol head, boolean evalComplex, org.hipparchus.complex.Complex[] arr) {
return AST.newInstance(head, evalComplex, arr);
}

/**
* <pre>
* AtomQ(x)
Expand Down Expand Up @@ -9609,7 +9622,7 @@ public static IAST Times(final long num, final IExpr... a) {
public static IAST ToExpression(final IExpr a0) {
return new AST1(ToExpression, a0);
}

public static IAST Together(final IExpr a0) {
return new AST1(Together, a0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public abstract class HMArrayList extends AbstractAST implements IASTAppendable,
/**
* Constructs a new instance of list with capacity <code>10</code>.
*/
public HMArrayList() {
/*package protected */ HMArrayList() {
this(10);
}

Expand All @@ -72,7 +72,7 @@ public HMArrayList() {
* @param collection
* the collection of elements to add.
*/
public HMArrayList(Collection<? extends IExpr> collection) {
/*package protected */ HMArrayList(Collection<? extends IExpr> collection) {
firstIndex = hashValue = 0;
Object[] objects = collection.toArray();
int size = objects.length;
Expand All @@ -91,7 +91,7 @@ public HMArrayList(Collection<? extends IExpr> collection) {
* @param arguments
* the argument expressions
*/
public HMArrayList(IExpr headExpr, IExpr... arguments) {
/*package protected */ HMArrayList(IExpr headExpr, IExpr... arguments) {
firstIndex = hashValue = 0;
lastIndex = arguments.length + 1;
switch (lastIndex) {
Expand Down
Loading

0 comments on commit 35c533a

Please sign in to comment.