/** * Combine two records. */ public static GraphAnalyticsRecord addRecords( GraphAnalyticsRecord... records) { if (null == records || 0 == records.length) return null; int numCommunities = records[0].getNumCommunities(); LinkedList<GraphCommunity> communities = new LinkedList<>(records[0].getCommunities()); for (int i = 1; i < records.length; ++i) { numCommunities += records[i].getNumCommunities(); addCommunitiesInPlace(communities, records[i].getCommunities()); } return new GraphAnalyticsRecord(numCommunities, communities); }
/** * Add a graph community to an existing record, summing counts as needed, and keeping * the MAX_COMMUNITIES largest communities. */ public static GraphAnalyticsRecord addCommunityToRecord( GraphAnalyticsRecord record, GraphCommunity newCommunity) { if (null == record) return null; int numCommunities = record.getNumCommunities() + 1; LinkedList<GraphCommunity> accumulatedCommunities = new LinkedList<>(record.getCommunities()); addCommunityInPlace(accumulatedCommunities, newCommunity); return new GraphAnalyticsRecord(numCommunities, accumulatedCommunities); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (null == obj) return false; if (!(obj instanceof GraphAnalyticsRecord)) return false; GraphAnalyticsRecord that = (GraphAnalyticsRecord) obj; if (this.getNumCommunities() != that.getNumCommunities()) { return false; } else if ((this.getCommunities()!= null) && (!listsEqual(this.getCommunities(), that.getCommunities()))) { return false; } else { return true; } }
@Override protected void setEntryValue (GenericRecord avroEntry, GraphAnalyticsRecord rawEntry) { try { Schema entrySchema = getEntrySchema(); avroEntry.put("numCommunities", rawEntry.getNumCommunities()); avroEntry.put("communities", communityListToAvro(entrySchema, rawEntry.getCommunities())); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
minNumCommunities = Math.min(minNumCommunities, record.getNumCommunities()); minInPlace(minCommunity, record.getCommunities());
maxNumCommunities = Math.max(maxNumCommunities, record.getNumCommunities()); maxInPlace(maxCommunity, record.getCommunities());