question: private void addEvent ( EventReg reg ) { if ( reg . listener == null ) return ; EntryRep [ ] tmpls = reg . tmpl . attributeSetTemplates ; if ( tmpls != null ) { for ( int i = tmpls . length ; -- i >= 0 ; ) { EntryClass eclass = tmpls [ i ] . eclass ; eclass . setNumTemplates ( eclass . getNumTemplates ( ) + 1 ) ; } } Long id = new Long ( reg . eventID ) ; eventByID . put ( id , reg ) ; eventByTime . put ( reg , reg ) ; if ( reg . tmpl . serviceID != null ) { Object val = subEventByService . get ( reg . tmpl . serviceID ) ; if ( val == null ) val = reg ; else if ( val instanceof EventReg ) val = new EventReg [ ] { ( EventReg ) val , reg } ; else val = arrayAdd ( ( EventReg [ ] ) val , reg ) ; subEventByService . put ( reg . tmpl . serviceID , val ) ; } else { subEventByID . put ( id , reg ) ; } computeMaxLeases ( ) ; }
target:  Add an event registration to our state.  This includes adding a template of each EntryClass, putting the registration in the eventByID map, in the eventByTime map, and in either subEventByService (if the template is for a specific service id) or subEventByID.  Since we expect in most cases there will only ever be a single event registration for a given service id, we avoid creating a singleton array in that case.