JSci.mathml.MathMLMatrixrowElementImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jsci Show documentation
Show all versions of jsci Show documentation
JSci is a set of open source Java packages. The aim is to encapsulate scientific methods/principles in the most natural way possible. As such they should greatly aid the development of scientific based software.
It offers: abstract math interfaces, linear algebra (support for various matrix and vector types), statistics (including probability distributions), wavelets, newtonian mechanics, chart/graph components (AWT and Swing), MathML DOM implementation, ...
Note: some packages, like javax.comm, for the astro and instruments package aren't listed as dependencies (not available).
The newest version!
package JSci.mathml;
import org.w3c.dom.*;
import org.w3c.dom.mathml.*;
import org.apache.xerces.dom.*;
/**
* Implements a MathML matrixrow
element.
* @version 1.0
* @author Mark Hale
*/
public class MathMLMatrixrowElementImpl extends MathMLElementImpl implements MathMLMatrixrowElement {
/**
* Constructs a MathML matrixrow
element.
*/
public MathMLMatrixrowElementImpl(MathMLDocumentImpl owner, String qualifiedName) {
super(owner, qualifiedName);
}
public int getNEntries() {
return getEntriesGetLength();
}
public MathMLContentElement getEntry(int index) throws DOMException {
Node entry = getEntriesItem(index-1);
if (entry == null) {
throw new DOMException(DOMException.INDEX_SIZE_ERR, "Index out of bounds");
}
return (MathMLContentElement) entry;
}
public MathMLContentElement setEntry(MathMLContentElement newEntry, int index) throws DOMException {
final int entriesLength = getEntriesGetLength();
if ((index < 1) || (index > entriesLength+1)) {
throw new DOMException(DOMException.INDEX_SIZE_ERR, "Index out of bounds");
}
if (index == entriesLength+1) {
return (MathMLContentElement) appendChild(newEntry);
} else {
return (MathMLContentElement) replaceChild(newEntry, getEntriesItem(index-1));
}
}
public MathMLContentElement insertEntry(MathMLContentElement newEntry, int index) throws DOMException {
final int entriesLength = getEntriesGetLength();
if ((index < 0) || (index > entriesLength+1)) {
throw new DOMException(DOMException.INDEX_SIZE_ERR, "Index out of bounds");
}
if ((index == 0) || (index == entriesLength+1)) {
return (MathMLContentElement) appendChild(newEntry);
} else {
return (MathMLContentElement) insertBefore(newEntry, getEntriesItem(index-1));
}
}
public MathMLContentElement removeEntry(int index) throws DOMException {
Node entry = getEntriesItem(index-1);
if (entry == null) {
throw new DOMException(DOMException.INDEX_SIZE_ERR, "Index out of bounds");
}
return (MathMLContentElement) removeChild(entry);
}
public void deleteEntry(int index) throws DOMException {
removeEntry(index);
}
private int getEntriesGetLength() {
final int length = getLength();
int numEntries = 0;
for (int i = 0; i < length; i++) {
if (item(i) instanceof MathMLContentElement) {
numEntries++;
}
}
return numEntries;
}
private Node getEntriesItem(int index) {
final int entriesLength = getEntriesGetLength();
if ((index < 0) || (index >= entriesLength))
return null;
Node node = null;
int n = -1;
for (int i = 0; n < index; i++) {
node = item(i);
if (node instanceof MathMLContentElement) {
n++;
}
}
return node;
}
}