[英]How to compare 2 arraylist in one of value object
I have two arraylist. 我有两个arraylist。 How to match a value of String just running the proccess?
如何在运行过程中匹配String的值?
Coding: 编码:
ArrayList<TimeSeriesObject> arrayDayMinutes = new ArrayList<TimeSeriesObject>();
List<GetTimeSeriesResponseType.Row> rows = (List<Row>) el.getObjectValue();
for (i = iStart; i < arrayDayMinutes.size(); i++)
{
for (int j = n; j < rows.size(); j++)
{
nLoop++;
if (arrayDayMinutes.get(i).getTimeStamp().equals(ConvertDateTime(rows.get(j).getTIMESTAMP().toGregorianCalendar())))
{
// khteo 20140211
if (arrayDayMinutes.get(i).getTimeStamp().equals(ConvertDateTime(rows.get(j).getTIMESTAMP().toGregorianCalendar(), marketInfo.getTimezone())))
{
arrayDayMinutes.get(i).setOpen(rows.get(j).getOPEN());
arrayDayMinutes.get(i).setHigh(rows.get(j).getHIGH());
arrayDayMinutes.get(i).setLow(rows.get(j).getLOW());
arrayDayMinutes.get(i).setClose(rows.get(j).getCLOSE());
try
{
arrayDayMinutes.get(i).setVolume(rows.get(j).getVOLUME());
}
catch (NullPointerException npe)
{
arrayDayMinutes.get(i).setVolume(0);
}
n = j + 1;
long executeReques_end = System.currentTimeMillis();
// System.out.println("After 2nd loop:" + executeReques_end +"|total timing " + (executeReques_end-executeRequest_2ndbeforeLoop));
break;
}
}
}
}
If I'm using steps as above, 如果我使用上述步骤,
if (arrayDayMinutes.get(i).getTimeStamp().equals(ConvertDateTime(rows.get(j).getTIMESTAMP().toGregorianCalendar())))
The code above has a bad performance... How to improve performance? 上面的代码性能不好...如何提高性能? When the ArrayList not match, it will keep loading.. can be skip the unmatching value?
当ArrayList不匹配时,它将继续加载..可以跳过不匹配的值吗?
I don't get the second if: Isn't there a more effective way to compute: 如果没有,我就没有第二个:没有更有效的计算方法:
arrayDayMinutes.get(i).getTimeStamp().equals(ConvertDateTime(rows.get(j).getTIMESTAMP().toGregorianCalendar(), marketInfo.getTimezone()))
when you know that: 当您知道:
arrayDayMinutes.get(i).getTimeStamp().equals(ConvertDateTime(rows.get(j).getTIMESTAMP().toGregorianCalendar()))
is true? 是真的?
for instance: 例如:
Calendar cal = rows.get(j).getTIMESTAMP().toGregorianCalendar();
if (cal.getTimeZone().equals(marketInfo.getTimeZone())
&& arrayDayMinutes.get(i).getTimeStamp().equals(ConvertDateTime(cal)))
{
In any case, if ConvertDateTime is costly, it could be worthwhile to keep it in a cache to avoid computing is several times: 无论如何,如果ConvertDateTime的成本很高,可能值得将其保存在缓存中以避免计算多次:
// assuming that TimeSeriesObject.getTimeStamp() returns a Date
Date[] cache = new Date[rows.size()];
for (i = iStart; i < arrayDayMinutes.size(); i++)
{
for (int j = n; j < rows.size(); j++)
{
Date timestamp = cache[j];
if (timestamp == null) {
timestamp = ConvertDateTime(rows.get(j).getTIMESTAMP().toGregorianCalendar());
cache[j] = timestamp;
}
nLoop++;
if (arrayDayMinutes.get(i).getTimeStamp().equals(timestamp))
{
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.