<s> from hazelcast . protocol . codec import set_add_all_codec , set_add_codec , set_add_listener_codec , set_clear_codec , set_compare_and_remove_all_codec , set_compare_and_retain_all_codec , set_contains_all_codec , set_contains_codec , set_get_all_codec , set_is_empty_codec , set_remove_codec , set_remove_listener_codec , set_size_codec <EOL> from hazelcast . proxy . base import PartitionSpecificProxy , ItemEvent , ItemEventType <EOL> from hazelcast . util import check_not_none <EOL> class Set ( PartitionSpecificProxy ) : <EOL> def add ( self , item ) : <EOL> check_not_none ( item , "<STR_LIT>" ) <EOL> element_data = self . _to_data ( item ) <EOL> return self . _encode_invoke ( set_add_codec , value = element_data ) <EOL> def add_all ( self , items ) : <EOL> check_not_none ( items , "<STR_LIT>" ) <EOL> data_items = [ ] <EOL> for item in items : <EOL> check_not_none ( item , "<STR_LIT>" ) <EOL> data_items . append ( self . _to_data ( item ) ) <EOL> return self . _encode_invoke ( set_add_all_codec , value_list = data_items ) <EOL> def add_listener ( self , include_value = False , item_added = None , item_removed = None ) : <EOL> request = set_add_listener_codec . encode_request ( self . name , include_value , False ) <EOL> def handle_event_item ( item , uuid , event_type ) : <EOL> item = item if include_value else None <EOL> member = self . _client . cluster . get_member_by_uuid ( uuid ) <EOL> item_event = ItemEvent ( self . name , item , event_type , member , self . _to_object ) <EOL> if event_type == ItemEventType . added : <EOL> if item_added : <EOL> item_added ( item_event ) <EOL> else : <EOL> if item_removed : <EOL> item_removed ( item_event ) <EOL> return self . _start_listening ( request , <EOL> lambda m : set_add_listener_codec . handle ( m , handle_event_item ) , <EOL> lambda r : set_add_listener_codec . decode_response ( r ) [ '<STR_LIT>' ] , <EOL> self . partition_key ) <EOL> def clear ( self ) : <EOL> return self . _encode_invoke ( set_clear_codec ) <EOL> def contains ( self , item ) : <EOL> check_not_none ( item , "<STR_LIT>" ) <EOL> item_data = self . _to_data ( item ) <EOL> return self . _encode_invoke ( set_contains_codec , value = item_data ) <EOL> def contains_all ( self , items ) : <EOL> check_not_none ( items , "<STR_LIT>" ) <EOL> data_items = [ ] <EOL> for item in items : <EOL> check_not_none ( item , "<STR_LIT>" ) <EOL> data_items . append ( self . _to_data ( item ) ) <EOL> return self . _encode_invoke ( set_contains_all_codec , items = data_items ) <EOL> def get_all ( self ) : <EOL> return self . _encode_invoke ( set_get_all_codec ) <EOL> def is_empty ( self ) : <EOL> return self . _encode_invoke ( set_is_empty_codec ) <EOL> def remove ( self , item ) : <EOL> check_not_none ( item , "<STR_LIT>" ) <EOL> item_data = self . _to_data ( item ) <EOL> return self . _encode_invoke ( set_remove_codec , value = item_data ) <EOL> def remove_all ( self , items ) : <EOL> check_not_none ( items , "<STR_LIT>" ) <EOL> data_items = [ ] <EOL> for item in items : <EOL> check_not_none ( item , "<STR_LIT>" ) <EOL> data_items . append ( self . _to_data ( item ) ) <EOL> return self . _encode_invoke ( set_compare_and_remove_all_codec , values = data_items ) <EOL> def remove_listener ( self , registration_id ) : <EOL> return self . _stop_listening ( registration_id , lambda i : set_remove_listener_codec . encode_request ( self . name , i ) ) <EOL> def retain_all ( self , items ) : <EOL> check_not_none ( items , "<STR_LIT>" ) <EOL> data_items = [ ] <EOL> for item in items : <EOL> check_not_none ( item , "<STR_LIT>" ) <EOL> data_items . append ( self . _to_data ( item ) ) <EOL> return self . _encode_invoke ( set_compare_and_retain_all_codec , values = data_items ) <EOL> def size ( self ) : <EOL> return self . _encode_invoke ( set_size_codec ) </s>
