android.arch.persistence.room.TypeConverter Java Examples

The following examples show how to use android.arch.persistence.room.TypeConverter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EarthquakeTypeConverters.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@TypeConverter
public static Location locationFromString(String location) {
  if (location != null && (location.contains(","))) {
    Location result = new Location("Generated");
    String[] locationStrings = location.split(",");

    if (locationStrings.length == 2) {
      result.setLatitude(Double.parseDouble(locationStrings[0]));
      result.setLongitude(Double.parseDouble(locationStrings[1]));
      return result;
    }
    else return null;
  }
  else
    return null;
}
 
Example #2
Source File: EarthquakeTypeConverters.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@TypeConverter
public static Location locationFromString(String location) {
  if (location != null && (location.contains(","))) {
    Location result = new Location("Generated");
    String[] locationStrings = location.split(",");

    if (locationStrings.length == 2) {
      result.setLatitude(Double.parseDouble(locationStrings[0]));
      result.setLongitude(Double.parseDouble(locationStrings[1]));
      return result;
    }
    else return null;
  }
  else
    return null;
}
 
Example #3
Source File: EarthquakeTypeConverters.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@TypeConverter
public static Location locationFromString(String location) {
  if (location != null && (location.contains(","))) {
    Location result = new Location("Generated");
    String[] locationStrings = location.split(",");

    if (locationStrings.length == 2) {
      result.setLatitude(Double.parseDouble(locationStrings[0]));
      result.setLongitude(Double.parseDouble(locationStrings[1]));
      return result;
    }
    else return null;
  }
  else
    return null;
}
 
Example #4
Source File: EarthquakeTypeConverters.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@TypeConverter
public static Location locationFromString(String location) {
  if (location != null && (location.contains(","))) {
    Location result = new Location("Generated");
    String[] locationStrings = location.split(",");

    if (locationStrings.length == 2) {
      result.setLatitude(Double.parseDouble(locationStrings[0]));
      result.setLongitude(Double.parseDouble(locationStrings[1]));
      return result;
    }
    else return null;
  }
  else
    return null;
}
 
Example #5
Source File: EarthquakeTypeConverters.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@TypeConverter
public static Location locationFromString(String location) {
  if (location != null && (location.contains(","))) {
    Location result = new Location("Generated");
    String[] locationStrings = location.split(",");

    if (locationStrings.length == 2) {
      result.setLatitude(Double.parseDouble(locationStrings[0]));
      result.setLongitude(Double.parseDouble(locationStrings[1]));
      return result;
    }
    else return null;
  }
  else
    return null;
}
 
Example #6
Source File: TimestampConverter.java    From RoomDb-Sample with Apache License 2.0 5 votes vote down vote up
@TypeConverter
public static Date fromTimestamp(String value) {
    if (value != null) {
        try {
            TimeZone timeZone = TimeZone.getTimeZone("IST");
            df.setTimeZone(timeZone);
            return df.parse(value);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    } else {
        return null;
    }
}
 
Example #7
Source File: ToxKeyConverter.java    From Tok-Android with GNU General Public License v3.0 5 votes vote down vote up
@TypeConverter
public static ContactsKey make(String key) {
    if (key == null) {
        return null;
    }
    return new ContactsKey(key);
}
 
Example #8
Source File: ToxNicknameConverter.java    From Tok-Android with GNU General Public License v3.0 5 votes vote down vote up
@TypeConverter
public static ToxNickname make(String nickname) {
    if (nickname == null) {
        return null;
    }
    return ToxNickname.unsafeFromValue(nickname.getBytes());
}
 
Example #9
Source File: FileKindConverter.java    From Tok-Android with GNU General Public License v3.0 5 votes vote down vote up
@TypeConverter
public static int parse(FileKind fileKind) {
    if (fileKind == null) {
        return FileKind.INVALID.getKindId();
    }
    return fileKind.getKindId();
}
 
Example #10
Source File: Converters.java    From input-samples with Apache License 2.0 5 votes vote down vote up
/**
 * If database returns a {@link String} containing a comma delimited list of ints, this converts
 * the {@link String} to an {@link IntList}.
 */
@TypeConverter
public static IntList storedStringToIntList(String value) {
    List<String> strings = Arrays.asList(value.split("\\s*,\\s*"));
    List<Integer> ints = strings.stream().map(Integer::parseInt).collect(toList());
    return new IntList(ints);
}
 
Example #11
Source File: Converters.java    From input-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Converts the {@link StringList} back into a {@link String} containing a comma delimited
 * list of {@link String}s.
 */
@TypeConverter
public static String stringListToStoredString(StringList list) {
    StringBuilder stringBuilder = new StringBuilder();
    for (String string : list.strings) {
        stringBuilder.append(string).append(",");
    }
    return stringBuilder.toString();
}
 
Example #12
Source File: ToxMeNameConverter.java    From Tok-Android with GNU General Public License v3.0 5 votes vote down vote up
@TypeConverter
public static ToxMeName make(String name) {
    if (name == null) {
        return null;
    }
    return new ToxMeName(name, "");
}
 
Example #13
Source File: DataConverter.java    From mobikul-standalone-pos with MIT License 5 votes vote down vote up
@TypeConverter
public String fromOptionValuesList(List<OptionValues> optionValues) {
    if (optionValues == null) {
        return (null);
    }
    Gson gson = new Gson();
    Type type = new TypeToken<List<OptionValues>>() {
    }.getType();
    String json = gson.toJson(optionValues, type);
    return json;
}
 
Example #14
Source File: DataConverter.java    From mobikul-standalone-pos with MIT License 5 votes vote down vote up
@TypeConverter
public List<OptionValues> toOptionValuesList(String optionValuesString) {
    if (optionValuesString == null) {
        return (null);
    }
    Gson gson = new Gson();
    Type type = new TypeToken<List<OptionValues>>() {
    }.getType();
    List<OptionValues> productCategoriesList = gson.fromJson(optionValuesString, type);
    return productCategoriesList;
}
 
Example #15
Source File: DataConverter.java    From mobikul-standalone-pos with MIT License 5 votes vote down vote up
@TypeConverter
public List<Options> toOptionsList(String optionString) {
    if (optionString == null) {
        return (null);
    }
    Gson gson = new Gson();
    Type type = new TypeToken<List<Options>>() {
    }.getType();
    List<Options> productOptionList = gson.fromJson(optionString, type);
    return productOptionList;
}
 
Example #16
Source File: DataConverter.java    From mobikul-standalone-pos with MIT License 5 votes vote down vote up
@TypeConverter
public CartModel fromStringToCartModel(String cartDataString) {
    if (cartDataString == null) {
        return (null);
    }
    Gson gson = new Gson();
    Type type = new TypeToken<CartModel>() {
    }.getType();
    CartModel cartData = gson.fromJson(cartDataString, type);
    return cartData;
}
 
Example #17
Source File: DataConverter.java    From mobikul-standalone-pos with MIT License 5 votes vote down vote up
@TypeConverter
public String fromTaxModelToString(Tax taxData) {
    if (taxData == null) {
        return (null);
    }
    Gson gson = new Gson();
    Type type = new TypeToken<Tax>() {
    }.getType();
    String json = gson.toJson(taxData, type);
    return json;
}
 
Example #18
Source File: DataConverter.java    From mobikul-standalone-pos with MIT License 5 votes vote down vote up
@TypeConverter
public CashModel fromStringToCashModel(String cashDataString) {
    if (cashDataString == null) {
        return (null);
    }
    Gson gson = new Gson();
    Type type = new TypeToken<CashModel>() {
    }.getType();
    CashModel cashData = gson.fromJson(cashDataString, type);
    return cashData;
}
 
Example #19
Source File: DataConverter.java    From mobikul-standalone-pos with MIT License 5 votes vote down vote up
@TypeConverter
public List<CashDrawerItems> fromStringToCashDrawerItem(String cashDrawerItemsString) {
    if (cashDrawerItemsString == null) {
        return (null);
    }
    Gson gson = new Gson();
    Type type = new TypeToken<List<CashDrawerItems>>() {
    }.getType();
    List<CashDrawerItems> cashDrawerItems = gson.fromJson(cashDrawerItemsString, type);
    return cashDrawerItems;
}
 
Example #20
Source File: DateConverter.java    From EasyNLU with Apache License 2.0 5 votes vote down vote up
@TypeConverter
public static Long fromDate(Date date) {
    if(date != null)
        return date.getTime();
    else
        return (long) -1;
}
 
Example #21
Source File: DateConverter.java    From EasyNLU with Apache License 2.0 5 votes vote down vote up
@TypeConverter
public  static Date toDate(Long time) {
    if(time == -1)
        return null;
    else
        return new Date(time);
}
 
Example #22
Source File: Converters.java    From tron-wallet-android with Apache License 2.0 5 votes vote down vote up
@TypeConverter
public static Protocol.Transaction hexStringToTransaction(String hexString) {
    try {
        return Protocol.Transaction.parseFrom(Hex.decode(hexString));
    } catch (InvalidProtocolBufferException e) {
        e.printStackTrace();
        return null;
    }
}
 
Example #23
Source File: ToxMeNameConverter.java    From Tok-Android with GNU General Public License v3.0 5 votes vote down vote up
@TypeConverter
public static String parse(ToxMeName toxMeName) {
    if (toxMeName == null) {
        return "";
    }
    return toxMeName.getUserName();
}
 
Example #24
Source File: EarthquakeTypeConverters.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 4 votes vote down vote up
@TypeConverter
public static String locationToString(Location location) {
  return location == null ?
           null : location.getLatitude() + "," + location.getLongitude();
}
 
Example #25
Source File: EarthquakeTypeConverters.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 4 votes vote down vote up
@TypeConverter
public static Date dateFromTimestamp(Long value) {
  return value == null ? null : new Date(value);
}
 
Example #26
Source File: Converters.java    From Building-Professional-Android-Applications with MIT License 4 votes vote down vote up
@TypeConverter
public static BigDecimal fromBigDecimal(String value) {
    return value == null ? null : new BigDecimal(value);
}
 
Example #27
Source File: DateConverter.java    From RoomDb-Sample with Apache License 2.0 4 votes vote down vote up
@TypeConverter
public static String dateToTimestamp(Date value) {
    return value == null ? null : df.format(value);
}
 
Example #28
Source File: EarthquakeTypeConverters.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 4 votes vote down vote up
@TypeConverter
public static Date dateFromTimestamp(Long value) {
  return value == null ? null : new Date(value);
}
 
Example #29
Source File: Converters.java    From Building-Professional-Android-Applications with MIT License 4 votes vote down vote up
@TypeConverter
public static Long dateToTimestamp(Date date) {
    return date == null ? null : date.getTime();
}
 
Example #30
Source File: Converters.java    From Building-Professional-Android-Applications with MIT License 4 votes vote down vote up
@TypeConverter
public static BigDecimal fromBigDecimal(String value) {
    return value == null ? null : new BigDecimal(value);
}