If you think the Android project android-google-spreadsheets-api listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.github.spreadsheets.android.api.model;
/*fromwww.java2s.com*/import com.google.common.collect.Lists;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
publicclass WorksheetData {
publicfinal CellFeed cellFeed;
publicfinal List<CellEntry> toInsert = Lists.newArrayList();
publicfinal SortedMap<Integer, SortedMap<Integer, CellEntry>> rows = new TreeMap<Integer, SortedMap<Integer, CellEntry>>();
public WorksheetData(final CellFeed cellFeed) {
this.cellFeed = cellFeed;
populate(cellFeed.getEntries());
}
privatevoid populate(List<CellEntry> cells) {
for (CellEntry ce : cells) {
Cell c = ce.cell;
int row = c.row;
SortedMap<Integer, CellEntry> rowValues = getRow(row);
rowValues.put(c.col, ce);
}
}
private CellEntry getCellEntry(int row, int col) {
Map<Integer, CellEntry> rowValues = rows.get(row);
if (rowValues == null) {
return null;
}
return rowValues.get(col);
}
public String getContent(int row, int col) {
CellEntry ce = getCellEntry(row, col);
if (ce != null) {
return ce.content;
}
return null;
}
publicvoid setValue(String value, int row, int col) {
CellEntry ce = getCellEntry(row, col);
if (ce != null) {
ce.content = value;
ce.batchUpdate(value);
} else {
ce = CellEntry.makeInstance(value, row, col);
ce.content = value;
SortedMap<Integer, CellEntry> rowValues = getRow(row);
rowValues.put(col, ce);
toInsert.add(ce);
}
}
private SortedMap<Integer, CellEntry> getRow(int row) {
SortedMap<Integer, CellEntry> rowValues = rows.get(row);
if (rowValues == null) {
rowValues = new TreeMap<Integer, CellEntry>();
rows.put(row, rowValues);
}
return rowValues;
}
}