this.sheet = sheet;
row = record;
setRowNum(record.getRowNumber());
-
+
// Size the initial cell list such that a read only case won't waste
// lots of memory, and a create/read followed by adding new cells can
// add a bit without needing a resize
cells = new HSSFCell[record.getLastCol()+INITIAL_CAPACITY];
-
+
// Don't trust colIx boundaries as read by other apps
// set the RowRecord empty for the moment
record.setEmpty();
* Use this to create new cells within the row and return it.
* <p>
* The cell that is returned will be of the requested type.
- * The type can be changed either through calling setCellValue
+ * The type can be changed either through calling setCellValue
* or setCellType, but there is a small overhead to doing this,
* so it is best to create the required type up front.
*
{
int count = 0;
for (HSSFCell cell : cells) {
- if (cell != null) count++;
+ if (cell != null) {
+ count++;
+ }
}
return count;
}
//The low-order 15 bits contain the row height.
//The 0x8000 bit indicates that the row is standard height (optional)
- if ((height & 0x8000) != 0) height = sheet.getSheet().getDefaultRowHeight();
- else height &= 0x7FFF;
+ if ((height & 0x8000) != 0) {
+ height = sheet.getSheet().getDefaultRowHeight();
+ } else {
+ height &= 0x7FFF;
+ }
return height;
}
int thisId=-1;
int nextId=-1;
- public CellIterator()
- {
- findNext();
+ public CellIterator() {
+ findNext();
}
@Override
- public boolean hasNext() {
- return nextId<cells.length;
+ public boolean hasNext() {
+ return nextId < cells.length;
}
@Override
- public Cell next() {
- if (!hasNext())
+ public Cell next() {
+ if (!hasNext()) {
throw new NoSuchElementException("At last element");
- HSSFCell cell=cells[nextId];
- thisId=nextId;
- findNext();
- return cell;
+ }
+ HSSFCell cell = cells[nextId];
+ thisId = nextId;
+ findNext();
+ return cell;
}
@Override
- public void remove() {
- if (thisId == -1)
+ public void remove() {
+ if (thisId == -1) {
throw new IllegalStateException("remove() called before next()");
- cells[thisId]=null;
+ }
+ cells[thisId] = null;
}
- private void findNext()
- {
- int i=nextId+1;
- for(;i<cells.length;i++)
- {
- if(cells[i]!=null) break;
- }
- nextId=i;
+ private void findNext() {
+ int i = nextId + 1;
+ for (; i < cells.length; i++) {
+ if (cells[i] != null) {
+ break;
+ }
+ }
+ nextId = i;
}
}
-
+
/**
* Compares two <code>HSSFRow</code> objects. Two rows are equal if they belong to the same worksheet and
* their row indexes are equal.
* @throws IllegalArgumentException if the argument row belongs to a different worksheet
*/
@Override
- public int compareTo(HSSFRow other)
- {
+ public int compareTo(HSSFRow other) {
if (this.getSheet() != other.getSheet()) {
throw new IllegalArgumentException("The compared rows must belong to the same sheet");
}
- Integer thisRow = this.getRowNum();
- Integer otherRow = other.getRowNum();
- return thisRow.compareTo(otherRow);
+ int thisRow = this.getRowNum();
+ int otherRow = other.getRowNum();
+ return Integer.compare(thisRow, otherRow);
}
@Override
- public boolean equals(Object obj)
- {
- if (!(obj instanceof HSSFRow))
- {
+ public boolean equals(Object obj) {
+ if (!(obj instanceof HSSFRow)) {
return false;
}
HSSFRow other = (HSSFRow) obj;
public int hashCode() {
return row.hashCode();
}
-
+
/**
* Shifts column range [firstShiftColumnIndex-lastShiftColumnIndex] step places to the right.
* @param firstShiftColumnIndex the column to start shifting
public void shiftCellsRight(int firstShiftColumnIndex, int lastShiftColumnIndex, int step) {
RowShifter.validateShiftParameters(firstShiftColumnIndex, lastShiftColumnIndex, step);
- if(lastShiftColumnIndex + step + 1> cells.length)
+ if (lastShiftColumnIndex + step + 1 > cells.length) {
extend(lastShiftColumnIndex + step + 1);
- for (int columnIndex = lastShiftColumnIndex; columnIndex >= firstShiftColumnIndex; columnIndex--){ // process cells backwards, because of shifting
+ }
+
+ for (int columnIndex = lastShiftColumnIndex; columnIndex >= firstShiftColumnIndex; columnIndex--){ // process cells backwards, because of shifting
HSSFCell cell = getCell(columnIndex);
cells[columnIndex+step] = null;
- if(cell != null)
+ if (cell != null) {
moveCell(cell, (short)(columnIndex+step));
+ }
}
- for (int columnIndex = firstShiftColumnIndex; columnIndex <= firstShiftColumnIndex+step-1; columnIndex++)
+ for (int columnIndex = firstShiftColumnIndex; columnIndex <= firstShiftColumnIndex+step-1; columnIndex++) {
cells[columnIndex] = null;
+ }
}
- private void extend(int newLenght){
+
+ private void extend(int newLength) {
HSSFCell[] temp = cells.clone();
- cells = new HSSFCell[newLenght];
+ cells = new HSSFCell[newLength];
System.arraycopy(temp, 0, cells, 0, temp.length);
}
public void shiftCellsLeft(int firstShiftColumnIndex, int lastShiftColumnIndex, int step) {
RowShifter.validateShiftLeftParameters(firstShiftColumnIndex, lastShiftColumnIndex, step);
- for (int columnIndex = firstShiftColumnIndex; columnIndex <= lastShiftColumnIndex; columnIndex++){
+ for (int columnIndex = firstShiftColumnIndex; columnIndex <= lastShiftColumnIndex; columnIndex++){
HSSFCell cell = getCell(columnIndex);
if(cell != null){
cells[columnIndex-step] = null;
moveCell(cell, (short)(columnIndex-step));
+ } else {
+ cells[columnIndex-step] = null;
}
- else cells[columnIndex-step] = null;
}
- for (int columnIndex = lastShiftColumnIndex-step+1; columnIndex <= lastShiftColumnIndex; columnIndex++)
+ for (int columnIndex = lastShiftColumnIndex-step+1; columnIndex <= lastShiftColumnIndex; columnIndex++) {
cells[columnIndex] = null;
+ }
}
}
package org.apache.poi.ss.formula.functions;
-import org.apache.poi.ss.formula.eval.*;
+import org.apache.poi.ss.formula.eval.AreaEval;
+import org.apache.poi.ss.formula.eval.ErrorEval;
+import org.apache.poi.ss.formula.eval.EvaluationException;
+import org.apache.poi.ss.formula.eval.NumberEval;
+import org.apache.poi.ss.formula.eval.OperandResolver;
+import org.apache.poi.ss.formula.eval.RefEval;
+import org.apache.poi.ss.formula.eval.RefListEval;
+import org.apache.poi.ss.formula.eval.ValueEval;
/**
* Returns the rank of a number in a list of numbers. The rank of a number is its size relative to other values in a list.
* Syntax:
- * RANK(number,ref,order)
- * Number is the number whose rank you want to find.
- * Ref is an array of, or a reference to, a list of numbers. Nonnumeric values in ref are ignored.
- * Order is a number specifying how to rank number.
+ * RANK(number,ref,order)
+ * Number is the number whose rank you want to find.
+ * Ref is an array of, or a reference to, a list of numbers. Nonnumeric values in ref are ignored.
+ * Order is a number specifying how to rank number.
* If order is 0 (zero) or omitted, Microsoft Excel ranks number as if ref were a list sorted in descending order.
* If order is any nonzero value, Microsoft Excel ranks number as if ref were a list sorted in ascending order.
- *
+ *
* @author Rubin Wang
*/
public class Rank extends Var2or3ArgFunction {
+ @Override
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1) {
try {
ValueEval ve = OperandResolver.getSingleValue(arg0, srcRowIndex, srcColumnIndex);
throw new EvaluationException(ErrorEval.NUM_ERROR);
}
- if(arg1 instanceof RefListEval) {
- return eval(result, ((RefListEval)arg1), true);
- }
+ if (arg1 instanceof RefListEval) {
+ return eval(result, ((RefListEval)arg1), true);
+ }
final AreaEval aeRange = convertRangeArg(arg1);
}
}
+ @Override
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1, ValueEval arg2) {
try {
ValueEval ve = OperandResolver.getSingleValue(arg0, srcRowIndex, srcColumnIndex);
throw new EvaluationException(ErrorEval.NUM_ERROR);
}
- ve = OperandResolver.getSingleValue(arg2, srcRowIndex, srcColumnIndex);
- int order_value = OperandResolver.coerceValueToInt(ve);
- final boolean order;
- if(order_value==0) {
- order = true;
- } else if(order_value==1) {
- order = false;
- } else {
- throw new EvaluationException(ErrorEval.NUM_ERROR);
- }
-
- if(arg1 instanceof RefListEval) {
- return eval(result, ((RefListEval)arg1), order);
- }
-
- final AreaEval aeRange = convertRangeArg(arg1);
+ ve = OperandResolver.getSingleValue(arg2, srcRowIndex, srcColumnIndex);
+ int order_value = OperandResolver.coerceValueToInt(ve);
+ final boolean order;
+ if (order_value==0) {
+ order = true;
+ } else if(order_value==1) {
+ order = false;
+ } else {
+ throw new EvaluationException(ErrorEval.NUM_ERROR);
+ }
+
+ if (arg1 instanceof RefListEval) {
+ return eval(result, ((RefListEval)arg1), order);
+ }
+
+ final AreaEval aeRange = convertRangeArg(arg1);
return eval(result, aeRange, order);
} catch (EvaluationException e) {
return e.getErrorEval();
int width= aeRange.getWidth();
for (int r=0; r<height; r++) {
for (int c=0; c<width; c++) {
-
+
Double value = getValue(aeRange, r, c);
- if(value==null)continue;
- if(descending_order && value>arg0 || !descending_order && value<arg0){
+ if (value==null) {
+ continue;
+ }
+ if (descending_order && value>arg0 || !descending_order && value<arg0){
rank++;
}
}
private static ValueEval eval(double arg0, RefListEval aeRange, boolean descending_order) {
int rank = 1;
for(ValueEval ve : aeRange.getList()) {
- if (ve instanceof RefEval) {
- ve = ((RefEval) ve).getInnerValueEval(((RefEval) ve).getFirstSheetIndex());
- }
-
- final Double value;
- if (ve instanceof NumberEval) {
- value = ((NumberEval)ve).getNumberValue();
- } else {
- continue;
- }
-
- if(descending_order && value>arg0 || !descending_order && value<arg0){
- rank++;
- }
- }
+ if (ve instanceof RefEval) {
+ ve = ((RefEval) ve).getInnerValueEval(((RefEval) ve).getFirstSheetIndex());
+ }
+
+ final double value;
+ if (ve instanceof NumberEval) {
+ value = ((NumberEval)ve).getNumberValue();
+ } else {
+ continue;
+ }
+
+ if (descending_order && value>arg0 || !descending_order && value<arg0){
+ rank++;
+ }
+ }
return new NumberEval(rank);
}
* @return boolean result true:string has at least one multibyte character
*/
public static boolean hasMultibyte(String value) {
- if (value == null)
+ if (value == null) {
return false;
+ }
for (char c : value.toCharArray()) {
if (c > 0xFF) {
return true;
}
}
+ @Override
public boolean hasNext() {
return position < strings.length;
}
+ @Override
public String next() {
int ourPos = position++;
if (ourPos >= strings.length) {
return strings[ourPos];
}
+ @Override
public void remove() {
}
}
* @see <a href="http://www.alanwood.net/demos/symbol.html">Symbol font - Unicode alternatives for Greek and special characters in HTML</a>
*/
public static String mapMsCodepointString(String string) {
- if (string == null || string.isEmpty()) return string;
+ if (string == null || string.isEmpty()) {
+ return string;
+ }
initMsCodepointMap();
StringBuilder sb = new StringBuilder();
final int length = string.length();
for (int offset = 0; offset < length; ) {
- Integer msCodepoint = string.codePointAt(offset);
+ int msCodepoint = string.codePointAt(offset);
Integer uniCodepoint = msCodepointToUnicode.get(msCodepoint);
sb.appendCodePoint(uniCodepoint == null ? msCodepoint : uniCodepoint);
offset += Character.charCount(msCodepoint);
}
private static synchronized void initMsCodepointMap() {
- if (msCodepointToUnicode != null) return;
+ if (msCodepointToUnicode != null) {
+ return;
+ }
msCodepointToUnicode = new HashMap<>();
int i = 0xF020;
for (int ch : symbolMap_f020) {
// Could be replaced with org.apache.commons.lang3.StringUtils#join
@Internal
public static String join(Object[] array, String separator) {
- if (array == null || array.length == 0) return "";
+ if (array == null || array.length == 0) {
+ return "";
+ }
StringBuilder sb = new StringBuilder();
sb.append(array[0]);
for (int i = 1; i < array.length; i++) {
@Internal
public static String join(Object[] array) {
- if (array == null) return "";
+ if (array == null) {
+ return "";
+ }
StringBuilder sb = new StringBuilder();
for (Object o : array) {
sb.append(o);
* @return the number of occurrences, 0 if the CharSequence is null
*/
public static int countMatches(CharSequence haystack, char needle) {
- if (haystack == null) return 0;
+ if (haystack == null) {
+ return 0;
+ }
int count = 0;
final int length = haystack.length();
for (int i = 0; i < length; i++) {
private static byte[] fileContents;
public static void main(String[] args) throws IOException {
- if(args.length < 1) {
+ if (args.length < 1) {
System.err.println("Need to give a filename");
System.exit(1);
}
System.out.println();
// Look for latest core records that are slides or notes
- for(int i=0; i<latestRecords.length; i++) {
- if(latestRecords[i] instanceof Slide) {
+ for (int i=0; i<latestRecords.length; i++) {
+ if (latestRecords[i] instanceof Slide) {
Slide s = (Slide)latestRecords[i];
SlideAtom sa = s.getSlideAtom();
System.out.println("Found the latest version of a slide record:");
}
}
System.out.println();
- for(int i=0; i<latestRecords.length; i++) {
- if(latestRecords[i] instanceof Notes) {
+ for (int i=0; i<latestRecords.length; i++) {
+ if (latestRecords[i] instanceof Notes) {
Notes n = (Notes)latestRecords[i];
NotesAtom na = n.getNotesAtom();
System.out.println("Found the latest version of a notes record:");
}
ss.close();
-
+
System.out.println();
}
long type = LittleEndian.getUShort(fileContents, pos+2);
long rlen = LittleEndian.getUInt(fileContents, pos+4);
- return Record.createRecordForType(type,fileContents,pos,(int)rlen+8);
+ return Record.createRecordForType(type,fileContents,pos,(int)rlen+8);
}
}