Android Open Source - android-google-spreadsheets-api Worksheet Data






From Project

Back to project page android-google-spreadsheets-api.

License

The source code is released under:

Apache License

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;
/*from w w w  .  j  a v  a  2 s . c  om*/
import com.google.common.collect.Lists;

import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;

public class WorksheetData {

  public final CellFeed cellFeed;

  public final List<CellEntry> toInsert = Lists.newArrayList();

  public final SortedMap<Integer, SortedMap<Integer, CellEntry>> rows = new TreeMap<Integer, SortedMap<Integer, CellEntry>>();

  public WorksheetData(final CellFeed cellFeed) {
    this.cellFeed = cellFeed;
    populate(cellFeed.getEntries());
  }

  private void 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;
  }

  public void 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;
  }
}




Java Source Code List

com.example.android.spreadsheet.sample.MainActivity.java
com.github.spreadsheets.android.api.model.Author.java
com.github.spreadsheets.android.api.model.BatchOperation.java
com.github.spreadsheets.android.api.model.BatchStatus.java
com.github.spreadsheets.android.api.model.CellEntry.java
com.github.spreadsheets.android.api.model.CellFeed.java
com.github.spreadsheets.android.api.model.Cell.java
com.github.spreadsheets.android.api.model.Content.java
com.github.spreadsheets.android.api.model.Entry.java
com.github.spreadsheets.android.api.model.Feed.java
com.github.spreadsheets.android.api.model.Link.java
com.github.spreadsheets.android.api.model.ListEntry.java
com.github.spreadsheets.android.api.model.ListFeed.java
com.github.spreadsheets.android.api.model.List.java
com.github.spreadsheets.android.api.model.SpreadsheetEntry.java
com.github.spreadsheets.android.api.model.SpreadsheetFeed.java
com.github.spreadsheets.android.api.model.SpreadsheetUrl.java
com.github.spreadsheets.android.api.model.WorksheetData.java
com.github.spreadsheets.android.api.model.WorksheetEntry.java
com.github.spreadsheets.android.api.model.WorksheetFeed.java
com.github.spreadsheets.android.api.oauth.SpreadsheetOAuthActivity.java
com.github.spreadsheets.android.api.oauth.SpreadsheetOAuth.java
com.github.spreadsheets.android.api.requests.CellEntryRequest.java
com.github.spreadsheets.android.api.requests.CellFeedRequest.java
com.github.spreadsheets.android.api.requests.ListEntryRequest.java
com.github.spreadsheets.android.api.requests.ListFeedRequest.java
com.github.spreadsheets.android.api.requests.SpreadsheetEntryRequest.java
com.github.spreadsheets.android.api.requests.SpreadsheetFeedRequest.java
com.github.spreadsheets.android.api.requests.SpreadsheetRequest.java
com.github.spreadsheets.android.api.requests.WorksheetEntryRequest.java
com.github.spreadsheets.android.api.requests.WorksheetFeedRequest.java