使用set出现问题,size有时变为0

机器学习之禅 2014-07-04 05:04:51
在for循环中显示set的size,没有问题,随着数据增加size也增加,
但是后面那条size就变为0了,这是为什么?
关键是还不是所有数据都这样

while ((s1 = br.readLine()) != null)
{
Set<String> usrSet = new HashSet<String>();
try
{
LOG.info("[INFO] The "+count+" ID.");
count++;

// 获取一个用户id
String id = s1;
// 根据id获取用户行为记录
HashMap<String, String> usrlog_hashmap = new HashMap<String, String>();
usrlog_hashmap = logDBOperation.queryUserIDInDateRange(id, timeStamp, 7);//logDBOperation.queryByUsrID(id);//queryUserIDInDateRange(id, "2014061900000", 500);//;queryUserIDInDateRange
int tempcount = 0;
// 循环读取用户行为
for (Entry<String, String> entry : usrlog_hashmap.entrySet())
{
//System.out.println(entry.getValue() + "\n");
String[] usrlog = entry.getValue().split("!");
for(String tem : usrlog)
{
//System.out.println(tem + "\n");
tempcount++;
countUserLog++;
//匹配
Matcher matcher = pattern.matcher(tem);
if(matcher.find())
{
//System.out.println(tem + "\n");
countUsefulLog++;
String postid = matcher.group(1);
String leftStr = matcher.group(2);
//System.out.println("postid "+postid);
Item item = null;
boolean flag = true;
while(flag)
{
try
{
item = itemop.get(postid);

flag = false;
}
catch(Exception e)
{
LOG.error("[ERROR] Get item failed.");
continue;
}
}

String channel = "";


try{
channel = channelsParser.getInstance(ItemOperation.ItemType.APPITEM).getTransChannelByItem(item,0);

}
catch(java.lang.NoClassDefFoundError e)
{
LOG.error("[ERROR] Get channel failed.");
continue;
}
if(channel == null || channel == "" || channel == " ")
{
Matcher matcher1 = pattern1.matcher(leftStr);
if(matcher1.find())
{
channel = matcher1.group(1);
System.out.println("channel: "+channel);
countref++;
}
}
//System.out.println("channel: "+channel);
String[] row = channel.split("-");
for(int i = 1; i < row.length; i++)
{
row[i] = row[i-1]+"-"+row[i];
}

for(int j = 0; j < row.length; j++)
{
System.out.println("row[j] "+ row[j]);
usrSet.add(row[j]);
System.out.println("usrSet.size() "+usrSet.size());
}
//String[] channelclass = channel.split("/");
}
}

}
System.out.println("usrSet.size() "+usrSet.size());

}
catch(Exception e)
{
LOG.error("Something wrong with me.");
continue;
}
}
...全文
109 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧