在自定义Arraylist

时间:2017-04-25 23:14:39

标签: java android sqlite csv arraylist

我在sqlite数据库单元格中有以下字符串

1492972200000, 67.529999
1492367400000, 66.400002
1491762600000, 64.949997
1491157800000, 65.68
1490553000000, 65.860001
1489948200000, 64.980003
1489343400000, 64.870003
1488738600000, 64.93
1488133800000, 64.25
1487615400000, 64.620003
1486924200000, 64.620003
1486319400000, 64.00
1485714600000, 63.68
1485109800000, 65.779999
1484591400000, 62.740002
1483900200000, 62.700001
1483381800000, 62.84
1482777000000, 62.139999
1482085800000, 63.240002
1481481000000, 62.299999
1480876200000, 61.970001
1480271400000, 59.25
1479666600000, 60.529999
1479061800000, 60.349998
1478457000000, 59.02
1477852200000, 58.709999
1477247400000, 59.869999
1476642600000, 59.66

我想在自定义Arraylist中将这些分为“时间”和“价值”

 if (cursor.moveToFirst()) {
            do {
                String dataColumn = cursor.getString(Contract.Quote.POSITION_HISTORY);
                Timber.d(dataColumn);
//Timber.d is giving me the value above


            } while (cursor.moveToNext());
        }
        cursor.close();
    }

...

加上有人可以告诉我哪种因素显示这种格式的简单记事本 http://prntscr.com/f0ua6l

这种格式的

和notepad ++和android studio logger http://prntscr.com/f0uag4

它可能有助于制作正则表达式

由于

1 个答案:

答案 0 :(得分:0)

我想说创建一个简单的POJO类

class MyClass {
    private Date time;
    private Double value;

    public MyClass(String record) {
        values = record.split(',');
        time = new Date(new Long(values[0]));
        value = new Date(new Double(values[1]));
    }
    //Getters and setters for above    
}

然后,您的代码可以解析每条记录并为它们创建新对象并添加到数组列表中。这就是大多数ORM系统的工作原理。

ArrayList<MyClass> myList = new ArrayList<MyClass>();

if (cursor.moveToFirst()) {
     do {
            String dataColumn = cursor.getString(Contract.Quote.POSITION_HISTORY);
            myObj = new MyClass(dataColumn);
            myList.append(myObj);


        } while (cursor.moveToNext());
    }
    cursor.close();

    //myList holds the list of items you want.
    //This way adding new field in DB can be managed easily. 
    //Separation of concern - basic principle in OO design
}

希望它有所帮助!