Android Open Source - SimpleStorage String Array Handler






From Project

Back to project page SimpleStorage.

License

The source code is released under:

Apache License

If you think the Android project SimpleStorage 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.njzk2.simplestorage.handler;
//from  w w  w.  jav  a2s  . com
import java.util.Arrays;

import org.json.JSONArray;

import android.database.Cursor;

// TODO consider using a generic ArrayHandler that can delegate to simple handlers
public class StringArrayHandler extends TypeHandler<String[]> {

  @Override
  public String[] fromCursor(String name, Cursor content) {
    String val = content.getString(content.getColumnIndex(name));
    if (val == null) {
      return null;
    }
    try {
      JSONArray arr = new JSONArray(val);
      String[] res = new String[arr.length()];
      for (int i = 0; i < res.length; i++) {
        res[i] = arr.getString(i);
      }
      return res;
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }

  @Override
  public String getSQLValue(String[] object) {
    if (object == null) {
      return null;
    }
    return new JSONArray(Arrays.asList(object)).toString();
  }
}




Java Source Code List

com.njzk2.simplestorage.DataProvider.java
com.njzk2.simplestorage.Database.java
com.njzk2.simplestorage.SQLHelper.java
com.njzk2.simplestorage.SQLSchema.java
com.njzk2.simplestorage.Storable.java
com.njzk2.simplestorage.handler.BooleanHandler.java
com.njzk2.simplestorage.handler.BytesHandler.java
com.njzk2.simplestorage.handler.DateHandler.java
com.njzk2.simplestorage.handler.IntHandler.java
com.njzk2.simplestorage.handler.LongHandler.java
com.njzk2.simplestorage.handler.StringArrayHandler.java
com.njzk2.simplestorage.handler.StringHandler.java
com.njzk2.simplestorage.handler.TypeHandler.java