Skip to content

Commit dd388ec

Browse files
committed
new method IASTAppendable#appendAll(IExpr[] args, int startPosition, int
endPosition)
1 parent e5d142b commit dd388ec

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/F.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5454,7 +5454,10 @@ public static IAST Plus(final IExpr a0, final IExpr a1) {
54545454
}
54555455

54565456
public static IAST Plus(final long num, final IExpr... a) {
5457-
return ast(a, Plus).prependClone(ZZ(num));
5457+
IASTAppendable ast = ast(Plus, a.length + 1, false);
5458+
ast.append(ZZ(num));
5459+
ast.appendAll(a, 0, a.length);
5460+
return ast;
54585461
}
54595462

54605463
public static IAST Pochhammer(final IExpr a0, final IExpr a1) {
@@ -6490,7 +6493,10 @@ public static IASTMutable Times(final IExpr a0, final IExpr a1) {
64906493
}
64916494

64926495
public static IAST Times(final long num, final IExpr... a) {
6493-
return ast(a, Times).prependClone(ZZ(num));
6496+
IASTAppendable ast = ast(Times, a.length + 1, false);
6497+
ast.append(ZZ(num));
6498+
ast.appendAll(a, 0, a.length);
6499+
return ast;
64946500
}
64956501

64966502
public static IAST Together(final IExpr a0) {

symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/HMArrayList.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,23 @@ public boolean appendAll(List<? extends IExpr> list, int startPosition, int endP
351351
}
352352
return false;
353353
}
354+
355+
/** {@inheritDoc} */
356+
@Override
357+
public boolean appendAll(IExpr[] args, int startPosition, int endPosition) {
358+
if (args.length > 0 && startPosition < endPosition) {
359+
hashValue = 0;
360+
int length = endPosition - startPosition;
361+
if (length > array.length - lastIndex) {
362+
growAtEnd(length);
363+
}
364+
for (int i = startPosition; i < endPosition; i++) {
365+
array[lastIndex++] = args[i];
366+
}
367+
return true;
368+
}
369+
return false;
370+
}
354371

355372
/** {@inheritDoc} */
356373
@Override

symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/NILPointer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ public boolean appendAll(List<? extends IExpr> list, int startPosition, int endP
7474
throw new UnsupportedOperationException();
7575
}
7676

77+
@Override
78+
public boolean appendAll(IExpr[] args, int startPosition, int endPosition) {
79+
throw new UnsupportedOperationException();
80+
}
81+
7782
@Override
7883
public boolean appendArgs(IAST ast) {
7984
throw new UnsupportedOperationException();

symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/interfaces/IASTAppendable.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,21 @@ public interface IASTAppendable extends IASTMutable {
131131
*/
132132
public boolean appendAll(List<? extends IExpr> list, int startPosition, int endPosition);
133133

134+
/**
135+
* Appends all elements from offset <code>startPosition</code> to <code>endPosition</code> in the specified list to
136+
* the end of this AST.
137+
*
138+
* @param args
139+
* array containing elements to be added to this AST
140+
* @param startPosition
141+
* the start position, inclusive.
142+
* @param endPosition
143+
* the ending position, exclusive.
144+
* @return <tt>true</tt> if this AST changed as a result of the call
145+
*
146+
*/
147+
public boolean appendAll(IExpr[] args, int startPosition, int endPosition);
148+
134149
/**
135150
* Appends all of the arguments (starting from offset <code>1</code>) in the specified AST to the end of this AST.
136151
*

0 commit comments

Comments
 (0)