public static void sanityCheck ( List < Protocol > protocols ) throws Exception { // check for unique IDs Set < Short > ids = new HashSet <> ( ) ; for ( Protocol protocol : protocols ) { short id = protocol . getId ( ) ; if ( id > 0 && ! ids . add ( id ) ) throw new Exception ( "Protocol ID " + id + " (name=" + protocol . getName ( ) + ") is duplicate; protocol IDs have to be unique" ) ; } // For each protocol, get its required up and down services and check (if available) if they're satisfied for ( Protocol protocol : protocols ) { List < Integer > required_down_services = protocol . requiredDownServices ( ) ; List < Integer > required_up_services = protocol . requiredUpServices ( ) ; if ( required_down_services != null && ! required_down_services . isEmpty ( ) ) { // the protocols below 'protocol' have to provide the services listed in required_down_services List < Integer > tmp = new ArrayList <> ( required_down_services ) ; removeProvidedUpServices ( protocol , tmp ) ; if ( ! tmp . isEmpty ( ) ) throw new Exception ( "events " + printEvents ( tmp ) + " are required by " + protocol . getName ( ) + ", but not provided by any of the protocols below it" ) ; } if ( required_up_services != null && ! required_up_services . isEmpty ( ) ) { // the protocols above 'protocol' have to provide the services listed in required_up_services List < Integer > tmp = new ArrayList <> ( required_up_services ) ; removeProvidedDownServices ( protocol , tmp ) ; if ( ! tmp . isEmpty ( ) ) throw new Exception ( "events " + printEvents ( tmp ) + " are required by " + protocol . getName ( ) + ", but not provided by any of the protocols above it" ) ; } } }
Throws an exception if sanity check fails . Possible sanity check is uniqueness of all protocol names