mirror of
https://github.com/apache/poi.git
synced 2026-02-27 20:40:08 +08:00
remove some tab indents
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1859758 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3e80ec9c5e
commit
3d5671ac5e
@ -45,116 +45,116 @@ import org.apache.poi.ss.formula.eval.ValueEval;
|
||||
*/
|
||||
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);
|
||||
double result = OperandResolver.coerceValueToDouble(ve);
|
||||
if (Double.isNaN(result) || Double.isInfinite(result)) {
|
||||
throw new EvaluationException(ErrorEval.NUM_ERROR);
|
||||
}
|
||||
@Override
|
||||
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1) {
|
||||
try {
|
||||
ValueEval ve = OperandResolver.getSingleValue(arg0, srcRowIndex, srcColumnIndex);
|
||||
double result = OperandResolver.coerceValueToDouble(ve);
|
||||
if (Double.isNaN(result) || Double.isInfinite(result)) {
|
||||
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);
|
||||
final AreaEval aeRange = convertRangeArg(arg1);
|
||||
|
||||
return eval(result, aeRange, true);
|
||||
} catch (EvaluationException e) {
|
||||
return e.getErrorEval();
|
||||
}
|
||||
}
|
||||
return eval(result, aeRange, true);
|
||||
} catch (EvaluationException e) {
|
||||
return e.getErrorEval();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1, ValueEval arg2) {
|
||||
try {
|
||||
ValueEval ve = OperandResolver.getSingleValue(arg0, srcRowIndex, srcColumnIndex);
|
||||
final double result = OperandResolver.coerceValueToDouble(ve);
|
||||
if (Double.isNaN(result) || Double.isInfinite(result)) {
|
||||
throw new EvaluationException(ErrorEval.NUM_ERROR);
|
||||
}
|
||||
@Override
|
||||
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1, ValueEval arg2) {
|
||||
try {
|
||||
ValueEval ve = OperandResolver.getSingleValue(arg0, srcRowIndex, srcColumnIndex);
|
||||
final double result = OperandResolver.coerceValueToDouble(ve);
|
||||
if (Double.isNaN(result) || Double.isInfinite(result)) {
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
final AreaEval aeRange = convertRangeArg(arg1);
|
||||
return eval(result, aeRange, order);
|
||||
} catch (EvaluationException e) {
|
||||
return e.getErrorEval();
|
||||
}
|
||||
}
|
||||
|
||||
private static ValueEval eval(double arg0, AreaEval aeRange, boolean descending_order) {
|
||||
int rank = 1;
|
||||
int height=aeRange.getHeight();
|
||||
int width= aeRange.getWidth();
|
||||
for (int r=0; r<height; r++) {
|
||||
for (int c=0; c<width; c++) {
|
||||
private static ValueEval eval(double arg0, AreaEval aeRange, boolean descending_order) {
|
||||
int rank = 1;
|
||||
int height=aeRange.getHeight();
|
||||
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){
|
||||
rank++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return new NumberEval(rank);
|
||||
}
|
||||
Double value = getValue(aeRange, r, c);
|
||||
if (value==null) {
|
||||
continue;
|
||||
}
|
||||
if (descending_order && value>arg0 || !descending_order && value<arg0){
|
||||
rank++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return new NumberEval(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());
|
||||
}
|
||||
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;
|
||||
}
|
||||
final double value;
|
||||
if (ve instanceof NumberEval) {
|
||||
value = ((NumberEval)ve).getNumberValue();
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (descending_order && value>arg0 || !descending_order && value<arg0){
|
||||
rank++;
|
||||
}
|
||||
}
|
||||
if (descending_order && value>arg0 || !descending_order && value<arg0){
|
||||
rank++;
|
||||
}
|
||||
}
|
||||
|
||||
return new NumberEval(rank);
|
||||
}
|
||||
return new NumberEval(rank);
|
||||
}
|
||||
|
||||
private static Double getValue(AreaEval aeRange, int relRowIndex, int relColIndex) {
|
||||
ValueEval addend = aeRange.getRelativeValue(relRowIndex, relColIndex);
|
||||
if (addend instanceof NumberEval) {
|
||||
return ((NumberEval)addend).getNumberValue();
|
||||
}
|
||||
// everything else (including string and boolean values) counts as zero
|
||||
return null;
|
||||
}
|
||||
private static Double getValue(AreaEval aeRange, int relRowIndex, int relColIndex) {
|
||||
ValueEval addend = aeRange.getRelativeValue(relRowIndex, relColIndex);
|
||||
if (addend instanceof NumberEval) {
|
||||
return ((NumberEval)addend).getNumberValue();
|
||||
}
|
||||
// everything else (including string and boolean values) counts as zero
|
||||
return null;
|
||||
}
|
||||
|
||||
private static AreaEval convertRangeArg(ValueEval eval) throws EvaluationException {
|
||||
if (eval instanceof AreaEval) {
|
||||
return (AreaEval) eval;
|
||||
}
|
||||
if (eval instanceof RefEval) {
|
||||
return ((RefEval)eval).offset(0, 0, 0, 0);
|
||||
}
|
||||
throw new EvaluationException(ErrorEval.VALUE_INVALID);
|
||||
}
|
||||
private static AreaEval convertRangeArg(ValueEval eval) throws EvaluationException {
|
||||
if (eval instanceof AreaEval) {
|
||||
return (AreaEval) eval;
|
||||
}
|
||||
if (eval instanceof RefEval) {
|
||||
return ((RefEval)eval).offset(0, 0, 0, 0);
|
||||
}
|
||||
throw new EvaluationException(ErrorEval.VALUE_INVALID);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -41,128 +41,128 @@ import org.apache.poi.util.LittleEndian;
|
||||
* all mean
|
||||
*/
|
||||
public final class SlideIdListing {
|
||||
private static byte[] fileContents;
|
||||
private static byte[] fileContents;
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
if (args.length < 1) {
|
||||
System.err.println("Need to give a filename");
|
||||
System.exit(1);
|
||||
}
|
||||
public static void main(String[] args) throws IOException {
|
||||
if (args.length < 1) {
|
||||
System.err.println("Need to give a filename");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
|
||||
// Create the slideshow object, for normal working with
|
||||
HSLFSlideShowImpl hss = new HSLFSlideShowImpl(args[0]);
|
||||
HSLFSlideShow ss = new HSLFSlideShow(hss);
|
||||
// Create the slideshow object, for normal working with
|
||||
HSLFSlideShowImpl hss = new HSLFSlideShowImpl(args[0]);
|
||||
HSLFSlideShow ss = new HSLFSlideShow(hss);
|
||||
|
||||
// Grab the base contents
|
||||
fileContents = hss.getUnderlyingBytes();
|
||||
Record[] records = hss.getRecords();
|
||||
Record[] latestRecords = ss.getMostRecentCoreRecords();
|
||||
// Grab the base contents
|
||||
fileContents = hss.getUnderlyingBytes();
|
||||
Record[] records = hss.getRecords();
|
||||
Record[] latestRecords = ss.getMostRecentCoreRecords();
|
||||
|
||||
// Grab any records that interest us
|
||||
Document document = null;
|
||||
for (Record latestRecord : latestRecords) {
|
||||
if (latestRecord instanceof Document) {
|
||||
document = (Document) latestRecord;
|
||||
}
|
||||
}
|
||||
// Grab any records that interest us
|
||||
Document document = null;
|
||||
for (Record latestRecord : latestRecords) {
|
||||
if (latestRecord instanceof Document) {
|
||||
document = (Document) latestRecord;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
System.out.println();
|
||||
|
||||
|
||||
// Look for SlidePersistAtoms, and report what they have to
|
||||
// say about possible slide IDs
|
||||
SlideListWithText[] slwts = document.getSlideListWithTexts();
|
||||
for (SlideListWithText slwt : slwts) {
|
||||
Record[] cr = slwt.getChildRecords();
|
||||
for (Record record : cr) {
|
||||
if (record instanceof SlidePersistAtom) {
|
||||
SlidePersistAtom spa = (SlidePersistAtom) record;
|
||||
System.out.println("SlidePersistAtom knows about slide:");
|
||||
System.out.println("\t" + spa.getRefID());
|
||||
System.out.println("\t" + spa.getSlideIdentifier());
|
||||
}
|
||||
}
|
||||
}
|
||||
// Look for SlidePersistAtoms, and report what they have to
|
||||
// say about possible slide IDs
|
||||
SlideListWithText[] slwts = document.getSlideListWithTexts();
|
||||
for (SlideListWithText slwt : slwts) {
|
||||
Record[] cr = slwt.getChildRecords();
|
||||
for (Record record : cr) {
|
||||
if (record instanceof SlidePersistAtom) {
|
||||
SlidePersistAtom spa = (SlidePersistAtom) record;
|
||||
System.out.println("SlidePersistAtom knows about slide:");
|
||||
System.out.println("\t" + spa.getRefID());
|
||||
System.out.println("\t" + spa.getSlideIdentifier());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
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) {
|
||||
Slide s = (Slide)latestRecords[i];
|
||||
SlideAtom sa = s.getSlideAtom();
|
||||
System.out.println("Found the latest version of a slide record:");
|
||||
System.out.println("\tCore ID is " + s.getSheetId());
|
||||
System.out.println("\t(Core Records count is " + i + ")");
|
||||
System.out.println("\tDisk Position is " + s.getLastOnDiskOffset());
|
||||
System.out.println("\tMaster ID is " + sa.getMasterID());
|
||||
System.out.println("\tNotes ID is " + sa.getNotesID());
|
||||
}
|
||||
}
|
||||
System.out.println();
|
||||
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:");
|
||||
System.out.println("\tCore ID is " + n.getSheetId());
|
||||
System.out.println("\t(Core Records count is " + i + ")");
|
||||
System.out.println("\tDisk Position is " + n.getLastOnDiskOffset());
|
||||
System.out.println("\tMatching slide is " + na.getSlideID());
|
||||
}
|
||||
}
|
||||
// Look for latest core records that are slides or notes
|
||||
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("\tCore ID is " + s.getSheetId());
|
||||
System.out.println("\t(Core Records count is " + i + ")");
|
||||
System.out.println("\tDisk Position is " + s.getLastOnDiskOffset());
|
||||
System.out.println("\tMaster ID is " + sa.getMasterID());
|
||||
System.out.println("\tNotes ID is " + sa.getNotesID());
|
||||
}
|
||||
}
|
||||
System.out.println();
|
||||
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:");
|
||||
System.out.println("\tCore ID is " + n.getSheetId());
|
||||
System.out.println("\t(Core Records count is " + i + ")");
|
||||
System.out.println("\tDisk Position is " + n.getLastOnDiskOffset());
|
||||
System.out.println("\tMatching slide is " + na.getSlideID());
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
System.out.println();
|
||||
|
||||
// Find any persist ones first
|
||||
int pos = 0;
|
||||
for (Record r : records) {
|
||||
if (r.getRecordType() == 6001L) {
|
||||
// PersistPtrFullBlock
|
||||
System.out.println("Found PersistPtrFullBlock at " + pos + " (" + Integer.toHexString(pos) + ")");
|
||||
}
|
||||
if (r.getRecordType() == 6002L) {
|
||||
// PersistPtrIncrementalBlock
|
||||
System.out.println("Found PersistPtrIncrementalBlock at " + pos + " (" + Integer.toHexString(pos) + ")");
|
||||
PersistPtrHolder pph = (PersistPtrHolder) r;
|
||||
// Find any persist ones first
|
||||
int pos = 0;
|
||||
for (Record r : records) {
|
||||
if (r.getRecordType() == 6001L) {
|
||||
// PersistPtrFullBlock
|
||||
System.out.println("Found PersistPtrFullBlock at " + pos + " (" + Integer.toHexString(pos) + ")");
|
||||
}
|
||||
if (r.getRecordType() == 6002L) {
|
||||
// PersistPtrIncrementalBlock
|
||||
System.out.println("Found PersistPtrIncrementalBlock at " + pos + " (" + Integer.toHexString(pos) + ")");
|
||||
PersistPtrHolder pph = (PersistPtrHolder) r;
|
||||
|
||||
// Check the sheet offsets
|
||||
int[] sheetIDs = pph.getKnownSlideIDs();
|
||||
Map<Integer, Integer> sheetOffsets = pph.getSlideLocationsLookup();
|
||||
for (Integer id : sheetIDs) {
|
||||
Integer offset = sheetOffsets.get(id);
|
||||
// Check the sheet offsets
|
||||
int[] sheetIDs = pph.getKnownSlideIDs();
|
||||
Map<Integer, Integer> sheetOffsets = pph.getSlideLocationsLookup();
|
||||
for (Integer id : sheetIDs) {
|
||||
Integer offset = sheetOffsets.get(id);
|
||||
|
||||
System.out.println(" Knows about sheet " + id);
|
||||
System.out.println(" That sheet lives at " + offset);
|
||||
System.out.println(" Knows about sheet " + id);
|
||||
System.out.println(" That sheet lives at " + offset);
|
||||
|
||||
Record atPos = findRecordAtPos(offset.intValue());
|
||||
System.out.println(" The record at that pos is of type " + atPos.getRecordType());
|
||||
System.out.println(" The record at that pos has class " + atPos.getClass().getName());
|
||||
Record atPos = findRecordAtPos(offset.intValue());
|
||||
System.out.println(" The record at that pos is of type " + atPos.getRecordType());
|
||||
System.out.println(" The record at that pos has class " + atPos.getClass().getName());
|
||||
|
||||
if (!(atPos instanceof PositionDependentRecord)) {
|
||||
System.out.println(" ** The record class isn't position aware! **");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!(atPos instanceof PositionDependentRecord)) {
|
||||
System.out.println(" ** The record class isn't position aware! **");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Increase the position by the on disk size
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
r.writeOut(baos);
|
||||
pos += baos.size();
|
||||
}
|
||||
// Increase the position by the on disk size
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
r.writeOut(baos);
|
||||
pos += baos.size();
|
||||
}
|
||||
|
||||
ss.close();
|
||||
ss.close();
|
||||
|
||||
System.out.println();
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
|
||||
// Finds the record at a given position
|
||||
public static Record findRecordAtPos(int pos) {
|
||||
long type = LittleEndian.getUShort(fileContents, pos+2);
|
||||
long rlen = LittleEndian.getUInt(fileContents, pos+4);
|
||||
// Finds the record at a given position
|
||||
public static Record findRecordAtPos(int pos) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user