private static void doSomething(Context context, PerformingInterface perform) throws IOException { String traceId = null, tagId = null; for (Record record : context.getContext().readCacheTable("subscribe")) { getTraceIdAndTagIdFromRecord(record, traceId, tagId); if (traceSet.contains(traceId) == false) continue; if (!checkTagIdIsNumber(tagId)) { context.getCounter("Error", "tag_id not a number").increment(1); continue; } perform.accept(tagId, traceId); } }
private static void imYourNewMethod(Context context,Boolean isAddTag){ String traceId = null, tagId = null; for (Record record : context.getContext().readCacheTable("subscribe")) { getTraceIdAndTagIdFromRecord(record, traceId, tagId); if (traceSet.contains(traceId) == false) continue; if (!checkTagIdIsNumber(tagId)) { context.getCounter("Error", "tag_id not a number").increment(1); continue; } if(isAddTag){ Vector<String> ret = traceListMap.get(tagId); if (ret == null) { ret = new Vector<String>(); } ret.add(traceId); traceListMap.put(tagId, ret); }else{ tagSet.add(tagId); } }
private static Stream<Record> validRecords(Context context) throws IOException { return context.getContext().readCacheTable("subscribe").stream() .filter(r -> { if (!traceSet.contains(traceId(r))) { return false; } try { Integer.parseInt(tagId(r)); return true; } catch (NumberFormatException e) { context.getCounter("Error", "tag_id not a number").increment(1); return false; } }); } private static String traceId(Record record) { return record.get("trace_id").toString(); } private static String tagId(Record record) { return record.get("tag_id").toString(); }