From 878480097a7f1c09c25e07f95786503f7d6cfefb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 14 Dec 2023 11:10:02 +0900 Subject: [PATCH] =?UTF-8?q?Converter=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/TagArrayListConverter.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 source/src/main/java/one/nem/lacerta/source/database/common/TagArrayListConverter.java diff --git a/source/src/main/java/one/nem/lacerta/source/database/common/TagArrayListConverter.java b/source/src/main/java/one/nem/lacerta/source/database/common/TagArrayListConverter.java new file mode 100644 index 00000000..e9bd635b --- /dev/null +++ b/source/src/main/java/one/nem/lacerta/source/database/common/TagArrayListConverter.java @@ -0,0 +1,28 @@ +package one.nem.lacerta.source.database.common; + +import androidx.room.TypeConverter; + +import java.util.ArrayList; +import java.util.Arrays; + +public class TagArrayListConverter { + + @TypeConverter + public static ArrayList fromString(String value) { + return value == null ? null : new ArrayList(Arrays.asList(value.split(","))); + } + + @TypeConverter + public static String fromArrayList(ArrayList list) { + if (list == null) { + return null; + } + + StringBuilder sb = new StringBuilder(); + for (String s : list) { + sb.append(s); + sb.append(","); + } + return sb.toString(); + } +}