public boolean add ( final K key , final V value ) { final V curValue = this . valueByKey . get ( key ) ; if ( curValue == null ) { // key does not exist if ( this . mode == Mode . UPDATE ) return false ; } else { // key exists if ( this . mode == Mode . CREATE ) return false ; } if ( this . closed && ! this . valueByKey . containsKey ( key ) ) { throw new IllegalStateException ( "Container put(" + key + ", " + value + ")" ) ; } else if ( this . debug && ! this . valueByKey . containsKey ( key ) ) { Logger . getLogger ( "debug" ) . severe ( "Container put(" + key + ", " + value + ")" ) ; } this . valueByKey . put ( key , value ) ; return true ; }
If mode is update then the key must exist . If the mode is create then the key must not exist . Otherwise the key may exist . If the container is frozen no new key - value pair is accepted .