Skip to content

Commit

Permalink
new method IASTAppendable#appendAll(IExpr[] args, int startPosition, int
Browse files Browse the repository at this point in the history
endPosition)
  • Loading branch information
axkr committed Jun 18, 2018
1 parent e5d142b commit dd388ec
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5454,7 +5454,10 @@ public static IAST Plus(final IExpr a0, final IExpr a1) {
}

public static IAST Plus(final long num, final IExpr... a) {
return ast(a, Plus).prependClone(ZZ(num));
IASTAppendable ast = ast(Plus, a.length + 1, false);
ast.append(ZZ(num));
ast.appendAll(a, 0, a.length);
return ast;
}

public static IAST Pochhammer(final IExpr a0, final IExpr a1) {
Expand Down Expand Up @@ -6490,7 +6493,10 @@ public static IASTMutable Times(final IExpr a0, final IExpr a1) {
}

public static IAST Times(final long num, final IExpr... a) {
return ast(a, Times).prependClone(ZZ(num));
IASTAppendable ast = ast(Times, a.length + 1, false);
ast.append(ZZ(num));
ast.appendAll(a, 0, a.length);
return ast;
}

public static IAST Together(final IExpr a0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,23 @@ public boolean appendAll(List<? extends IExpr> list, int startPosition, int endP
}
return false;
}

/** {@inheritDoc} */
@Override
public boolean appendAll(IExpr[] args, int startPosition, int endPosition) {
if (args.length > 0 && startPosition < endPosition) {
hashValue = 0;
int length = endPosition - startPosition;
if (length > array.length - lastIndex) {
growAtEnd(length);
}
for (int i = startPosition; i < endPosition; i++) {
array[lastIndex++] = args[i];
}
return true;
}
return false;
}

/** {@inheritDoc} */
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public boolean appendAll(List<? extends IExpr> list, int startPosition, int endP
throw new UnsupportedOperationException();
}

@Override
public boolean appendAll(IExpr[] args, int startPosition, int endPosition) {
throw new UnsupportedOperationException();
}

@Override
public boolean appendArgs(IAST ast) {
throw new UnsupportedOperationException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,21 @@ public interface IASTAppendable extends IASTMutable {
*/
public boolean appendAll(List<? extends IExpr> list, int startPosition, int endPosition);

/**
* Appends all elements from offset <code>startPosition</code> to <code>endPosition</code> in the specified list to
* the end of this AST.
*
* @param args
* array containing elements to be added to this AST
* @param startPosition
* the start position, inclusive.
* @param endPosition
* the ending position, exclusive.
* @return <tt>true</tt> if this AST changed as a result of the call
*
*/
public boolean appendAll(IExpr[] args, int startPosition, int endPosition);

/**
* Appends all of the arguments (starting from offset <code>1</code>) in the specified AST to the end of this AST.
*
Expand Down

0 comments on commit dd388ec

Please sign in to comment.