pax_global_header00006660000000000000000000000064123431541140014510gustar00rootroot0000000000000052 comment=0c0753aa2eb69fbef47b4e4e5f43ef531d10291b gs-collections-5.1.0/000077500000000000000000000000001234315411400144405ustar00rootroot00000000000000gs-collections-5.1.0/.classpath000066400000000000000000000023301234315411400164210ustar00rootroot00000000000000 gs-collections-5.1.0/.gitignore000066400000000000000000000000101234315411400164170ustar00rootroot00000000000000target gs-collections-5.1.0/.idea/000077500000000000000000000000001234315411400154205ustar00rootroot00000000000000gs-collections-5.1.0/.idea/ant.xml000066400000000000000000000005141234315411400167240ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/codeStyleSettings.xml000066400000000000000000000317541234315411400216300ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/compiler.xml000066400000000000000000000050631234315411400177600ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/copyright/000077500000000000000000000000001234315411400174305ustar00rootroot00000000000000gs-collections-5.1.0/.idea/copyright/Apache.xml000066400000000000000000000016671234315411400213450ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/copyright/profiles_settings.xml000066400000000000000000000003031234315411400237110ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/encodings.xml000066400000000000000000000025421234315411400201160ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/inspectionProfiles/000077500000000000000000000000001234315411400212775ustar00rootroot00000000000000gs-collections-5.1.0/.idea/inspectionProfiles/1_Severe.xml000066400000000000000000005702241234315411400235040ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/inspectionProfiles/2_1_Java_Lang_Migration_Aids.xml000066400000000000000000005702441234315411400272710ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/inspectionProfiles/2_2_Inconsistent_Constructs.xml000066400000000000000000005702311234315411400274020ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/inspectionProfiles/2_3_More_Inconsistent_Constructs.xml000066400000000000000000005671141234315411400303730ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/inspectionProfiles/2_4_Redundant_Constructs.xml000066400000000000000000005703251234315411400266540ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/inspectionProfiles/2_5_String_Constructs.xml000066400000000000000000005703721234315411400262010ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/inspectionProfiles/2_Inconsistent_Constructs.xml000066400000000000000000005701151234315411400271620ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/inspectionProfiles/3_Consistent_Style.xml000066400000000000000000006310451234315411400255650ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/inspectionProfiles/4_1_Auto_fix_libraries.xml000066400000000000000000005672431234315411400263170ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/inspectionProfiles/4_2_Auto_fix_Individually.xml000066400000000000000000006061371234315411400267750ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/inspectionProfiles/4_3_Do_not_apply_auto_fix.xml000066400000000000000000005672441234315411400270350ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/inspectionProfiles/4_4_Fix_Manually.xml000066400000000000000000006061051234315411400250670ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/inspectionProfiles/4_No_Auto_fix.xml000066400000000000000000006061351234315411400244710ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/inspectionProfiles/IDE.xml000066400000000000000000004663331234315411400224410ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/inspectionProfiles/profiles_settings.xml000066400000000000000000000023431234315411400255660ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/libraries/000077500000000000000000000000001234315411400173745ustar00rootroot00000000000000gs-collections-5.1.0/.idea/libraries/Maven__classworlds_classworlds_1_1_alpha_2.xml000066400000000000000000000010531234315411400304100ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/libraries/Maven__commons_codec_commons_codec_1_8.xml000066400000000000000000000010111234315411400275430ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/libraries/Maven__commons_lang_commons_lang_2_6.xml000066400000000000000000000007761234315411400272730ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/libraries/Maven__junit_junit_3_8_1.xml000066400000000000000000000006771234315411400246500ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/libraries/Maven__junit_junit_4_11.xml000066400000000000000000000006701234315411400244740ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/libraries/Maven__net_jcip_jcip_annotations_1_0.xml000066400000000000000000000010121234315411400272510ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/libraries/Maven__net_sf_trove4j_trove4j_3_0_3.xml000066400000000000000000000007611234315411400267020ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/libraries/Maven__org_antlr_ST4_4_0_7.xml000066400000000000000000000007011234315411400247520ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/libraries/Maven__org_antlr_antlr_runtime_3_5.xml000066400000000000000000000007711234315411400270100ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/libraries/Maven__org_apache_ant_ant_1_9_3.xml000066400000000000000000000007251234315411400260750ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/libraries/Maven__org_apache_ant_ant_launcher_1_9_3.xml000066400000000000000000000010241234315411400277470ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/libraries/Maven__org_apache_maven_maven_artifact_2_0.xml000066400000000000000000000010341234315411400303620ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/libraries/Maven__org_apache_maven_maven_artifact_manager_2_0.xml000066400000000000000000000011241234315411400320540ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/libraries/Maven__org_apache_maven_maven_model_2_0.xml000066400000000000000000000010071234315411400276650ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/libraries/Maven__org_apache_maven_maven_plugin_api_2_0.xml000066400000000000000000000010521234315411400307140ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/libraries/Maven__org_apache_maven_maven_profile_2_0.xml000066400000000000000000000010251234315411400302250ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/libraries/Maven__org_apache_maven_maven_project_2_0.xml000066400000000000000000000010251234315411400302330ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/libraries/Maven__org_apache_maven_maven_repository_metadata_2_0.xml000066400000000000000000000011511234315411400326440ustar00rootroot00000000000000 Maven__org_apache_maven_wagon_wagon_provider_api_1_0_alpha_5.xml000066400000000000000000000012101234315411400337550ustar00rootroot00000000000000gs-collections-5.1.0/.idea/libraries Maven__org_codehaus_plexus_plexus_container_default_1_0_alpha_8.xml000066400000000000000000000012461234315411400345720ustar00rootroot00000000000000gs-collections-5.1.0/.idea/libraries gs-collections-5.1.0/.idea/libraries/Maven__org_codehaus_plexus_plexus_utils_1_0_4.xml000066400000000000000000000010501234315411400311430ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml000066400000000000000000000010051234315411400274140ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/libraries/Maven__org_scala_lang_scala_compiler_bundle_2_10_2.xml000066400000000000000000000007411234315411400316700ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/libraries/Maven__org_slf4j_slf4j_api_1_7_6.xml000066400000000000000000000007531234315411400261270ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/libraries/Maven__org_slf4j_slf4j_nop_1_7_6.xml000066400000000000000000000007531234315411400261520ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/misc.xml000077500000000000000000000051471234315411400171070ustar00rootroot00000000000000 http://www.w3.org/1999/xhtml gs-collections-5.1.0/.idea/modules.xml000066400000000000000000000052431234315411400176160ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/projectCodeStyle.xml000066400000000000000000000132771234315411400214360ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/runConfigurations/000077500000000000000000000000001234315411400211375ustar00rootroot00000000000000gs-collections-5.1.0/.idea/runConfigurations/All_Unit_Tests.xml000066400000000000000000000035331234315411400245560ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/runConfigurations/JMH.xml000066400000000000000000000020301234315411400222720ustar00rootroot00000000000000 gs-collections-5.1.0/.idea/runConfigurations/JMHTestRunner_runTests.xml000066400000000000000000000025031234315411400262400ustar00rootroot00000000000000 JMHTestRunner_runTests___XX__UnlockDiagnosticVMOptions__XX__PrintCompilation_.xml000066400000000000000000000026571234315411400410350ustar00rootroot00000000000000gs-collections-5.1.0/.idea/runConfigurations gs-collections-5.1.0/.idea/runConfigurations/JMHTestRunner_runTests___verbose_class_.xml000066400000000000000000000025431234315411400316130ustar00rootroot00000000000000 gs-collections-5.1.0/.project000066400000000000000000000013171234315411400161110ustar00rootroot00000000000000 collections-parent org.eclipse.jdt.core.javabuilder ch.epfl.lamp.sdt.core.scalabuilder org.maven.ide.eclipse.maven2Builder org.eclipse.jdt.core.javanature ch.epfl.lamp.sdt.core.scalanature org.maven.ide.eclipse.maven2Nature gs-collections-5.1.0/.settings/000077500000000000000000000000001234315411400163565ustar00rootroot00000000000000gs-collections-5.1.0/.settings/org.eclipse.jdt.core.prefs000066400000000000000000000542371234315411400233530ustar00rootroot00000000000000#Mon Sep 19 11:29:41 EDT 2011 eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.compliance=1.5 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.source=1.5 org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_assignment=16 org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16 org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 org.eclipse.jdt.core.formatter.alignment_for_enum_constants=16 org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16 org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16 org.eclipse.jdt.core.formatter.blank_lines_after_imports=1 org.eclipse.jdt.core.formatter.blank_lines_after_package=1 org.eclipse.jdt.core.formatter.blank_lines_before_field=0 org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0 org.eclipse.jdt.core.formatter.blank_lines_before_imports=1 org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1 org.eclipse.jdt.core.formatter.blank_lines_before_method=1 org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1 org.eclipse.jdt.core.formatter.blank_lines_before_package=0 org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1 org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1 org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=next_line org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=next_line org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line org.eclipse.jdt.core.formatter.brace_position_for_block=next_line org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=next_line org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=next_line org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=next_line org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=next_line org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=next_line org.eclipse.jdt.core.formatter.brace_position_for_switch=next_line org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=next_line org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false org.eclipse.jdt.core.formatter.comment.format_block_comments=true org.eclipse.jdt.core.formatter.comment.format_header=false org.eclipse.jdt.core.formatter.comment.format_html=true org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true org.eclipse.jdt.core.formatter.comment.format_line_comments=true org.eclipse.jdt.core.formatter.comment.format_source_code=true org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true org.eclipse.jdt.core.formatter.comment.indent_root_tags=true org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert org.eclipse.jdt.core.formatter.comment.line_length=120 org.eclipse.jdt.core.formatter.compact_else_if=true org.eclipse.jdt.core.formatter.continuation_indentation=2 org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2 org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true org.eclipse.jdt.core.formatter.indent_empty_lines=false org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=true org.eclipse.jdt.core.formatter.indentation.size=4 org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member=insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=insert org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=insert org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=insert org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=insert org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=insert org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert org.eclipse.jdt.core.formatter.join_lines_in_comments=true org.eclipse.jdt.core.formatter.join_wrapped_lines=false org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false org.eclipse.jdt.core.formatter.lineSplit=120 org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=true org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0 org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true org.eclipse.jdt.core.formatter.tabulation.char=space org.eclipse.jdt.core.formatter.tabulation.size=4 org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true gs-collections-5.1.0/.settings/org.eclipse.jdt.ui.prefs000066400000000000000000000236031234315411400230310ustar00rootroot00000000000000#Mon Sep 19 11:30:29 EDT 2011 cleanup.add_default_serial_version_id=false cleanup.add_generated_serial_version_id=true cleanup.add_missing_annotations=true cleanup.add_missing_deprecated_annotations=true cleanup.add_missing_methods=false cleanup.add_missing_nls_tags=false cleanup.add_missing_override_annotations=true cleanup.add_serial_version_id=false cleanup.always_use_blocks=true cleanup.always_use_parentheses_in_expressions=false cleanup.always_use_this_for_non_static_field_access=true cleanup.always_use_this_for_non_static_method_access=true cleanup.convert_to_enhanced_for_loop=false cleanup.correct_indentation=false cleanup.format_source_code=false cleanup.format_source_code_changes_only=false cleanup.make_local_variable_final=false cleanup.make_parameters_final=false cleanup.make_private_fields_final=true cleanup.make_type_abstract_if_missing_method=false cleanup.make_variable_declarations_final=true cleanup.never_use_blocks=false cleanup.never_use_parentheses_in_expressions=true cleanup.organize_imports=true cleanup.qualify_static_field_accesses_with_declaring_class=false cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true cleanup.qualify_static_member_accesses_with_declaring_class=true cleanup.qualify_static_method_accesses_with_declaring_class=false cleanup.remove_private_constructors=true cleanup.remove_trailing_whitespaces=true cleanup.remove_trailing_whitespaces_all=true cleanup.remove_trailing_whitespaces_ignore_empty=false cleanup.remove_unnecessary_casts=true cleanup.remove_unnecessary_nls_tags=true cleanup.remove_unused_imports=true cleanup.remove_unused_local_variables=false cleanup.remove_unused_private_fields=true cleanup.remove_unused_private_members=false cleanup.remove_unused_private_methods=true cleanup.remove_unused_private_types=true cleanup.sort_members=false cleanup.sort_members_all=false cleanup.use_blocks=true cleanup.use_blocks_only_for_return_and_throw=false cleanup.use_parentheses_in_expressions=false cleanup.use_this_for_non_static_field_access=true cleanup.use_this_for_non_static_field_access_only_if_necessary=false cleanup.use_this_for_non_static_method_access=true cleanup.use_this_for_non_static_method_access_only_if_necessary=false cleanup_profile=_Collections cleanup_settings_version=2 eclipse.preferences.version=1 editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true formatter_profile=_Collections formatter_settings_version=11 org.eclipse.jdt.ui.javadoc=true org.eclipse.jdt.ui.text.custom_code_templates= sp_cleanup.add_default_serial_version_id=true sp_cleanup.add_generated_serial_version_id=false sp_cleanup.add_missing_annotations=true sp_cleanup.add_missing_deprecated_annotations=true sp_cleanup.add_missing_methods=false sp_cleanup.add_missing_nls_tags=false sp_cleanup.add_missing_override_annotations=true sp_cleanup.add_serial_version_id=false sp_cleanup.always_use_blocks=true sp_cleanup.always_use_parentheses_in_expressions=false sp_cleanup.always_use_this_for_non_static_field_access=true sp_cleanup.always_use_this_for_non_static_method_access=true sp_cleanup.convert_to_enhanced_for_loop=false sp_cleanup.correct_indentation=false sp_cleanup.format_source_code=false sp_cleanup.format_source_code_changes_only=true sp_cleanup.make_local_variable_final=false sp_cleanup.make_parameters_final=false sp_cleanup.make_private_fields_final=true sp_cleanup.make_type_abstract_if_missing_method=false sp_cleanup.make_variable_declarations_final=true sp_cleanup.never_use_blocks=false sp_cleanup.never_use_parentheses_in_expressions=true sp_cleanup.on_save_use_additional_actions=true sp_cleanup.organize_imports=true sp_cleanup.qualify_static_field_accesses_with_declaring_class=false sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true sp_cleanup.qualify_static_member_accesses_with_declaring_class=true sp_cleanup.qualify_static_method_accesses_with_declaring_class=false sp_cleanup.remove_private_constructors=true sp_cleanup.remove_trailing_whitespaces=true sp_cleanup.remove_trailing_whitespaces_all=true sp_cleanup.remove_trailing_whitespaces_ignore_empty=false sp_cleanup.remove_unnecessary_casts=true sp_cleanup.remove_unnecessary_nls_tags=true sp_cleanup.remove_unused_imports=true sp_cleanup.remove_unused_local_variables=false sp_cleanup.remove_unused_private_fields=true sp_cleanup.remove_unused_private_members=false sp_cleanup.remove_unused_private_methods=true sp_cleanup.remove_unused_private_types=true sp_cleanup.sort_members=false sp_cleanup.sort_members_all=false sp_cleanup.use_blocks=true sp_cleanup.use_blocks_only_for_return_and_throw=false sp_cleanup.use_parentheses_in_expressions=false sp_cleanup.use_this_for_non_static_field_access=true sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=false sp_cleanup.use_this_for_non_static_method_access=true sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=false gs-collections-5.1.0/.settings/org.maven.ide.eclipse.prefs000066400000000000000000000004051234315411400234750ustar00rootroot00000000000000#Thu Feb 04 11:25:58 EST 2010 activeProfiles= eclipse.preferences.version=1 fullBuildGoals=process-test-resources includeModules=true resolveWorkspaceProjects=true resourceFilterGoals=process-resources resources\:testResources skipCompilerPlugin=true version=1 gs-collections-5.1.0/LICENSE-2.0.txt000066400000000000000000000261361234315411400165700ustar00rootroot00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. gs-collections-5.1.0/NOTICE000066400000000000000000000011101234315411400153350ustar00rootroot00000000000000GS Collections Copyright 2013 Goldman Sachs This product includes software (slf4j) developed by QOS.ch (http://www.slf4j.org/index.html). This product includes software (JCIP Annotations) developed by Brian Goetz and Tim Peierls (http://jcip.net/). This product includes software (JUnit) developed by JUnit.org (http://www.junit.org/). This product includes software developed by Dr. Heinz M. Kabutz (http://www.javaspecialists.eu/archive/Issue193.html). This product includes software (StringTemplate) developed by Terence Parr and Sam Harwell (http://www.stringtemplate.org/). gs-collections-5.1.0/README.md000066400000000000000000000071771234315411400157330ustar00rootroot00000000000000# GS Collections GS Collections is a collections framework for Java. It has JDK-compatible List, Set and Map implementations with a rich API and set of utility classes that work with any JDK compatible Collections, Arrays, Maps or Strings. The iteration protocol was inspired by the Smalltalk collection framework. ## Download * [Version 5.0.0](http://www.goldmansachs.com/gs-collections/binaries/gs-collections-5.0.0.zip) * [Older versions](https://github.com/goldmansachs/gs-collections/releases) ## Quick Example GS Collections puts iteration methods on the container types. Lambdas are simulated using anonymous inner classes. Here's a code example that demonstrates the usual style of programming with GS Collections. ```java MutableList people = FastList.newListWith(person1, person2, person3); MutableList sortedLastNames = people.collect(Person.TO_LAST_NAME).sortThis(); System.out.println("Comma separated, sorted last names: " + sortedLastNames.makeString()); ``` Person.TO_LAST_NAME is defined as a constant Function in the Person class. ```java public static final Function TO_LAST_NAME = new Function() { public String valueOf(Person person) { return person.lastName; } }; ``` In Java 8, the Function can be replaced with a lambda: ```java MutableList sortedLastNames = people.collect(person -> person.getLastName()).sortThis(); ``` Or, a method reference: ```java MutableList sortedLastNames = people.collect(Person::getLastName).sortThis(); ``` ## Why GS Collections? * Improves readability and reduces duplication of iteration code (enforces DRY/OAOO) * Implements several, high-level iteration patterns (select, reject, collect, inject into, etc.) on "humane" container interfaces which are extensions of the JDK interfaces * Provides a consistent mechanism for iterating over Collections, Arrays, Maps, and Strings * Provides replacements for ArrayList, HashSet, and HashMap optimized for performance and memory usage * Performs more "behind-the-scene" optimizations in utility classes * Encapsulates a lot of the structural complexity of parallel iteration and lazy evaluation * Adds new containers including Bag, Interval, Multimap, and immutable versions of all types * Has been under active development since 2005 and is a mature library ## Documentation The best way to learn about GS Collections is to dive into the [code kata](https://github.com/goldmansachs/gs-collections-kata). The kata is a fun way to learn idiomatic GS Collections usage and hone your skills through practice. For more comprehensive documentation, take a look at the [Reference Guide](https://github.com/goldmansachs/gs-collections/wiki). ## Contributions We currently do all development in an internal Subversion repository and are not prepared to take external contributions. However, we watch the [issue tracker](https://github.com/goldmansachs/gs-collections/issues) for bug reports and feature requests. ## FAQ ### Why is Goldman Sachs open-sourcing GS Collections? * We believe that GS Collections offers a significant advantage over existing solutions. We hope others will benefit from it. * We believe in the power of the technical community to help improve GS Collections. * Technology is a huge part of what we do at Goldman Sachs. GS Collections exemplifies our commitment to technology. * We use open source software in many of our operations. We have benefited from the work of others and we'd like to give something back. ### Does Goldman Sachs use GS Collections? Yes, we use GS Collections in many of our internal applications. gs-collections-5.1.0/acceptance-tests/000077500000000000000000000000001234315411400176665ustar00rootroot00000000000000gs-collections-5.1.0/acceptance-tests/.classpath000066400000000000000000000007701234315411400216550ustar00rootroot00000000000000 gs-collections-5.1.0/acceptance-tests/.project000066400000000000000000000010431234315411400213330ustar00rootroot00000000000000 acceptance-tests org.eclipse.jdt.core.javabuilder org.maven.ide.eclipse.maven2Builder org.eclipse.jdt.core.javanature org.maven.ide.eclipse.maven2Nature gs-collections-5.1.0/acceptance-tests/acceptance-tests.iml000066400000000000000000000030221234315411400236140ustar00rootroot00000000000000 gs-collections-5.1.0/acceptance-tests/build.xml000066400000000000000000000026151234315411400215130ustar00rootroot00000000000000 gs-collections-5.1.0/acceptance-tests/ivy.xml000066400000000000000000000050461234315411400212240ustar00rootroot00000000000000 gs-collections-5.1.0/acceptance-tests/pom.xml000066400000000000000000000132031234315411400212020ustar00rootroot00000000000000 gs-collections-parent com.goldmansachs 5.1.0 4.0.0 acceptance-tests Goldman Sachs Collections Acceptance Test Suite true 3.0 com.goldmansachs gs-collections-api ${project.version} test com.goldmansachs gs-collections ${project.version} test com.goldmansachs gs-collections-testutils ${project.version} test com.goldmansachs gs-collections-forkjoin ${project.version} test junit junit test org.slf4j slf4j-api test org.slf4j slf4j-nop test maven-compiler-plugin 1.8 1.8 maven-surefire-plugin maven-source-plugin org.codehaus.mojo sonar-maven-plugin maven-checkstyle-plugin org.codehaus.mojo findbugs-maven-plugin maven-enforcer-plugin enforce 1.8.0 3.0.2 enforce clover com.atlassian.maven.plugins maven-clover2-plugin ${clover.version} ${clover.license} @deprecated true ${user.home}/clover/${project.artifactId} true block gs-collections-5.1.0/acceptance-tests/src/000077500000000000000000000000001234315411400204555ustar00rootroot00000000000000gs-collections-5.1.0/acceptance-tests/src/test/000077500000000000000000000000001234315411400214345ustar00rootroot00000000000000gs-collections-5.1.0/acceptance-tests/src/test/java/000077500000000000000000000000001234315411400223555ustar00rootroot00000000000000gs-collections-5.1.0/acceptance-tests/src/test/java/com/000077500000000000000000000000001234315411400231335ustar00rootroot00000000000000gs-collections-5.1.0/acceptance-tests/src/test/java/com/gs/000077500000000000000000000000001234315411400235445ustar00rootroot00000000000000gs-collections-5.1.0/acceptance-tests/src/test/java/com/gs/collections/000077500000000000000000000000001234315411400260625ustar00rootroot00000000000000gs-collections-5.1.0/acceptance-tests/src/test/java/com/gs/collections/impl/000077500000000000000000000000001234315411400270235ustar00rootroot00000000000000gs-collections-5.1.0/acceptance-tests/src/test/java/com/gs/collections/impl/CollidingInt.java000066400000000000000000000033311234315411400322450ustar00rootroot00000000000000/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl; import java.io.Serializable; public class CollidingInt implements Serializable, Comparable { private static final long serialVersionUID = 1L; private final int value; private final int shift; public CollidingInt(int value, int shift) { this.shift = shift; this.value = value; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || this.getClass() != o.getClass()) { return false; } CollidingInt that = (CollidingInt) o; return this.value == that.value && this.shift == that.shift; } @Override public int hashCode() { return this.value >> this.shift; } public int getValue() { return this.value; } @Override public int compareTo(CollidingInt o) { int result = Integer.valueOf(this.value).compareTo(o.value); if (result != 0) { return result; } return Integer.valueOf(this.shift).compareTo(o.shift); } } gs-collections-5.1.0/acceptance-tests/src/test/java/com/gs/collections/impl/concurrent/000077500000000000000000000000001234315411400312055ustar00rootroot00000000000000MultiReaderUnifiedSetAcceptanceTest.java000066400000000000000000000400101234315411400407700ustar00rootroot00000000000000gs-collections-5.1.0/acceptance-tests/src/test/java/com/gs/collections/impl/concurrent/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.concurrent; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.set.MutableSet; import com.gs.collections.impl.CollidingInt; import com.gs.collections.impl.block.factory.Procedures; import com.gs.collections.impl.factory.Lists; import com.gs.collections.impl.list.mutable.FastList; import com.gs.collections.impl.set.mutable.MultiReaderUnifiedSet; import com.gs.collections.impl.test.SerializeTestHelper; import com.gs.collections.impl.test.Verify; import org.junit.Assert; import org.junit.Test; public class MultiReaderUnifiedSetAcceptanceTest { @Test public void testUnifiedSet() { MultiReaderUnifiedSet set = MultiReaderUnifiedSet.newSet(); int size = 100000; for (int i = 0; i < size; i++) { Assert.assertTrue(set.add(i)); } Verify.assertSize(size, set); for (int i = 0; i < size; i++) { Verify.assertContains(i, set); } for (int i = 0; i < size; i += 2) { Assert.assertTrue(set.remove(i)); } Verify.assertSize(size / 2, set); for (int i = 1; i < size; i += 2) { Verify.assertContains(i, set); } } @Test public void testUnifiedSetClear() { assertUnifiedSetClear(0); assertUnifiedSetClear(1); assertUnifiedSetClear(2); assertUnifiedSetClear(3); } private static void assertUnifiedSetClear(int shift) { MultiReaderUnifiedSet set = MultiReaderUnifiedSet.newSet(); int size = 100000; for (int i = 0; i < size; i++) { Assert.assertTrue(set.add(new CollidingInt(i, shift))); } set.clear(); Verify.assertEmpty(set); for (int i = 0; i < size; i++) { Verify.assertNotContains(new CollidingInt(i, shift), set); } } @Test public void testUnifiedSetForEach() { assertUnifiedSetForEach(0); assertUnifiedSetForEach(1); assertUnifiedSetForEach(2); assertUnifiedSetForEach(3); } private static void assertUnifiedSetForEach(int shift) { MultiReaderUnifiedSet set = MultiReaderUnifiedSet.newSet(); int size = 100000; for (int i = 0; i < size; i++) { Assert.assertTrue(set.add(new CollidingInt(i, shift))); } MutableList keys = FastList.newList(size); set.forEach(Procedures.cast(keys::add)); Verify.assertSize(size, keys); Collections.sort(keys); for (int i = 0; i < size; i++) { Verify.assertItemAtIndex(new CollidingInt(i, shift), i, keys); } } @Test public void testUnifiedSetForEachWith() { assertUnifiedSetForEachWith(0); assertUnifiedSetForEachWith(1); assertUnifiedSetForEachWith(2); assertUnifiedSetForEachWith(3); } private static void assertUnifiedSetForEachWith(int shift) { MultiReaderUnifiedSet set = MultiReaderUnifiedSet.newSet(); int size = 100000; for (int i = 0; i < size; i++) { Assert.assertTrue(set.add(new CollidingInt(i, shift))); } MutableList keys = FastList.newList(size); set.forEachWith((key, s) -> { Assert.assertEquals("foo", s); keys.add(key); }, "foo"); Verify.assertSize(size, keys); Collections.sort(keys); for (int i = 0; i < size; i++) { Verify.assertItemAtIndex(new CollidingInt(i, shift), i, keys); } } @Test public void testUnifiedSetForEachWithIndex() { assertUnifiedSetForEachWithIndex(0); assertUnifiedSetForEachWithIndex(1); assertUnifiedSetForEachWithIndex(2); assertUnifiedSetForEachWithIndex(3); } private static void assertUnifiedSetForEachWithIndex(int shift) { MultiReaderUnifiedSet set = MultiReaderUnifiedSet.newSet(); int size = 100000; for (int i = 0; i < size; i++) { Assert.assertTrue(set.add(new CollidingInt(i, shift))); } MutableList keys = FastList.newList(size); int[] prevIndex = new int[1]; set.forEachWithIndex((key, index) -> { Assert.assertEquals(prevIndex[0], index); prevIndex[0]++; keys.add(key); }); Verify.assertSize(size, keys); Collections.sort(keys); for (int i = 0; i < size; i++) { Verify.assertItemAtIndex(new CollidingInt(i, shift), i, keys); } } @Test public void testUnifiedSetAddAll() { assertUnifiedSetAddAll(0); assertUnifiedSetAddAll(1); assertUnifiedSetAddAll(2); assertUnifiedSetAddAll(3); } private static void assertUnifiedSetAddAll(int shift) { MultiReaderUnifiedSet set = MultiReaderUnifiedSet.newSet(); int size = 100000; for (int i = 0; i < size; i++) { set.add(new CollidingInt(i, shift)); } MultiReaderUnifiedSet newSet = MultiReaderUnifiedSet.newSet(size); newSet.addAll(set); Verify.assertSize(size, newSet); for (int i = 0; i < size; i++) { Verify.assertContains(new CollidingInt(i, shift), newSet); } } @Test public void testUnifiedSetAddAllWithHashSet() { assertUnifiedSetAddAllWithHashSet(0); assertUnifiedSetAddAllWithHashSet(1); assertUnifiedSetAddAllWithHashSet(2); assertUnifiedSetAddAllWithHashSet(3); } private static void assertUnifiedSetAddAllWithHashSet(int shift) { Set set = new HashSet(); int size = 100000; for (int i = 0; i < size; i++) { set.add(new CollidingInt(i, shift)); } MultiReaderUnifiedSet newSet = MultiReaderUnifiedSet.newSet(size); newSet.addAll(set); Verify.assertSize(size, newSet); for (int i = 0; i < size; i++) { Verify.assertContains(new CollidingInt(i, shift), newSet); } MultiReaderUnifiedSet newSet2 = MultiReaderUnifiedSet.newSet(); newSet2.addAll(set); Verify.assertSize(size, newSet2); for (int i = 0; i < size; i++) { Verify.assertContains(new CollidingInt(i, shift), newSet2); } } @Test public void testUnifiedSetReplace() { assertUnifiedSetReplace(0); assertUnifiedSetReplace(1); assertUnifiedSetReplace(2); assertUnifiedSetReplace(3); } private static void assertUnifiedSetReplace(int shift) { MultiReaderUnifiedSet set = MultiReaderUnifiedSet.newSet(); int size = 100000; for (int i = 0; i < size; i++) { set.add(new CollidingInt(i, shift)); } for (int i = 0; i < size; i++) { set.add(new CollidingInt(i, shift)); } Verify.assertSize(size, set); for (int i = 0; i < size; i++) { Verify.assertContains(new CollidingInt(i, shift), set); } } @Test public void testUnifiedSetRetainAllFromList() { runUnifiedSetRetainAllFromList(0); runUnifiedSetRetainAllFromList(1); runUnifiedSetRetainAllFromList(2); runUnifiedSetRetainAllFromList(3); } private static void runUnifiedSetRetainAllFromList(int shift) { MultiReaderUnifiedSet set = MultiReaderUnifiedSet.newSet(); MutableList toRetain = Lists.mutable.of(); int size = 100000; for (int i = 0; i < size; i++) { set.add(new CollidingInt(i, shift)); if (i % 2 == 0) { toRetain.add(new CollidingInt(i, shift)); } } Verify.assertSize(size, set); Assert.assertTrue(set.containsAll(toRetain)); Assert.assertTrue(set.retainAll(toRetain)); Assert.assertTrue(set.containsAll(toRetain)); Assert.assertFalse(set.retainAll(toRetain)); // a second call should not modify the set Verify.assertSize(size / 2, set); for (int i = 0; i < size; i += 2) { Verify.assertContains(new CollidingInt(i, shift), set); } } @Test public void testUnifiedSetRetainAllFromSet() { runUnifiedSetRetainAllFromSet(0); runUnifiedSetRetainAllFromSet(1); runUnifiedSetRetainAllFromSet(2); runUnifiedSetRetainAllFromSet(3); } private static void runUnifiedSetRetainAllFromSet(int shift) { MultiReaderUnifiedSet set = MultiReaderUnifiedSet.newSet(); Set toRetain = new HashSet(); int size = 100000; for (int i = 0; i < size; i++) { set.add(new CollidingInt(i, shift)); if (i % 2 == 0) { toRetain.add(new CollidingInt(i, shift)); } } Verify.assertSize(size, set); Assert.assertTrue(set.containsAll(toRetain)); Assert.assertTrue(set.retainAll(toRetain)); Assert.assertTrue(set.containsAll(toRetain)); Assert.assertFalse(set.retainAll(toRetain)); // a second call should not modify the set Verify.assertSize(size / 2, set); for (int i = 0; i < size; i += 2) { Verify.assertContains(new CollidingInt(i, shift), set); } } @Test public void testUnifiedSetToArray() { runUnifiedSetToArray(0); runUnifiedSetToArray(1); runUnifiedSetToArray(2); runUnifiedSetToArray(3); } private static void runUnifiedSetToArray(int shift) { MultiReaderUnifiedSet set = MultiReaderUnifiedSet.newSet(); int size = 100000; for (int i = 0; i < size; i++) { set.add(new CollidingInt(i, shift)); } Verify.assertSize(size, set); Object[] keys = set.toArray(); Assert.assertEquals(size, keys.length); Arrays.sort(keys); for (int i = 0; i < size; i++) { Verify.assertItemAtIndex(new CollidingInt(i, shift), i, keys); } } @Test public void testUnifiedSetSerialize() { runUnifiedSetSerialize(0); runUnifiedSetSerialize(1); runUnifiedSetSerialize(2); runUnifiedSetSerialize(3); } private static void runUnifiedSetSerialize(int shift) { MultiReaderUnifiedSet set = MultiReaderUnifiedSet.newSet(); int size = 100000; for (int i = 0; i < size; i++) { set.add(new CollidingInt(i, shift)); } set.add(null); set = SerializeTestHelper.serializeDeserialize(set); Verify.assertSize(size + 1, set); for (int i = 0; i < size; i++) { Verify.assertContains(new CollidingInt(i, shift), set); } Verify.assertContains(null, set); } @Test public void testUnifiedSetKeySetToArrayDest() { MutableSet set = MultiReaderUnifiedSet.newSetWith(1, 2, 3, 4); // deliberately to small to force the method to allocate one of the correct size Integer[] dest = new Integer[2]; Integer[] result = set.toArray(dest); Verify.assertSize(4, result); Arrays.sort(result); Assert.assertArrayEquals(new Integer[]{1, 2, 3, 4}, result); } @Test public void testUnifiedSetEqualsAndHashCode() { assertUnifiedSetEqualsAndHashCode(0); assertUnifiedSetEqualsAndHashCode(1); assertUnifiedSetEqualsAndHashCode(2); assertUnifiedSetEqualsAndHashCode(3); } private static void assertUnifiedSetEqualsAndHashCode(int shift) { MutableSet set1 = MultiReaderUnifiedSet.newSet(); Set set2 = new HashSet(); MutableSet set3 = MultiReaderUnifiedSet.newSet(); MutableSet set4 = MultiReaderUnifiedSet.newSet(); int size = 100000; for (int i = 0; i < size; i++) { set1.add(new CollidingInt(i, shift)); set2.add(new CollidingInt(i, shift)); set3.add(new CollidingInt(i, shift)); set4.add(new CollidingInt(size - i - 1, shift)); } Assert.assertEquals(set1, set2); Assert.assertEquals(set1.hashCode(), set2.hashCode()); Verify.assertSetsEqual(set1, set3); Verify.assertEqualsAndHashCode(set1, set3); Verify.assertSetsEqual(set2, set4); Assert.assertEquals(set4, set2); Assert.assertEquals(set2.hashCode(), set4.hashCode()); } @Test public void testUnifiedSetRemoveAll() { runUnifiedSetRemoveAll(0); runUnifiedSetRemoveAll(1); runUnifiedSetRemoveAll(2); runUnifiedSetRemoveAll(3); } private static void runUnifiedSetRemoveAll(int shift) { MultiReaderUnifiedSet set = MultiReaderUnifiedSet.newSet(); List toRemove = new ArrayList(); int size = 100000; for (int i = 0; i < size; i++) { set.add(new CollidingInt(i, shift)); if (i % 2 == 0) { toRemove.add(new CollidingInt(i, shift)); } } Verify.assertSize(size, set); Assert.assertTrue(set.removeAll(toRemove)); Assert.assertFalse(set.removeAll(toRemove)); // a second call should not modify the set Verify.assertSize(size / 2, set); for (int i = 1; i < size; i += 2) { Verify.assertContains(new CollidingInt(i, shift), set); } } @Test public void testUnifiedSetPutDoesNotReplace() { this.assertUnifiedSetPutDoesNotReplace(0); this.assertUnifiedSetPutDoesNotReplace(1); this.assertUnifiedSetPutDoesNotReplace(2); this.assertUnifiedSetPutDoesNotReplace(3); this.assertUnifiedSetPutDoesNotReplace(4); } private void assertUnifiedSetPutDoesNotReplace(int shift) { MultiReaderUnifiedSet set = MultiReaderUnifiedSet.newSet(); for (int i = 0; i < 1000; i++) { Assert.assertTrue(set.add(new CollidingIntWithFlag(i, shift, false))); } Assert.assertEquals(1000, set.size()); for (int i = 0; i < 1000; i++) { Assert.assertFalse(set.add(new CollidingIntWithFlag(i, shift, true))); } Assert.assertEquals(1000, set.size()); set.withReadLockAndDelegate(delegate -> { for (CollidingIntWithFlag ciwf : delegate) { Assert.assertFalse(ciwf.isFlag()); } }); } private static final class CollidingIntWithFlag extends CollidingInt { private static final long serialVersionUID = 1L; private final boolean flag; private CollidingIntWithFlag(int value, int shift, boolean flag) { super(value, shift); this.flag = flag; } public boolean isFlag() { return this.flag; } } } gs-collections-5.1.0/acceptance-tests/src/test/java/com/gs/collections/impl/forkjoin/000077500000000000000000000000001234315411400306445ustar00rootroot00000000000000FJIterateAcceptanceTest.java000066400000000000000000000674211234315411400360660ustar00rootroot00000000000000gs-collections-5.1.0/acceptance-tests/src/test/java/com/gs/collections/impl/forkjoin/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.forkjoin; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.atomic.AtomicInteger; import com.gs.collections.api.RichIterable; import com.gs.collections.api.bag.Bag; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.list.ImmutableList; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.map.MapIterable; import com.gs.collections.api.map.MutableMap; import com.gs.collections.api.set.MutableSet; import com.gs.collections.impl.bag.mutable.HashBag; import com.gs.collections.impl.block.factory.Functions; import com.gs.collections.impl.block.factory.HashingStrategies; import com.gs.collections.impl.block.factory.Predicates; import com.gs.collections.impl.block.factory.Procedures; import com.gs.collections.impl.factory.Lists; import com.gs.collections.impl.list.Interval; import com.gs.collections.impl.list.mutable.ArrayListAdapter; import com.gs.collections.impl.list.mutable.CompositeFastList; import com.gs.collections.impl.list.mutable.FastList; import com.gs.collections.impl.list.mutable.ListAdapter; import com.gs.collections.impl.map.mutable.UnifiedMap; import com.gs.collections.impl.parallel.AbstractProcedureCombiner; import com.gs.collections.impl.parallel.ParallelIterate; import com.gs.collections.impl.parallel.PassThruCombiner; import com.gs.collections.impl.parallel.PassThruObjectIntProcedureFactory; import com.gs.collections.impl.parallel.PassThruProcedureFactory; import com.gs.collections.impl.parallel.ProcedureFactory; import com.gs.collections.impl.set.mutable.MultiReaderUnifiedSet; import com.gs.collections.impl.set.mutable.UnifiedSet; import com.gs.collections.impl.set.strategy.mutable.UnifiedSetWithHashingStrategy; import com.gs.collections.impl.test.Verify; import com.gs.collections.impl.utility.ArrayIterate; import com.gs.collections.impl.utility.LazyIterate; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; public class FJIterateAcceptanceTest { private static final Procedure EXCEPTION_PROCEDURE = value -> { throw new RuntimeException("Thread death on its way!"); }; private static final ObjectIntProcedure EXCEPTION_OBJECT_INT_PROCEDURE = (object, index) -> { throw new RuntimeException("Thread death on its way!"); }; private static final Function> INT_TO_TWO_STRINGS = integer -> Lists.fixedSize.of(integer.toString(), integer.toString()); private static final Function EVEN_OR_ODD = value -> value % 2 == 0 ? "Even" : "Odd"; private int count; private final MutableSet threadNames = MultiReaderUnifiedSet.newSet(); private ImmutableList> iterables; private final ForkJoinPool executor = new ForkJoinPool(2); @Before public void setUp() { Interval interval = Interval.oneTo(20000); this.iterables = Lists.immutable.of( interval.toList(), interval.toList().asUnmodifiable(), interval.toList().asSynchronized(), interval.toList().toImmutable(), interval.toSet(), interval.toSet().asUnmodifiable(), interval.toSet().asSynchronized(), interval.toSet().toImmutable(), interval.toBag(), interval.toBag().asUnmodifiable(), interval.toBag().asSynchronized(), interval.toBag().toImmutable(), interval.toSortedSet(), interval.toSortedSet().asUnmodifiable(), interval.toSortedSet().asSynchronized(), interval.toSortedSet().toImmutable(), interval.toMap(Functions.getPassThru(), Functions.getPassThru()), interval.toMap(Functions.getPassThru(), Functions.getPassThru()).asUnmodifiable(), interval.toMap(Functions.getPassThru(), Functions.getPassThru()).asSynchronized(), interval.toMap(Functions.getPassThru(), Functions.getPassThru()).toImmutable(), ArrayListAdapter.newList().withAll(interval), ArrayListAdapter.newList().withAll(interval).asUnmodifiable(), ArrayListAdapter.newList().withAll(interval).asSynchronized(), new CompositeFastList().withAll(interval.toList()), new CompositeFastList().withAll(interval.toList()).asUnmodifiable(), new CompositeFastList().withAll(interval.toList()).asSynchronized(), new CompositeFastList().withAll(interval.toList()).toImmutable(), ListAdapter.adapt(new LinkedList()).withAll(interval), ListAdapter.adapt(new LinkedList()).withAll(interval).asUnmodifiable(), ListAdapter.adapt(new LinkedList()).withAll(interval).asSynchronized(), UnifiedSetWithHashingStrategy.newSet(HashingStrategies.defaultStrategy()).withAll(interval), UnifiedSetWithHashingStrategy.newSet(HashingStrategies.defaultStrategy()).withAll(interval).asUnmodifiable(), UnifiedSetWithHashingStrategy.newSet(HashingStrategies.defaultStrategy()).withAll(interval).asSynchronized(), UnifiedSetWithHashingStrategy.newSet(HashingStrategies.defaultStrategy()).withAll(interval).toImmutable()); } @After public void tearDown() { this.executor.shutdown(); } @Test public void testOneLevelCall() { new RecursiveProcedure().value(1); synchronized (this) { Assert.assertEquals("all iterations completed", 20000, this.count); } } @Test public void testNestedCall() { new RecursiveProcedure().value(2); synchronized (this) { Assert.assertEquals("all iterations completed", 419980, this.count); } Assert.assertTrue("uses multiple threads", this.threadNames.size() > 1); } @Test public void testForEachUsingSet() { //Tests the default batch size calculations IntegerSum sum = new IntegerSum(0); MutableSet set = Interval.toSet(1, 10000); FJIterate.forEach(set, new SumProcedure(sum), new SumCombiner(sum)); Assert.assertEquals(50005000, sum.getSum()); //Testing batch size 1 IntegerSum sum2 = new IntegerSum(0); UnifiedSet set2 = UnifiedSet.newSet(Interval.oneTo(100)); FJIterate.forEach(set2, new SumProcedure(sum2), new SumCombiner(sum2), 1, set2.getBatchCount(set2.size())); Assert.assertEquals(5050, sum2.getSum()); //Testing an uneven batch size IntegerSum sum3 = new IntegerSum(0); UnifiedSet set3 = UnifiedSet.newSet(Interval.oneTo(100)); FJIterate.forEach(set3, new SumProcedure(sum3), new SumCombiner(sum3), 1, set3.getBatchCount(13)); Assert.assertEquals(5050, sum3.getSum()); //Testing divideByZero exception by passing 1 as batchSize IntegerSum sum4 = new IntegerSum(0); UnifiedSet set4 = UnifiedSet.newSet(Interval.oneTo(100)); FJIterate.forEach(set4, new SumProcedure(sum4), new SumCombiner(sum4), 1); Assert.assertEquals(5050, sum4.getSum()); } @Test public void testForEachUsingMap() { //Test the default batch size calculations IntegerSum sum1 = new IntegerSum(0); MutableMap map1 = Interval.fromTo(1, 10000).toMap(String::valueOf, Functions.getIntegerPassThru()); FJIterate.forEach(map1, new SumProcedure(sum1), new SumCombiner(sum1)); Assert.assertEquals(50005000, sum1.getSum()); //Testing batch size 1 IntegerSum sum2 = new IntegerSum(0); UnifiedMap map2 = (UnifiedMap) Interval.fromTo(1, 100).toMap(String::valueOf, Functions.getIntegerPassThru()); FJIterate.forEach(map2, new SumProcedure(sum2), new SumCombiner(sum2), 1, map2.getBatchCount(map2.size())); Assert.assertEquals(5050, sum2.getSum()); //Testing an uneven batch size IntegerSum sum3 = new IntegerSum(0); UnifiedMap set3 = (UnifiedMap) Interval.fromTo(1, 100).toMap(String::valueOf, Functions.getIntegerPassThru()); FJIterate.forEach(set3, new SumProcedure(sum3), new SumCombiner(sum3), 1, set3.getBatchCount(13)); Assert.assertEquals(5050, sum3.getSum()); } @Test public void testForEach() { IntegerSum sum1 = new IntegerSum(0); List list1 = FJIterateAcceptanceTest.createIntegerList(16); FJIterate.forEach(list1, new SumProcedure(sum1), new SumCombiner(sum1), 1, list1.size() / 2); Assert.assertEquals(16, sum1.getSum()); IntegerSum sum2 = new IntegerSum(0); List list2 = FJIterateAcceptanceTest.createIntegerList(7); FJIterate.forEach(list2, new SumProcedure(sum2), new SumCombiner(sum2)); Assert.assertEquals(7, sum2.getSum()); IntegerSum sum3 = new IntegerSum(0); List list3 = FJIterateAcceptanceTest.createIntegerList(15); FJIterate.forEach(list3, new SumProcedure(sum3), new SumCombiner(sum3), 1, list3.size() / 2); Assert.assertEquals(15, sum3.getSum()); IntegerSum sum4 = new IntegerSum(0); List list4 = FJIterateAcceptanceTest.createIntegerList(35); FJIterate.forEach(list4, new SumProcedure(sum4), new SumCombiner(sum4)); Assert.assertEquals(35, sum4.getSum()); IntegerSum sum5 = new IntegerSum(0); MutableList list5 = FastList.newList(list4); FJIterate.forEach(list5, new SumProcedure(sum5), new SumCombiner(sum5)); Assert.assertEquals(35, sum5.getSum()); IntegerSum sum6 = new IntegerSum(0); List list6 = FJIterateAcceptanceTest.createIntegerList(40); FJIterate.forEach(list6, new SumProcedure(sum6), new SumCombiner(sum6), 1, list6.size() / 2); Assert.assertEquals(40, sum6.getSum()); IntegerSum sum7 = new IntegerSum(0); MutableList list7 = FastList.newList(list6); FJIterate.forEach(list7, new SumProcedure(sum7), new SumCombiner(sum7), 1, list6.size() / 2); Assert.assertEquals(40, sum7.getSum()); } @Test public void testForEachImmutableList() { IntegerSum sum1 = new IntegerSum(0); ImmutableList list1 = Lists.immutable.ofAll(FJIterateAcceptanceTest.createIntegerList(16)); FJIterate.forEach(list1, new SumProcedure(sum1), new SumCombiner(sum1), 1, list1.size() / 2); Assert.assertEquals(16, sum1.getSum()); IntegerSum sum2 = new IntegerSum(0); ImmutableList list2 = Lists.immutable.ofAll(FJIterateAcceptanceTest.createIntegerList(7)); FJIterate.forEach(list2, new SumProcedure(sum2), new SumCombiner(sum2)); Assert.assertEquals(7, sum2.getSum()); IntegerSum sum3 = new IntegerSum(0); ImmutableList list3 = Lists.immutable.ofAll(FJIterateAcceptanceTest.createIntegerList(15)); FJIterate.forEach(list3, new SumProcedure(sum3), new SumCombiner(sum3), 1, list3.size() / 2); Assert.assertEquals(15, sum3.getSum()); IntegerSum sum4 = new IntegerSum(0); ImmutableList list4 = Lists.immutable.ofAll(FJIterateAcceptanceTest.createIntegerList(35)); FJIterate.forEach(list4, new SumProcedure(sum4), new SumCombiner(sum4)); Assert.assertEquals(35, sum4.getSum()); IntegerSum sum5 = new IntegerSum(0); ImmutableList list5 = FastList.newList(list4).toImmutable(); FJIterate.forEach(list5, new SumProcedure(sum5), new SumCombiner(sum5)); Assert.assertEquals(35, sum5.getSum()); IntegerSum sum6 = new IntegerSum(0); ImmutableList list6 = Lists.immutable.ofAll(FJIterateAcceptanceTest.createIntegerList(40)); FJIterate.forEach(list6, new SumProcedure(sum6), new SumCombiner(sum6), 1, list6.size() / 2); Assert.assertEquals(40, sum6.getSum()); IntegerSum sum7 = new IntegerSum(0); ImmutableList list7 = FastList.newList(list6).toImmutable(); FJIterate.forEach(list7, new SumProcedure(sum7), new SumCombiner(sum7), 1, list6.size() / 2); Assert.assertEquals(40, sum7.getSum()); } @Test public void testForEachWithException() { Verify.assertThrows(RuntimeException.class, () -> FJIterate.forEach( FJIterateAcceptanceTest.createIntegerList(5), new PassThruProcedureFactory>(EXCEPTION_PROCEDURE), new PassThruCombiner>(), 1, 5)); } @Test public void testForEachWithIndexToArrayUsingFastListSerialPath() { Integer[] array = new Integer[200]; FastList list = (FastList) Interval.oneTo(200).toList(); Assert.assertTrue(ArrayIterate.allSatisfy(array, Predicates.isNull())); FJIterate.forEachWithIndex(list, (each, index) -> { array[index] = each; }); Assert.assertArrayEquals(array, list.toArray(new Integer[]{})); } @Test public void testForEachWithIndexToArrayUsingFastList() { Integer[] array = new Integer[200]; FastList list = (FastList) Interval.oneTo(200).toList(); Assert.assertTrue(ArrayIterate.allSatisfy(array, Predicates.isNull())); FJIterate.forEachWithIndex(list, (each, index) -> { array[index] = each; }, 10, 10); Assert.assertArrayEquals(array, list.toArray(new Integer[]{})); } @Test public void testForEachWithIndexToArrayUsingImmutableList() { Integer[] array = new Integer[200]; ImmutableList list = Interval.oneTo(200).toList().toImmutable(); Assert.assertTrue(ArrayIterate.allSatisfy(array, Predicates.isNull())); FJIterate.forEachWithIndex(list, (each, index) -> { array[index] = each; }, 10, 10); Assert.assertArrayEquals(array, list.toArray(new Integer[]{})); } @Test public void testForEachWithIndexToArrayUsingArrayList() { Integer[] array = new Integer[200]; MutableList list = FastList.newList(Interval.oneTo(200)); Assert.assertTrue(ArrayIterate.allSatisfy(array, Predicates.isNull())); FJIterate.forEachWithIndex(list, (each, index) -> { array[index] = each; }, 10, 10); Assert.assertArrayEquals(array, list.toArray(new Integer[]{})); } @Test public void testForEachWithIndexToArrayUsingFixedArrayList() { Integer[] array = new Integer[10]; List list = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); Assert.assertTrue(ArrayIterate.allSatisfy(array, Predicates.isNull())); FJIterate.forEachWithIndex(list, (each, index) -> { array[index] = each; }, 1, 2); Assert.assertArrayEquals(array, list.toArray(new Integer[list.size()])); } @Test public void testForEachWithIndexException() { Verify.assertThrows(RuntimeException.class, () -> FJIterate.forEachWithIndex( FJIterateAcceptanceTest.createIntegerList(5), new PassThruObjectIntProcedureFactory>(EXCEPTION_OBJECT_INT_PROCEDURE), new PassThruCombiner>(), 1, 5)); } @Test public void select() { this.iterables.forEach(Procedures.cast(this::basicSelect)); } private void basicSelect(RichIterable iterable) { Collection actual1 = FJIterate.select(iterable, Predicates.greaterThan(10000)); Collection actual2 = FJIterate.select(iterable, Predicates.greaterThan(10000), HashBag.newBag(), 3, this.executor, true); Collection actual3 = FJIterate.select(iterable, Predicates.greaterThan(10000), true); RichIterable expected = iterable.select(Predicates.greaterThan(10000)); Assert.assertEquals(expected.getClass().getSimpleName() + '/' + actual1.getClass().getSimpleName(), expected, actual1); Assert.assertEquals(expected.getClass().getSimpleName() + '/' + actual2.getClass().getSimpleName(), expected.toBag(), actual2); Assert.assertEquals(expected.getClass().getSimpleName() + '/' + actual3.getClass().getSimpleName(), expected.toBag(), HashBag.newBag(actual3)); } @Test public void selectSortedSet() { RichIterable iterable = Interval.oneTo(20000).toSortedSet(); Collection actual1 = FJIterate.select(iterable, Predicates.greaterThan(10000)); Collection actual2 = FJIterate.select(iterable, Predicates.greaterThan(10000), true); RichIterable expected = iterable.select(Predicates.greaterThan(10000)); Assert.assertSame(expected.getClass(), actual1.getClass()); Assert.assertSame(expected.getClass(), actual2.getClass()); Assert.assertEquals(expected.getClass().getSimpleName() + '/' + actual1.getClass().getSimpleName(), expected, actual1); Assert.assertEquals(expected.getClass().getSimpleName() + '/' + actual2.getClass().getSimpleName(), expected, actual2); } @Test public void count() { this.iterables.forEach(Procedures.cast(this::basicCount)); } private void basicCount(RichIterable listIterable) { int actual1 = FJIterate.count(listIterable, Predicates.greaterThan(10000)); int actual2 = FJIterate.count(listIterable, Predicates.greaterThan(10000), 11, this.executor); Assert.assertEquals(10000, actual1); Assert.assertEquals(10000, actual2); } @Test public void reject() { this.iterables.forEach(Procedures.cast(this::basicReject)); } private void basicReject(RichIterable iterable) { Collection actual1 = FJIterate.reject(iterable, Predicates.greaterThan(10000)); Collection actual2 = FJIterate.reject(iterable, Predicates.greaterThan(10000), HashBag.newBag(), 3, this.executor, true); Collection actual3 = FJIterate.reject(iterable, Predicates.greaterThan(10000), true); RichIterable expected = iterable.reject(Predicates.greaterThan(10000)); Assert.assertEquals(expected.getClass().getSimpleName() + '/' + actual1.getClass().getSimpleName(), expected, actual1); Assert.assertEquals(expected.getClass().getSimpleName() + '/' + actual2.getClass().getSimpleName(), expected.toBag(), actual2); Assert.assertEquals(expected.getClass().getSimpleName() + '/' + actual3.getClass().getSimpleName(), expected.toBag(), HashBag.newBag(actual3)); } @Test public void collect() { this.iterables.forEach(Procedures.cast(this::basicCollect)); } private void basicCollect(RichIterable iterable) { Collection actual1 = FJIterate.collect(iterable, String::valueOf); Collection actual2 = FJIterate.collect(iterable, String::valueOf, HashBag.newBag(), 3, this.executor, false); Collection actual3 = FJIterate.collect(iterable, String::valueOf, true); RichIterable expected = iterable.collect(String::valueOf); Verify.assertSize(20000, actual1); Verify.assertContains(String.valueOf(20000), actual1); Assert.assertEquals(expected.getClass().getSimpleName() + '/' + actual1.getClass().getSimpleName(), expected, actual1); Assert.assertEquals(expected.getClass().getSimpleName() + '/' + actual2.getClass().getSimpleName(), expected.toBag(), actual2); Assert.assertEquals(expected.getClass().getSimpleName() + '/' + actual3.getClass().getSimpleName(), expected.toBag(), HashBag.newBag(actual3)); } @Test public void collectIf() { this.iterables.forEach(Procedures.cast(this::basicCollectIf)); } private void basicCollectIf(RichIterable collection) { Predicate greaterThan = Predicates.greaterThan(10000); Collection actual1 = FJIterate.collectIf(collection, greaterThan, String::valueOf); Collection actual2 = FJIterate.collectIf(collection, greaterThan, String::valueOf, HashBag.newBag(), 3, this.executor, true); Collection actual3 = FJIterate.collectIf(collection, greaterThan, String::valueOf, HashBag.newBag(), 3, this.executor, true); Bag expected = collection.collectIf(greaterThan, String::valueOf).toBag(); Verify.assertSize(10000, actual1); Verify.assertNotContains(String.valueOf(9000), actual1); Verify.assertNotContains(String.valueOf(21000), actual1); Verify.assertContains(String.valueOf(15976), actual1); Assert.assertEquals(expected.getClass().getSimpleName() + '/' + actual1.getClass().getSimpleName(), expected, HashBag.newBag(actual1)); Assert.assertEquals(expected.getClass().getSimpleName() + '/' + actual2.getClass().getSimpleName(), expected, actual2); Assert.assertEquals(expected.getClass().getSimpleName() + '/' + actual3.getClass().getSimpleName(), expected, actual3); } @Test public void flatCollect() { this.iterables.forEach(Procedures.cast(this::basicFlatCollect)); } private void basicFlatCollect(RichIterable iterable) { Collection actual1 = FJIterate.flatCollect(iterable, INT_TO_TWO_STRINGS); Collection actual2 = FJIterate.flatCollect(iterable, INT_TO_TWO_STRINGS, HashBag.newBag(), 3, this.executor, false); Collection actual3 = FJIterate.flatCollect(iterable, INT_TO_TWO_STRINGS, true); RichIterable expected1 = iterable.flatCollect(INT_TO_TWO_STRINGS); RichIterable expected2 = iterable.flatCollect(INT_TO_TWO_STRINGS, HashBag.newBag()); Verify.assertContains(String.valueOf(20000), actual1); Assert.assertEquals(expected1.getClass().getSimpleName() + '/' + actual1.getClass().getSimpleName(), expected1, actual1); Assert.assertEquals(expected2.getClass().getSimpleName() + '/' + actual2.getClass().getSimpleName(), expected2, actual2); Assert.assertEquals(expected1.getClass().getSimpleName() + '/' + actual3.getClass().getSimpleName(), expected1.toBag(), HashBag.newBag(actual3)); } @Test public void aggregateInPlaceBy() { Procedure2 countAggregator = (aggregate, value) -> { aggregate.incrementAndGet(); }; List list = Interval.oneTo(20000); MutableMap aggregation = FJIterate.aggregateInPlaceBy(list, EVEN_OR_ODD, AtomicInteger::new, countAggregator); Assert.assertEquals(10000, aggregation.get("Even").intValue()); Assert.assertEquals(10000, aggregation.get("Odd").intValue()); FJIterate.aggregateInPlaceBy(list, EVEN_OR_ODD, AtomicInteger::new, countAggregator, aggregation); Assert.assertEquals(20000, aggregation.get("Even").intValue()); Assert.assertEquals(20000, aggregation.get("Odd").intValue()); } @Test public void aggregateInPlaceByWithBatchSize() { MutableList list = LazyIterate.adapt(Collections.nCopies(1000, 1)) .concatenate(Collections.nCopies(2000, 2)) .concatenate(Collections.nCopies(3000, 3)) .toList(); Collections.shuffle(list); MapIterable aggregation = FJIterate.aggregateInPlaceBy(list, String::valueOf, AtomicInteger::new, AtomicInteger::addAndGet, 100); Assert.assertEquals(1000, aggregation.get("1").intValue()); Assert.assertEquals(4000, aggregation.get("2").intValue()); Assert.assertEquals(9000, aggregation.get("3").intValue()); } private static List createIntegerList(int size) { return Collections.nCopies(size, Integer.valueOf(1)); } private class RecursiveProcedure implements Procedure { private static final long serialVersionUID = 1L; private final ForkJoinPool executorService = new ForkJoinPool(ParallelIterate.getDefaultMaxThreadPoolSize()); @Override public void value(Integer level) { if (level > 0) { FJIterateAcceptanceTest.this.threadNames.add(Thread.currentThread().getName()); this.executeFJIterate(level - 1, this.executorService); } else { this.simulateWork(); } } private void simulateWork() { synchronized (FJIterateAcceptanceTest.this) { FJIterateAcceptanceTest.this.count++; } } private void executeFJIterate(int level, ForkJoinPool executorService) { MutableList items = Lists.mutable.of(); for (int i = 0; i < 20000; i++) { items.add(i % 1000 == 0 ? level : 0); } FJIterate.forEach(items, new RecursiveProcedure(), executorService); } } public static final class IntegerSum { private int sum = 0; public IntegerSum(int newSum) { this.sum = newSum; } public IntegerSum add(int value) { this.sum += value; return this; } public int getSum() { return this.sum; } } public static final class SumProcedure implements Procedure, Function2, ProcedureFactory { private static final long serialVersionUID = 1L; private final IntegerSum sum; public SumProcedure(IntegerSum newSum) { this.sum = newSum; } @Override public SumProcedure create() { return new SumProcedure(new IntegerSum(0)); } @Override public IntegerSum value(IntegerSum s1, Integer s2) { return s1.add(s2); } @Override public void value(Integer object) { this.sum.add(object); } public int getSum() { return this.sum.getSum(); } } public static final class SumCombiner extends AbstractProcedureCombiner { private static final long serialVersionUID = 1L; private final IntegerSum sum; public SumCombiner(IntegerSum initialSum) { super(true); this.sum = initialSum; } @Override public void combineOne(SumProcedure sumProcedure) { this.sum.add(sumProcedure.getSum()); } } } gs-collections-5.1.0/acceptance-tests/src/test/java/com/gs/collections/impl/list/000077500000000000000000000000001234315411400277765ustar00rootroot00000000000000gs-collections-5.1.0/acceptance-tests/src/test/java/com/gs/collections/impl/list/mutable/000077500000000000000000000000001234315411400314275ustar00rootroot00000000000000MultiReaderFastListAcceptanceTest.java000066400000000000000000000023341234315411400407130ustar00rootroot00000000000000gs-collections-5.1.0/acceptance-tests/src/test/java/com/gs/collections/impl/list/mutable/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.mutable; import com.gs.collections.api.list.MutableList; import com.gs.collections.impl.list.Interval; import com.gs.collections.impl.test.Verify; import org.junit.Test; /** * JUnit test for {@link MultiReaderFastList}. */ public class MultiReaderFastListAcceptanceTest { @Test public void sortThisOnListWithMoreThan9Elements() { MutableList integers = MultiReaderFastList.newList(Interval.toReverseList(1, 10000)); Verify.assertStartsWith(integers.sortThis(), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); Verify.assertEndsWith(integers, 9997, 9998, 9999, 10000); } } gs-collections-5.1.0/acceptance-tests/src/test/java/com/gs/collections/impl/map/000077500000000000000000000000001234315411400276005ustar00rootroot00000000000000gs-collections-5.1.0/acceptance-tests/src/test/java/com/gs/collections/impl/map/mutable/000077500000000000000000000000001234315411400312315ustar00rootroot00000000000000ConcurrentHashMapAcceptanceTest.java000066400000000000000000000230401234315411400402070ustar00rootroot00000000000000gs-collections-5.1.0/acceptance-tests/src/test/java/com/gs/collections/impl/map/mutable/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.map.mutable; import java.util.Collections; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import com.gs.collections.api.bag.MutableBag; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.Function3; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.map.MutableMap; import com.gs.collections.impl.bag.mutable.HashBag; import com.gs.collections.impl.block.factory.Functions; import com.gs.collections.impl.factory.Maps; import com.gs.collections.impl.list.Interval; import com.gs.collections.impl.list.mutable.FastList; import com.gs.collections.impl.parallel.ParallelIterate; import com.gs.collections.impl.test.Verify; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; /** * JUnit test for {@link ConcurrentHashMap}. */ public class ConcurrentHashMapAcceptanceTest { private static final MutableMap> BAG_MUTABLE_MAP = Interval.oneTo(1000).groupBy(new Function() { public Integer valueOf(Integer each) { return each % 100; } }).toMap(HashBag::new); private ExecutorService executor; @Before public void setUp() { this.executor = Executors.newFixedThreadPool(20); } @After public void tearDown() { this.executor.shutdown(); } @Test public void parallelGroupByIntoConcurrentHashMap() { MutableMap> actual = ConcurrentHashMap.newMap(); ParallelIterate.forEach( Interval.oneTo(1000000), each -> { actual.getIfAbsentPut(each % 100000, () -> HashBag.newBag().asSynchronized()).add(each); }, 10, this.executor); Verify.assertEqualsAndHashCode(Interval.oneTo(1000000).groupBy(each -> each % 100000).toMap(HashBag::new), actual); } @Test public void parallelForEachValue() { ConcurrentHashMap source = ConcurrentHashMap.newMap(Interval.oneTo(1000).toMap(Functions.getIntegerPassThru(), Functions.getIntegerPassThru())); MutableMap> actual = ConcurrentHashMap.newMap(); Procedure procedure = each -> { actual.getIfAbsentPut(each % 100, () -> HashBag.newBag().asSynchronized()).add(each); }; source.parallelForEachValue(FastList.newList(Collections.nCopies(5, procedure)), this.executor); Verify.assertEqualsAndHashCode(BAG_MUTABLE_MAP, actual); } @Test public void parallelForEachEntry() { ConcurrentHashMap source = ConcurrentHashMap.newMap(Interval.oneTo(1000).toMap(Functions.getIntegerPassThru(), Functions.getIntegerPassThru())); MutableMap> actual = ConcurrentHashMap.newMap(); Procedure2 procedure2 = (key, value) -> { actual.getIfAbsentPut(value % 100, () -> HashBag.newBag().asSynchronized()).add(value); }; source.parallelForEachKeyValue(FastList.newList(Collections.nCopies(5, procedure2)), this.executor); Verify.assertEqualsAndHashCode(BAG_MUTABLE_MAP, actual); } @Test public void putAllInParallelSmallMap() { ConcurrentHashMap source = ConcurrentHashMap.newMap(Interval.oneTo(1000).toMap(Functions.getIntegerPassThru(), Functions.getIntegerPassThru())); ConcurrentHashMap target = ConcurrentHashMap.newMap(); target.putAllInParallel(source, 10, this.executor); Verify.assertEqualsAndHashCode(source, target); } @Test public void putAllInParallelLargeMap() { ConcurrentHashMap source = ConcurrentHashMap.newMap(Interval.oneTo(60000).toMap(Functions.getIntegerPassThru(), Functions.getIntegerPassThru())); ConcurrentHashMap target = ConcurrentHashMap.newMap(); target.putAllInParallel(source, 10, this.executor); Verify.assertEqualsAndHashCode(source, target); } @Test public void concurrentPutGetPutAllRemoveContainsKeyContainsValueGetIfAbsentPutTest() { ConcurrentHashMap map1 = ConcurrentHashMap.newMap(); ConcurrentHashMap map2 = ConcurrentHashMap.newMap(); ParallelIterate.forEach(Interval.oneTo(1000), each -> { map1.put(each, each); Assert.assertEquals(each, map1.get(each)); map2.putAll(Maps.mutable.of(each, each)); map1.remove(each); map1.putAll(Maps.mutable.of(each, each)); Assert.assertEquals(each, map2.get(each)); map2.remove(each); Assert.assertNull(map2.get(each)); Assert.assertFalse(map2.containsValue(each)); Assert.assertFalse(map2.containsKey(each)); Assert.assertEquals(each, map2.getIfAbsentPut(each, Functions.getIntegerPassThru())); Assert.assertTrue(map2.containsValue(each)); Assert.assertTrue(map2.containsKey(each)); Assert.assertEquals(each, map2.getIfAbsentPut(each, Functions.getIntegerPassThru())); map2.remove(each); Assert.assertEquals(each, map2.getIfAbsentPutWith(each, Functions.getIntegerPassThru(), each)); Assert.assertEquals(each, map2.getIfAbsentPutWith(each, Functions.getIntegerPassThru(), each)); Assert.assertEquals(each, map2.getIfAbsentPut(each, Functions.getIntegerPassThru())); }, 10, this.executor); Verify.assertEqualsAndHashCode(map1, map2); } @Test public void concurrentPutIfAbsentGetIfPresentPutTest() { ConcurrentHashMap map1 = ConcurrentHashMap.newMap(); ConcurrentHashMap map2 = ConcurrentHashMap.newMap(); ParallelIterate.forEach(Interval.oneTo(1000), each -> { map1.put(each, each); map1.put(each, each); Assert.assertEquals(each, map1.get(each)); map2.putAll(Maps.mutable.of(each, each)); map2.putAll(Maps.mutable.of(each, each)); map1.remove(each); Assert.assertNull(map1.putIfAbsentGetIfPresent(each, new KeyTransformer(), new ValueFactory(), null, null)); Assert.assertEquals(each, map1.putIfAbsentGetIfPresent(each, new KeyTransformer(), new ValueFactory(), null, null)); }, 10, this.executor); Assert.assertEquals(map1, map2); } @Test public void concurrentClear() { ConcurrentHashMap map = ConcurrentHashMap.newMap(); ParallelIterate.forEach(Interval.oneTo(1000), each -> { for (int i = 0; i < each; i++) { map.put(each + i * 1000, each); } map.clear(); for (int i = 0; i < 100; i++) { map.put(each + i * 1000, each); } map.clear(); }, 10, this.executor); Verify.assertEmpty(map); } @Test public void concurrentRemoveAndPutIfAbsent() { ConcurrentHashMap map1 = ConcurrentHashMap.newMap(); ParallelIterate.forEach(Interval.oneTo(1000), each -> { Assert.assertNull(map1.put(each, each)); map1.remove(each); Assert.assertNull(map1.get(each)); Assert.assertEquals(each, map1.getIfAbsentPut(each, Functions.getIntegerPassThru())); map1.remove(each); Assert.assertNull(map1.get(each)); Assert.assertEquals(each, map1.getIfAbsentPutWith(each, Functions.getIntegerPassThru(), each)); map1.remove(each); Assert.assertNull(map1.get(each)); for (int i = 0; i < each; i++) { Assert.assertNull(map1.putIfAbsent(each + i * 1000, each)); } for (int i = 0; i < each; i++) { Assert.assertEquals(each, map1.putIfAbsent(each + i * 1000, each)); } for (int i = 0; i < each; i++) { Assert.assertEquals(each, map1.remove(each + i * 1000)); } }, 10, this.executor); } private static class KeyTransformer implements Function2 { private static final long serialVersionUID = 1L; @Override public Integer value(Integer key, Integer value) { return key; } } private static class ValueFactory implements Function3 { private static final long serialVersionUID = 1L; @Override public Integer value(Object argument1, Object argument2, Integer key) { return key; } } } ConcurrentHashMapUnsafeAcceptanceTest.java000066400000000000000000000233171234315411400413600ustar00rootroot00000000000000gs-collections-5.1.0/acceptance-tests/src/test/java/com/gs/collections/impl/map/mutable/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.map.mutable; import java.util.Collections; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import com.gs.collections.api.bag.MutableBag; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.Function3; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.map.MutableMap; import com.gs.collections.impl.bag.mutable.HashBag; import com.gs.collections.impl.block.factory.Functions; import com.gs.collections.impl.factory.Maps; import com.gs.collections.impl.list.Interval; import com.gs.collections.impl.list.mutable.FastList; import com.gs.collections.impl.parallel.ParallelIterate; import com.gs.collections.impl.test.Verify; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; /** * JUnit test for {@link ConcurrentHashMapUnsafe}. */ public class ConcurrentHashMapUnsafeAcceptanceTest { private static final MutableMap> BAG_MUTABLE_MAP = Interval.oneTo(1000).groupBy(new Function() { public Integer valueOf(Integer each) { return each % 100; } }).toMap(HashBag::new); private ExecutorService executor; @Before public void setUp() { this.executor = Executors.newFixedThreadPool(20); } @After public void tearDown() { this.executor.shutdown(); } @Test public void parallelGroupByIntoConcurrentHashMap() { MutableMap> actual = ConcurrentHashMapUnsafe.newMap(); ParallelIterate.forEach( Interval.oneTo(1000000), each -> { actual.getIfAbsentPut(each % 100000, () -> HashBag.newBag().asSynchronized()).add(each); }, 10, this.executor); Verify.assertEqualsAndHashCode(Interval.oneTo(1000000).groupBy(each -> each % 100000).toMap(HashBag::new), actual); } @Test public void parallelForEachValue() { ConcurrentHashMapUnsafe source = ConcurrentHashMapUnsafe.newMap(Interval.oneTo(1000).toMap(Functions.getIntegerPassThru(), Functions.getIntegerPassThru())); MutableMap> actual = ConcurrentHashMapUnsafe.newMap(); Procedure procedure = each -> { actual.getIfAbsentPut(each % 100, () -> HashBag.newBag().asSynchronized()).add(each); }; source.parallelForEachValue(FastList.newList(Collections.nCopies(5, procedure)), this.executor); Verify.assertEqualsAndHashCode(BAG_MUTABLE_MAP, actual); } @Test public void parallelForEachEntry() { ConcurrentHashMapUnsafe source = ConcurrentHashMapUnsafe.newMap(Interval.oneTo(1000).toMap(Functions.getIntegerPassThru(), Functions.getIntegerPassThru())); MutableMap> actual = ConcurrentHashMapUnsafe.newMap(); Procedure2 procedure2 = (key, value) -> { actual.getIfAbsentPut(value % 100, () -> HashBag.newBag().asSynchronized()).add(value); }; source.parallelForEachKeyValue(FastList.newList(Collections.nCopies(5, procedure2)), this.executor); Verify.assertEqualsAndHashCode(BAG_MUTABLE_MAP, actual); } @Test public void putAllInParallelSmallMap() { ConcurrentHashMapUnsafe source = ConcurrentHashMapUnsafe.newMap(Interval.oneTo(1000).toMap(Functions.getIntegerPassThru(), Functions.getIntegerPassThru())); ConcurrentHashMapUnsafe target = ConcurrentHashMapUnsafe.newMap(); target.putAllInParallel(source, 10, this.executor); Verify.assertEqualsAndHashCode(source, target); } @Test public void putAllInParallelLargeMap() { ConcurrentHashMapUnsafe source = ConcurrentHashMapUnsafe.newMap(Interval.oneTo(600000).toMap(Functions.getIntegerPassThru(), Functions.getIntegerPassThru())); ConcurrentHashMapUnsafe target = ConcurrentHashMapUnsafe.newMap(); target.putAllInParallel(source, 10, this.executor); Verify.assertEqualsAndHashCode(source, target); } @Test public void concurrentPutGetPutAllRemoveContainsKeyContainsValueGetIfAbsentPutTest() { ConcurrentHashMapUnsafe map1 = ConcurrentHashMapUnsafe.newMap(); ConcurrentHashMapUnsafe map2 = ConcurrentHashMapUnsafe.newMap(); ParallelIterate.forEach(Interval.oneTo(1000), each -> { map1.put(each, each); Assert.assertEquals(each, map1.get(each)); map2.putAll(Maps.mutable.of(each, each)); map1.remove(each); map1.putAll(Maps.mutable.of(each, each)); Assert.assertEquals(each, map2.get(each)); map2.remove(each); Assert.assertNull(map2.get(each)); Assert.assertFalse(map2.containsValue(each)); Assert.assertFalse(map2.containsKey(each)); Assert.assertEquals(each, map2.getIfAbsentPut(each, Functions.getIntegerPassThru())); Assert.assertTrue(map2.containsValue(each)); Assert.assertTrue(map2.containsKey(each)); Assert.assertEquals(each, map2.getIfAbsentPut(each, Functions.getIntegerPassThru())); map2.remove(each); Assert.assertEquals(each, map2.getIfAbsentPutWith(each, Functions.getIntegerPassThru(), each)); Assert.assertEquals(each, map2.getIfAbsentPutWith(each, Functions.getIntegerPassThru(), each)); Assert.assertEquals(each, map2.getIfAbsentPut(each, Functions.getIntegerPassThru())); }, 10, this.executor); Verify.assertEqualsAndHashCode(map1, map2); } @Test public void concurrentPutIfAbsentGetIfPresentPutTest() { ConcurrentHashMapUnsafe map1 = ConcurrentHashMapUnsafe.newMap(); ConcurrentHashMapUnsafe map2 = ConcurrentHashMapUnsafe.newMap(); ParallelIterate.forEach(Interval.oneTo(1000), each -> { map1.put(each, each); map1.put(each, each); Assert.assertEquals(each, map1.get(each)); map2.putAll(Maps.mutable.of(each, each)); map2.putAll(Maps.mutable.of(each, each)); map1.remove(each); Assert.assertNull(map1.putIfAbsentGetIfPresent(each, new KeyTransformer(), new ValueFactory(), null, null)); Assert.assertEquals(each, map1.putIfAbsentGetIfPresent(each, new KeyTransformer(), new ValueFactory(), null, null)); }, 10, this.executor); Assert.assertEquals(map1, map2); } @Test public void concurrentClear() { ConcurrentHashMapUnsafe map = ConcurrentHashMapUnsafe.newMap(); ParallelIterate.forEach(Interval.oneTo(1000), each -> { for (int i = 0; i < each; i++) { map.put(each + i * 1000, each); } map.clear(); for (int i = 0; i < 100; i++) { map.put(each + i * 1000, each); } map.clear(); }, 10, this.executor); Verify.assertEmpty(map); } @Test public void concurrentRemoveAndPutIfAbsent() { ConcurrentHashMapUnsafe map1 = ConcurrentHashMapUnsafe.newMap(); ParallelIterate.forEach(Interval.oneTo(1000), each -> { Assert.assertNull(map1.put(each, each)); map1.remove(each); Assert.assertNull(map1.get(each)); Assert.assertEquals(each, map1.getIfAbsentPut(each, Functions.getIntegerPassThru())); map1.remove(each); Assert.assertNull(map1.get(each)); Assert.assertEquals(each, map1.getIfAbsentPutWith(each, Functions.getIntegerPassThru(), each)); map1.remove(each); Assert.assertNull(map1.get(each)); for (int i = 0; i < each; i++) { Assert.assertNull(map1.putIfAbsent(each + i * 1000, each)); } for (int i = 0; i < each; i++) { Assert.assertEquals(each, map1.putIfAbsent(each + i * 1000, each)); } for (int i = 0; i < each; i++) { Assert.assertEquals(each, map1.remove(each + i * 1000)); } }, 10, this.executor); } private static class KeyTransformer implements Function2 { private static final long serialVersionUID = 1L; @Override public Integer value(Integer key, Integer value) { return key; } } private static class ValueFactory implements Function3 { private static final long serialVersionUID = 1L; @Override public Integer value(Object argument1, Object argument2, Integer key) { return key; } } } ParallelMapIteratePutAcceptanceTest.java000066400000000000000000000141401234315411400410250ustar00rootroot00000000000000gs-collections-5.1.0/acceptance-tests/src/test/java/com/gs/collections/impl/map/mutable/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.map.mutable; import java.util.Arrays; import java.util.Collections; import java.util.Map; import java.util.Random; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import com.gs.collections.impl.set.mutable.UnifiedSet; import com.gs.collections.impl.test.Verify; import org.junit.After; import org.junit.Assert; import org.junit.Test; public class ParallelMapIteratePutAcceptanceTest { private static final long SEED = 0x12345678ABCDL; private static final long PUT_REPEAT = 100; private static final int CHUNK_SIZE = 16000; private static final int MAX_THREADS = 48; @After public void tearDown() { fullGc(); } private static void fullGc() { System.gc(); Thread.yield(); System.gc(); try { Thread.sleep(100); } catch (InterruptedException e) { throw new RuntimeException(e); } } @Test public void testMapIteratePut() { int constSize = 100000; int size = 10000000; Integer[] contents = new Integer[size]; Integer[] constContents = new Integer[constSize]; for (int i = 0; i < size; i++) { contents[i] = i; if (i < constSize / 2) { constContents[i] = i; } else if (i < constSize) { constContents[i] = size - i; } } Collections.shuffle(Arrays.asList(contents), new Random(SEED)); this.runAllPutTests(contents, constContents); } private void runAllPutTests(Integer[] contents, Integer[] constContents) { ExecutorService executorService = new ThreadPoolExecutor(MAX_THREADS, MAX_THREADS, 0, TimeUnit.SECONDS, new LinkedBlockingDeque(MAX_THREADS)); int threads = 10; this.runPutTest1(threads, contents, constContents, executorService, false); executorService.shutdown(); } private void runPutTest1(int threadCount, Integer[] contents, Integer[] constContents, ExecutorService executorService, boolean warmup) { long ops = (warmup ? 1000000 / contents.length : 1000000 * PUT_REPEAT / contents.length) + 1; Future[] futures = new Future[threadCount]; for (int i = 0; i < ops; i++) { ConcurrentHashMap map = new ConcurrentHashMap(constContents.length); UnifiedSet setToRemove = UnifiedSet.newSet(constContents.length); for (Integer x : constContents) { map.put(x, x); setToRemove.put(x); } AtomicInteger currentPos = new AtomicInteger(); for (int t = 0; t < threadCount; t++) { futures[t] = executorService.submit(new PutRunner1(map, contents, currentPos)); } int count = 0; UnifiedSet setToAdd = UnifiedSet.newSet(constContents.length); for (Integer next : map.keySet()) { setToRemove.remove(next); Assert.assertTrue(setToAdd.add(next)); count++; } Assert.assertTrue(count >= constContents.length); Verify.assertEmpty(setToRemove); for (Future future : futures) { try { future.get(); } catch (ExecutionException e) { throw new RuntimeException("unexpected", e); } catch (InterruptedException e) { throw new RuntimeException("unexpected", e); } } if (map.size() != contents.length) { throw new AssertionError(); } } } private static final class PutRunner1 implements Runnable { private final Map map; private final Integer[] contents; private long total; private final AtomicInteger queuePosition; private PutRunner1(Map map, Integer[] contents, AtomicInteger queuePosition) { this.map = map; this.contents = contents; this.queuePosition = queuePosition; } @Override public void run() { while (this.queuePosition.get() < this.contents.length) { int end = this.queuePosition.addAndGet(CHUNK_SIZE); int start = end - CHUNK_SIZE; if (start < this.contents.length) { if (end > this.contents.length) { end = this.contents.length; } for (int i = start; i < end; i++) { if (this.map.put(this.contents[i], this.contents[i]) != null) { this.total++; } } } } if (this.total < 0) { throw new AssertionError("never gets here, but it can't be optimized away"); } } } } ParallelUnsafeMapIteratePutAcceptanceTest.java000066400000000000000000000141621234315411400421730ustar00rootroot00000000000000gs-collections-5.1.0/acceptance-tests/src/test/java/com/gs/collections/impl/map/mutable/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.map.mutable; import java.util.Arrays; import java.util.Collections; import java.util.Map; import java.util.Random; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import com.gs.collections.impl.set.mutable.UnifiedSet; import com.gs.collections.impl.test.Verify; import org.junit.After; import org.junit.Assert; import org.junit.Test; public class ParallelUnsafeMapIteratePutAcceptanceTest { private static final long SEED = 0x12345678ABCDL; private static final long PUT_REPEAT = 100; private static final int CHUNK_SIZE = 16000; private static final int MAX_THREADS = 48; @After public void tearDown() { fullGc(); } private static void fullGc() { System.gc(); Thread.yield(); System.gc(); try { Thread.sleep(100); } catch (InterruptedException e) { throw new RuntimeException(e); } } @Test public void testMapIteratePut() { int constSize = 100000; int size = 10000000; Integer[] contents = new Integer[size]; Integer[] constContents = new Integer[constSize]; for (int i = 0; i < size; i++) { contents[i] = i; if (i < constSize / 2) { constContents[i] = i; } else if (i < constSize) { constContents[i] = size - i; } } Collections.shuffle(Arrays.asList(contents), new Random(SEED)); this.runAllPutTests(contents, constContents); } private void runAllPutTests(Integer[] contents, Integer[] constContents) { ExecutorService executorService = new ThreadPoolExecutor(MAX_THREADS, MAX_THREADS, 0, TimeUnit.SECONDS, new LinkedBlockingDeque(MAX_THREADS)); int threads = 10; this.runPutTest1(threads, contents, constContents, executorService, false); executorService.shutdown(); } private void runPutTest1(int threadCount, Integer[] contents, Integer[] constContents, ExecutorService executorService, boolean warmup) { long ops = (warmup ? 1000000 / contents.length : 1000000 * PUT_REPEAT / contents.length) + 1; Future[] futures = new Future[threadCount]; for (int i = 0; i < ops; i++) { ConcurrentHashMapUnsafe map = new ConcurrentHashMapUnsafe(constContents.length); UnifiedSet setToRemove = UnifiedSet.newSet(constContents.length); for (Integer x : constContents) { map.put(x, x); setToRemove.put(x); } AtomicInteger currentPos = new AtomicInteger(); for (int t = 0; t < threadCount; t++) { futures[t] = executorService.submit(new PutRunner1(map, contents, currentPos)); } int count = 0; UnifiedSet setToAdd = UnifiedSet.newSet(constContents.length); for (Integer next : map.keySet()) { setToRemove.remove(next); Assert.assertTrue(setToAdd.add(next)); count++; } Assert.assertTrue(count >= constContents.length); Verify.assertEmpty(setToRemove); for (Future future : futures) { try { future.get(); } catch (ExecutionException e) { throw new RuntimeException("unexpected", e); } catch (InterruptedException e) { throw new RuntimeException("unexpected", e); } } if (map.size() != contents.length) { throw new AssertionError(); } } } private static final class PutRunner1 implements Runnable { private final Map map; private final Integer[] contents; private long total; private final AtomicInteger queuePosition; private PutRunner1(Map map, Integer[] contents, AtomicInteger queuePosition) { this.map = map; this.contents = contents; this.queuePosition = queuePosition; } @Override public void run() { while (this.queuePosition.get() < this.contents.length) { int end = this.queuePosition.addAndGet(CHUNK_SIZE); int start = end - CHUNK_SIZE; if (start < this.contents.length) { if (end > this.contents.length) { end = this.contents.length; } for (int i = start; i < end; i++) { if (this.map.put(this.contents[i], this.contents[i]) != null) { this.total++; } } } } if (this.total < 0) { throw new AssertionError("never gets here, but it can't be optimized away"); } } } } UnifiedMapAcceptanceTest.java000066400000000000000000001745111234315411400366560ustar00rootroot00000000000000gs-collections-5.1.0/acceptance-tests/src/test/java/com/gs/collections/impl/map/mutable/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.map.mutable; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import com.gs.collections.api.map.MutableMap; import com.gs.collections.impl.CollidingInt; import com.gs.collections.impl.block.factory.Comparators; import com.gs.collections.impl.test.SerializeTestHelper; import com.gs.collections.impl.test.Verify; import org.junit.Assert; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class UnifiedMapAcceptanceTest { private static final Logger LOGGER = LoggerFactory.getLogger(UnifiedMapAcceptanceTest.class); private static final Comparator> ENTRY_COMPARATOR = (o1, o2) -> o1.getKey().compareTo(o2.getKey()); private static final Comparator VALUE_COMPARATOR = (o1, o2) -> Integer.parseInt(o1.substring(1)) - Integer.parseInt(o2.substring(1)); @Test public void forEachWithIndexWithChainedValues() { UnifiedMap map = UnifiedMap.newMap(); int size = 100000; for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, 3), UnifiedMapAcceptanceTest.createVal(i)); } int[] intArray = new int[1]; intArray[0] = -1; map.forEachWithIndex((value, index) -> { Assert.assertEquals(index, intArray[0] + 1); intArray[0] = index; }); } @Test public void getMapMemoryUsedInWords() { UnifiedMap map = UnifiedMap.newMap(); Assert.assertEquals(34, map.getMapMemoryUsedInWords()); map.put("1", "1"); Assert.assertEquals(34, map.getMapMemoryUsedInWords()); } @Test public void getCollidingBuckets() { UnifiedMap map = UnifiedMap.newMap(); Assert.assertEquals(0, map.getCollidingBuckets()); } private static String createVal(int i) { return "X" + i; } //todo: tests with null values //todo: keyset.removeAll(some collection where one of the keys is associated with null in the map) == true //todo: entryset.add(key associated with null) == true //todo: entryset.contains(entry with null value) == true @Test public void unifiedMapWithCollisions() { UnifiedMapAcceptanceTest.assertUnifiedMapWithCollisions(0, 2); UnifiedMapAcceptanceTest.assertUnifiedMapWithCollisions(1, 2); UnifiedMapAcceptanceTest.assertUnifiedMapWithCollisions(2, 2); UnifiedMapAcceptanceTest.assertUnifiedMapWithCollisions(3, 2); UnifiedMapAcceptanceTest.assertUnifiedMapWithCollisions(4, 2); UnifiedMapAcceptanceTest.assertUnifiedMapWithCollisions(0, 4); UnifiedMapAcceptanceTest.assertUnifiedMapWithCollisions(1, 4); UnifiedMapAcceptanceTest.assertUnifiedMapWithCollisions(2, 4); UnifiedMapAcceptanceTest.assertUnifiedMapWithCollisions(3, 4); UnifiedMapAcceptanceTest.assertUnifiedMapWithCollisions(4, 4); UnifiedMapAcceptanceTest.assertUnifiedMapWithCollisions(0, 8); UnifiedMapAcceptanceTest.assertUnifiedMapWithCollisions(1, 8); UnifiedMapAcceptanceTest.assertUnifiedMapWithCollisions(2, 8); UnifiedMapAcceptanceTest.assertUnifiedMapWithCollisions(3, 8); UnifiedMapAcceptanceTest.assertUnifiedMapWithCollisions(4, 8); } private static void assertUnifiedMapWithCollisions(int shift, int removeStride) { UnifiedMap map = UnifiedMap.newMap(); int size = 100000; for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); } Verify.assertSize(size, map); for (int i = 0; i < size; i++) { Verify.assertContainsKey(new CollidingInt(i, shift), map); Verify.assertContainsKeyValue(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i), map); } for (int i = 0; i < size; i += removeStride) { Assert.assertEquals(UnifiedMapAcceptanceTest.createVal(i), map.remove(new CollidingInt(i, shift))); } Verify.assertSize(size - size / removeStride, map); for (int i = 0; i < size; i++) { if (i % removeStride == 0) { Verify.assertNotContainsKey(new CollidingInt(i, shift), map); Assert.assertNull(map.get(new CollidingInt(i, shift))); } else { Verify.assertContainsKey(new CollidingInt(i, shift), map); Verify.assertContainsKeyValue(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i), map); } } for (int i = 0; i < size; i++) { map.remove(new CollidingInt(i, shift)); } Verify.assertSize(0, map); } @Test public void unifiedMapWithCollisionsAndNullKey() { UnifiedMapAcceptanceTest.assertUnifiedMapWithCollisionsAndNullKey(0, 2); UnifiedMapAcceptanceTest.assertUnifiedMapWithCollisionsAndNullKey(1, 2); UnifiedMapAcceptanceTest.assertUnifiedMapWithCollisionsAndNullKey(2, 2); UnifiedMapAcceptanceTest.assertUnifiedMapWithCollisionsAndNullKey(3, 2); UnifiedMapAcceptanceTest.assertUnifiedMapWithCollisionsAndNullKey(4, 2); UnifiedMapAcceptanceTest.assertUnifiedMapWithCollisionsAndNullKey(0, 4); UnifiedMapAcceptanceTest.assertUnifiedMapWithCollisionsAndNullKey(1, 4); UnifiedMapAcceptanceTest.assertUnifiedMapWithCollisionsAndNullKey(2, 4); UnifiedMapAcceptanceTest.assertUnifiedMapWithCollisionsAndNullKey(3, 4); UnifiedMapAcceptanceTest.assertUnifiedMapWithCollisionsAndNullKey(4, 4); UnifiedMapAcceptanceTest.assertUnifiedMapWithCollisionsAndNullKey(0, 8); UnifiedMapAcceptanceTest.assertUnifiedMapWithCollisionsAndNullKey(1, 8); UnifiedMapAcceptanceTest.assertUnifiedMapWithCollisionsAndNullKey(2, 8); UnifiedMapAcceptanceTest.assertUnifiedMapWithCollisionsAndNullKey(3, 8); UnifiedMapAcceptanceTest.assertUnifiedMapWithCollisionsAndNullKey(4, 8); } private static void assertUnifiedMapWithCollisionsAndNullKey(int shift, int removeStride) { UnifiedMap map = UnifiedMap.newMap(); Assert.assertTrue(map.isEmpty()); int size = 100000; for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); } map.put(null, "Y"); Verify.assertSize(size + 1, map); for (int i = 0; i < size; i++) { Verify.assertContainsKey(new CollidingInt(i, shift), map); Verify.assertContainsKeyValue(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i), map); } Assert.assertTrue(map.containsKey(null)); Assert.assertEquals("Y", map.get(null)); for (int i = 0; i < size; i += removeStride) { Assert.assertEquals(UnifiedMapAcceptanceTest.createVal(i), map.remove(new CollidingInt(i, shift))); } Verify.assertSize(size - size / removeStride + 1, map); for (int i = 0; i < size; i++) { if (i % removeStride != 0) { Verify.assertContainsKey(new CollidingInt(i, shift), map); Verify.assertContainsKeyValue(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i), map); } } Assert.assertTrue(map.containsKey(null)); Assert.assertEquals("Y", map.get(null)); map.remove(null); Assert.assertFalse(map.containsKey(null)); Assert.assertNull(map.get(null)); } @Test public void unifiedMap() { UnifiedMap map = UnifiedMap.newMap(); int size = 100000; for (int i = 0; i < size; i++) { map.put(i, UnifiedMapAcceptanceTest.createVal(i)); } Verify.assertSize(size, map); for (int i = 0; i < size; i++) { Assert.assertTrue(map.containsKey(i)); Assert.assertEquals(UnifiedMapAcceptanceTest.createVal(i), map.get(i)); } for (int i = 0; i < size; i += 2) { Assert.assertEquals(UnifiedMapAcceptanceTest.createVal(i), map.remove(i)); } Verify.assertSize(size / 2, map); for (int i = 1; i < size; i += 2) { Assert.assertTrue(map.containsKey(i)); Assert.assertEquals(UnifiedMapAcceptanceTest.createVal(i), map.get(i)); } } @Test public void unifiedMapClear() { UnifiedMapAcceptanceTest.assertUnifiedMapClear(0); UnifiedMapAcceptanceTest.assertUnifiedMapClear(1); UnifiedMapAcceptanceTest.assertUnifiedMapClear(2); UnifiedMapAcceptanceTest.assertUnifiedMapClear(3); } private static void assertUnifiedMapClear(int shift) { UnifiedMap map = UnifiedMap.newMap(); int size = 100000; for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); } map.clear(); Verify.assertSize(0, map); for (int i = 0; i < size; i++) { Verify.assertNotContainsKey(new CollidingInt(i, shift), map); Assert.assertNull(map.get(new CollidingInt(i, shift))); } } @Test public void unifiedMapForEachEntry() { UnifiedMapAcceptanceTest.assertUnifiedMapForEachEntry(0); UnifiedMapAcceptanceTest.assertUnifiedMapForEachEntry(1); UnifiedMapAcceptanceTest.assertUnifiedMapForEachEntry(2); UnifiedMapAcceptanceTest.assertUnifiedMapForEachEntry(3); } private static void assertUnifiedMapForEachEntry(int shift) { UnifiedMap map = UnifiedMap.newMap(); int size = 100000; for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); } int[] count = new int[1]; map.forEachKeyValue((key, value) -> { Assert.assertEquals(UnifiedMapAcceptanceTest.createVal(key.getValue()), value); count[0]++; }); Assert.assertEquals(size, count[0]); } @Test public void unifiedMapForEachKey() { UnifiedMapAcceptanceTest.assertUnifiedMapForEachKey(0); UnifiedMapAcceptanceTest.assertUnifiedMapForEachKey(1); UnifiedMapAcceptanceTest.assertUnifiedMapForEachKey(2); UnifiedMapAcceptanceTest.assertUnifiedMapForEachKey(3); } private static void assertUnifiedMapForEachKey(int shift) { UnifiedMap map = UnifiedMap.newMap(); int size = 100000; for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); } List keys = new ArrayList(size); map.forEachKey(keys::add); Verify.assertSize(size, keys); Collections.sort(keys); for (int i = 0; i < size; i++) { Assert.assertEquals(new CollidingInt(i, shift), keys.get(i)); } } @Test public void unifiedMapForEachValue() { UnifiedMapAcceptanceTest.assertUnifiedMapForEachValue(0); UnifiedMapAcceptanceTest.assertUnifiedMapForEachValue(1); UnifiedMapAcceptanceTest.assertUnifiedMapForEachValue(2); UnifiedMapAcceptanceTest.assertUnifiedMapForEachValue(3); } private static void assertUnifiedMapForEachValue(int shift) { UnifiedMap map = UnifiedMap.newMap(); int size = 100000; for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); } List values = new ArrayList(size); map.forEachValue(values::add); Verify.assertSize(size, values); Collections.sort(values, UnifiedMapAcceptanceTest.VALUE_COMPARATOR); for (int i = 0; i < size; i++) { Assert.assertEquals(UnifiedMapAcceptanceTest.createVal(i), values.get(i)); } } @Test public void equalsWithNullValue() { MutableMap map1 = UnifiedMap.newWithKeysValues(1, null, 2, 2); MutableMap map2 = UnifiedMap.newWithKeysValues(2, 2, 3, 3); Assert.assertNotEquals(map1, map2); } @Test public void unifiedMapEqualsAndHashCode() { UnifiedMapAcceptanceTest.assertUnifiedMapEqualsAndHashCode(0); UnifiedMapAcceptanceTest.assertUnifiedMapEqualsAndHashCode(1); UnifiedMapAcceptanceTest.assertUnifiedMapEqualsAndHashCode(2); UnifiedMapAcceptanceTest.assertUnifiedMapEqualsAndHashCode(3); } private static void assertUnifiedMapEqualsAndHashCode(int shift) { MutableMap map1 = UnifiedMap.newMap(); Map map2 = new HashMap(); MutableMap map3 = UnifiedMap.newMap(); MutableMap map4 = UnifiedMap.newMap(); int size = 100000; for (int i = 0; i < size; i++) { map1.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); map2.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); map3.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); map4.put(new CollidingInt(size - i - 1, shift), UnifiedMapAcceptanceTest.createVal(size - i - 1)); } Assert.assertEquals(map2, map1); Assert.assertEquals(map1, map2); Assert.assertEquals(map2.hashCode(), map1.hashCode()); Assert.assertEquals(map1, map3); Assert.assertEquals(map1.hashCode(), map3.hashCode()); Assert.assertEquals(map2, map4); Assert.assertEquals(map4, map2); Assert.assertEquals(map2.hashCode(), map4.hashCode()); Verify.assertSetsEqual(map2.entrySet(), map1.entrySet()); Verify.assertSetsEqual(map1.entrySet(), map2.entrySet()); Assert.assertEquals(map2.entrySet().hashCode(), map1.entrySet().hashCode()); Verify.assertSetsEqual(map1.entrySet(), map3.entrySet()); Assert.assertEquals(map1.entrySet().hashCode(), map3.entrySet().hashCode()); Verify.assertSetsEqual(map2.entrySet(), map4.entrySet()); Verify.assertSetsEqual(map4.entrySet(), map2.entrySet()); Assert.assertEquals(map2.entrySet().hashCode(), map4.entrySet().hashCode()); Verify.assertSetsEqual(map2.keySet(), map1.keySet()); Verify.assertSetsEqual(map1.keySet(), map2.keySet()); Assert.assertEquals(map2.keySet().hashCode(), map1.keySet().hashCode()); Verify.assertSetsEqual(map1.keySet(), map3.keySet()); Assert.assertEquals(map1.keySet().hashCode(), map3.keySet().hashCode()); Verify.assertSetsEqual(map2.keySet(), map4.keySet()); Verify.assertSetsEqual(map4.keySet(), map2.keySet()); Assert.assertEquals(map2.keySet().hashCode(), map4.keySet().hashCode()); } @Test public void unifiedMapPutAll() { UnifiedMapAcceptanceTest.assertUnifiedMapPutAll(0); UnifiedMapAcceptanceTest.assertUnifiedMapPutAll(1); UnifiedMapAcceptanceTest.assertUnifiedMapPutAll(2); UnifiedMapAcceptanceTest.assertUnifiedMapPutAll(3); } private static void assertUnifiedMapPutAll(int shift) { UnifiedMap map = UnifiedMap.newMap(); int size = 100000; for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); } UnifiedMap newMap = UnifiedMap.newMap(size); newMap.putAll(map); Verify.assertSize(size, newMap); for (int i = 0; i < size; i++) { Verify.assertContainsKey(new CollidingInt(i, shift), newMap); Verify.assertContainsKeyValue(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i), newMap); } } @Test public void unifiedMapPutAllWithHashMap() { UnifiedMapAcceptanceTest.assertUnifiedMapPutAllWithHashMap(0); UnifiedMapAcceptanceTest.assertUnifiedMapPutAllWithHashMap(1); UnifiedMapAcceptanceTest.assertUnifiedMapPutAllWithHashMap(2); UnifiedMapAcceptanceTest.assertUnifiedMapPutAllWithHashMap(3); } private static void assertUnifiedMapPutAllWithHashMap(int shift) { Map map = new HashMap(); int size = 100000; for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); } UnifiedMap newMap = UnifiedMap.newMap(size); newMap.putAll(map); Verify.assertSize(size, newMap); for (int i = 0; i < size; i++) { Verify.assertContainsKey(new CollidingInt(i, shift), newMap); Verify.assertContainsKeyValue(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i), newMap); } } @Test public void unifiedMapReplace() { UnifiedMapAcceptanceTest.assertUnifiedMapReplace(0); UnifiedMapAcceptanceTest.assertUnifiedMapReplace(1); UnifiedMapAcceptanceTest.assertUnifiedMapReplace(2); UnifiedMapAcceptanceTest.assertUnifiedMapReplace(3); } private static void assertUnifiedMapReplace(int shift) { UnifiedMap map = UnifiedMap.newMap(); int size = 100000; for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); } for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, shift), "Y" + i); } Verify.assertSize(size, map); for (int i = 0; i < size; i++) { Assert.assertEquals("Y" + i, map.get(new CollidingInt(i, shift))); } } @Test public void unifiedMapContainsValue() { UnifiedMapAcceptanceTest.runUnifiedMapContainsValue(0); UnifiedMapAcceptanceTest.runUnifiedMapContainsValue(1); UnifiedMapAcceptanceTest.runUnifiedMapContainsValue(2); UnifiedMapAcceptanceTest.runUnifiedMapContainsValue(3); } private static void runUnifiedMapContainsValue(int shift) { UnifiedMap map = UnifiedMap.newMap(); int size = 1000; for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); } for (int i = 0; i < size; i++) { Assert.assertTrue(map.containsValue(UnifiedMapAcceptanceTest.createVal(i))); } } @Test public void unifiedMapKeySet() { UnifiedMapAcceptanceTest.runUnifiedMapKeySet(0); UnifiedMapAcceptanceTest.runUnifiedMapKeySet(1); UnifiedMapAcceptanceTest.runUnifiedMapKeySet(2); UnifiedMapAcceptanceTest.runUnifiedMapKeySet(3); } private static void runUnifiedMapKeySet(int shift) { UnifiedMap map = UnifiedMap.newMap(); int size = 100000; for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); } Verify.assertSize(size, map); Set keySet = map.keySet(); Verify.assertSize(size, keySet); for (int i = 0; i < size; i++) { Verify.assertContains(new CollidingInt(i, shift), keySet); } for (int i = 0; i < size; i += 2) { Assert.assertTrue(keySet.remove(new CollidingInt(i, shift))); } Verify.assertSize(size / 2, map); Verify.assertSize(size / 2, keySet); for (int i = 1; i < size; i += 2) { Verify.assertContainsKey(new CollidingInt(i, shift), map); Verify.assertContains(new CollidingInt(i, shift), keySet); Verify.assertContainsKeyValue(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i), map); } } @Test public void unifiedMapKeySetRetainAll() { UnifiedMapAcceptanceTest.runUnifiedMapKeySetRetainAll(0); UnifiedMapAcceptanceTest.runUnifiedMapKeySetRetainAll(1); UnifiedMapAcceptanceTest.runUnifiedMapKeySetRetainAll(2); UnifiedMapAcceptanceTest.runUnifiedMapKeySetRetainAll(3); } private static void runUnifiedMapKeySetRetainAll(int shift) { UnifiedMap map = UnifiedMap.newMap(); List toRetain = new ArrayList(); int size = 100000; for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); if (i % 2 == 0) { toRetain.add(new CollidingInt(i, shift)); } } Verify.assertSize(size, map); Set keySet = map.keySet(); Assert.assertTrue(keySet.containsAll(toRetain)); Assert.assertTrue(keySet.retainAll(toRetain)); Assert.assertTrue(keySet.containsAll(toRetain)); Assert.assertFalse(keySet.retainAll(toRetain)); // a second call should not modify the set Verify.assertSize(size / 2, map); Verify.assertSize(size / 2, keySet); for (int i = 0; i < size; i += 2) { Verify.assertContainsKey(new CollidingInt(i, shift), map); Verify.assertContains(new CollidingInt(i, shift), keySet); Verify.assertContainsKeyValue(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i), map); } } @Test public void unifiedMapKeySetRemoveAll() { UnifiedMapAcceptanceTest.runUnifiedMapKeySetRemoveAll(0); UnifiedMapAcceptanceTest.runUnifiedMapKeySetRemoveAll(1); UnifiedMapAcceptanceTest.runUnifiedMapKeySetRemoveAll(2); UnifiedMapAcceptanceTest.runUnifiedMapKeySetRemoveAll(3); } private static void runUnifiedMapKeySetRemoveAll(int shift) { UnifiedMap map = UnifiedMap.newMap(); List toRemove = new ArrayList(); int size = 100000; for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); if (i % 2 == 0) { toRemove.add(new CollidingInt(i, shift)); } } Verify.assertSize(size, map); Set keySet = map.keySet(); Assert.assertTrue(keySet.removeAll(toRemove)); Assert.assertFalse(keySet.removeAll(toRemove)); // a second call should not modify the set Verify.assertSize(size / 2, map); Verify.assertSize(size / 2, keySet); for (int i = 1; i < size; i += 2) { Verify.assertContainsKey(new CollidingInt(i, shift), map); Verify.assertContains(new CollidingInt(i, shift), keySet); Verify.assertContainsKeyValue(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i), map); } } @Test public void unifiedMapKeySetToArray() { UnifiedMapAcceptanceTest.runUnifiedMapKeySetToArray(0); UnifiedMapAcceptanceTest.runUnifiedMapKeySetToArray(1); UnifiedMapAcceptanceTest.runUnifiedMapKeySetToArray(2); UnifiedMapAcceptanceTest.runUnifiedMapKeySetToArray(3); } private static void runUnifiedMapKeySetToArray(int shift) { UnifiedMap map = UnifiedMap.newMap(); int size = 100000; for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); } Verify.assertSize(size, map); Set keySet = map.keySet(); Object[] keys = keySet.toArray(); Arrays.sort(keys); for (int i = 0; i < size; i++) { Assert.assertEquals(new CollidingInt(i, shift), keys[i]); } } @Test public void unifiedMapKeySetIterator() { UnifiedMapAcceptanceTest.runUnifiedMapKeySetIterator(0); UnifiedMapAcceptanceTest.runUnifiedMapKeySetIterator(1); UnifiedMapAcceptanceTest.runUnifiedMapKeySetIterator(2); UnifiedMapAcceptanceTest.runUnifiedMapKeySetIterator(3); } private static void runUnifiedMapKeySetIterator(int shift) { UnifiedMap map = UnifiedMap.newMap(); int size = 100000; for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); } Verify.assertSize(size, map); Set keySet = map.keySet(); CollidingInt[] keys = new CollidingInt[size]; int count = 0; for (Iterator it = keySet.iterator(); it.hasNext(); ) { keys[count++] = it.next(); } Arrays.sort(keys); for (int i = 0; i < size; i++) { Assert.assertEquals(new CollidingInt(i, shift), keys[i]); } } @Test public void unifiedMapKeySetIteratorRemove() { UnifiedMapAcceptanceTest.runUnifiedMapKeySetIteratorRemove(0, 2); UnifiedMapAcceptanceTest.runUnifiedMapKeySetIteratorRemove(1, 2); UnifiedMapAcceptanceTest.runUnifiedMapKeySetIteratorRemove(2, 2); UnifiedMapAcceptanceTest.runUnifiedMapKeySetIteratorRemove(3, 2); UnifiedMapAcceptanceTest.runUnifiedMapKeySetIteratorRemove(0, 3); UnifiedMapAcceptanceTest.runUnifiedMapKeySetIteratorRemove(1, 3); UnifiedMapAcceptanceTest.runUnifiedMapKeySetIteratorRemove(2, 3); UnifiedMapAcceptanceTest.runUnifiedMapKeySetIteratorRemove(3, 3); UnifiedMapAcceptanceTest.runUnifiedMapKeySetIteratorRemove(0, 4); UnifiedMapAcceptanceTest.runUnifiedMapKeySetIteratorRemove(1, 4); UnifiedMapAcceptanceTest.runUnifiedMapKeySetIteratorRemove(2, 4); UnifiedMapAcceptanceTest.runUnifiedMapKeySetIteratorRemove(3, 4); } private static void runUnifiedMapKeySetIteratorRemove(int shift, int removeStride) { UnifiedMap map = UnifiedMap.newMap(); int size = 100000; for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); } Verify.assertSize(size, map); Set keySet = map.keySet(); int count = 0; for (Iterator it = keySet.iterator(); it.hasNext(); ) { CollidingInt key = it.next(); count++; if (key.getValue() % removeStride == 0) { it.remove(); } } Assert.assertEquals(size, count); for (int i = 0; i < size; i++) { if (i % removeStride != 0) { Assert.assertTrue("map contains " + i + "for shift " + shift + " and remove stride " + removeStride, map .containsKey(new CollidingInt(i, shift))); Verify.assertContainsKeyValue(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i), map); } } } @Test public void unifiedMapKeySetIteratorRemoveFlip() { UnifiedMapAcceptanceTest.runUnifiedMapKeySetIteratorRemoveFlip(0, 2); UnifiedMapAcceptanceTest.runUnifiedMapKeySetIteratorRemoveFlip(1, 2); UnifiedMapAcceptanceTest.runUnifiedMapKeySetIteratorRemoveFlip(2, 2); UnifiedMapAcceptanceTest.runUnifiedMapKeySetIteratorRemoveFlip(3, 2); UnifiedMapAcceptanceTest.runUnifiedMapKeySetIteratorRemoveFlip(0, 3); UnifiedMapAcceptanceTest.runUnifiedMapKeySetIteratorRemoveFlip(1, 3); UnifiedMapAcceptanceTest.runUnifiedMapKeySetIteratorRemoveFlip(2, 3); UnifiedMapAcceptanceTest.runUnifiedMapKeySetIteratorRemoveFlip(3, 3); UnifiedMapAcceptanceTest.runUnifiedMapKeySetIteratorRemoveFlip(0, 4); UnifiedMapAcceptanceTest.runUnifiedMapKeySetIteratorRemoveFlip(1, 4); UnifiedMapAcceptanceTest.runUnifiedMapKeySetIteratorRemoveFlip(2, 4); UnifiedMapAcceptanceTest.runUnifiedMapKeySetIteratorRemoveFlip(3, 4); } private static void runUnifiedMapKeySetIteratorRemoveFlip(int shift, int removeStride) { UnifiedMap map = UnifiedMap.newMap(); int size = 100000; for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); } Verify.assertSize(size, map); Set keySet = map.keySet(); int count = 0; for (Iterator it = keySet.iterator(); it.hasNext(); ) { CollidingInt key = it.next(); count++; if (key.getValue() % removeStride != 0) { it.remove(); } } Assert.assertEquals(size, count); for (int i = 0; i < size; i++) { if (i % removeStride == 0) { Assert.assertTrue("map contains " + i + "for shift " + shift + " and remove stride " + removeStride, map .containsKey(new CollidingInt(i, shift))); Verify.assertContainsKeyValue(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i), map); } } } //entry set tests @Test public void unifiedMapEntrySet() { UnifiedMapAcceptanceTest.runUnifiedMapEntrySet(0); UnifiedMapAcceptanceTest.runUnifiedMapEntrySet(1); UnifiedMapAcceptanceTest.runUnifiedMapEntrySet(2); UnifiedMapAcceptanceTest.runUnifiedMapEntrySet(3); } private static void runUnifiedMapEntrySet(int shift) { UnifiedMap map = UnifiedMap.newMap(); int size = 100000; for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); } Verify.assertSize(size, map); Set> entrySet = map.entrySet(); Verify.assertSize(size, entrySet); for (int i = 0; i < size; i++) { Verify.assertContains(new Entry(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)), entrySet); } for (int i = 0; i < size; i += 2) { Assert.assertTrue(entrySet.remove(new Entry(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)))); } Verify.assertSize(size / 2, map); Verify.assertSize(size / 2, entrySet); for (int i = 1; i < size; i += 2) { Verify.assertContainsKey(new CollidingInt(i, shift), map); Verify.assertContains(new Entry(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)), entrySet); Verify.assertContainsKeyValue(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i), map); } } @Test public void unifiedMapEntrySetRetainAll() { UnifiedMapAcceptanceTest.runUnifiedMapEntrySetRetainAll(0); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetRetainAll(1); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetRetainAll(2); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetRetainAll(3); } private static void runUnifiedMapEntrySetRetainAll(int shift) { UnifiedMap map = UnifiedMap.newMap(); List toRetain = new ArrayList(); int size = 100000; for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); if (i % 2 == 0) { toRetain.add(new Entry(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i))); } } Verify.assertSize(size, map); Set> entrySet = map.entrySet(); Assert.assertTrue(entrySet.containsAll(toRetain)); Assert.assertTrue(entrySet.retainAll(toRetain)); Assert.assertTrue(entrySet.containsAll(toRetain)); Assert.assertFalse(entrySet.retainAll(toRetain)); // a second call should not modify the set Verify.assertSize(size / 2, map); Verify.assertSize(size / 2, entrySet); for (int i = 0; i < size; i += 2) { Verify.assertContainsKey(new CollidingInt(i, shift), map); Verify.assertContains(new Entry(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)), entrySet); Verify.assertContainsKeyValue(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i), map); } } @Test public void unifiedMapEntrySetRemoveAll() { UnifiedMapAcceptanceTest.runUnifiedMapEntrySetRemoveAll(0); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetRemoveAll(1); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetRemoveAll(2); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetRemoveAll(3); } private static void runUnifiedMapEntrySetRemoveAll(int shift) { UnifiedMap map = UnifiedMap.newMap(); List toRemove = new ArrayList(); int size = 100000; for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); if (i % 2 == 0) { toRemove.add(new Entry(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i))); } } Verify.assertSize(size, map); Set> entrySet = map.entrySet(); Assert.assertTrue(entrySet.removeAll(toRemove)); Assert.assertFalse(entrySet.removeAll(toRemove)); // a second call should not modify the set Verify.assertSize(size / 2, map); Verify.assertSize(size / 2, entrySet); for (int i = 1; i < size; i += 2) { Verify.assertContainsKey(new CollidingInt(i, shift), map); Verify.assertContains(new Entry(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)), entrySet); Verify.assertContainsKeyValue(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i), map); } } @Test public void unifiedMapEntrySetToArray() { UnifiedMapAcceptanceTest.runUnifiedMapEntrySetToArray(0); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetToArray(1); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetToArray(2); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetToArray(3); } private static void runUnifiedMapEntrySetToArray(int shift) { UnifiedMap map = UnifiedMap.newMap(); int size = 100000; for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); } Verify.assertSize(size, map); Set> entrySet = map.entrySet(); Map.Entry[] entries = entrySet.toArray(new Map.Entry[0]); Arrays.sort(entries, UnifiedMapAcceptanceTest.ENTRY_COMPARATOR); for (int i = 0; i < size; i++) { Assert.assertEquals(new Entry(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)), entries[i]); } } @Test public void unifiedMapEntrySetIterator() { UnifiedMapAcceptanceTest.runUnifiedMapEntrySetIterator(0); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetIterator(1); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetIterator(2); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetIterator(3); } private static void runUnifiedMapEntrySetIterator(int shift) { UnifiedMap map = UnifiedMap.newMap(); int size = 100000; for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); } Verify.assertSize(size, map); Set> entrySet = map.entrySet(); Map.Entry[] entries = new Map.Entry[size]; int count = 0; for (Iterator> it = entrySet.iterator(); it.hasNext(); ) { entries[count++] = it.next(); } Arrays.sort(entries, UnifiedMapAcceptanceTest.ENTRY_COMPARATOR); for (int i = 0; i < size; i++) { Assert.assertEquals(new Entry(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)), entries[i]); } } @Test public void unifiedMapEntrySetIteratorSetValue() { UnifiedMapAcceptanceTest.runUnifiedMapEntrySetIteratorSetValue(0); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetIteratorSetValue(1); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetIteratorSetValue(2); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetIteratorSetValue(3); } private static void runUnifiedMapEntrySetIteratorSetValue(int shift) { UnifiedMap map = UnifiedMap.newMap(); int size = 100000; for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); } Verify.assertSize(size, map); Set> entrySet = map.entrySet(); for (Map.Entry entry : entrySet) { CollidingInt key = entry.getKey(); entry.setValue("Y" + key.getValue()); } Map.Entry[] entries = new Map.Entry[size]; int count = 0; for (Iterator> it = entrySet.iterator(); it.hasNext(); ) { entries[count++] = it.next(); } Arrays.sort(entries, UnifiedMapAcceptanceTest.ENTRY_COMPARATOR); for (int i = 0; i < size; i++) { Assert.assertEquals(new Entry(new CollidingInt(i, shift), "Y" + i), entries[i]); } } @Test public void unifiedMapEntrySetIteratorRemove() { UnifiedMapAcceptanceTest.runUnifiedMapEntrySetIteratorRemove(0, 2); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetIteratorRemove(1, 2); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetIteratorRemove(2, 2); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetIteratorRemove(3, 2); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetIteratorRemove(0, 3); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetIteratorRemove(1, 3); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetIteratorRemove(2, 3); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetIteratorRemove(3, 3); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetIteratorRemove(0, 4); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetIteratorRemove(1, 4); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetIteratorRemove(2, 4); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetIteratorRemove(3, 4); } private static void runUnifiedMapEntrySetIteratorRemove(int shift, int removeStride) { UnifiedMap map = UnifiedMap.newMap(); int size = 100000; for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); } Verify.assertSize(size, map); Set> entrySet = map.entrySet(); int count = 0; for (Iterator> it = entrySet.iterator(); it.hasNext(); ) { CollidingInt entry = it.next().getKey(); count++; if (entry.getValue() % removeStride == 0) { it.remove(); } } Assert.assertEquals(size, count); for (int i = 0; i < size; i++) { if (i % removeStride != 0) { Assert.assertTrue("map contains " + i + "for shift " + shift + " and remove stride " + removeStride, map .containsKey(new CollidingInt(i, shift))); Verify.assertContainsKeyValue(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i), map); } } } @Test public void unifiedMapEntrySetIteratorRemoveFlip() { UnifiedMapAcceptanceTest.runUnifiedMapEntrySetIteratorRemoveFlip(0, 2); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetIteratorRemoveFlip(1, 2); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetIteratorRemoveFlip(2, 2); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetIteratorRemoveFlip(3, 2); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetIteratorRemoveFlip(0, 3); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetIteratorRemoveFlip(1, 3); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetIteratorRemoveFlip(2, 3); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetIteratorRemoveFlip(3, 3); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetIteratorRemoveFlip(0, 4); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetIteratorRemoveFlip(1, 4); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetIteratorRemoveFlip(2, 4); UnifiedMapAcceptanceTest.runUnifiedMapEntrySetIteratorRemoveFlip(3, 4); } private static void runUnifiedMapEntrySetIteratorRemoveFlip(int shift, int removeStride) { UnifiedMap map = UnifiedMap.newMap(); int size = 100000; for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); } Verify.assertSize(size, map); Set> entrySet = map.entrySet(); int count = 0; for (Iterator> it = entrySet.iterator(); it.hasNext(); ) { CollidingInt entry = it.next().getKey(); count++; if (entry.getValue() % removeStride != 0) { it.remove(); } } Assert.assertEquals(size, count); for (int i = 0; i < size; i++) { if (i % removeStride == 0) { Assert.assertTrue("map contains " + i + "for shift " + shift + " and remove stride " + removeStride, map .containsKey(new CollidingInt(i, shift))); Verify.assertContainsKeyValue(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i), map); } } } // values collection @Test public void unifiedMapValues() { UnifiedMapAcceptanceTest.runUnifiedMapValues(0); UnifiedMapAcceptanceTest.runUnifiedMapValues(1); UnifiedMapAcceptanceTest.runUnifiedMapValues(2); UnifiedMapAcceptanceTest.runUnifiedMapValues(3); } private static void runUnifiedMapValues(int shift) { UnifiedMap map = UnifiedMap.newMap(); int size = 1000; for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); } Verify.assertSize(size, map); Collection values = map.values(); Assert.assertEquals(size, values.size()); for (int i = 0; i < size; i++) { Verify.assertContains(UnifiedMapAcceptanceTest.createVal(i), values); } for (int i = 0; i < size; i += 2) { Assert.assertTrue(values.remove(UnifiedMapAcceptanceTest.createVal(i))); } Verify.assertSize(size / 2, map); Verify.assertSize(size / 2, values); for (int i = 1; i < size; i += 2) { Verify.assertContainsKey(new CollidingInt(i, shift), map); Verify.assertContains(UnifiedMapAcceptanceTest.createVal(i), values); Verify.assertContainsKeyValue(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i), map); } } @Test public void unifiedMapValuesRetainAll() { UnifiedMapAcceptanceTest.runUnifiedMapValuesRetainAll(0); UnifiedMapAcceptanceTest.runUnifiedMapValuesRetainAll(1); UnifiedMapAcceptanceTest.runUnifiedMapValuesRetainAll(2); UnifiedMapAcceptanceTest.runUnifiedMapValuesRetainAll(3); } private static void runUnifiedMapValuesRetainAll(int shift) { UnifiedMap map = UnifiedMap.newMap(); List toRetain = new ArrayList(); int size = 1000; for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); if (i % 2 == 0) { toRetain.add(UnifiedMapAcceptanceTest.createVal(i)); } } Verify.assertSize(size, map); Collection values = map.values(); Assert.assertTrue(values.containsAll(toRetain)); Assert.assertTrue(values.retainAll(toRetain)); Assert.assertTrue(values.containsAll(toRetain)); Assert.assertFalse(values.retainAll(toRetain)); // a second call should not modify the set Verify.assertSize(size / 2, map); Verify.assertSize(size / 2, values); for (int i = 0; i < size; i += 2) { Verify.assertContainsKey(new CollidingInt(i, shift), map); Verify.assertContains(UnifiedMapAcceptanceTest.createVal(i), values); Verify.assertContainsKeyValue(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i), map); } } @Test public void unifiedMapValuesRemoveAll() { UnifiedMapAcceptanceTest.runUnifiedMapValuesRemoveAll(0); UnifiedMapAcceptanceTest.runUnifiedMapValuesRemoveAll(1); UnifiedMapAcceptanceTest.runUnifiedMapValuesRemoveAll(2); UnifiedMapAcceptanceTest.runUnifiedMapValuesRemoveAll(3); } private static void runUnifiedMapValuesRemoveAll(int shift) { UnifiedMap map = UnifiedMap.newMap(); List toRemove = new ArrayList(); int size = 1000; for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); if (i % 2 == 0) { toRemove.add(UnifiedMapAcceptanceTest.createVal(i)); } } Verify.assertSize(size, map); Collection values = map.values(); Assert.assertTrue(values.removeAll(toRemove)); Assert.assertFalse(values.removeAll(toRemove)); // a second call should not modify the set Verify.assertSize(size / 2, map); Verify.assertSize(size / 2, values); for (int i = 1; i < size; i += 2) { Verify.assertContainsKey(new CollidingInt(i, shift), map); Verify.assertContains(UnifiedMapAcceptanceTest.createVal(i), values); Verify.assertContainsKeyValue(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i), map); } } @Test public void unifiedMapValuesToArray() { UnifiedMapAcceptanceTest.runUnifiedMapValuesToArray(0); UnifiedMapAcceptanceTest.runUnifiedMapValuesToArray(1); UnifiedMapAcceptanceTest.runUnifiedMapValuesToArray(2); UnifiedMapAcceptanceTest.runUnifiedMapValuesToArray(3); } private static void runUnifiedMapValuesToArray(int shift) { UnifiedMap map = UnifiedMap.newMap(); int size = 1000; for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); } Verify.assertSize(size, map); Collection values = map.values(); String[] entries = values.toArray(new String[0]); Arrays.sort(entries, UnifiedMapAcceptanceTest.VALUE_COMPARATOR); for (int i = 0; i < size; i++) { Assert.assertEquals(UnifiedMapAcceptanceTest.createVal(i), entries[i]); } } @Test public void unifiedMapValuesIterator() { UnifiedMapAcceptanceTest.runUnifiedMapValuesIterator(0); UnifiedMapAcceptanceTest.runUnifiedMapValuesIterator(1); UnifiedMapAcceptanceTest.runUnifiedMapValuesIterator(2); UnifiedMapAcceptanceTest.runUnifiedMapValuesIterator(3); } private static void runUnifiedMapValuesIterator(int shift) { UnifiedMap map = UnifiedMap.newMap(); int size = 1000; for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); } Verify.assertSize(size, map); Collection values = map.values(); String[] valuesArray = new String[size]; int count = 0; for (Iterator it = values.iterator(); it.hasNext(); ) { valuesArray[count++] = it.next(); } Arrays.sort(valuesArray, UnifiedMapAcceptanceTest.VALUE_COMPARATOR); for (int i = 0; i < size; i++) { Assert.assertEquals(UnifiedMapAcceptanceTest.createVal(i), valuesArray[i]); } } @Test public void unifiedMapValuesIteratorRemove() { UnifiedMapAcceptanceTest.runUnifiedMapValuesIteratorRemove(0, 2); UnifiedMapAcceptanceTest.runUnifiedMapValuesIteratorRemove(1, 2); UnifiedMapAcceptanceTest.runUnifiedMapValuesIteratorRemove(2, 2); UnifiedMapAcceptanceTest.runUnifiedMapValuesIteratorRemove(3, 2); UnifiedMapAcceptanceTest.runUnifiedMapValuesIteratorRemove(0, 3); UnifiedMapAcceptanceTest.runUnifiedMapValuesIteratorRemove(1, 3); UnifiedMapAcceptanceTest.runUnifiedMapValuesIteratorRemove(2, 3); UnifiedMapAcceptanceTest.runUnifiedMapValuesIteratorRemove(3, 3); UnifiedMapAcceptanceTest.runUnifiedMapValuesIteratorRemove(0, 4); UnifiedMapAcceptanceTest.runUnifiedMapValuesIteratorRemove(1, 4); UnifiedMapAcceptanceTest.runUnifiedMapValuesIteratorRemove(2, 4); UnifiedMapAcceptanceTest.runUnifiedMapValuesIteratorRemove(3, 4); } private static void runUnifiedMapValuesIteratorRemove(int shift, int removeStride) { UnifiedMap map = UnifiedMap.newMap(); int size = 100000; for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); } Verify.assertSize(size, map); Collection values = map.values(); int count = 0; for (Iterator it = values.iterator(); it.hasNext(); ) { String value = it.next(); int x = Integer.parseInt(value.substring(1)); count++; if (x % removeStride == 0) { it.remove(); } } Assert.assertEquals(size, count); for (int i = 0; i < size; i++) { if (i % removeStride != 0) { Assert.assertTrue("map contains " + i + "for shift " + shift + " and remove stride " + removeStride, map .containsKey(new CollidingInt(i, shift))); Verify.assertContainsKeyValue(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i), map); } } } @Test public void unifiedMapValuesIteratorRemoveFlip() { UnifiedMapAcceptanceTest.runUnifiedMapValuesIteratorRemoveFlip(0, 2); UnifiedMapAcceptanceTest.runUnifiedMapValuesIteratorRemoveFlip(1, 2); UnifiedMapAcceptanceTest.runUnifiedMapValuesIteratorRemoveFlip(2, 2); UnifiedMapAcceptanceTest.runUnifiedMapValuesIteratorRemoveFlip(3, 2); UnifiedMapAcceptanceTest.runUnifiedMapValuesIteratorRemoveFlip(0, 3); UnifiedMapAcceptanceTest.runUnifiedMapValuesIteratorRemoveFlip(1, 3); UnifiedMapAcceptanceTest.runUnifiedMapValuesIteratorRemoveFlip(2, 3); UnifiedMapAcceptanceTest.runUnifiedMapValuesIteratorRemoveFlip(3, 3); UnifiedMapAcceptanceTest.runUnifiedMapValuesIteratorRemoveFlip(0, 4); UnifiedMapAcceptanceTest.runUnifiedMapValuesIteratorRemoveFlip(1, 4); UnifiedMapAcceptanceTest.runUnifiedMapValuesIteratorRemoveFlip(2, 4); UnifiedMapAcceptanceTest.runUnifiedMapValuesIteratorRemoveFlip(3, 4); } private static void runUnifiedMapValuesIteratorRemoveFlip(int shift, int removeStride) { UnifiedMap map = UnifiedMap.newMap(); int size = 100000; for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); } Verify.assertSize(size, map); Collection values = map.values(); int count = 0; for (Iterator it = values.iterator(); it.hasNext(); ) { String value = it.next(); int x = Integer.parseInt(value.substring(1)); count++; if (x % removeStride != 0) { it.remove(); } } Assert.assertEquals(size, count); for (int i = 0; i < size; i++) { if (i % removeStride == 0) { Assert.assertTrue("map contains " + i + "for shift " + shift + " and remove stride " + removeStride, map .containsKey(new CollidingInt(i, shift))); Verify.assertContainsKeyValue(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i), map); } } } @Test public void unifiedMapSerialize() { UnifiedMapAcceptanceTest.runUnifiedMapSerialize(0); UnifiedMapAcceptanceTest.runUnifiedMapSerialize(1); UnifiedMapAcceptanceTest.runUnifiedMapSerialize(2); UnifiedMapAcceptanceTest.runUnifiedMapSerialize(3); } private static void runUnifiedMapSerialize(int shift) { UnifiedMap map = UnifiedMap.newMap(); int size = 100000; for (int i = 0; i < size; i++) { map.put(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)); } String nullVal = "Y99999999"; map.put(null, nullVal); map = SerializeTestHelper.serializeDeserialize(map); Verify.assertSize(size + 1, map); for (int i = 0; i < size; i++) { Verify.assertContainsKey(new CollidingInt(i, shift), map); Verify.assertContainsKeyValue(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i), map); } Assert.assertTrue(map.containsKey(null)); Assert.assertEquals(nullVal, map.get(null)); Set keySet = SerializeTestHelper.serializeDeserialize(map.keySet()); Verify.assertSize(size + 1, keySet); for (int i = 0; i < size; i++) { Verify.assertContains(new CollidingInt(i, shift), keySet); } Verify.assertContains(null, keySet); Set> entrySet = SerializeTestHelper.serializeDeserialize(map.entrySet()); Verify.assertSize(size + 1, entrySet); for (int i = 0; i < size; i++) { Verify.assertContains(new Entry(new CollidingInt(i, shift), UnifiedMapAcceptanceTest.createVal(i)), entrySet); } Verify.assertContains(new Entry(null, nullVal), entrySet); for (Map.Entry e : entrySet) { CollidingInt key = e.getKey(); if (key == null) { Assert.assertEquals(nullVal, e.getValue()); } else { Assert.assertEquals(UnifiedMapAcceptanceTest.createVal(key.getValue()), e.getValue()); } } List values = new ArrayList(SerializeTestHelper.serializeDeserialize(map.values())); Collections.sort(values, UnifiedMapAcceptanceTest.VALUE_COMPARATOR); Verify.assertSize(size + 1, values); for (int i = 0; i < size; i++) { Assert.assertEquals(UnifiedMapAcceptanceTest.createVal(i), values.get(i)); } Assert.assertEquals(nullVal, values.get(values.size() - 1)); } public void perfTestUnifiedMapGet() { for (int i = 1000000; i > 10; i /= 10) { this.runGetTest(new UnifiedMap(), "Unified Map", i); } } public void perfTestJdkHashMapGet() { for (int i = 1000000; i > 10; i /= 10) { this.runGetTest(new HashMap(), "JDK HashMap", i); } } public void perfTestUnifiedMapCollidingGet() { this.runCollidingGetTest(new UnifiedMap(), "Unified Map", 1); this.runCollidingGetTest(new UnifiedMap(), "Unified Map", 2); this.runCollidingGetTest(new UnifiedMap(), "Unified Map", 3); } public void perfTestJdkHashMapCollidingGet() { this.runCollidingGetTest(new HashMap(), "JDK HashMap", 1); this.runCollidingGetTest(new HashMap(), "JDK HashMap", 2); this.runCollidingGetTest(new HashMap(), "JDK HashMap", 3); } private void runGetTest(Map map, String mapName, int size) { Integer[] keys = UnifiedMapAcceptanceTest.createMap((Map) (Map) map, size); UnifiedMapAcceptanceTest.sleep(100L); int n = 10000000 / size; int max = 4; for (int i = 0; i < max; i++) { long startTime = System.nanoTime(); UnifiedMapAcceptanceTest.runMapGet(map, keys, n); long runTimes = System.nanoTime() - startTime; LOGGER.info("{} get: {} ns per get on map size {}", mapName, (double) runTimes / (double) n / size, size); } map = null; System.gc(); Thread.yield(); System.gc(); Thread.yield(); } private static Integer[] createMap(Map map, int size) { Integer[] keys = new Integer[size]; for (int i = 0; i < size; i++) { keys[i] = i; map.put(i, UnifiedMapAcceptanceTest.createVal(i)); } Verify.assertSize(size, map); return keys; } private static void runMapGet(Map map, Object[] keys, int n) { for (int i = 0; i < n; i++) { for (Object key : keys) { map.get(key); } } } private void runCollidingGetTest(Map map, String mapName, int shift) { int size = 100000; Object[] keys = UnifiedMapAcceptanceTest.createCollidingMap(map, size, shift); UnifiedMapAcceptanceTest.sleep(100L); int n = 100; int max = 5; for (int i = 0; i < max; i++) { long startTime = System.nanoTime(); UnifiedMapAcceptanceTest.runMapGet(map, keys, n); long runTimes = System.nanoTime() - startTime; LOGGER.info("{} with {} collisions. get: {} ns per get", mapName, 1 << shift, (double) runTimes / (double) n / size); } } private static CollidingInt[] createCollidingMap(Map map, int size, int shift) { CollidingInt[] keys = new CollidingInt[size]; for (int i = 0; i < size; i++) { keys[i] = new CollidingInt(i, shift); map.put(keys[i], UnifiedMapAcceptanceTest.createVal(i)); } Assert.assertEquals(size, map.size()); return keys; } private static void sleep(long millis) { long now = System.currentTimeMillis(); long target = now + millis; while (now < target) { try { Thread.sleep(target - now); } catch (InterruptedException ignored) { Assert.fail("why were we interrupted?"); } now = System.currentTimeMillis(); } } public static final class Entry implements Map.Entry { private final CollidingInt key; private String value; private Entry(CollidingInt key, String value) { this.key = key; this.value = value; } @Override public CollidingInt getKey() { return this.key; } @Override public String getValue() { return this.value; } @Override public String setValue(String value) { String ret = this.value; this.value = value; return ret; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof Map.Entry)) { return false; } Map.Entry entry = (Map.Entry) o; if (!Comparators.nullSafeEquals(this.key, entry.getKey())) { return false; } return Comparators.nullSafeEquals(this.value, entry.getValue()); } @Override public int hashCode() { return this.key == null ? 0 : this.key.hashCode(); } } @Test public void unifiedMapToString() { UnifiedMap map = UnifiedMap.newWithKeysValues(1, "One", 2, "Two"); Verify.assertContains("1=One", map.toString()); Verify.assertContains("2=Two", map.toString()); map.put("value is 'self'", map); Verify.assertContains("value is 'self'=(this Map)", map.toString()); } } gs-collections-5.1.0/acceptance-tests/src/test/java/com/gs/collections/impl/parallel/000077500000000000000000000000001234315411400306175ustar00rootroot00000000000000ParallelArrayIterateAcceptanceTest.java000066400000000000000000000057051234315411400402720ustar00rootroot00000000000000gs-collections-5.1.0/acceptance-tests/src/test/java/com/gs/collections/impl/parallel/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.parallel; import java.util.concurrent.ExecutorService; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.set.MutableSet; import com.gs.collections.impl.factory.Lists; import com.gs.collections.impl.set.mutable.MultiReaderUnifiedSet; import org.junit.Assert; import org.junit.Test; public class ParallelArrayIterateAcceptanceTest { private int count = 0; private final MutableSet threadNames = MultiReaderUnifiedSet.newSet(); @Test public void oneLevelCall() { new RecursiveProcedure().value(1); synchronized (this) { Assert.assertEquals("all iterations completed", 20000, this.count); } } @Test public void nestedCall() { new RecursiveProcedure().value(2); synchronized (this) { Assert.assertEquals("all iterations completed", 419980, this.count); } Assert.assertTrue("uses multiple threads", this.threadNames.size() > 1); } private class RecursiveProcedure implements Procedure { private static final long serialVersionUID = 1L; private final ExecutorService executorService = ParallelIterate.newPooledExecutor("ParallelArrayIterateAcceptanceTest", false); @Override public void value(Integer object) { int level = object.intValue(); if (level > 0) { ParallelArrayIterateAcceptanceTest.this.threadNames.add(Thread.currentThread().getName()); this.executeParallelIterate(level - 1, this.executorService); } else { this.simulateWork(); } } private void simulateWork() { synchronized (ParallelArrayIterateAcceptanceTest.this) { ParallelArrayIterateAcceptanceTest.this.count++; } } private void executeParallelIterate(int level, ExecutorService executorService) { MutableList items = Lists.mutable.of(); for (int i = 0; i < 20000; i++) { items.add(i % 1000 == 0 ? level : 0); } ParallelIterate.forEach(items, new RecursiveProcedure(), executorService); } } } ParallelIterateAcceptanceTest.java000066400000000000000000000672701234315411400373000ustar00rootroot00000000000000gs-collections-5.1.0/acceptance-tests/src/test/java/com/gs/collections/impl/parallel/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.parallel; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicInteger; import com.gs.collections.api.RichIterable; import com.gs.collections.api.bag.Bag; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.list.ImmutableList; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.map.MapIterable; import com.gs.collections.api.map.MutableMap; import com.gs.collections.api.set.MutableSet; import com.gs.collections.impl.bag.mutable.HashBag; import com.gs.collections.impl.block.factory.Functions; import com.gs.collections.impl.block.factory.HashingStrategies; import com.gs.collections.impl.block.factory.Predicates; import com.gs.collections.impl.block.factory.Procedures; import com.gs.collections.impl.factory.Lists; import com.gs.collections.impl.list.Interval; import com.gs.collections.impl.list.mutable.ArrayListAdapter; import com.gs.collections.impl.list.mutable.CompositeFastList; import com.gs.collections.impl.list.mutable.FastList; import com.gs.collections.impl.list.mutable.ListAdapter; import com.gs.collections.impl.map.mutable.UnifiedMap; import com.gs.collections.impl.set.mutable.MultiReaderUnifiedSet; import com.gs.collections.impl.set.mutable.UnifiedSet; import com.gs.collections.impl.set.strategy.mutable.UnifiedSetWithHashingStrategy; import com.gs.collections.impl.test.Verify; import com.gs.collections.impl.utility.ArrayIterate; import com.gs.collections.impl.utility.LazyIterate; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; public class ParallelIterateAcceptanceTest { private static final Procedure EXCEPTION_PROCEDURE = value -> { throw new RuntimeException("Thread death on its way!"); }; private static final ObjectIntProcedure EXCEPTION_OBJECT_INT_PROCEDURE = (object, index) -> { throw new RuntimeException("Thread death on its way!"); }; private static final Function> INT_TO_TWO_STRINGS = integer -> Lists.fixedSize.of(integer.toString(), integer.toString()); private static final Function0 ATOMIC_INTEGER_NEW = AtomicInteger::new; private static final Function EVEN_OR_ODD = value -> value % 2 == 0 ? "Even" : "Odd"; private int count; private final MutableSet threadNames = MultiReaderUnifiedSet.newSet(); private ImmutableList> iterables; private final ExecutorService executor = Executors.newFixedThreadPool(2); @Before public void setUp() { Interval interval = Interval.oneTo(20000); this.iterables = Lists.immutable.of( interval.toList(), interval.toList().asUnmodifiable(), interval.toList().asSynchronized(), interval.toList().toImmutable(), interval.toSet(), interval.toSet().asUnmodifiable(), interval.toSet().asSynchronized(), interval.toSet().toImmutable(), interval.toBag(), interval.toBag().asUnmodifiable(), interval.toBag().asSynchronized(), interval.toBag().toImmutable(), interval.toSortedSet(), interval.toSortedSet().asUnmodifiable(), interval.toSortedSet().asSynchronized(), interval.toSortedSet().toImmutable(), interval.toMap(Functions.getPassThru(), Functions.getPassThru()), interval.toMap(Functions.getPassThru(), Functions.getPassThru()).asUnmodifiable(), interval.toMap(Functions.getPassThru(), Functions.getPassThru()).asSynchronized(), interval.toMap(Functions.getPassThru(), Functions.getPassThru()).toImmutable(), ArrayListAdapter.newList().withAll(interval), ArrayListAdapter.newList().withAll(interval).asUnmodifiable(), ArrayListAdapter.newList().withAll(interval).asSynchronized(), new CompositeFastList().withAll(interval.toList()), new CompositeFastList().withAll(interval.toList()).asUnmodifiable(), new CompositeFastList().withAll(interval.toList()).asSynchronized(), new CompositeFastList().withAll(interval.toList()).toImmutable(), ListAdapter.adapt(new LinkedList()).withAll(interval), ListAdapter.adapt(new LinkedList()).withAll(interval).asUnmodifiable(), ListAdapter.adapt(new LinkedList()).withAll(interval).asSynchronized(), UnifiedSetWithHashingStrategy.newSet(HashingStrategies.defaultStrategy()).withAll(interval), UnifiedSetWithHashingStrategy.newSet(HashingStrategies.defaultStrategy()).withAll(interval).asUnmodifiable(), UnifiedSetWithHashingStrategy.newSet(HashingStrategies.defaultStrategy()).withAll(interval).asSynchronized(), UnifiedSetWithHashingStrategy.newSet(HashingStrategies.defaultStrategy()).withAll(interval).toImmutable()); } @After public void tearDown() { this.executor.shutdown(); } @Test public void testOneLevelCall() { new RecursiveProcedure().value(1); synchronized (this) { Assert.assertEquals("all iterations completed", 20000, this.count); } } @Test public void testNestedCall() { new RecursiveProcedure().value(2); synchronized (this) { Assert.assertEquals("all iterations completed", 419980, this.count); } Assert.assertTrue("uses multiple threads", this.threadNames.size() > 1); } @Test public void testForEachUsingSet() { //Tests the default batch size calculations IntegerSum sum = new IntegerSum(0); MutableSet set = Interval.toSet(1, 10000); ParallelIterate.forEach(set, new SumProcedure(sum), new SumCombiner(sum)); Assert.assertEquals(50005000, sum.getSum()); //Testing batch size 1 IntegerSum sum2 = new IntegerSum(0); UnifiedSet set2 = UnifiedSet.newSet(Interval.oneTo(100)); ParallelIterate.forEach(set2, new SumProcedure(sum2), new SumCombiner(sum2), 1, set2.getBatchCount(set2.size())); Assert.assertEquals(5050, sum2.getSum()); //Testing an uneven batch size IntegerSum sum3 = new IntegerSum(0); UnifiedSet set3 = UnifiedSet.newSet(Interval.oneTo(100)); ParallelIterate.forEach(set3, new SumProcedure(sum3), new SumCombiner(sum3), 1, set3.getBatchCount(13)); Assert.assertEquals(5050, sum3.getSum()); //Testing divideByZero exception by passing 1 as batchSize IntegerSum sum4 = new IntegerSum(0); UnifiedSet set4 = UnifiedSet.newSet(Interval.oneTo(100)); ParallelIterate.forEach(set4, new SumProcedure(sum4), new SumCombiner(sum4), 1); Assert.assertEquals(5050, sum4.getSum()); } @Test public void testForEachUsingMap() { //Test the default batch size calculations IntegerSum sum1 = new IntegerSum(0); MutableMap map1 = Interval.fromTo(1, 10000).toMap(String::valueOf, Functions.getIntegerPassThru()); ParallelIterate.forEach(map1, new SumProcedure(sum1), new SumCombiner(sum1)); Assert.assertEquals(50005000, sum1.getSum()); //Testing batch size 1 IntegerSum sum2 = new IntegerSum(0); UnifiedMap map2 = (UnifiedMap) Interval.fromTo(1, 100).toMap(String::valueOf, Functions.getIntegerPassThru()); ParallelIterate.forEach(map2, new SumProcedure(sum2), new SumCombiner(sum2), 1, map2.getBatchCount(map2.size())); Assert.assertEquals(5050, sum2.getSum()); //Testing an uneven batch size IntegerSum sum3 = new IntegerSum(0); UnifiedMap set3 = (UnifiedMap) Interval.fromTo(1, 100).toMap(String::valueOf, Functions.getIntegerPassThru()); ParallelIterate.forEach(set3, new SumProcedure(sum3), new SumCombiner(sum3), 1, set3.getBatchCount(13)); Assert.assertEquals(5050, sum3.getSum()); } @Test public void testForEach() { IntegerSum sum1 = new IntegerSum(0); List list1 = createIntegerList(16); ParallelIterate.forEach(list1, new SumProcedure(sum1), new SumCombiner(sum1), 1, list1.size() / 2); Assert.assertEquals(16, sum1.getSum()); IntegerSum sum2 = new IntegerSum(0); List list2 = createIntegerList(7); ParallelIterate.forEach(list2, new SumProcedure(sum2), new SumCombiner(sum2)); Assert.assertEquals(7, sum2.getSum()); IntegerSum sum3 = new IntegerSum(0); List list3 = createIntegerList(15); ParallelIterate.forEach(list3, new SumProcedure(sum3), new SumCombiner(sum3), 1, list3.size() / 2); Assert.assertEquals(15, sum3.getSum()); IntegerSum sum4 = new IntegerSum(0); List list4 = createIntegerList(35); ParallelIterate.forEach(list4, new SumProcedure(sum4), new SumCombiner(sum4)); Assert.assertEquals(35, sum4.getSum()); IntegerSum sum5 = new IntegerSum(0); MutableList list5 = FastList.newList(list4); ParallelIterate.forEach(list5, new SumProcedure(sum5), new SumCombiner(sum5)); Assert.assertEquals(35, sum5.getSum()); IntegerSum sum6 = new IntegerSum(0); List list6 = createIntegerList(40); ParallelIterate.forEach(list6, new SumProcedure(sum6), new SumCombiner(sum6), 1, list6.size() / 2); Assert.assertEquals(40, sum6.getSum()); IntegerSum sum7 = new IntegerSum(0); MutableList list7 = FastList.newList(list6); ParallelIterate.forEach(list7, new SumProcedure(sum7), new SumCombiner(sum7), 1, list6.size() / 2); Assert.assertEquals(40, sum7.getSum()); } @Test public void testForEachImmutableList() { IntegerSum sum1 = new IntegerSum(0); ImmutableList list1 = Lists.immutable.ofAll(createIntegerList(16)); ParallelIterate.forEach(list1, new SumProcedure(sum1), new SumCombiner(sum1), 1, list1.size() / 2); Assert.assertEquals(16, sum1.getSum()); IntegerSum sum2 = new IntegerSum(0); ImmutableList list2 = Lists.immutable.ofAll(createIntegerList(7)); ParallelIterate.forEach(list2, new SumProcedure(sum2), new SumCombiner(sum2)); Assert.assertEquals(7, sum2.getSum()); IntegerSum sum3 = new IntegerSum(0); ImmutableList list3 = Lists.immutable.ofAll(createIntegerList(15)); ParallelIterate.forEach(list3, new SumProcedure(sum3), new SumCombiner(sum3), 1, list3.size() / 2); Assert.assertEquals(15, sum3.getSum()); IntegerSum sum4 = new IntegerSum(0); ImmutableList list4 = Lists.immutable.ofAll(createIntegerList(35)); ParallelIterate.forEach(list4, new SumProcedure(sum4), new SumCombiner(sum4)); Assert.assertEquals(35, sum4.getSum()); IntegerSum sum5 = new IntegerSum(0); ImmutableList list5 = FastList.newList(list4).toImmutable(); ParallelIterate.forEach(list5, new SumProcedure(sum5), new SumCombiner(sum5)); Assert.assertEquals(35, sum5.getSum()); IntegerSum sum6 = new IntegerSum(0); ImmutableList list6 = Lists.immutable.ofAll(createIntegerList(40)); ParallelIterate.forEach(list6, new SumProcedure(sum6), new SumCombiner(sum6), 1, list6.size() / 2); Assert.assertEquals(40, sum6.getSum()); IntegerSum sum7 = new IntegerSum(0); ImmutableList list7 = FastList.newList(list6).toImmutable(); ParallelIterate.forEach(list7, new SumProcedure(sum7), new SumCombiner(sum7), 1, list6.size() / 2); Assert.assertEquals(40, sum7.getSum()); } @Test public void testForEachWithException() { Verify.assertThrows(RuntimeException.class, () -> ParallelIterate.forEach( createIntegerList(5), new PassThruProcedureFactory>(EXCEPTION_PROCEDURE), new PassThruCombiner>(), 1, 5)); } @Test public void testForEachWithIndexToArrayUsingFastListSerialPath() { Integer[] array = new Integer[200]; FastList list = (FastList) Interval.oneTo(200).toList(); Assert.assertTrue(ArrayIterate.allSatisfy(array, Predicates.isNull())); ParallelIterate.forEachWithIndex(list, (each, index) -> { array[index] = each; }); Assert.assertArrayEquals(array, list.toArray(new Integer[]{})); } @Test public void testForEachWithIndexToArrayUsingFastList() { Integer[] array = new Integer[200]; FastList list = (FastList) Interval.oneTo(200).toList(); Assert.assertTrue(ArrayIterate.allSatisfy(array, Predicates.isNull())); ParallelIterate.forEachWithIndex(list, (each, index) -> { array[index] = each; }, 10, 10); Assert.assertArrayEquals(array, list.toArray(new Integer[]{})); } @Test public void testForEachWithIndexToArrayUsingImmutableList() { Integer[] array = new Integer[200]; ImmutableList list = Interval.oneTo(200).toList().toImmutable(); Assert.assertTrue(ArrayIterate.allSatisfy(array, Predicates.isNull())); ParallelIterate.forEachWithIndex(list, (each, index) -> { array[index] = each; }, 10, 10); Assert.assertArrayEquals(array, list.toArray(new Integer[]{})); } @Test public void testForEachWithIndexToArrayUsingArrayList() { Integer[] array = new Integer[200]; List list = new ArrayList(Interval.oneTo(200)); Assert.assertTrue(ArrayIterate.allSatisfy(array, Predicates.isNull())); ParallelIterate.forEachWithIndex(list, (each, index) -> { array[index] = each; }, 10, 10); Assert.assertArrayEquals(array, list.toArray(new Integer[]{})); } @Test public void testForEachWithIndexToArrayUsingFixedArrayList() { Integer[] array = new Integer[10]; List list = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); Assert.assertTrue(ArrayIterate.allSatisfy(array, Predicates.isNull())); ParallelIterate.forEachWithIndex(list, (each, index) -> { array[index] = each; }, 1, 2); Assert.assertArrayEquals(array, list.toArray(new Integer[list.size()])); } @Test public void testForEachWithIndexException() { Verify.assertThrows(RuntimeException.class, () -> ParallelIterate.forEachWithIndex( createIntegerList(5), new PassThruObjectIntProcedureFactory>(EXCEPTION_OBJECT_INT_PROCEDURE), new PassThruCombiner>(), 1, 5)); } @Test public void select() { this.iterables.forEach(Procedures.cast(this::basicSelect)); } private void basicSelect(RichIterable iterable) { Collection actual1 = ParallelIterate.select(iterable, Predicates.greaterThan(10000)); Collection actual2 = ParallelIterate.select(iterable, Predicates.greaterThan(10000), HashBag.newBag(), 3, this.executor, true); Collection actual3 = ParallelIterate.select(iterable, Predicates.greaterThan(10000), true); RichIterable expected = iterable.select(Predicates.greaterThan(10000)); Assert.assertEquals(expected.getClass().getSimpleName() + '/' + actual1.getClass().getSimpleName(), expected, actual1); Assert.assertEquals(expected.getClass().getSimpleName() + '/' + actual2.getClass().getSimpleName(), expected.toBag(), actual2); Assert.assertEquals(expected.getClass().getSimpleName() + '/' + actual3.getClass().getSimpleName(), expected.toBag(), HashBag.newBag(actual3)); } @Test public void selectSortedSet() { RichIterable iterable = Interval.oneTo(20000).toSortedSet(); Collection actual1 = ParallelIterate.select(iterable, Predicates.greaterThan(10000)); Collection actual2 = ParallelIterate.select(iterable, Predicates.greaterThan(10000), true); RichIterable expected = iterable.select(Predicates.greaterThan(10000)); Assert.assertSame(expected.getClass(), actual1.getClass()); Assert.assertSame(expected.getClass(), actual2.getClass()); Assert.assertEquals(expected.getClass().getSimpleName() + '/' + actual1.getClass().getSimpleName(), expected, actual1); Assert.assertEquals(expected.getClass().getSimpleName() + '/' + actual2.getClass().getSimpleName(), expected, actual2); } @Test public void count() { this.iterables.forEach(Procedures.cast(this::basicCount)); } private void basicCount(RichIterable listIterable) { int actual1 = ParallelIterate.count(listIterable, Predicates.greaterThan(10000)); int actual2 = ParallelIterate.count(listIterable, Predicates.greaterThan(10000), 11, this.executor); Assert.assertEquals(10000, actual1); Assert.assertEquals(10000, actual2); } @Test public void reject() { this.iterables.forEach(Procedures.cast(this::basicReject)); } private void basicReject(RichIterable iterable) { Collection actual1 = ParallelIterate.reject(iterable, Predicates.greaterThan(10000)); Collection actual2 = ParallelIterate.reject(iterable, Predicates.greaterThan(10000), HashBag.newBag(), 3, this.executor, true); Collection actual3 = ParallelIterate.reject(iterable, Predicates.greaterThan(10000), true); RichIterable expected = iterable.reject(Predicates.greaterThan(10000)); Assert.assertEquals(expected.getClass().getSimpleName() + '/' + actual1.getClass().getSimpleName(), expected, actual1); Assert.assertEquals(expected.getClass().getSimpleName() + '/' + actual2.getClass().getSimpleName(), expected.toBag(), actual2); Assert.assertEquals(expected.getClass().getSimpleName() + '/' + actual3.getClass().getSimpleName(), expected.toBag(), HashBag.newBag(actual3)); } @Test public void collect() { this.iterables.forEach(Procedures.cast(this::basicCollect)); } private void basicCollect(RichIterable iterable) { Collection actual1 = ParallelIterate.collect(iterable, String::valueOf); Collection actual2 = ParallelIterate.collect(iterable, String::valueOf, HashBag.newBag(), 3, this.executor, false); Collection actual3 = ParallelIterate.collect(iterable, String::valueOf, true); RichIterable expected = iterable.collect(String::valueOf); Verify.assertSize(20000, actual1); Verify.assertContains(String.valueOf(20000), actual1); Assert.assertEquals(expected.getClass().getSimpleName() + '/' + actual1.getClass().getSimpleName(), expected, actual1); Assert.assertEquals(expected.getClass().getSimpleName() + '/' + actual2.getClass().getSimpleName(), expected.toBag(), actual2); Assert.assertEquals(expected.getClass().getSimpleName() + '/' + actual3.getClass().getSimpleName(), expected.toBag(), HashBag.newBag(actual3)); } @Test public void collectIf() { this.iterables.forEach(Procedures.cast(this::basicCollectIf)); } private void basicCollectIf(RichIterable collection) { Predicate greaterThan = Predicates.greaterThan(10000); Collection actual1 = ParallelIterate.collectIf(collection, greaterThan, String::valueOf); Collection actual2 = ParallelIterate.collectIf(collection, greaterThan, String::valueOf, HashBag.newBag(), 3, this.executor, true); Collection actual3 = ParallelIterate.collectIf(collection, greaterThan, String::valueOf, HashBag.newBag(), 3, this.executor, true); Bag expected = collection.collectIf(greaterThan, String::valueOf).toBag(); Verify.assertSize(10000, actual1); Verify.assertNotContains(String.valueOf(9000), actual1); Verify.assertNotContains(String.valueOf(21000), actual1); Verify.assertContains(String.valueOf(15976), actual1); Assert.assertEquals(expected.getClass().getSimpleName() + '/' + actual1.getClass().getSimpleName(), expected, HashBag.newBag(actual1)); Assert.assertEquals(expected.getClass().getSimpleName() + '/' + actual2.getClass().getSimpleName(), expected, actual2); Assert.assertEquals(expected.getClass().getSimpleName() + '/' + actual3.getClass().getSimpleName(), expected, actual3); } @Test public void flatCollect() { this.iterables.forEach(Procedures.cast(this::basicFlatCollect)); } private void basicFlatCollect(RichIterable iterable) { Collection actual1 = ParallelIterate.flatCollect(iterable, INT_TO_TWO_STRINGS); Collection actual2 = ParallelIterate.flatCollect(iterable, INT_TO_TWO_STRINGS, HashBag.newBag(), 3, this.executor, false); Collection actual3 = ParallelIterate.flatCollect(iterable, INT_TO_TWO_STRINGS, true); RichIterable expected1 = iterable.flatCollect(INT_TO_TWO_STRINGS); RichIterable expected2 = iterable.flatCollect(INT_TO_TWO_STRINGS, HashBag.newBag()); Verify.assertContains(String.valueOf(20000), actual1); Assert.assertEquals(expected1.getClass().getSimpleName() + '/' + actual1.getClass().getSimpleName(), expected1, actual1); Assert.assertEquals(expected2.getClass().getSimpleName() + '/' + actual2.getClass().getSimpleName(), expected2, actual2); Assert.assertEquals(expected1.getClass().getSimpleName() + '/' + actual3.getClass().getSimpleName(), expected1.toBag(), HashBag.newBag(actual3)); } @Test public void aggregateInPlaceBy() { Procedure2 countAggregator = (aggregate, value) -> { aggregate.incrementAndGet(); }; List list = Interval.oneTo(20000); MutableMap aggregation = ParallelIterate.aggregateInPlaceBy(list, EVEN_OR_ODD, ATOMIC_INTEGER_NEW, countAggregator); Assert.assertEquals(10000, aggregation.get("Even").intValue()); Assert.assertEquals(10000, aggregation.get("Odd").intValue()); ParallelIterate.aggregateInPlaceBy(list, EVEN_OR_ODD, ATOMIC_INTEGER_NEW, countAggregator, aggregation); Assert.assertEquals(20000, aggregation.get("Even").intValue()); Assert.assertEquals(20000, aggregation.get("Odd").intValue()); } @Test public void aggregateInPlaceByWithBatchSize() { MutableList list = LazyIterate.adapt(Collections.nCopies(1000, 1)) .concatenate(Collections.nCopies(2000, 2)) .concatenate(Collections.nCopies(3000, 3)) .toList(); Collections.shuffle(list); MapIterable aggregation = ParallelIterate.aggregateInPlaceBy(list, String::valueOf, ATOMIC_INTEGER_NEW, AtomicInteger::addAndGet, 100); Assert.assertEquals(1000, aggregation.get("1").intValue()); Assert.assertEquals(4000, aggregation.get("2").intValue()); Assert.assertEquals(9000, aggregation.get("3").intValue()); } private static List createIntegerList(int size) { return Collections.nCopies(size, Integer.valueOf(1)); } private class RecursiveProcedure implements Procedure { private static final long serialVersionUID = 1L; private final ExecutorService executorService = ParallelIterate.newPooledExecutor("ParallelIterateTest", false); @Override public void value(Integer level) { if (level > 0) { ParallelIterateAcceptanceTest.this.threadNames.add(Thread.currentThread().getName()); this.executeParallelIterate(level - 1, this.executorService); } else { this.simulateWork(); } } private void simulateWork() { synchronized (ParallelIterateAcceptanceTest.this) { ParallelIterateAcceptanceTest.this.count++; } } private void executeParallelIterate(int level, ExecutorService executorService) { MutableList items = Lists.mutable.of(); for (int i = 0; i < 20000; i++) { items.add(i % 1000 == 0 ? level : 0); } ParallelIterate.forEach(items, new RecursiveProcedure(), executorService); } } public static final class IntegerSum { private int sum = 0; public IntegerSum(int newSum) { this.sum = newSum; } public IntegerSum add(int value) { this.sum += value; return this; } public int getSum() { return this.sum; } } public static final class SumProcedure implements Procedure, Function2, ProcedureFactory { private static final long serialVersionUID = 1L; private final IntegerSum sum; public SumProcedure(IntegerSum newSum) { this.sum = newSum; } @Override public SumProcedure create() { return new SumProcedure(new IntegerSum(0)); } @Override public IntegerSum value(IntegerSum s1, Integer s2) { return s1.add(s2); } @Override public void value(Integer object) { this.sum.add(object); } public int getSum() { return this.sum.getSum(); } } public static final class SumCombiner extends AbstractProcedureCombiner { private static final long serialVersionUID = 1L; private final IntegerSum sum; public SumCombiner(IntegerSum initialSum) { super(true); this.sum = initialSum; } @Override public void combineOne(SumProcedure sumProcedure) { this.sum.add(sumProcedure.getSum()); } } } gs-collections-5.1.0/acceptance-tests/src/test/java/com/gs/collections/impl/set/000077500000000000000000000000001234315411400276165ustar00rootroot00000000000000gs-collections-5.1.0/acceptance-tests/src/test/java/com/gs/collections/impl/set/mutable/000077500000000000000000000000001234315411400312475ustar00rootroot00000000000000UnifiedSetAcceptanceTest.java000066400000000000000000000627511234315411400367140ustar00rootroot00000000000000gs-collections-5.1.0/acceptance-tests/src/test/java/com/gs/collections/impl/set/mutable/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.set.mutable; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Random; import java.util.Set; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.set.MutableSet; import com.gs.collections.impl.CollidingInt; import com.gs.collections.impl.block.factory.Procedures; import com.gs.collections.impl.factory.Lists; import com.gs.collections.impl.list.mutable.FastList; import com.gs.collections.impl.test.SerializeTestHelper; import com.gs.collections.impl.test.Verify; import org.junit.Assert; import org.junit.Test; /** * JUnit test suite for {@link UnifiedSet}. */ public class UnifiedSetAcceptanceTest { @Test public void testUnifiedSetWithCollisions() { for (int removeStride = 2; removeStride < 9; removeStride++) { assertUnifiedSetWithCollisions(0, removeStride); assertUnifiedSetWithCollisions(1, removeStride); assertUnifiedSetWithCollisions(2, removeStride); assertUnifiedSetWithCollisions(3, removeStride); assertUnifiedSetWithCollisions(4, removeStride); } } private static void assertUnifiedSetWithCollisions(int shift, int removeStride) { UnifiedSet set = UnifiedSet.newSet(); int size = 84000; // divisible by every integer between 2 and 8 for (int i = 0; i < size; i++) { Assert.assertTrue(set.add(new CollidingInt(i, shift))); } Verify.assertSize(size, set); for (int i = 0; i < size; i++) { Verify.assertContains(new CollidingInt(i, shift), set); } for (int i = 0; i < size; i += removeStride) { Assert.assertTrue(set.remove(new CollidingInt(i, shift))); } Verify.assertSize(size - size / removeStride, set); for (int i = 0; i < size; i++) { if (i % removeStride == 0) { Verify.assertNotContains(new CollidingInt(i, shift), set); } else { Verify.assertContains(new CollidingInt(i, shift), set); } } for (int i = 0; i < size; i++) { set.remove(new CollidingInt(i, shift)); } Verify.assertEmpty(set); } @Test public void testUnifiedSetWithCollisionsAndNullKey() { for (int removeStride = 2; removeStride < 9; removeStride++) { setupAndAssertUnifiedSetWithCollisionsAndNullKey(0, removeStride); setupAndAssertUnifiedSetWithCollisionsAndNullKey(1, removeStride); setupAndAssertUnifiedSetWithCollisionsAndNullKey(2, removeStride); setupAndAssertUnifiedSetWithCollisionsAndNullKey(3, removeStride); setupAndAssertUnifiedSetWithCollisionsAndNullKey(4, removeStride); } } private static void setupAndAssertUnifiedSetWithCollisionsAndNullKey(int shift, int removeStride) { UnifiedSet set = UnifiedSet.newSet(); Verify.assertEmpty(set); int size = 84000; for (int i = 0; i < size; i++) { Assert.assertTrue(set.add(new CollidingInt(i, shift))); } set.add(null); UnifiedSet clone = set.clone(); assertUnifiedSetWithCollisionsAndNullKey(shift, removeStride, clone, size); assertUnifiedSetWithCollisionsAndNullKey(shift, removeStride, set, size); } private static void assertUnifiedSetWithCollisionsAndNullKey( int shift, int removeStride, UnifiedSet set, int size) { Verify.assertSize(size + 1, set); for (int i = 0; i < size; i++) { Verify.assertContains(new CollidingInt(i, shift), set); } Verify.assertContains(null, set); for (int i = 0; i < size; i += removeStride) { Assert.assertTrue(set.remove(new CollidingInt(i, shift))); } Verify.assertSize(size - size / removeStride + 1, set); for (int i = 0; i < size; i++) { if (i % removeStride != 0) { Verify.assertContains(new CollidingInt(i, shift), set); } } Verify.assertContains(null, set); set.remove(null); Verify.assertNotContains(null, set); } @Test public void testUnifiedSet() { UnifiedSet set = UnifiedSet.newSet(); int size = 100000; for (int i = 0; i < size; i++) { Assert.assertTrue(set.add(i)); } Verify.assertSize(size, set); for (int i = 0; i < size; i++) { Verify.assertContains(i, set); } for (int i = 0; i < size; i += 2) { Assert.assertTrue(set.remove(i)); } Verify.assertSize(size / 2, set); for (int i = 1; i < size; i += 2) { Verify.assertContains(i, set); } } @Test public void testUnifiedSetClear() { assertUnifiedSetClear(0); assertUnifiedSetClear(1); assertUnifiedSetClear(2); assertUnifiedSetClear(3); } private static void assertUnifiedSetClear(int shift) { UnifiedSet set = UnifiedSet.newSet(); int size = 100000; for (int i = 0; i < size; i++) { Assert.assertTrue(set.add(new CollidingInt(i, shift))); } set.clear(); Verify.assertEmpty(set); for (int i = 0; i < size; i++) { Verify.assertNotContains(new CollidingInt(i, shift), set); } } @Test public void testUnifiedSetForEach() { assertUnifiedSetForEach(0); assertUnifiedSetForEach(1); assertUnifiedSetForEach(2); assertUnifiedSetForEach(3); } private static void assertUnifiedSetForEach(int shift) { UnifiedSet set = UnifiedSet.newSet(); int size = 100000; for (int i = 0; i < size; i++) { Assert.assertTrue(set.add(new CollidingInt(i, shift))); } MutableList keys = FastList.newList(size); set.forEach(Procedures.cast(keys::add)); Verify.assertSize(size, keys); Collections.sort(keys); for (int i = 0; i < size; i++) { Verify.assertItemAtIndex(new CollidingInt(i, shift), i, keys); } } @Test public void testUnifiedSetForEachWith() { assertUnifiedSetForEachWith(0); assertUnifiedSetForEachWith(1); assertUnifiedSetForEachWith(2); assertUnifiedSetForEachWith(3); } private static void assertUnifiedSetForEachWith(int shift) { UnifiedSet set = UnifiedSet.newSet(); int size = 100000; for (int i = 0; i < size; i++) { Assert.assertTrue(set.add(new CollidingInt(i, shift))); } MutableList keys = FastList.newList(size); set.forEachWith((key, s) -> { Assert.assertEquals("foo", s); keys.add(key); }, "foo"); Verify.assertSize(size, keys); Collections.sort(keys); for (int i = 0; i < size; i++) { Verify.assertItemAtIndex(new CollidingInt(i, shift), i, keys); } } @Test public void testUnifiedSetForEachWithIndex() { assertUnifiedSetForEachWithIndex(0); assertUnifiedSetForEachWithIndex(1); assertUnifiedSetForEachWithIndex(2); assertUnifiedSetForEachWithIndex(3); } private static void assertUnifiedSetForEachWithIndex(int shift) { UnifiedSet set = UnifiedSet.newSet(); int size = 100000; for (int i = 0; i < size; i++) { Assert.assertTrue(set.add(new CollidingInt(i, shift))); } MutableList keys = FastList.newList(size); int[] prevIndex = new int[1]; set.forEachWithIndex((key, index) -> { Assert.assertEquals(prevIndex[0], index); prevIndex[0]++; keys.add(key); }); Verify.assertSize(size, keys); Collections.sort(keys); for (int i = 0; i < size; i++) { Verify.assertItemAtIndex(new CollidingInt(i, shift), i, keys); } } @Test public void testUnifiedSetAddAll() { assertUnifiedSetAddAll(0); assertUnifiedSetAddAll(1); assertUnifiedSetAddAll(2); assertUnifiedSetAddAll(3); } private static void assertUnifiedSetAddAll(int shift) { UnifiedSet set = UnifiedSet.newSet(); int size = 100000; for (int i = 0; i < size; i++) { set.add(new CollidingInt(i, shift)); } UnifiedSet newSet = UnifiedSet.newSet(size); newSet.addAll(set); Verify.assertSize(size, newSet); for (int i = 0; i < size; i++) { Verify.assertContains(new CollidingInt(i, shift), newSet); } } @Test public void testUnifiedSetAddAllWithHashSet() { assertUnifiedSetAddAllWithHashSet(0); assertUnifiedSetAddAllWithHashSet(1); assertUnifiedSetAddAllWithHashSet(2); assertUnifiedSetAddAllWithHashSet(3); } private static void assertUnifiedSetAddAllWithHashSet(int shift) { Set set = new HashSet(); int size = 100000; for (int i = 0; i < size; i++) { set.add(new CollidingInt(i, shift)); } UnifiedSet newSet = UnifiedSet.newSet(size); newSet.addAll(set); Verify.assertSize(size, newSet); for (int i = 0; i < size; i++) { Verify.assertContains(new CollidingInt(i, shift), newSet); } UnifiedSet newSet2 = UnifiedSet.newSet(); newSet2.addAll(set); Verify.assertSize(size, newSet2); for (int i = 0; i < size; i++) { Verify.assertContains(new CollidingInt(i, shift), newSet2); } } @Test public void testUnifiedSetReplace() { assertUnifiedSetReplace(0); assertUnifiedSetReplace(1); assertUnifiedSetReplace(2); assertUnifiedSetReplace(3); } private static void assertUnifiedSetReplace(int shift) { UnifiedSet set = UnifiedSet.newSet(); int size = 100000; for (int i = 0; i < size; i++) { set.add(new CollidingInt(i, shift)); } for (int i = 0; i < size; i++) { set.add(new CollidingInt(i, shift)); } Verify.assertSize(size, set); for (int i = 0; i < size; i++) { Verify.assertContains(new CollidingInt(i, shift), set); } } @Test public void testUnifiedSetRetainAllFromList() { runUnifiedSetRetainAllFromList(0); runUnifiedSetRetainAllFromList(1); runUnifiedSetRetainAllFromList(2); runUnifiedSetRetainAllFromList(3); } private static void runUnifiedSetRetainAllFromList(int shift) { UnifiedSet set = UnifiedSet.newSet(); MutableList toRetain = Lists.mutable.of(); int size = 100000; for (int i = 0; i < size; i++) { set.add(new CollidingInt(i, shift)); if (i % 2 == 0) { toRetain.add(new CollidingInt(i, shift)); } } Verify.assertSize(size, set); Assert.assertTrue(set.containsAll(toRetain)); Assert.assertTrue(set.retainAll(toRetain)); Assert.assertTrue(set.containsAll(toRetain)); Assert.assertFalse(set.retainAll(toRetain)); // a second call should not modify the set Verify.assertSize(size / 2, set); for (int i = 0; i < size; i += 2) { Verify.assertContains(new CollidingInt(i, shift), set); } } @Test public void testUnifiedSetRetainAllFromSet() { runUnifiedSetRetainAllFromSet(0); runUnifiedSetRetainAllFromSet(1); runUnifiedSetRetainAllFromSet(2); runUnifiedSetRetainAllFromSet(3); } private static void runUnifiedSetRetainAllFromSet(int shift) { UnifiedSet set = UnifiedSet.newSet(); Set toRetain = new HashSet(); int size = 100000; for (int i = 0; i < size; i++) { set.add(new CollidingInt(i, shift)); if (i % 2 == 0) { toRetain.add(new CollidingInt(i, shift)); } } Verify.assertSize(size, set); Assert.assertTrue(set.containsAll(toRetain)); Assert.assertTrue(set.retainAll(toRetain)); Assert.assertTrue(set.containsAll(toRetain)); Assert.assertFalse(set.retainAll(toRetain)); // a second call should not modify the set Verify.assertSize(size / 2, set); for (int i = 0; i < size; i += 2) { Verify.assertContains(new CollidingInt(i, shift), set); } } @Test public void testUnifiedSetToArray() { runUnifiedSetToArray(0); runUnifiedSetToArray(1); runUnifiedSetToArray(2); runUnifiedSetToArray(3); } private static void runUnifiedSetToArray(int shift) { UnifiedSet set = UnifiedSet.newSet(); int size = 100000; for (int i = 0; i < size; i++) { set.add(new CollidingInt(i, shift)); } Verify.assertSize(size, set); Object[] keys = set.toArray(); Assert.assertEquals(size, keys.length); Arrays.sort(keys); for (int i = 0; i < size; i++) { Verify.assertItemAtIndex(new CollidingInt(i, shift), i, keys); } } @Test public void testUnifiedSetIterator() { runUnifiedSetIterator(0); runUnifiedSetIterator(1); runUnifiedSetIterator(2); runUnifiedSetIterator(3); } private static void runUnifiedSetIterator(int shift) { UnifiedSet set = UnifiedSet.newSet(); int size = 100000; for (int i = 0; i < size; i++) { set.add(new CollidingInt(i, shift)); } Verify.assertSize(size, set); CollidingInt[] keys = new CollidingInt[size]; int count = 0; for (Iterator it = set.iterator(); it.hasNext(); ) { keys[count++] = it.next(); } Arrays.sort(keys); for (int i = 0; i < size; i++) { Assert.assertEquals(new CollidingInt(i, shift), keys[i]); } } @Test public void testUnifiedSetIteratorRemove() { for (int removeStride = 2; removeStride < 9; removeStride++) { runUnifiedSetIteratorRemove(0, removeStride); runUnifiedSetIteratorRemove(1, removeStride); runUnifiedSetIteratorRemove(2, removeStride); runUnifiedSetIteratorRemove(3, removeStride); } } private static void runUnifiedSetIteratorRemove(int shift, int removeStride) { UnifiedSet set = UnifiedSet.newSet(); int size = 100000; for (int i = 0; i < size; i++) { set.add(new CollidingInt(i, shift)); } Verify.assertSize(size, set); int count = 0; for (Iterator it = set.iterator(); it.hasNext(); ) { CollidingInt key = it.next(); count++; if (key.getValue() % removeStride == 0) { it.remove(); } } Assert.assertEquals(size, count); for (int i = 0; i < size; i++) { if (i % removeStride != 0) { Verify.assertContains( "set contains " + i + "for shift " + shift + " and remove stride " + removeStride, new CollidingInt(i, shift), set); } } } @Test public void testUnifiedSetIteratorRemoveFlip() { for (int removeStride = 2; removeStride < 9; removeStride++) { runUnifiedSetKeySetIteratorRemoveFlip(0, removeStride); runUnifiedSetKeySetIteratorRemoveFlip(1, removeStride); runUnifiedSetKeySetIteratorRemoveFlip(2, removeStride); runUnifiedSetKeySetIteratorRemoveFlip(3, removeStride); } } private static void runUnifiedSetKeySetIteratorRemoveFlip(int shift, int removeStride) { UnifiedSet set = UnifiedSet.newSet(); int size = 100000; for (int i = 0; i < size; i++) { set.add(new CollidingInt(i, shift)); } Verify.assertSize(size, set); int count = 0; for (Iterator it = set.iterator(); it.hasNext(); ) { CollidingInt key = it.next(); count++; if (key.getValue() % removeStride != 0) { it.remove(); } } Assert.assertEquals(size, count); for (int i = 0; i < size; i++) { if (i % removeStride == 0) { Verify.assertContains( "set contains " + i + "for shift " + shift + " and remove stride " + removeStride, new CollidingInt(i, shift), set); } } } @Test public void testUnifiedSetSerialize() { runUnifiedSetSerialize(0); runUnifiedSetSerialize(1); runUnifiedSetSerialize(2); runUnifiedSetSerialize(3); } private static void runUnifiedSetSerialize(int shift) { UnifiedSet set = UnifiedSet.newSet(); int size = 100000; for (int i = 0; i < size; i++) { set.add(new CollidingInt(i, shift)); } set.add(null); set = SerializeTestHelper.serializeDeserialize(set); Verify.assertSize(size + 1, set); for (int i = 0; i < size; i++) { Verify.assertContains(new CollidingInt(i, shift), set); } Verify.assertContains(null, set); } public static T[] shuffle(T[] array) { Object[] result = new Object[array.length]; Random rand = new Random(12345678912345L); int left = array.length; for (int i = 0; i < array.length; i++) { int chosen = rand.nextInt(left); result[i] = array[chosen]; left--; array[chosen] = array[left]; array[left] = null; } System.arraycopy(result, 0, array, 0, array.length); return array; } @Test public void testUnifiedSetEqualsAndHashCode() { assertUnifiedSetEqualsAndHashCode(0); assertUnifiedSetEqualsAndHashCode(1); assertUnifiedSetEqualsAndHashCode(2); assertUnifiedSetEqualsAndHashCode(3); } private static void assertUnifiedSetEqualsAndHashCode(int shift) { MutableSet set1 = UnifiedSet.newSet(); Set set2 = new HashSet(); MutableSet set3 = UnifiedSet.newSet(); MutableSet set4 = UnifiedSet.newSet(); int size = 100000; for (int i = 0; i < size; i++) { set1.add(new CollidingInt(i, shift)); set2.add(new CollidingInt(i, shift)); set3.add(new CollidingInt(i, shift)); set4.add(new CollidingInt(size - i - 1, shift)); } Verify.assertSetsEqual(set2, set1); Verify.assertSetsEqual(set1, set2); Verify.assertEqualsAndHashCode(set2, set1); Verify.assertSetsEqual(set1, set3); Verify.assertEqualsAndHashCode(set1, set3); Verify.assertSetsEqual(set2, set4); Verify.assertSetsEqual(set4, set2); Verify.assertEqualsAndHashCode(set2, set4); } @Test public void testUnifiedSetRemoveAll() { runUnifiedSetRemoveAll(0); runUnifiedSetRemoveAll(1); runUnifiedSetRemoveAll(2); runUnifiedSetRemoveAll(3); } private static void runUnifiedSetRemoveAll(int shift) { UnifiedSet set = UnifiedSet.newSet(); List toRemove = new ArrayList(); int size = 100000; for (int i = 0; i < size; i++) { set.add(new CollidingInt(i, shift)); if (i % 2 == 0) { toRemove.add(new CollidingInt(i, shift)); } } Verify.assertSize(size, set); Assert.assertTrue(set.removeAll(toRemove)); Assert.assertFalse(set.removeAll(toRemove)); // a second call should not modify the set Verify.assertSize(size / 2, set); for (int i = 1; i < size; i += 2) { Verify.assertContains(new CollidingInt(i, shift), set); } } @Test public void testUnifiedSetPutDoesNotReplace() { this.assertUnifiedSetPutDoesNotReplace(0); this.assertUnifiedSetPutDoesNotReplace(1); this.assertUnifiedSetPutDoesNotReplace(2); this.assertUnifiedSetPutDoesNotReplace(3); this.assertUnifiedSetPutDoesNotReplace(4); } private void assertUnifiedSetPutDoesNotReplace(int shift) { UnifiedSet set = UnifiedSet.newSet(); for (int i = 0; i < 1000; i++) { Assert.assertTrue(set.add(new CollidingIntWithFlag(i, shift, false))); } Assert.assertEquals(1000, set.size()); for (int i = 0; i < 1000; i++) { Assert.assertFalse(set.add(new CollidingIntWithFlag(i, shift, true))); } Assert.assertEquals(1000, set.size()); for (CollidingIntWithFlag ciwf : set) { Assert.assertFalse(ciwf.flag); } } @Test public void testUnifiedSetAsPool() { this.runUnifiedSetAsPool(0); this.runUnifiedSetAsPool(1); this.runUnifiedSetAsPool(2); this.runUnifiedSetAsPool(3); } private void runUnifiedSetAsPool(int shift) { CollidingInt[] toPool = new CollidingInt[5000]; UnifiedSet set = new UnifiedSet(); for (int i = 0; i < toPool.length; i++) { toPool[i] = new CollidingInt(i, shift); Assert.assertSame(toPool[i], set.put(toPool[i])); } for (int i = 0; i < toPool.length; i++) { Assert.assertSame(toPool[i], set.put(new CollidingInt(i, shift))); } Random random = new Random(); for (int i = 0; i < toPool.length * 4; i++) { int x = random.nextInt(toPool.length); Assert.assertSame(toPool[x], set.put(new CollidingInt(x, shift))); } for (int i = 0; i < toPool.length; i++) { Assert.assertSame(toPool[i], set.get(toPool[i])); } for (int i = 0; i < toPool.length * 4; i++) { int x = random.nextInt(toPool.length); Assert.assertSame(toPool[x], set.removeFromPool(new CollidingInt(x, shift))); toPool[x] = null; } } @Test public void testUnifiedSetAsPoolRandomInput() { this.runUnifiedSetAsPoolRandomInput(0); this.runUnifiedSetAsPoolRandomInput(1); this.runUnifiedSetAsPoolRandomInput(2); this.runUnifiedSetAsPoolRandomInput(3); } private void runUnifiedSetAsPoolRandomInput(int shift) { CollidingInt[] toPool = new CollidingInt[5000]; for (int i = 0; i < toPool.length; i++) { toPool[i] = new CollidingInt(i, shift); } toPool = shuffle(toPool); UnifiedSet set = new UnifiedSet(); for (int i = 0; i < toPool.length; i++) { Assert.assertSame(toPool[i], set.put(toPool[i])); } for (int i = 0; i < toPool.length; i++) { Assert.assertSame(toPool[i], set.put(new CollidingInt(toPool[i].getValue(), shift))); } Random random = new Random(); for (int i = 0; i < toPool.length * 4; i++) { int x = random.nextInt(toPool.length); Assert.assertSame(toPool[x], set.put(new CollidingInt(toPool[x].getValue(), shift))); } for (int i = 0; i < toPool.length; i++) { Assert.assertSame(toPool[i], set.get(toPool[i])); } } private static final class CollidingIntWithFlag extends CollidingInt { private static final long serialVersionUID = 1L; private final boolean flag; private CollidingIntWithFlag(int value, int shift, boolean flag) { super(value, shift); this.flag = flag; } } } gs-collections-5.1.0/acceptance-tests/src/test/java/com/gs/collections/impl/utility/000077500000000000000000000000001234315411400305265ustar00rootroot00000000000000ArrayListIterateAcceptanceTest.java000066400000000000000000000023101234315411400373450ustar00rootroot00000000000000gs-collections-5.1.0/acceptance-tests/src/test/java/com/gs/collections/impl/utility/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.utility; import java.util.ArrayList; import com.gs.collections.impl.list.Interval; import com.gs.collections.impl.test.Verify; import org.junit.Test; /** * JUnit test for {@link ArrayListIterate}. */ public class ArrayListIterateAcceptanceTest { @Test public void testSortOnListWithMoreThan10Elements() { ArrayList integers = new ArrayList(Interval.toReverseList(1, 10000)); Verify.assertStartsWith(ArrayListIterate.sortThis(integers), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); Verify.assertEndsWith(integers, 9997, 9998, 9999, 10000); } } gs-collections-5.1.0/build.xml000066400000000000000000000106321234315411400162630ustar00rootroot00000000000000 A delegating master build file, which builds targets in each module gs-collections-5.1.0/checkstyle-configuration.xml000066400000000000000000000233141234315411400221700ustar00rootroot00000000000000 gs-collections-5.1.0/checkstyle-suppressions.xml000066400000000000000000000061461234315411400221020ustar00rootroot00000000000000 gs-collections-5.1.0/collections-api/000077500000000000000000000000001234315411400175255ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/.classpath000066400000000000000000000006501234315411400215110ustar00rootroot00000000000000 gs-collections-5.1.0/collections-api/.project000066400000000000000000000010421234315411400211710ustar00rootroot00000000000000 collections-api org.eclipse.jdt.core.javabuilder org.maven.ide.eclipse.maven2Builder org.eclipse.jdt.core.javanature org.maven.ide.eclipse.maven2Nature gs-collections-5.1.0/collections-api/build.xml000066400000000000000000000046741234315411400213610ustar00rootroot00000000000000 gs-collections-5.1.0/collections-api/gs-collections-api.iml000066400000000000000000000016371234315411400237330ustar00rootroot00000000000000 gs-collections-5.1.0/collections-api/ivy.xml000066400000000000000000000045361234315411400210660ustar00rootroot00000000000000 gs-collections-5.1.0/collections-api/pom.xml000066400000000000000000000353401234315411400210470ustar00rootroot00000000000000 4.0.0 com.goldmansachs gs-collections-api 5.1.0 bundle Goldman Sachs Collections API GS Collections is a collections framework for Java. It has JDK-compatible List, Set and Map implementations with a rich API and set of utility classes that work with any JDK compatible Collections, Arrays, Maps or Strings. The iteration protocol was inspired by the Smalltalk collection framework. https://github.com/goldmansachs/gs-collections 2004 The Apache Software License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0.txt repo https://github.com/goldmansachs/gs-collections scm:git:https://github.com/goldmansachs/gs-collections.git scm:git:https://github.com/goldmansachs/gs-collections.git Craig P. Motlin craig.motlin@gs.com Donald Raab donald.raab@gs.com Bhavana Hindupur bhavana.hindupur@gs.com UTF-8 3.2.2 2.10 ${project.basedir}/target/clover/surefire-reports ${build.is.personal} 3.0 net.jcip jcip-annotations 1.0 true maven-antrun-plugin 1.7 maven-assembly-plugin 2.4 maven-clean-plugin 2.5 maven-compiler-plugin 2.5.1 maven-dependency-plugin 2.8 maven-deploy-plugin 2.8.1 maven-install-plugin 2.5.1 maven-jar-plugin 2.4 maven-javadoc-plugin 2.9.1 maven-release-plugin 2.4.2 maven-resources-plugin 2.6 maven-site-plugin 3.3 maven-source-plugin 2.2.1 maven-enforcer-plugin 1.3.1 org.codehaus.mojo versions-maven-plugin 2.1 org.codehaus.mojo clirr-maven-plugin 2.6.1 org.apache.felix maven-bundle-plugin 2.4.0 org.scala-tools maven-scala-plugin 2.15.2 maven-surefire-plugin 2.16 maven-project-info-reports-plugin 2.7 com.fortify.ps.maven.plugin maven-sca-plugin 2.6 com.goldmansachs gs-collections-code-generator-maven-plugin 5.1.0 generate-sources generate api maven-compiler-plugin 1.5 1.5 maven-surefire-plugin **/*Test.java -XX:-OmitStackTraceInFastThrow random never maven-source-plugin 2.1.2 verify jar-no-fork org.apache.felix maven-bundle-plugin 2.4.0 true com.gs.collections.api J2SE-1.5,JavaSE-1.6 net.jcip.annotations;resolution:=optional,* ${project.version} org.codehaus.mojo sonar-maven-plugin 2.2 maven-checkstyle-plugin ${checkstyle.version} checkstyle-configuration.xml true true org.codehaus.mojo findbugs-maven-plugin 2.5.3 Max Default true true findbugs-exclude.xml maven-javadoc-plugin Goldman Sachs Collections API - ${project.version} Goldman Sachs Collections API - ${project.version} public http://java.sun.com/j2se/1.5.0/docs/api/ ${project.version} -Xdoclint:none maven-enforcer-plugin enforce com.goldmansachs:gs-collections-code-generator-maven-plugin 1.7.0 3.0.2 enforce org.codehaus.mojo clirr-maven-plugin 2.5 com.goldmansachs gs-collections-api 5.1.0 ${project.build.directory}/clirr.txt clover com.atlassian.maven.plugins maven-clover2-plugin ${clover.version} ${clover.license} @deprecated true true block ${user.home}/clover/${project.artifactId} setup process-sources setup gs-collections-5.1.0/collections-api/src/000077500000000000000000000000001234315411400203145ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/000077500000000000000000000000001234315411400212405ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/000077500000000000000000000000001234315411400221615ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/000077500000000000000000000000001234315411400227375ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/000077500000000000000000000000001234315411400233505ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/000077500000000000000000000000001234315411400256665ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/000077500000000000000000000000001234315411400264375ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/InternalIterable.java000066400000000000000000000047721234315411400325400ustar00rootroot00000000000000/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; /** * The base interface for all GS Collections. All GS Collections are internally iterable, and this interface provides * the base set of internal iterators that every GS collection should implement. */ public interface InternalIterable extends Iterable { /** * The procedure is executed for each element in the iterable. *

*

e.g.
     * people.forEach(new Procedure()
     * {
     *     public void value(Person person)
     *     {
     *         LOGGER.info(person.getName());
     *     }
     * });
     * 
*/ void forEach(Procedure procedure); /** * Iterates over the iterable passing each element and the current relative int index to the specified instance of * ObjectIntProcedure *
e.g.
     * people.forEachWithIndex(new ObjectIntProcedure()
     * {
     *     public void value(Person person, int index)
     *     {
     *         LOGGER.info("Index: " + index + " person: " + person.getName());
     *     }
     * });
     * 
*/ void forEachWithIndex(ObjectIntProcedure objectIntProcedure); /** * The procedure2 is evaluated for each element in the iterable with the specified parameter provided * as the second argument. *

*

e.g.
     * people.forEachWith(new Procedure2()
     * {
     *     public void value(Person person, Person other)
     *     {
     *         if (person.isRelatedTo(other))
     *         {
     *              LOGGER.info(person.getName());
     *         }
     *     }
     * }, fred);
     * 
*/

void forEachWith(Procedure2 procedure, P parameter); } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/LazyIterable.java000066400000000000000000000135301234315411400316730ustar00rootroot00000000000000/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api; import java.util.Collection; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.tuple.Pair; /** * A LazyIterable is RichIterable which will defer evaluation for certain methods like select, reject, collect, etc. * Any methods that do not return a LazyIterable when called will cause evaluation to be forced. * * @since 1.0 */ public interface LazyIterable extends RichIterable { /** * Creates a deferred iterable for selecting elements from the current iterable. */ LazyIterable select(Predicate predicate);

LazyIterable selectWith(Predicate2 predicate, P parameter); LazyIterable selectInstancesOf(Class clazz); /** * Creates a deferred iterable for rejecting elements from the current iterable. */ LazyIterable reject(Predicate predicate);

LazyIterable rejectWith(Predicate2 predicate, P parameter); /** * Creates a deferred iterable for collecting elements from the current iterable. */ LazyIterable collect(Function function); LazyIterable collectWith(Function2 function, P parameter); /** * Creates a deferred iterable for selecting and collecting elements from the current iterable. */ LazyIterable collectIf(Predicate predicate, Function function); /** * Creates a deferred take iterable for the current iterable using the specified count as the limit. */ LazyIterable take(int count); /** * Creates a deferred drop iterable for the current iterable using the specified count as the limit. */ LazyIterable drop(int count); /** * Creates a deferred distinct iterable to get distinct elements from the current iterable. * * @since 5.0 */ LazyIterable distinct(); /** * Creates a deferred flattening iterable for the current iterable. */ LazyIterable flatCollect(Function> function); /** * Creates a deferred iterable that will join this iterable with the specified iterable. */ LazyIterable concatenate(Iterable iterable); /** * Creates a deferred zip iterable. */ LazyIterable> zip(Iterable that); /** * Creates a deferred zipWithIndex iterable. */ LazyIterable> zipWithIndex(); /** * Creates a deferred chunking iterable. */ LazyIterable> chunk(int size); /** * Iterates over this iterable adding all elements into the target collection. */ > R into(R target); /** * Returns a lazy BooleanIterable which will transform the underlying iterable data to boolean values based on the booleanFunction. */ LazyBooleanIterable collectBoolean(BooleanFunction booleanFunction); /** * Returns a lazy ByteIterable which will transform the underlying iterable data to byte values based on the byteFunction. */ LazyByteIterable collectByte(ByteFunction byteFunction); /** * Returns a lazy CharIterable which will transform the underlying iterable data to char values based on the charFunction. */ LazyCharIterable collectChar(CharFunction charFunction); /** * Returns a lazy DoubleIterable which will transform the underlying iterable data to double values based on the doubleFunction. */ LazyDoubleIterable collectDouble(DoubleFunction doubleFunction); /** * Returns a lazy FloatIterable which will transform the underlying iterable data to float values based on the floatFunction. */ LazyFloatIterable collectFloat(FloatFunction floatFunction); /** * Returns a lazy IntIterable which will transform the underlying iterable data to int values based on the intFunction. */ LazyIntIterable collectInt(IntFunction intFunction); /** * Returns a lazy LongIterable which will transform the underlying iterable data to long values based on the longFunction. */ LazyLongIterable collectLong(LongFunction longFunction); /** * Returns a lazy ShortIterable which will transform the underlying iterable data to short values based on the shortFunction. */ LazyShortIterable collectShort(ShortFunction shortFunction); } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/ParallelIterable.java000066400000000000000000000215021234315411400325060ustar00rootroot00000000000000/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api; import java.util.Comparator; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.bag.MutableBag; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.map.MapIterable; import com.gs.collections.api.map.MutableMap; import com.gs.collections.api.map.sorted.MutableSortedMap; import com.gs.collections.api.multimap.Multimap; import com.gs.collections.api.set.MutableSet; import com.gs.collections.api.set.sorted.MutableSortedSet; /** * A ParallelIterable is RichIterable which will defer evaluation for certain methods like select, reject, collect, etc. * Any methods that do not return a ParallelIterable when called will cause evaluation to be forced. Evaluation occurs * in parallel. All code blocks passed in must be stateless or thread-safe. * * @since 5.0 */ @Beta public interface ParallelIterable { ParallelIterable asUnique(); /** * Creates a parallel iterable for selecting elements from the current iterable. */ ParallelIterable select(Predicate predicate);

ParallelIterable selectWith(Predicate2 predicate, P parameter); ParallelIterable selectInstancesOf(Class clazz); /** * Creates a parallel iterable for rejecting elements from the current iterable. */ ParallelIterable reject(Predicate predicate);

ParallelIterable rejectWith(Predicate2 predicate, P parameter); /** * Creates a parallel iterable for collecting elements from the current iterable. */ ParallelIterable collect(Function function); ParallelIterable collectWith(Function2 function, P parameter); /** * Creates a parallel iterable for selecting and collecting elements from the current iterable. */ ParallelIterable collectIf(Predicate predicate, Function function); /** * Creates a parallel flattening iterable for the current iterable. */ ParallelIterable flatCollect(Function> function); // /** // * Returns a parallel BooleanIterable which will transform the underlying iterable data to boolean values based on the booleanFunction. // */ // ParallelBooleanIterable collectBoolean(BooleanFunction booleanFunction); // // /** // * Returns a parallel ByteIterable which will transform the underlying iterable data to byte values based on the byteFunction. // */ // ParallelByteIterable collectByte(ByteFunction byteFunction); // // /** // * Returns a parallel CharIterable which will transform the underlying iterable data to char values based on the charFunction. // */ // ParallelCharIterable collectChar(CharFunction charFunction); // // /** // * Returns a parallel DoubleIterable which will transform the underlying iterable data to double values based on the doubleFunction. // */ // ParallelDoubleIterable collectDouble(DoubleFunction doubleFunction); // // /** // * Returns a parallel FloatIterable which will transform the underlying iterable data to float values based on the floatFunction. // */ // ParallelFloatIterable collectFloat(FloatFunction floatFunction); // // /** // * Returns a parallel IntIterable which will transform the underlying iterable data to int values based on the intFunction. // */ // ParallelIntIterable collectInt(IntFunction intFunction); // // /** // * Returns a parallel LongIterable which will transform the underlying iterable data to long values based on the longFunction. // */ // ParallelLongIterable collectLong(LongFunction longFunction); // // /** // * Returns a parallel ShortIterable which will transform the underlying iterable data to short values based on the shortFunction. // */ // ParallelShortIterable collectShort(ShortFunction shortFunction); void forEach(Procedure procedure);

void forEachWith(Procedure2 procedure, P parameter); T detect(Predicate predicate);

T detectWith(Predicate2 predicate, P parameter); T detectIfNone(Predicate predicate, Function0 function);

T detectWithIfNone(Predicate2 predicate, P parameter, Function0 function); int count(Predicate predicate);

int countWith(Predicate2 predicate, P parameter); boolean anySatisfy(Predicate predicate);

boolean anySatisfyWith(Predicate2 predicate, P parameter); boolean allSatisfy(Predicate predicate);

boolean allSatisfyWith(Predicate2 predicate, P parameter); boolean noneSatisfy(Predicate predicate);

boolean noneSatisfyWith(Predicate2 predicate, P parameter); MutableList toList(); MutableList toSortedList(); MutableList toSortedList(Comparator comparator); > MutableList toSortedListBy(Function function); MutableSet toSet(); MutableSortedSet toSortedSet(); MutableSortedSet toSortedSet(Comparator comparator); > MutableSortedSet toSortedSetBy(Function function); MutableBag toBag(); MutableMap toMap(Function keyFunction, Function valueFunction); MutableSortedMap toSortedMap(Function keyFunction, Function valueFunction); MutableSortedMap toSortedMap(Comparator comparator, Function keyFunction, Function valueFunction); Object[] toArray(); T1[] toArray(T1[] target); T min(Comparator comparator); T max(Comparator comparator); T min(); T max(); > T minBy(Function function); > T maxBy(Function function); long sumOfInt(IntFunction function); double sumOfFloat(FloatFunction function); long sumOfLong(LongFunction function); double sumOfDouble(DoubleFunction function); String makeString(); String makeString(String separator); String makeString(String start, String separator, String end); void appendString(Appendable appendable); void appendString(Appendable appendable, String separator); void appendString(Appendable appendable, String start, String separator, String end); Multimap groupBy(Function function); Multimap groupByEach(Function> function); MapIterable groupByUniqueKey(Function function); MapIterable aggregateInPlaceBy(Function groupBy, Function0 zeroValueFactory, Procedure2 mutatingAggregator); MapIterable aggregateBy(Function groupBy, Function0 zeroValueFactory, Function2 nonMutatingAggregator); } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/PrimitiveIterable.java000066400000000000000000000071611234315411400327270ustar00rootroot00000000000000/* * Copyright 2012 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api; /** * PrimitiveIterable includes API that is common to all primitive collections. * * @since 3.0 */ public interface PrimitiveIterable { /** * Returns the number of items in this iterable. * * @since 3.0 */ int size(); /** * Returns true if this iterable has zero items. * * @since 3.0 */ boolean isEmpty(); /** * The English equivalent of !this.isEmpty() * * @since 3.0 */ boolean notEmpty(); /** * Returns a string representation of this PrimitiveIterable. The string representation consists of a list of the * PrimitiveIterable's elements in the order they are returned by its iterator, enclosed in square brackets * ("[]"). Adjacent elements are separated by the characters ", " (comma and space). Elements * are converted to strings as by String#valueOf(). * * @return a string representation of this PrimitiveIterable */ @Override String toString(); /** * Returns a string representation of this collection by delegating to {@link #makeString(String)} and defaulting * the separator parameter to the characters ", " (comma and space). * * @return a string representation of this collection. * @since 3.0 */ String makeString(); /** * Returns a string representation of this collection by delegating to {@link #makeString(String, String, String)} * and defaulting the start and end parameters to "" (the empty String). * * @return a string representation of this collection. * @since 3.0 */ String makeString(String separator); /** * Returns a string representation of this collection. The string representation consists of a list of the * collection's elements in the order they are returned by its iterator, enclosed in the start and end strings. * Adjacent elements are separated by the separator string. Elements are converted to strings using the appropriate * version of String.valueOf(). * * @return a string representation of this collection. * @since 3.0 */ String makeString(String start, String separator, String end); /** * Prints a string representation of this collection onto the given {@code Appendable}. Prints the string returned * by {@link #makeString()}. * * @since 3.0 */ void appendString(Appendable appendable); /** * Prints a string representation of this collection onto the given {@code Appendable}. Prints the string returned * by {@link #makeString(String)}. * * @since 3.0 */ void appendString(Appendable appendable, String separator); /** * Prints a string representation of this collection onto the given {@code Appendable}. Prints the string returned * by {@link #makeString(String, String, String)}. * * @since 3.0 */ void appendString(Appendable appendable, String start, String separator, String end); } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/RichIterable.java000066400000000000000000001505411234315411400316450ustar00rootroot00000000000000/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api; import java.util.Collection; import java.util.Comparator; import java.util.NoSuchElementException; import com.gs.collections.api.bag.MutableBag; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.DoubleObjectToDoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.FloatObjectToFloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.IntObjectToIntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.LongObjectToLongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.collection.primitive.MutableBooleanCollection; import com.gs.collections.api.collection.primitive.MutableByteCollection; import com.gs.collections.api.collection.primitive.MutableCharCollection; import com.gs.collections.api.collection.primitive.MutableDoubleCollection; import com.gs.collections.api.collection.primitive.MutableFloatCollection; import com.gs.collections.api.collection.primitive.MutableIntCollection; import com.gs.collections.api.collection.primitive.MutableLongCollection; import com.gs.collections.api.collection.primitive.MutableShortCollection; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.map.MapIterable; import com.gs.collections.api.map.MutableMap; import com.gs.collections.api.map.sorted.MutableSortedMap; import com.gs.collections.api.multimap.Multimap; import com.gs.collections.api.multimap.MutableMultimap; import com.gs.collections.api.partition.PartitionIterable; import com.gs.collections.api.set.MutableSet; import com.gs.collections.api.set.sorted.MutableSortedSet; import com.gs.collections.api.tuple.Pair; /** * RichIterable is an interface which extends the InternalIterable interface with several internal iterator methods, from * the Smalltalk Collection protocol. These include select, reject, detect, collect, injectInto, anySatisfy, * allSatisfy. The API also includes converter methods to convert a RichIterable to a List (toList), to a sorted * List (toSortedList), to a Set (toSet), and to a Map (toMap). * * @since 1.0 */ public interface RichIterable extends InternalIterable { /** * Returns the number of items in this iterable. * * @since 1.0 */ int size(); /** * Returns true if this iterable has zero items. * * @since 1.0 */ boolean isEmpty(); /** * The English equivalent of !this.isEmpty() * * @since 1.0 */ boolean notEmpty(); /** * Returns the first element of an iterable. In the case of a List it is the element at the first index. In the * case of any other Collection, it is the first element that would be returned during an iteration. If the * iterable is empty, null is returned. If null is a valid element of the container, then a developer would need to * check to see if the iterable is empty to validate that a null result was not due to the container being empty. *

* The order of Sets are not guaranteed (except for TreeSets and other Ordered Set implementations), so if you use * this method, the first element could be any element from the Set. * * @since 1.0 */ T getFirst(); /** * Returns the last element of an iterable. In the case of a List it is the element at the last index. In the case * of any other Collection, it is the last element that would be returned during an iteration. If the iterable is * empty, null is returned. If null is a valid element of the container, then a developer would need to check to * see if the iterable is empty to validate that a null result was not due to the container being empty. *

* The order of Sets are not guaranteed (except for TreeSets and other Ordered Set implementations), so if you use * this method, the last element could be any element from the Set. * * @since 1.0 */ T getLast(); /** * Returns true if the iterable has an element which responds true to element.equals(object). * * @since 1.0 */ boolean contains(Object object); /** * Returns true if all elements in source are contained in this collection. * * @since 1.0 */ boolean containsAllIterable(Iterable source); /** * Returns true if all elements in source are contained in this collection. * * @see Collection#containsAll(Collection) * @since 1.0 */ boolean containsAll(Collection source); /** * Returns true if all elements in the specified var arg array are contained in this collection. * * @since 1.0 */ boolean containsAllArguments(Object... elements); /** * Returns all elements of the source collection that return true when evaluating the predicate. This method is also * commonly called filter. *

*

e.g.
     * return people.select(new Predicate<Person>()
     * {
     *     public boolean accept(Person person)
     *     {
     *         return person.getAddress().getCity().equals("Metuchen");
     *     }
     * });
     * 
* * @since 1.0 */ RichIterable select(Predicate predicate); /** * Same as the select method with one parameter but uses the specified target collection for the results. *

*

e.g.
     * return people.select(new Predicate<Person>()
     * {
     *     public boolean accept(Person person)
     *     {
     *         return person.person.getLastName().equals("Smith");
     *     }
     * }, Lists.mutable.of());
     * 
*

*

e.g.
     * return collection.select(Predicates.attributeEqual("lastName", "Smith"), new ArrayList());
     * 
* * @param predicate a {@link Predicate} to use as the select criteria * @param target the Collection to append to for all elements in this {@code RichIterable} that meet select criteria {@code predicate} * @return {@code target}, which contains appended elements as a result of the select criteria * @see #select(Predicate) * @since 1.0 */ > R select(Predicate predicate, R target); /** * Similar to {@link #select(Predicate)}, except with an evaluation parameter for the second generic argument in {@link Predicate2}. * * @param predicate a {@link Predicate2} to use as the select criteria * @param parameter a parameter to pass in for evaluation of the second argument {@code P} in {@code predicate} * @see #select(Predicate) * @since 5.0 */

RichIterable selectWith(Predicate2 predicate, P parameter); /** * Similar to {@link #select(Predicate, Collection)}, except with an evaluation parameter for the second generic argument in {@link Predicate2}. * * @param predicate a {@link Predicate2} to use as the select criteria * @param parameter a parameter to pass in for evaluation of the second argument {@code P} in {@code predicate} * @param targetCollection the Collection to append to for all elements in this {@code RichIterable} that meet select criteria {@code predicate} * @return {@code targetCollection}, which contains appended elements as a result of the select criteria * @see #select(Predicate) * @see #select(Predicate, Collection) * @since 1.0 */ > R selectWith( Predicate2 predicate, P parameter, R targetCollection); /** * Returns all elements of the source collection that return false when evaluating of the predicate. This method is also * sometimes called filterNot and is the equivalent of calling iterable.select(Predicates.not(predicate)). *

*

e.g.
     * return people.reject(new Predicate<Person>()
     * {
     *     public boolean accept(Person person)
     *     {
     *         return person.person.getLastName().equals("Smith");
     *     }
     * });
     * 
*

*

e.g.
     * return people.reject(Predicates.attributeEqual("lastName", "Smith"));
     * 
* * @param predicate a {@link Predicate} to use as the reject criteria * @return a RichIterable that contains elements that cause {@link Predicate#accept(Object)} method to evaluate to false * @since 1.0 */ RichIterable reject(Predicate predicate); /** * Similar to {@link #reject(Predicate)}, except with an evaluation parameter for the second generic argument in {@link Predicate2}. * * @param predicate a {@link Predicate2} to use as the select criteria * @param parameter a parameter to pass in for evaluation of the second argument {@code P} in {@code predicate} * @see #select(Predicate) * @since 5.0 */

RichIterable rejectWith(Predicate2 predicate, P parameter); /** * Same as the reject method with one parameter but uses the specified target collection for the results. *

*

e.g.
     * return people.reject(new Predicate<Person>()
     * {
     *     public boolean accept(Person person)
     *     {
     *         return person.person.getLastName().equals("Smith");
     *     }
     * }, Lists.mutable.of());
     * 
* * @param predicate a {@link Predicate} to use as the reject criteria * @param target the Collection to append to for all elements in this {@code RichIterable} that cause {@code Predicate#accept(Object)} method to evaluate to false * @return {@code target}, which contains appended elements as a result of the reject criteria * @since 1.0 */ > R reject(Predicate predicate, R target); /** * Similar to {@link #reject(Predicate, Collection)}, except with an evaluation parameter for the second generic argument in {@link Predicate2}. *

* E.g. return a {@link Collection} of Person elements where the person has a height greater than 100cm *

     * return people.reject(new Predicate2<Person, Integer>()
     * {
     *     public boolean accept(Person p, Integer i)
     *     {
     *         return p.getHeightInCm() < i.intValue();
     *     }
     * }, Integer.valueOf(100), FastList.newList());
     * 
* * @param predicate a {@link Predicate2} to use as the reject criteria * @param parameter a parameter to pass in for evaluation of the second argument {@code P} in {@code predicate} * @param targetCollection the Collection to append to for all elements in this {@code RichIterable} that cause {@code Predicate#accept(Object)} method to evaluate to false * @return {@code targetCollection}, which contains appended elements as a result of the reject criteria * @see #reject(Predicate) * @see #reject(Predicate, Collection) * @since 1.0 */ > R rejectWith( Predicate2 predicate, P parameter, R targetCollection); /** * Filters a collection into a PartitionedIterable based on the evaluation of the predicate. *

*

e.g.
     * return people.partition(new Predicate<Person>()
     * {
     *     public boolean accept(Person person)
     *     {
     *         return person.getAddress().getState().getName().equals("New York");
     *     }
     * });
     * 
* * @since 1.0. */ PartitionIterable partition(Predicate predicate); /** * Filters a collection into a PartitionIterable based on the evaluation of the predicate. *

*

e.g.
     * return people.partitionWith(new Predicate2<Person, String>()
     * {
     *     public boolean accept(Person person, String state)
     *     {
     *         return person.getAddress().getState().getName().equals(state);
     *     }
     * }, "New York");
     * 
* * @since 5.0. */

PartitionIterable partitionWith(Predicate2 predicate, P parameter); /** * Returns all elements of the source collection that are instances of the Class {@code clazz}. * * @since 2.0 */ RichIterable selectInstancesOf(Class clazz); /** * Returns a new collection with the results of applying the specified function on each element of the source * collection. This method is also commonly called transform or map. *

*

e.g.
     * return people.collect(new Function<Person, String>()
     * {
     *     public String valueOf(Person person)
     *     {
     *         return person.getFirstName() + " " + person.getLastName();
     *     }
     * });
     * 
* * @since 1.0 */ RichIterable collect(Function function); /** * Returns a new primitive {@code boolean} iterable with the results of applying the specified function on each element * of the source collection. This method is also commonly called transform or map. *

*

e.g.
     * return people.collectBoolean(new BooleanFunction<Person>()
     * {
     *     public boolean booleanValueOf(Person person)
     *     {
     *         return person.hasDrivingLicense();
     *     }
     * });
     * 
* * @since 4.0 */ BooleanIterable collectBoolean(BooleanFunction booleanFunction); /** * Same as {@link #collectBoolean(BooleanFunction)}, except that the results are gathered into the specified {@code target} * collection. *

*

e.g.
     * return people.collectBoolean(new BooleanFunction<Person>()
     * {
     *     public boolean booleanValueOf(Person person)
     *     {
     *         return person.hasDrivingLicense();
     *     }
     * }, new BooleanArrayList());
     * 
* * @param booleanFunction a {@link BooleanFunction} to use as the collect transformation function * @param target the MutableBooleanCollection to append to for all elements in this {@code RichIterable} * @return {@code target}, which contains appended elements as a result of the collect transformation * @since 5.0 */ R collectBoolean(BooleanFunction booleanFunction, R target); /** * Returns a new primitive {@code byte} iterable with the results of applying the specified function on each element * of the source collection. This method is also commonly called transform or map. *

*

e.g.
     * return people.collectByte(new ByteFunction<Person>()
     * {
     *     public byte byteValueOf(Person person)
     *     {
     *         return person.getCode();
     *     }
     * });
     * 
* * @since 4.0 */ ByteIterable collectByte(ByteFunction byteFunction); /** * Same as {@link #collectByte(ByteFunction)}, except that the results are gathered into the specified {@code target} * collection. *

*

e.g.
     * return people.collectByte(new ByteFunction<Person>()
     * {
     *     public byte byteValueOf(Person person)
     *     {
     *         return person.getCode();
     *     }
     * }, new ByteArrayList());
     * 
* * @param byteFunction a {@link ByteFunction} to use as the collect transformation function * @param target the MutableByteCollection to append to for all elements in this {@code RichIterable} * @return {@code target}, which contains appended elements as a result of the collect transformation * @since 5.0 */ R collectByte(ByteFunction byteFunction, R target); /** * Returns a new primitive {@code char} iterable with the results of applying the specified function on each element * of the source collection. This method is also commonly called transform or map. *

*

e.g.
     * return people.collectChar(new CharFunction<Person>()
     * {
     *     public char charValueOf(Person person)
     *     {
     *         return person.getMiddleInitial();
     *     }
     * });
     * 
* * @since 4.0 */ CharIterable collectChar(CharFunction charFunction); /** * Same as {@link #collectChar(CharFunction)}, except that the results are gathered into the specified {@code target} * collection. *

*

e.g.
     * return people.collectChar(new CharFunction<Person>()
     * {
     *     public char charValueOf(Person person)
     *     {
     *         return person.getMiddleInitial();
     *     }
     * }, new CharArrayList());
     * 
* * @param charFunction a {@link CharFunction} to use as the collect transformation function * @param target the MutableCharCollection to append to for all elements in this {@code RichIterable} * @return {@code target}, which contains appended elements as a result of the collect transformation * @since 5.0 */ R collectChar(CharFunction charFunction, R target); /** * Returns a new primitive {@code double} iterable with the results of applying the specified function on each element * of the source collection. This method is also commonly called transform or map. *

*

e.g.
     * return people.collectDouble(new DoubleFunction<Person>()
     * {
     *     public double doubleValueOf(Person person)
     *     {
     *         return person.getMilesFromNorthPole();
     *     }
     * });
     * 
* * @since 4.0 */ DoubleIterable collectDouble(DoubleFunction doubleFunction); /** * Same as {@link #collectDouble(DoubleFunction)}, except that the results are gathered into the specified {@code target} * collection. *

*

e.g.
     * return people.collectDouble(new DoubleFunction<Person>()
     * {
     *     public double doubleValueOf(Person person)
     *     {
     *         return person.getMilesFromNorthPole();
     *     }
     * }, new DoubleArrayList());
     * 
* * @param doubleFunction a {@link DoubleFunction} to use as the collect transformation function * @param target the MutableDoubleCollection to append to for all elements in this {@code RichIterable} * @return {@code target}, which contains appended elements as a result of the collect transformation * @since 5.0 */ R collectDouble(DoubleFunction doubleFunction, R target); /** * Returns a new primitive {@code float} iterable with the results of applying the specified function on each element * of the source collection. This method is also commonly called transform or map. *

*

e.g.
     * return people.collectFloat(new FloatFunction<Person>()
     * {
     *     public float floatValueOf(Person person)
     *     {
     *         return person.getHeightInInches();
     *     }
     * });
     * 
* * @since 4.0 */ FloatIterable collectFloat(FloatFunction floatFunction); /** * Same as {@link #collectFloat(FloatFunction)}, except that the results are gathered into the specified {@code target} * collection. *

*

e.g.
     * return people.collectFloat(new FloatFunction<Person>()
     * {
     *     public float floatValueOf(Person person)
     *     {
     *         return person.getHeightInInches();
     *     }
     * }, new FloatArrayList());
     * 
* * @param floatFunction a {@link FloatFunction} to use as the collect transformation function * @param target the MutableFloatCollection to append to for all elements in this {@code RichIterable} * @return {@code target}, which contains appended elements as a result of the collect transformation * @since 5.0 */ R collectFloat(FloatFunction floatFunction, R target); /** * Returns a new primitive {@code int} iterable with the results of applying the specified function on each element * of the source collection. This method is also commonly called transform or map. *

*

e.g.
     * return people.collectInt(new IntFunction<Person>()
     * {
     *     public int intValueOf(Person person)
     *     {
     *         return person.getAge();
     *     }
     * });
     * 
* * @since 4.0 */ IntIterable collectInt(IntFunction intFunction); /** * Same as {@link #collectInt(IntFunction)}, except that the results are gathered into the specified {@code target} * collection. *

*

e.g.
     * return people.collectInt(new IntFunction<Person>()
     * {
     *     public int intValueOf(Person person)
     *     {
     *         return person.getAge();
     *     }
     * }, new IntArrayList());
     * 
* * @param intFunction a {@link IntFunction} to use as the collect transformation function * @param target the MutableIntCollection to append to for all elements in this {@code RichIterable} * @return {@code target}, which contains appended elements as a result of the collect transformation * @since 5.0 */ R collectInt(IntFunction intFunction, R target); /** * Returns a new primitive {@code long} iterable with the results of applying the specified function on each element * of the source collection. This method is also commonly called transform or map. *

*

e.g.
     * return people.collectLong(new LongFunction<Person>()
     * {
     *     public long longValueOf(Person person)
     *     {
     *         return person.getGuid();
     *     }
     * });
     * 
* * @since 4.0 */ LongIterable collectLong(LongFunction longFunction); /** * Same as {@link #collectLong(LongFunction)}, except that the results are gathered into the specified {@code target} * collection. *

*

e.g.
     * return people.collectLong(new LongFunction<Person>()
     * {
     *     public long longValueOf(Person person)
     *     {
     *         return person.getGuid();
     *     }
     * }, new LongArrayList());
     * 
* * @param longFunction a {@link LongFunction} to use as the collect transformation function * @param target the MutableLongCollection to append to for all elements in this {@code RichIterable} * @return {@code target}, which contains appended elements as a result of the collect transformation * @since 5.0 */ R collectLong(LongFunction longFunction, R target); /** * Returns a new primitive {@code short} iterable with the results of applying the specified function on each element * of the source collection. This method is also commonly called transform or map. *

*

e.g.
     * return people.collectShort(new ShortFunction<Person>()
     * {
     *     public short shortValueOf(Person person)
     *     {
     *         return person.getNumberOfJunkMailItemsReceivedPerMonth();
     *     }
     * });
     * 
* * @since 4.0 */ ShortIterable collectShort(ShortFunction shortFunction); /** * Same as {@link #collectShort(ShortFunction)}, except that the results are gathered into the specified {@code target} * collection. *

*

e.g.
     * return people.collectShort(new ShortFunction<Person>()
     * {
     *     public short shortValueOf(Person person)
     *     {
     *         return person.getNumberOfJunkMailItemsReceivedPerMonth;
     *     }
     * }, new ShortArrayList());
     * 
* * @param shortFunction a {@link ShortFunction} to use as the collect transformation function * @param target the MutableShortCollection to append to for all elements in this {@code RichIterable} * @return {@code target}, which contains appended elements as a result of the collect transformation * @since 5.0 */ R collectShort(ShortFunction shortFunction, R target); /** * Same as {@link #collect(Function)}, except that the results are gathered into the specified {@code target} * collection. *

*

e.g.
     * return people.collect(new Function<Person, String>()
     * {
     *     public String valueOf(Person person)
     *     {
     *         return person.getFirstName() + " " + person.getLastName();
     *     }
     * }, Lists.mutable.of());
     * 
* * @param function a {@link Function} to use as the collect transformation function * @param target the Collection to append to for all elements in this {@code RichIterable} that meet select criteria {@code function} * @return {@code target}, which contains appended elements as a result of the collect transformation * @see #collect(Function) * @since 1.0 */ > R collect(Function function, R target); /** * Same as collect with a {@code Function2} and specified parameter which is passed to the block *

*

e.g.
     * Function2 addParameterFunction =
     * new Function2()
     * {
     *      public Integer value(final Integer each, final Integer parameter)
     *      {
     *          return each + parameter;
     *      }
     * };
     * FastList.newListWith(1, 2, 3).collectWith(addParameterFunction, Integer.valueOf(1));
     * 
* * @param function A {@link Function2} to use as the collect transformation function * @param parameter A parameter to pass in for evaluation of the second argument {@code P} in {@code function} * @return A new {@code RichIterable} that contains the transformed elements returned by {@link Function2#value(Object, Object)} * @see #collect(Function) * @since 5.0 */ RichIterable collectWith( Function2 function, P parameter); /** * Same as collectWith but with a targetCollection parameter to gather the results. *

*

e.g.
     * Function2 addParameterFunction =
     * new Function2()
     * {
     *      public Integer value(final Integer each, final Integer parameter)
     *      {
     *          return each + parameter;
     *      }
     * };
     * FastList.newListWith(1, 2, 3).collectWith(addParameterFunction, Integer.valueOf(1), UnifiedSet.newSet());
     * 
* * @param function a {@link Function2} to use as the collect transformation function * @param parameter a parameter to pass in for evaluation of the second argument {@code P} in {@code function} * @param targetCollection the Collection to append to for all elements in this {@code RichIterable} that meet select criteria {@code function} * @return {@code targetCollection}, which contains appended elements as a result of the collect transformation * @since 1.0 */ > R collectWith( Function2 function, P parameter, R targetCollection); /** * Returns a new collection with the results of applying the specified function on each element of the source * collection, but only for those elements which return true upon evaluation of the predicate. This is the * the optimized equivalent of calling iterable.select(predicate).collect(function). *

*

e.g.
     * Lists.mutable.of().with(1, 2, 3).collectIf(Predicates.notNull(), Functions.getToString())
     * 
* * @since 1.0 */ RichIterable collectIf(Predicate predicate, Function function); /** * Same as the collectIf method with two parameters but uses the specified target collection for the results. * * @param predicate a {@link Predicate} to use as the select criteria * @param function a {@link Function} to use as the collect transformation function * @param target the Collection to append to for all elements in this {@code RichIterable} that meet the collect criteria {@code predicate} * @return {@code targetCollection}, which contains appended elements as a result of the collect criteria and transformation * @see #collectIf(Predicate, Function) * @since 1.0 */ > R collectIf( Predicate predicate, Function function, R target); /** * {@code flatCollect} is a special case of {@link #collect(Function)}. With {@code collect}, when the {@link Function} returns * a collection, the result is a collection of collections. {@code flatCollect} outputs a single "flattened" collection * instead. This method is commonly called flatMap. *

* Consider the following example where we have a {@code Person} class, and each {@code Person} has a list of {@code Address} objects. Take the following {@link Function}: *

     * Function<Person, List<Address>> addressFunction = new Function<Person, List<Address>>()
     * {
     *     public List<Address> valueOf(Person person)
     *     {
     *         return person.getAddresses();
     *     }
     * };
     * MutableList<Person> people = ...;
     * 
* Using {@code collect} returns a collection of collections of addresses. *
     * MutableList<List<Address>> addresses = people.collect(addressFunction);
     * 
* Using {@code flatCollect} returns a single flattened list of addresses. *
     * MutableList<Address> addresses = people.flatCollect(addressFunction);
     * 
* * @param function The {@link Function} to apply * @return a new flattened collection produced by applying the given {@code function} * @since 1.0 */ RichIterable flatCollect(Function> function); /** * Same as flatCollect, only the results are collected into the target collection. * * @param function The {@link Function} to apply * @param target The collection into which results should be added. * @return {@code target}, which will contain a flattened collection of results produced by applying the given {@code function} * @see #flatCollect(Function) */ > R flatCollect(Function> function, R target); /** * Returns the first element of the iterable for which the predicate evaluates to true or null in the case where no * element returns true. This method is commonly called find. *

*

e.g.
     * return people.detect(new Predicate<Person>()
     * {
     *     public boolean value(Person person)
     *     {
     *         return person.getFirstName().equals("John") && person.getLastName().equals("Smith");
     *     }
     * });
     * 
* * @since 1.0 */ T detect(Predicate predicate); /** * Returns the first element that evaluates to true for the specified predicate2 and parameter, or null if none * evaluate to true. *

*

e.g.
     * people.detectWith(new Predicate2<Person, String>()
     * {
     *     public boolean value(Person person, String fullName)
     *     {
     *         return person.getFullName().equals(fullName);
     *     }
     * }, "John Smith");
     * 
* * @since 5.0 */

T detectWith(Predicate2 predicate, P parameter); /** * Returns the first element of the iterable for which the predicate evaluates to true. If no element matches * the predicate, then returns the value of applying the specified function. * * @since 1.0 */ T detectIfNone(Predicate predicate, Function0 function); /** * Returns the first element of the iterable that evaluates to true for the specified predicate2 and parameter, or * returns the value of evaluating the specified function. * * @since 5.0 */

T detectWithIfNone( Predicate2 predicate, P parameter, Function0 function); /** * Return the total number of elements that answer true to the specified predicate. *

*

e.g.
     * return people.count(new Predicate<Person>()
     * {
     *     public boolean value(Person person)
     *     {
     *         return person.getAddress().getState().getName().equals("New York");
     *     }
     * });
     * 
* * @since 1.0 */ int count(Predicate predicate); /** * Returns the total number of elements that evaluate to true for the specified predicate. *

*

e.g.
     * return lastNames.countWith(PredicatesLite.equal(), "Smith");
     * 
*/

int countWith(Predicate2 predicate, P parameter); /** * Returns true if the predicate evaluates to true for any element of the iterable. Returns * false if the iterable is empty, or if no element returned true when evaluating the predicate. * * @since 1.0 */ boolean anySatisfy(Predicate predicate); /** * Returns true if the predicate evaluates to true for any element of the collection, or return false. Returns * false if the collection is empty. * * @since 5.0 */

boolean anySatisfyWith(Predicate2 predicate, P parameter); /** * Returns true if the predicate evaluates to true for every element of the iterable or if the iterable is empty. * Otherwise, returns false. * * @since 1.0 */ boolean allSatisfy(Predicate predicate); /** * Returns true if the predicate evaluates to true for every element of the collection, or returns false. * * @since 5.0 */

boolean allSatisfyWith(Predicate2 predicate, P parameter); /** * Returns true if the predicate evaluates to false for every element of the iterable or if the iterable is empty. * Otherwise, returns false. * * @since 3.0 */ boolean noneSatisfy(Predicate predicate); /** * Returns true if the predicate evaluates to false for every element of the collection, or return false. Returns * true if the collection is empty. * * @since 5.0 */

boolean noneSatisfyWith(Predicate2 predicate, P parameter); /** * Returns the final result of evaluating function using each element of the iterable and the previous evaluation * result as the parameters. The injected value is used for the first parameter of the first evaluation, and the current * item in the iterable is used as the second parameter. This method is commonly called fold or sometimes reduce. * * @since 1.0 */ IV injectInto(IV injectedValue, Function2 function); /** * Returns the final int result of evaluating function using each element of the iterable and the previous evaluation * result as the parameters. The injected value is used for the first parameter of the first evaluation, and the current * item in the iterable is used as the second parameter. * * @since 1.0 */ int injectInto(int injectedValue, IntObjectToIntFunction function); /** * Returns the final long result of evaluating function using each element of the iterable and the previous evaluation * result as the parameters. The injected value is used for the first parameter of the first evaluation, and the current * item in the iterable is used as the second parameter. * * @since 1.0 */ long injectInto(long injectedValue, LongObjectToLongFunction function); /** * Returns the final float result of evaluating function using each element of the iterable and the previous evaluation * result as the parameters. The injected value is used for the first parameter of the first evaluation, and the current * item in the iterable is used as the second parameter. * * @since 2.0 */ float injectInto(float injectedValue, FloatObjectToFloatFunction function); /** * Returns the final double result of evaluating function using each element of the iterable and the previous evaluation * result as the parameters. The injected value is used for the first parameter of the first evaluation, and the current * item in the iterable is used as the second parameter. * * @since 1.0 */ double injectInto(double injectedValue, DoubleObjectToDoubleFunction function); /** * Converts the collection to a MutableList implementation. * * @since 1.0 */ MutableList toList(); /** * Converts the collection to a MutableList implementation and sorts it using the natural order of the elements. * * @since 1.0 */ MutableList toSortedList(); /** * Converts the collection to a MutableList implementation and sorts it using the specified comparator. * * @since 1.0 */ MutableList toSortedList(Comparator comparator); /** * Converts the collection to a MutableList implementation and sorts it based on the natural order of the * attribute returned by {@code function}. * * @since 1.0 */ > MutableList toSortedListBy(Function function); /** * Converts the collection to a MutableSet implementation. * * @since 1.0 */ MutableSet toSet(); /** * Converts the collection to a MutableSortedSet implementation and sorts it using the natural order of the * elements. * * @since 1.0 */ MutableSortedSet toSortedSet(); /** * Converts the collection to a MutableSortedSet implementation and sorts it using the specified comparator. * * @since 1.0 */ MutableSortedSet toSortedSet(Comparator comparator); /** * Converts the collection to a MutableSortedSet implementation and sorts it based on the natural order of the * attribute returned by {@code function}. * * @since 1.0 */ > MutableSortedSet toSortedSetBy(Function function); /** * Converts the collection to the default MutableBag implementation. * * @since 1.0 */ MutableBag toBag(); /** * Converts the collection to a MutableMap implementation using the specified key and value functions. * * @since 1.0 */ MutableMap toMap( Function keyFunction, Function valueFunction); /** * Converts the collection to a MutableSortedMap implementation using the specified key and value functions * sorted by the key elements' natural ordering. * * @since 1.0 */ MutableSortedMap toSortedMap( Function keyFunction, Function valueFunction); /** * Converts the collection to a MutableSortedMap implementation using the specified key and value functions * sorted by the given comparator. * * @since 1.0 */ MutableSortedMap toSortedMap( Comparator comparator, Function keyFunction, Function valueFunction); /** * Returns a lazy (deferred) iterable, most likely implemented by calling LazyIterate.adapt(this). * * @since 1.0. */ LazyIterable asLazy(); /** * Converts this iterable to an array. * * @see Collection#toArray() * @since 1.0 */ Object[] toArray(); /** * Converts this iterable to an array using the specified target array, assuming the target array is as long * or longer than the iterable. * * @see Collection#toArray(Object[]) * @since 1.0 */ T[] toArray(T[] target); /** * Returns the minimum element out of this container based on the comparator. * * @throws NoSuchElementException if the RichIterable is empty * @since 1.0 */ T min(Comparator comparator); /** * Returns the maximum element out of this container based on the comparator. * * @throws NoSuchElementException if the RichIterable is empty * @since 1.0 */ T max(Comparator comparator); /** * Returns the minimum element out of this container based on the natural order. * * @throws ClassCastException if the elements are not {@link Comparable} * @throws NoSuchElementException if the RichIterable is empty * @since 1.0 */ T min(); /** * Returns the maximum element out of this container based on the natural order. * * @throws ClassCastException if the elements are not {@link Comparable} * @throws NoSuchElementException if the RichIterable is empty * @since 1.0 */ T max(); /** * Returns the minimum elements out of this container based on the natural order of the attribute returned by Function. * * @throws NoSuchElementException if the RichIterable is empty * @since 1.0 */ > T minBy(Function function); /** * Returns the maximum elements out of this container based on the natural order of the attribute returned by Function. * * @throws NoSuchElementException if the RichIterable is empty * @since 1.0 */ > T maxBy(Function function); /** * Returns the final long result of evaluating function for each element of the iterable and adding the results * together. * * @since 2.0 */ long sumOfInt(IntFunction function); /** * Returns the final double result of evaluating function for each element of the iterable and adding the results * together. * * @since 2.0 */ double sumOfFloat(FloatFunction function); /** * Returns the final long result of evaluating function for each element of the iterable and adding the results * together. * * @since 2.0 */ long sumOfLong(LongFunction function); /** * Returns the final double result of evaluating function for each element of the iterable and adding the results * together. * * @since 2.0 */ double sumOfDouble(DoubleFunction function); /** * Returns a string representation of this collection by delegating to {@link #makeString(String)} and defaulting * the separator parameter to the characters ", " (comma and space). * * @return a string representation of this collection. * @since 1.0 */ String makeString(); /** * Returns a string representation of this collection by delegating to {@link #makeString(String, String, String)} * and defaulting the start and end parameters to "" (the empty String). * * @return a string representation of this collection. * @since 1.0 */ String makeString(String separator); /** * Returns a string representation of this collection. The string representation consists of a list of the * collection's elements in the order they are returned by its iterator, enclosed in the start and end strings. * Adjacent elements are separated by the separator string. Elements are converted to strings as by * String.valueOf(Object). * * @return a string representation of this collection. * @since 1.0 */ String makeString(String start, String separator, String end); /** * Prints a string representation of this collection onto the given {@code Appendable}. Prints the string returned * by {@link #makeString()}. * * @since 1.0 */ void appendString(Appendable appendable); /** * Prints a string representation of this collection onto the given {@code Appendable}. Prints the string returned * by {@link #makeString(String)}. * * @since 1.0 */ void appendString(Appendable appendable, String separator); /** * Prints a string representation of this collection onto the given {@code Appendable}. Prints the string returned * by {@link #makeString(String, String, String)}. * * @since 1.0 */ void appendString(Appendable appendable, String start, String separator, String end); /** * For each element of the iterable, the function is evaluated and the results of these evaluations are collected * into a new multimap, where the transformed value is the key and the original values are added to the same (or similar) * species of collection as the source iterable. *

*

e.g.
     * return people.groupBy(new Function<Person, String>()
     * {
     *     public String value(Person person)
     *     {
     *         return person.getFirstName() + " " + person.getLastName();
     *     }
     * });
     * 
* * @since 1.0 */ Multimap groupBy(Function function); /** * Same as {@link #groupBy(Function)}, except that the results are gathered into the specified {@code target} * multimap. *

*

e.g.
     * return people.groupBy(new Function<Person, String>()
     * {
     *     public String value(Person person)
     *     {
     *         return person.getFirstName() + " " + person.getLastName();
     *     }
     * }, new FastListMultimap<String, Person>());
     * 
* * @since 1.0 */ > R groupBy(Function function, R target); /** * Similar to {@link #groupBy(Function)}, except the result of evaluating function will return a collection of keys * for each value. * * @since 1.0 */ Multimap groupByEach(Function> function); /** * Same as {@link #groupByEach(Function)}, except that the results are gathered into the specified {@code target} * multimap. * * @since 1.0 */ > R groupByEach( Function> function, R target); /** * For each element of the iterable, the function is evaluated and he results of these evaluations are collected * into a new map, where the transformed value is the key. The generated keys must each be unique, or else an * exception is thrown. * * @throws IllegalStateException if the keys returned by the function are not unique * @see #groupBy(Function) * @since 5.0 */ MapIterable groupByUniqueKey(Function function); /** * Returns a string representation of this RichIterable. The string representation consists of a list of the * RichIterable's elements in the order they are returned by its iterator, enclosed in square brackets * ("[]"). Adjacent elements are separated by the characters ", " (comma and space). Elements * are converted to strings as by {@link String#valueOf(Object)}. * * @return a string representation of this RichIterable * @since 1.0 */ @Override String toString(); /** * Returns a {@code RichIterable} formed from this {@code RichIterable} and another {@code RichIterable} by * combining corresponding elements in pairs. If one of the two {@code RichIterable}s is longer than the other, its * remaining elements are ignored. * * @param that The {@code RichIterable} providing the second half of each result pair * @param the type of the second half of the returned pairs * @return A new {@code RichIterable} containing pairs consisting of corresponding elements of this {@code * RichIterable} and that. The length of the returned {@code RichIterable} is the minimum of the lengths of * this {@code RichIterable} and that. * @since 1.0 */ RichIterable> zip(Iterable that); /** * Same as {@link #zip(Iterable)} but uses {@code target} for output. * * @since 1.0 */ >> R zip(Iterable that, R target); /** * Zips this {@code RichIterable} with its indices. * * @return A new {@code RichIterable} containing pairs consisting of all elements of this {@code RichIterable} * paired with their index. Indices start at 0. * @see #zip(Iterable) * @since 1.0 */ RichIterable> zipWithIndex(); /** * Same as {@link #zipWithIndex()} but uses {@code target} for output. * * @since 1.0 */ >> R zipWithIndex(R target); /** * Partitions elements in fixed size chunks. * * @param size the number of elements per chunk * @return A {@code RichIterable} containing {@code RichIterable}s of size {@code size}, except the last will be * truncated if the elements don't divide evenly. * @since 1.0 */ RichIterable> chunk(int size); /** * Applies an aggregate procedure over the iterable grouping results into a Map based on the specific groupBy function. * Aggregate results are required to be mutable as they will be changed in place by the procedure. A second function * specifies the initial "zero" aggregate value to work with (i.e. new AtomicInteger(0)). * * @since 3.0 */ MapIterable aggregateInPlaceBy(Function groupBy, Function0 zeroValueFactory, Procedure2 mutatingAggregator); /** * Applies an aggregate function over the iterable grouping results into a map based on the specific groupBy function. * Aggregate results are allowed to be immutable as they will be replaced in place in the map. A second function * specifies the initial "zero" aggregate value to work with (i.e. Integer.valueOf(0)). * * @since 3.0 */ MapIterable aggregateBy(Function groupBy, Function0 zeroValueFactory, Function2 nonMutatingAggregator); } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/annotation/000077500000000000000000000000001234315411400306115ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/annotation/Beta.java000066400000000000000000000016601234315411400323320ustar00rootroot00000000000000/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.annotation; /** * API tagged Beta is new API that has not stabilized. The library generally follows * semantic versioning and preserves backwards compatibility in minor and fix releases. * The exception is Beta API, which may change at any time. */ public @interface Beta { } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/bag/000077500000000000000000000000001234315411400271705ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/bag/Bag.java000066400000000000000000000104661234315411400305330ustar00rootroot00000000000000/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.bag; import java.util.Map; import com.gs.collections.api.RichIterable; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.predicate.primitive.IntPredicate; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.map.MapIterable; import com.gs.collections.api.multimap.bag.BagMultimap; import com.gs.collections.api.partition.bag.PartitionBag; import com.gs.collections.api.set.SetIterable; import com.gs.collections.api.tuple.Pair; /** * A Bag is a Collection whose elements are unordered and may contain duplicate entries. It varies from * MutableCollection in that it adds a protocol for determining, adding, and removing the number of occurrences for an * item. * * @since 1.0 */ public interface Bag extends RichIterable { /** * Two bagsb1 and b2 are equal if m1.toMapOfItemToCount().equals(m2.toMapOfItemToCount()). * * @see Map#equals(Object) */ @Override boolean equals(Object object); /** * Returns the hash code for this Bag, defined as this.{@link #toMapOfItemToCount()}.hashCode(). * * @see Map#hashCode() */ @Override int hashCode(); Bag select(Predicate predicate);

Bag selectWith(Predicate2 predicate, P parameter); Bag reject(Predicate predicate);

Bag rejectWith(Predicate2 predicate, P parameter); PartitionBag partition(Predicate predicate);

PartitionBag partitionWith(Predicate2 predicate, P parameter); Bag selectInstancesOf(Class clazz); BagMultimap groupBy(Function function); BagMultimap groupByEach(Function> function); SetIterable> zipWithIndex(); /** * For each distinct item, with the number of occurrences, execute the specified procedure. */ void forEachWithOccurrences(ObjectIntProcedure procedure); /** * The occurrences of a distinct item in the bag. */ int occurrencesOf(Object item); /** * Returns all elements of the bag that have a number of occurrences that satisfy the predicate. * * @since 3.0 */ Bag selectByOccurrences(IntPredicate predicate); /** * The size of the Bag when counting only distinct elements. */ int sizeDistinct(); /** * Converts the Bag to a Map of the Item type to its count as an Integer. */ MapIterable toMapOfItemToCount(); /** * Returns a string representation of this bag. The string representation consists of a list of element-count mappings. * The elements each appear once, in an order consistent with other methods like {@link #forEachWithOccurrences(ObjectIntProcedure)} * and {@link #iterator()}. The element-count mappings are enclosed in braces ("{}"). Adjacent mappings are * separated by the characters ", " (comma and space). Each element-count mapping is rendered as the element * followed by an equals sign ("=") followed by the number of ooccurrences. Elements and are converted to * strings as by {@link String#valueOf(Object)}. *

* The string representation is similar to {@link java.util.AbstractMap#toString()}, not {@link RichIterable#toString()}. * * @return a string representation of this bag * @since 3.0 */ String toStringOfItemToCount(); } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/bag/ImmutableBag.java000066400000000000000000000106361234315411400323720ustar00rootroot00000000000000/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.bag; import com.gs.collections.api.bag.primitive.ImmutableBooleanBag; import com.gs.collections.api.bag.primitive.ImmutableByteBag; import com.gs.collections.api.bag.primitive.ImmutableCharBag; import com.gs.collections.api.bag.primitive.ImmutableDoubleBag; import com.gs.collections.api.bag.primitive.ImmutableFloatBag; import com.gs.collections.api.bag.primitive.ImmutableIntBag; import com.gs.collections.api.bag.primitive.ImmutableLongBag; import com.gs.collections.api.bag.primitive.ImmutableShortBag; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.predicate.primitive.IntPredicate; import com.gs.collections.api.collection.ImmutableCollection; import com.gs.collections.api.multimap.bag.ImmutableBagMultimap; import com.gs.collections.api.partition.bag.PartitionImmutableBag; import com.gs.collections.api.set.ImmutableSet; import com.gs.collections.api.tuple.Pair; /** * @since 1.0 */ public interface ImmutableBag extends UnsortedBag, ImmutableCollection { ImmutableBag newWith(T element); ImmutableBag newWithout(T element); ImmutableBag newWithAll(Iterable elements); ImmutableBag newWithoutAll(Iterable elements); ImmutableBag selectByOccurrences(IntPredicate predicate); ImmutableBag select(Predicate predicate);

ImmutableBag selectWith(Predicate2 predicate, P parameter); ImmutableBag reject(Predicate predicate);

ImmutableBag rejectWith(Predicate2 predicate, P parameter); PartitionImmutableBag partition(Predicate predicate);

PartitionImmutableBag partitionWith(Predicate2 predicate, P parameter); ImmutableBag selectInstancesOf(Class clazz); ImmutableBag collect(Function function); ImmutableBooleanBag collectBoolean(BooleanFunction booleanFunction); ImmutableByteBag collectByte(ByteFunction byteFunction); ImmutableCharBag collectChar(CharFunction charFunction); ImmutableDoubleBag collectDouble(DoubleFunction doubleFunction); ImmutableFloatBag collectFloat(FloatFunction floatFunction); ImmutableIntBag collectInt(IntFunction intFunction); ImmutableLongBag collectLong(LongFunction longFunction); ImmutableShortBag collectShort(ShortFunction shortFunction); ImmutableBag collectWith(Function2 function, P parameter); ImmutableBag collectIf(Predicate predicate, Function function); ImmutableBag flatCollect(Function> function); ImmutableBagMultimap groupBy(Function function); ImmutableBagMultimap groupByEach(Function> function); ImmutableBag> zip(Iterable that); ImmutableSet> zipWithIndex(); } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/bag/MutableBag.java000066400000000000000000000115111234315411400320350ustar00rootroot00000000000000/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.bag; import com.gs.collections.api.bag.primitive.MutableBooleanBag; import com.gs.collections.api.bag.primitive.MutableByteBag; import com.gs.collections.api.bag.primitive.MutableCharBag; import com.gs.collections.api.bag.primitive.MutableDoubleBag; import com.gs.collections.api.bag.primitive.MutableFloatBag; import com.gs.collections.api.bag.primitive.MutableIntBag; import com.gs.collections.api.bag.primitive.MutableLongBag; import com.gs.collections.api.bag.primitive.MutableShortBag; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.predicate.primitive.IntPredicate; import com.gs.collections.api.collection.MutableCollection; import com.gs.collections.api.multimap.bag.MutableBagMultimap; import com.gs.collections.api.partition.bag.PartitionMutableBag; import com.gs.collections.api.set.MutableSet; import com.gs.collections.api.tuple.Pair; /** * A MutableBag is a Collection whose elements are unordered and may contain duplicate entries. It varies from * MutableCollection in that it adds a protocol for determining, adding, and removing the number of occurrences for an * item. * * @since 1.0 */ public interface MutableBag extends UnsortedBag, MutableCollection { MutableBag selectByOccurrences(IntPredicate predicate); MutableBag with(T element); MutableBag without(T element); MutableBag withAll(Iterable elements); MutableBag withoutAll(Iterable elements); MutableBag newEmpty(); MutableBag asUnmodifiable(); MutableBag asSynchronized(); PartitionMutableBag partition(Predicate predicate);

PartitionMutableBag partitionWith(Predicate2 predicate, P parameter); MutableBagMultimap groupBy(Function function); MutableBagMultimap groupByEach(Function> function); MutableBag> zip(Iterable that); MutableSet> zipWithIndex(); MutableBag select(Predicate predicate);

MutableBag selectWith(Predicate2 predicate, P parameter); MutableBag reject(Predicate predicate);

MutableBag rejectWith(Predicate2 predicate, P parameter); MutableBag selectInstancesOf(Class clazz); MutableBag collect(Function function); MutableByteBag collectByte(ByteFunction byteFunction); MutableCharBag collectChar(CharFunction charFunction); MutableIntBag collectInt(IntFunction intFunction); MutableBooleanBag collectBoolean(BooleanFunction booleanFunction); MutableDoubleBag collectDouble(DoubleFunction doubleFunction); MutableFloatBag collectFloat(FloatFunction floatFunction); MutableLongBag collectLong(LongFunction longFunction); MutableShortBag collectShort(ShortFunction shortFunction); MutableBag collectWith(Function2 function, P parameter); MutableBag collectIf(Predicate predicate, Function function); MutableBag flatCollect(Function> function); void addOccurrences(T item, int occurrences); boolean removeOccurrences(Object item, int occurrences); boolean setOccurrences(T item, int occurrences); } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/bag/ParallelBag.java000066400000000000000000000036231234315411400322050ustar00rootroot00000000000000/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.bag; import com.gs.collections.api.ParallelIterable; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.multimap.bag.BagMultimap; /** * @since 5.0 */ @Beta public interface ParallelBag extends ParallelIterable { void forEachWithOccurrences(ObjectIntProcedure procedure); /** * Creates a parallel iterable for selecting elements from the current iterable. */ ParallelBag select(Predicate predicate);

ParallelBag selectWith(Predicate2 predicate, P parameter); /** * Creates a parallel iterable for rejecting elements from the current iterable. */ ParallelBag reject(Predicate predicate);

ParallelBag rejectWith(Predicate2 predicate, P parameter); ParallelBag selectInstancesOf(Class clazz); BagMultimap groupBy(Function function); BagMultimap groupByEach(Function> function); } ParallelUnsortedBag.java000066400000000000000000000110001234315411400336360ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/bag/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.bag; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.multimap.bag.UnsortedBagMultimap; import com.gs.collections.api.set.ParallelUnsortedSetIterable; /** * @since 5.0 */ @Beta public interface ParallelUnsortedBag extends ParallelBag { ParallelUnsortedSetIterable asUnique(); /** * Creates a parallel iterable for selecting elements from the current iterable. */ ParallelUnsortedBag select(Predicate predicate);

ParallelUnsortedBag selectWith(Predicate2 predicate, P parameter); /** * Creates a parallel iterable for rejecting elements from the current iterable. */ ParallelUnsortedBag reject(Predicate predicate);

ParallelUnsortedBag rejectWith(Predicate2 predicate, P parameter); ParallelUnsortedBag selectInstancesOf(Class clazz); /** * Creates a parallel iterable for collecting elements from the current iterable. */ ParallelUnsortedBag collect(Function function); ParallelUnsortedBag collectWith(Function2 function, P parameter); /** * Creates a parallel iterable for selecting and collecting elements from the current iterable. */ ParallelUnsortedBag collectIf(Predicate predicate, Function function); /** * Creates a parallel flattening iterable for the current iterable. */ ParallelUnsortedBag flatCollect(Function> function); UnsortedBagMultimap groupBy(Function function); UnsortedBagMultimap groupByEach(Function> function); // /** // * Returns a parallel BooleanIterable which will transform the underlying iterable data to boolean values based on the booleanFunction. // */ // ParallelBooleanIterable collectBoolean(BooleanFunction booleanFunction); // // /** // * Returns a parallel ByteIterable which will transform the underlying iterable data to byte values based on the byteFunction. // */ // ParallelByteIterable collectByte(ByteFunction byteFunction); // // /** // * Returns a parallel CharIterable which will transform the underlying iterable data to char values based on the charFunction. // */ // ParallelCharIterable collectChar(CharFunction charFunction); // // /** // * Returns a parallel DoubleIterable which will transform the underlying iterable data to double values based on the doubleFunction. // */ // ParallelDoubleIterable collectDouble(DoubleFunction doubleFunction); // // /** // * Returns a parallel FloatIterable which will transform the underlying iterable data to float values based on the floatFunction. // */ // ParallelFloatIterable collectFloat(FloatFunction floatFunction); // // /** // * Returns a parallel IntIterable which will transform the underlying iterable data to int values based on the intFunction. // */ // ParallelIntIterable collectInt(IntFunction intFunction); // // /** // * Returns a parallel LongIterable which will transform the underlying iterable data to long values based on the longFunction. // */ // ParallelLongIterable collectLong(LongFunction longFunction); // // /** // * Returns a parallel ShortIterable which will transform the underlying iterable data to short values based on the shortFunction. // */ // ParallelShortIterable collectShort(ShortFunction shortFunction); } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/bag/UnsortedBag.java000066400000000000000000000077471234315411400322670ustar00rootroot00000000000000/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.bag; import com.gs.collections.api.bag.primitive.BooleanBag; import com.gs.collections.api.bag.primitive.ByteBag; import com.gs.collections.api.bag.primitive.CharBag; import com.gs.collections.api.bag.primitive.DoubleBag; import com.gs.collections.api.bag.primitive.FloatBag; import com.gs.collections.api.bag.primitive.IntBag; import com.gs.collections.api.bag.primitive.LongBag; import com.gs.collections.api.bag.primitive.ShortBag; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.predicate.primitive.IntPredicate; import com.gs.collections.api.multimap.bag.UnsortedBagMultimap; import com.gs.collections.api.partition.bag.PartitionUnsortedBag; import com.gs.collections.api.set.UnsortedSetIterable; import com.gs.collections.api.tuple.Pair; public interface UnsortedBag extends Bag { UnsortedBag selectByOccurrences(IntPredicate predicate); UnsortedBag select(Predicate predicate);

UnsortedBag selectWith(Predicate2 predicate, P parameter); UnsortedBag reject(Predicate predicate);

UnsortedBag rejectWith(Predicate2 predicate, P parameter); UnsortedBag selectInstancesOf(Class clazz); PartitionUnsortedBag partition(Predicate predicate); UnsortedBag collect(Function function); BooleanBag collectBoolean(BooleanFunction booleanFunction); ByteBag collectByte(ByteFunction byteFunction); CharBag collectChar(CharFunction charFunction); DoubleBag collectDouble(DoubleFunction doubleFunction); FloatBag collectFloat(FloatFunction floatFunction); IntBag collectInt(IntFunction intFunction); LongBag collectLong(LongFunction longFunction); ShortBag collectShort(ShortFunction shortFunction); UnsortedBag collectWith(Function2 function, P parameter); UnsortedBag collectIf(Predicate predicate, Function function); UnsortedBag flatCollect(Function> function); UnsortedBag> zip(Iterable that); UnsortedSetIterable> zipWithIndex(); UnsortedBagMultimap groupBy(Function function); UnsortedBagMultimap groupByEach(Function> function); /** * Converts the UnsortedBag to an ImmutableBag. If the bag is immutable, it returns itself. */ ImmutableBag toImmutable(); } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/bag/package-info.java000066400000000000000000000026271234315411400323660ustar00rootroot00000000000000/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains interfaces for Bag API. *

* A Bag is a {@link java.util.Collection} which contains elements that are unordered, and may contain duplicate entries. It adds a protocol for * adding, removing, and determining the number of occurrences for an item. *

*

* This package contains 3 interfaces: *

    *
  • * {@link com.gs.collections.api.bag.Bag} - contains the common API for Mutable and Immutable Bag. *
  • *
  • * {@link com.gs.collections.api.bag.MutableBag} - a Bag whose contents can be altered after initialization. *
  • *
  • * {@link com.gs.collections.api.bag.ImmutableBag} - a Bag whose contents cannot be altered after initialization. *
  • *
*

*/ package com.gs.collections.api.bag; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/bag/primitive/000077500000000000000000000000001234315411400312005ustar00rootroot00000000000000package-info.java000066400000000000000000000016411234315411400343120ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/bag/primitive/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains API for Primitive Bags with Mutable and Immutable variants. *

* A primitive bag is similar to a {@link com.gs.collections.api.bag.Bag}, but is memory-optimized for primitive types. * These bags are backed by primitive int maps. *

*/ package com.gs.collections.api.bag.primitive; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/bag/sorted/000077500000000000000000000000001234315411400304705ustar00rootroot00000000000000ImmutableSortedBag.java000066400000000000000000000133301234315411400347660ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/bag/sorted/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.bag.sorted; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.predicate.primitive.IntPredicate; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.collection.ImmutableCollection; import com.gs.collections.api.list.ImmutableList; import com.gs.collections.api.list.primitive.ImmutableBooleanList; import com.gs.collections.api.list.primitive.ImmutableByteList; import com.gs.collections.api.list.primitive.ImmutableCharList; import com.gs.collections.api.list.primitive.ImmutableDoubleList; import com.gs.collections.api.list.primitive.ImmutableFloatList; import com.gs.collections.api.list.primitive.ImmutableIntList; import com.gs.collections.api.list.primitive.ImmutableLongList; import com.gs.collections.api.list.primitive.ImmutableShortList; import com.gs.collections.api.map.ImmutableMap; import com.gs.collections.api.multimap.sortedbag.ImmutableSortedBagMultimap; import com.gs.collections.api.partition.bag.sorted.PartitionImmutableSortedBag; import com.gs.collections.api.set.sorted.ImmutableSortedSet; import com.gs.collections.api.tuple.Pair; import net.jcip.annotations.Immutable; /** * ImmutableSortedBag is the non-modifiable equivalent interface to {@link MutableSortedBag}. * * @since 4.2 */ @Immutable public interface ImmutableSortedBag extends ImmutableCollection, SortedBag { ImmutableSortedBag newWith(T element); ImmutableSortedBag newWithout(T element); ImmutableSortedBag newWithAll(Iterable elements); ImmutableSortedBag newWithoutAll(Iterable elements); ImmutableSortedBag selectByOccurrences(IntPredicate predicate); ImmutableSortedBag select(Predicate predicate);

ImmutableSortedBag selectWith(Predicate2 predicate, P parameter); ImmutableSortedBag reject(Predicate predicate);

ImmutableSortedBag rejectWith(Predicate2 predicate, P parameter); PartitionImmutableSortedBag partition(Predicate predicate);

PartitionImmutableSortedBag partitionWith(Predicate2 predicate, P parameter); ImmutableSortedBag selectInstancesOf(Class clazz); ImmutableList collect(Function function); ImmutableBooleanList collectBoolean(BooleanFunction booleanFunction); ImmutableByteList collectByte(ByteFunction byteFunction); ImmutableCharList collectChar(CharFunction charFunction); ImmutableDoubleList collectDouble(DoubleFunction doubleFunction); ImmutableFloatList collectFloat(FloatFunction floatFunction); ImmutableIntList collectInt(IntFunction intFunction); ImmutableLongList collectLong(LongFunction longFunction); ImmutableShortList collectShort(ShortFunction shortFunction); ImmutableList collectWith(Function2 function, P parameter); ImmutableList collectIf(Predicate predicate, Function function); ImmutableList flatCollect(Function> function); ImmutableSortedSet distinct(); ImmutableSortedBag takeWhile(Predicate predicate); ImmutableSortedBag dropWhile(Predicate predicate); ImmutableSortedBagMultimap groupBy(Function function); ImmutableSortedBagMultimap groupByEach(Function> function); /** * Can return an ImmutableMap that's backed by a LinkedHashMap. */ ImmutableMap aggregateBy( Function groupBy, Function0 zeroValueFactory, Function2 nonMutatingAggregator); /** * Can return an ImmutableMap that's backed by a LinkedHashMap. */ ImmutableMap aggregateInPlaceBy( Function groupBy, Function0 zeroValueFactory, Procedure2 mutatingAggregator); ImmutableList> zip(Iterable that); ImmutableSortedSet> zipWithIndex(); } MutableSortedBag.java000066400000000000000000000140121234315411400344360ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/bag/sorted/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.bag.sorted; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.predicate.primitive.IntPredicate; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.collection.MutableCollection; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.list.primitive.MutableBooleanList; import com.gs.collections.api.list.primitive.MutableByteList; import com.gs.collections.api.list.primitive.MutableCharList; import com.gs.collections.api.list.primitive.MutableDoubleList; import com.gs.collections.api.list.primitive.MutableFloatList; import com.gs.collections.api.list.primitive.MutableIntList; import com.gs.collections.api.list.primitive.MutableLongList; import com.gs.collections.api.list.primitive.MutableShortList; import com.gs.collections.api.map.MutableMap; import com.gs.collections.api.multimap.sortedbag.MutableSortedBagMultimap; import com.gs.collections.api.partition.bag.sorted.PartitionMutableSortedBag; import com.gs.collections.api.set.sorted.MutableSortedSet; import com.gs.collections.api.tuple.Pair; /** * @since 4.2 */ public interface MutableSortedBag extends SortedBag, MutableCollection, Cloneable { void addOccurrences(T item, int occurrences); boolean removeOccurrences(Object item, int occurrences); MutableSortedBag selectByOccurrences(IntPredicate predicate); MutableSortedBag with(T element); MutableSortedBag without(T element); MutableSortedBag withAll(Iterable elements); MutableSortedBag withoutAll(Iterable elements); MutableSortedBag newEmpty(); MutableSortedBag clone(); /** * Returns an unmodifiable view of the set. The returned set will be Serializable if this set is Serializable. * * @return an unmodifiable view of this set */ MutableSortedBag asUnmodifiable(); MutableSortedBag asSynchronized(); MutableSortedBag select(Predicate predicate);

MutableSortedBag selectWith(Predicate2 predicate, P parameter); MutableSortedBag reject(Predicate predicate);

MutableSortedBag rejectWith(Predicate2 predicate, P parameter); PartitionMutableSortedBag partition(Predicate predicate);

PartitionMutableSortedBag partitionWith(Predicate2 predicate, P parameter); PartitionMutableSortedBag partitionWhile(Predicate predicate); MutableSortedBag selectInstancesOf(Class clazz); MutableList collect(Function function); MutableBooleanList collectBoolean(BooleanFunction booleanFunction); MutableByteList collectByte(ByteFunction byteFunction); MutableCharList collectChar(CharFunction charFunction); MutableDoubleList collectDouble(DoubleFunction doubleFunction); MutableFloatList collectFloat(FloatFunction floatFunction); MutableIntList collectInt(IntFunction intFunction); MutableLongList collectLong(LongFunction longFunction); MutableShortList collectShort(ShortFunction shortFunction); MutableList collectWith(Function2 function, P parameter); MutableList collectIf(Predicate predicate, Function function); MutableList flatCollect(Function> function); MutableSortedSet distinct(); MutableSortedBag takeWhile(Predicate predicate); MutableSortedBag dropWhile(Predicate predicate); MutableSortedBagMultimap groupBy(Function function); MutableSortedBagMultimap groupByEach(Function> function); /** * Can return an MutableMap that's backed by a LinkedHashMap. */ MutableMap aggregateBy( Function groupBy, Function0 zeroValueFactory, Function2 nonMutatingAggregator); /** * Can return an MutableMap that's backed by a LinkedHashMap. */ MutableMap aggregateInPlaceBy( Function groupBy, Function0 zeroValueFactory, Procedure2 mutatingAggregator); MutableList> zip(Iterable that); MutableSortedSet> zipWithIndex(); } ParallelSortedBag.java000066400000000000000000000107701234315411400346100ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/bag/sorted/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.bag.sorted; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.bag.ParallelBag; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.list.ParallelListIterable; import com.gs.collections.api.multimap.sortedbag.SortedBagMultimap; /** * @since 5.0 */ @Beta public interface ParallelSortedBag extends ParallelBag { /** * Creates a parallel iterable for selecting elements from the current iterable. */ ParallelSortedBag select(Predicate predicate);

ParallelSortedBag selectWith(Predicate2 predicate, P parameter); /** * Creates a parallel iterable for rejecting elements from the current iterable. */ ParallelSortedBag reject(Predicate predicate);

ParallelSortedBag rejectWith(Predicate2 predicate, P parameter); ParallelSortedBag selectInstancesOf(Class clazz); /** * Creates a parallel iterable for collecting elements from the current iterable. */ ParallelListIterable collect(Function function); ParallelListIterable collectWith(Function2 function, P parameter); /** * Creates a parallel iterable for selecting and collecting elements from the current iterable. */ ParallelListIterable collectIf(Predicate predicate, Function function); /** * Creates a parallel flattening iterable for the current iterable. */ ParallelListIterable flatCollect(Function> function); SortedBagMultimap groupBy(Function function); SortedBagMultimap groupByEach(Function> function); // /** // * Returns a parallel BooleanIterable which will transform the underlying iterable data to boolean values based on the booleanFunction. // */ // ParallelBooleanIterable collectBoolean(BooleanFunction booleanFunction); // // /** // * Returns a parallel ByteIterable which will transform the underlying iterable data to byte values based on the byteFunction. // */ // ParallelByteIterable collectByte(ByteFunction byteFunction); // // /** // * Returns a parallel CharIterable which will transform the underlying iterable data to char values based on the charFunction. // */ // ParallelCharIterable collectChar(CharFunction charFunction); // // /** // * Returns a parallel DoubleIterable which will transform the underlying iterable data to double values based on the doubleFunction. // */ // ParallelDoubleIterable collectDouble(DoubleFunction doubleFunction); // // /** // * Returns a parallel FloatIterable which will transform the underlying iterable data to float values based on the floatFunction. // */ // ParallelFloatIterable collectFloat(FloatFunction floatFunction); // // /** // * Returns a parallel IntIterable which will transform the underlying iterable data to int values based on the intFunction. // */ // ParallelIntIterable collectInt(IntFunction intFunction); // // /** // * Returns a parallel LongIterable which will transform the underlying iterable data to long values based on the longFunction. // */ // ParallelLongIterable collectLong(LongFunction longFunction); // // /** // * Returns a parallel ShortIterable which will transform the underlying iterable data to short values based on the shortFunction. // */ // ParallelShortIterable collectShort(ShortFunction shortFunction); } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/bag/sorted/SortedBag.java000066400000000000000000000151201234315411400332040ustar00rootroot00000000000000/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.bag.sorted; import java.util.Comparator; import java.util.NoSuchElementException; import com.gs.collections.api.bag.Bag; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.predicate.primitive.IntPredicate; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.list.ListIterable; import com.gs.collections.api.list.primitive.BooleanList; import com.gs.collections.api.list.primitive.ByteList; import com.gs.collections.api.list.primitive.CharList; import com.gs.collections.api.list.primitive.DoubleList; import com.gs.collections.api.list.primitive.FloatList; import com.gs.collections.api.list.primitive.IntList; import com.gs.collections.api.list.primitive.LongList; import com.gs.collections.api.list.primitive.ShortList; import com.gs.collections.api.map.MapIterable; import com.gs.collections.api.map.sorted.MutableSortedMap; import com.gs.collections.api.multimap.sortedbag.SortedBagMultimap; import com.gs.collections.api.ordered.SortedIterable; import com.gs.collections.api.partition.bag.sorted.PartitionSortedBag; import com.gs.collections.api.set.sorted.SortedSetIterable; import com.gs.collections.api.tuple.Pair; /** * An Iterable whose elements are sorted by some comparator or their natural ordering and may contain duplicate entries. * * @since 4.2 */ public interface SortedBag extends Bag, Comparable>, SortedIterable { SortedBag selectByOccurrences(IntPredicate predicate); MutableSortedMap toMapOfItemToCount(); /** * Convert the SortedBag to an ImmutableSortedBag. If the bag is immutable, it returns itself. * Not yet supported. */ ImmutableSortedBag toImmutable(); /** * Returns the minimum element out of this container based on the natural order, not the order of this bag. * If you want the minimum element based on the order of this bag, use {@link #getFirst()}. * * @throws ClassCastException if the elements are not {@link Comparable} * @throws NoSuchElementException if the SortedBag is empty * @since 1.0 */ T min(); /** * Returns the maximum element out of this container based on the natural order, not the order of this bag. * If you want the maximum element based on the order of this bag, use {@link #getLast()}. * * @throws ClassCastException if the elements are not {@link Comparable} * @throws NoSuchElementException if the SortedBag is empty * @since 1.0 */ T max(); SortedBag select(Predicate predicate);

SortedBag selectWith(Predicate2 predicate, P parameter); SortedBag reject(Predicate predicate);

SortedBag rejectWith(Predicate2 predicate, P parameter); PartitionSortedBag partition(Predicate predicate);

PartitionSortedBag partitionWith(Predicate2 predicate, P parameter); PartitionSortedBag partitionWhile(Predicate predicate); SortedBag selectInstancesOf(Class clazz); ListIterable collect(Function function); BooleanList collectBoolean(BooleanFunction booleanFunction); ByteList collectByte(ByteFunction byteFunction); CharList collectChar(CharFunction charFunction); DoubleList collectDouble(DoubleFunction doubleFunction); FloatList collectFloat(FloatFunction floatFunction); IntList collectInt(IntFunction intFunction); LongList collectLong(LongFunction longFunction); ShortList collectShort(ShortFunction shortFunction); ListIterable collectWith(Function2 function, P parameter); ListIterable collectIf(Predicate predicate, Function function); ListIterable flatCollect(Function> function); SortedSetIterable distinct(); SortedBag takeWhile(Predicate predicate); SortedBag dropWhile(Predicate predicate); SortedBagMultimap groupBy(Function function); SortedBagMultimap groupByEach(Function> function); /** * Can return an MapIterable that's backed by a LinkedHashMap. */ MapIterable aggregateBy( Function groupBy, Function0 zeroValueFactory, Function2 nonMutatingAggregator); /** * Can return an MapIterable that's backed by a LinkedHashMap. */ MapIterable aggregateInPlaceBy( Function groupBy, Function0 zeroValueFactory, Procedure2 mutatingAggregator); /** * Returns the comparator used to order the elements in this bag, or null if this bag uses the natural ordering of * its elements. */ Comparator comparator(); SortedSetIterable> zipWithIndex(); } package-info.java000066400000000000000000000027411234315411400336040ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/bag/sorted/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains interfaces for SortedBag API. *

* A sorted bag is a {@link java.util.Collection} which contains elements that are sorted, and may contain duplicate entries. It adds a protocol for * adding, removing, and determining the number of occurrences for an item. *

*

* This package contains 3 interfaces: *

    *
  • * {@link com.gs.collections.api.bag.sorted.SortedBag} - contains the common API for Mutable and Immutable SortedBag. *
  • *
  • * {@link com.gs.collections.api.bag.sorted.MutableSortedBag} - a SortedBag whose contents can be altered after initialization. *
  • *
  • * {@link com.gs.collections.api.bag.sorted.ImmutableSortedBag} - a SortedBag whose contents cannot be altered after initialization. *
  • *
*

*/ package com.gs.collections.api.bag.sorted; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/bimap/000077500000000000000000000000001234315411400275275ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/bimap/BiMap.java000066400000000000000000000032411234315411400313620ustar00rootroot00000000000000/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.bimap; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.map.MapIterable; import com.gs.collections.api.tuple.Pair; /** * A map that allows users to look up key-value pairs from either direction. Uniqueness is enforced on both the keys and values. * * @since 4.2 */ public interface BiMap extends MapIterable { /** * Returns an inversed view of this BiMap, where the associations are in the direction of this bimap’s values to keys. */ BiMap inverse(); /** * Converts the BiMap to an ImmutableBiMap. If the bimap is immutable, it returns itself. */ ImmutableBiMap toImmutable(); BiMap collectValues(Function2 function); BiMap select(Predicate2 predicate); BiMap collect(Function2> function); BiMap reject(Predicate2 predicate); } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/bimap/ImmutableBiMap.java000066400000000000000000000030071234315411400332220ustar00rootroot00000000000000/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.bimap; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.map.ImmutableMap; import com.gs.collections.api.tuple.Pair; import net.jcip.annotations.Immutable; /** * A {@link com.gs.collections.api.bimap.BiMap} whose contents cannot be altered after initialization. * * @since 4.2 */ @Immutable public interface ImmutableBiMap extends BiMap, ImmutableMap { ImmutableBiMap inverse(); ImmutableBiMap select(Predicate2 predicate); ImmutableBiMap collectValues(Function2 function); ImmutableBiMap collect(Function2> function); ImmutableBiMap reject(Predicate2 predicate); ImmutableBiMap flipUniqueValues(); } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/bimap/MutableBiMap.java000066400000000000000000000040301234315411400326710ustar00rootroot00000000000000/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.bimap; import java.util.Map; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.map.MutableMap; import com.gs.collections.api.tuple.Pair; /** * A {@link BiMap} whose contents can be altered after initialization. * * @since 4.2 */ public interface MutableBiMap extends BiMap, MutableMap { MutableBiMap clone(); MutableBiMap newEmpty(); MutableBiMap inverse(); /** * Similar to {@link Map#put(Object, Object)}, except that it throws on the addition of a duplicate value. * * @throws IllegalArgumentException if the value already exists in the bimap. */ V put(K key, V value); /** * Similar to {@link #put(Object, Object)}, except that it quietly removes any existing entry with the same * value before putting the key-value pair. */ V forcePut(K key, V value); MutableBiMap asSynchronized(); MutableBiMap asUnmodifiable(); MutableBiMap select(Predicate2 predicate); MutableBiMap collectValues(Function2 function); MutableBiMap collect(Function2> function); MutableBiMap reject(Predicate2 predicate); MutableBiMap flipUniqueValues(); } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/bimap/package-info.java000066400000000000000000000025351234315411400327230ustar00rootroot00000000000000/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains interfaces for BiMap API. *

* A BiMap is a map that allows users to look up key-value pairs from either direction. Uniqueness is enforced on both the keys and values. *

*

* This package contains 3 interfaces: *

    *
  • * {@link com.gs.collections.api.bimap.BiMap} - contains the common API for Mutable and Immutable BiMap. *
  • *
  • * {@link com.gs.collections.api.bimap.MutableBiMap} - a BiMap whose contents can be altered after initialization. *
  • *
  • * {@link com.gs.collections.api.bimap.ImmutableBiMap} - a BiMap whose contents cannot be altered after initialization. *
  • *
*

*/ package com.gs.collections.api.bimap; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/block/000077500000000000000000000000001234315411400275315ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/block/HashingStrategy.java000066400000000000000000000022641234315411400335040ustar00rootroot00000000000000/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.block; import java.io.Serializable; /** * Interface for supporting user defined hashing strategies in Sets and Maps */ public interface HashingStrategy extends Serializable { /** * Computes the hashCode of the object as defined by the user. */ int computeHashCode(E object); /** * Checks two objects for equality. The equality check can use the objects own equals() method or * a custom method defined by the user. It should be consistent with the computeHashCode() method. */ boolean equals(E object1, E object2); } SerializableComparator.java000066400000000000000000000014241234315411400347540ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/block/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.block; import java.io.Serializable; import java.util.Comparator; public interface SerializableComparator extends Comparator, Serializable { } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/block/function/000077500000000000000000000000001234315411400313565ustar00rootroot00000000000000Function.java000066400000000000000000000020371234315411400337310ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/block/function/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.block.function; import java.io.Serializable; /** * Function is a one-argument lambda which performs a transformation on the object of type {@code T} * passed to the valueOf() method. This transformation can return the value of calling a getter, or perform * some more elaborate logic to calculate a value, of type {@code V}. */ public interface Function extends Serializable { V valueOf(T object); } Function0.java000066400000000000000000000016111234315411400340060ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/block/function/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.block.function; import java.io.Serializable; /** * Function0 is a zero argument lambda. It can be stored in a variable or passed as a parameter and executed * by calling the value method. */ public interface Function0 extends Serializable { R value(); } Function2.java000066400000000000000000000021141234315411400340070ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/block/function/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.block.function; import java.io.Serializable; /** * A Function2 is used by injectInto() methods. It takes the injected argument as the first argument, and the * current item of the collection as the second argument, for the first item in the collection. The result of each * subsequent iteration is passed in as the first argument. * * @since 1.0 */ public interface Function2 extends Serializable { R value(T1 argument1, T2 argument2); } Function3.java000066400000000000000000000021711234315411400340130ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/block/function/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.block.function; import java.io.Serializable; /** * A Function3 is used by injectIntoWith(). In the injectIntoWith() method the block takes the injected * argument as the first argument, the current item of the collection as the second argument, and the specified * parameter for the third argument. The result of each subsequent iteration is passed in as the first argument. */ public interface Function3 extends Serializable { R value(T1 argument1, T2 argument2, T3 argument3); } package-info.java000066400000000000000000000014651234315411400344740ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/block/function/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains interfaces for Function API. *

* A Function is a lambda which performs a transformation on the object that is passed to it. *

*/ package com.gs.collections.api.block.function; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/block/function/primitive/000077500000000000000000000000001234315411400333665ustar00rootroot00000000000000package-info.java000066400000000000000000000015261234315411400365020ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/block/function/primitive/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains API for primitive functions. *

* These primitive function blocks exist to avoid the overhead of autoboxing in places where primitives can be used. *

*/ package com.gs.collections.api.block.function.primitive; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/block/package-info.java000066400000000000000000000021011234315411400327120ustar00rootroot00000000000000/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains interfaces for Block API. *

* This package contains 2 interfaces: *

    *
  • * {@link com.gs.collections.api.block.HashingStrategy} - an interface for supporting user defined hashing strategies in Sets and Maps. *
  • *
  • * {@link com.gs.collections.api.block.SerializableComparator} - a marker interface for serializable Comparators. *
  • *
*

*/ package com.gs.collections.api.block; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/block/predicate/000077500000000000000000000000001234315411400314715ustar00rootroot00000000000000Predicate.java000066400000000000000000000017751234315411400341670ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/block/predicate/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.block.predicate; import java.io.Serializable; /** * A Predicate is a lambda or closure with a boolean result. The method accept should be implemented to indicate the object * passed to the method meets the criteria of this Predicate. A Predicate is also known as a Discriminator or Filter. */ public interface Predicate extends Serializable { boolean accept(T each); } Predicate2.java000066400000000000000000000020431234315411400342360ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/block/predicate/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.block.predicate; import java.io.Serializable; /** * A Predicate2 is primarily used in methods like selectWith, detectWith, rejectWith. The first argument * is the element of the collection being iterated over, and the second argument is a parameter passed into * the predicate from the calling method. */ public interface Predicate2 extends Serializable { boolean accept(T1 argument1, T2 argument2); } package-info.java000066400000000000000000000022641234315411400346050ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/block/predicate/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains interfaces for Predicate API. *

* A Predicate is a lambda with a boolean result. *

*

* This package contains 2 interfaces. *

    *
  • * {@link com.gs.collections.api.block.predicate.Predicate} - a lambda with a boolean result. *
  • *
  • * {@link com.gs.collections.api.block.predicate.Predicate2} - a two argument Predicate. Primarily used in methods like selectWith, detectWith, rejectWith. *
  • *
*

*/ package com.gs.collections.api.block.predicate; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/block/predicate/primitive/000077500000000000000000000000001234315411400335015ustar00rootroot00000000000000package-info.java000066400000000000000000000015561234315411400366200ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/block/predicate/primitive/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains API for primitive predicates. *

* A primitive predicate is a lambda which returns a boolean. It reduces the overhead of autoboxing where primitives can be directly used. *

*/ package com.gs.collections.api.block.predicate.primitive; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/block/procedure/000077500000000000000000000000001234315411400315215ustar00rootroot00000000000000ObjectIntProcedure.java000066400000000000000000000021111234315411400360320ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/block/procedure/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.block.procedure; /** * A ObjectIntProcedure is a single argument Closure which has no return argument and takes an int as a second argument * which is usually the index of the current element of a collection. * * @deprecated since 3.0 use {@link com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure} instead. */ @Deprecated public interface ObjectIntProcedure extends com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure { } Procedure.java000066400000000000000000000015161234315411400342400ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/block/procedure/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.block.procedure; import java.io.Serializable; /** * A Procedure is a single argument lambda which has no return argument. */ public interface Procedure extends Serializable { void value(T each); } Procedure2.java000066400000000000000000000022131234315411400343150ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/block/procedure/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.block.procedure; import java.io.Serializable; /** * A Procedure2 is used by forEachWith() methods and for MapIterate.forEachKeyValue(). In the forEachKeyValue() * case the procedure takes the key as the first argument, and the value as the second. In the forEachWith() case * the procedure takes the the element of the collection as the first argument, and the specified parameter as the * second argument. */ public interface Procedure2 extends Serializable { void value(T1 argument1, T2 argument2); } package-info.java000066400000000000000000000023571234315411400346400ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/block/procedure/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains interfaces for Procedure API. *

* A Procedure is a single argument lambda which has no return argument. *

*

* This package contains the following interfaces: *

    *
  • * {@link com.gs.collections.api.block.procedure.Procedure} - a single argument lambda which has no return argument. *
  • *
  • * {@link com.gs.collections.api.block.procedure.Procedure2} - a two argument Procedure. Used by forEachWith() methods and for MapIterate.forEachKeyValue(). *
  • *
*

*/ package com.gs.collections.api.block.procedure; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/block/procedure/primitive/000077500000000000000000000000001234315411400335315ustar00rootroot00000000000000package-info.java000066400000000000000000000016321234315411400366430ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/block/procedure/primitive/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains API for PrimitivePrimitiveProcedure, PrimitiveObjectProcedure, ObjectPrimitiveProcedure. *

* These primitive procedures are lambdas or closures with no return argument and and accept primitive or object arguments. *

*/ package com.gs.collections.api.block.procedure.primitive; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/collection/000077500000000000000000000000001234315411400305725ustar00rootroot00000000000000FixedSizeCollection.java000066400000000000000000000122661234315411400352730ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/collection/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.collection; import java.util.Collection; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; /** * A FixedSizeCollection is a collection that may be mutated, but cannot grow or shrink in size. It is up to * the underlying implementation to decide which mutations are allowable. */ public interface FixedSizeCollection extends MutableCollection { /** * This method allows fixed size collections the ability to add elements to their existing elements. A new instance * of {@link MutableCollection} is returned containing the elements of the original collection with the new element * {@link #add(Object) added}. Implementations will return a new FixedSizeCollection where possible. In order to * use this method properly with mutable and fixed size collections the following approach must be taken: *

*

     * MutableCollection list;
     * list = list.with("1");
     * list = list.with("2");
     * return list;
     * 
* * @see #add(Object) */ MutableCollection with(T element); /** * This method allows fixed size collections the ability to remove elements from their existing elements. A new * instance of {@link MutableCollection} is returned containing the elements of the original collection with the * element {@link #remove(Object) removed}. Implementations will return a new FixedSizeCollection where possible. * In order to use this method properly with mutable and fixed size collections the following approach must be * taken: *

*

     * MutableCollection list;
     * list = list.without("1");
     * list = list.without("2");
     * return list;
     * 
* * @see #remove(Object) */ MutableCollection without(T element); /** * This method allows fixed size collections the ability to add multiple elements to their existing elements. A new * instance of {@link MutableCollection} is returned containing the elements of the original collection with all of * the new elements {@link #addAll(Collection) added}. Implementations will return a new FixedSizeCollection where * possible. In order to use this method properly with mutable and fixed size collections the following approach * must be taken: *

*

     * MutableCollection list;
     * list = list.withAll(FastList.newListWith("1", "2"));
     * return list;
     * 
* * @see #addAll(Collection) */ MutableCollection withAll(Iterable elements); /** * This method allows fixed size collections the ability to remove multiple elements from their existing elements. * A new instance of {@link MutableCollection} is returned containing the elements of the original collection with * the given elements {@link #removeAll(Collection) removed}. Implementations will return a new FixedSizeCollection * where possible. In order to use this method properly with mutable and fixed size collections the following * approach must be taken: *

*

     * MutableCollection list;
     * list = list.withoutAll(FastList.newListWith("1", "2"));
     * return list;
     * 
* * @see #removeAll(Collection) */ MutableCollection withoutAll(Iterable elements); /** * @throws UnsupportedOperationException */ boolean add(T t); /** * @throws UnsupportedOperationException */ boolean addAllIterable(Iterable iterable); /** * @throws UnsupportedOperationException */ boolean addAll(Collection collection); /** * @throws UnsupportedOperationException */ boolean remove(Object o); /** * @throws UnsupportedOperationException */ boolean removeAll(Collection collection); /** * @throws UnsupportedOperationException */ boolean removeAllIterable(Iterable iterable); /** * @throws UnsupportedOperationException */ void removeIf(Predicate predicate); /** * @throws UnsupportedOperationException */

void removeIfWith(Predicate2 predicate, P parameter); /** * @throws UnsupportedOperationException */ boolean retainAll(Collection collection); /** * @throws UnsupportedOperationException */ boolean retainAllIterable(Iterable iterable); /** * @throws UnsupportedOperationException */ void clear(); } ImmutableCollection.java000066400000000000000000000124461234315411400353200ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/collection/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.collection; import com.gs.collections.api.RichIterable; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.collection.primitive.ImmutableBooleanCollection; import com.gs.collections.api.collection.primitive.ImmutableByteCollection; import com.gs.collections.api.collection.primitive.ImmutableCharCollection; import com.gs.collections.api.collection.primitive.ImmutableDoubleCollection; import com.gs.collections.api.collection.primitive.ImmutableFloatCollection; import com.gs.collections.api.collection.primitive.ImmutableIntCollection; import com.gs.collections.api.collection.primitive.ImmutableLongCollection; import com.gs.collections.api.collection.primitive.ImmutableShortCollection; import com.gs.collections.api.map.ImmutableMap; import com.gs.collections.api.multimap.ImmutableMultimap; import com.gs.collections.api.partition.PartitionImmutableCollection; import com.gs.collections.api.tuple.Pair; import net.jcip.annotations.Immutable; /** * ImmutableCollection is the common interface between ImmutableList and ImmutableSet. */ @Immutable public interface ImmutableCollection extends RichIterable { ImmutableCollection newWith(T element); ImmutableCollection newWithout(T element); ImmutableCollection newWithAll(Iterable elements); ImmutableCollection newWithoutAll(Iterable elements); ImmutableCollection select(Predicate predicate);

ImmutableCollection selectWith(Predicate2 predicate, P parameter); ImmutableCollection reject(Predicate predicate);

ImmutableCollection rejectWith(Predicate2 predicate, P parameter); PartitionImmutableCollection partition(Predicate predicate);

PartitionImmutableCollection partitionWith(Predicate2 predicate, P parameter); ImmutableCollection selectInstancesOf(Class clazz); ImmutableCollection collect(Function function); ImmutableBooleanCollection collectBoolean(BooleanFunction booleanFunction); ImmutableByteCollection collectByte(ByteFunction byteFunction); ImmutableCharCollection collectChar(CharFunction charFunction); ImmutableDoubleCollection collectDouble(DoubleFunction doubleFunction); ImmutableFloatCollection collectFloat(FloatFunction floatFunction); ImmutableIntCollection collectInt(IntFunction intFunction); ImmutableLongCollection collectLong(LongFunction longFunction); ImmutableShortCollection collectShort(ShortFunction shortFunction); ImmutableCollection collectWith(Function2 function, P parameter); ImmutableCollection collectIf(Predicate predicate, Function function); ImmutableCollection flatCollect(Function> function); ImmutableMultimap groupBy(Function function); ImmutableMultimap groupByEach(Function> function); ImmutableMap groupByUniqueKey(Function function); ImmutableCollection> zip(Iterable that); ImmutableCollection> zipWithIndex(); ImmutableMap aggregateInPlaceBy( Function groupBy, Function0 zeroValueFactory, Procedure2 mutatingAggregator); ImmutableMap aggregateBy( Function groupBy, Function0 zeroValueFactory, Function2 nonMutatingAggregator); } MutableCollection.java000066400000000000000000000427761234315411400350030ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/collection/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.collection; import java.util.Collection; import com.gs.collections.api.RichIterable; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.Function3; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.collection.primitive.MutableBooleanCollection; import com.gs.collections.api.collection.primitive.MutableByteCollection; import com.gs.collections.api.collection.primitive.MutableCharCollection; import com.gs.collections.api.collection.primitive.MutableDoubleCollection; import com.gs.collections.api.collection.primitive.MutableFloatCollection; import com.gs.collections.api.collection.primitive.MutableIntCollection; import com.gs.collections.api.collection.primitive.MutableLongCollection; import com.gs.collections.api.collection.primitive.MutableShortCollection; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.map.MutableMap; import com.gs.collections.api.multimap.MutableMultimap; import com.gs.collections.api.partition.PartitionMutableCollection; import com.gs.collections.api.tuple.Pair; import com.gs.collections.api.tuple.Twin; /** * MutableCollection is an interface which extends the base java.util.Collection interface and adds several internal * iterator methods, from the Smalltalk Collection protocol. These include variations of forEach, select, reject, * detect, collect, injectInto, anySatisfy, allSatisfy. These include count, remove, partition, collectIf. The API also * includes converter methods to convert a MutableCollection to a List (toList), to a sorted List (toSortedList), to a * Set (toSet), and to a Map (toMap). *

* There are several extensions to MutableCollection, including MutableList, MutableSet, and MutableBag. */ public interface MutableCollection extends Collection, RichIterable { /** * This method allows mutable and fixed size collections the ability to add elements to their existing elements. * In order to support fixed size a new instance of a collection would have to be returned taking the elements of * the original collection and appending the new element to form the new collection. In the case of mutable * collections, the original collection is modified, and is returned. In order to use this method properly with * mutable and fixed size collections the following approach must be taken: *

*

     * MutableCollection list;
     * list = list.with("1");
     * list = list.with("2");
     * return list;
     * 
* In the case of {@link FixedSizeCollection} a new instance of MutableCollection will be returned by with, and any * variables that previously referenced the original collection will need to be redirected to reference the * new instance. For other MutableCollection types you will replace the reference to collection with the same * collection, since the instance will return "this" after calling add on itself. * * @see #add(Object) */ MutableCollection with(T element); /** * This method allows mutable and fixed size collections the ability to remove elements from their existing elements. * In order to support fixed size a new instance of a collection would have to be returned contaning the elements * that would be left from the original collection after calling remove. In the case of mutable collections, the * original collection is modified, and is returned. In order to use this method properly with mutable and fixed * size collections the following approach must be taken: *

*

     * MutableCollection list;
     * list = list.without("1");
     * list = list.without("2");
     * return list;
     * 
* In the case of {@link FixedSizeCollection} a new instance of MutableCollection will be returned by without, and * any variables that previously referenced the original collection will need to be redirected to reference the * new instance. For other MutableCollection types you will replace the reference to collection with the same * collection, since the instance will return "this" after calling remove on itself. * * @see #remove(Object) */ MutableCollection without(T element); /** * This method allows mutable and fixed size collections the ability to add multiple elements to their existing * elements. In order to support fixed size a new instance of a collection would have to be returned taking the * elements of the original collection and appending the new elements to form the new collection. In the case of * mutable collections, the original collection is modified, and is returned. In order to use this method properly * with mutable and fixed size collections the following approach must be taken: *

*

     * MutableCollection list;
     * list = list.withAll(FastList.newListWith("1", "2"));
     * return list;
     * 
* In the case of {@link FixedSizeCollection} a new instance of MutableCollection will be returned by withAll, and * any variables that previously referenced the original collection will need to be redirected to reference the * new instance. For other MutableCollection types you will replace the reference to collection with the same * collection, since the instance will return "this" after calling addAll on itself. * * @see #addAll(Collection) */ MutableCollection withAll(Iterable elements); /** * This method allows mutable and fixed size collections the ability to remove multiple elements from their existing * elements. In order to support fixed size a new instance of a collection would have to be returned contaning the * elements that would be left from the original collection after calling removeAll. In the case of mutable * collections, the original collection is modified, and is returned. In order to use this method properly with * mutable and fixed size collections the following approach must be taken: *

*

     * MutableCollection list;
     * list = list.withoutAll(FastList.newListWith("1", "2"));
     * return list;
     * 
* In the case of {@link FixedSizeCollection} a new instance of MutableCollection will be returned by withoutAll, * and any variables that previously referenced the original collection will need to be redirected to reference the * new instance. For other MutableCollection types you will replace the reference to collection with the same * collection, since the instance will return "this" after calling removeAll on itself. * * @see #removeAll(Collection) */ MutableCollection withoutAll(Iterable elements); /** * Creates a new empty mutable version of the same collection type. For example, if this instance is a FastList, * this method will return a new empty FastList. If the class of this instance is immutable or fixed size (i.e. * SingletonList) then a mutable alternative to the class will be provided. */ MutableCollection newEmpty(); /** * Returns a MutableCollection with all elements that evaluate to true for the specified predicate. *

*

e.g.
     * return people.select(new Predicate<Person>()
     * {
     *     public boolean value(Person person)
     *     {
     *         return person.getAddress().getCity().equals("Metuchen");
     *     }
     * });
     * 
*/ MutableCollection select(Predicate predicate); /** * Returns a MutableCollection with all elements that evaluate to true for the specified predicate2 and parameter. *

*

e.g.
     * return integers.selectWith(PredicatesLite.equal(), Integer.valueOf(5));
     * 
*/

MutableCollection selectWith(Predicate2 predicate, P parameter); /** * Returns a MutableCollection with all elements that evaluate to false for the specified predicate. *

*

e.g.
     * return people.reject(new Predicate<Person>()
     * {
     *     public boolean value(Person person)
     *     {
     *         return person.person.getLastName().equals("Smith");
     *     }
     * });
     * 
*

*

e.g.
     * return people.reject(Predicates.attributeEqual("lastName", "Smith"));
     * 
*/ MutableCollection reject(Predicate predicate); /** * Returns a MutableCollection with all elements that evaluate to false for the specified predicate2 and parameter. *

*

e.g.
     * return integers.rejectWith(PredicatesLite.equal(), Integer.valueOf(5));
     * 
*/

MutableCollection rejectWith( Predicate2 predicate, P parameter); /** * Filters a collection into two separate collections based on a predicate returned via a Pair. *

*

e.g.
     * return lastNames.selectAndRejectWith(PredicatesLite.lessThan(), "Mason");
     * 
*/

Twin> selectAndRejectWith( Predicate2 predicate, P parameter); PartitionMutableCollection partition(Predicate predicate);

PartitionMutableCollection partitionWith(Predicate2 predicate, P parameter); MutableCollection selectInstancesOf(Class clazz); /** * Removes all elements in the collection that evaluate to true for the specified predicate. *

*

e.g.
     * return lastNames.removeIf(Predicates.isNull());
     * 
*/ void removeIf(Predicate predicate); /** * Removes all elements in the collection that evaluate to true for the specified predicate2 and parameter. *

*

e.g.
     * return lastNames.removeIfWith(PredicatesLite.isNull(), null);
     * 
*/

void removeIfWith(Predicate2 predicate, P parameter); /** * Returns a new MutableCollection with the results of applying the specified function to each element of the source * collection. *

*

e.g.
     * return people.collect(new Function<Person, String>()
     * {
     *     public String value(Person person)
     *     {
     *         return person.getFirstName() + " " + person.getLastName();
     *     }
     * });
     * 
*/ MutableCollection collect(Function function); MutableBooleanCollection collectBoolean(BooleanFunction booleanFunction); MutableByteCollection collectByte(ByteFunction byteFunction); MutableCharCollection collectChar(CharFunction charFunction); MutableDoubleCollection collectDouble(DoubleFunction doubleFunction); MutableFloatCollection collectFloat(FloatFunction floatFunction); MutableIntCollection collectInt(IntFunction intFunction); MutableLongCollection collectLong(LongFunction longFunction); MutableShortCollection collectShort(ShortFunction shortFunction); MutableCollection collectWith(Function2 function, P parameter); /** * Returns a new MutableCollection with the results of applying the specified function to each element of the source * collection, but only for elements that evaluate to true for the specified predicate. *

*

e.g.
     * Lists.mutable.of().with(1, 2, 3).collectIf(Predicates.notNull(), Functions.getToString())
     * 
*/ MutableCollection collectIf(Predicate predicate, Function function); MutableCollection flatCollect(Function> function); IV injectIntoWith( IV injectValue, Function3 function, P parameter); /** * Returns an unmodifiable view of this collection. This method allows modules to provide users with "read-only" * access to internal collections. Query operations on the returned collection "read through" to this collection, * and attempts to modify the returned collection, whether direct or via its iterator, result in an * UnsupportedOperationException. *

* The returned collection does not pass the hashCode and equals operations through to the backing * collection, but relies on Object's equals and hashCode methods. This is necessary to * preserve the contracts of these operations in the case that the backing collection is a set or a list.

*

* The returned collection will be serializable if this collection is serializable. * * @return an unmodifiable view of this collection. * @since 1.0 */ MutableCollection asUnmodifiable(); /** * Returns a synchronized (thread-safe) collection backed by this collection. In order to guarantee serial access, * it is critical that all access to the backing collection is accomplished through the returned * collection. *

* It is imperative that the user manually synchronize on the returned collection when iterating over it using the * standard JDK iterator or JDK 5 for loop. *

     *  MutableCollection collection = myCollection.asSynchronized();
     *     ...
     *  synchronized(collection)
     *  {
     *      Iterator i = c.iterator(); // Must be in the synchronized block
     *      while (i.hasNext())
     *         foo(i.next());
     *  }
     * 
* Failure to follow this advice may result in non-deterministic behavior. *

* The preferred way of iterating over a synchronized collection is to use the collection.forEach() method which is * properly synchronized internally. *

     *  MutableCollection collection = myCollection.asSynchronized();
     *     ...
     *  collection.forEach(new Procedure()
     *  {
     *      public void value(Object each)
     *      {
     *          ...
     *      }
     *  });
     * 
*

* The returned collection does not pass the hashCode and equals operations through to the * backing collection, but relies on Object's equals and hashCode methods. This is necessary to preserve * the contracts of these operations in the case that the backing collection is a set or a list. *

* The returned collection will be serializable if this collection is serializable. * * @return a synchronized view of this collection. * @since 1.0 */ MutableCollection asSynchronized(); /** * Converts this MutableCollection to an ImmutableCollection. * * @since 1.0 */ ImmutableCollection toImmutable(); MutableMultimap groupBy(Function function); MutableMultimap groupByEach(Function> function); MutableMap groupByUniqueKey(Function function); MutableCollection> zip(Iterable that); MutableCollection> zipWithIndex(); /** * @see #addAll(Collection) * @since 1.0 */ boolean addAllIterable(Iterable iterable); /** * @see #removeAll(Collection) * @since 1.0 */ boolean removeAllIterable(Iterable iterable); /** * @see #retainAll(Collection) * @since 1.0 */ boolean retainAllIterable(Iterable iterable); MutableMap aggregateInPlaceBy( Function groupBy, Function0 zeroValueFactory, Procedure2 mutatingAggregator); MutableMap aggregateBy( Function groupBy, Function0 zeroValueFactory, Function2 nonMutatingAggregator); } package-info.java000066400000000000000000000015451234315411400337070ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/collection/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains {@link com.gs.collections.api.collection.FixedSizeCollection}, {@link com.gs.collections.api.collection.ImmutableCollection} and {@link com.gs.collections.api.collection.MutableCollection} API. */ package com.gs.collections.api.collection; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/collection/primitive/000077500000000000000000000000001234315411400326025ustar00rootroot00000000000000package-info.java000066400000000000000000000013351234315411400357140ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/collection/primitive/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains mutable and immutable primitive collection API. */ package com.gs.collections.api.collection.primitive; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/000077500000000000000000000000001234315411400301065ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/bag/000077500000000000000000000000001234315411400306375ustar00rootroot00000000000000ImmutableBagFactory.java000066400000000000000000000026041234315411400353060ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/bag/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.factory.bag; import com.gs.collections.api.bag.ImmutableBag; /** * A factory which creates instances of type {@link com.gs.collections.api.bag.ImmutableBag}. */ public interface ImmutableBagFactory { /** * Same as {@link #with()}. */ ImmutableBag of(); ImmutableBag with(); /** * Same as {@link #with(Object)}. */ ImmutableBag of(T element); ImmutableBag with(T element); /** * Same as {@link #with(Object[])}. */ ImmutableBag of(T... elements); ImmutableBag with(T... elements); /** * Same as {@link #withAll(Iterable)}. */ ImmutableBag ofAll(Iterable items); ImmutableBag withAll(Iterable items); } MutableBagFactory.java000066400000000000000000000020671234315411400347630ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/bag/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.factory.bag; import com.gs.collections.api.bag.MutableBag; /** * A factory which creates instances of type {@link com.gs.collections.api.bag.MutableBag}. */ public interface MutableBagFactory { /** * Same as {@link #with()}. */ MutableBag of(); MutableBag with(); /** * Same as {@link #with(Object[])}. */ MutableBag of(T... elements); MutableBag with(T... elements); } package-info.java000066400000000000000000000013661234315411400337550ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/bag/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains factory API for creating instance of type {@link com.gs.collections.api.bag.Bag}. */ package com.gs.collections.api.factory.bag; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/list/000077500000000000000000000000001234315411400310615ustar00rootroot00000000000000FixedSizeListFactory.java000066400000000000000000000044111234315411400357230ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/list/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.factory.list; import com.gs.collections.api.list.FixedSizeList; public interface FixedSizeListFactory { /** * Same as {@link #with()}. */ FixedSizeList of(); FixedSizeList with(); /** * Same as {@link #with(Object)}. */ FixedSizeList of(T one); FixedSizeList with(T one); /** * Same as {@link #with(Object, Object)}. */ FixedSizeList of(T one, T two); FixedSizeList with(T one, T two); /** * Same as {@link #with(Object, Object, Object)}. */ FixedSizeList of(T one, T two, T three); FixedSizeList with(T one, T two, T three); /** * Same as {@link #with(Object, Object, Object, Object)}. */ FixedSizeList of(T one, T two, T three, T four); FixedSizeList with(T one, T two, T three, T four); /** * Same as {@link #with(Object, Object, Object, Object, Object)}. */ FixedSizeList of(T one, T two, T three, T four, T five); FixedSizeList with(T one, T two, T three, T four, T five); /** * Same as {@link #with(Object, Object, Object, Object, Object, Object)}. */ FixedSizeList of(T one, T two, T three, T four, T five, T six); FixedSizeList with(T one, T two, T three, T four, T five, T six); /** * Same as {@link #with(Object[])} */ FixedSizeList of(T... items); FixedSizeList with(T... items); /** * Same as {@link #withAll(Iterable)}. */ FixedSizeList ofAll(Iterable items); FixedSizeList withAll(Iterable items); } ImmutableListFactory.java000066400000000000000000000067461234315411400357650ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/list/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.factory.list; import com.gs.collections.api.list.ImmutableList; public interface ImmutableListFactory { /** * Same as {@link #with()}. */ ImmutableList of(); ImmutableList with(); /** * Same as {@link #with(Object)}. */ ImmutableList of(T one); ImmutableList with(T one); /** * Same as {@link #with(Object, Object)}. */ ImmutableList of(T one, T two); ImmutableList with(T one, T two); /** * Same as {@link #with(Object, Object, Object)}. */ ImmutableList of(T one, T two, T three); ImmutableList with(T one, T two, T three); /** * Same as {@link #with(Object, Object, Object, Object)}. */ ImmutableList of(T one, T two, T three, T four); ImmutableList with(T one, T two, T three, T four); /** * Same as {@link #with(Object, Object, Object, Object, Object)}. */ ImmutableList of(T one, T two, T three, T four, T five); ImmutableList with(T one, T two, T three, T four, T five); /** * Same as {@link #with(Object, Object, Object, Object, Object, Object)}. */ ImmutableList of(T one, T two, T three, T four, T five, T six); ImmutableList with(T one, T two, T three, T four, T five, T six); /** * Same as {@link #with(Object, Object, Object, Object, Object, Object, Object)}. */ ImmutableList of(T one, T two, T three, T four, T five, T six, T seven); ImmutableList with(T one, T two, T three, T four, T five, T six, T seven); /** * Same as {@link #with(Object, Object, Object, Object, Object, Object, Object, Object)}. */ ImmutableList of(T one, T two, T three, T four, T five, T six, T seven, T eight); ImmutableList with(T one, T two, T three, T four, T five, T six, T seven, T eight); /** * Same as {@link #with(Object, Object, Object, Object, Object, Object, Object, Object, Object)}. */ ImmutableList of(T one, T two, T three, T four, T five, T six, T seven, T eight, T nine); ImmutableList with(T one, T two, T three, T four, T five, T six, T seven, T eight, T nine); /** * Same as {@link #with(Object, Object, Object, Object, Object, Object, Object, Object, Object, Object)}. */ ImmutableList of(T one, T two, T three, T four, T five, T six, T seven, T eight, T nine, T ten); ImmutableList with(T one, T two, T three, T four, T five, T six, T seven, T eight, T nine, T ten); /** * Same as {@link #with(Object[])}. */ ImmutableList of(T... items); ImmutableList with(T... items); /** * Same as {@link #withAll(Iterable)}. */ ImmutableList ofAll(Iterable items); ImmutableList withAll(Iterable items); } MutableListFactory.java000066400000000000000000000024151234315411400354240ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/list/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.factory.list; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.list.MutableList; public interface MutableListFactory { /** * Same as {@link #with()}. */ MutableList of(); MutableList with(); /** * Same as {@link #with(Object[])}. */ MutableList of(T... items); MutableList with(T... items); /** * Same as {@link #withAll(Iterable)}. */ MutableList ofAll(Iterable iterable); MutableList withAll(Iterable iterable); MutableList withNValues(int size, Function0 factory); } package-info.java000066400000000000000000000026451234315411400342000ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/list/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains factory API for creating instances of type {@link com.gs.collections.api.list.ListIterable}. *

* This package contains the following interfaces: *

    *
  • * {@link com.gs.collections.api.factory.list.FixedSizeListFactory} - a factory which creates instances of type {@link com.gs.collections.api.list.FixedSizeList}. *
  • *
  • * {@link com.gs.collections.api.factory.list.ImmutableListFactory} - a factory which creates instances of type {@link com.gs.collections.api.list.ImmutableList}. *
  • *
  • * {@link com.gs.collections.api.factory.list.MutableListFactory} - a factory which creates instances of type {@link com.gs.collections.api.list.MutableList}. *
  • *
*

*/ package com.gs.collections.api.factory.list; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/list/primitive/000077500000000000000000000000001234315411400330715ustar00rootroot00000000000000package-info.java000066400000000000000000000013541234315411400362040ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/list/primitive/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains factory API for creating immutable primitive list instances. */ package com.gs.collections.api.factory.list.primitive; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/map/000077500000000000000000000000001234315411400306635ustar00rootroot00000000000000FixedSizeMapFactory.java000066400000000000000000000027571234315411400353420ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/map/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.factory.map; import com.gs.collections.api.map.FixedSizeMap; public interface FixedSizeMapFactory { /** * Same as {@link #with()}. */ FixedSizeMap of(); FixedSizeMap with(); /** * Same as {@link #with(Object, Object)}. */ FixedSizeMap of(K key, V value); FixedSizeMap with(K key, V value); /** * Same as {@link #with(Object, Object, Object, Object)}. */ FixedSizeMap of(K key1, V value1, K key2, V value2); FixedSizeMap with(K key1, V value1, K key2, V value2); /** * Same as {@link #with(Object, Object, Object, Object, Object, Object)}. */ FixedSizeMap of(K key1, V value1, K key2, V value2, K key3, V value3); FixedSizeMap with(K key1, V value1, K key2, V value2, K key3, V value3); } ImmutableMapFactory.java000066400000000000000000000040551234315411400353600ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/map/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.factory.map; import java.util.Map; import com.gs.collections.api.map.ImmutableMap; public interface ImmutableMapFactory { /** * Same as {@link #with()}. */ ImmutableMap of(); ImmutableMap with(); /** * Same as {@link #with(Object, Object)}. */ ImmutableMap of(K key, V value); ImmutableMap with(K key, V value); /** * Same as {@link #with(Object, Object, Object, Object)}. */ ImmutableMap of(K key1, V value1, K key2, V value2); ImmutableMap with(K key1, V value1, K key2, V value2); /** * Same as {@link #with(Object, Object, Object, Object, Object, Object)}. */ ImmutableMap of(K key1, V value1, K key2, V value2, K key3, V value3); ImmutableMap with(K key1, V value1, K key2, V value2, K key3, V value3); /** * Same as {@link #with(Object, Object, Object, Object, Object, Object, Object, Object)}. */ ImmutableMap of(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4); ImmutableMap with(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4); ImmutableMap ofMap(Map map); /** * Same as {@link #withAll(java.util.Map)}. */ ImmutableMap ofAll(Map map); ImmutableMap withAll(Map map); } MutableMapFactory.java000066400000000000000000000034351234315411400350330ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/map/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.factory.map; import com.gs.collections.api.map.MutableMap; public interface MutableMapFactory { /** * Same as {@link #with()}. */ MutableMap of(); MutableMap with(); /** * Same as {@link #with(Object, Object)}. */ MutableMap of(K key, V value); MutableMap with(K key, V value); /** * Same as {@link #with(Object, Object, Object, Object)}. */ MutableMap of(K key1, V value1, K key2, V value2); MutableMap with(K key1, V value1, K key2, V value2); /** * Same as {@link #with(Object, Object, Object, Object, Object, Object)}. */ MutableMap of(K key1, V value1, K key2, V value2, K key3, V value3); MutableMap with(K key1, V value1, K key2, V value2, K key3, V value3); /** * Same as {@link #with(Object, Object, Object, Object, Object, Object, Object, Object)}. */ MutableMap of(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4); MutableMap with(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4); } package-info.java000066400000000000000000000026111234315411400337730ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/map/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains factory API for creating instances of type {@link com.gs.collections.api.map.MapIterable}. *

* This package contains 3 interfaces: *

    *
  • * {@link com.gs.collections.api.factory.map.FixedSizeMapFactory} - a factory which creates instances of type {@link com.gs.collections.api.map.FixedSizeMap}. *
  • *
  • * {@link com.gs.collections.api.factory.map.ImmutableMapFactory} - a factory which creates instances of type {@link com.gs.collections.api.map.ImmutableMap}. *
  • *
  • * {@link com.gs.collections.api.factory.map.MutableMapFactory} - a factory which creates instances of type {@link com.gs.collections.api.map.MutableMap}. *
  • *
*

*/ package com.gs.collections.api.factory.map; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/map/sorted/000077500000000000000000000000001234315411400321635ustar00rootroot00000000000000ImmutableSortedMapFactory.java000066400000000000000000000073611234315411400400440ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/map/sorted/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.factory.map.sorted; import java.util.Comparator; import java.util.SortedMap; import com.gs.collections.api.map.sorted.ImmutableSortedMap; public interface ImmutableSortedMapFactory { /** * Same as {@link #with()}. */ ImmutableSortedMap of(); ImmutableSortedMap with(); /** * Same as {@link #with(Object, Object)}. */ ImmutableSortedMap of(K key, V value); ImmutableSortedMap with(K key, V value); /** * Same as {@link #with(Object, Object, Object, Object)}. */ ImmutableSortedMap of(K key1, V value1, K key2, V value2); ImmutableSortedMap with(K key1, V value1, K key2, V value2); /** * Same as {@link #with(Object, Object, Object, Object, Object, Object)}. */ ImmutableSortedMap of(K key1, V value1, K key2, V value2, K key3, V value3); ImmutableSortedMap with(K key1, V value1, K key2, V value2, K key3, V value3); /** * Same as {@link #with(Object, Object, Object, Object, Object, Object, Object, Object)}. */ ImmutableSortedMap of(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4); ImmutableSortedMap with(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4); /** * Same as {@link #with(java.util.Comparator)}. */ ImmutableSortedMap of(Comparator comparator); ImmutableSortedMap with(Comparator comparator); /** * Same as {@link #with(java.util.Comparator, Object, Object)}. */ ImmutableSortedMap of(Comparator comparator, K key, V value); ImmutableSortedMap with(Comparator comparator, K key, V value); /** * Same as {@link #with(java.util.Comparator, Object, Object, Object, Object)}. */ ImmutableSortedMap of(Comparator comparator, K key1, V value1, K key2, V value2); ImmutableSortedMap with(Comparator comparator, K key1, V value1, K key2, V value2); /** * Same as {@link #with(java.util.Comparator, Object, Object, Object, Object, Object, Object)}. */ ImmutableSortedMap of(Comparator comparator, K key1, V value1, K key2, V value2, K key3, V value3); ImmutableSortedMap with(Comparator comparator, K key1, V value1, K key2, V value2, K key3, V value3); /** * Same as {@link #with(java.util.Comparator, Object, Object, Object, Object, Object, Object, Object, Object)}. */ ImmutableSortedMap of(Comparator comparator, K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4); ImmutableSortedMap with(Comparator comparator, K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4); /** * Same as {@link #withSortedMap(java.util.SortedMap)}. */ ImmutableSortedMap ofSortedMap(SortedMap map); ImmutableSortedMap withSortedMap(SortedMap map); } MutableSortedMapFactory.java000066400000000000000000000073211234315411400375120ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/map/sorted/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.factory.map.sorted; import java.util.Comparator; import java.util.Map; import com.gs.collections.api.map.sorted.MutableSortedMap; public interface MutableSortedMapFactory { /** * Same as {@link #with()}. */ MutableSortedMap of(); MutableSortedMap with(); /** * Same as {@link #with(Object, Object)}. */ MutableSortedMap of(K key, V value); MutableSortedMap with(K key, V value); /** * Same as {@link #with(Object, Object, Object, Object)}. */ MutableSortedMap of(K key1, V value1, K key2, V value2); MutableSortedMap with(K key1, V value1, K key2, V value2); /** * Same as {@link #with(Object, Object, Object, Object, Object, Object)}. */ MutableSortedMap of(K key1, V value1, K key2, V value2, K key3, V value3); MutableSortedMap with(K key1, V value1, K key2, V value2, K key3, V value3); /** * Same as {@link #with(Object, Object, Object, Object, Object, Object, Object, Object)}. */ MutableSortedMap of(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4); MutableSortedMap with(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4); /** * Same as {@link #with(java.util.Comparator)}. */ MutableSortedMap of(Comparator comparator); MutableSortedMap with(Comparator comparator); /** * Same as {@link #with(java.util.Comparator, Object, Object)}. */ MutableSortedMap of(Comparator comparator, K key, V value); MutableSortedMap with(Comparator comparator, K key, V value); /** * Same as {@link #with(java.util.Comparator, Object, Object, Object, Object)}. */ MutableSortedMap of(Comparator comparator, K key1, V value1, K key2, V value2); MutableSortedMap with(Comparator comparator, K key1, V value1, K key2, V value2); /** * Same as {@link #with(java.util.Comparator, Object, Object, Object, Object, Object, Object)}. */ MutableSortedMap of(Comparator comparator, K key1, V value1, K key2, V value2, K key3, V value3); MutableSortedMap with(Comparator comparator, K key1, V value1, K key2, V value2, K key3, V value3); /** * Same as {@link #with(java.util.Comparator, Object, Object, Object, Object, Object, Object, Object, Object)}. */ MutableSortedMap of(Comparator comparator, K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4); MutableSortedMap with(Comparator comparator, K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4); /** * Same as {@link #withSortedMap(java.util.Map)}. */ MutableSortedMap ofSortedMap(Map map); MutableSortedMap withSortedMap(Map map); } package-info.java000066400000000000000000000024201234315411400352710ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/map/sorted/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains factory API for creating instances of type {@link com.gs.collections.api.map.sorted.SortedMapIterable}. *

* This package contains 2 interfaces: *

    *
  • * {@link com.gs.collections.api.factory.map.sorted.ImmutableSortedMapFactory} - a factory which creates instances of type {@link com.gs.collections.api.map.sorted.ImmutableSortedMap}. *
  • *
  • * {@link com.gs.collections.api.factory.map.sorted.MutableSortedMapFactory} - a factory which creates instances of type {@link com.gs.collections.api.map.sorted.MutableSortedMap}. *
  • *
*

*/ package com.gs.collections.api.factory.map.sorted; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/map/strategy/000077500000000000000000000000001234315411400325255ustar00rootroot00000000000000ImmutableHashingStrategyMapFactory.java000066400000000000000000000057071234315411400422540ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/map/strategy/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.factory.map.strategy; import java.util.Map; import com.gs.collections.api.block.HashingStrategy; import com.gs.collections.api.map.ImmutableMap; public interface ImmutableHashingStrategyMapFactory { /** * Same as {@link #with(HashingStrategy)}. */ ImmutableMap of(HashingStrategy hashingStrategy); ImmutableMap with(HashingStrategy hashingStrategy); /** * Same as {@link #with(com.gs.collections.api.block.HashingStrategy, Object, Object)}. */ ImmutableMap of(HashingStrategy hashingStrategy, K key, V value); ImmutableMap with(HashingStrategy hashingStrategy, K key, V value); /** * Same as {@link #with(com.gs.collections.api.block.HashingStrategy, Object, Object, Object, Object)}. */ ImmutableMap of(HashingStrategy hashingStrategy, K key1, V value1, K key2, V value2); ImmutableMap with(HashingStrategy hashingStrategy, K key1, V value1, K key2, V value2); /** * Same as {@link #with(com.gs.collections.api.block.HashingStrategy, Object, Object, Object, Object, Object, Object)}. */ ImmutableMap of( HashingStrategy hashingStrategy, K key1, V value1, K key2, V value2, K key3, V value3); ImmutableMap with( HashingStrategy hashingStrategy, K key1, V value1, K key2, V value2, K key3, V value3); /** * Same as {@link #with(com.gs.collections.api.block.HashingStrategy, Object, Object, Object, Object, Object, Object, Object, Object)}. */ ImmutableMap of( HashingStrategy hashingStrategy, K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4); ImmutableMap with( HashingStrategy hashingStrategy, K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4); ImmutableMap ofMap(Map map); /** * Same as {@link #withAll(Map)}. */ ImmutableMap ofAll(Map map); ImmutableMap withAll(Map map); } MutableHashingStrategyMapFactory.java000066400000000000000000000053011234315411400417140ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/map/strategy/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.factory.map.strategy; import com.gs.collections.api.block.HashingStrategy; import com.gs.collections.api.map.MutableMap; public interface MutableHashingStrategyMapFactory { /** * Same as {@link #with(HashingStrategy)}. */ MutableMap of(HashingStrategy hashingStrategy); MutableMap with(HashingStrategy hashingStrategy); /** * Same as {@link #with(com.gs.collections.api.block.HashingStrategy, Object, Object)}. */ MutableMap of(HashingStrategy hashingStrategy, K key, V value); MutableMap with(HashingStrategy hashingStrategy, K key, V value); /** * Same as {@link #with(com.gs.collections.api.block.HashingStrategy, Object, Object, Object, Object)}. */ MutableMap of(HashingStrategy hashingStrategy, K key1, V value1, K key2, V value2); MutableMap with(HashingStrategy hashingStrategy, K key1, V value1, K key2, V value2); /** * Same as {@link #with(com.gs.collections.api.block.HashingStrategy, Object, Object, Object, Object, Object, Object)}. */ MutableMap of( HashingStrategy hashingStrategy, K key1, V value1, K key2, V value2, K key3, V value3); MutableMap with( HashingStrategy hashingStrategy, K key1, V value1, K key2, V value2, K key3, V value3); /** * Same as {@link #with(com.gs.collections.api.block.HashingStrategy, Object, Object, Object, Object, Object, Object, Object, Object)}. */ MutableMap of( HashingStrategy hashingStrategy, K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4); MutableMap with( HashingStrategy hashingStrategy, K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4); } package-info.java000066400000000000000000000024601234315411400356370ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/map/strategy/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains factory API for creating instances of maps with user defined {@link com.gs.collections.api.block.HashingStrategy}s. *

* This package contains 2 interfaces: *

    *
  • * {@link com.gs.collections.api.factory.map.ImmutableMapFactory} - a factory which creates instances of type {@link com.gs.collections.api.map.ImmutableMap} with user defined hashing strategy. *
  • *
  • * {@link com.gs.collections.api.factory.map.MutableMapFactory} - a factory which creates instances of type {@link com.gs.collections.api.map.MutableMap} with user defined hashing strategy. *
  • *
*

*/ package com.gs.collections.api.factory.map.strategy; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/set/000077500000000000000000000000001234315411400307015ustar00rootroot00000000000000FixedSizeSetFactory.java000066400000000000000000000032741234315411400353710ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/set/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.factory.set; import com.gs.collections.api.set.FixedSizeSet; import com.gs.collections.api.set.MutableSet; public interface FixedSizeSetFactory { /** * Same as {@link #with()}. */ FixedSizeSet of(); FixedSizeSet with(); /** * Same as {@link #with(Object)}. */ FixedSizeSet of(T one); FixedSizeSet with(T one); /** * Same as {@link #with(Object, Object)}. */ FixedSizeSet of(T one, T two); FixedSizeSet with(T one, T two); /** * Same as {@link #with(Object, Object, Object)}. */ FixedSizeSet of(T one, T two, T three); FixedSizeSet with(T one, T two, T three); /** * Same as {@link #with(Object, Object, Object, Object)}. */ FixedSizeSet of(T one, T two, T three, T four); FixedSizeSet with(T one, T two, T three, T four); /** * Same as {@link #withAll(Iterable)}. */ MutableSet ofAll(Iterable items); MutableSet withAll(Iterable items); } ImmutableSetFactory.java000066400000000000000000000034361234315411400354160ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/set/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.factory.set; import com.gs.collections.api.set.ImmutableSet; public interface ImmutableSetFactory { /** * Same as {@link #with()}. */ ImmutableSet of(); ImmutableSet with(); /** * Same as {@link #with(Object)}. */ ImmutableSet of(T one); ImmutableSet with(T one); /** * Same as {@link #with(Object, Object)}. */ ImmutableSet of(T one, T two); ImmutableSet with(T one, T two); /** * Same as {@link #with(Object, Object, Object)}. */ ImmutableSet of(T one, T two, T three); ImmutableSet with(T one, T two, T three); /** * Same as {@link #with(Object, Object, Object, Object)}. */ ImmutableSet of(T one, T two, T three, T four); ImmutableSet with(T one, T two, T three, T four); /** * Same as {@link #with(Object[])}. */ ImmutableSet of(T... items); ImmutableSet with(T... items); /** * Same as {@link #withAll(Iterable)}. */ ImmutableSet ofAll(Iterable items); ImmutableSet withAll(Iterable items); } MutableSetFactory.java000066400000000000000000000022001234315411400350540ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/set/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.factory.set; import com.gs.collections.api.set.MutableSet; public interface MutableSetFactory { /** * Same as {@link #with()}. */ MutableSet of(); MutableSet with(); /** * Same as {@link #with(Object[])}. */ MutableSet of(T... items); MutableSet with(T... items); /** * Same as {@link #withAll(Iterable)}. */ MutableSet ofAll(Iterable items); MutableSet withAll(Iterable items); } package-info.java000066400000000000000000000026371234315411400340210ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/set/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains Factory API for {@link com.gs.collections.api.set.FixedSizeSet}, {@link com.gs.collections.api.set.ImmutableSet} and {@link com.gs.collections.api.set.MutableSet}. *

* This package contains 3 interfaces: *

    *
  • * {@link com.gs.collections.api.factory.set.FixedSizeSetFactory} - Contains Factory API for {@link com.gs.collections.api.set.FixedSizeSet}. *
  • *
  • * {@link com.gs.collections.api.factory.set.ImmutableSetFactory} - Contains Factory API for {@link com.gs.collections.api.set.ImmutableSet}. *
  • *
  • * {@link com.gs.collections.api.factory.set.MutableSetFactory} - Contains Factory API for {@link com.gs.collections.api.set.MutableSet}. *
  • *
*

*/ package com.gs.collections.api.factory.set; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/set/sorted/000077500000000000000000000000001234315411400322015ustar00rootroot00000000000000ImmutableSortedSetFactory.java000066400000000000000000000042231234315411400400720ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/set/sorted/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.factory.set.sorted; import java.util.Comparator; import java.util.SortedSet; import com.gs.collections.api.set.sorted.ImmutableSortedSet; public interface ImmutableSortedSetFactory { /** * Same as {@link #with()}. */ ImmutableSortedSet of(); ImmutableSortedSet with(); /** * Same as {@link #with(Object[])}. */ ImmutableSortedSet of(T... items); ImmutableSortedSet with(T... items); /** * Same as {@link #withAll(Iterable)}. */ ImmutableSortedSet ofAll(Iterable items); ImmutableSortedSet withAll(Iterable items); /** * Same as {@link #with(Comparator)}. */ ImmutableSortedSet of(Comparator comparator); ImmutableSortedSet with(Comparator comparator); /** * Same as {@link #with(java.util.Comparator, Object[])}. */ ImmutableSortedSet of(Comparator comparator, T... items); ImmutableSortedSet with(Comparator comparator, T... items); /** * Same as {@link #withAll(Comparator, Iterable)}. */ ImmutableSortedSet ofAll(Comparator comparator, Iterable items); ImmutableSortedSet withAll(Comparator comparator, Iterable items); /** * Same as {@link #withSortedSet(SortedSet)}. */ ImmutableSortedSet ofSortedSet(SortedSet set); ImmutableSortedSet withSortedSet(SortedSet set); } MutableSortedSetFactory.java000066400000000000000000000030511234315411400375420ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/set/sorted/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.factory.set.sorted; import java.util.Comparator; import com.gs.collections.api.set.sorted.MutableSortedSet; public interface MutableSortedSetFactory { MutableSortedSet of(); MutableSortedSet with(); MutableSortedSet of(T... items); MutableSortedSet with(T... items); MutableSortedSet ofAll(Iterable items); MutableSortedSet withAll(Iterable items); MutableSortedSet of(Comparator comparator); MutableSortedSet with(Comparator comparator); MutableSortedSet of(Comparator comparator, T... items); MutableSortedSet with(Comparator comparator, T... items); MutableSortedSet ofAll(Comparator comparator, Iterable items); MutableSortedSet withAll(Comparator comparator, Iterable items); } package-info.java000066400000000000000000000024411234315411400353120ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/set/sorted/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains {@link com.gs.collections.api.factory.set.sorted.ImmutableSortedSetFactory} and {@link com.gs.collections.api.factory.set.sorted.MutableSortedSetFactory}. *

* This package contains 2 interfaces: *

    *
  • * {@link com.gs.collections.api.factory.set.sorted.ImmutableSortedSetFactory} - Contains Factory API for {@link com.gs.collections.api.set.sorted.ImmutableSortedSet}. *
  • *
  • * {@link com.gs.collections.api.factory.set.sorted.MutableSortedSetFactory} - Contains Factory API for {@link com.gs.collections.api.set.sorted.MutableSortedSet}. *
  • *
*

*/ package com.gs.collections.api.factory.set.sorted; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/set/strategy/000077500000000000000000000000001234315411400325435ustar00rootroot00000000000000ImmutableHashingStrategySetFactory.java000066400000000000000000000030571234315411400423040ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/set/strategy/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.factory.set.strategy; import com.gs.collections.api.block.HashingStrategy; import com.gs.collections.api.set.ImmutableSet; public interface ImmutableHashingStrategySetFactory { /** * Same as {@link #with(HashingStrategy)}. */ ImmutableSet of(HashingStrategy hashingStrategy); ImmutableSet with(HashingStrategy hashingStrategy); /** * Same as {@link #with(com.gs.collections.api.block.HashingStrategy, Object[])}. */ ImmutableSet of(HashingStrategy hashingStrategy, T... items); ImmutableSet with(HashingStrategy hashingStrategy, T... items); /** * Same as {@link #withAll(HashingStrategy, Iterable)}. */ ImmutableSet ofAll(HashingStrategy hashingStrategy, Iterable items); ImmutableSet withAll(HashingStrategy hashingStrategy, Iterable items); } MutableHashingStrategySetFactory.java000066400000000000000000000030371234315411400417540ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/set/strategy/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.factory.set.strategy; import com.gs.collections.api.block.HashingStrategy; import com.gs.collections.api.set.MutableSet; public interface MutableHashingStrategySetFactory { /** * Same as {@link #with(HashingStrategy)}. */ MutableSet of(HashingStrategy hashingStrategy); MutableSet with(HashingStrategy hashingStrategy); /** * Same as {@link #with(com.gs.collections.api.block.HashingStrategy, Object[])}. */ MutableSet of(HashingStrategy hashingStrategy, T... items); MutableSet with(HashingStrategy hashingStrategy, T... items); /** * Same as {@link #withAll(HashingStrategy, Iterable)}. */ MutableSet ofAll(HashingStrategy hashingStrategy, Iterable items); MutableSet withAll(HashingStrategy hashingStrategy, Iterable items); } package-info.java000066400000000000000000000024671234315411400356640ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/set/strategy/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains Factory API for {@link com.gs.collections.api.factory.set.strategy.ImmutableHashingStrategySetFactory} and {@link com.gs.collections.api.factory.set.strategy.MutableHashingStrategySetFactory}. *

* This package contains 2 interfaces: *

    *
  • * {@link com.gs.collections.api.factory.bag.ImmutableBagFactory} - Contains Hashing Strategy Factory API for {@link com.gs.collections.api.set.ImmutableSet}. *
  • *
  • * {@link com.gs.collections.api.factory.bag.MutableBagFactory} - Contains Hashing Strategy Factory API for {@link com.gs.collections.api.set.MutableSet}. *
  • *
*

*/ package com.gs.collections.api.factory.set.strategy; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/stack/000077500000000000000000000000001234315411400312135ustar00rootroot00000000000000ImmutableStackFactory.java000066400000000000000000000032671234315411400362440ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/stack/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.factory.stack; import com.gs.collections.api.stack.ImmutableStack; public interface ImmutableStackFactory { /** * Same as {@link #with()}. */ ImmutableStack of(); ImmutableStack with(); /** * Same as {@link #with(Object)}. */ ImmutableStack of(T element); ImmutableStack with(T element); /** * Same as {@link #with(Object[])}. */ ImmutableStack of(T... elements); ImmutableStack with(T... elements); /** * Same as {@link #withAll(Iterable)}. */ ImmutableStack ofAll(Iterable items); ImmutableStack withAll(Iterable items); /** * Same as {@link #withReversed(Object[])}. */ ImmutableStack ofReversed(T... elements); ImmutableStack withReversed(T... elements); /** * Same as {@link #withAllReversed(Iterable)}. */ ImmutableStack ofAllReversed(Iterable items); ImmutableStack withAllReversed(Iterable items); } MutableStackFactory.java000066400000000000000000000030311234315411400357030ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/stack/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.factory.stack; import com.gs.collections.api.stack.MutableStack; public interface MutableStackFactory { /** * Same as {@link #with()}. */ MutableStack of(); MutableStack with(); /** * Same as {@link #with(Object[])}. */ MutableStack of(T... elements); MutableStack with(T... elements); /** * Same as {@link #withAll(Iterable)}. */ MutableStack ofAll(Iterable elements); MutableStack withAll(Iterable elements); /** * Same as {@link #withReversed(Object[])}. */ MutableStack ofReversed(T... elements); MutableStack withReversed(T... elements); /** * Same as {@link #withAllReversed(Iterable)}. */ MutableStack ofAllReversed(Iterable items); MutableStack withAllReversed(Iterable items); } package-info.java000066400000000000000000000023301234315411400343210ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/factory/stack/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains Factory API for {@link com.gs.collections.api.stack.ImmutableStack} and {@link com.gs.collections.api.stack.MutableStack}. *

* This package contains 2 interfaces: *

    *
  • * {@link com.gs.collections.api.factory.stack.ImmutableStackFactory} - Contains Factory API for {@link com.gs.collections.api.stack.ImmutableStack}. *
  • *
  • * {@link com.gs.collections.api.factory.stack.MutableStackFactory} - Contains Factory API for {@link com.gs.collections.api.stack.MutableStack}. *
  • *
*

*/ package com.gs.collections.api.factory.stack; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/iterator/000077500000000000000000000000001234315411400302705ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/iterator/package-info.java000066400000000000000000000015011234315411400334540ustar00rootroot00000000000000/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains primitive iterator API. *

* This package contains 8 iterator interfaces one each for boolean, byte, char, int, long, double, short and float. *

*/ package com.gs.collections.api.iterator; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/list/000077500000000000000000000000001234315411400274125ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/list/FixedSizeList.java000066400000000000000000000020321234315411400330000ustar00rootroot00000000000000/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.list; import com.gs.collections.api.collection.FixedSizeCollection; /** * A FixedSizeList is a list that may be mutated, but cannot grow or shrink in size. The typical * mutation allowed for a FixedSizeList implementation is a working implementation for set(int, T). * This will allow the FixedSizeList to be sorted. */ public interface FixedSizeList extends MutableList, FixedSizeCollection { } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/list/ImmutableList.java000066400000000000000000000117641234315411400330410ustar00rootroot00000000000000/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.list; import java.util.List; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.collection.ImmutableCollection; import com.gs.collections.api.list.primitive.ImmutableBooleanList; import com.gs.collections.api.list.primitive.ImmutableByteList; import com.gs.collections.api.list.primitive.ImmutableCharList; import com.gs.collections.api.list.primitive.ImmutableDoubleList; import com.gs.collections.api.list.primitive.ImmutableFloatList; import com.gs.collections.api.list.primitive.ImmutableIntList; import com.gs.collections.api.list.primitive.ImmutableLongList; import com.gs.collections.api.list.primitive.ImmutableShortList; import com.gs.collections.api.multimap.list.ImmutableListMultimap; import com.gs.collections.api.partition.list.PartitionImmutableList; import com.gs.collections.api.tuple.Pair; import net.jcip.annotations.Immutable; /** * ImmutableList is the non-modifiable equivalent interface to {@link MutableList}. {@link MutableList#toImmutable()} * will give you an appropriately trimmed implementation of ImmutableList. All ImmutableList implementations must * implement the java.util.List interface so they can satisfy the equals() contract and be compared against other list * structures like FastList or ArrayList. */ @Immutable public interface ImmutableList extends ImmutableCollection, ListIterable { ImmutableList newWith(T element); ImmutableList newWithout(T element); ImmutableList newWithAll(Iterable elements); ImmutableList newWithoutAll(Iterable elements); ImmutableList select(Predicate predicate);

ImmutableList selectWith(Predicate2 predicate, P parameter); ImmutableList reject(Predicate predicate);

ImmutableList rejectWith(Predicate2 predicate, P parameter); PartitionImmutableList partition(Predicate predicate);

PartitionImmutableList partitionWith(Predicate2 predicate, P parameter); ImmutableList selectInstancesOf(Class clazz); ImmutableList collect(Function function); ImmutableBooleanList collectBoolean(BooleanFunction booleanFunction); ImmutableByteList collectByte(ByteFunction byteFunction); ImmutableCharList collectChar(CharFunction charFunction); ImmutableDoubleList collectDouble(DoubleFunction doubleFunction); ImmutableFloatList collectFloat(FloatFunction floatFunction); ImmutableIntList collectInt(IntFunction intFunction); ImmutableLongList collectLong(LongFunction longFunction); ImmutableShortList collectShort(ShortFunction shortFunction); ImmutableList collectWith(Function2 function, P parameter); ImmutableList collectIf(Predicate predicate, Function function); ImmutableList flatCollect(Function> function); ImmutableListMultimap groupBy(Function function); ImmutableListMultimap groupByEach(Function> function); ImmutableList distinct(); ImmutableList> zip(Iterable that); ImmutableList> zipWithIndex(); ImmutableList takeWhile(Predicate predicate); ImmutableList dropWhile(Predicate predicate); PartitionImmutableList partitionWhile(Predicate predicate); List castToList(); } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/list/ListIterable.java000066400000000000000000000224451234315411400326470ustar00rootroot00000000000000/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.list; import java.util.Comparator; import java.util.List; import java.util.ListIterator; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.list.primitive.BooleanList; import com.gs.collections.api.list.primitive.ByteList; import com.gs.collections.api.list.primitive.CharList; import com.gs.collections.api.list.primitive.DoubleList; import com.gs.collections.api.list.primitive.FloatList; import com.gs.collections.api.list.primitive.IntList; import com.gs.collections.api.list.primitive.LongList; import com.gs.collections.api.list.primitive.ShortList; import com.gs.collections.api.multimap.list.ListMultimap; import com.gs.collections.api.ordered.ReversibleIterable; import com.gs.collections.api.partition.list.PartitionList; import com.gs.collections.api.stack.MutableStack; import com.gs.collections.api.tuple.Pair; /** * An iterable whose items are ordered and may be accessed directly by index. A reverseForEach * internal iterator is available iterating over the indexed iterable in reverse, starting from * the end and going to the beginning. Additionally, internal iterators are available for batching * style iteration which is useful for parallel processing. */ public interface ListIterable extends ReversibleIterable { /** * Iterates over the section of the list covered by the specified inclusive indexes. The indexes are * both inclusive. *

*

*

e.g.
     * ListIterable people = FastList.newListWith(ted, mary, bob, sally)
     * people.forEach(0, 1, new Procedure()
     * {
     *     public void value(Person person)
     *     {
     *          LOGGER.info(person.getName());
     *     }
     * });
     * 
*

* This code would output ted and mary's names. */ void forEach(int startIndex, int endIndex, Procedure procedure); /** * Iterates over the section of the list covered by the specified inclusive indexes. The indexes are * both inclusive. *

*

*

e.g.
     * ListIterable people = FastList.newListWith(ted, mary, bob, sally)
     * people.forEachWithIndex(0, 1, new ObjectIntProcedure()
     * {
     *     public void value(Person person, int index)
     *     {
     *          LOGGER.info(person.getName());
     *     }
     * });
     * 
*

* This code would output ted and mary's names. */ void forEachWithIndex(int fromIndex, int toIndex, ObjectIntProcedure objectIntProcedure); /** * Returns the item at the specified position in this list iterable. */ T get(int index); /** * Returns the index of the last occurrence of the specified item * in this list, or -1 if this list does not contain the item. */ int lastIndexOf(Object o); /** * Returns the item at index 0 of the container. If the container is empty, null is returned. If null * is a valid item of the container, then a developer will need to check to see if the container is * empty first. */ T getFirst(); /** * Returns the item at index (size() - 1) of the container. If the container is empty, null is returned. If null * is a valid item of the container, then a developer will need to check to see if the container is * empty first. */ T getLast(); /** * @see List#listIterator() * @since 1.0. */ ListIterator listIterator(); /** * @see List#listIterator(int) * @since 1.0. */ ListIterator listIterator(int index); /** * Converts the list to a mutable MutableStack implementation. * * @since 2.0 */ MutableStack toStack(); /** * Converts the ListIterable to an immutable implementation. Returns this for immutable lists. * * @since 5.0 */ ImmutableList toImmutable(); ListIterable select(Predicate predicate);

ListIterable selectWith(Predicate2 predicate, P parameter); ListIterable reject(Predicate predicate);

ListIterable rejectWith(Predicate2 predicate, P parameter); PartitionList partition(Predicate predicate);

PartitionList partitionWith(Predicate2 predicate, P parameter); ListIterable selectInstancesOf(Class clazz); ListIterable collect(Function function); BooleanList collectBoolean(BooleanFunction booleanFunction); ByteList collectByte(ByteFunction byteFunction); CharList collectChar(CharFunction charFunction); DoubleList collectDouble(DoubleFunction doubleFunction); FloatList collectFloat(FloatFunction floatFunction); IntList collectInt(IntFunction intFunction); LongList collectLong(LongFunction longFunction); ShortList collectShort(ShortFunction shortFunction); ListIterable collectWith(Function2 function, P parameter); ListIterable collectIf(Predicate predicate, Function function); ListIterable flatCollect(Function> function); ListMultimap groupBy(Function function); ListMultimap groupByEach(Function> function); /** * Returns a new {@code ListIterable} containing the distinct elements in this list. *

* Conceptually similar to {@link #toSet()}.{@link #toList()} but retains the original order. If an element appears * multiple times in this list, the first one will be copied into the result. * * @return {@code ListIterable} of distinct elements * @since 3.0 */ ListIterable distinct(); ListIterable> zip(Iterable that); ListIterable> zipWithIndex(); /** * Returns the initial elements that satisfy the Predicate. Short circuits at the first element which does not * satisfy the Predicate. * * @since 3.0 */ ListIterable takeWhile(Predicate predicate); /** * Returns the final elements that do not satisfy the Predicate. Short circuits at the first element which does * satisfy the Predicate. * * @since 3.0 */ ListIterable dropWhile(Predicate predicate); /** * Returns a Partition of the initial elements that satisfy the Predicate and the remaining elements. Short circuits at the first element which does * satisfy the Predicate. * * @since 3.0 */ PartitionList partitionWhile(Predicate predicate); /** * Returns a reversed view of this ListIterable. * * @since 3.0 */ LazyIterable asReversed(); /** * Searches for the specified object using the binary search algorithm. The list must be sorted into ascending * order according to the specified comparator. * * @see java.util.Collections#binarySearch(java.util.List, Object, java.util.Comparator) */ int binarySearch(T key, Comparator comparator); /** * Searches for the specified object using the binary search algorithm. The elements in this list must implement * Comparable and the list must be sorted into ascending order. * * @see java.util.Collections#binarySearch(java.util.List, Object) */ int binarySearch(T key); /** * Follows the same general contract as {@link List#equals(Object)}. */ @Override boolean equals(Object o); /** * Follows the same general contract as {@link List#hashCode()}. */ @Override int hashCode(); } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/list/MutableList.java000066400000000000000000000140531234315411400325050ustar00rootroot00000000000000/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.list; import java.util.Comparator; import java.util.List; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.collection.MutableCollection; import com.gs.collections.api.list.primitive.MutableBooleanList; import com.gs.collections.api.list.primitive.MutableByteList; import com.gs.collections.api.list.primitive.MutableCharList; import com.gs.collections.api.list.primitive.MutableDoubleList; import com.gs.collections.api.list.primitive.MutableFloatList; import com.gs.collections.api.list.primitive.MutableIntList; import com.gs.collections.api.list.primitive.MutableLongList; import com.gs.collections.api.list.primitive.MutableShortList; import com.gs.collections.api.multimap.list.MutableListMultimap; import com.gs.collections.api.partition.list.PartitionMutableList; import com.gs.collections.api.tuple.Pair; /** * A MutableList is an implementation of a JCF List which provides methods matching the Smalltalk Collection protocol. */ public interface MutableList extends MutableCollection, List, Cloneable, ListIterable { MutableList with(T element); MutableList without(T element); MutableList withAll(Iterable elements); MutableList withoutAll(Iterable elements); MutableList newEmpty(); MutableList clone(); MutableList select(Predicate predicate);

MutableList selectWith(Predicate2 predicate, P parameter); MutableList reject(Predicate predicate);

MutableList rejectWith(Predicate2 predicate, P parameter); PartitionMutableList partition(Predicate predicate);

PartitionMutableList partitionWith(Predicate2 predicate, P parameter); MutableList selectInstancesOf(Class clazz); MutableList collect(Function function); MutableBooleanList collectBoolean(BooleanFunction booleanFunction); MutableByteList collectByte(ByteFunction byteFunction); MutableCharList collectChar(CharFunction charFunction); MutableDoubleList collectDouble(DoubleFunction doubleFunction); MutableFloatList collectFloat(FloatFunction floatFunction); MutableIntList collectInt(IntFunction intFunction); MutableLongList collectLong(LongFunction longFunction); MutableShortList collectShort(ShortFunction shortFunction); MutableList collectWith(Function2 function, P parameter); MutableList collectIf(Predicate predicate, Function function); MutableList flatCollect(Function> function); MutableList distinct(); /** * Sorts the internal data structure of this list and returns the list itself as a convenience. */ MutableList sortThis(Comparator comparator); /** * Sorts the internal data structure of this list and returns the list itself as a convenience. */ MutableList sortThis(); /** * Sorts the internal data structure of this list based on the natural order of the attribute returned by {@code * function}. */ > MutableList sortThisBy(Function function); MutableList subList(int fromIndex, int toIndex); /** * Returns an unmodifable view of the list. * The returned list will be Serializable if this list is Serializable. * * @return an unmodifiable view of this list */ MutableList asUnmodifiable(); MutableList asSynchronized(); /** * Returns an immutable copy of this list. If the list is immutable, it returns itself. * The returned list will be Serializable if this list is Serializable. */ ImmutableList toImmutable(); MutableListMultimap groupBy(Function function); MutableListMultimap groupByEach(Function> function); MutableList> zip(Iterable that); MutableList> zipWithIndex(); MutableList takeWhile(Predicate predicate); MutableList dropWhile(Predicate predicate); PartitionMutableList partitionWhile(Predicate predicate); /** * Returns a new MutableList in reverse order */ MutableList toReversed(); /** * Mutates the current list by reversing its order and returns the current list as a result */ MutableList reverseThis(); } ParallelListIterable.java000066400000000000000000000115671234315411400342500ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/list/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.list; import com.gs.collections.api.ParallelIterable; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.multimap.list.ListMultimap; import com.gs.collections.api.set.ParallelUnsortedSetIterable; /** * A ParallelIterable is RichIterable which will defer evaluation for certain methods like select, reject, collect, etc. * Any methods that do not return a ParallelIterable when called will cause evaluation to be forced. Evaluation occurs * in parallel. All code blocks passed in must be stateless or thread-safe. * * @since 5.0 */ @Beta public interface ParallelListIterable extends ParallelIterable { ParallelUnsortedSetIterable asUnique(); /** * Creates a parallel iterable for selecting elements from the current iterable. */ ParallelListIterable select(Predicate predicate);

ParallelListIterable selectWith(Predicate2 predicate, P parameter); /** * Creates a parallel iterable for rejecting elements from the current iterable. */ ParallelListIterable reject(Predicate predicate);

ParallelListIterable rejectWith(Predicate2 predicate, P parameter); ParallelListIterable selectInstancesOf(Class clazz); /** * Creates a parallel iterable for collecting elements from the current iterable. */ ParallelListIterable collect(Function function); ParallelListIterable collectWith(Function2 function, P parameter); /** * Creates a parallel iterable for selecting and collecting elements from the current iterable. */ ParallelListIterable collectIf(Predicate predicate, Function function); /** * Creates a parallel flattening iterable for the current iterable. */ ParallelListIterable flatCollect(Function> function); ListMultimap groupBy(Function function); ListMultimap groupByEach(Function> function); // /** // * Returns a parallel BooleanIterable which will transform the underlying iterable data to boolean values based on the booleanFunction. // */ // ParallelBooleanIterable collectBoolean(BooleanFunction booleanFunction); // // /** // * Returns a parallel ByteIterable which will transform the underlying iterable data to byte values based on the byteFunction. // */ // ParallelByteIterable collectByte(ByteFunction byteFunction); // // /** // * Returns a parallel CharIterable which will transform the underlying iterable data to char values based on the charFunction. // */ // ParallelCharIterable collectChar(CharFunction charFunction); // // /** // * Returns a parallel DoubleIterable which will transform the underlying iterable data to double values based on the doubleFunction. // */ // ParallelDoubleIterable collectDouble(DoubleFunction doubleFunction); // // /** // * Returns a parallel FloatIterable which will transform the underlying iterable data to float values based on the floatFunction. // */ // ParallelFloatIterable collectFloat(FloatFunction floatFunction); // // /** // * Returns a parallel IntIterable which will transform the underlying iterable data to int values based on the intFunction. // */ // ParallelIntIterable collectInt(IntFunction intFunction); // // /** // * Returns a parallel LongIterable which will transform the underlying iterable data to long values based on the longFunction. // */ // ParallelLongIterable collectLong(LongFunction longFunction); // // /** // * Returns a parallel ShortIterable which will transform the underlying iterable data to short values based on the shortFunction. // */ // ParallelShortIterable collectShort(ShortFunction shortFunction); } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/list/package-info.java000066400000000000000000000030441234315411400326020ustar00rootroot00000000000000/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains interfaces for list API which enhance the performance and functionality of {@link java.util.List}. *

* This package contains 4 interfaces: *

    *
  • * {@link com.gs.collections.api.list.ListIterable} - an {@link java.lang.Iterable} which contains items that are ordered and may be accessed directly by index. *
  • *
  • * {@link com.gs.collections.api.list.MutableList} - an implementation of a JCF List which provides internal iterator methods matching the Smalltalk Collection protocol. *
  • *
  • * {@link com.gs.collections.api.list.ImmutableList} - the non-modifiable equivalent interface to {@link com.gs.collections.api.list.MutableList}. *
  • *
  • * {@link com.gs.collections.api.list.FixedSizeList} - a list that may be mutated, but cannot grow or shrink in size. *
  • *
*

*/ package com.gs.collections.api.list; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/list/primitive/000077500000000000000000000000001234315411400314225ustar00rootroot00000000000000package-info.java000066400000000000000000000015421234315411400345340ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/list/primitive/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains mutable and immutable primitive list API. *

* A primitive list is similar to a {@link com.gs.collections.api.list.ListIterable}, but is memory-optimized for primitives. *

*/ package com.gs.collections.api.list.primitive; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/map/000077500000000000000000000000001234315411400272145ustar00rootroot00000000000000ConcurrentMutableMap.java000066400000000000000000000015771234315411400341040ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/map/* * Copyright 2012 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.map; import java.util.concurrent.ConcurrentMap; /** * A ConcurrentMutableMap provides an api which combines and supports both MutableMap and ConcurrentMap. */ public interface ConcurrentMutableMap extends MutableMap, ConcurrentMap { } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/map/FixedSizeMap.java000066400000000000000000000023771234315411400324200ustar00rootroot00000000000000/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.map; import java.util.Map; /** * A FixedSizeMap is a map that may be mutated, but cannot grow or shrink in size. */ public interface FixedSizeMap extends MutableMap { /** * @throws UnsupportedOperationException */ void clear(); /** * @throws UnsupportedOperationException */ V put(K key, V value); /** * @throws UnsupportedOperationException */ void putAll(Map map); /** * @throws UnsupportedOperationException */ V remove(Object key); /** * @throws UnsupportedOperationException */ V removeKey(K key); } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/map/ImmutableMap.java000066400000000000000000000133421234315411400324370ustar00rootroot00000000000000/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.map; import java.util.Map; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.collection.ImmutableCollection; import com.gs.collections.api.collection.primitive.ImmutableBooleanCollection; import com.gs.collections.api.collection.primitive.ImmutableByteCollection; import com.gs.collections.api.collection.primitive.ImmutableCharCollection; import com.gs.collections.api.collection.primitive.ImmutableDoubleCollection; import com.gs.collections.api.collection.primitive.ImmutableFloatCollection; import com.gs.collections.api.collection.primitive.ImmutableIntCollection; import com.gs.collections.api.collection.primitive.ImmutableLongCollection; import com.gs.collections.api.collection.primitive.ImmutableShortCollection; import com.gs.collections.api.multimap.ImmutableMultimap; import com.gs.collections.api.multimap.set.ImmutableSetMultimap; import com.gs.collections.api.partition.PartitionImmutableCollection; import com.gs.collections.api.tuple.Pair; import net.jcip.annotations.Immutable; /** * An ImmutableMap is different than a JCF Map but in that it has no mutating methods. It shares the read-only * protocol of a JDK Map. */ @Immutable public interface ImmutableMap extends UnsortedMapIterable { ImmutableMap select(Predicate2 predicate); ImmutableMap collect(Function2> function); ImmutableMap collectValues(Function2 function); ImmutableMap reject(Predicate2 predicate); Map castToMap(); ImmutableMap newWithKeyValue(K key, V value); ImmutableMap newWithAllKeyValues(Iterable> keyValues); ImmutableMap newWithAllKeyValueArguments(Pair... keyValuePairs); ImmutableMap newWithoutKey(K key); ImmutableMap newWithoutAllKeys(Iterable keys); MutableMap toMap(); ImmutableSetMultimap flip(); ImmutableCollection collect(Function function); ImmutableBooleanCollection collectBoolean(BooleanFunction booleanFunction); ImmutableByteCollection collectByte(ByteFunction byteFunction); ImmutableCharCollection collectChar(CharFunction charFunction); ImmutableDoubleCollection collectDouble(DoubleFunction doubleFunction); ImmutableFloatCollection collectFloat(FloatFunction floatFunction); ImmutableIntCollection collectInt(IntFunction intFunction); ImmutableLongCollection collectLong(LongFunction longFunction); ImmutableShortCollection collectShort(ShortFunction shortFunction); ImmutableCollection collectIf(Predicate predicate, Function function); ImmutableCollection flatCollect(Function> function); ImmutableCollection select(Predicate predicate); ImmutableCollection reject(Predicate predicate); PartitionImmutableCollection partition(Predicate predicate);

PartitionImmutableCollection partitionWith(Predicate2 predicate, P parameter); ImmutableCollection selectInstancesOf(Class clazz); ImmutableCollection> zip(Iterable that); ImmutableCollection> zipWithIndex(); ImmutableMultimap groupBy(Function function); ImmutableMultimap groupByEach(Function> function); ImmutableMap groupByUniqueKey(Function function); ImmutableMap aggregateInPlaceBy( Function groupBy, Function0 zeroValueFactory, Procedure2 mutatingAggregator); ImmutableMap aggregateBy( Function groupBy, Function0 zeroValueFactory, Function2 nonMutatingAggregator); ImmutableMap flipUniqueValues(); } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/map/MapIterable.java000066400000000000000000000241231234315411400322460ustar00rootroot00000000000000/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.map; import java.util.Map; import com.gs.collections.api.RichIterable; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.multimap.Multimap; import com.gs.collections.api.tuple.Pair; /** * A Read-only Map API, with the minor exception inherited from java.lang.Iterable. The method map.iterator().remove() * will throw an UnsupportedOperationException. */ public interface MapIterable extends RichIterable { /** * @see Map#get(Object) */ V get(Object key); /** * @see Map#containsKey(Object) */ boolean containsKey(Object key); /** * @see Map#containsValue(Object) */ boolean containsValue(Object value); /** * Calls the procedure with each value of the map. *

     *     Set<String> result = UnifiedSet.newSet();
     *     MutableMap<Integer, String> map = this.newMapWithKeysValues(1, "One", 2, "Two", 3, "Three", 4, "Four");
     *     map.forEachValue(new CollectionAddProcedure<String>(result));
     *     Verify.assertSetsEqual(UnifiedSet.newSetWith("One", "Two", "Three", "Four"), result);
     * 
*/ void forEachValue(Procedure procedure); /** * Calls the {@code procedure} with each key of the map. *
     *     final Collection<Integer> result = new ArrayList<Integer>();
     *     MutableMap<Integer, String> map = this.newMapWithKeysValues(1, "1", 2, "2", 3, "3");
     *     map.forEachKey(new CollectionAddProcedure<Integer>(result));
     *     Verify.assertContainsAll(result, 1, 2, 3);
     * 
*/ void forEachKey(Procedure procedure); /** * Calls the {@code procedure} with each key-value pair of the map. *
     *     final Collection<String> collection = new ArrayList<String>();
     *     MutableMap<Integer, String> map = this.newMapWithKeysValues(1, "One", 2, "Two", 3, "Three");
     *     map.forEachKeyValue(new Procedure2<Integer, String>()
     *     {
     *         public void value(final Integer key, final String value)
     *         {
     *             collection.add(String.valueOf(key) + value);
     *         }
     *     });
     *     Verify.assertContainsAll(collection, "1One", "2Two", "3Three");
     * 
*/ void forEachKeyValue(Procedure2 procedure); /** * Return the MapIterable that is obtained by flipping the direction of this map and making the associations * from value to key. *
     *     MapIterable map = this.newMapWithKeysValues(1, "1", 2, "2", 3, "3");
     *     MapIterable result = map.flipUniqueValues();
     *     Assert.assertTrue(result.equals(UnifiedMap.newWithKeysValues("1", 1, "2", 2, "3", 3)));
     * 
* * @throws IllegalStateException if the MapIterable contains duplicate values. * @since 5.0 */ MapIterable flipUniqueValues(); /** * Return the value in the Map that corresponds to the specified key, or if there is no value at the key, return the * result of evaluating the specified Function0. */ V getIfAbsent(K key, Function0 function); /** * Return the value in the Map that corresponds to the specified key, or if there is no value at the key, return {@code value}. */ V getIfAbsentValue(K key, V value); /** * Return the value in the Map that corresponds to the specified key, or if there is no value at the key, return the * result of evaluating the specified function and parameter. */

V getIfAbsentWith(K key, Function function, P parameter); /** * If there is a value in the Map that corresponds to the specified key return the result of applying the specified * Function on the value, otherwise return null. */ A ifPresentApply(K key, Function function); /** * Returns an unmodifiable lazy iterable wrapped around the keySet for the map */ RichIterable keysView(); /** * Returns an unmodifiable lazy iterable wrapped around the values for the map */ RichIterable valuesView(); /** * Returns an unmodifiable lazy iterable of key/value pairs wrapped around the entrySet for the map */ RichIterable> keyValuesView(); /** * Given a map from Domain -> Range return a multimap from Range -> Domain. We chose the name 'flip' * rather than 'invert' or 'transpose' since this method does not have the property of applying twice * returns the original. *

* Since the keys in the input are unique, the values in the output are unique, so the return type should * be a SetMultimap. However since SetMultimap and SortedSetMultimap don't inherit from one another, SetMultimap * here does not allow SortedMapIterable to have a SortedSetMultimap return. Thus we compromise and call this * Multimap, even though all implementations will be a SetMultimap or SortedSetMultimap. */ Multimap flip(); /** * For each key and value of the map the predicate is evaluated, if the result of the evaluation is true, * that key and value are returned in a new map. *

*

e.g.
     * peopleByCity.select(new Predicate2<City, Person>()
     * {
     *     public boolean accept(City city, Person person)
     *     {
     *         return city.getName().equals("Anytown") && person.getLastName().equals("Smith");
     *     }
     * });
     * 
*/ MapIterable select(Predicate2 predicate); /** * For each key and value of the map the function is evaluated. The results of these evaluations are returned in * a new map. The map returned will use the values projected from the function rather than the original values. *

*

e.g.
     * peopleByCity.collectValues(new Function2<City, Person, String>()
     * {
     *     public String value(City city, Person person)
     *     {
     *         return person.getFirstName() + " " + person.getLastName();
     *     }
     * });
     * 
*/ MapIterable collectValues(Function2 function); /** * For each key and value of the map the function is evaluated. The results of these evaluations are returned in * a new map. The map returned will use the values projected from the function rather than the original values. *

*

e.g.
     * peopleByCity.collect(new Function2<City, Person, String>()
     * {
     *     public String value(City city, Person person)
     *     {
     *         return Pair.of(city.getCountry(), person.getAddress().getCity());
     *     }
     * });
     * 
*/ MapIterable collect(Function2> function); /** * For each key and value of the map the predicate is evaluated, if the result of the evaluation is false, * that key and value are returned in a new map. *

*

e.g.
     * peopleByCity.reject(new Predicate2<City, Person>()
     * {
     *     public boolean accept(City city, Person person)
     *     {
     *         return city.getName().equals("Anytown") && person.getLastName().equals("Smith");
     *     }
     * });
     * 
*/ MapIterable reject(Predicate2 predicate); /** * Return the first key and value of the map for which the predicate evaluates to true when they are given * as arguments. The predicate will only be evaluated until such pair is found or until all of the keys and * values of the map have been used as arguments. That is, there may be keys and values of the map that are * never used as arguments to the predicate. The result is null if predicate does not evaluate to true for * any key/value combination. *

*

e.g.
     * peopleByCity.detect(new Predicate2<City, Person>()
     * {
     *     public boolean accept(City city, Person person)
     *     {
     *         return city.getName().equals("Anytown") && person.getLastName().equals("Smith");
     *     }
     * });
     * 
*/ Pair detect(Predicate2 predicate); /** * Follows the same general contract as {@link Map#equals(Object)}. */ @Override boolean equals(Object o); /** * Follows the same general contract as {@link Map#hashCode()}. */ @Override int hashCode(); /** * Returns a string representation of this MapIterable. The string representation consists of a list of the * map's key-value pairs in the order they are returned by its iterator. The key and value in each key-value pair are separated * by a colon (":") and each pair is enclosed in square brackets ("[]"). Adjacent key-value pairs * are separated by the characters ", " (comma and space). Keys and values are converted to strings as by * {@link String#valueOf(Object)}. * * @return a string representation of this MapIterable */ String toString(); } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/map/MutableMap.java000066400000000000000000000365001234315411400321120ustar00rootroot00000000000000/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.map; import java.util.Map; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.collection.MutableCollection; import com.gs.collections.api.collection.primitive.MutableBooleanCollection; import com.gs.collections.api.collection.primitive.MutableByteCollection; import com.gs.collections.api.collection.primitive.MutableCharCollection; import com.gs.collections.api.collection.primitive.MutableDoubleCollection; import com.gs.collections.api.collection.primitive.MutableFloatCollection; import com.gs.collections.api.collection.primitive.MutableIntCollection; import com.gs.collections.api.collection.primitive.MutableLongCollection; import com.gs.collections.api.collection.primitive.MutableShortCollection; import com.gs.collections.api.multimap.MutableMultimap; import com.gs.collections.api.multimap.set.MutableSetMultimap; import com.gs.collections.api.partition.PartitionMutableCollection; import com.gs.collections.api.tuple.Pair; /** * A MutableMap is similar to a JCF Map but adds additional useful internal iterator methods. The MutableMap interface * additionally implements some of the methods in the Smalltalk Dictionary protocol. */ public interface MutableMap extends UnsortedMapIterable, Map, Cloneable { /** * Creates a new instance of the same type, using the default capacity and growth parameters. */ MutableMap newEmpty(); /** * Adds all the entries derived from {@code collection} to {@code this}. The key and value for each entry * is determined by applying the {@code keyFunction} and {@code valueFunction} to each item in * {@code collection}. Any entry in {@code map} that has the same key as an entry in {@code this} * will have it's value replaced by that in {@code map}. */ MutableMap collectKeysAndValues( Iterable iterable, Function keyFunction, Function valueFunction); /** * Remove an entry from the map at the specified {@code key}. * * @return The value removed from entry at key, or null if not found. * @see #remove(Object) */ V removeKey(K key); /** * Get and return the value in the Map at the specified key. Alternatively, if there is no value in the map at the key, * return the result of evaluating the specified Function0, and put that value in the map at the specified key. */ V getIfAbsentPut(K key, Function0 function); /** * Get and return the value in the Map at the specified key. Alternatively, if there is no value in the map at the key, * return the specified value, and put that value in the map at the specified key. * * @since 5.0 */ V getIfAbsentPut(K key, V value); /** * Get and return the value in the Map at the specified key. Alternatively, if there is no value in the map for that key * return the result of evaluating the specified Function using the specified key, and put that value in the * map at the specified key. */ V getIfAbsentPutWithKey(K key, Function function); /** * Get and return the value in the Map at the specified key. Alternatively, if there is no value in the map for that key * return the result of evaluating the specified Function using the specified parameter, and put that value in the * map at the specified key. */

V getIfAbsentPutWith(K key, Function function, P parameter); MutableMap clone(); /** * Returns an unmodifiable view of this map. This method allows modules to provide users with "read-only" access to * internal maps. Any query operations on the returned map that "read through" to this map and attempt to modify the * returned map, whether direct or via its iterator, result in an {@link UnsupportedOperationException}. * The returned map will be Serializable if this map is Serializable. * * @return an unmodifiable view of this map. */ MutableMap asUnmodifiable(); /** * Returns an immutable copy of this map. If the map is immutable, it returns itself. *

* The returned map will be Serializable if this map is Serializable. */ ImmutableMap toImmutable(); /** * Returns a synchronized (thread-safe) map backed by the specified map. In order to guarantee serial access, it is * critical that all access to the backing map is accomplished through the returned map.

*

* It is imperative that the user manually synchronize on the returned map when iterating over any of its collection * views: *

     *  MutableMap map = myMutableMap.asSynchronized();
     *      ...
     *  Set set = map.keySet();  // Needn't be in synchronized block
     *      ...
     *  synchronized(map)
     *  {  // Synchronizing on map, not set!
     *      Iterator i = s.iterator(); // Must be in synchronized block
     *      while (i.hasNext())
     *          foo(i.next());
     *  }
     * 
* Failure to follow this advice may result in non-deterministic behavior. *

* The preferred way of iterating over a synchronized collection is to use the collection.forEach() method which is * properly synchronized internally. *

     *  MutableMap map = myMutableMap.asSynchronized();
     *      ...
     *  Set set = map.keySet();  // Needn't be in synchronized block
     *     ...
     *  Iterate.forEach(set, new Procedure()
     *  {
     *      public void value(Object each)
     *      {
     *          ...
     *      }
     *  });
     * 
*

*

The returned map will be serializable if the specified map is serializable. */ MutableMap asSynchronized(); MutableSetMultimap flip(); MutableMap select(Predicate2 predicate); MutableMap collectValues(Function2 function); MutableMap collect(Function2> function); MutableMap reject(Predicate2 predicate); MutableCollection collect(Function function); MutableBooleanCollection collectBoolean(BooleanFunction booleanFunction); MutableByteCollection collectByte(ByteFunction byteFunction); MutableCharCollection collectChar(CharFunction charFunction); MutableDoubleCollection collectDouble(DoubleFunction doubleFunction); MutableFloatCollection collectFloat(FloatFunction floatFunction); MutableIntCollection collectInt(IntFunction intFunction); MutableLongCollection collectLong(LongFunction longFunction); MutableShortCollection collectShort(ShortFunction shortFunction); MutableCollection collectIf(Predicate predicate, Function function); MutableCollection flatCollect(Function> function); MutableCollection reject(Predicate predicate); MutableCollection select(Predicate predicate); PartitionMutableCollection partition(Predicate predicate);

PartitionMutableCollection partitionWith(Predicate2 predicate, P parameter); MutableCollection selectInstancesOf(Class clazz); MutableCollection> zip(Iterable that); MutableCollection> zipWithIndex(); MutableMap flipUniqueValues(); /** * This method allows mutable map the ability to add an element in the form of Pair. * * @see #put(Object, Object) */ V add(Pair keyValuePair); /** * This method allows mutable, fixed size, and immutable maps the ability to add elements to their existing * elements. In order to support fixed size maps, a new instance of a map would have to be returned including the * keys and values of the original plus the additional key and value. In the case of mutable maps, the original map * is modified and then returned. In order to use this method properly with mutable and fixed size maps the * following approach must be taken: *

*

     * map = map.withKeyValue("new key", "new value");
     * 
* In the case of FixedSizeMap, a new instance will be returned by withKeyValue, and any variables that * previously referenced the original map will need to be redirected to reference the new instance. In the case * of a FastMap or UnifiedMap, you will be replacing the reference to map with map, since FastMap and UnifiedMap * will both return "this" after calling put on themselves. * * @see #put(Object, Object) */ MutableMap withKeyValue(K key, V value); /** * This method allows mutable, fixed size, and immutable maps the ability to add elements to their existing * elements. In order to support fixed size maps, a new instance of a map would have to be returned including the * keys and values of the original plus all of the additional keys and values. In the case of mutable maps, the * original map is modified and then returned. In order to use this method properly with mutable and fixed size * maps the following approach must be taken: *

*

     * map = map.withAllKeyValues(FastList.newListWith(PairImpl.of("new key", "new value")));
     * 
* In the case of FixedSizeMap, a new instance will be returned by withAllKeyValues, and any variables that * previously referenced the original map will need to be redirected to reference the new instance. In the case * of a FastMap or UnifiedMap, you will be replacing the reference to map with map, since FastMap and UnifiedMap * will both return "this" after calling put on themselves. * * @see #put(Object, Object) */ MutableMap withAllKeyValues(Iterable> keyValues); /** * Convenience var-args version of withAllKeyValues * * @see #withAllKeyValues(Iterable) */ MutableMap withAllKeyValueArguments(Pair... keyValuePairs); /** * This method allows mutable, fixed size, and immutable maps the ability to remove elements from their existing * elements. In order to support fixed size maps, a new instance of a map would have to be returned including the * keys and values of the original minus the key and value to be removed. In the case of mutable maps, the original * map is modified and then returned. In order to use this method properly with mutable and fixed size maps the * following approach must be taken: *

*

     * map = map.withoutKey("key");
     * 
* In the case of FixedSizeMap, a new instance will be returned by withoutKey, and any variables that previously * referenced the original map will need to be redirected to reference the new instance. In the case of a FastMap * or UnifiedMap, you will be replacing the reference to map with map, since FastMap and UnifiedMap will both return * "this" after calling remove on themselves. * * @see #remove(Object) */ MutableMap withoutKey(K key); /** * This method allows mutable, fixed size, and immutable maps the ability to remove elements from their existing * elements. In order to support fixed size maps, a new instance of a map would have to be returned including the * keys and values of the original minus all of the keys and values to be removed. In the case of mutable maps, the * original map is modified and then returned. In order to use this method properly with mutable and fixed size * maps the following approach must be taken: *

*

     * map = map.withoutAllKeys(FastList.newListWith("key1", "key2"));
     * 
* In the case of FixedSizeMap, a new instance will be returned by withoutAllKeys, and any variables that previously * referenced the original map will need to be redirected to reference the new instance. In the case of a FastMap * or UnifiedMap, you will be replacing the reference to map with map, since FastMap and UnifiedMap will both return * "this" after calling remove on themselves. * * @see #remove(Object) */ MutableMap withoutAllKeys(Iterable keys); MutableMultimap groupBy(Function function); MutableMultimap groupByEach(Function> function); MutableMap groupByUniqueKey(Function function); MutableMap aggregateInPlaceBy( Function groupBy, Function0 zeroValueFactory, Procedure2 mutatingAggregator); MutableMap aggregateBy( Function groupBy, Function0 zeroValueFactory, Function2 nonMutatingAggregator); /** * Looks up the value associated with {@code key}, applies the {@code function} to it, and replaces the value. If there * is no value associated with {@code key}, starts it off with a value supplied by {@code factory}. */ V updateValue(K key, Function0 factory, Function function); /** * Same as {@link #updateValue(Object, Function0, Function)} with a Function2 and specified parameter which is * passed to the function. */

V updateValueWith(K key, Function0 factory, Function2 function, P parameter); } UnsortedMapIterable.java000066400000000000000000000030531234315411400337120ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/map/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.map; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.multimap.set.SetMultimap; import com.gs.collections.api.tuple.Pair; /** * An iterable Map whose elements are unsorted. */ public interface UnsortedMapIterable extends MapIterable { SetMultimap flip(); UnsortedMapIterable select(Predicate2 predicate); UnsortedMapIterable reject(Predicate2 predicate); UnsortedMapIterable collectValues(Function2 function); UnsortedMapIterable collect(Function2> function); /** * Converts the UnsortedMapIterable to an immutable implementation. Returns this for immutable maps. * * @since 5.0 */ ImmutableMap toImmutable(); } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/map/package-info.java000066400000000000000000000034441234315411400324100ustar00rootroot00000000000000/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains interfaces for map API which enhance the performance and functionality of {@link java.util.Map} *

* This package contains the following interfaces: *

    *
  • * {@link com.gs.collections.api.map.MapIterable} - a Read-only Map API, with the minor exception inherited from {@link java.lang.Iterable}. *
  • *
  • * {@link com.gs.collections.api.map.MutableMap} - an implementation of a JCF Map which provides methods matching the Smalltalk Collection protocol. *
  • *
  • * {@link com.gs.collections.api.map.ImmutableMap} - the non-modifiable equivalent interface to {@link com.gs.collections.api.map.MutableMap}. *
  • *
  • * {@link com.gs.collections.api.map.FixedSizeMap} - a map that may be mutated, but cannot grow or shrink in size. *
  • *
  • * {@link com.gs.collections.api.map.ConcurrentMutableMap} - provides an API which combines and supports both MutableMap and ConcurrentMap. *
  • *
  • * {@link com.gs.collections.api.map.UnsortedMapIterable} - a map whose elements are unsorted. *
  • *
*

*/ package com.gs.collections.api.map; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/map/primitive/000077500000000000000000000000001234315411400312245ustar00rootroot00000000000000MutablePrimitiveObjectMap.java000066400000000000000000000113221234315411400370560ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/map/primitive/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.map.primitive; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.collection.MutableCollection; import com.gs.collections.api.collection.primitive.MutableBooleanCollection; import com.gs.collections.api.collection.primitive.MutableByteCollection; import com.gs.collections.api.collection.primitive.MutableCharCollection; import com.gs.collections.api.collection.primitive.MutableDoubleCollection; import com.gs.collections.api.collection.primitive.MutableFloatCollection; import com.gs.collections.api.collection.primitive.MutableIntCollection; import com.gs.collections.api.collection.primitive.MutableLongCollection; import com.gs.collections.api.collection.primitive.MutableShortCollection; import com.gs.collections.api.map.MutableMap; import com.gs.collections.api.multimap.MutableMultimap; import com.gs.collections.api.partition.PartitionMutableCollection; import com.gs.collections.api.tuple.Pair; public interface MutablePrimitiveObjectMap { void clear(); MutableMap aggregateInPlaceBy(Function groupBy, Function0 zeroValueFactory, Procedure2 mutatingAggregator); MutableMap aggregateBy(Function groupBy, Function0 zeroValueFactory, Function2 nonMutatingAggregator); MutableMultimap groupByEach(Function> function); MutableMultimap groupBy(Function function); MutableMap groupByUniqueKey(Function function); MutableCollection collectIf(Predicate predicate, Function function); MutableCollection collect(Function function); MutableBooleanCollection collectBoolean(BooleanFunction booleanFunction); MutableByteCollection collectByte(ByteFunction byteFunction); MutableCharCollection collectChar(CharFunction charFunction); MutableDoubleCollection collectDouble(DoubleFunction doubleFunction); MutableFloatCollection collectFloat(FloatFunction floatFunction); MutableIntCollection collectInt(IntFunction intFunction); MutableLongCollection collectLong(LongFunction longFunction); MutableShortCollection collectShort(ShortFunction shortFunction); MutableCollection collectWith(Function2 function, P parameter); MutableCollection selectInstancesOf(Class clazz); MutableCollection select(Predicate predicate);

MutableCollection selectWith(Predicate2 predicate, P parameter); MutableCollection reject(Predicate predicate);

MutableCollection rejectWith(Predicate2 predicate, P parameter); PartitionMutableCollection partition(Predicate predicate);

PartitionMutableCollection partitionWith(Predicate2 predicate, P parameter); MutableCollection> zip(Iterable that); MutableCollection> zipWithIndex(); } package-info.java000066400000000000000000000016641234315411400343430ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/map/primitive/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains API for primitive to primitive maps, primitive to object maps and object to primitive maps with mutable and immutable variants. *

* A primitive map is similar to a {@link com.gs.collections.api.map.MapIterable}, but is memory-optimized for primitives. *

*/ package com.gs.collections.api.map.primitive; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/map/sorted/000077500000000000000000000000001234315411400305145ustar00rootroot00000000000000ImmutableSortedMap.java000066400000000000000000000104031234315411400350340ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/map/sorted/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.map.sorted; import java.util.SortedMap; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.list.ImmutableList; import com.gs.collections.api.map.ImmutableMap; import com.gs.collections.api.multimap.list.ImmutableListMultimap; import com.gs.collections.api.multimap.sortedset.ImmutableSortedSetMultimap; import com.gs.collections.api.partition.list.PartitionImmutableList; import com.gs.collections.api.tuple.Pair; import net.jcip.annotations.Immutable; /** * An ImmutableSortedMap is different than a JCF SortedMap in that it has no mutating methods, but it shares * the read-only protocol of a SortedMap. */ @Immutable public interface ImmutableSortedMap extends SortedMapIterable { SortedMap castToSortedMap(); ImmutableSortedSetMultimap flip(); ImmutableSortedMap newWithKeyValue(K key, V value); ImmutableSortedMap newWithAllKeyValues(Iterable> keyValues); ImmutableSortedMap newWithAllKeyValueArguments(Pair... keyValuePairs); ImmutableSortedMap newWithoutKey(K key); ImmutableSortedMap newWithoutAllKeys(Iterable keys); MutableSortedMap toSortedMap(); ImmutableMap flipUniqueValues(); ImmutableSortedMap select(Predicate2 predicate); ImmutableMap collect(Function2> function); ImmutableSortedMap reject(Predicate2 predicate); PartitionImmutableList partition(Predicate predicate); ImmutableSortedMap collectValues(Function2 function); ImmutableList select(Predicate predicate);

ImmutableList selectWith(Predicate2 predicate, P parameter); ImmutableList reject(Predicate predicate);

ImmutableList rejectWith(Predicate2 predicate, P parameter); ImmutableList selectInstancesOf(Class clazz); ImmutableList collect(Function function); ImmutableList collectWith(Function2 function, P parameter); ImmutableList collectIf( Predicate predicate, Function function); ImmutableList flatCollect(Function> function); ImmutableList> zip(Iterable that); ImmutableList> zipWithIndex(); ImmutableListMultimap groupBy(Function function); ImmutableListMultimap groupByEach(Function> function); ImmutableMap groupByUniqueKey(Function function); ImmutableMap aggregateInPlaceBy( Function groupBy, Function0 zeroValueFactory, Procedure2 mutatingAggregator); ImmutableMap aggregateBy( Function groupBy, Function0 zeroValueFactory, Function2 nonMutatingAggregator); } MutableSortedMap.java000066400000000000000000000251021234315411400345100ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/map/sorted/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.map.sorted; import java.util.SortedMap; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.collection.MutableCollection; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.list.primitive.MutableBooleanList; import com.gs.collections.api.list.primitive.MutableByteList; import com.gs.collections.api.list.primitive.MutableCharList; import com.gs.collections.api.list.primitive.MutableDoubleList; import com.gs.collections.api.list.primitive.MutableFloatList; import com.gs.collections.api.list.primitive.MutableIntList; import com.gs.collections.api.list.primitive.MutableLongList; import com.gs.collections.api.list.primitive.MutableShortList; import com.gs.collections.api.map.MutableMap; import com.gs.collections.api.multimap.list.MutableListMultimap; import com.gs.collections.api.multimap.sortedset.MutableSortedSetMultimap; import com.gs.collections.api.partition.list.PartitionMutableList; import com.gs.collections.api.set.MutableSet; import com.gs.collections.api.tuple.Pair; /** * A MutableSortedMap is similar to a JCF Map but adds additional useful internal iterator methods. * The MutableSortedMap interface additionally implements some of the methods in the Smalltalk Dictionary protocol. */ public interface MutableSortedMap extends SortedMapIterable, SortedMap, Cloneable { /** * Creates a new instance of the same type with the same internal Comparator. */ MutableSortedMap newEmpty(); /** * Adds all the entries derived from {@code iterable} to {@code this}. * The key and value for each entry is determined by applying the {@code keyFunction} and {@code valueFunction} to each item in {@code collection}. * Any entry in {@code map} that has the same key as an entry in {@code this} will have it's value replaced by that in {@code map}. */ MutableSortedMap collectKeysAndValues( Iterable iterable, Function keyFunction, Function valueFunction); /** * Remove an entry from the map at the specified {@code key}. * * @return The value removed from entry at key, or null if not found. * @see #remove(Object) */ V removeKey(K key); /** * Return the value in the Map that corresponds to the specified key, or if there is no value * at the key, return the result of evaluating the specified Function0, and put that value in the * map at the specified key. */ V getIfAbsentPut(K key, Function0 function); /** * Get and return the value in the Map at the specified key. Alternatively, if there is no value in the map for that key * return the result of evaluating the specified Function using the specified key, and put that value in the * map at the specified key. */ V getIfAbsentPutWithKey(K key, Function function); /** * Return the value in the Map that corresponds to the specified key, or if there is no value * at the key, return the result of evaluating the specified one argument Function * using the specified parameter, and put that value in the map at the specified key. */

V getIfAbsentPutWith(K key, Function function, P parameter); MutableSortedMap with(Pair... pairs); /** * Returns an unmodifiable view of this map. * This method allows modules to provide users with "read-only" access to internal maps. * Any query operations on the returned map that "read through" to this map and attempt * to modify the returned map, whether direct or via its iterator, result in an * {@link UnsupportedOperationException}. *

* The returned map will be Serializable if this map is Serializable. * * @return an unmodifiable view of this map. */ MutableSortedMap asUnmodifiable(); /** * Returns an immutable copy of this map. * If the map is immutable, it returns itself. *

* The returned map will be Serializable if this map is Serializable. */ ImmutableSortedMap toImmutable(); /** * Returns a synchronized (thread-safe) map backed by the specified * map. In order to guarantee serial access, it is critical that * all access to the backing map is accomplished * through the returned map.

*

* It is imperative that the user manually synchronize on the returned * map when iterating over any of its collection views: *

     *  MutableMap map = myMutableMap.asSynchronized();
     *      ...
     *  Set set = map.keySet();  // Needn't be in synchronized block
     *      ...
     *  synchronized(map)
     *  {  // Synchronizing on map, not set!
     *      Iterator i = s.iterator(); // Must be in synchronized block
     *      while (i.hasNext())
     *          foo(i.next());
     *  }
     * 
* Failure to follow this advice may result in non-deterministic behavior. *

* The preferred way of iterating over a synchronized collection is to use the collection.forEach() * method which is properly synchronized internally. *

     *  MutableMap map = myMutableMap.asSynchronized();
     *      ...
     *  Set set = map.keySet();  // Needn't be in synchronized block
     *     ...
     *  Iterate.forEach(set, new Procedure()
     *  {
     *      public void value(Object each)
     *      {
     *          ...
     *      }
     *  });
     * 
*

*

The returned map will be serializable if the specified map is * serializable. */ MutableSortedMap asSynchronized(); MutableSortedSetMultimap flip(); MutableSortedMap select(Predicate2 predicate); MutableSortedMap reject(Predicate2 predicate); MutableMap collect(Function2> function); MutableSortedMap collectValues(Function2 function); MutableList collect(Function function); MutableBooleanList collectBoolean(BooleanFunction booleanFunction); MutableByteList collectByte(ByteFunction byteFunction); MutableCharList collectChar(CharFunction charFunction); MutableDoubleList collectDouble(DoubleFunction doubleFunction); MutableFloatList collectFloat(FloatFunction floatFunction); MutableIntList collectInt(IntFunction intFunction); MutableLongList collectLong(LongFunction longFunction); MutableShortList collectShort(ShortFunction shortFunction); MutableList collectWith(Function2 function, P parameter); MutableList collectIf(Predicate predicate, Function function); MutableList flatCollect(Function> function); MutableList select(Predicate predicate);

MutableList selectWith(Predicate2 predicate, P parameter); MutableList reject(Predicate predicate);

MutableList rejectWith(Predicate2 predicate, P parameter); PartitionMutableList partition(Predicate predicate);

PartitionMutableList partitionWith(Predicate2 predicate, P parameter); MutableList selectInstancesOf(Class clazz); MutableList> zip(Iterable that); MutableList> zipWithIndex(); MutableSet> entrySet(); /** * The underlying set for the keys is sorted in ascending order according to their natural ordering or a custom comparator. * However, Java 5 TreeMap returns a keySet that does not inherit from SortedSet therefore we have decided to * return the keySet simply as a MutableSet to maintain Java 5 compatibility. */ //todo: Change return type to MutableSortedSet when we move to Java 6 MutableSet keySet(); MutableSortedMap headMap(K toKey); MutableSortedMap tailMap(K fromKey); MutableSortedMap subMap(K fromKey, K toKey); MutableCollection values(); MutableSortedMap clone(); MutableListMultimap groupBy(Function function); MutableListMultimap groupByEach(Function> function); MutableMap groupByUniqueKey(Function function); MutableMap aggregateInPlaceBy( Function groupBy, Function0 zeroValueFactory, Procedure2 mutatingAggregator); MutableMap aggregateBy( Function groupBy, Function0 zeroValueFactory, Function2 nonMutatingAggregator); } SortedMapIterable.java000066400000000000000000000050641234315411400346530ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/map/sorted/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.map.sorted; import java.util.Comparator; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.list.ListIterable; import com.gs.collections.api.map.MapIterable; import com.gs.collections.api.multimap.list.ListMultimap; import com.gs.collections.api.multimap.sortedset.SortedSetMultimap; import com.gs.collections.api.partition.list.PartitionList; import com.gs.collections.api.tuple.Pair; /** * An iterable Map whose elements are sorted. */ public interface SortedMapIterable extends MapIterable { Comparator comparator(); SortedSetMultimap flip(); SortedMapIterable select(Predicate2 predicate); SortedMapIterable reject(Predicate2 predicate); SortedMapIterable collectValues(Function2 function); ListIterable select(Predicate predicate);

ListIterable selectWith(Predicate2 predicate, P parameter); ListIterable reject(Predicate predicate);

ListIterable rejectWith(Predicate2 predicate, P parameter); PartitionList partition(Predicate predicate); ListIterable selectInstancesOf(Class clazz); ListIterable> zip(Iterable that); ListIterable> zipWithIndex(); ListMultimap groupBy(Function function); ListMultimap groupByEach(Function> function); /** * Converts the SortedMapIterable to an immutable implementation. Returns this for immutable maps. * * @since 5.0 */ ImmutableSortedMap toImmutable(); } package-info.java000066400000000000000000000026361234315411400336330ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/map/sorted/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains mutable and immutable sorted map interfaces. *

* A sorted map is a map which contains elements in sorted order. It allows for faster retrievals. *

*

* This package contains 3 interfaces: *

    *
  • * {@link com.gs.collections.api.map.sorted.MutableSortedMap} - an implementation of a JCF Map which provides methods matching the Smalltalk Collection protocol. *
  • *
  • * {@link com.gs.collections.api.map.sorted.ImmutableSortedMap} - the non-mutable equivalent of {@link com.gs.collections.api.map.sorted.MutableSortedMap}. *
  • *
  • * {@link com.gs.collections.api.map.sorted.SortedMapIterable} - a map which contains elements in sorted order. *
  • *
*

*/ package com.gs.collections.api.map.sorted; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/000077500000000000000000000000001234315411400302675ustar00rootroot00000000000000ImmutableMultimap.java000066400000000000000000000021611234315411400345030ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.multimap; import com.gs.collections.api.collection.ImmutableCollection; /** * @since 1.0 */ public interface ImmutableMultimap extends Multimap { ImmutableMultimap newEmpty(); ImmutableCollection get(K key); ImmutableMultimap newWith(K key, V value); ImmutableMultimap newWithout(Object key, Object value); ImmutableMultimap newWithAll(K key, Iterable values); ImmutableMultimap newWithoutAll(Object key); } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/Multimap.java000066400000000000000000000172601234315411400327300ustar00rootroot00000000000000/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.multimap; import java.util.Collection; import com.gs.collections.api.RichIterable; import com.gs.collections.api.bag.Bag; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.map.MutableMap; import com.gs.collections.api.tuple.Pair; /** * This collection is a type of {@code Map} that can associate multiple values for keys. *

*

Unlike {@code Map} however, this interface is read-only so the results of access methods such as {@link * #get(Object)} return a view onto the values associated with that key. The {@link MutableMultimap} subinterface * provides methods to mutate the collection. *

*

The advantages to using this container over a {@code Map>} is that all of the handling of the * value collection can be done automatically. It also allows implementations to further specialize in how duplicate * values will be handled. Value collections with list semantics would allow duplicate values for a key, while those * implementing set semantics would not. *

*

Internal iteration methods for keys and values (singly - {@link #forEachKey(Procedure)}, {@link * #forEachValue(Procedure)}, and together - {@link #forEachKeyValue(Procedure2)}) are provided to allow flexible * browsing of the collection's contents. Similarly, views also are provided for keys ({@link #keysView()}), values * ({@link #valuesView()}) and the combination thereof ({@link #keyValuePairsView()}, {@link * #keyMultiValuePairsView()}). *

* * @param the type of keys used * @param the type of mapped values * @since 1.0 */ @SuppressWarnings("JavaDoc") public interface Multimap { /** * Creates a new instance of the same implementation type, using the default capacity and growth parameters. */ Multimap newEmpty(); /** * Returns {@code true} if there are no entries. */ boolean isEmpty(); /** * Returns {@code true} if there is at least one entry. */ boolean notEmpty(); /** * Calls the procedure with each value. *

* Given a Multimap with the contents: *

* {@code { "key1" : ["val1", "val2", "val2"], "key2" : ["val3"] }} *

* The given procedure would be invoked with the parameters: *

* {@code [ "val1", "val2", "val2", "val3" ]} */ void forEachValue(Procedure procedure); /** * Calls the {@code procedure} with each key. *

* Given a Multimap with the contents: *

* {@code { "key1" : ["val1", "val2", "val2"], "key2" : ["val3"] }} *

* The given procedure would be invoked with the parameters: *

* {@code [ "key1", "key2" ]} */ void forEachKey(Procedure procedure); /** * Calls the {@code procedure} with each key-value pair. *

* Given a Multimap with the contents: *

* {@code { "key1" : ["val1", "val2", "val2"], "key2" : ["val3"] }} *

* The given procedure would be invoked with the parameters: *

* {@code [ ["key1", "val1"], ["key1", "val2"], ["key1", "val2"], ["key2", "val3"] ]} */ void forEachKeyValue(Procedure2 procedure); /** * Returns the number of key-value entry pairs. *

* This method is implemented with O(1) (constant-time) performance. */ int size(); /** * Returns the number of distinct keys. */ int sizeDistinct(); /** * Returns {@code true} if any values are mapped to the specified key. * * @param key the key to search for */ boolean containsKey(Object key); /** * Returns {@code true} if any key is mapped to the specified value. * * @param value the value to search for */ boolean containsValue(Object value); /** * Returns {@code true} if the specified key-value pair is mapped. * * @param key the key to search for * @param value the value to search for */ boolean containsKeyAndValue(Object key, Object value); /** * Returns a view of all values associated with the given key. *

* If the given key does not exist, an empty {@link RichIterable} is returned. * * @param key the key to search for */ RichIterable get(K key); /** * Returns a lazy view of the unique keys. */ RichIterable keysView(); /** * Returns a {@link Bag} of keys with the count corresponding to the number of mapped values. */ Bag keyBag(); /** * Returns an unmodifiable view of all of the values mapped to each key. */ RichIterable> multiValuesView(); /** * Returns a lazy flattened view of all the values. */ RichIterable valuesView(); /** * Returns a lazy view of the pair of a key and and a lazy view of the values mapped to that key. */ RichIterable>> keyMultiValuePairsView(); /** * Returns a lazy view of all of the key/value pairs. */ RichIterable> keyValuePairsView(); /** * Returns a new {@link MutableMap} of keys from this Multimap to the mapped values as a {@link RichIterable}. */ MutableMap> toMap(); /** * Returns a new {@link MutableMap} of keys from this Multimap to the mapped values as a {@link RichIterable}. * * @param collectionFactory used to create the collections that hold the values and affects the return type */ > MutableMap toMap(Function0 collectionFactory); /** * Compares the specified object with this Multimap for equality. *

* Two Multimaps are equal when their map views (as returned by {@link #toMap}) are also equal. *

*

In general, two Multimaps with identical key-value mappings may or may not be equal, depending on the type of * the collections holding the values. If the backing collections are Sets, then two instances with the same * key-value mappings are equal, but if the backing collections are Lists, equality depends on the ordering of the * values for each key. *

* Any two empty Multimaps are equal, because they both have empty {@link #toMap} views. */ @Override boolean equals(Object obj); /** * Returns the hash code for this Multimap. *

*

The hash code of a Multimap is defined as the hash code of the map view, as returned by {@link #toMap}. */ @Override int hashCode(); /** * Returns a mutable copy of this Multimap. */ MutableMultimap toMutable(); /** * Returns an immutable copy of this Multimap if it is not already immutable. If the Multimap is immutable, * it will return itself. *

* The returned Multimap will be {@code Serializable} if this Multimap is {@code Serializable}. */ ImmutableMultimap toImmutable(); } MutableMultimap.java000066400000000000000000000026061234315411400341610ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.multimap; import com.gs.collections.api.RichIterable; import com.gs.collections.api.collection.MutableCollection; import com.gs.collections.api.tuple.Pair; /** * @since 1.0 */ public interface MutableMultimap extends Multimap { MutableMultimap newEmpty(); MutableCollection get(K key); // Modification Operations boolean put(K key, V value); boolean remove(Object key, Object value); // Bulk Operations boolean putAllPairs(Pair... pairs); boolean putAll(K key, Iterable values); boolean putAll(Multimap multimap); RichIterable replaceValues(K key, Iterable values); RichIterable removeAll(Object key); void clear(); } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/bag/000077500000000000000000000000001234315411400310205ustar00rootroot00000000000000BagMultimap.java000066400000000000000000000015361234315411400340130ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/bag/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.multimap.bag; import com.gs.collections.api.bag.Bag; import com.gs.collections.api.multimap.Multimap; public interface BagMultimap extends Multimap { BagMultimap newEmpty(); Bag get(K key); } ImmutableBagMultimap.java000066400000000000000000000023201234315411400356430ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/bag/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.multimap.bag; import com.gs.collections.api.bag.ImmutableBag; import com.gs.collections.api.multimap.ImmutableMultimap; /** * @since 1.0 */ public interface ImmutableBagMultimap extends UnsortedBagMultimap, ImmutableMultimap { ImmutableBagMultimap newEmpty(); ImmutableBag get(K key); ImmutableBagMultimap newWith(K key, V value); ImmutableBagMultimap newWithout(Object key, Object value); ImmutableBagMultimap newWithAll(K key, Iterable values); ImmutableBagMultimap newWithoutAll(Object key); } MutableBagMultimap.java000066400000000000000000000020521234315411400353170ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/bag/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.multimap.bag; import com.gs.collections.api.bag.MutableBag; import com.gs.collections.api.multimap.MutableMultimap; /** * @since 1.0 */ public interface MutableBagMultimap extends MutableMultimap, UnsortedBagMultimap { MutableBag replaceValues(K key, Iterable values); MutableBag removeAll(Object key); MutableBagMultimap newEmpty(); MutableBag get(K key); } UnsortedBagMultimap.java000066400000000000000000000016421234315411400355350ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/bag/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.multimap.bag; import com.gs.collections.api.bag.UnsortedBag; public interface UnsortedBagMultimap extends BagMultimap { UnsortedBagMultimap newEmpty(); UnsortedBag get(K key); MutableBagMultimap toMutable(); ImmutableBagMultimap toImmutable(); } package-info.java000066400000000000000000000026531234315411400341360ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/bag/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains interfaces for {@link com.gs.collections.api.multimap.bag.BagMultimap}. *

* A BagMultimap is a type of {@link com.gs.collections.api.multimap.Multimap} that stores the values for keys in a {@link com.gs.collections.api.bag.Bag}. *

*

* This package contains 3 interfaces: *

    *
  • * {@link com.gs.collections.api.multimap.bag.BagMultimap} - A Read-only Bag Multimap API. *
  • *
  • * {@link com.gs.collections.api.multimap.bag.MutableBagMultimap} - Modifiable Bag multimap. *
  • *
  • * {@link com.gs.collections.api.multimap.bag.ImmutableBagMultimap} - Non-modifiable equivalent interface to {@link com.gs.collections.api.multimap.bag.MutableBagMultimap}. *
  • *
*

*/ package com.gs.collections.api.multimap.bag; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/list/000077500000000000000000000000001234315411400312425ustar00rootroot00000000000000ImmutableListMultimap.java000066400000000000000000000023231234315411400363120ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/list/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.multimap.list; import com.gs.collections.api.list.ImmutableList; import com.gs.collections.api.multimap.ImmutableMultimap; /** * @since 1.0 */ public interface ImmutableListMultimap extends ListMultimap, ImmutableMultimap { ImmutableListMultimap newEmpty(); ImmutableList get(K key); ImmutableListMultimap newWith(K key, V value); ImmutableListMultimap newWithout(Object key, Object value); ImmutableListMultimap newWithAll(K key, Iterable values); ImmutableListMultimap newWithoutAll(Object key); } ListMultimap.java000066400000000000000000000017741234315411400344630ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/list/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.multimap.list; import com.gs.collections.api.list.ListIterable; import com.gs.collections.api.multimap.ordered.ReversibleIterableMultimap; public interface ListMultimap extends ReversibleIterableMultimap { ListMultimap newEmpty(); ListIterable get(K key); MutableListMultimap toMutable(); ImmutableListMultimap toImmutable(); } MutableListMultimap.java000066400000000000000000000020531234315411400357640ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/list/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.multimap.list; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.multimap.MutableMultimap; /** * @since 1.0 */ public interface MutableListMultimap extends ListMultimap, MutableMultimap { MutableList replaceValues(K key, Iterable values); MutableList removeAll(Object key); MutableListMultimap newEmpty(); MutableList get(K key); } package-info.java000066400000000000000000000027021234315411400343530ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/list/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains interfaces for {@link com.gs.collections.api.multimap.list.ListMultimap}. *

* A ListMultimap is a type of {@link com.gs.collections.api.multimap.Multimap} that stores the values for keys in a {@link com.gs.collections.api.list.MutableList}. *

*

* This package contains 3 interfaces: *

    *
  • * {@link com.gs.collections.api.multimap.list.ListMultimap} - A Read-only List Multimap API. *
  • *
  • * {@link com.gs.collections.api.multimap.list.MutableListMultimap} - Modifiable List multimap. *
  • *
  • * {@link com.gs.collections.api.multimap.list.ImmutableListMultimap} - Non-modifiable equivalent interface to {@link com.gs.collections.api.multimap.list.MutableListMultimap}. *
  • *
*

*/ package com.gs.collections.api.multimap.list; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/ordered/000077500000000000000000000000001234315411400317135ustar00rootroot00000000000000ReversibleIterableMultimap.java000066400000000000000000000016421234315411400377650ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/ordered/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.multimap.ordered; import com.gs.collections.api.multimap.Multimap; import com.gs.collections.api.ordered.ReversibleIterable; public interface ReversibleIterableMultimap extends Multimap { ReversibleIterableMultimap newEmpty(); ReversibleIterable get(K key); } SortedIterableMultimap.java000066400000000000000000000017571234315411400371320ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/ordered/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.multimap.ordered; import java.util.Comparator; import com.gs.collections.api.multimap.Multimap; import com.gs.collections.api.ordered.SortedIterable; /** * @since 5.0 */ public interface SortedIterableMultimap extends Multimap { SortedIterableMultimap newEmpty(); SortedIterable get(K key); Comparator comparator(); } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/package-info.java000066400000000000000000000025111234315411400334550ustar00rootroot00000000000000/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains interfaces for {@link com.gs.collections.api.multimap.Multimap}. *

* A Multimap is a type of {@link java.util.Map} that can associate multiple values for keys. *

*

* This package contains 3 interfaces: *

    *
  • * {@link com.gs.collections.api.multimap.Multimap} - a Read-only Multimap API. *
  • *
  • * {@link com.gs.collections.api.multimap.MutableMultimap} - a modifiable Multimap. *
  • *
  • * {@link com.gs.collections.api.multimap.ImmutableMultimap} - the non-modifiable equivalent interface to {@link com.gs.collections.api.multimap.MutableMultimap}. *
  • *
*

*/ package com.gs.collections.api.multimap; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/set/000077500000000000000000000000001234315411400310625ustar00rootroot00000000000000ImmutableSetMultimap.java000066400000000000000000000023201234315411400357470ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/set/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.multimap.set; import com.gs.collections.api.multimap.ImmutableMultimap; import com.gs.collections.api.set.ImmutableSet; /** * @since 1.0 */ public interface ImmutableSetMultimap extends UnsortedSetMultimap, ImmutableMultimap { ImmutableSet get(K key); ImmutableSetMultimap newEmpty(); ImmutableSetMultimap newWith(K key, V value); ImmutableSetMultimap newWithout(Object key, Object value); ImmutableSetMultimap newWithAll(K key, Iterable values); ImmutableSetMultimap newWithoutAll(Object key); } MutableSetMultimap.java000066400000000000000000000020521234315411400354230ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/set/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.multimap.set; import com.gs.collections.api.multimap.MutableMultimap; import com.gs.collections.api.set.MutableSet; /** * @since 1.0 */ public interface MutableSetMultimap extends UnsortedSetMultimap, MutableMultimap { MutableSet replaceValues(K key, Iterable values); MutableSet removeAll(Object key); MutableSetMultimap newEmpty(); MutableSet get(K key); } SetMultimap.java000066400000000000000000000015561234315411400341210ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/set/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.multimap.set; import com.gs.collections.api.multimap.Multimap; import com.gs.collections.api.set.SetIterable; public interface SetMultimap extends Multimap { SetMultimap newEmpty(); SetIterable get(K key); } UnsortedSetMultimap.java000066400000000000000000000016621234315411400356430ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/set/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.multimap.set; import com.gs.collections.api.set.UnsortedSetIterable; public interface UnsortedSetMultimap extends SetMultimap { UnsortedSetMultimap newEmpty(); UnsortedSetIterable get(K key); MutableSetMultimap toMutable(); ImmutableSetMultimap toImmutable(); } package-info.java000066400000000000000000000026621234315411400342000ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/set/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains interfaces for {@link com.gs.collections.api.multimap.set.SetMultimap}. *

* A SetMultimap is a type of {@link com.gs.collections.api.multimap.Multimap} that stores the values for keys in a {@link com.gs.collections.api.set.MutableSet}. *

*

* This package contains 3 interfaces: *

    *
  • * {@link com.gs.collections.api.multimap.set.SetMultimap} - A Read-only Set Multimap API. *
  • *
  • * {@link com.gs.collections.api.multimap.set.MutableSetMultimap} - Modifiable Set multimap. *
  • *
  • * {@link com.gs.collections.api.multimap.set.ImmutableSetMultimap} - Non-modifiable equivalent interface to {@link com.gs.collections.api.multimap.set.MutableSetMultimap}. *
  • *
*

*/ package com.gs.collections.api.multimap.set; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/sortedbag/000077500000000000000000000000001234315411400322415ustar00rootroot00000000000000ImmutableSortedBagMultimap.java000066400000000000000000000024231234315411400402510ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/sortedbag/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.multimap.sortedbag; import com.gs.collections.api.bag.sorted.ImmutableSortedBag; import com.gs.collections.api.multimap.ImmutableMultimap; /** * @since 4.2 */ public interface ImmutableSortedBagMultimap extends ImmutableMultimap, SortedBagMultimap { ImmutableSortedBag get(K key); ImmutableSortedBagMultimap newEmpty(); ImmutableSortedBagMultimap newWith(K key, V value); ImmutableSortedBagMultimap newWithout(Object key, Object value); ImmutableSortedBagMultimap newWithAll(K key, Iterable values); ImmutableSortedBagMultimap newWithoutAll(Object key); } MutableSortedBagMultimap.java000066400000000000000000000021311234315411400377170ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/sortedbag/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.multimap.sortedbag; import com.gs.collections.api.bag.sorted.MutableSortedBag; import com.gs.collections.api.multimap.MutableMultimap; /** * @since 4.2 */ public interface MutableSortedBagMultimap extends MutableMultimap, SortedBagMultimap { MutableSortedBag replaceValues(K key, Iterable values); MutableSortedBag removeAll(Object key); MutableSortedBagMultimap newEmpty(); MutableSortedBag get(K key); } SortedBagMultimap.java000066400000000000000000000021561234315411400364140ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/sortedbag/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.multimap.sortedbag; import com.gs.collections.api.bag.sorted.SortedBag; import com.gs.collections.api.multimap.bag.BagMultimap; import com.gs.collections.api.multimap.ordered.SortedIterableMultimap; /** * @since 4.2 */ public interface SortedBagMultimap extends BagMultimap, SortedIterableMultimap { SortedBagMultimap newEmpty(); SortedBag get(K key); MutableSortedBagMultimap toMutable(); ImmutableSortedBagMultimap toImmutable(); } package-info.java000066400000000000000000000030251234315411400353510ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/sortedbag/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains interfaces for {@link com.gs.collections.api.multimap.sortedbag.SortedBagMultimap}. *

* A SortedBagMultimap is a type of {@link com.gs.collections.api.multimap.Multimap} that stores the values for keys in a {@link com.gs.collections.api.bag.sorted.MutableSortedBag}. *

*

* This package contains 3 interfaces: *

    *
  • * {@link com.gs.collections.api.multimap.sortedbag.SortedBagMultimap} - A Read-only Sorted Bag Multimap API. *
  • *
  • * {@link com.gs.collections.api.multimap.sortedbag.MutableSortedBagMultimap} - Modifiable Sorted Bag multimap. *
  • *
  • * {@link com.gs.collections.api.multimap.sortedbag.ImmutableSortedBagMultimap} - Non-modifiable equivalent interface to {@link com.gs.collections.api.multimap.sortedbag.MutableSortedBagMultimap}. *
  • *
*

*/ package com.gs.collections.api.multimap.sortedbag; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/sortedset/000077500000000000000000000000001234315411400323035ustar00rootroot00000000000000ImmutableSortedSetMultimap.java000066400000000000000000000024131234315411400403540ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/sortedset/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.multimap.sortedset; import com.gs.collections.api.multimap.ImmutableMultimap; import com.gs.collections.api.set.sorted.ImmutableSortedSet; /** * @since 1.0 */ public interface ImmutableSortedSetMultimap extends SortedSetMultimap, ImmutableMultimap { ImmutableSortedSet get(K key); ImmutableSortedSetMultimap newEmpty(); ImmutableSortedSetMultimap newWith(K key, V value); ImmutableSortedSetMultimap newWithout(Object key, Object value); ImmutableSortedSetMultimap newWithAll(K key, Iterable values); ImmutableSortedSetMultimap newWithoutAll(Object key); } MutableSortedSetMultimap.java000066400000000000000000000021311234315411400400230ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/sortedset/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.multimap.sortedset; import com.gs.collections.api.multimap.MutableMultimap; import com.gs.collections.api.set.sorted.MutableSortedSet; /** * @since 1.0 */ public interface MutableSortedSetMultimap extends MutableMultimap, SortedSetMultimap { MutableSortedSet replaceValues(K key, Iterable values); MutableSortedSet removeAll(Object key); MutableSortedSetMultimap newEmpty(); MutableSortedSet get(K key); } SortedSetMultimap.java000066400000000000000000000021761234315411400365220ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/sortedset/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.multimap.sortedset; import com.gs.collections.api.multimap.ordered.SortedIterableMultimap; import com.gs.collections.api.multimap.set.SetMultimap; import com.gs.collections.api.set.sorted.SortedSetIterable; /** * @since 1.0 */ public interface SortedSetMultimap extends SetMultimap, SortedIterableMultimap { SortedSetMultimap newEmpty(); SortedSetIterable get(K key); MutableSortedSetMultimap toMutable(); ImmutableSortedSetMultimap toImmutable(); } package-info.java000066400000000000000000000030231234315411400354110ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/multimap/sortedset/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains interfaces for {@link com.gs.collections.api.multimap.sortedset.SortedSetMultimap}. *

* A SortedSetMultimap is a type of {@link com.gs.collections.api.multimap.Multimap} that stores the values for keys in a {@link com.gs.collections.api.set.sorted.MutableSortedSet}. *

*

* This package contains 3 interfaces: *

    *
  • * {@link com.gs.collections.api.multimap.sortedset.SortedSetMultimap} - A Read-only SortedSet Multimap API. *
  • *
  • * {@link com.gs.collections.api.multimap.sortedset.MutableSortedSetMultimap} - Modifiable SortedSet multimap. *
  • *
  • * {@link com.gs.collections.api.multimap.sortedset.ImmutableSortedSetMultimap} - Non-modifiable equivalent interface to {@link com.gs.collections.api.multimap.sortedset.MutableSortedSetMultimap}. *
  • *
*

*/ package com.gs.collections.api.multimap.sortedset; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/ordered/000077500000000000000000000000001234315411400300635ustar00rootroot00000000000000ReversibleIterable.java000066400000000000000000000147331234315411400344310ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/ordered/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.ordered; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.RichIterable; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.multimap.ordered.ReversibleIterableMultimap; import com.gs.collections.api.ordered.primitive.ReversibleBooleanIterable; import com.gs.collections.api.ordered.primitive.ReversibleByteIterable; import com.gs.collections.api.ordered.primitive.ReversibleCharIterable; import com.gs.collections.api.ordered.primitive.ReversibleDoubleIterable; import com.gs.collections.api.ordered.primitive.ReversibleFloatIterable; import com.gs.collections.api.ordered.primitive.ReversibleIntIterable; import com.gs.collections.api.ordered.primitive.ReversibleLongIterable; import com.gs.collections.api.ordered.primitive.ReversibleShortIterable; import com.gs.collections.api.partition.ordered.PartitionReversibleIterable; import com.gs.collections.api.stack.MutableStack; import com.gs.collections.api.tuple.Pair; /** * A ReversibleIterable is an ordered iterable that you can iterate over forwards or backwards. Besides being ordered, * it has methods that support efficient iteration from the end, including {@link #asReversed()} and * {@link #reverseForEach(Procedure)}. * * @since 5.0 */ public interface ReversibleIterable extends RichIterable { /** * Evaluates the procedure for each element of the list iterating in reverse order. *

*

e.g.
     * people.reverseForEach(new Procedure()
     * {
     *     public void value(Person person)
     *     {
     *         LOGGER.info(person.getName());
     *     }
     * });
     * 
*/ void reverseForEach(Procedure procedure); /** * Returns a reversed view of this ReversibleIterable. */ LazyIterable asReversed(); /** * Returns the index of the first occurrence of the specified item * in this list, or -1 if this list does not contain the item. */ int indexOf(Object o); /** * Returns the initial elements that satisfy the Predicate. Short circuits at the first element which does not * satisfy the Predicate. */ ReversibleIterable takeWhile(Predicate predicate); /** * Returns the final elements that do not satisfy the Predicate. Short circuits at the first element which does * satisfy the Predicate. */ ReversibleIterable dropWhile(Predicate predicate); /** * Returns a Partition of the initial elements that satisfy the Predicate and the remaining elements. Short circuits at the first element which does * satisfy the Predicate. */ PartitionReversibleIterable partitionWhile(Predicate predicate); /** * Returns a new {@code ReversibleIterable} containing the distinct elements in this iterable. *

* Conceptually similar to {@link #toSet()}.{@link #toList()} but retains the original order. If an element appears * multiple times in this iterable, the first one will be copied into the result. * * @return {@code ReversibleIterable} of distinct elements */ ReversibleIterable distinct(); /** * Converts the ReversibleIterable to a mutable MutableStack implementation. */ MutableStack toStack(); ReversibleIterable select(Predicate predicate);

ReversibleIterable selectWith(Predicate2 predicate, P parameter); ReversibleIterable reject(Predicate predicate);

ReversibleIterable rejectWith(Predicate2 predicate, P parameter); PartitionReversibleIterable partition(Predicate predicate); ReversibleIterable selectInstancesOf(Class clazz); ReversibleIterable collect(Function function); ReversibleIterable collectWith(Function2 function, P parameter); ReversibleIterable collectIf(Predicate predicate, Function function); ReversibleIterable flatCollect(Function> function); ReversibleBooleanIterable collectBoolean(BooleanFunction booleanFunction); ReversibleByteIterable collectByte(ByteFunction byteFunction); ReversibleCharIterable collectChar(CharFunction charFunction); ReversibleDoubleIterable collectDouble(DoubleFunction doubleFunction); ReversibleFloatIterable collectFloat(FloatFunction floatFunction); ReversibleIntIterable collectInt(IntFunction intFunction); ReversibleLongIterable collectLong(LongFunction longFunction); ReversibleShortIterable collectShort(ShortFunction shortFunction); ReversibleIterableMultimap groupBy(Function function); ReversibleIterableMultimap groupByEach(Function> function); ReversibleIterable> zip(Iterable that); ReversibleIterable> zipWithIndex(); } SortedIterable.java000066400000000000000000000113421234315411400335600ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/ordered/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.ordered; import java.util.Comparator; import com.gs.collections.api.RichIterable; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.list.ListIterable; import com.gs.collections.api.multimap.ordered.SortedIterableMultimap; import com.gs.collections.api.partition.ordered.PartitionSortedIterable; import com.gs.collections.api.stack.MutableStack; import com.gs.collections.api.tuple.Pair; /** * A SortedIterable is an ordered iterable where the elements are stored in sorted order defined by a non-strict partial * order relation. The sort order is determined by the Comparator returned by {@link #comparator()} or is the natural * ordering if {@code comparator()} returns {@code null}. Operations that would sort the collection can be faster than * O(n log n). For example {@link #toSortedList()} takes O(n) time. * * @since 5.0 */ public interface SortedIterable extends RichIterable { /** * Returns the comparator used to order the elements in this container, or null if this container uses the natural * ordering of its elements. */ Comparator comparator(); /** * Returns the initial elements that satisfy the Predicate. Short circuits at the first element which does not * satisfy the Predicate. */ SortedIterable takeWhile(Predicate predicate); /** * Returns the final elements that do not satisfy the Predicate. Short circuits at the first element which does * satisfy the Predicate. */ SortedIterable dropWhile(Predicate predicate); /** * Returns a Partition of the initial elements that satisfy the Predicate and the remaining elements. Short circuits at the first element which does * satisfy the Predicate. */ PartitionSortedIterable partitionWhile(Predicate predicate); /** * Returns a new {@code SortedIterable} containing the distinct elements in this iterable. *

* Conceptually similar to {@link #toSet()}.{@link #toList()} but retains the original order. If an element appears * multiple times in this iterable, the first one will be copied into the result. * * @return {@code SortedIterable} of distinct elements */ SortedIterable distinct(); /** * Converts the SortedIterable to a mutable MutableStack implementation. */ MutableStack toStack(); /** * Returns the minimum element out of this container based on the natural order, not the order of this container. * If you want the minimum element based on the order of this container, use {@link #getFirst()}. * * @throws ClassCastException if the elements are not {@link Comparable} * @throws java.util.NoSuchElementException * if the SortedIterable is empty */ T min(); /** * Returns the maximum element out of this container based on the natural order, not the order of this container. * If you want the maximum element based on the order of this container, use {@link #getLast()}. * * @throws ClassCastException if the elements are not {@link Comparable} * @throws java.util.NoSuchElementException * if the SortedIterable is empty */ T max(); SortedIterable select(Predicate predicate);

SortedIterable selectWith(Predicate2 predicate, P parameter); SortedIterable reject(Predicate predicate);

SortedIterable rejectWith(Predicate2 predicate, P parameter); PartitionSortedIterable partition(Predicate predicate); SortedIterable selectInstancesOf(Class clazz); SortedIterableMultimap groupBy(Function function); SortedIterableMultimap groupByEach(Function> function); ListIterable> zip(Iterable that); SortedIterable> zipWithIndex(); } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/package-info.java000066400000000000000000000014641234315411400316330ustar00rootroot00000000000000/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains interfaces for GS Collections API. *

* This package contains interfaces for object collections, primitive collections and lazy iterables. *

*/ package com.gs.collections.api; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/000077500000000000000000000000001234315411400304505ustar00rootroot00000000000000PartitionImmutableCollection.java000066400000000000000000000023031234315411400370570ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.partition; import com.gs.collections.api.collection.ImmutableCollection; /** * A PartitionImmutableCollection is the result of splitting an immutable collection into two immutable collections based * on a Predicate. The results that answer true for the Predicate will be returned from the getSelected() method and the * results that answer false for the predicate will be returned from the getRejected() method. */ public interface PartitionImmutableCollection extends PartitionIterable { ImmutableCollection getSelected(); ImmutableCollection getRejected(); } PartitionIterable.java000066400000000000000000000021301234315411400346510ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.partition; import com.gs.collections.api.RichIterable; /** * A PartitionIterable is the result of splitting an iterable into two iterables based on a Predicate. The results that * answer true for the Predicate will be returned from the getSelected() method and the results that answer false for the * predicate will be returned from the getRejected() method. */ public interface PartitionIterable { RichIterable getSelected(); RichIterable getRejected(); } PartitionMutableCollection.java000066400000000000000000000023471234315411400365410ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.partition; import com.gs.collections.api.collection.MutableCollection; /** * A PartitionMutableCollection is the result of splitting a mutable collection into two mutable collections based on a Predicate. * The results that answer true for the Predicate will be returned from the getSelected() method and the results that answer false * for the predicate will be returned from the getRejected() method. */ public interface PartitionMutableCollection extends PartitionIterable { MutableCollection getSelected(); MutableCollection getRejected(); PartitionImmutableCollection toImmutable(); } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/bag/000077500000000000000000000000001234315411400312015ustar00rootroot00000000000000PartitionBag.java000066400000000000000000000022101234315411400343430ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/bag/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.partition.bag; import com.gs.collections.api.bag.Bag; import com.gs.collections.api.partition.PartitionIterable; /** * A PartitionBag is the result of splitting a bag into two Bags based on a Predicate. The results that answer true for * the Predicate will be returned from the getSelected() method and the results that answer false for the * predicate will be returned from the getRejected() method. */ public interface PartitionBag extends PartitionIterable { Bag getSelected(); Bag getRejected(); } PartitionImmutableBag.java000066400000000000000000000023701234315411400362120ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/bag/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.partition.bag; import com.gs.collections.api.bag.ImmutableBag; import com.gs.collections.api.partition.PartitionImmutableCollection; /** * A PartitionImmutableBag is the result of splitting an immutable bag into two immutable bags based on a Predicate. * The results that answer true for the Predicate will be returned from the getSelected() method and the * results that answer false for the predicate will be returned from the getRejected() method. */ public interface PartitionImmutableBag extends PartitionImmutableCollection, PartitionUnsortedBag { ImmutableBag getSelected(); ImmutableBag getRejected(); } PartitionMutableBag.java000066400000000000000000000024221234315411400356620ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/bag/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.partition.bag; import com.gs.collections.api.bag.MutableBag; import com.gs.collections.api.partition.PartitionMutableCollection; /** * A PartitionMutableBag is the result of splitting a mutable bag into two mutable bags based on a Predicate. * The results that answer true for the Predicate will be returned from the getSelected() method and the results that answer * false for the predicate will be returned from the getRejected() method. */ public interface PartitionMutableBag extends PartitionMutableCollection, PartitionUnsortedBag { MutableBag getSelected(); MutableBag getRejected(); PartitionImmutableBag toImmutable(); } PartitionUnsortedBag.java000066400000000000000000000015001234315411400360700ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/bag/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.partition.bag; import com.gs.collections.api.bag.UnsortedBag; public interface PartitionUnsortedBag extends PartitionBag { UnsortedBag getSelected(); UnsortedBag getRejected(); } package-info.java000066400000000000000000000026371234315411400343210ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/bag/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains interfaces for {@link com.gs.collections.api.partition.bag.PartitionBag}. *

* A PartitionBag is the result of splitting a {@link com.gs.collections.api.bag.Bag} into two bags based on a Predicate. *

*

* This package contains 3 interfaces: *

    *
  • * {@link com.gs.collections.api.partition.bag.PartitionBag} - a read-only PartitionBag API. *
  • *
  • * {@link com.gs.collections.api.partition.bag.PartitionMutableBag} - a modifiable PartitionBag. *
  • *
  • * {@link com.gs.collections.api.partition.bag.PartitionImmutableBag} - the non-modifiable equivalent interface to {@link com.gs.collections.api.partition.bag.PartitionMutableBag}. *
  • *
*

*/ package com.gs.collections.api.partition.bag; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/bag/sorted/000077500000000000000000000000001234315411400325015ustar00rootroot00000000000000PartitionImmutableSortedBag.java000066400000000000000000000025021234315411400406700ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/bag/sorted/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.partition.bag.sorted; import com.gs.collections.api.bag.sorted.ImmutableSortedBag; import com.gs.collections.api.partition.PartitionImmutableCollection; /** * A PartitionImmutableSortedBag is the result of splitting an immutable sorted bag into two immutable sorted bags based * on a Predicate. The results that answer true for the Predicate will be returned from the getSelected() method and the * results that answer false for the predicate will be returned from the getRejected() method. * * @since 4.2 */ public interface PartitionImmutableSortedBag extends PartitionImmutableCollection, PartitionSortedBag { ImmutableSortedBag getSelected(); ImmutableSortedBag getRejected(); } PartitionMutableSortedBag.java000066400000000000000000000020241234315411400403410ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/bag/sorted/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.partition.bag.sorted; import com.gs.collections.api.bag.sorted.MutableSortedBag; import com.gs.collections.api.partition.PartitionMutableCollection; /** * @since 4.2 */ public interface PartitionMutableSortedBag extends PartitionMutableCollection, PartitionSortedBag { MutableSortedBag getSelected(); MutableSortedBag getRejected(); PartitionImmutableSortedBag toImmutable(); } PartitionSortedBag.java000066400000000000000000000017731234315411400370410ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/bag/sorted/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.partition.bag.sorted; import com.gs.collections.api.bag.sorted.SortedBag; import com.gs.collections.api.partition.bag.PartitionBag; import com.gs.collections.api.partition.ordered.PartitionSortedIterable; /** * @since 4.2 */ public interface PartitionSortedBag extends PartitionBag, PartitionSortedIterable { SortedBag getSelected(); SortedBag getRejected(); } package-info.java000066400000000000000000000024001234315411400356050ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/bag/sorted/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains interfaces for {@link com.gs.collections.api.partition.bag.sorted.PartitionSortedBag}. *

* A PartitionSortedBag is the result of splitting a sorted bag into two sorted bags based on a Predicate. *

*

* This package contains the following interfaces: *

    *
  • * {@link com.gs.collections.api.partition.bag.sorted.PartitionSortedBag} - a Read-only PartitionSortedSet API. *
  • *
  • * {@link com.gs.collections.api.partition.bag.sorted.PartitionMutableSortedBag} - a modifiable PartitionSortedSet. *
  • *
*

*/ package com.gs.collections.api.partition.bag.sorted; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/list/000077500000000000000000000000001234315411400314235ustar00rootroot00000000000000PartitionImmutableList.java000066400000000000000000000023721234315411400366600ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/list/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.partition.list; import com.gs.collections.api.list.ImmutableList; import com.gs.collections.api.partition.PartitionImmutableCollection; /** * A PartitionImmutableList is the result of splitting an immutable list into two immutable lists based on a Predicate. * The results that answer true for the Predicate will be returned from the getSelected() method and the results that answer * false for the predicate will be returned from the getRejected() method. */ public interface PartitionImmutableList extends PartitionImmutableCollection, PartitionList { ImmutableList getSelected(); ImmutableList getRejected(); } PartitionList.java000066400000000000000000000023241234315411400350150ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/list/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.partition.list; import com.gs.collections.api.list.ListIterable; import com.gs.collections.api.partition.ordered.PartitionReversibleIterable; /** * A PartitionList is the result of splitting a ListIterable into two ListIterables based on a Predicate. * The results that answer true for the Predicate will be returned from the getSelected() method and the results * that answer false for the predicate will be returned from the getRejected() method. */ public interface PartitionList extends PartitionReversibleIterable { ListIterable getSelected(); ListIterable getRejected(); } PartitionMutableList.java000066400000000000000000000024251234315411400363310ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/list/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.partition.list; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.partition.PartitionMutableCollection; /** * A PartitionMutableList is the result of splitting a mutable list into two mutable lists based on a Predicate. * The results that answer true for the Predicate will be returned from the getSelected() method and the results that answer * false for the predicate will be returned from the getRejected() method. */ public interface PartitionMutableList extends PartitionMutableCollection, PartitionList { MutableList getSelected(); MutableList getRejected(); PartitionImmutableList toImmutable(); } package-info.java000066400000000000000000000026141234315411400345360ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/list/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains interfaces for {@link com.gs.collections.api.partition.list.PartitionList}. *

* A PartitionList is the result of splitting a list into two lists based on a Predicate. *

*

* This package contains 3 interfaces: *

    *
  • * {@link com.gs.collections.api.partition.list.PartitionList} - a read-only PartitionList API. *
  • *
  • * {@link com.gs.collections.api.partition.list.PartitionMutableList} - a modifiable PartitionList. *
  • *
  • * {@link com.gs.collections.api.partition.list.PartitionImmutableList} - the non-modifiable equivalent interface to {@link com.gs.collections.api.partition.list.PartitionMutableList}. *
  • *
*

*/ package com.gs.collections.api.partition.list; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/ordered/000077500000000000000000000000001234315411400320745ustar00rootroot00000000000000PartitionReversibleIterable.java000066400000000000000000000024111234315411400403220ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/ordered/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.partition.ordered; import com.gs.collections.api.ordered.ReversibleIterable; import com.gs.collections.api.partition.PartitionIterable; /** * A PartitionReversibleIterable is the result of splitting a ReversibleIterable into two ReversibleIterables based on a Predicate. * The results that answer true for the Predicate will be returned from the getSelected() method and the results * that answer false for the predicate will be returned from the getRejected() method. * * @since 5.0 */ public interface PartitionReversibleIterable extends PartitionIterable { ReversibleIterable getSelected(); ReversibleIterable getRejected(); } PartitionSortedIterable.java000066400000000000000000000023551234315411400374670ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/ordered/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.partition.ordered; import com.gs.collections.api.ordered.SortedIterable; import com.gs.collections.api.partition.PartitionIterable; /** * A PartitionSortedIterable is the result of splitting a SortedIterable into two SortedIterables based on a Predicate. * The results that answer true for the Predicate will be returned from the getSelected() method and the results * that answer false for the predicate will be returned from the getRejected() method. * * @since 5.0 */ public interface PartitionSortedIterable extends PartitionIterable { SortedIterable getSelected(); SortedIterable getRejected(); } package-info.java000066400000000000000000000027141234315411400335640ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains interfaces for {@link com.gs.collections.api.partition.PartitionIterable}. *

* A PartitionIterable is the result of splitting an iterable into two iterables based on a {@link com.gs.collections.api.block.predicate.Predicate}. *

*

* This package contains 3 interfaces: *

    *
  • * {@link com.gs.collections.api.partition.PartitionIterable} - a read-only PartitionIterable API. *
  • *
  • * {@link com.gs.collections.api.partition.PartitionMutableCollection} - a modifiable PartitionIterable. *
  • *
  • * {@link com.gs.collections.api.partition.PartitionImmutableCollection} - the non-modifiable equivalent interface to {@link com.gs.collections.api.partition.PartitionMutableCollection}. *
  • *
*

*/ package com.gs.collections.api.partition; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/set/000077500000000000000000000000001234315411400312435ustar00rootroot00000000000000PartitionImmutableSet.java000066400000000000000000000023701234315411400363160ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/set/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.partition.set; import com.gs.collections.api.partition.PartitionImmutableCollection; import com.gs.collections.api.set.ImmutableSet; /** * A PartitionImmutableSet is the result of splitting an immutable set into two immutable sets based on a Predicate. * The results that answer true for the Predicate will be returned from the getSelected() method and the * results that answer false for the predicate will be returned from the getRejected() method. */ public interface PartitionImmutableSet extends PartitionImmutableCollection, PartitionUnsortedSet { ImmutableSet getSelected(); ImmutableSet getRejected(); } PartitionMutableSet.java000066400000000000000000000024221234315411400357660ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/set/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.partition.set; import com.gs.collections.api.partition.PartitionMutableCollection; import com.gs.collections.api.set.MutableSet; /** * A PartitionMutableSet is the result of splitting a mutable set into two mutable sets based on a Predicate. * The results that answer true for the Predicate will be returned from the getSelected() method and the results that answer * false for the predicate will be returned from the getRejected() method. */ public interface PartitionMutableSet extends PartitionMutableCollection, PartitionUnsortedSet { MutableSet getSelected(); MutableSet getRejected(); PartitionImmutableSet toImmutable(); } PartitionSet.java000066400000000000000000000022601234315411400344540ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/set/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.partition.set; import com.gs.collections.api.partition.PartitionIterable; import com.gs.collections.api.set.SetIterable; /** * A PartitionSet is the result of splitting a SetIterable into two SetIterables based on a Predicate. The results that * answer true for the Predicate will be returned from the getSelected() method and the results that answer * false for the predicate will be returned from the getRejected() method. */ public interface PartitionSet extends PartitionIterable { SetIterable getSelected(); SetIterable getRejected(); } PartitionUnsortedSet.java000066400000000000000000000022061234315411400362000ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/set/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.partition.set; import com.gs.collections.api.set.UnsortedSetIterable; /** * A PartitionUnsortedSet is the result of splitting two UnsortedSetIterable on a Predicate. The results that * answer true for the Predicate will be returned from the getSelected() method and the results that answer * false for the predicate will be returned from the getRejected() method. */ public interface PartitionUnsortedSet extends PartitionSet { UnsortedSetIterable getSelected(); UnsortedSetIterable getRejected(); } package-info.java000066400000000000000000000030461234315411400343560ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/set/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains interfaces for {@link com.gs.collections.api.partition.set.PartitionSet}. *

* A PartitionSet is the result of splitting a set into two sets based on a Predicate. *

*

* This package contains 4 interfaces: *

    *
  • * {@link com.gs.collections.api.partition.set.PartitionSet} - a read-only PartitionSet API. *
  • *
  • * {@link com.gs.collections.api.partition.set.PartitionMutableSet} - a modifiable PartitionSet. *
  • *
  • * {@link com.gs.collections.api.partition.set.PartitionImmutableSet} - the non-modifiable equivalent interface to {@link com.gs.collections.api.partition.set.PartitionMutableSet}. *
  • *
  • * {@link com.gs.collections.api.partition.set.PartitionUnsortedSet} - the result of splitting two UnsortedSetIterables based on a Predicate. *
  • *
*

*/ package com.gs.collections.api.partition.set; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/set/sorted/000077500000000000000000000000001234315411400325435ustar00rootroot00000000000000PartitionImmutableSortedSet.java000066400000000000000000000024611234315411400410000ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/set/sorted/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.partition.set.sorted; import com.gs.collections.api.partition.PartitionImmutableCollection; import com.gs.collections.api.set.sorted.ImmutableSortedSet; /** * A PartitionImmutableSortedSet is the result of splitting an immutable sorted set into two immutable sorted sets based * on a Predicate. The results that answer true for the Predicate will be returned from the getSelected() method and the * results that answer false for the predicate will be returned from the getRejected() method. */ public interface PartitionImmutableSortedSet extends PartitionImmutableCollection, PartitionSortedSet { ImmutableSortedSet getSelected(); ImmutableSortedSet getRejected(); } PartitionMutableSortedSet.java000066400000000000000000000025201234315411400404460ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/set/sorted/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.partition.set.sorted; import com.gs.collections.api.partition.PartitionMutableCollection; import com.gs.collections.api.set.sorted.MutableSortedSet; /** * A PartitionMutableSortedSet is the result of splitting a mutable sorted set into two mutable sorted sets based on a Predicate. * The results that answer true for the Predicate will be returned from the getSelected() method and the results that answer * false for the predicate will be returned from the getRejected() method. */ public interface PartitionMutableSortedSet extends PartitionMutableCollection, PartitionSortedSet { MutableSortedSet getSelected(); MutableSortedSet getRejected(); PartitionImmutableSortedSet toImmutable(); } PartitionSortedSet.java000066400000000000000000000025061234315411400371400ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/set/sorted/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.partition.set.sorted; import com.gs.collections.api.partition.ordered.PartitionSortedIterable; import com.gs.collections.api.partition.set.PartitionSet; import com.gs.collections.api.set.sorted.SortedSetIterable; /** * A PartitionSortedSet is the result of splitting a SortedSetIterable into two SortedSetIterables based on a Predicate. * The results that answer true for the Predicate will be returned from the getSelected() method and the results that answer * false for the predicate will be returned from the getRejected() method. */ public interface PartitionSortedSet extends PartitionSet, PartitionSortedIterable { SortedSetIterable getSelected(); SortedSetIterable getRejected(); } package-info.java000066400000000000000000000027601234315411400356600ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/set/sorted/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains interfaces for {@link com.gs.collections.api.partition.set.sorted.PartitionSortedSet}. *

* A PartitionSortedSet is the result of splitting a sorted set into two sorted sets based on a Predicate. *

*

* This package contains the following interfaces: *

    *
  • * {@link com.gs.collections.api.partition.set.sorted.PartitionSortedSet} - a Read-only PartitionSortedSet API. *
  • *
  • * {@link com.gs.collections.api.partition.set.sorted.PartitionMutableSortedSet} - a modifiable PartitionSortedSet. *
  • *
  • * {@link com.gs.collections.api.partition.set.sorted.PartitionImmutableSortedSet} - the non-modifiable equivalent interface to {@link com.gs.collections.api.partition.set.sorted.PartitionMutableSortedSet}. *
  • *
*

*/ package com.gs.collections.api.partition.set.sorted; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/stack/000077500000000000000000000000001234315411400315555ustar00rootroot00000000000000PartitionImmutableStack.java000066400000000000000000000022351234315411400371420ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/stack/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.partition.stack; import com.gs.collections.api.stack.ImmutableStack; /** * A PartitionImmutableStack is the result of splitting an immutable stack into two immutable stacks based on a Predicate. * The results that answer true for the Predicate will be returned from the getSelected() method and the results that answer * false for the predicate will be returned from the getRejected() method. */ public interface PartitionImmutableStack extends PartitionStack { ImmutableStack getSelected(); ImmutableStack getRejected(); } PartitionMutableStack.java000066400000000000000000000024051234315411400366130ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/stack/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.partition.stack; import com.gs.collections.api.stack.MutableStack; /** * A PartitionMutableStack is the result of splitting a mutable stack into two mutable stacks on a Predicate. * The results that answer true for the Predicate will be returned from the getSelected() method and the results * that answer false for the predicate will be returned from the getRejected() method. */ public interface PartitionMutableStack extends PartitionStack { MutableStack getSelected(); MutableStack getRejected(); PartitionImmutableStack toImmutable(); /** * @deprecated in 5.0 */ @Deprecated void add(T t); } PartitionStack.java000066400000000000000000000023011234315411400352740ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/stack/* * Copyright 2012 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.partition.stack; import com.gs.collections.api.partition.PartitionIterable; import com.gs.collections.api.stack.StackIterable; /** * A PartitionStack is the result of splitting a StackIterable into two StackIterables based on a Predicate. * The results that answer true for the Predicate will be returned from the getSelected() method and the results * that answer false for the predicate will be returned from the getRejected() method. */ public interface PartitionStack extends PartitionIterable { StackIterable getSelected(); StackIterable getRejected(); } package-info.java000066400000000000000000000026271234315411400346740ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/partition/stack/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains interfaces for {@link com.gs.collections.api.partition.stack.PartitionStack}. *

* A PartitionStack is the result of splitting a stack into two stacks based on a Predicate. *

*

* This package contains 3 interfaces: *

    *
  • * {@link com.gs.collections.api.partition.stack.PartitionStack} - a read-only PartitionStack API. *
  • *
  • * {@link com.gs.collections.api.partition.stack.PartitionMutableStack} - a modifiable PartitionStack. *
  • *
  • * {@link com.gs.collections.api.partition.stack.PartitionImmutableStack} - the non-modifiable equivalent interface to {@link com.gs.collections.api.partition.stack.PartitionMutableStack}. *
  • *
*

*/ package com.gs.collections.api.partition.stack; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/set/000077500000000000000000000000001234315411400272325ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/set/FixedSizeSet.java000066400000000000000000000015611234315411400324460ustar00rootroot00000000000000/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.set; import com.gs.collections.api.collection.FixedSizeCollection; /** * A FixedSizeSet is a set that may be mutated, but cannot grow or shrink in size. */ public interface FixedSizeSet extends MutableSet, FixedSizeCollection { } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/set/ImmutableSet.java000066400000000000000000000120151234315411400324670ustar00rootroot00000000000000/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.set; import java.util.Set; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.collection.ImmutableCollection; import com.gs.collections.api.multimap.set.ImmutableSetMultimap; import com.gs.collections.api.partition.set.PartitionImmutableSet; import com.gs.collections.api.set.primitive.ImmutableBooleanSet; import com.gs.collections.api.set.primitive.ImmutableByteSet; import com.gs.collections.api.set.primitive.ImmutableCharSet; import com.gs.collections.api.set.primitive.ImmutableDoubleSet; import com.gs.collections.api.set.primitive.ImmutableFloatSet; import com.gs.collections.api.set.primitive.ImmutableIntSet; import com.gs.collections.api.set.primitive.ImmutableLongSet; import com.gs.collections.api.set.primitive.ImmutableShortSet; import com.gs.collections.api.tuple.Pair; import net.jcip.annotations.Immutable; /** * ImmutableSet is the non-modifiable equivalent interface to {@link MutableSet}. {@link MutableSet#toImmutable()} will * give you an appropriately trimmed implementation of ImmutableSet. All ImmutableSet implementations must implement * the java.util.Set interface so they can satisfy the equals() contract and be compared against other set structures * like UnifiedSet or HashSet. */ @Immutable public interface ImmutableSet extends ImmutableCollection, UnsortedSetIterable { ImmutableSet newWith(T element); ImmutableSet newWithout(T element); ImmutableSet newWithAll(Iterable elements); ImmutableSet newWithoutAll(Iterable elements); ImmutableSet select(Predicate predicate);

ImmutableSet selectWith(Predicate2 predicate, P parameter); ImmutableSet reject(Predicate predicate);

ImmutableSet rejectWith(Predicate2 predicate, P parameter); PartitionImmutableSet partition(Predicate predicate);

PartitionImmutableSet partitionWith(Predicate2 predicate, P parameter); ImmutableSet selectInstancesOf(Class clazz); ImmutableSet collect(Function function); ImmutableBooleanSet collectBoolean(BooleanFunction booleanFunction); ImmutableByteSet collectByte(ByteFunction byteFunction); ImmutableCharSet collectChar(CharFunction charFunction); ImmutableDoubleSet collectDouble(DoubleFunction doubleFunction); ImmutableFloatSet collectFloat(FloatFunction floatFunction); ImmutableIntSet collectInt(IntFunction intFunction); ImmutableLongSet collectLong(LongFunction longFunction); ImmutableShortSet collectShort(ShortFunction shortFunction); ImmutableSet collectWith(Function2 function, P parameter); ImmutableSet collectIf(Predicate predicate, Function function); ImmutableSet flatCollect(Function> function); ImmutableSetMultimap groupBy(Function function); ImmutableSetMultimap groupByEach(Function> function); ImmutableSet> zip(Iterable that); ImmutableSet> zipWithIndex(); Set castToSet(); ImmutableSet union(SetIterable set); ImmutableSet intersect(SetIterable set); ImmutableSet difference(SetIterable subtrahendSet); ImmutableSet symmetricDifference(SetIterable setB); ImmutableSet> powerSet(); } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/set/MutableSet.java000066400000000000000000000122561234315411400321500ustar00rootroot00000000000000/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.set; import java.util.Set; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.collection.MutableCollection; import com.gs.collections.api.multimap.set.MutableSetMultimap; import com.gs.collections.api.partition.set.PartitionMutableSet; import com.gs.collections.api.set.primitive.MutableBooleanSet; import com.gs.collections.api.set.primitive.MutableByteSet; import com.gs.collections.api.set.primitive.MutableCharSet; import com.gs.collections.api.set.primitive.MutableDoubleSet; import com.gs.collections.api.set.primitive.MutableFloatSet; import com.gs.collections.api.set.primitive.MutableIntSet; import com.gs.collections.api.set.primitive.MutableLongSet; import com.gs.collections.api.set.primitive.MutableShortSet; import com.gs.collections.api.tuple.Pair; /** * A MutableSet is an implementation of a JCF Set which provides methods matching the Smalltalk Collection protocol. */ public interface MutableSet extends UnsortedSetIterable, MutableCollection, Set, Cloneable { MutableSet with(T element); MutableSet without(T element); MutableSet withAll(Iterable elements); MutableSet withoutAll(Iterable elements); MutableSet newEmpty(); MutableSet clone(); MutableSet select(Predicate predicate);

MutableSet selectWith(Predicate2 predicate, P parameter); MutableSet reject(Predicate predicate);

MutableSet rejectWith(Predicate2 predicate, P parameter); PartitionMutableSet partition(Predicate predicate);

PartitionMutableSet partitionWith(Predicate2 predicate, P parameter); MutableSet selectInstancesOf(Class clazz); MutableSet collect(Function function); MutableBooleanSet collectBoolean(BooleanFunction booleanFunction); MutableByteSet collectByte(ByteFunction byteFunction); MutableCharSet collectChar(CharFunction charFunction); MutableDoubleSet collectDouble(DoubleFunction doubleFunction); MutableFloatSet collectFloat(FloatFunction floatFunction); MutableIntSet collectInt(IntFunction intFunction); MutableLongSet collectLong(LongFunction longFunction); MutableShortSet collectShort(ShortFunction shortFunction); MutableSet collectWith(Function2 function, P parameter); MutableSet collectIf(Predicate predicate, Function function); MutableSet flatCollect(Function> function); /** * Returns an unmodifable view of the set. * The returned set will be Serializable if this set is Serializable. * * @return an unmodifiable view of this set */ MutableSet asUnmodifiable(); MutableSet asSynchronized(); /** * Returns an immutable copy of this set. If the set is immutable, it returns itself. *

* The returned set will be Serializable if this set is Serializable. */ ImmutableSet toImmutable(); MutableSetMultimap groupBy(Function function); MutableSetMultimap groupByEach(Function> function); MutableSet> zip(Iterable that); MutableSet> zipWithIndex(); MutableSet union(SetIterable set); MutableSet intersect(SetIterable set); MutableSet difference(SetIterable subtrahendSet); MutableSet symmetricDifference(SetIterable setB); MutableSet> powerSet(); } ParallelSetIterable.java000066400000000000000000000034541234315411400337040ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/set/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.set; import com.gs.collections.api.ParallelIterable; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.multimap.set.SetMultimap; /** * @since 5.0 */ @Beta public interface ParallelSetIterable extends ParallelIterable { /** * Creates a parallel iterable for selecting elements from the current iterable. */ ParallelSetIterable select(Predicate predicate);

ParallelSetIterable selectWith(Predicate2 predicate, P parameter); /** * Creates a parallel iterable for rejecting elements from the current iterable. */ ParallelSetIterable reject(Predicate predicate);

ParallelSetIterable rejectWith(Predicate2 predicate, P parameter); ParallelSetIterable selectInstancesOf(Class clazz); SetMultimap groupBy(Function function); SetMultimap groupByEach(Function> function); } ParallelUnsortedSetIterable.java000066400000000000000000000100561234315411400354240ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/set/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.set; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.multimap.set.UnsortedSetMultimap; /** * A ParallelIterable is RichIterable which will defer evaluation for certain methods like select, reject, collect, etc. * Any methods that do not return a ParallelIterable when called will cause evaluation to be forced. Evaluation occurs * in parallel. All code blocks passed in must be stateless or thread-safe. * * @since 5.0 */ @Beta public interface ParallelUnsortedSetIterable extends ParallelSetIterable { ParallelUnsortedSetIterable asUnique(); /** * Creates a parallel iterable for selecting elements from the current iterable. */ ParallelUnsortedSetIterable select(Predicate predicate);

ParallelUnsortedSetIterable selectWith(Predicate2 predicate, P parameter); /** * Creates a parallel iterable for rejecting elements from the current iterable. */ ParallelUnsortedSetIterable reject(Predicate predicate);

ParallelUnsortedSetIterable rejectWith(Predicate2 predicate, P parameter); ParallelUnsortedSetIterable selectInstancesOf(Class clazz); UnsortedSetMultimap groupBy(Function function); UnsortedSetMultimap groupByEach(Function> function); // /** // * Returns a parallel BooleanIterable which will transform the underlying iterable data to boolean values based on the booleanFunction. // */ // ParallelBooleanIterable collectBoolean(BooleanFunction booleanFunction); // // /** // * Returns a parallel ByteIterable which will transform the underlying iterable data to byte values based on the byteFunction. // */ // ParallelByteIterable collectByte(ByteFunction byteFunction); // // /** // * Returns a parallel CharIterable which will transform the underlying iterable data to char values based on the charFunction. // */ // ParallelCharIterable collectChar(CharFunction charFunction); // // /** // * Returns a parallel DoubleIterable which will transform the underlying iterable data to double values based on the doubleFunction. // */ // ParallelDoubleIterable collectDouble(DoubleFunction doubleFunction); // // /** // * Returns a parallel FloatIterable which will transform the underlying iterable data to float values based on the floatFunction. // */ // ParallelFloatIterable collectFloat(FloatFunction floatFunction); // // /** // * Returns a parallel IntIterable which will transform the underlying iterable data to int values based on the intFunction. // */ // ParallelIntIterable collectInt(IntFunction intFunction); // // /** // * Returns a parallel LongIterable which will transform the underlying iterable data to long values based on the longFunction. // */ // ParallelLongIterable collectLong(LongFunction longFunction); // // /** // * Returns a parallel ShortIterable which will transform the underlying iterable data to short values based on the shortFunction. // */ // ParallelShortIterable collectShort(ShortFunction shortFunction); } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/set/Pool.java000066400000000000000000000032501234315411400310060ustar00rootroot00000000000000/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.set; public interface Pool { /** * Locates an object in the pool which is equal to {@code key}. * * @param key the value to look for * @return The object reference in the pool equal to key or null. */ V get(V key); void clear(); /** * Puts {@code key} into the pool. If there is no existing object that is equal * to key, key will be added to the pool and the return value will be the same instance. * If there is an existing object in the pool that is equal to {@code key}, the pool will remain unchanged * and the pooled instance will be is returned. * * @param key the value to add if not in the pool * @return the object reference in the pool equal to key (either key itself or the existing reference) */ V put(V key); int size(); /** * Locates an object in the pool which is equal to {@code key} and removes it. * * @param key object to remove * @return The object reference in the pool equal to key or null. */ V removeFromPool(V key); } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/set/SetIterable.java000066400000000000000000000115571234315411400323110ustar00rootroot00000000000000/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.set; import java.util.Set; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.RichIterable; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.partition.set.PartitionSet; import com.gs.collections.api.tuple.Pair; /** * A Read-only Set api, with the minor exception inherited from java.lang.Iterable (iterable.iterator().remove()). */ public interface SetIterable extends RichIterable { /** * Returns the set of all objects that are a member of {@code this} or {@code set} or both. The union of [1, 2, 3] * and [2, 3, 4] is the set [1, 2, 3, 4]. If equal elements appear in both sets, then the output will contain the * copy from {@code this}. */ SetIterable union(SetIterable set); /** * Same as {@link #union(SetIterable)} but adds all the objects to {@code targetSet} and returns it. */ > R unionInto(SetIterable set, R targetSet); /** * Returns the set of all objects that are members of both {@code this} and {@code set}. The intersection of * [1, 2, 3] and [2, 3, 4] is the set [2, 3]. The output will contain instances from {@code this}, not {@code set}. */ SetIterable intersect(SetIterable set); /** * Same as {@link #intersect(SetIterable)} but adds all the objects to {@code targetSet} and returns it. */ > R intersectInto(SetIterable set, R targetSet); /** * Returns the set of all members of {@code this} that are not members of {@code subtrahendSet}. The difference of * [1, 2, 3] and [2, 3, 4] is [1]. */ SetIterable difference(SetIterable subtrahendSet); /** * Same as {@link #difference(SetIterable)} but adds all the objects to {@code targetSet} and returns it. */ > R differenceInto(SetIterable subtrahendSet, R targetSet); /** * Returns the set of all objects that are a member of exactly one of {@code this} and {@code setB} (elements which * are in one of the sets, but not in both). For instance, for the sets [1, 2, 3] and [2, 3, 4], the symmetric * difference set is [1, 4] . It is the set difference of the union and the intersection. */ SetIterable symmetricDifference(SetIterable setB); /** * Same as {@link #symmetricDifference(SetIterable)} but adds all the objects to {@code targetSet} and returns it. */ > R symmetricDifferenceInto(SetIterable set, R targetSet); /** * Returns {@literal true} if all the members of {@code this} are also members of {@code candidateSuperset}. * For example, [1, 2] is a subset of [1, 2, 3], but [1, 4] is not. */ boolean isSubsetOf(SetIterable candidateSuperset); /** * Returns {@literal true} if all the members of {@code this} are also members of {@code candidateSuperset} and the * two sets are not equal. For example, [1, 2] is a proper subset of [1, 2, 3], but [1, 2, 3] is not. */ boolean isProperSubsetOf(SetIterable candidateSuperset); /** * Returns the set whose members are all possible ordered pairs (a, b) where a is a member of {@code this} and b is a * member of {@code set}. */ LazyIterable> cartesianProduct(SetIterable set); SetIterable select(Predicate predicate);

SetIterable selectWith(Predicate2 predicate, P parameter); SetIterable reject(Predicate predicate);

SetIterable rejectWith(Predicate2 predicate, P parameter); PartitionSet partition(Predicate predicate);

PartitionSet partitionWith(Predicate2 predicate, P parameter); SetIterable selectInstancesOf(Class clazz); SetIterable> zipWithIndex(); /** * Follows the same general contract as {@link Set#equals(Object)}. */ @Override boolean equals(Object o); /** * Follows the same general contract as {@link Set#hashCode()}. */ @Override int hashCode(); } UnsortedSetIterable.java000066400000000000000000000105101234315411400337420ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/set/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.set; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.multimap.set.SetMultimap; import com.gs.collections.api.set.primitive.BooleanSet; import com.gs.collections.api.set.primitive.ByteSet; import com.gs.collections.api.set.primitive.CharSet; import com.gs.collections.api.set.primitive.DoubleSet; import com.gs.collections.api.set.primitive.FloatSet; import com.gs.collections.api.set.primitive.IntSet; import com.gs.collections.api.set.primitive.LongSet; import com.gs.collections.api.set.primitive.ShortSet; import com.gs.collections.api.tuple.Pair; /** * An iterable whose items are unique. */ public interface UnsortedSetIterable extends SetIterable { /** * Returns the set whose members are all possible subsets of {@code this}. For example, the powerset of [1, 2] is * [[], [1], [2], [1, 2]]. */ UnsortedSetIterable> powerSet(); UnsortedSetIterable collect(Function function); BooleanSet collectBoolean(BooleanFunction booleanFunction); ByteSet collectByte(ByteFunction byteFunction); CharSet collectChar(CharFunction charFunction); DoubleSet collectDouble(DoubleFunction doubleFunction); FloatSet collectFloat(FloatFunction floatFunction); IntSet collectInt(IntFunction intFunction); LongSet collectLong(LongFunction longFunction); ShortSet collectShort(ShortFunction shortFunction); UnsortedSetIterable collectWith(Function2 function, P parameter); UnsortedSetIterable collectIf(Predicate predicate, Function function); UnsortedSetIterable flatCollect(Function> function); SetMultimap groupBy(Function function); SetMultimap groupByEach(Function> function); UnsortedSetIterable union(SetIterable set); UnsortedSetIterable intersect(SetIterable set); UnsortedSetIterable difference(SetIterable subtrahendSet); UnsortedSetIterable symmetricDifference(SetIterable setB); UnsortedSetIterable select(Predicate predicate);

UnsortedSetIterable selectWith(Predicate2 predicate, P parameter); UnsortedSetIterable reject(Predicate predicate);

UnsortedSetIterable rejectWith(Predicate2 predicate, P parameter); UnsortedSetIterable selectInstancesOf(Class clazz); UnsortedSetIterable> zip(Iterable that); UnsortedSetIterable> zipWithIndex(); /** * Converts the UnsortedSetIterable to an immutable implementation. Returns this for immutable sets. * * @since 5.0 */ ImmutableSet toImmutable(); } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/set/package-info.java000066400000000000000000000034121234315411400324210ustar00rootroot00000000000000/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains interfaces for set API which enhance the performance and functionality of {@link java.util.Set}. *

* This package contains 6 interfaces: *

    *
  • * {@link com.gs.collections.api.set.FixedSizeSet} - a set that may be mutated, but cannot grow or shrink in size. *
  • *
  • * {@link com.gs.collections.api.set.ImmutableSet} - the non-modifiable equivalent interface to {@link com.gs.collections.api.set.MutableSet}. *
  • *
  • * {@link com.gs.collections.api.set.MutableSet} - an implementation of a JCF Set which provides internal iterator methods matching the Smalltalk Collection protocol. *
  • *
  • * {@link com.gs.collections.api.set.Pool} - locates an object in the pool which is equal to {@code key}. *
  • *
  • * {@link com.gs.collections.api.set.SetIterable} - a read-only Set API, with the minor exception inherited from {@link java.lang.Iterable} (iterable.iterator().remove()). *
  • *
  • * {@link com.gs.collections.api.set.UnsortedSetIterable} - an iterable whose items are unique. *
  • *
*

*/ package com.gs.collections.api.set; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/set/primitive/000077500000000000000000000000001234315411400312425ustar00rootroot00000000000000package-info.java000066400000000000000000000015371234315411400343600ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/set/primitive/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains API for mutable and immutable primitive sets. *

* A primitive set is similar to {@link com.gs.collections.api.set.SetIterable} and is memory-optimized for primitives. *

*/ package com.gs.collections.api.set.primitive; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/set/sorted/000077500000000000000000000000001234315411400305325ustar00rootroot00000000000000ImmutableSortedSet.java000066400000000000000000000131341234315411400350740ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/set/sorted/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.set.sorted; import java.util.Set; import java.util.SortedSet; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.collection.ImmutableCollection; import com.gs.collections.api.list.ImmutableList; import com.gs.collections.api.list.primitive.ImmutableBooleanList; import com.gs.collections.api.list.primitive.ImmutableByteList; import com.gs.collections.api.list.primitive.ImmutableCharList; import com.gs.collections.api.list.primitive.ImmutableDoubleList; import com.gs.collections.api.list.primitive.ImmutableFloatList; import com.gs.collections.api.list.primitive.ImmutableIntList; import com.gs.collections.api.list.primitive.ImmutableLongList; import com.gs.collections.api.list.primitive.ImmutableShortList; import com.gs.collections.api.multimap.sortedset.ImmutableSortedSetMultimap; import com.gs.collections.api.partition.set.sorted.PartitionImmutableSortedSet; import com.gs.collections.api.set.SetIterable; import com.gs.collections.api.tuple.Pair; import net.jcip.annotations.Immutable; /** * ImmutableSortedSet is the non-modifiable equivalent interface to {@link MutableSortedSet}. {@link * MutableSortedSet#toImmutable()} will give you an appropriately trimmed implementation of ImmutableSortedSet. All * ImmutableSortedSet implementations must implement the {@link SortedSet} interface so they can satisfy the {@link * Set#equals(Object)} contract and be compared against other Sets. */ @Immutable public interface ImmutableSortedSet extends ImmutableCollection, SortedSetIterable { ImmutableSortedSet newWith(T element); ImmutableSortedSet newWithout(T element); ImmutableSortedSet newWithAll(Iterable elements); ImmutableSortedSet newWithoutAll(Iterable elements); ImmutableSortedSet select(Predicate predicate);

ImmutableSortedSet selectWith(Predicate2 predicate, P parameter); ImmutableSortedSet reject(Predicate predicate);

ImmutableSortedSet rejectWith(Predicate2 predicate, P parameter); PartitionImmutableSortedSet partition(Predicate predicate);

PartitionImmutableSortedSet partitionWith(Predicate2 predicate, P parameter); PartitionImmutableSortedSet partitionWhile(Predicate predicate); ImmutableSortedSet selectInstancesOf(Class clazz); ImmutableList collect(Function function); ImmutableBooleanList collectBoolean(BooleanFunction booleanFunction); ImmutableByteList collectByte(ByteFunction byteFunction); ImmutableCharList collectChar(CharFunction charFunction); ImmutableDoubleList collectDouble(DoubleFunction doubleFunction); ImmutableFloatList collectFloat(FloatFunction floatFunction); ImmutableIntList collectInt(IntFunction intFunction); ImmutableLongList collectLong(LongFunction longFunction); ImmutableShortList collectShort(ShortFunction shortFunction); ImmutableList collectWith(Function2 function, P parameter); ImmutableList collectIf(Predicate predicate, Function function); ImmutableList flatCollect(Function> function); ImmutableSortedSet distinct(); ImmutableSortedSet takeWhile(Predicate predicate); ImmutableSortedSet dropWhile(Predicate predicate); ImmutableSortedSetMultimap groupBy(Function function); ImmutableSortedSetMultimap groupByEach(Function> function); ImmutableList> zip(Iterable that); ImmutableSortedSet> zipWithIndex(); SortedSet castToSortedSet(); ImmutableSortedSet union(SetIterable set); ImmutableSortedSet intersect(SetIterable set); ImmutableSortedSet difference(SetIterable subtrahendSet); ImmutableSortedSet symmetricDifference(SetIterable setB); ImmutableSortedSet> powerSet(); } MutableSortedSet.java000066400000000000000000000136351234315411400345540ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/set/sorted/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.set.sorted; import java.util.SortedSet; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.collection.MutableCollection; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.list.primitive.MutableBooleanList; import com.gs.collections.api.list.primitive.MutableByteList; import com.gs.collections.api.list.primitive.MutableCharList; import com.gs.collections.api.list.primitive.MutableDoubleList; import com.gs.collections.api.list.primitive.MutableFloatList; import com.gs.collections.api.list.primitive.MutableIntList; import com.gs.collections.api.list.primitive.MutableLongList; import com.gs.collections.api.list.primitive.MutableShortList; import com.gs.collections.api.multimap.sortedset.MutableSortedSetMultimap; import com.gs.collections.api.partition.set.sorted.PartitionMutableSortedSet; import com.gs.collections.api.set.SetIterable; import com.gs.collections.api.tuple.Pair; /** * A MutableSortedSet is an implementation of a JCF SortedSet which provides methods matching the Smalltalk Collection * protocol. * * @since 1.0 */ public interface MutableSortedSet extends SortedSetIterable, MutableCollection, SortedSet, Cloneable { MutableSortedSet with(T element); MutableSortedSet without(T element); MutableSortedSet withAll(Iterable elements); MutableSortedSet withoutAll(Iterable elements); MutableSortedSet newEmpty(); MutableSortedSet clone(); MutableSortedSet select(Predicate predicate);

MutableSortedSet selectWith(Predicate2 predicate, P parameter); MutableSortedSet reject(Predicate predicate);

MutableSortedSet rejectWith(Predicate2 predicate, P parameter); PartitionMutableSortedSet partition(Predicate predicate);

PartitionMutableSortedSet partitionWith(Predicate2 predicate, P parameter); PartitionMutableSortedSet partitionWhile(Predicate predicate); MutableSortedSet selectInstancesOf(Class clazz); MutableList collect(Function function); MutableBooleanList collectBoolean(BooleanFunction booleanFunction); MutableByteList collectByte(ByteFunction byteFunction); MutableCharList collectChar(CharFunction charFunction); MutableDoubleList collectDouble(DoubleFunction doubleFunction); MutableFloatList collectFloat(FloatFunction floatFunction); MutableIntList collectInt(IntFunction intFunction); MutableLongList collectLong(LongFunction longFunction); MutableShortList collectShort(ShortFunction shortFunction); MutableList collectWith(Function2 function, P parameter); MutableList collectIf(Predicate predicate, Function function); MutableList flatCollect(Function> function); MutableSortedSet distinct(); MutableSortedSet takeWhile(Predicate predicate); MutableSortedSet dropWhile(Predicate predicate); /** * Returns an unmodifable view of the set. The returned set will be Serializable if this set is Serializable. * * @return an unmodifiable view of this set */ MutableSortedSet asUnmodifiable(); MutableSortedSet asSynchronized(); /** * Returns an immutable copy of this set. If the set is immutable, it returns itself. *

* The returned set will be Serializable if this set is Serializable. */ ImmutableSortedSet toImmutable(); MutableSortedSetMultimap groupBy(Function function); MutableSortedSetMultimap groupByEach(Function> function); MutableList> zip(Iterable that); MutableSortedSet> zipWithIndex(); MutableSortedSet union(SetIterable set); MutableSortedSet intersect(SetIterable set); MutableSortedSet difference(SetIterable subtrahendSet); MutableSortedSet symmetricDifference(SetIterable setB); MutableSortedSet> powerSet(); MutableSortedSet subSet(T fromElement, T toElement); MutableSortedSet headSet(T toElement); MutableSortedSet tailSet(T fromElement); } ParallelSortedSetIterable.java000066400000000000000000000110701234315411400363560ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/set/sorted/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.set.sorted; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.list.ParallelListIterable; import com.gs.collections.api.multimap.sortedset.SortedSetMultimap; import com.gs.collections.api.set.ParallelSetIterable; /** * @since 5.0 */ @Beta public interface ParallelSortedSetIterable extends ParallelSetIterable { /** * Creates a parallel iterable for selecting elements from the current iterable. */ ParallelSortedSetIterable select(Predicate predicate);

ParallelSortedSetIterable selectWith(Predicate2 predicate, P parameter); /** * Creates a parallel iterable for rejecting elements from the current iterable. */ ParallelSortedSetIterable reject(Predicate predicate);

ParallelSortedSetIterable rejectWith(Predicate2 predicate, P parameter); ParallelSortedSetIterable selectInstancesOf(Class clazz); /** * Creates a parallel iterable for collecting elements from the current iterable. */ ParallelListIterable collect(Function function); ParallelListIterable collectWith(Function2 function, P parameter); /** * Creates a parallel iterable for selecting and collecting elements from the current iterable. */ ParallelListIterable collectIf(Predicate predicate, Function function); /** * Creates a parallel flattening iterable for the current iterable. */ ParallelListIterable flatCollect(Function> function); SortedSetMultimap groupBy(Function function); SortedSetMultimap groupByEach(Function> function); // /** // * Returns a parallel BooleanIterable which will transform the underlying iterable data to boolean values based on the booleanFunction. // */ // ParallelBooleanIterable collectBoolean(BooleanFunction booleanFunction); // // /** // * Returns a parallel ByteIterable which will transform the underlying iterable data to byte values based on the byteFunction. // */ // ParallelByteIterable collectByte(ByteFunction byteFunction); // // /** // * Returns a parallel CharIterable which will transform the underlying iterable data to char values based on the charFunction. // */ // ParallelCharIterable collectChar(CharFunction charFunction); // // /** // * Returns a parallel DoubleIterable which will transform the underlying iterable data to double values based on the doubleFunction. // */ // ParallelDoubleIterable collectDouble(DoubleFunction doubleFunction); // // /** // * Returns a parallel FloatIterable which will transform the underlying iterable data to float values based on the floatFunction. // */ // ParallelFloatIterable collectFloat(FloatFunction floatFunction); // // /** // * Returns a parallel IntIterable which will transform the underlying iterable data to int values based on the intFunction. // */ // ParallelIntIterable collectInt(IntFunction intFunction); // // /** // * Returns a parallel LongIterable which will transform the underlying iterable data to long values based on the longFunction. // */ // ParallelLongIterable collectLong(LongFunction longFunction); // // /** // * Returns a parallel ShortIterable which will transform the underlying iterable data to short values based on the shortFunction. // */ // ParallelShortIterable collectShort(ShortFunction shortFunction); } SortedSetIterable.java000066400000000000000000000143761234315411400347150ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/set/sorted/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.set.sorted; import java.util.Comparator; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.list.ListIterable; import com.gs.collections.api.list.primitive.BooleanList; import com.gs.collections.api.list.primitive.ByteList; import com.gs.collections.api.list.primitive.CharList; import com.gs.collections.api.list.primitive.DoubleList; import com.gs.collections.api.list.primitive.FloatList; import com.gs.collections.api.list.primitive.IntList; import com.gs.collections.api.list.primitive.LongList; import com.gs.collections.api.list.primitive.ShortList; import com.gs.collections.api.multimap.sortedset.SortedSetMultimap; import com.gs.collections.api.ordered.SortedIterable; import com.gs.collections.api.partition.set.sorted.PartitionSortedSet; import com.gs.collections.api.set.SetIterable; import com.gs.collections.api.tuple.Pair; /** * An iterable whose items are unique and sorted by some comparator or their natural ordering. */ public interface SortedSetIterable extends SetIterable, Comparable>, SortedIterable { /** * Returns the comparator used to order the elements in this set, or null if this set uses the natural ordering of * its elements. */ Comparator comparator(); /** * Returns the set of all objects that are a member of {@code this} or {@code set} or both. The union of [1, 2, 3] * and [2, 3, 4] is the set [1, 2, 3, 4]. If equal elements appear in both sets, then the output will contain the * copy from {@code this}. */ SortedSetIterable union(SetIterable set); /** * Returns the set of all objects that are members of both {@code this} and {@code set}. The intersection of * [1, 2, 3] and [2, 3, 4] is the set [2, 3]. The output will contain instances from {@code this}, not {@code set}. */ SortedSetIterable intersect(SetIterable set); /** * Returns the set of all members of {@code this} that are not members of {@code subtrahendSet}. The difference of * [1, 2, 3] and [2, 3, 4] is [1]. */ SortedSetIterable difference(SetIterable subtrahendSet); /** * Returns the set of all objects that are a member of exactly one of {@code this} and {@code setB} (elements which * are in one of the sets, but not in both). For instance, for the sets [1, 2, 3] and [2, 3, 4], the symmetric * difference set is [1, 4] . It is the set difference of the union and the intersection. */ SortedSetIterable symmetricDifference(SetIterable setB); /** * Returns the set whose members are all possible subsets of {@code this}. For example, the powerset of [1, 2] is * [[], [1], [2], [1, 2]]. */ SortedSetIterable> powerSet(); SortedSetIterable select(Predicate predicate);

SortedSetIterable selectWith(Predicate2 predicate, P parameter); SortedSetIterable reject(Predicate predicate);

SortedSetIterable rejectWith(Predicate2 predicate, P parameter); PartitionSortedSet partition(Predicate predicate);

PartitionSortedSet partitionWith(Predicate2 predicate, P parameter); PartitionSortedSet partitionWhile(Predicate predicate); SortedSetIterable selectInstancesOf(Class clazz); ListIterable collect(Function function); BooleanList collectBoolean(BooleanFunction booleanFunction); ByteList collectByte(ByteFunction byteFunction); CharList collectChar(CharFunction charFunction); DoubleList collectDouble(DoubleFunction doubleFunction); FloatList collectFloat(FloatFunction floatFunction); IntList collectInt(IntFunction intFunction); LongList collectLong(LongFunction longFunction); ShortList collectShort(ShortFunction shortFunction); ListIterable collectWith(Function2 function, P parameter); ListIterable collectIf(Predicate predicate, Function function); ListIterable flatCollect(Function> function); SortedSetIterable distinct(); SortedSetIterable takeWhile(Predicate predicate); SortedSetIterable dropWhile(Predicate predicate); SortedSetMultimap groupBy(Function function); SortedSetMultimap groupByEach(Function> function); SortedSetIterable> zipWithIndex(); /** * Converts the SortedSetIterable to an immutable implementation. Returns this for immutable sets. * * @since 5.0 */ ImmutableSortedSet toImmutable(); } package-info.java000066400000000000000000000026721234315411400336510ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/set/sorted/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains interfaces for sorted set API. *

* A sorted set is an {@link java.lang.Iterable} which contains elements in sorted order. It allows for faster retrievals. *

*

* This package contains 3 interfaces: *

    *
  • * {@link com.gs.collections.api.set.sorted.ImmutableSortedSet} - the non-modifiable equivalent interface to {@link com.gs.collections.api.set.sorted.MutableSortedSet}. *
  • *
  • * {@link com.gs.collections.api.set.sorted.MutableSortedSet} - an implementation of a JCF SortedSet which provides internal iterator methods matching the Smalltalk Collection protocol. *
  • *
  • * {@link com.gs.collections.api.set.sorted.SortedSetIterable} - an iterable whose items are unique and sorted. *
  • *
*

*/ package com.gs.collections.api.set.sorted; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/stack/000077500000000000000000000000001234315411400275445ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/stack/ImmutableStack.java000066400000000000000000000104001234315411400333070ustar00rootroot00000000000000/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.stack; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.map.ImmutableMap; import com.gs.collections.api.multimap.list.ImmutableListMultimap; import com.gs.collections.api.partition.stack.PartitionImmutableStack; import com.gs.collections.api.stack.primitive.ImmutableBooleanStack; import com.gs.collections.api.stack.primitive.ImmutableByteStack; import com.gs.collections.api.stack.primitive.ImmutableCharStack; import com.gs.collections.api.stack.primitive.ImmutableDoubleStack; import com.gs.collections.api.stack.primitive.ImmutableFloatStack; import com.gs.collections.api.stack.primitive.ImmutableIntStack; import com.gs.collections.api.stack.primitive.ImmutableLongStack; import com.gs.collections.api.stack.primitive.ImmutableShortStack; import com.gs.collections.api.tuple.Pair; public interface ImmutableStack extends StackIterable { ImmutableStack push(T item); ImmutableStack pop(); ImmutableStack pop(int count); ImmutableStack select(Predicate predicate);

ImmutableStack selectWith(Predicate2 predicate, P parameter); ImmutableStack reject(Predicate predicate);

ImmutableStack rejectWith(Predicate2 predicate, P parameter); PartitionImmutableStack partition(Predicate predicate);

PartitionImmutableStack partitionWith(Predicate2 predicate, P parameter); ImmutableStack collect(Function function); ImmutableBooleanStack collectBoolean(BooleanFunction booleanFunction); ImmutableByteStack collectByte(ByteFunction byteFunction); ImmutableCharStack collectChar(CharFunction charFunction); ImmutableDoubleStack collectDouble(DoubleFunction doubleFunction); ImmutableFloatStack collectFloat(FloatFunction floatFunction); ImmutableIntStack collectInt(IntFunction intFunction); ImmutableLongStack collectLong(LongFunction longFunction); ImmutableShortStack collectShort(ShortFunction shortFunction); ImmutableStack collectWith(Function2 function, P parameter); ImmutableStack collectIf(Predicate predicate, Function function); ImmutableStack flatCollect(Function> function); ImmutableListMultimap groupBy(Function function); ImmutableListMultimap groupByEach(Function> function); ImmutableMap groupByUniqueKey(Function function); ImmutableStack> zip(Iterable that); ImmutableStack> zipWithIndex(); /** * Size takes linear time on ImmutableStacks. */ int size(); } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/stack/MutableStack.java000066400000000000000000000120251234315411400327660ustar00rootroot00000000000000/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.stack; import java.util.Collection; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.list.ListIterable; import com.gs.collections.api.map.MutableMap; import com.gs.collections.api.multimap.list.MutableListMultimap; import com.gs.collections.api.partition.stack.PartitionMutableStack; import com.gs.collections.api.stack.primitive.MutableBooleanStack; import com.gs.collections.api.stack.primitive.MutableByteStack; import com.gs.collections.api.stack.primitive.MutableCharStack; import com.gs.collections.api.stack.primitive.MutableDoubleStack; import com.gs.collections.api.stack.primitive.MutableFloatStack; import com.gs.collections.api.stack.primitive.MutableIntStack; import com.gs.collections.api.stack.primitive.MutableLongStack; import com.gs.collections.api.stack.primitive.MutableShortStack; import com.gs.collections.api.tuple.Pair; public interface MutableStack extends StackIterable { /** * Adds an item to the top of the stack. */ void push(T item); /** * Removes and returns the top element of the stack. */ T pop(); /** * Removes and returns a ListIterable of the number of elements specified by the count, beginning with the top of the stack. */ ListIterable pop(int count); /** * Removes and returns a ListIterable of the number of elements specified by the count, * beginning with the top of the stack and puts them into the targeted collection type. */ > R pop(int count, R targetCollection); /** * Removes and returns a ListIterable of the number of elements specified by the count, * beginning with the top of the stack and puts them into a new stack. */ > R pop(int count, R targetStack); void clear(); MutableStack asUnmodifiable(); MutableStack asSynchronized(); MutableStack select(Predicate predicate);

MutableStack selectWith(Predicate2 predicate, P parameter); MutableStack reject(Predicate predicate);

MutableStack rejectWith(Predicate2 predicate, P parameter); PartitionMutableStack partition(Predicate predicate);

PartitionMutableStack partitionWith(Predicate2 predicate, P parameter); MutableStack collect(Function function); MutableBooleanStack collectBoolean(BooleanFunction booleanFunction); MutableByteStack collectByte(ByteFunction byteFunction); MutableCharStack collectChar(CharFunction charFunction); MutableDoubleStack collectDouble(DoubleFunction doubleFunction); MutableFloatStack collectFloat(FloatFunction floatFunction); MutableIntStack collectInt(IntFunction intFunction); MutableLongStack collectLong(LongFunction longFunction); MutableShortStack collectShort(ShortFunction shortFunction); MutableStack collectWith(Function2 function, P parameter); MutableStack collectIf(Predicate predicate, Function function); MutableStack flatCollect(Function> function); MutableListMultimap groupBy(Function function); MutableListMultimap groupByEach(Function> function); MutableMap groupByUniqueKey(Function function); MutableStack> zip(Iterable that); MutableStack> zipWithIndex(); } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/stack/StackIterable.java000066400000000000000000000136361234315411400331350ustar00rootroot00000000000000/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.stack; import java.util.AbstractCollection; import java.util.List; import com.gs.collections.api.RichIterable; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.list.ListIterable; import com.gs.collections.api.multimap.list.ListMultimap; import com.gs.collections.api.partition.stack.PartitionStack; import com.gs.collections.api.stack.primitive.BooleanStack; import com.gs.collections.api.stack.primitive.ByteStack; import com.gs.collections.api.stack.primitive.CharStack; import com.gs.collections.api.stack.primitive.DoubleStack; import com.gs.collections.api.stack.primitive.FloatStack; import com.gs.collections.api.stack.primitive.IntStack; import com.gs.collections.api.stack.primitive.LongStack; import com.gs.collections.api.stack.primitive.ShortStack; import com.gs.collections.api.tuple.Pair; /** * StackIterable is a last-in-first-out data structure. All iteration methods iterate from the "top" of the stack to the * "bottom". In other words, it processes the most recently added elements first. *

* For example: *

* {@link #forEach(Procedure)} iterates over every element, starting with the most recently added *

* {@link #getFirst()} returns the most recently added element, not the element that was added first *

* {@link #toString()} follows the same rules as {@link AbstractCollection#toString()} except it processes the elements * in the same order as {@code forEach()}. */ public interface StackIterable extends RichIterable { /** * @return the top of the stack. */ T peek(); /** * @return a ListIterable of the number of elements specified by the count, beginning with the top of the stack. */ ListIterable peek(int count); /** * @param index the location to peek into * @return the element at the specified index */ T peekAt(int index); /** * Should return the same value as peek(). */ T getFirst(); /** * Should not work as it violates the contract of a Stack. * * @throws UnsupportedOperationException */ T getLast(); /** * Follows the same rules as {@link AbstractCollection#toString()} except it processes the elements * in the same order as {@code forEach()}. */ String toString(); /** * Follows the same general contract as {@link List#equals(Object)}, but for Stacks. */ @Override boolean equals(Object o); /** * Follows the same general contract as {@link List#hashCode()}, but for Stacks. */ @Override int hashCode(); /** * Converts the stack to a MutableStack implementation. * * @since 2.0 */ MutableStack toStack(); StackIterable select(Predicate predicate);

StackIterable selectWith(Predicate2 predicate, P parameter); StackIterable reject(Predicate predicate);

StackIterable rejectWith(Predicate2 predicate, P parameter); PartitionStack partition(Predicate predicate);

PartitionStack partitionWith(Predicate2 predicate, P parameter); StackIterable collect(Function function); BooleanStack collectBoolean(BooleanFunction booleanFunction); ByteStack collectByte(ByteFunction byteFunction); CharStack collectChar(CharFunction charFunction); DoubleStack collectDouble(DoubleFunction doubleFunction); FloatStack collectFloat(FloatFunction floatFunction); IntStack collectInt(IntFunction intFunction); LongStack collectLong(LongFunction longFunction); ShortStack collectShort(ShortFunction shortFunction); StackIterable collectWith(Function2 function, P parameter); StackIterable collectIf(Predicate predicate, Function function); StackIterable flatCollect(Function> function); ListMultimap groupBy(Function function); ListMultimap groupByEach(Function> function); StackIterable> zip(Iterable that); StackIterable> zipWithIndex(); /** * Converts the StackIterable to an immutable implementation. Returns this for immutable stacks. * * @since 5.0 */ ImmutableStack toImmutable(); } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/stack/package-info.java000066400000000000000000000023151234315411400327340ustar00rootroot00000000000000/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains interfaces for stack API. *

* A stack is a last-in-first-out data structure. *

*

* This package contains 3 interfaces: *

    *
  • * {@link com.gs.collections.api.stack.MutableStack} - a mutable stack API. *
  • *
  • * {@link com.gs.collections.api.stack.ImmutableStack} - the non-modifiable equivalent interface to {@link com.gs.collections.api.stack.MutableStack}. *
  • *
  • * {@link com.gs.collections.api.stack.StackIterable} - a read-only stack API. *
  • *
*

*/ package com.gs.collections.api.stack; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/stack/primitive/000077500000000000000000000000001234315411400315545ustar00rootroot00000000000000package-info.java000066400000000000000000000015441234315411400346700ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/stack/primitive/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains mutable and immutable primitive stack API. *

* A primitive stack is similar to {@link com.gs.collections.api.stack.StackIterable} and is memory-optimized for primitives. *

*/ package com.gs.collections.api.stack.primitive; gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/tuple/000077500000000000000000000000001234315411400275705ustar00rootroot00000000000000gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/tuple/Pair.java000066400000000000000000000020301234315411400313210ustar00rootroot00000000000000/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.tuple; import java.io.Serializable; import java.util.Map; /** * A Pair is a container that holds two related objects. It is the equivalent of an Association in Smalltalk, or an * implementation of Map.Entry in the JDK. */ public interface Pair extends Serializable, Comparable> { T1 getOne(); T2 getTwo(); void put(Map map); Map.Entry toEntry(); } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/tuple/Twin.java000066400000000000000000000012661234315411400313610ustar00rootroot00000000000000/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.api.tuple; public interface Twin extends Pair { } gs-collections-5.1.0/collections-api/src/main/java/com/gs/collections/api/tuple/package-info.java000066400000000000000000000022201234315411400327530ustar00rootroot00000000000000/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains the {@link com.gs.collections.api.tuple.Pair} and {@link com.gs.collections.api.tuple.Twin} interfaces. *

* A tuple is a container used to hold two related objects. *

*

* This package contains 2 interfaces: *

    *
  • * {@link com.gs.collections.api.tuple.Pair} - a container that holds two related objects. *
  • *
  • * {@link com.gs.collections.api.tuple.Twin} - a Pair that has the same type for both items. *
  • *
*

*/ package com.gs.collections.api.tuple; gs-collections-5.1.0/collections-parent.iml000066400000000000000000000011071234315411400207470ustar00rootroot00000000000000 gs-collections-5.1.0/collections-testutils/000077500000000000000000000000001234315411400210145ustar00rootroot00000000000000gs-collections-5.1.0/collections-testutils/.classpath000066400000000000000000000007701234315411400230030ustar00rootroot00000000000000 gs-collections-5.1.0/collections-testutils/.project000066400000000000000000000010501234315411400224570ustar00rootroot00000000000000 collections-testutils org.eclipse.jdt.core.javabuilder org.maven.ide.eclipse.maven2Builder org.eclipse.jdt.core.javanature org.maven.ide.eclipse.maven2Nature gs-collections-5.1.0/collections-testutils/.settings/000077500000000000000000000000001234315411400227325ustar00rootroot00000000000000gs-collections-5.1.0/collections-testutils/.settings/org.eclipse.jdt.core.prefs000066400000000000000000000557521234315411400277320ustar00rootroot00000000000000# # Copyright 2011 Goldman Sachs. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #Thu Jun 04 15:26:03 EDT 2009 eclipse.preferences.version=1 org.eclipse.jdt.core.codeComplete.argumentPrefixes= org.eclipse.jdt.core.codeComplete.argumentSuffixes= org.eclipse.jdt.core.codeComplete.fieldPrefixes= org.eclipse.jdt.core.codeComplete.fieldSuffixes= org.eclipse.jdt.core.codeComplete.localPrefixes= org.eclipse.jdt.core.codeComplete.localSuffixes= org.eclipse.jdt.core.codeComplete.staticFieldPrefixes= org.eclipse.jdt.core.codeComplete.staticFieldSuffixes= org.eclipse.jdt.core.codeComplete.staticFinalFieldPrefixes= org.eclipse.jdt.core.codeComplete.staticFinalFieldSuffixes= org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.compliance=1.5 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.source=1.5 org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_assignment=16 org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16 org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 org.eclipse.jdt.core.formatter.alignment_for_enum_constants=16 org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16 org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16 org.eclipse.jdt.core.formatter.blank_lines_after_imports=1 org.eclipse.jdt.core.formatter.blank_lines_after_package=1 org.eclipse.jdt.core.formatter.blank_lines_before_field=0 org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0 org.eclipse.jdt.core.formatter.blank_lines_before_imports=1 org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1 org.eclipse.jdt.core.formatter.blank_lines_before_method=1 org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1 org.eclipse.jdt.core.formatter.blank_lines_before_package=0 org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1 org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1 org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=next_line org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=next_line org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line org.eclipse.jdt.core.formatter.brace_position_for_block=next_line org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=next_line org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=next_line org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=next_line org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=next_line org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=next_line org.eclipse.jdt.core.formatter.brace_position_for_switch=next_line org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=next_line org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false org.eclipse.jdt.core.formatter.comment.format_block_comments=true org.eclipse.jdt.core.formatter.comment.format_header=false org.eclipse.jdt.core.formatter.comment.format_html=true org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true org.eclipse.jdt.core.formatter.comment.format_line_comments=true org.eclipse.jdt.core.formatter.comment.format_source_code=true org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true org.eclipse.jdt.core.formatter.comment.indent_root_tags=true org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert org.eclipse.jdt.core.formatter.comment.line_length=120 org.eclipse.jdt.core.formatter.compact_else_if=true org.eclipse.jdt.core.formatter.continuation_indentation=2 org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2 org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true org.eclipse.jdt.core.formatter.indent_empty_lines=false org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=true org.eclipse.jdt.core.formatter.indentation.size=4 org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member=insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=insert org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=insert org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=insert org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=insert org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=insert org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert org.eclipse.jdt.core.formatter.join_lines_in_comments=true org.eclipse.jdt.core.formatter.join_wrapped_lines=false org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false org.eclipse.jdt.core.formatter.lineSplit=120 org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=true org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0 org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true org.eclipse.jdt.core.formatter.tabulation.char=space org.eclipse.jdt.core.formatter.tabulation.size=4 org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true gs-collections-5.1.0/collections-testutils/.settings/org.eclipse.jdt.ui.prefs000066400000000000000000000250131234315411400274020ustar00rootroot00000000000000# # Copyright 2011 Goldman Sachs. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #Fri Feb 12 11:50:45 EST 2010 cleanup.add_default_serial_version_id=false cleanup.add_generated_serial_version_id=true cleanup.add_missing_annotations=true cleanup.add_missing_deprecated_annotations=true cleanup.add_missing_methods=false cleanup.add_missing_nls_tags=false cleanup.add_missing_override_annotations=true cleanup.add_serial_version_id=false cleanup.always_use_blocks=true cleanup.always_use_parentheses_in_expressions=false cleanup.always_use_this_for_non_static_field_access=true cleanup.always_use_this_for_non_static_method_access=true cleanup.convert_to_enhanced_for_loop=false cleanup.correct_indentation=false cleanup.format_source_code=false cleanup.format_source_code_changes_only=false cleanup.make_local_variable_final=false cleanup.make_parameters_final=false cleanup.make_private_fields_final=true cleanup.make_type_abstract_if_missing_method=false cleanup.make_variable_declarations_final=true cleanup.never_use_blocks=false cleanup.never_use_parentheses_in_expressions=true cleanup.organize_imports=true cleanup.qualify_static_field_accesses_with_declaring_class=false cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true cleanup.qualify_static_member_accesses_with_declaring_class=true cleanup.qualify_static_method_accesses_with_declaring_class=false cleanup.remove_private_constructors=true cleanup.remove_trailing_whitespaces=true cleanup.remove_trailing_whitespaces_all=true cleanup.remove_trailing_whitespaces_ignore_empty=false cleanup.remove_unnecessary_casts=true cleanup.remove_unnecessary_nls_tags=true cleanup.remove_unused_imports=true cleanup.remove_unused_local_variables=false cleanup.remove_unused_private_fields=true cleanup.remove_unused_private_members=false cleanup.remove_unused_private_methods=true cleanup.remove_unused_private_types=true cleanup.sort_members=false cleanup.sort_members_all=false cleanup.use_blocks=true cleanup.use_blocks_only_for_return_and_throw=false cleanup.use_parentheses_in_expressions=false cleanup.use_this_for_non_static_field_access=true cleanup.use_this_for_non_static_field_access_only_if_necessary=false cleanup.use_this_for_non_static_method_access=true cleanup.use_this_for_non_static_method_access_only_if_necessary=false cleanup_profile=_Collections cleanup_settings_version=2 eclipse.preferences.version=1 editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true formatter_profile=_Collections formatter_settings_version=11 org.eclipse.jdt.ui.ignorelowercasenames=false org.eclipse.jdt.ui.importorder=java;javax; org.eclipse.jdt.ui.javadoc=true org.eclipse.jdt.ui.ondemandthreshold=99 org.eclipse.jdt.ui.staticondemandthreshold=99 org.eclipse.jdt.ui.text.custom_code_templates= sp_cleanup.add_default_serial_version_id=true sp_cleanup.add_generated_serial_version_id=false sp_cleanup.add_missing_annotations=true sp_cleanup.add_missing_deprecated_annotations=true sp_cleanup.add_missing_methods=false sp_cleanup.add_missing_nls_tags=false sp_cleanup.add_missing_override_annotations=true sp_cleanup.add_serial_version_id=false sp_cleanup.always_use_blocks=true sp_cleanup.always_use_parentheses_in_expressions=false sp_cleanup.always_use_this_for_non_static_field_access=true sp_cleanup.always_use_this_for_non_static_method_access=true sp_cleanup.convert_to_enhanced_for_loop=false sp_cleanup.correct_indentation=false sp_cleanup.format_source_code=false sp_cleanup.format_source_code_changes_only=true sp_cleanup.make_local_variable_final=false sp_cleanup.make_parameters_final=false sp_cleanup.make_private_fields_final=true sp_cleanup.make_type_abstract_if_missing_method=false sp_cleanup.make_variable_declarations_final=true sp_cleanup.never_use_blocks=false sp_cleanup.never_use_parentheses_in_expressions=true sp_cleanup.on_save_use_additional_actions=true sp_cleanup.organize_imports=true sp_cleanup.qualify_static_field_accesses_with_declaring_class=false sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true sp_cleanup.qualify_static_member_accesses_with_declaring_class=true sp_cleanup.qualify_static_method_accesses_with_declaring_class=false sp_cleanup.remove_private_constructors=true sp_cleanup.remove_trailing_whitespaces=true sp_cleanup.remove_trailing_whitespaces_all=true sp_cleanup.remove_trailing_whitespaces_ignore_empty=false sp_cleanup.remove_unnecessary_casts=true sp_cleanup.remove_unnecessary_nls_tags=true sp_cleanup.remove_unused_imports=true sp_cleanup.remove_unused_local_variables=false sp_cleanup.remove_unused_private_fields=true sp_cleanup.remove_unused_private_members=false sp_cleanup.remove_unused_private_methods=true sp_cleanup.remove_unused_private_types=true sp_cleanup.sort_members=false sp_cleanup.sort_members_all=false sp_cleanup.use_blocks=true sp_cleanup.use_blocks_only_for_return_and_throw=false sp_cleanup.use_parentheses_in_expressions=false sp_cleanup.use_this_for_non_static_field_access=true sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=false sp_cleanup.use_this_for_non_static_method_access=true sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=false gs-collections-5.1.0/collections-testutils/.settings/org.maven.ide.eclipse.prefs000066400000000000000000000015151234315411400300540ustar00rootroot00000000000000# # Copyright 2011 Goldman Sachs. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #Wed Feb 03 15:04:25 EST 2010 activeProfiles= eclipse.preferences.version=1 fullBuildGoals=process-test-resources includeModules=false resolveWorkspaceProjects=true resourceFilterGoals=process-resources resources\:testResources skipCompilerPlugin=true version=1 gs-collections-5.1.0/collections-testutils/build.xml000066400000000000000000000022201234315411400226310ustar00rootroot00000000000000 gs-collections-5.1.0/collections-testutils/gs-collections-testutils.iml000066400000000000000000000024121234315411400265010ustar00rootroot00000000000000 gs-collections-5.1.0/collections-testutils/ivy.xml000066400000000000000000000051211234315411400223440ustar00rootroot00000000000000 gs-collections-5.1.0/collections-testutils/pom.xml000066400000000000000000000341671234315411400223440ustar00rootroot00000000000000 4.0.0 com.goldmansachs gs-collections-testutils 5.1.0 bundle Goldman Sachs Collections Test Utilities GS Collections is a collections framework for Java. It has JDK-compatible List, Set and Map implementations with a rich API and set of utility classes that work with any JDK compatible Collections, Arrays, Maps or Strings. The iteration protocol was inspired by the Smalltalk collection framework. https://github.com/goldmansachs/gs-collections 2004 The Apache Software License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0.txt repo https://github.com/goldmansachs/gs-collections scm:git:https://github.com/goldmansachs/gs-collections.git scm:git:https://github.com/goldmansachs/gs-collections.git Craig P. Motlin craig.motlin@gs.com Donald Raab donald.raab@gs.com Bhavana Hindupur bhavana.hindupur@gs.com UTF-8 3.2.2 2.10 ${project.basedir}/target/site/clover/clover.xml ${project.basedir}/target/clover/surefire-reports ${build.is.personal} 3.0 com.goldmansachs gs-collections-api 5.1.0 com.goldmansachs gs-collections 5.1.0 commons-codec commons-codec 1.8 junit junit 4.11 compile maven-antrun-plugin 1.7 maven-assembly-plugin 2.4 maven-clean-plugin 2.5 maven-compiler-plugin 2.5.1 maven-dependency-plugin 2.8 maven-deploy-plugin 2.8.1 maven-install-plugin 2.5.1 maven-jar-plugin 2.4 maven-javadoc-plugin 2.9.1 maven-release-plugin 2.4.2 maven-resources-plugin 2.6 maven-site-plugin 3.3 maven-source-plugin 2.2.1 maven-enforcer-plugin 1.3.1 org.codehaus.mojo versions-maven-plugin 2.1 org.codehaus.mojo clirr-maven-plugin 2.6.1 org.apache.felix maven-bundle-plugin 2.4.0 org.scala-tools maven-scala-plugin 2.15.2 maven-surefire-plugin 2.16 maven-project-info-reports-plugin 2.7 com.fortify.ps.maven.plugin maven-sca-plugin 2.6 maven-compiler-plugin 1.5 1.5 maven-surefire-plugin **/*Test.java -XX:-OmitStackTraceInFastThrow random never maven-source-plugin 2.1.2 verify jar-no-fork org.apache.felix maven-bundle-plugin 2.4.0 true com.gs.collections.impl.test J2SE-1.5,JavaSE-1.6 net.jcip.annotations;resolution:=optional,* ${project.version} org.codehaus.mojo sonar-maven-plugin 2.2 maven-checkstyle-plugin ${checkstyle.version} checkstyle-configuration.xml true true org.codehaus.mojo findbugs-maven-plugin 2.5.3 Max Default true true findbugs-exclude.xml maven-javadoc-plugin Goldman Sachs Collections Test Utilities - ${project.version} Goldman Sachs Collections Test Utilities - ${project.version} public http://java.sun.com/j2se/1.5.0/docs/api/ ${project.version} -Xdoclint:none maven-enforcer-plugin enforce 1.7.0 3.0.2 enforce org.codehaus.mojo clirr-maven-plugin 2.5 com.goldmansachs gs-collections-testutils 5.1.0 ${project.build.directory}/clirr.txt clover com.atlassian.maven.plugins maven-clover2-plugin ${clover.version} ${clover.license} @deprecated true ${user.home}/clover/${project.artifactId} true block gs-collections-5.1.0/collections-testutils/src/000077500000000000000000000000001234315411400216035ustar00rootroot00000000000000gs-collections-5.1.0/collections-testutils/src/main/000077500000000000000000000000001234315411400225275ustar00rootroot00000000000000gs-collections-5.1.0/collections-testutils/src/main/java/000077500000000000000000000000001234315411400234505ustar00rootroot00000000000000gs-collections-5.1.0/collections-testutils/src/main/java/com/000077500000000000000000000000001234315411400242265ustar00rootroot00000000000000gs-collections-5.1.0/collections-testutils/src/main/java/com/gs/000077500000000000000000000000001234315411400246375ustar00rootroot00000000000000gs-collections-5.1.0/collections-testutils/src/main/java/com/gs/collections/000077500000000000000000000000001234315411400271555ustar00rootroot00000000000000gs-collections-5.1.0/collections-testutils/src/main/java/com/gs/collections/impl/000077500000000000000000000000001234315411400301165ustar00rootroot00000000000000gs-collections-5.1.0/collections-testutils/src/main/java/com/gs/collections/impl/test/000077500000000000000000000000001234315411400310755ustar00rootroot00000000000000SerializeTestHelper.java000066400000000000000000000057131234315411400356160ustar00rootroot00000000000000gs-collections-5.1.0/collections-testutils/src/main/java/com/gs/collections/impl/test/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; public final class SerializeTestHelper { private SerializeTestHelper() { throw new AssertionError("Suppress default constructor for noninstantiability"); } public static T serializeDeserialize(T sourceObject) { byte[] pileOfBytes = serialize(sourceObject); return (T) deserialize(pileOfBytes); } public static byte[] serialize(T sourceObject) { ByteArrayOutputStream baos = SerializeTestHelper.getByteArrayOutputStream(sourceObject); return baos.toByteArray(); } public static ByteArrayOutputStream getByteArrayOutputStream(T sourceObject) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { writeObjectToStream(sourceObject, baos); } catch (IOException e) { Verify.fail("Failed to marshal an object", e); } return baos; } private static void writeObjectToStream(Object sourceObject, ByteArrayOutputStream baos) throws IOException { ObjectOutputStream objectOutputStream = new ObjectOutputStream(baos); try { objectOutputStream.writeObject(sourceObject); objectOutputStream.flush(); objectOutputStream.close(); } finally { objectOutputStream.close(); } } private static Object readOneObject(ByteArrayInputStream bais) throws IOException, ClassNotFoundException { ObjectInputStream objectStream = new ObjectInputStream(bais); try { return objectStream.readObject(); } finally { objectStream.close(); } } public static Object deserialize(byte[] pileOfBytes) { ByteArrayInputStream bais = new ByteArrayInputStream(pileOfBytes); try { return readOneObject(bais); } catch (ClassNotFoundException e) { Verify.fail("Failed to unmarshal an object", e); } catch (IOException e) { Verify.fail("Failed to unmarshal an object", e); } return null; } } gs-collections-5.1.0/collections-testutils/src/main/java/com/gs/collections/impl/test/Verify.java000066400000000000000000003121721234315411400332120ustar00rootroot00000000000000/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.ObjectStreamClass; import java.io.Serializable; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import java.util.SortedSet; import java.util.concurrent.Callable; import com.gs.collections.api.PrimitiveIterable; import com.gs.collections.api.bag.sorted.SortedBag; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.collection.ImmutableCollection; import com.gs.collections.api.list.ImmutableList; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.map.ImmutableMap; import com.gs.collections.api.map.MutableMap; import com.gs.collections.api.map.sorted.SortedMapIterable; import com.gs.collections.api.multimap.Multimap; import com.gs.collections.api.set.ImmutableSet; import com.gs.collections.api.set.MutableSet; import com.gs.collections.impl.block.factory.Comparators; import com.gs.collections.impl.block.factory.Predicates; import com.gs.collections.impl.factory.Lists; import com.gs.collections.impl.factory.Sets; import com.gs.collections.impl.map.mutable.UnifiedMap; import com.gs.collections.impl.set.mutable.UnifiedSet; import com.gs.collections.impl.tuple.ImmutableEntry; import com.gs.collections.impl.utility.ArrayIterate; import com.gs.collections.impl.utility.Iterate; import org.apache.commons.codec.binary.Base64; import org.junit.Assert; /** * An extension of the {@link Assert} class, which adds useful additional "assert" methods. * You can import this class instead of Assert, and use it thus, e.g.: *
 *     Verify.assertEquals("fred", name);  // from original Assert class
 *     Verify.assertContains("fred", nameList);  // from new extensions
 *     Verify.assertBefore("fred", "jim", orderedNamesList);  // from new extensions
 * 
*/ public final class Verify extends Assert { private static final int MAX_DIFFERENCES = 5; private static final byte[] LINE_SEPARATOR = {'\n'}; private Verify() { throw new AssertionError("Suppress default constructor for noninstantiability"); } /** * Mangles the stack trace of {@link AssertionError} so that it looks like its been thrown from the line that * called to a custom assertion. *

*

This method behaves identically to {@link #throwMangledException(AssertionError, int)} and is provided * for convenience for assert methods that only want to pop two stack frames. The only time that you would want to * call the other {@link #throwMangledException(AssertionError, int)} method is if you have a custom assert * that calls another custom assert i.e. the source line calling the custom asserts is more than two stack frames * away

* * @param e The exception to mangle. * @see #throwMangledException(AssertionError, int) */ public static void throwMangledException(AssertionError e) { /* * Note that we actually remove 3 frames from the stack trace because * we wrap the real method doing the work: e.fillInStackTrace() will * include us in the exceptions stack frame. */ Verify.throwMangledException(e, 3); } /** *

Mangles the stack trace of {@link AssertionError} so that it looks like * its been thrown from the line that called to a custom assertion.

*

*

This is useful for when you are in a debugging session and you want to go to the source * of the problem in the test case quickly. The regular use case for this would be something * along the lines of:

*
     * public class TestFoo extends junit.framework.TestCase
     * {
     *   public void testFoo() throws Exception
     *   {
     *     Foo foo = new Foo();
     *     ...
     *     assertFoo(foo);
     *   }
     *
     *   // Custom assert
     *   private static void assertFoo(Foo foo)
     *   {
     *     try
     *     {
     *       assertEquals(...);
     *       ...
     *       assertSame(...);
     *     }
     *     catch (AssertionFailedException e)
     *     {
     *       AssertUtils.throwMangledException(e, 2);
     *     }
     *   }
     * }
     * 
*

*

Without the {@code try ... catch} block around lines 11-13 the stack trace following a test failure * would look a little like: *

*

     * java.lang.AssertionError: ...
     *  at TestFoo.assertFoo(TestFoo.java:11)
     *  at TestFoo.testFoo(TestFoo.java:5)
     *  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     *  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     *  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     *  at java.lang.reflect.Method.invoke(Method.java:324)
     *  ...
     * 
*

*

Note that the source of the error isn't readily apparent as the first line in the stack trace * is the code within the custom assert. If we were debugging the failure we would be more interested * in the second line of the stack trace which shows us where in our tests the assert failed.

*

*

With the {@code try ... catch} block around lines 11-13 the stack trace would look like the * following:

*

*

     * java.lang.AssertionError: ...
     *  at TestFoo.testFoo(TestFoo.java:5)
     *  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     *  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     *  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     *  at java.lang.reflect.Method.invoke(Method.java:324)
     *  ...
     * 
*

*

Here the source of the error is more visible as we can instantly see that the testFoo test is * failing at line 5.

* * @param e The exception to mangle. * @param framesToPop The number of frames to remove from the stack trace. * @throws AssertionError that was given as an argument with its stack trace mangled. */ public static void throwMangledException(AssertionError e, int framesToPop) { e.fillInStackTrace(); StackTraceElement[] stackTrace = e.getStackTrace(); StackTraceElement[] newStackTrace = new StackTraceElement[stackTrace.length - framesToPop]; System.arraycopy(stackTrace, framesToPop, newStackTrace, 0, newStackTrace.length); e.setStackTrace(newStackTrace); throw e; } public static void fail(String message, Throwable cause) { AssertionError failedException = new AssertionError(message); failedException.initCause(cause); Verify.throwMangledException(failedException); } /** * Assert that two items are not the same. If one item is null, the the other must be non-null. * * @deprecated in 3.0. Use {@link Assert#assertNotEquals(String, Object, Object)} in JUnit 4.11 instead. */ @Deprecated public static void assertNotEquals(String itemsName, Object item1, Object item2) { try { if (Comparators.nullSafeEquals(item1, item2) || Comparators.nullSafeEquals(item2, item1)) { Assert.fail(itemsName + " should not be equal, item1:<" + item1 + ">, item2:<" + item2 + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that two items are not the same. If one item is null, the the other must be non-null. * * @deprecated in 3.0. Use {@link Assert#assertNotEquals(Object, Object)} in JUnit 4.11 instead. */ @Deprecated public static void assertNotEquals(Object item1, Object item2) { try { Verify.assertNotEquals("items", item1, item2); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Asserts that two Strings are not equal. * * @deprecated in 3.0. Use {@link Assert#assertNotEquals(String, Object, Object)} in JUnit 4.11 instead. */ @Deprecated public static void assertNotEquals(String itemName, String notExpected, String actual) { try { if (Comparators.nullSafeEquals(notExpected, actual)) { Assert.fail(itemName + " should not equal:<" + notExpected + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Asserts that two Strings are not equal. * * @deprecated in 3.0. Use {@link Assert#assertNotEquals(Object, Object)} in JUnit 4.11 instead. */ @Deprecated public static void assertNotEquals(String notExpected, String actual) { try { Verify.assertNotEquals("string", notExpected, actual); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Asserts that two doubles are not equal concerning a delta. If the expected value is infinity then the delta value * is ignored. * * @deprecated in 3.0. Use {@link Assert#assertNotEquals(String, double, double, double)} in JUnit 4.11 instead. */ @Deprecated public static void assertNotEquals(String itemName, double notExpected, double actual, double delta) { // handle infinity specially since subtracting to infinite values gives NaN and the // the following test fails try { //noinspection FloatingPointEquality if (Double.isInfinite(notExpected) && notExpected == actual || Math.abs(notExpected - actual) <= delta) { Assert.fail(itemName + " should not be equal:<" + notExpected + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Asserts that two doubles are not equal concerning a delta. If the expected value is infinity then the delta value * is ignored. * * @deprecated in 3.0. Use {@link Assert#assertNotEquals(double, double, double)} in JUnit 4.11 instead. */ @Deprecated public static void assertNotEquals(double notExpected, double actual, double delta) { try { Verify.assertNotEquals("double", notExpected, actual, delta); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Asserts that two floats are not equal concerning a delta. If the expected value is infinity then the delta value * is ignored. */ public static void assertNotEquals(String itemName, float notExpected, float actual, float delta) { try { // handle infinity specially since subtracting to infinite values gives NaN and the // the following test fails //noinspection FloatingPointEquality if (Float.isInfinite(notExpected) && notExpected == actual || Math.abs(notExpected - actual) <= delta) { Assert.fail(itemName + " should not be equal:<" + notExpected + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Asserts that two floats are not equal concerning a delta. If the expected value is infinity then the delta value * is ignored. */ public static void assertNotEquals(float expected, float actual, float delta) { try { Verify.assertNotEquals("float", expected, actual, delta); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Asserts that two longs are not equal. * * @deprecated in 3.0. Use {@link Assert#assertNotEquals(String, long, long)} in JUnit 4.11 instead. */ @Deprecated public static void assertNotEquals(String itemName, long notExpected, long actual) { try { if (notExpected == actual) { Assert.fail(itemName + " should not be equal:<" + notExpected + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Asserts that two longs are not equal. * * @deprecated in 3.0. Use {@link Assert#assertNotEquals(long, long)} in JUnit 4.11 instead. */ @Deprecated public static void assertNotEquals(long notExpected, long actual) { try { Verify.assertNotEquals("long", notExpected, actual); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Asserts that two booleans are not equal. */ public static void assertNotEquals(String itemName, boolean notExpected, boolean actual) { try { if (notExpected == actual) { Assert.fail(itemName + " should not be equal:<" + notExpected + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Asserts that two booleans are not equal. */ public static void assertNotEquals(boolean notExpected, boolean actual) { try { Verify.assertNotEquals("boolean", notExpected, actual); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Asserts that two bytes are not equal. */ public static void assertNotEquals(String itemName, byte notExpected, byte actual) { try { if (notExpected == actual) { Assert.fail(itemName + " should not be equal:<" + notExpected + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Asserts that two bytes are not equal. */ public static void assertNotEquals(byte notExpected, byte actual) { try { Verify.assertNotEquals("byte", notExpected, actual); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Asserts that two chars are not equal. */ public static void assertNotEquals(String itemName, char notExpected, char actual) { try { if (notExpected == actual) { Assert.fail(itemName + " should not be equal:<" + notExpected + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Asserts that two chars are not equal. */ public static void assertNotEquals(char notExpected, char actual) { try { Verify.assertNotEquals("char", notExpected, actual); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Asserts that two shorts are not equal. */ public static void assertNotEquals(String itemName, short notExpected, short actual) { try { if (notExpected == actual) { Assert.fail(itemName + " should not be equal:<" + notExpected + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Asserts that two shorts are not equal. */ public static void assertNotEquals(short notExpected, short actual) { try { Verify.assertNotEquals("short", notExpected, actual); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Asserts that two ints are not equal. * * @deprecated in 3.0. Use {@link Assert#assertNotEquals(String, long, long)} in JUnit 4.11 instead. */ @Deprecated public static void assertNotEquals(String itemName, int notExpected, int actual) { try { if (notExpected == actual) { Assert.fail(itemName + " should not be equal:<" + notExpected + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Asserts that two ints are not equal. * * @deprecated in 3.0. Use {@link Assert#assertNotEquals(long, long)} in JUnit 4.11 instead. */ @Deprecated public static void assertNotEquals(int notExpected, int actual) { try { Verify.assertNotEquals("int", notExpected, actual); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link Collection} is empty. */ public static void assertEmpty(Collection actualCollection) { try { Verify.assertEmpty("collection", actualCollection); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link Collection} is empty. */ public static void assertEmpty(String collectionName, Collection actualCollection) { try { Verify.assertObjectNotNull(collectionName, actualCollection); if (!actualCollection.isEmpty()) { Assert.fail(collectionName + " should be empty; actual size:<" + actualCollection.size() + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link PrimitiveIterable} is empty. */ public static void assertEmpty(PrimitiveIterable primitiveIterable) { try { Verify.assertEmpty("primitiveIterable", primitiveIterable); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link PrimitiveIterable} is empty. */ public static void assertEmpty(String iterableName, PrimitiveIterable primitiveIterable) { try { Verify.assertObjectNotNull(iterableName, primitiveIterable); if (!primitiveIterable.isEmpty()) { Assert.fail(iterableName + " should be empty; actual size:<" + primitiveIterable.size() + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link Iterable} is empty. */ public static void assertIterableEmpty(Iterable iterable) { try { Verify.assertIterableEmpty("iterable", iterable); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link Iterable} is empty. */ public static void assertIterableEmpty(String iterableName, Iterable iterable) { try { Verify.assertObjectNotNull(iterableName, iterable); if (!Iterate.isEmpty(iterable)) { Assert.fail(iterableName + " should be empty; actual size:<" + Iterate.sizeOf(iterable) + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given object is an instanceof expectedClassType. */ public static void assertInstanceOf(Class expectedClassType, Object actualObject) { try { Verify.assertInstanceOf(actualObject.getClass().getName(), expectedClassType, actualObject); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given object is an instanceof expectedClassType. */ public static void assertInstanceOf(String objectName, Class expectedClassType, Object actualObject) { try { if (!expectedClassType.isInstance(actualObject)) { Assert.fail(objectName + " is not an instance of " + expectedClassType.getName()); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link Map} is empty. */ public static void assertEmpty(Map actualMap) { try { Verify.assertEmpty("map", actualMap); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link Multimap} is empty. */ public static void assertEmpty(Multimap actualMultimap) { try { Verify.assertEmpty("multimap", actualMultimap); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link Multimap} is empty. */ public static void assertEmpty(String multimapName, Multimap actualMultimap) { try { Verify.assertObjectNotNull(multimapName, actualMultimap); if (!actualMultimap.isEmpty()) { Assert.fail(multimapName + " should be empty; actual size:<" + actualMultimap.size() + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link Map} is empty. */ public static void assertEmpty(String mapName, Map actualMap) { try { Verify.assertObjectNotNull(mapName, actualMap); if (!actualMap.isEmpty()) { Assert.fail(mapName + " should be empty; actual size:<" + actualMap.size() + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertEmpty(ImmutableMap actualImmutableMap) { try { Verify.assertEmpty("immutable map", actualImmutableMap); } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertEmpty(String mapName, ImmutableMap actualImmutableMap) { try { Verify.assertObjectNotNull(mapName, actualImmutableMap); if (!actualImmutableMap.isEmpty()) { Assert.fail(mapName + " should be empty; actual size:<" + actualImmutableMap.size() + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link Collection} is not empty. */ public static void assertNotEmpty(Collection actualCollection) { try { Verify.assertNotEmpty("collection", actualCollection); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link Collection} is not empty. */ public static void assertNotEmpty(String collectionName, Collection actualCollection) { try { Verify.assertObjectNotNull(collectionName, actualCollection); Assert.assertFalse(collectionName + " should be non-empty, but was empty", actualCollection.isEmpty()); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link PrimitiveIterable} is not empty. */ public static void assertNotEmpty(PrimitiveIterable primitiveIterable) { try { Verify.assertNotEmpty("primitiveIterable", primitiveIterable); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link PrimitiveIterable} is not empty. */ public static void assertNotEmpty(String iterableName, PrimitiveIterable primitiveIterable) { try { Verify.assertObjectNotNull(iterableName, primitiveIterable); Assert.assertFalse(iterableName + " should be non-empty, but was empty", primitiveIterable.isEmpty()); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link Iterable} is not empty. */ public static void assertIterableNotEmpty(Iterable iterable) { try { Verify.assertIterableNotEmpty("iterable", iterable); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link Iterable} is not empty. */ public static void assertIterableNotEmpty(String iterableName, Iterable iterable) { try { Verify.assertObjectNotNull(iterableName, iterable); Assert.assertFalse(iterableName + " should be non-empty, but was empty", Iterate.isEmpty(iterable)); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link Map} is not empty. */ public static void assertNotEmpty(Map actualMap) { try { Verify.assertNotEmpty("map", actualMap); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link Map} is not empty. */ public static void assertNotEmpty(String mapName, Map actualMap) { try { Verify.assertObjectNotNull(mapName, actualMap); Assert.assertFalse(mapName + " should be non-empty, but was empty", actualMap.isEmpty()); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link Multimap} is not empty. */ public static void assertNotEmpty(Multimap actualMultimap) { try { Verify.assertNotEmpty("multimap", actualMultimap); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link Multimap} is not empty. */ public static void assertNotEmpty(String multimapName, Multimap actualMultimap) { try { Verify.assertObjectNotNull(multimapName, actualMultimap); Assert.assertTrue(multimapName + " should be non-empty, but was empty", actualMultimap.notEmpty()); } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertNotEmpty(String itemsName, T[] items) { try { Verify.assertObjectNotNull(itemsName, items); Verify.assertNotEquals(itemsName, 0, items.length); } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertNotEmpty(T[] items) { try { Verify.assertNotEmpty("items", items); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert the size of the given array. */ public static void assertSize(int expectedSize, Object[] actualArray) { try { Verify.assertSize("array", expectedSize, actualArray); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert the size of the given array. */ public static void assertSize(String arrayName, int expectedSize, Object[] actualArray) { try { Assert.assertNotNull(arrayName + " should not be null", actualArray); int actualSize = actualArray.length; if (actualSize != expectedSize) { Assert.fail("Incorrect size for " + arrayName + "; expected:<" + expectedSize + "> but was:<" + actualSize + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert the size of the given {@link Collection}. */ public static void assertSize(int expectedSize, Collection actualCollection) { try { Verify.assertSize("collection", expectedSize, actualCollection); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert the size of the given {@link Collection}. */ public static void assertSize( String collectionName, int expectedSize, Collection actualCollection) { try { Verify.assertObjectNotNull(collectionName, actualCollection); int actualSize = actualCollection.size(); if (actualSize != expectedSize) { Assert.fail("Incorrect size for " + collectionName + "; expected:<" + expectedSize + "> but was:<" + actualSize + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert the size of the given {@link PrimitiveIterable}. */ public static void assertSize(int expectedSize, PrimitiveIterable primitiveIterable) { try { Verify.assertSize("primitiveIterable", expectedSize, primitiveIterable); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert the size of the given {@link PrimitiveIterable}. */ public static void assertSize( String primitiveIterableName, int expectedSize, PrimitiveIterable actualPrimitiveIterable) { try { Verify.assertObjectNotNull(primitiveIterableName, actualPrimitiveIterable); int actualSize = actualPrimitiveIterable.size(); if (actualSize != expectedSize) { Assert.fail("Incorrect size for " + primitiveIterableName + "; expected:<" + expectedSize + "> but was:<" + actualSize + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert the size of the given {@link Iterable}. */ public static void assertIterableSize(int expectedSize, Iterable actualIterable) { try { Verify.assertIterableSize("iterable", expectedSize, actualIterable); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert the size of the given {@link Iterable}. */ public static void assertIterableSize( String iterableName, int expectedSize, Iterable actualIterable) { try { Verify.assertObjectNotNull(iterableName, actualIterable); int actualSize = Iterate.sizeOf(actualIterable); if (actualSize != expectedSize) { Assert.fail("Incorrect size for " + iterableName + "; expected:<" + expectedSize + "> but was:<" + actualSize + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert the size of the given {@link Map}. */ public static void assertSize(String mapName, int expectedSize, Map actualMap) { try { Verify.assertSize(mapName, expectedSize, actualMap.keySet()); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert the size of the given {@link Map}. */ public static void assertSize(int expectedSize, Map actualMap) { try { Verify.assertSize("map", expectedSize, actualMap); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert the size of the given {@link Multimap}. */ public static void assertSize(int expectedSize, Multimap actualMultimap) { try { Verify.assertSize("multimap", expectedSize, actualMultimap); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert the size of the given {@link Multimap}. */ public static void assertSize(String multimapName, int expectedSize, Multimap actualMultimap) { try { int actualSize = actualMultimap.size(); if (actualSize != expectedSize) { Assert.fail("Incorrect size for " + multimapName + "; expected:<" + expectedSize + "> but was:<" + actualSize + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert the size of the given {@link ImmutableMap}. */ public static void assertSize(int expectedSize, ImmutableMap actualImmutableMap) { try { Verify.assertSize("immutable map", expectedSize, actualImmutableMap); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert the size of the given {@link ImmutableMap}. */ public static void assertSize(String immutableMapName, int expectedSize, ImmutableMap actualImmutableMap) { try { int actualSize = actualImmutableMap.size(); if (actualSize != expectedSize) { Assert.fail("Incorrect size for " + immutableMapName + "; expected:<" + expectedSize + "> but was:<" + actualSize + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert the size of the given {@link ImmutableSet}. */ public static void assertSize(int expectedSize, ImmutableSet actualImmutableSet) { try { Verify.assertSize("immutable set", expectedSize, actualImmutableSet); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert the size of the given {@link ImmutableSet}. */ public static void assertSize(String immutableSetName, int expectedSize, ImmutableSet actualImmutableSet) { try { int actualSize = actualImmutableSet.size(); if (actualSize != expectedSize) { Assert.fail("Incorrect size for " + immutableSetName + "; expected:<" + expectedSize + "> but was:<" + actualSize + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@code stringToFind} is contained within the {@code stringToSearch}. */ public static void assertContains(String stringToFind, String stringToSearch) { try { Verify.assertContains("string", stringToFind, stringToSearch); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@code unexpectedString} is not contained within the {@code stringToSearch}. */ public static void assertNotContains(String unexpectedString, String stringToSearch) { try { Verify.assertNotContains("string", unexpectedString, stringToSearch); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@code stringToFind} is contained within the {@code stringToSearch}. */ public static void assertContains(String stringName, String stringToFind, String stringToSearch) { try { Assert.assertNotNull("stringToFind should not be null", stringToFind); Assert.assertNotNull("stringToSearch should not be null", stringToSearch); if (!stringToSearch.contains(stringToFind)) { Assert.fail(stringName + " did not contain stringToFind:<" + stringToFind + "> in stringToSearch:<" + stringToSearch + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@code unexpectedString} is not contained within the {@code stringToSearch}. */ public static void assertNotContains(String stringName, String unexpectedString, String stringToSearch) { try { Assert.assertNotNull("unexpectedString should not be null", unexpectedString); Assert.assertNotNull("stringToSearch should not be null", stringToSearch); if (stringToSearch.contains(unexpectedString)) { Assert.fail(stringName + " contains unexpectedString:<" + unexpectedString + "> in stringToSearch:<" + stringToSearch + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertCount( int expectedCount, Iterable iterable, Predicate predicate) { Assert.assertEquals(expectedCount, Iterate.count(iterable, predicate)); } public static void assertAllSatisfy(Iterable iterable, Predicate predicate) { try { Verify.assertAllSatisfy("The following items failed to satisfy the condition", iterable, predicate); } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertAllSatisfy(Map map, Predicate predicate) { try { Verify.assertAllSatisfy(map.values(), predicate); } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertAllSatisfy(String message, Iterable iterable, Predicate predicate) { try { MutableList unnacceptable = Lists.mutable.of(); for (T each : iterable) { if (!predicate.accept(each)) { unnacceptable.add(each); } } if (unnacceptable.notEmpty()) { Assert.fail(message + " <" + unnacceptable + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertAnySatisfy(Iterable iterable, Predicate predicate) { try { Verify.assertAnySatisfy("No items satisfied the condition", iterable, predicate); } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertAnySatisfy(Map map, Predicate predicate) { try { Verify.assertAnySatisfy(map.values(), predicate); } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertAnySatisfy(String message, Iterable iterable, Predicate predicate) { try { Assert.assertTrue(message, Predicates.anySatisfy(predicate).accept(iterable)); } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertNoneSatisfy(Iterable iterable, Predicate predicate) { try { Verify.assertNoneSatisfy("The following items satisfied the condition", iterable, predicate); } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertNoneSatisfy(Map map, Predicate predicate) { try { Verify.assertNoneSatisfy(map.values(), predicate); } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertNoneSatisfy(String message, Iterable iterable, Predicate predicate) { try { MutableList unnacceptable = Lists.mutable.of(); for (T each : iterable) { if (predicate.accept(each)) { unnacceptable.add(each); } } if (unnacceptable.notEmpty()) { Assert.fail(message + " <" + unnacceptable + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link Map} contains all of the given keys and values. */ public static void assertContainsAllKeyValues(Map actualMap, Object... keyValues) { try { Verify.assertContainsAllKeyValues("map", actualMap, keyValues); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link Map} contains all of the given keys and values. */ public static void assertContainsAllKeyValues( String mapName, Map actualMap, Object... expectedKeyValues) { try { Verify.assertNotEmpty("Expected keys/values in assertion", expectedKeyValues); if (expectedKeyValues.length % 2 != 0) { Assert.fail("Odd number of keys and values (every key must have a value)"); } Verify.assertObjectNotNull(mapName, actualMap); Verify.assertMapContainsKeys(mapName, actualMap, expectedKeyValues); Verify.assertMapContainsValues(mapName, actualMap, expectedKeyValues); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link ImmutableMap} contains all of the given keys and values. */ public static void assertContainsAllKeyValues(ImmutableMap actualImmutableMap, Object... keyValues) { try { Verify.assertContainsAllKeyValues("immutable map", actualImmutableMap, keyValues); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link ImmutableMap} contains all of the given keys and values. */ public static void assertContainsAllKeyValues( String immutableMapName, ImmutableMap actualImmutableMap, Object... expectedKeyValues) { try { Verify.assertNotEmpty("Expected keys/values in assertion", expectedKeyValues); if (expectedKeyValues.length % 2 != 0) { Assert.fail("Odd number of keys and values (every key must have a value)"); } Verify.assertObjectNotNull(immutableMapName, actualImmutableMap); Verify.assertMapContainsKeys(immutableMapName, actualImmutableMap, expectedKeyValues); Verify.assertMapContainsValues(immutableMapName, actualImmutableMap, expectedKeyValues); } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void denyContainsAny(Collection actualCollection, Object... items) { try { Verify.denyContainsAny("collection", actualCollection, items); } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertContainsNone(Collection actualCollection, Object... items) { try { Verify.denyContainsAny("collection", actualCollection, items); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link Collection} contains the given item. */ public static void assertContains(Object expectedItem, Collection actualCollection) { try { Verify.assertContains("collection", expectedItem, actualCollection); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link Collection} contains the given item. */ public static void assertContains( String collectionName, Object expectedItem, Collection actualCollection) { try { Verify.assertObjectNotNull(collectionName, actualCollection); if (!actualCollection.contains(expectedItem)) { Assert.fail(collectionName + " did not contain expectedItem:<" + expectedItem + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link ImmutableCollection} contains the given item. */ public static void assertContains(Object expectedItem, ImmutableCollection actualImmutableCollection) { try { Verify.assertContains("ImmutableCollection", expectedItem, actualImmutableCollection); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link ImmutableCollection} contains the given item. */ public static void assertContains( String immutableCollectionName, Object expectedItem, ImmutableCollection actualImmutableCollection) { try { Verify.assertObjectNotNull(immutableCollectionName, actualImmutableCollection); if (!actualImmutableCollection.contains(expectedItem)) { Assert.fail(immutableCollectionName + " did not contain expectedItem:<" + expectedItem + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertContainsAll( Iterable iterable, Object... items) { try { Verify.assertContainsAll("iterable", iterable, items); } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertContainsAll( String collectionName, final Iterable iterable, Object... items) { try { Verify.assertObjectNotNull(collectionName, iterable); Verify.assertNotEmpty("Expected items in assertion", items); Predicate containsPredicate = new Predicate() { public boolean accept(Object each) { return Iterate.contains(iterable, each); } }; if (!ArrayIterate.allSatisfy(items, containsPredicate)) { ImmutableList result = Lists.immutable.of(items).newWithoutAll(iterable); Assert.fail(collectionName + " did not contain these items" + ":<" + result + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertListsEqual(List expectedList, List actualList) { try { Verify.assertListsEqual("list", expectedList, actualList); } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertListsEqual(String listName, List expectedList, List actualList) { try { Verify.assertIterablesEqual(listName, expectedList, actualList); } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertSetsEqual(Set expectedSet, Set actualSet) { try { Verify.assertSetsEqual("set", expectedSet, actualSet); } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertSetsEqual(String setName, Set expectedSet, Set actualSet) { try { if (expectedSet == null) { Assert.assertNull(setName + " should be null", actualSet); return; } Verify.assertObjectNotNull(setName, actualSet); Verify.assertSize(setName, expectedSet.size(), actualSet); if (!actualSet.equals(expectedSet)) { MutableSet inExpectedOnlySet = UnifiedSet.newSet(expectedSet); inExpectedOnlySet.removeAll(actualSet); int numberDifferences = inExpectedOnlySet.size(); String message = setName + ": " + numberDifferences + " elements different."; if (numberDifferences > MAX_DIFFERENCES) { Assert.fail(message); } MutableSet inActualOnlySet = UnifiedSet.newSet(actualSet); inActualOnlySet.removeAll(expectedSet); junit.framework.Assert.failNotEquals(message, inExpectedOnlySet, inActualOnlySet); } } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertSortedSetsEqual(SortedSet expectedSet, SortedSet actualSet) { try { Verify.assertSortedSetsEqual("sortedSets", expectedSet, actualSet); } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertSortedSetsEqual(String setName, SortedSet expectedSet, SortedSet actualSet) { try { Verify.assertIterablesEqual(setName, expectedSet, actualSet); } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertSortedBagsEqual(SortedBag expectedBag, SortedBag actualBag) { try { Verify.assertSortedBagsEqual("sortedBags", expectedBag, actualBag); } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertSortedBagsEqual(String bagName, SortedBag expectedBag, SortedBag actualBag) { try { Verify.assertIterablesEqual(bagName, expectedBag, actualBag); } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertSortedMapsEqual(SortedMapIterable expectedMap, SortedMapIterable actualMap) { try { Verify.assertSortedMapsEqual("sortedMaps", expectedMap, actualMap); } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertSortedMapsEqual(String mapName, SortedMapIterable expectedMap, SortedMapIterable actualMap) { try { Verify.assertIterablesEqual(mapName, expectedMap, actualMap); } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertIterablesEqual(Iterable expectedIterable, Iterable actualIterable) { try { Verify.assertIterablesEqual("iterables", expectedIterable, actualIterable); } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertIterablesEqual(String iterableName, Iterable expectedIterable, Iterable actualIterable) { try { if (expectedIterable == null) { Assert.assertNull(iterableName + " should be null", actualIterable); return; } Verify.assertObjectNotNull(iterableName, actualIterable); Iterator expectedIterator = expectedIterable.iterator(); Iterator actualIterator = actualIterable.iterator(); int index = 0; while (expectedIterator.hasNext() && actualIterator.hasNext()) { Object eachExpected = expectedIterator.next(); Object eachActual = actualIterator.next(); if (!Comparators.nullSafeEquals(eachExpected, eachActual)) { junit.framework.Assert.failNotEquals(iterableName + " first differed at element [" + index + "];", eachExpected, eachActual); } index++; } Assert.assertFalse("Actual " + iterableName + " had " + index + " elements but expected " + iterableName + " had more.", expectedIterator.hasNext()); Assert.assertFalse("Expected " + iterableName + " had " + index + " elements but actual " + iterableName + " had more.", actualIterator.hasNext()); } catch (AssertionError e) { throwMangledException(e); } } public static void assertMapsEqual(Map expectedMap, Map actualMap) { try { Verify.assertMapsEqual("map", expectedMap, actualMap); } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertMapsEqual(String mapName, Map expectedMap, Map actualMap) { try { if (expectedMap == null) { Assert.assertNull(mapName + " should be null", actualMap); return; } Assert.assertNotNull(mapName + " should not be null", actualMap); Verify.assertSetsEqual(mapName + " keys", expectedMap.keySet(), actualMap.keySet()); Verify.assertSetsEqual(mapName + " entries", expectedMap.entrySet(), actualMap.entrySet()); } catch (AssertionError e) { Verify.throwMangledException(e); } } private static void assertMapContainsKeys( String mapName, Map actualMap, Object... expectedKeyValues) { try { Verify.assertNotEmpty("Expected keys/values in assertion", expectedKeyValues); MutableList expectedKeys = Lists.mutable.of(); for (int i = 0; i < expectedKeyValues.length; i += 2) { expectedKeys.add(expectedKeyValues[i]); } Verify.assertContainsAll(mapName + ".keySet()", actualMap.keySet(), expectedKeys.toArray()); } catch (AssertionError e) { Verify.throwMangledException(e); } } private static void assertMapContainsValues( String mapName, Map actualMap, Object... expectedKeyValues) { try { Verify.assertNotEmpty("Expected keys/values in assertion", expectedKeyValues); MutableMap missingEntries = UnifiedMap.newMap(); int i = 0; while (i < expectedKeyValues.length) { Object expectedKey = expectedKeyValues[i++]; Object expectedValue = expectedKeyValues[i++]; Object actualValue = actualMap.get(expectedKey); if (!Comparators.nullSafeEquals(expectedValue, actualValue)) { missingEntries.put( expectedKey, "expectedValue:<" + expectedValue + ">, actualValue:<" + actualValue + '>'); } } if (!missingEntries.isEmpty()) { StringBuilder buf = new StringBuilder(mapName + " has incorrect values for keys:["); for (Map.Entry expectedEntry : missingEntries.entrySet()) { buf.append("key:<") .append(expectedEntry.getKey()) .append(',') .append(expectedEntry.getValue()) .append("> "); } buf.append(']'); Assert.fail(buf.toString()); } } catch (AssertionError e) { Verify.throwMangledException(e); } } private static void assertMapContainsKeys( String immutableMapName, ImmutableMap actualImmutableMap, Object... expectedKeyValues) { try { Verify.assertNotEmpty("Expected keys/values in assertion", expectedKeyValues); MutableList expectedKeys = Lists.mutable.of(); for (int i = 0; i < expectedKeyValues.length; i += 2) { expectedKeys.add(expectedKeyValues[i]); } Verify.assertContainsAll(immutableMapName + ".keysView()", actualImmutableMap.keysView(), expectedKeys.toArray()); } catch (AssertionError e) { Verify.throwMangledException(e); } } private static void assertMapContainsValues( String immutableMapName, ImmutableMap actualImmutableMap, Object... expectedKeyValues) { try { Verify.assertNotEmpty("Expected keys/values in assertion", expectedKeyValues); MutableList expectedValues = Lists.mutable.of(); for (int i = 1; i < expectedKeyValues.length; i += 2) { expectedValues.add(expectedKeyValues[i]); } Verify.assertContainsAll(immutableMapName + ".valuesView()", actualImmutableMap.valuesView(), expectedValues.toArray()); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link Multimap} contains an entry with the given key and value. */ public static void assertContainsEntry( K expectedKey, V expectedValue, Multimap actualMultimap) { try { Verify.assertContainsEntry("multimap", expectedKey, expectedValue, actualMultimap); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link Multimap} contains an entry with the given key and value. */ public static void assertContainsEntry( String multimapName, K expectedKey, V expectedValue, Multimap actualMultimap) { try { Assert.assertNotNull(multimapName, actualMultimap); if (!actualMultimap.containsKeyAndValue(expectedKey, expectedValue)) { Assert.fail(multimapName + " did not contain entry: <" + expectedKey + ", " + expectedValue + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert the given {@link Multimap} contains all of the given keys and values. */ public static void assertContainsAllEntries(Multimap actualMultimap, Object... keyValues) { try { Verify.assertContainsAllEntries("multimap", actualMultimap, keyValues); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert the given {@link Multimap} contains all of the given keys and values. */ public static void assertContainsAllEntries( String multimapName, Multimap actualMultimap, Object... expectedKeyValues) { try { Verify.assertNotEmpty("Expected keys/values in assertion", expectedKeyValues); if (expectedKeyValues.length % 2 != 0) { Assert.fail("Odd number of keys and values (every key must have a value)"); } Verify.assertObjectNotNull(multimapName, actualMultimap); MutableList> missingEntries = Lists.mutable.of(); for (int i = 0; i < expectedKeyValues.length; i += 2) { Object expectedKey = expectedKeyValues[i]; Object expectedValue = expectedKeyValues[i + 1]; if (!actualMultimap.containsKeyAndValue(expectedKey, expectedValue)) { missingEntries.add(new ImmutableEntry(expectedKey, expectedValue)); } } if (!missingEntries.isEmpty()) { Assert.fail(multimapName + " is missing entries: " + missingEntries); } } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void denyContainsAny( String collectionName, Collection actualCollection, Object... items) { try { Verify.assertNotEmpty("Expected items in assertion", items); Verify.assertObjectNotNull(collectionName, actualCollection); MutableSet intersection = Sets.intersect(UnifiedSet.newSet(actualCollection), UnifiedSet.newSetWith(items)); if (intersection.notEmpty()) { Assert.fail(collectionName + " has an intersection with these items and should not :<" + intersection + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link Map} contains an entry with the given key. */ public static void assertContainsKey(Object expectedKey, Map actualMap) { try { Verify.assertContainsKey("map", expectedKey, actualMap); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link Map} contains an entry with the given key. */ public static void assertContainsKey(String mapName, Object expectedKey, Map actualMap) { try { Assert.assertNotNull(mapName, actualMap); if (!actualMap.containsKey(expectedKey)) { Assert.fail(mapName + " did not contain expectedKey:<" + expectedKey + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link ImmutableMap} contains an entry with the given key. */ public static void assertContainsKey(Object expectedKey, ImmutableMap actualImmutableMap) { try { Verify.assertContainsKey("immutable map", expectedKey, actualImmutableMap); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link ImmutableMap} contains an entry with the given key. */ public static void assertContainsKey( String immutableMapName, Object expectedKey, ImmutableMap actualImmutableMap) { try { Assert.assertNotNull(immutableMapName, actualImmutableMap); if (!actualImmutableMap.containsKey(expectedKey)) { Assert.fail(immutableMapName + " did not contain expectedKey:<" + expectedKey + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Deny that the given {@link Map} contains an entry with the given key. */ public static void denyContainsKey(Object unexpectedKey, Map actualMap) { try { Verify.denyContainsKey("map", unexpectedKey, actualMap); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Deny that the given {@link Map} contains an entry with the given key. */ public static void denyContainsKey(String mapName, Object unexpectedKey, Map actualMap) { try { Assert.assertNotNull(mapName, actualMap); if (actualMap.containsKey(unexpectedKey)) { Assert.fail(mapName + " contained unexpectedKey:<" + unexpectedKey + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link Map} contains an entry with the given key and value. */ public static void assertContainsKeyValue( Object expectedKey, Object expectedValue, Map actualMap) { try { Verify.assertContainsKeyValue("map", expectedKey, expectedValue, actualMap); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link Map} contains an entry with the given key and value. */ public static void assertContainsKeyValue( String mapName, Object expectedKey, Object expectedValue, Map actualMap) { try { Verify.assertContainsKey(mapName, expectedKey, actualMap); Object actualValue = actualMap.get(expectedKey); if (!Comparators.nullSafeEquals(actualValue, expectedValue)) { Assert.fail( mapName + " entry with expectedKey:<" + expectedKey + "> " + "did not contain expectedValue:<" + expectedValue + ">, " + "but had actualValue:<" + actualValue + '>' ); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link ImmutableMap} contains an entry with the given key and value. */ public static void assertContainsKeyValue( Object expectedKey, Object expectedValue, ImmutableMap actualImmutableMap) { try { Verify.assertContainsKeyValue("immutable map", expectedKey, expectedValue, actualImmutableMap); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link ImmutableMap} contains an entry with the given key and value. */ public static void assertContainsKeyValue( String immutableMapName, Object expectedKey, Object expectedValue, ImmutableMap actualImmutableMap) { try { Verify.assertContainsKey(immutableMapName, expectedKey, actualImmutableMap); Object actualValue = actualImmutableMap.get(expectedKey); if (!Comparators.nullSafeEquals(actualValue, expectedValue)) { Assert.fail( immutableMapName + " entry with expectedKey:<" + expectedKey + "> " + "did not contain expectedValue:<" + expectedValue + ">, " + "but had actualValue:<" + actualValue + '>' ); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link Collection} does not contain the given item. */ public static void assertNotContains(Object unexpectedItem, Collection actualCollection) { try { Verify.assertNotContains("collection", unexpectedItem, actualCollection); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link Collection} does not contain the given item. */ public static void assertNotContains( String collectionName, Object unexpectedItem, Collection actualCollection) { try { Verify.assertObjectNotNull(collectionName, actualCollection); if (actualCollection.contains(unexpectedItem)) { Assert.fail(collectionName + " should not contain unexpectedItem:<" + unexpectedItem + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link Iterable} does not contain the given item. */ public static void assertNotContains(Object unexpectedItem, Iterable iterable) { try { Verify.assertNotContains("iterable", unexpectedItem, iterable); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link Iterable} does not contain the given item. */ public static void assertNotContains( String collectionName, Object unexpectedItem, Iterable iterable) { try { Verify.assertObjectNotNull(collectionName, iterable); if (Iterate.contains(iterable, unexpectedItem)) { Assert.fail(collectionName + " should not contain unexpectedItem:<" + unexpectedItem + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link Collection} does not contain the given item. */ public static void assertNotContainsKey(Object unexpectedKey, Map actualMap) { try { Verify.assertNotContainsKey("map", unexpectedKey, actualMap); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@link Collection} does not contain the given item. */ public static void assertNotContainsKey(String mapName, Object unexpectedKey, Map actualMap) { try { Verify.assertObjectNotNull(mapName, actualMap); if (actualMap.containsKey(unexpectedKey)) { Assert.fail(mapName + " should not contain unexpectedItem:<" + unexpectedKey + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the formerItem appears before the latterItem in the given {@link Collection}. * Both the formerItem and the latterItem must appear in the collection, or this assert will fail. */ public static void assertBefore(Object formerItem, Object latterItem, List actualList) { try { Verify.assertBefore("list", formerItem, latterItem, actualList); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the formerItem appears before the latterItem in the given {@link Collection}. * {@link #assertContains(String, Object, Collection)} will be called for both the formerItem and the * latterItem, prior to the "before" assertion. */ public static void assertBefore( String listName, Object formerItem, Object latterItem, List actualList) { try { Verify.assertObjectNotNull(listName, actualList); Verify.assertNotEquals( "Bad test, formerItem and latterItem are equal, listName:<" + listName + '>', formerItem, latterItem); Verify.assertContainsAll(listName, actualList, formerItem, latterItem); int formerPosition = actualList.indexOf(formerItem); int latterPosition = actualList.indexOf(latterItem); if (latterPosition < formerPosition) { Assert.fail("Items in " + listName + " are in incorrect order; " + "expected formerItem:<" + formerItem + "> " + "to appear before latterItem:<" + latterItem + ">, but didn't"); } } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertObjectNotNull(String objectName, Object actualObject) { try { Assert.assertNotNull(objectName + " should not be null", actualObject); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@code item} is at the {@code index} in the given {@link List}. */ public static void assertItemAtIndex(Object expectedItem, int index, List list) { try { Verify.assertItemAtIndex("list", expectedItem, index, list); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@code item} is at the {@code index} in the given {@code array}. */ public static void assertItemAtIndex(Object expectedItem, int index, Object[] array) { try { Verify.assertItemAtIndex("array", expectedItem, index, array); } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertStartsWith(T[] array, T... items) { try { Verify.assertNotEmpty("Expected items in assertion", items); for (int i = 0; i < items.length; i++) { T item = items[i]; Verify.assertItemAtIndex("array", item, i, array); } } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertStartsWith(List list, T... items) { try { Verify.assertStartsWith("list", list, items); } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertStartsWith(String listName, List list, T... items) { try { Verify.assertNotEmpty("Expected items in assertion", items); for (int i = 0; i < items.length; i++) { T item = items[i]; Verify.assertItemAtIndex(listName, item, i, list); } } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertEndsWith(List list, T... items) { try { Verify.assertNotEmpty("Expected items in assertion", items); for (int i = 0; i < items.length; i++) { T item = items[i]; Verify.assertItemAtIndex("list", item, list.size() - items.length + i, list); } } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertEndsWith(T[] array, T... items) { try { Verify.assertNotEmpty("Expected items in assertion", items); for (int i = 0; i < items.length; i++) { T item = items[i]; Verify.assertItemAtIndex("array", item, array.length - items.length + i, array); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@code item} is at the {@code index} in the given {@link List}. */ public static void assertItemAtIndex( String listName, Object expectedItem, int index, List list) { try { Verify.assertObjectNotNull(listName, list); Object actualItem = list.get(index); if (!Comparators.nullSafeEquals(expectedItem, actualItem)) { Assert.assertEquals( listName + " has incorrect element at index:<" + index + '>', expectedItem, actualItem); } } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that the given {@code item} is at the {@code index} in the given {@link List}. */ public static void assertItemAtIndex( String arrayName, Object expectedItem, int index, Object[] array) { try { Assert.assertNotNull(array); Object actualItem = array[index]; if (!Comparators.nullSafeEquals(expectedItem, actualItem)) { Assert.assertEquals( arrayName + " has incorrect element at index:<" + index + '>', expectedItem, actualItem); } } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertPostSerializedEqualsAndHashCode(Object object) { try { Object deserialized = SerializeTestHelper.serializeDeserialize(object); Verify.assertEqualsAndHashCode("objects", object, deserialized); Assert.assertNotSame("not same object", object, deserialized); } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertPostSerializedIdentity(Object object) { try { Object deserialized = SerializeTestHelper.serializeDeserialize(object); Verify.assertEqualsAndHashCode("objects", object, deserialized); Assert.assertSame("same object", object, deserialized); } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertSerializedForm(String expectedBase64Form, Object actualObject) { try { Verify.assertInstanceOf(Serializable.class, actualObject); Assert.assertEquals( "Serialization was broken.", expectedBase64Form, encodeObject(actualObject)); } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertSerializedForm( long expectedSerialVersionUID, String expectedBase64Form, Object actualObject) { try { Verify.assertInstanceOf(Serializable.class, actualObject); Assert.assertEquals( "Serialization was broken.", expectedBase64Form, Verify.encodeObject(actualObject)); Object decodeToObject = Verify.decodeObject(expectedBase64Form); Assert.assertEquals( "serialVersionUID's differ", expectedSerialVersionUID, ObjectStreamClass.lookup(decodeToObject.getClass()).getSerialVersionUID()); } catch (AssertionError e) { Verify.throwMangledException(e); } } private static Object decodeObject(String expectedBase64Form) { try { byte[] bytes = Base64.decodeBase64(expectedBase64Form); return new ObjectInputStream(new ByteArrayInputStream(bytes)).readObject(); } catch (IOException e) { throw new AssertionError(e); } catch (ClassNotFoundException e) { throw new AssertionError(e); } } private static String encodeObject(Object actualObject) { try { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); objectOutputStream.writeObject(actualObject); objectOutputStream.flush(); objectOutputStream.close(); String string = new Base64(76, LINE_SEPARATOR, false).encodeAsString(byteArrayOutputStream.toByteArray()); String trimmedString = Verify.removeFinalNewline(string); return Verify.addFinalNewline(trimmedString); } catch (IOException e) { throw new AssertionError(e); } } private static String removeFinalNewline(String string) { return string.substring(0, string.length() - 1); } private static String addFinalNewline(String string) { if (string.length() % 77 == 76) { return string + '\n'; } return string; } /** * Assert that {@code objectA} and {@code objectB} are equal (via the {@link Object#equals(Object)} method, * and that they both return the same {@link Object#hashCode()}. */ public static void assertEqualsAndHashCode(Object objectA, Object objectB) { try { Verify.assertEqualsAndHashCode("objects", objectA, objectB); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Asserts that a value is negative. */ public static void assertNegative(int value) { try { Assert.assertTrue(value + " is not negative", value < 0); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Asserts that a value is positive. */ public static void assertPositive(int value) { try { Assert.assertTrue(value + " is not positive", value > 0); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Asserts that a value is positive. */ public static void assertZero(int value) { try { Assert.assertEquals(0, value); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Assert that {@code objectA} and {@code objectB} are equal (via the {@link Object#equals(Object)} method, * and that they both return the same {@link Object#hashCode()}. */ public static void assertEqualsAndHashCode(String itemNames, Object objectA, Object objectB) { try { if (objectA == null || objectB == null) { Assert.fail("Neither item should be null: <" + objectA + "> <" + objectB + '>'); } Assert.assertFalse("Neither item should equal null", objectA.equals(null)); Assert.assertFalse("Neither item should equal null", objectB.equals(null)); Verify.assertNotEquals("Neither item should equal new Object()", objectA.equals(new Object())); Verify.assertNotEquals("Neither item should equal new Object()", objectB.equals(new Object())); Assert.assertEquals("Expected " + itemNames + " to be equal.", objectA, objectA); Assert.assertEquals("Expected " + itemNames + " to be equal.", objectB, objectB); Assert.assertEquals("Expected " + itemNames + " to be equal.", objectA, objectB); Assert.assertEquals("Expected " + itemNames + " to be equal.", objectB, objectA); Assert.assertEquals( "Expected " + itemNames + " to have the same hashCode().", objectA.hashCode(), objectB.hashCode()); } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertShallowClone(Cloneable object) { try { Verify.assertShallowClone("object", object); } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertShallowClone(String itemName, Cloneable object) { try { Method method = Object.class.getDeclaredMethod("clone", (Class[]) null); method.setAccessible(true); Object clone = method.invoke(object); String prefix = itemName + " and its clone"; Assert.assertNotSame(prefix, object, clone); Verify.assertEqualsAndHashCode(prefix, object, clone); } catch (IllegalArgumentException e) { throw new AssertionError(e.getLocalizedMessage()); } catch (InvocationTargetException e) { throw new AssertionError(e.getLocalizedMessage()); } catch (SecurityException e) { throw new AssertionError(e.getLocalizedMessage()); } catch (NoSuchMethodException e) { throw new AssertionError(e.getLocalizedMessage()); } catch (IllegalAccessException e) { throw new AssertionError(e.getLocalizedMessage()); } catch (AssertionError e) { Verify.throwMangledException(e); } } public static void assertClassNonInstantiable(Class aClass) { try { try { aClass.newInstance(); Assert.fail("Expected class '" + aClass + "' to be non-instantiable"); } catch (InstantiationException e) { // pass } catch (IllegalAccessException e) { if (Verify.canInstantiateThroughReflection(aClass)) { Assert.fail("Expected constructor of non-instantiable class '" + aClass + "' to throw an exception, but didn't"); } } } catch (AssertionError e) { Verify.throwMangledException(e); } } private static boolean canInstantiateThroughReflection(Class aClass) { try { Constructor declaredConstructor = aClass.getDeclaredConstructor(); declaredConstructor.setAccessible(true); declaredConstructor.newInstance(); return true; } catch (NoSuchMethodException e) { return false; } catch (InvocationTargetException e) { return false; } catch (InstantiationException e) { return false; } catch (IllegalAccessException e) { return false; } catch (AssertionError e) { return false; } } public static void assertError(Class expectedErrorClass, Runnable code) { try { code.run(); } catch (Error ex) { try { Assert.assertSame( "Caught error of type <" + ex.getClass().getName() + ">, expected one of type <" + expectedErrorClass.getName() + '>', expectedErrorClass, ex.getClass() ); return; } catch (AssertionError e) { Verify.throwMangledException(e); } } try { Assert.fail("Block did not throw an error of type " + expectedErrorClass.getName()); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Runs the {@link Callable} {@code code} and asserts that it throws an {@code Exception} of the type * {@code expectedExceptionClass}. *

* {@code Callable} is most appropriate when a checked exception will be thrown. * If a subclass of {@link RuntimeException} will be thrown, the form * {@link #assertThrows(Class, Runnable)} may be more convenient. *

*

* e.g. *

     * Verify.assertThrows(StringIndexOutOfBoundsException.class, new Callable<String>()
     * {
     *    public String call() throws Exception
     *    {
     *        return "Craig".substring(42, 3);
     *    }
     * });
     * 
* * @see #assertThrows(Class, Runnable) */ public static void assertThrows( Class expectedExceptionClass, Callable code) { try { code.call(); } catch (Exception ex) { try { Assert.assertSame( "Caught exception of type <" + ex.getClass().getName() + ">, expected one of type <" + expectedExceptionClass.getName() + '>' + '\n' + "Exception Message: " + ex.getMessage() + '\n', expectedExceptionClass, ex.getClass() ); return; } catch (AssertionError e) { Verify.throwMangledException(e); } } try { Assert.fail("Block did not throw an exception of type " + expectedExceptionClass.getName()); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Runs the {@link Runnable} {@code code} and asserts that it throws an {@code Exception} of the type * {@code expectedExceptionClass}. *

* {@code Runnable} is most appropriate when a subclass of {@link RuntimeException} will be thrown. * If a checked exception will be thrown, the form {@link #assertThrows(Class, Callable)} may be more * convenient. *

*

* e.g. *

     * Verify.assertThrows(NullPointerException.class, new Runnable()
     * {
     *    public void run()
     *    {
     *        final Integer integer = null;
     *        LOGGER.info(integer.toString());
     *    }
     * });
     * 
* * @see #assertThrows(Class, Callable) */ public static void assertThrows( Class expectedExceptionClass, Runnable code) { try { code.run(); } catch (RuntimeException ex) { try { Assert.assertSame( "Caught exception of type <" + ex.getClass().getName() + ">, expected one of type <" + expectedExceptionClass.getName() + '>' + '\n' + "Exception Message: " + ex.getMessage() + '\n', expectedExceptionClass, ex.getClass() ); return; } catch (AssertionError e) { Verify.throwMangledException(e); } } try { Assert.fail("Block did not throw an exception of type " + expectedExceptionClass.getName()); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Runs the {@link Callable} {@code code} and asserts that it throws an {@code Exception} of the type * {@code expectedExceptionClass}, which contains a cause of type expectedCauseClass. *

* {@code Callable} is most appropriate when a checked exception will be thrown. * If a subclass of {@link RuntimeException} will be thrown, the form * {@link #assertThrowsWithCause(Class, Class, Runnable)} may be more convenient. *

*

* e.g. *

     * Verify.assertThrowsWithCause(RuntimeException.class, IOException.class, new Callable()
     * {
     *    public Void call() throws Exception
     *    {
     *        try
     *        {
     *            new File("").createNewFile();
     *        }
     *        catch (final IOException e)
     *        {
     *            throw new RuntimeException("Uh oh!", e);
     *        }
     *        return null;
     *    }
     * });
     * 
* * @see #assertThrowsWithCause(Class, Class, Runnable) */ public static void assertThrowsWithCause( Class expectedExceptionClass, Class expectedCauseClass, Callable code) { try { code.call(); } catch (Exception ex) { try { Assert.assertSame( "Caught exception of type <" + ex.getClass().getName() + ">, expected one of type <" + expectedExceptionClass.getName() + '>', expectedExceptionClass, ex.getClass() ); Throwable actualCauseClass = ex.getCause(); Assert.assertNotNull( "Caught exception with null cause, expected cause of type <" + expectedCauseClass.getName() + '>', actualCauseClass ); Assert.assertSame( "Caught exception with cause of type<" + actualCauseClass.getClass().getName() + ">, expected cause of type <" + expectedCauseClass.getName() + '>', expectedCauseClass, actualCauseClass.getClass() ); return; } catch (AssertionError e) { Verify.throwMangledException(e); } } try { Assert.fail("Block did not throw an exception of type " + expectedExceptionClass.getName()); } catch (AssertionError e) { Verify.throwMangledException(e); } } /** * Runs the {@link Runnable} {@code code} and asserts that it throws an {@code Exception} of the type * {@code expectedExceptionClass}, which contains a cause of type expectedCauseClass. *

* {@code Runnable} is most appropriate when a subclass of {@link RuntimeException} will be thrown. * If a checked exception will be thrown, the form {@link #assertThrowsWithCause(Class, Class, Callable)} * may be more convenient. *

*

* e.g. *

     * Verify.assertThrowsWithCause(RuntimeException.class, StringIndexOutOfBoundsException.class, new Runnable()
     * {
     *    public void run()
     *    {
     *        try
     *        {
     *            LOGGER.info("Craig".substring(42, 3));
     *        }
     *        catch (final StringIndexOutOfBoundsException e)
     *        {
     *            throw new RuntimeException("Uh oh!", e);
     *        }
     *    }
     * });
     * 
* * @see #assertThrowsWithCause(Class, Class, Callable) */ public static void assertThrowsWithCause( Class expectedExceptionClass, Class expectedCauseClass, Runnable code) { try { code.run(); } catch (RuntimeException ex) { try { Assert.assertSame( "Caught exception of type <" + ex.getClass().getName() + ">, expected one of type <" + expectedExceptionClass.getName() + '>', expectedExceptionClass, ex.getClass() ); Throwable actualCauseClass = ex.getCause(); Assert.assertNotNull( "Caught exception with null cause, expected cause of type <" + expectedCauseClass.getName() + '>', actualCauseClass ); Assert.assertSame( "Caught exception with cause of type<" + actualCauseClass.getClass().getName() + ">, expected cause of type <" + expectedCauseClass.getName() + '>', expectedCauseClass, actualCauseClass.getClass() ); return; } catch (AssertionError e) { Verify.throwMangledException(e); } } try { Assert.fail("Block did not throw an exception of type " + expectedExceptionClass.getName()); } catch (AssertionError e) { Verify.throwMangledException(e); } } } package-info.java000066400000000000000000000022111234315411400342010ustar00rootroot00000000000000gs-collections-5.1.0/collections-testutils/src/main/java/com/gs/collections/impl/test/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains {@link com.gs.collections.impl.test.SerializeTestHelper} and {@link com.gs.collections.impl.test.Verify} classes. *

* This package contains 2 classes: *

    *
  • * {@link com.gs.collections.impl.test.SerializeTestHelper} - contains API for testing serialization. *
  • *
  • * {@link com.gs.collections.impl.test.Verify} - an extension of the {@link org.junit.Assert} class, which adds useful additional "assert" methods. *
  • *
*

*/ package com.gs.collections.impl.test; gs-collections-5.1.0/collections-testutils/src/test/000077500000000000000000000000001234315411400225625ustar00rootroot00000000000000gs-collections-5.1.0/collections-testutils/src/test/java/000077500000000000000000000000001234315411400235035ustar00rootroot00000000000000gs-collections-5.1.0/collections-testutils/src/test/java/com/000077500000000000000000000000001234315411400242615ustar00rootroot00000000000000gs-collections-5.1.0/collections-testutils/src/test/java/com/gs/000077500000000000000000000000001234315411400246725ustar00rootroot00000000000000gs-collections-5.1.0/collections-testutils/src/test/java/com/gs/collections/000077500000000000000000000000001234315411400272105ustar00rootroot00000000000000gs-collections-5.1.0/collections-testutils/src/test/java/com/gs/collections/impl/000077500000000000000000000000001234315411400301515ustar00rootroot00000000000000gs-collections-5.1.0/collections-testutils/src/test/java/com/gs/collections/impl/test/000077500000000000000000000000001234315411400311305ustar00rootroot00000000000000AssertNotEqualsTest.java000066400000000000000000000075641234315411400356650ustar00rootroot00000000000000gs-collections-5.1.0/collections-testutils/src/test/java/com/gs/collections/impl/test/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.test; import org.junit.Test; public class AssertNotEqualsTest { private static final double DOUBLE_DELTA = 0.5d; private static final float FLOAT_DELTA = 0.5f; @Test public void objectObject() { Verify.assertNotEquals(new Object(), new Object()); } @Test public void stringObjectObject() { Verify.assertNotEquals("", new Object(), new Object()); } @Test public void stringString() { Verify.assertNotEquals("1", "2"); Verify.assertNotEquals(null, "2"); Verify.assertNotEquals("1", null); } @Test public void stringStringString() { Verify.assertNotEquals("", "1", "2"); } @Test public void doubleDoubleDouble() { Verify.assertNotEquals(1.0d, 2.0d, DOUBLE_DELTA); Verify.assertNotEquals(1.0d, Double.POSITIVE_INFINITY, DOUBLE_DELTA); Verify.assertNotEquals(Double.POSITIVE_INFINITY, 2.0d, DOUBLE_DELTA); Verify.assertNotEquals(1.0d, Double.NaN, DOUBLE_DELTA); Verify.assertNotEquals(Double.NaN, Double.NEGATIVE_INFINITY, DOUBLE_DELTA); Verify.assertNotEquals(Double.NaN, Double.NaN, DOUBLE_DELTA); Verify.assertNotEquals(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, DOUBLE_DELTA); } @Test public void stringDoubleDoubleDouble() { Verify.assertNotEquals("", 1.0d, 2.0d, DOUBLE_DELTA); } @Test public void floatFloatFloat() { Verify.assertNotEquals(1.0f, 2.0f, FLOAT_DELTA); Verify.assertNotEquals(1.0f, Float.POSITIVE_INFINITY, FLOAT_DELTA); Verify.assertNotEquals(Float.POSITIVE_INFINITY, 2.0f, FLOAT_DELTA); Verify.assertNotEquals(1.0f, Float.NaN, FLOAT_DELTA); Verify.assertNotEquals(Float.NaN, Float.NEGATIVE_INFINITY, FLOAT_DELTA); Verify.assertNotEquals(Float.NaN, Float.NaN, FLOAT_DELTA); Verify.assertNotEquals(Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY, FLOAT_DELTA); } @Test public void stringFloatFloatFloat() { Verify.assertNotEquals("", 1.0f, 2.0f, FLOAT_DELTA); } @Test public void longLong() { Verify.assertNotEquals(1L, 2L); } @Test public void stringLongLong() { Verify.assertNotEquals("", 1L, 2L); } @Test public void booleanBoolean() { Verify.assertNotEquals(true, false); } @Test public void stringBooleanBoolean() { Verify.assertNotEquals("", true, false); } @Test public void byteByte() { Verify.assertNotEquals((byte) 1, (byte) 2); } @Test public void stringByteByte() { Verify.assertNotEquals("", (byte) 1, (byte) 2); } @Test public void charChar() { Verify.assertNotEquals('1', '2'); } @Test public void stringCharChar() { Verify.assertNotEquals("", '1', '2'); } @Test public void shortShort() { Verify.assertNotEquals((short) 1, (short) 2); } @Test public void stringShortShort() { Verify.assertNotEquals("", (short) 1, (short) 2); } @Test public void intInt() { Verify.assertNotEquals(1, 2); } @Test public void stringIntInt() { Verify.assertNotEquals("", 1, 2); } } AssertNotEqualsThrowsTest.java000066400000000000000000000224441234315411400370660ustar00rootroot00000000000000gs-collections-5.1.0/collections-testutils/src/test/java/com/gs/collections/impl/test/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.test; import org.junit.Assert; import org.junit.Test; public class AssertNotEqualsThrowsTest { private static final Object OBJECT = new Object(); private static final String STRING = "1"; private static final double DOUBLE = 1.0d; private static final double DOUBLE_DELTA = 0.5d; private static final float FLOAT = 1.0f; private static final float FLOAT_DELTA = 0.5f; private static final long LONG = 1L; private static final boolean BOOLEAN = true; private static final byte BYTE = 1; private static final char CHAR = '1'; private static final short SHORT = 1; private static final int INT = 1; @Test public void objectObject() { try { Verify.assertNotEquals(OBJECT, OBJECT); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(AssertNotEqualsThrowsTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void stringObjectObject() { try { Verify.assertNotEquals("items", OBJECT, OBJECT); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(AssertNotEqualsThrowsTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void stringString() { try { Verify.assertNotEquals(STRING, STRING); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(AssertNotEqualsThrowsTest.class.getName(), e.getStackTrace()[0].toString()); } try { Verify.assertNotEquals(null, null); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(AssertNotEqualsThrowsTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void stringStringString() { try { Verify.assertNotEquals("strings", STRING, STRING); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(AssertNotEqualsThrowsTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void doubleDoubleDouble() { try { Verify.assertNotEquals(DOUBLE, DOUBLE, DOUBLE_DELTA); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(AssertNotEqualsThrowsTest.class.getName(), e.getStackTrace()[0].toString()); } try { Verify.assertNotEquals(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, DOUBLE_DELTA); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(AssertNotEqualsThrowsTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void stringDoubleDoubleDouble() { try { Verify.assertNotEquals("doubles", DOUBLE, DOUBLE, DOUBLE_DELTA); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(AssertNotEqualsThrowsTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void floatFloatFloat() { try { Verify.assertNotEquals(FLOAT, FLOAT, FLOAT_DELTA); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(AssertNotEqualsThrowsTest.class.getName(), e.getStackTrace()[0].toString()); } try { Verify.assertNotEquals(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, FLOAT_DELTA); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(AssertNotEqualsThrowsTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void stringFloatFloatFloat() { try { Verify.assertNotEquals("floats", FLOAT, FLOAT, FLOAT_DELTA); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(AssertNotEqualsThrowsTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void longLong() { try { Verify.assertNotEquals(LONG, LONG); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(AssertNotEqualsThrowsTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void stringLongLong() { try { Verify.assertNotEquals("longs", LONG, LONG); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(AssertNotEqualsThrowsTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void booleanBoolean() { try { Verify.assertNotEquals(BOOLEAN, BOOLEAN); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(AssertNotEqualsThrowsTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void stringBooleanBoolean() { try { Verify.assertNotEquals("booleans", BOOLEAN, BOOLEAN); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(AssertNotEqualsThrowsTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void byteByte() { try { Verify.assertNotEquals(BYTE, BYTE); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(AssertNotEqualsThrowsTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void stringByteByte() { try { Verify.assertNotEquals("bytes", BYTE, BYTE); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(AssertNotEqualsThrowsTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void charChar() { try { Verify.assertNotEquals(CHAR, CHAR); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(AssertNotEqualsThrowsTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void stringCharChar() { try { Verify.assertNotEquals("chars", CHAR, CHAR); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(AssertNotEqualsThrowsTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void shortShort() { try { Verify.assertNotEquals(SHORT, SHORT); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(AssertNotEqualsThrowsTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void stringShortShort() { try { Verify.assertNotEquals("shorts", SHORT, SHORT); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(AssertNotEqualsThrowsTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void intInt() { try { Verify.assertNotEquals(INT, INT); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(AssertNotEqualsThrowsTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void stringIntInt() { try { Verify.assertNotEquals("ints", INT, INT); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(AssertNotEqualsThrowsTest.class.getName(), e.getStackTrace()[0].toString()); } } } CollectionsEqualTest.java000066400000000000000000000312121234315411400360210ustar00rootroot00000000000000gs-collections-5.1.0/collections-testutils/src/test/java/com/gs/collections/impl/test/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.test; import java.util.List; import java.util.Map; import java.util.Set; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.set.MutableSet; import org.junit.Assert; import org.junit.Test; import static com.gs.collections.impl.factory.Iterables.*; /** * JUnit test to make sure that the methods {@link Verify#assertListsEqual(String, List, List)}, * {@link Verify#assertSetsEqual(String, Set, Set)}, * and {@link Verify#assertMapsEqual(String, Map, Map)} really throw when they ought to. */ public class CollectionsEqualTest { private final MutableList list = mList("asdf", "qwer"); private final MutableList list2 = mList("asdf", "zxcv"); private final MutableList list3 = mList("asdf"); private final MutableSet set = mSet("asdf", "qwer"); private final MutableSet set2 = mSet("asdf", "zxcv"); private final MutableSet set3 = mSet("asdf"); private final MutableSet bigSet1 = mSet("1", "2", "3", "4", "5", "6"); private final MutableSet bigSet2 = mSet("7", "8", "9", "10", "11", "12"); private final Map map = mMap("asdf", "asdf", "qwer", "qwer"); private final Map map2 = mMap("asdf", "zxcv", "qwer", "qwer"); private final Map map3 = mMap("zxcv", "asdf", "qwer", "qwer"); private final Map map4 = mMap("zxcv", "zxcv", "qwer", "qwer"); private final Map map5 = mMap("asdf", "asdf"); @Test public void listsEqual() { List nullList = null; Verify.assertListsEqual(nullList, nullList); Verify.assertListsEqual("assertListsEqual(nullList, nullList)", nullList, nullList); Verify.assertListsEqual(this.list, this.list); Verify.assertListsEqual("assertListsEqual(list, list)", this.list, this.list); try { Verify.assertListsEqual("assertListsEqual(nullList, list)", nullList, this.list); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(CollectionsEqualTest.class.getName(), e.getStackTrace()[0].toString()); } try { Verify.assertListsEqual(nullList, this.list); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(CollectionsEqualTest.class.getName(), e.getStackTrace()[0].toString()); } try { Verify.assertListsEqual("assertListsEqual(list, nullList)", this.list, nullList); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(CollectionsEqualTest.class.getName(), e.getStackTrace()[0].toString()); } try { Verify.assertListsEqual(this.list, nullList); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(CollectionsEqualTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void setsEqual() { Set nullSet = null; Verify.assertSetsEqual(nullSet, nullSet); Verify.assertSetsEqual("assertSetsEqual(nullSet, nullSet)", nullSet, nullSet); Verify.assertSetsEqual(this.set, this.set); Verify.assertSetsEqual("assertSetsEqual(set, set)", this.set, this.set); try { Verify.assertSetsEqual("assertSetsEqual(nullSet, set)", nullSet, this.set); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(CollectionsEqualTest.class.getName(), e.getStackTrace()[0].toString()); } try { Verify.assertSetsEqual(nullSet, this.set); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(CollectionsEqualTest.class.getName(), e.getStackTrace()[0].toString()); } try { Verify.assertSetsEqual("assertSetsEqual(set, nullSet)", this.set, nullSet); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(CollectionsEqualTest.class.getName(), e.getStackTrace()[0].toString()); } try { Verify.assertSetsEqual(this.set, nullSet); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(CollectionsEqualTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void mapsEqual() { Map nullMap = null; Verify.assertMapsEqual(nullMap, nullMap); Verify.assertMapsEqual("assertMapsEqual(nullMap, nullMap)", nullMap, nullMap); Verify.assertMapsEqual(this.map, this.map); Verify.assertMapsEqual("assertMapsEqual(map, map)", this.map, this.map); try { Verify.assertMapsEqual("assertMapsEqual(nullMap, map)", nullMap, this.map); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(CollectionsEqualTest.class.getName(), e.getStackTrace()[0].toString()); } try { Verify.assertMapsEqual(nullMap, this.map); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(CollectionsEqualTest.class.getName(), e.getStackTrace()[0].toString()); } try { Verify.assertMapsEqual("assertMapsEqual(map, nullMap)", this.map, nullMap); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(CollectionsEqualTest.class.getName(), e.getStackTrace()[0].toString()); } try { Verify.assertMapsEqual(this.map, nullMap); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(CollectionsEqualTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void listsDifferentSizes() { try { Verify.assertListsEqual("assertListsEqual(list, list3)", this.list, this.list3); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(CollectionsEqualTest.class.getName(), e.getStackTrace()[0].toString()); } try { Verify.assertListsEqual(this.list, this.list3); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(CollectionsEqualTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void differentLists() { try { Verify.assertListsEqual("assertListsEqual(list, list2)", this.list, this.list2); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(CollectionsEqualTest.class.getName(), e.getStackTrace()[0].toString()); } try { Verify.assertListsEqual(this.list, this.list2); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(CollectionsEqualTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void setsDifferentSizes() { try { Verify.assertSetsEqual("assertSetsEqual(set, set2)", this.set, this.set2); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(CollectionsEqualTest.class.getName(), e.getStackTrace()[0].toString()); } try { Verify.assertSetsEqual(this.set, this.set2); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(CollectionsEqualTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void differentSets() { try { Verify.assertSetsEqual("assertSetsEqual(set, set3)", this.set, this.set3); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(CollectionsEqualTest.class.getName(), e.getStackTrace()[0].toString()); } try { Verify.assertSetsEqual(this.set, this.set3); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(CollectionsEqualTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void mapsDifferentValue() { try { Verify.assertMapsEqual("assertMapsEqual(map, map2)", this.map, this.map2); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(CollectionsEqualTest.class.getName(), e.getStackTrace()[0].toString()); } try { Verify.assertMapsEqual(this.map, this.map2); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(CollectionsEqualTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void mapsDifferentKey() { try { Verify.assertMapsEqual("assertMapsEqual(map, map3)", this.map, this.map3); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(CollectionsEqualTest.class.getName(), e.getStackTrace()[0].toString()); } try { Verify.assertMapsEqual(this.map, this.map3); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(CollectionsEqualTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void mapsDifferentEntry() { try { Verify.assertMapsEqual("assertMapsEqual(map, map4)", this.map, this.map4); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(CollectionsEqualTest.class.getName(), e.getStackTrace()[0].toString()); } try { Verify.assertMapsEqual(this.map, this.map4); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(CollectionsEqualTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void mapsDifferentSize() { try { Verify.assertMapsEqual("assertMapsEqual(map, map5)", this.map, this.map5); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(CollectionsEqualTest.class.getName(), e.getStackTrace()[0].toString()); } try { Verify.assertMapsEqual(this.map, this.map5); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(CollectionsEqualTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void bigSetsDiffer() { try { Verify.assertSetsEqual(this.bigSet1, this.bigSet2); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(CollectionsEqualTest.class.getName(), e.getStackTrace()[0].toString()); } } } ExceptionThrownTest.java000066400000000000000000000050771234315411400357250ustar00rootroot00000000000000gs-collections-5.1.0/collections-testutils/src/test/java/com/gs/collections/impl/test/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.test; import java.util.concurrent.Callable; import org.junit.Assert; import org.junit.Test; /** * JUnit test to make sure that methods like {@link Verify#assertThrows(Class, Runnable)} really throw when * they ought to. */ public class ExceptionThrownTest { @Test public void specificRuntimeException() { try { Verify.assertThrows(NullPointerException.class, new EmptyRunnable()); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(ExceptionThrownTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void callableException() { try { Verify.assertThrows(NullPointerException.class, new EmptyCallable()); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(ExceptionThrownTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void nullCause() { try { Verify.assertThrowsWithCause( IllegalStateException.class, IllegalArgumentException.class, new Runnable() { public void run() { throw new IllegalStateException(); } }); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(ExceptionThrownTest.class.getName(), e.getStackTrace()[0].toString()); } } private static final class EmptyRunnable implements Runnable { public void run() { } } private static final class EmptyCallable implements Callable { public Void call() { return null; } } } SerializeTestHelperTest.java000066400000000000000000000034171234315411400365100ustar00rootroot00000000000000gs-collections-5.1.0/collections-testutils/src/test/java/com/gs/collections/impl/test/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.test; import org.junit.Assert; import org.junit.Test; public class SerializeTestHelperTest { @Test public void serializeDeserializeSuccess() { String input = "Test"; String output = SerializeTestHelper.serializeDeserialize(input); Assert.assertEquals(input, output); Assert.assertNotSame(input, output); } @Test public void serializeNotSerializable() { try { Object nonSerializable = new Object(); SerializeTestHelper.serialize(nonSerializable); } catch (AssertionError ignored) { return; } Assert.fail(); } @Test public void deserializeNonsense() { try { byte[] nonsenseByteArray = "Why is the man who invests all your money called a broker?".getBytes(); SerializeTestHelper.deserialize(nonsenseByteArray); } catch (AssertionError ignored) { return; } Assert.fail(); } @Test public void classIsNonInstantiable() { Verify.assertClassNonInstantiable(SerializeTestHelper.class); } } VerifyTest.java000066400000000000000000001231741234315411400340300ustar00rootroot00000000000000gs-collections-5.1.0/collections-testutils/src/test/java/com/gs/collections/impl/test/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.test; import java.util.Collection; import java.util.Map; import java.util.TreeSet; import java.util.concurrent.Callable; import com.gs.collections.api.multimap.list.MutableListMultimap; import com.gs.collections.impl.block.factory.Comparators; import com.gs.collections.impl.block.factory.IntegerPredicates; import com.gs.collections.impl.factory.Lists; import com.gs.collections.impl.factory.Maps; import com.gs.collections.impl.factory.Sets; import com.gs.collections.impl.list.mutable.FastList; import com.gs.collections.impl.list.mutable.primitive.IntArrayList; import com.gs.collections.impl.map.mutable.UnifiedMap; import com.gs.collections.impl.multimap.list.FastListMultimap; import com.gs.collections.impl.set.mutable.UnifiedSet; import com.gs.collections.impl.set.sorted.mutable.TreeSortedSet; import com.gs.collections.impl.tuple.Tuples; import org.junit.Assert; import org.junit.Test; /** * JUnit test for our extensions to JUnit. These tests make sure that methods in {@link Verify} really fail when they * ought to. */ public class VerifyTest { @Test public void assertThrowsWithCause() { Verify.assertThrowsWithCause(RuntimeException.class, NullPointerException.class, new Callable() { public Void call() throws Exception { throw new RuntimeException(new NullPointerException()); } }); Verify.assertError(AssertionError.class, new Runnable() { public void run() { Verify.assertThrowsWithCause(RuntimeException.class, NullPointerException.class, new Callable() { public Void call() throws Exception { return null; } }); } }); } @Test public void assertBefore() { Verify.assertBefore("numbers", Integer.valueOf(1), Integer.valueOf(2), FastList.newListWith(1, 2)); Verify.assertError(AssertionError.class, new Runnable() { public void run() { Verify.assertBefore("numbers", Integer.valueOf(2), Integer.valueOf(1), FastList.newListWith(1, 2)); } }); } @Test public void assertEndsWithArray() { Verify.assertEndsWith(new Integer[]{1, 2, 3, 4}, 3, 4); Verify.assertError(AssertionError.class, new Runnable() { public void run() { Verify.assertEndsWith(new Integer[]{1, 2, 3, 4}, 3, 2); } }); } @Test public void assertStartsWithArray() { Verify.assertStartsWith(new Integer[]{1, 2, 3, 4}, 1, 2); Verify.assertError(AssertionError.class, new Runnable() { public void run() { Verify.assertStartsWith(new Integer[]{1, 2, 3, 4}, 3, 2); } }); } @Test public void assertStartsWithList() { Verify.assertStartsWith(FastList.newListWith(1, 2, 3, 4), 1, 2); Verify.assertError(AssertionError.class, new Runnable() { public void run() { Verify.assertStartsWith(FastList.newListWith(1, 2, 3, 4), 3, 2); } }); } @Test public void assertEndsWithList() { Verify.assertEndsWith(FastList.newListWith(1, 2, 3, 4), 3, 4); Verify.assertError(AssertionError.class, new Runnable() { public void run() { Verify.assertEndsWith(FastList.newListWith(1, 2, 3, 4), 3, 2); } }); } @Test public void assertNotEqualsString() { Verify.assertNotEquals("yes", "no"); Verify.assertError(AssertionError.class, new Runnable() { public void run() { Verify.assertNotEquals("yes", "yes"); } }); } @Test public void assertNotEqualsDouble() { Verify.assertNotEquals(0.5d, 0.6d, 0.0001); Verify.assertNotEquals("message", 0.5d, 0.6d, 0.0001); Verify.assertError(AssertionError.class, new Runnable() { public void run() { Verify.assertNotEquals(0.5d, 0.5d, 0.0001); } }); Verify.assertError(AssertionError.class, new Runnable() { public void run() { Verify.assertNotEquals("message", 0.5d, 0.5d, 0.0001); } }); } @Test public void assertNotEqualsFloat() { Verify.assertNotEquals(0.5f, 0.6f, 0.0001f); Verify.assertNotEquals("message", 0.5f, 0.6f, 0.0001f); Verify.assertError(AssertionError.class, new Runnable() { public void run() { Verify.assertNotEquals(0.5f, 0.5f, 0.0001f); } }); Verify.assertError(AssertionError.class, new Runnable() { public void run() { Verify.assertNotEquals("message", 0.5f, 0.5f, 0.0001f); } }); } @Test public void assertNotEqualsLong() { Verify.assertNotEquals(5L, 6L); Verify.assertNotEquals("message", 5L, 6L); Verify.assertError(AssertionError.class, new Runnable() { public void run() { Verify.assertNotEquals(5L, 5L); } }); Verify.assertError(AssertionError.class, new Runnable() { public void run() { Verify.assertNotEquals("message", 5L, 5L); } }); } @Test public void assertNotEqualsBoolean() { Verify.assertNotEquals(true, false); Verify.assertNotEquals("message", true, false); Verify.assertError(AssertionError.class, new Runnable() { public void run() { Verify.assertNotEquals(true, true); } }); Verify.assertError(AssertionError.class, new Runnable() { public void run() { Verify.assertNotEquals("message", true, true); } }); } @Test public void assertNotEqualsByte() { Verify.assertNotEquals((byte) 1, (byte) 2); Verify.assertNotEquals("message", (byte) 1, (byte) 2); Verify.assertError(AssertionError.class, new Runnable() { public void run() { Verify.assertNotEquals((byte) 1, (byte) 1); } }); Verify.assertError(AssertionError.class, new Runnable() { public void run() { Verify.assertNotEquals("message", (byte) 1, (byte) 1); } }); } @Test public void assertNotEqualsChar() { Verify.assertNotEquals((char) 1, (char) 2); Verify.assertNotEquals("message", (char) 1, (char) 2); Verify.assertError(AssertionError.class, new Runnable() { public void run() { Verify.assertNotEquals((char) 1, (char) 1); } }); Verify.assertError(AssertionError.class, new Runnable() { public void run() { Verify.assertNotEquals("message", (char) 1, (byte) 1); } }); } @Test public void assertNotEqualsShort() { Verify.assertNotEquals((short) 1, (short) 2); Verify.assertNotEquals("message", (short) 1, (short) 2); Verify.assertError(AssertionError.class, new Runnable() { public void run() { Verify.assertNotEquals((short) 1, (short) 1); } }); Verify.assertError(AssertionError.class, new Runnable() { public void run() { Verify.assertNotEquals("message", (short) 1, (short) 1); } }); } @Test public void assertNotEqualsInt() { Verify.assertNotEquals(1, 2); Verify.assertNotEquals("message", 1, 2); Verify.assertError(AssertionError.class, new Runnable() { public void run() { Verify.assertNotEquals(1, 1); } }); Verify.assertError(AssertionError.class, new Runnable() { public void run() { Verify.assertNotEquals("message", 1, 1); } }); } @Test public void assertNotContainsString() { Verify.assertNotContains("1", "0"); Verify.assertNotContains("message", "1", "0"); Verify.assertError(AssertionError.class, new Runnable() { public void run() { Verify.assertNotContains("1", "1"); } }); Verify.assertError(AssertionError.class, new Runnable() { public void run() { Verify.assertNotContains("message", "1", "1"); } }); } @Test public void assertListsEqual() { Verify.assertListsEqual(FastList.newListWith(1, 2, 3), FastList.newListWith(1, 2, 3)); Verify.assertListsEqual("message", FastList.newListWith(1, 2, 3), FastList.newListWith(1, 2, 3)); Verify.assertError(AssertionError.class, new Runnable() { public void run() { Verify.assertListsEqual(FastList.newListWith(1, 2, 3), FastList.newListWith(1, 2)); } }); Verify.assertError(AssertionError.class, new Runnable() { public void run() { Verify.assertListsEqual("message", FastList.newListWith(1, 2, 3), FastList.newListWith(1, 2)); } }); } @Test public void assertSetsEqual() { Verify.assertSetsEqual(UnifiedSet.newSetWith(1, 2, 3), UnifiedSet.newSetWith(1, 2, 3)); Verify.assertSetsEqual("message", UnifiedSet.newSetWith(1, 2, 3), UnifiedSet.newSetWith(1, 2, 3)); Verify.assertError(AssertionError.class, new Runnable() { public void run() { Verify.assertSetsEqual(UnifiedSet.newSetWith(1, 2, 3), UnifiedSet.newSetWith(1, 2)); } }); Verify.assertError(AssertionError.class, new Runnable() { public void run() { Verify.assertSetsEqual("message", UnifiedSet.newSetWith(1, 2, 3), UnifiedSet.newSetWith(1, 2)); } }); } @Test public void assertMapsEqual() { Verify.assertMapsEqual(UnifiedMap.newWithKeysValues(1, 1, 2, 2), UnifiedMap.newWithKeysValues(1, 1, 2, 2)); Verify.assertMapsEqual("message", UnifiedMap.newWithKeysValues(1, 1, 2, 2), UnifiedMap.newWithKeysValues(1, 1, 2, 2)); Verify.assertError(AssertionError.class, new Runnable() { public void run() { Verify.assertMapsEqual(UnifiedMap.newWithKeysValues(1, 1, 2, 2), UnifiedMap.newWithKeysValues(1, 1, 2, 2, 3, 3)); } }); Verify.assertError(AssertionError.class, new Runnable() { public void run() { Verify.assertMapsEqual("message", UnifiedMap.newWithKeysValues(1, 1, 2, 2), UnifiedMap.newWithKeysValues(1, 1, 2, 2, 3, 3)); } }); } @Test public void assertIterablesEqual() { Verify.assertIterablesEqual(FastList.newListWith(1, 2, 3), TreeSortedSet.newSetWith(1, 2, 3)); Verify.assertIterablesEqual("message", FastList.newListWith(1, 2, 3), TreeSortedSet.newSetWith(1, 2, 3)); Verify.assertError(AssertionError.class, new Runnable() { public void run() { Verify.assertIterablesEqual(FastList.newListWith(1, 2, 3), FastList.newListWith(1, 2)); } }); Verify.assertError(AssertionError.class, new Runnable() { public void run() { Verify.assertIterablesEqual("message", FastList.newListWith(1, 2, 3), FastList.newListWith(1, 2)); } }); } @Test public void assertError() { Verify.assertError(AssertionError.class, new Runnable() { public void run() { throw new AssertionError(); } }); Verify.assertError(AssertionError.class, new Runnable() { public void run() { Verify.assertError(AssertionError.class, new Runnable() { public void run() { // do nothing } }); } }); } @Test public void shallowClone1() { try { Cloneable unclonable = new Cloneable() { }; Verify.assertShallowClone(unclonable); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(VerifyTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void shallowClone2() { Cloneable simpleCloneable = new SimpleCloneable(); Verify.assertShallowClone(simpleCloneable); } private static class SimpleCloneable implements Cloneable { @Override public boolean equals(Object obj) { if (this == obj) { return true; } return !(obj == null || this.getClass() != obj.getClass()); } @Override public int hashCode() { return 0; } } @Test public void assertNotEquals() { Object object = new Object() { @Override public boolean equals(Object obj) { return false; } }; Verify.assertNotEquals(object, object); } @Test public void assertNotEqualsFailsOnSameReference() { try { Object object = new Object(); Verify.assertNotEquals(object, object); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(VerifyTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void assertNotEqualsFailsOnDifferentReference() { try { //noinspection CachedNumberConstructorCall,UnnecessaryBoxing Integer integer1 = new Integer(12345); //noinspection CachedNumberConstructorCall,UnnecessaryBoxing Integer integer2 = new Integer(12345); Verify.assertNotEquals(integer1, integer2); Assert.fail("AssertionError expected"); } catch (AssertionError e) { Verify.assertContains(VerifyTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void assertEqualsAndHashCode() { try { Verify.assertEqualsAndHashCode(new ConstantHashCode(), new ConstantHashCode()); Assert.fail(); } catch (AssertionError e) { Verify.assertContains(VerifyTest.class.getName(), e.getStackTrace()[0].toString()); } try { Verify.assertEqualsAndHashCode(new AlwaysEqualWithHashCodeOf(1), new AlwaysEqualWithHashCodeOf(2)); Assert.fail(); } catch (AssertionError e) { Verify.assertContains(VerifyTest.class.getName(), e.getStackTrace()[0].toString()); } } private static class ConstantHashCode { @Override public int hashCode() { return 1; } } private static final class AlwaysEqualWithHashCodeOf { private final int hashcode; private AlwaysEqualWithHashCodeOf(int hashcode) { this.hashcode = hashcode; } @Override public int hashCode() { return this.hashcode; } @Override public boolean equals(Object obj) { return obj != null; } } @Test public void assertContainsAllEntries() { try { MutableListMultimap multimap = FastListMultimap.newMultimap(Tuples.pair("one", 1), Tuples.pair("two", 2)); Verify.assertContainsAllEntries(multimap, "one", 1, "three", 3); Assert.fail(); } catch (AssertionError e) { Verify.assertContains(VerifyTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void assertContainsAllEntries_OddArgumentCount() { try { MutableListMultimap multimap = FastListMultimap.newMultimap(Tuples.pair("one", 1), Tuples.pair("two", 2)); Verify.assertContainsAllEntries(multimap, "one", 1, "three"); Assert.fail(); } catch (AssertionError e) { Verify.assertContains(VerifyTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void assertContainsAll() { try { Collection list = FastList.newListWith("One", "Two", "Three"); Verify.assertContainsAll(list, "Foo", "Bar", "Baz"); Assert.fail(); } catch (AssertionError e) { Verify.assertContains("these items", e.getMessage()); } } @Test public void assertInstanceOf() { try { Verify.assertInstanceOf(Integer.class, 1L); Assert.fail(); } catch (AssertionError e) { Verify.assertContains(VerifyTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void assertSortedSetsEqual() { TreeSortedSet integers = TreeSortedSet.newSetWith(Comparators.reverseNaturalOrder(), 1, 2, 3, 4); Verify.assertSortedSetsEqual(null, null); Verify.assertSortedSetsEqual(TreeSortedSet.newSet(), new TreeSet()); Verify.assertSortedSetsEqual(TreeSortedSet.newSetWith(1, 2, 3), new TreeSet(FastList.newListWith(1, 2, 3))); Verify.assertSortedSetsEqual(new TreeSet(integers), integers); Verify.assertSortedSetsEqual(TreeSortedSet.newSet(integers), integers); try { Verify.assertSortedSetsEqual(TreeSortedSet.newSetWith(1, 2, 3), new TreeSet(FastList.newListWith())); Assert.fail(); } catch (AssertionError e) { Verify.assertContains(VerifyTest.class.getName(), e.getStackTrace()[0].toString()); } try { Verify.assertSortedSetsEqual(TreeSortedSet.newSetWith(1, 2, 3), integers); Assert.fail(); } catch (AssertionError e) { Verify.assertContains(VerifyTest.class.getName(), e.getStackTrace()[0].toString()); } try { Verify.assertSortedSetsEqual(TreeSortedSet.newSetWith(Comparators.reverseNaturalOrder(), 1, 2, 3, 4, 5), integers); Assert.fail(); } catch (AssertionError e) { Verify.assertContains(VerifyTest.class.getName(), e.getStackTrace()[0].toString()); } try { Verify.assertSortedSetsEqual(TreeSortedSet.newSetWith(Comparators.reverseNaturalOrder(), 3, 4), integers); Assert.fail(); } catch (AssertionError e) { Verify.assertContains(VerifyTest.class.getName(), e.getStackTrace()[0].toString()); } } @Test public void assertEmpty() { try { Verify.assertEmpty(FastList.newListWith("foo")); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("actual size:<1>", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertEmpty_PrimitiveIterable() { try { Verify.assertEmpty(IntArrayList.newListWith(1)); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("actual size:<1>", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertEmpty_Iterable() { try { Verify.assertIterableEmpty(FastList.newListWith("foo")); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("actual size:<1>", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertEmpty_Map() { try { Verify.assertEmpty(UnifiedMap.newWithKeysValues("foo", "bar")); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("actual size:<1>", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertEmpty_ImmutableMap() { try { Verify.assertEmpty(Maps.immutable.of("foo", "bar")); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("actual size:<1>", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertEmpty_Multimap() { try { Verify.assertEmpty(FastListMultimap.newMultimap(Tuples.pair("foo", "1"), Tuples.pair("foo", "2"))); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("actual size:<2>", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertNotEmpty() { try { Verify.assertNotEmpty(Lists.mutable.of()); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("should be non-empty", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertNotEmpty_PrimitiveIterable() { try { Verify.assertNotEmpty(new IntArrayList()); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("should be non-empty", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertNotEmpty_Iterable() { try { Verify.assertIterableNotEmpty(Lists.mutable.of()); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("should be non-empty", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertNotEmpty_Map() { try { Verify.assertNotEmpty(UnifiedMap.newMap()); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("should be non-empty", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertNotEmpty_Multimap() { try { Verify.assertNotEmpty(FastListMultimap.newMultimap()); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("should be non-empty", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertNotEmpty_Array() { Verify.assertNotEmpty(new Object[]{new Object()}); try { Verify.assertNotEmpty(new Object[0]); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("items should not be equal", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertSize() { try { Verify.assertSize(3, FastList.newListWith("foo", "bar")); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("Incorrect size", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertCount() { try { Verify.assertSize(3, FastList.newListWith("foo", "bar")); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("Incorrect size", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertSize_Array() { try { Verify.assertSize(3, new Object[]{new Object()}); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("Incorrect size", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertSize_Iterable() { try { Verify.assertIterableSize(3, FastList.newListWith("foo", "bar")); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("Incorrect size", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertSize_PrimitiveIterable() { try { Verify.assertSize(3, IntArrayList.newListWith(1, 2)); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("Incorrect size", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertSize_Map() { try { Verify.assertSize(3, UnifiedMap.newWithKeysValues("foo", "bar")); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("Incorrect size", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertSize_Multimap() { try { Verify.assertSize(3, FastListMultimap.newMultimap()); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("Incorrect size", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertSize_ImmutableMap() { try { Verify.assertSize(3, Maps.immutable.of("foo", "bar")); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("Incorrect size", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertSize_ImmutableSet() { try { Verify.assertSize(3, Sets.immutable.of("foo", "bar")); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("Incorrect size", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertContains_String() { try { Verify.assertContains("foo", "bar"); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("did not contain", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertAllSatisfy() { try { Verify.assertAllSatisfy(FastList.newListWith(1, 3), IntegerPredicates.isEven()); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("failed to satisfy the condition", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertAllSatisfy_Map() { try { Verify.assertAllSatisfy((Map) UnifiedMap.newWithKeysValues(1, 1, 3, 3), IntegerPredicates.isEven()); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("failed to satisfy the condition", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertNoneSatisfy() { try { Verify.assertNoneSatisfy(FastList.newListWith(1, 3), IntegerPredicates.isOdd()); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("satisfied the condition", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertNoneSatisfy_Map() { try { Verify.assertNoneSatisfy((Map) UnifiedMap.newWithKeysValues(1, 1, 3, 3), IntegerPredicates.isOdd()); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("satisfied the condition", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertAnySatisfy() { try { Verify.assertAnySatisfy(FastList.newListWith(1, 3), IntegerPredicates.isEven()); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("No items satisfied the condition", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertAnySatisfy_Map() { try { Verify.assertAnySatisfy((Map) UnifiedMap.newWithKeysValues(1, 1, 3, 3), IntegerPredicates.isEven()); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("No items satisfied the condition", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertContainsAllKeyValues_MissingKeys() { try { Verify.assertContainsAllKeyValues(UnifiedMap.newWithKeysValues("foo", "bar"), "baz", "quaz"); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("did not contain", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertContainsAllKeyValues_MissingValues() { try { Verify.assertContainsAllKeyValues(UnifiedMap.newWithKeysValues("foo", "bar"), "foo", "quaz"); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("map has incorrect values for keys", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertContainsAllKeyValues_OddVarArgCount() { try { Verify.assertContainsAllKeyValues(UnifiedMap.newWithKeysValues("foo", "bar"), "baz"); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("Odd number of keys and values", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertContainsAllKeyValues_ImmutableMap_MissingKey() { try { Verify.assertContainsAllKeyValues(Maps.immutable.of("foo", "bar"), "baz", "quaz"); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("did not contain these items", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertContainsAllKeyValues_ImmutableMap_MissingValue() { try { Verify.assertContainsAllKeyValues(Maps.immutable.of("foo", "bar"), "foo", "quaz"); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("did not contain these items", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertContainsAllKeyValues_ImmutableMap_OddVarArgCount() { try { Verify.assertContainsAllKeyValues(Maps.immutable.of("foo", "bar"), "baz"); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("Odd number of keys and values", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertContainsNone() { try { Verify.assertContainsNone(FastList.newListWith("foo", "bar"), "foo", "bar"); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("has an intersection with", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void denyContainsAny() { try { Verify.denyContainsAny(FastList.newListWith("foo", "bar"), "foo", "bar"); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("has an intersection with", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertContains_Collection() { try { Verify.assertContains("baz", FastList.newListWith("foo", "bar")); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("did not contain", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertContains_ImmutableSet() { try { Verify.assertContains("bar", Sets.immutable.of("foo")); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("did not contain", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertContainsEntry() { try { Verify.assertContainsEntry("foo", "bar", FastListMultimap.newMultimap(Tuples.pair("foo", "baz"))); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("did not contain", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertContainsKey() { try { Verify.assertContainsKey("foo", UnifiedMap.newWithKeysValues("foozle", "bar")); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("did not contain", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertContainsKey_ImmutableMap() { try { Verify.assertContainsKey("foo", Maps.immutable.of("foozle", "bar")); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("did not contain", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void denyContainsKey() { try { Verify.denyContainsKey("foo", UnifiedMap.newWithKeysValues("foo", "bar")); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("contained unexpected", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertContainsKeyValue_MissingKey() { try { Verify.assertContainsKeyValue("foo", "bar", UnifiedMap.newWithKeysValues("baz", "quaz")); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("did not contain", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertContainsKeyValue_MissingValue() { try { Verify.assertContainsKeyValue("foo", "bar", UnifiedMap.newWithKeysValues("foo", "quaz")); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("did not contain", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertContainsKeyValue_ImmutableMap_MissingKey() { try { Verify.assertContainsKeyValue("foo", "bar", Maps.immutable.of("baz", "quaz")); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("did not contain", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertContainsKeyValue_ImmutableMap_MissingValue() { try { Verify.assertContainsKeyValue("foo", "bar", Maps.immutable.of("baz", "quaz")); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("did not contain", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertNotContains_Collection() { try { Verify.assertNotContains("foo", FastList.newListWith("foo")); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("should not contain", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertNotContains_Iterable() { try { Verify.assertNotContains("foo", (Iterable) FastList.newListWith("foo")); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("should not contain", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertNotContainsKey() { try { Verify.assertNotContainsKey("foo", UnifiedMap.newWithKeysValues("foo", "bar")); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("should not contain", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } @Test public void assertClassNonInstantiable() { Verify.assertClassNonInstantiable(SerializeTestHelper.class); try { Verify.assertClassNonInstantiable(VerifyTest.class); Assert.fail(); } catch (AssertionError ex) { Verify.assertContains("to be non-instantiable", ex.getMessage()); Verify.assertContains(VerifyTest.class.getName(), ex.getStackTrace()[0].toString()); } } } gs-collections-5.1.0/collections-testutils/src/test/resources/000077500000000000000000000000001234315411400245745ustar00rootroot00000000000000gs-collections-5.1.0/collections-testutils/src/test/resources/log4j.properties000066400000000000000000000015151234315411400277330ustar00rootroot00000000000000# # Copyright 2011 Goldman Sachs. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # log4j.rootCategory=INFO, Console # Console Appender log4j.appender.Console=org.apache.log4j.ConsoleAppender log4j.appender.Console.layout=org.apache.log4j.PatternLayout log4j.appender.Console.layout.ConversionPattern=%d{ABSOLUTE} %-5p [%t] (%c{1}.java:%L) %m%n gs-collections-5.1.0/collections/000077500000000000000000000000001234315411400167565ustar00rootroot00000000000000gs-collections-5.1.0/collections/.classpath000066400000000000000000000006501234315411400207420ustar00rootroot00000000000000 gs-collections-5.1.0/collections/.project000066400000000000000000000010361234315411400204250ustar00rootroot00000000000000 collections org.eclipse.jdt.core.javabuilder org.maven.ide.eclipse.maven2Builder org.eclipse.jdt.core.javanature org.maven.ide.eclipse.maven2Nature gs-collections-5.1.0/collections/.settings/000077500000000000000000000000001234315411400206745ustar00rootroot00000000000000gs-collections-5.1.0/collections/.settings/org.eclipse.jdt.core.prefs000066400000000000000000000546431234315411400256720ustar00rootroot00000000000000#Thu Jun 04 15:26:03 EDT 2009 eclipse.preferences.version=1 org.eclipse.jdt.core.codeComplete.argumentPrefixes= org.eclipse.jdt.core.codeComplete.argumentSuffixes= org.eclipse.jdt.core.codeComplete.fieldPrefixes= org.eclipse.jdt.core.codeComplete.fieldSuffixes= org.eclipse.jdt.core.codeComplete.localPrefixes= org.eclipse.jdt.core.codeComplete.localSuffixes= org.eclipse.jdt.core.codeComplete.staticFieldPrefixes= org.eclipse.jdt.core.codeComplete.staticFieldSuffixes= org.eclipse.jdt.core.codeComplete.staticFinalFieldPrefixes= org.eclipse.jdt.core.codeComplete.staticFinalFieldSuffixes= org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.compliance=1.5 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.source=1.5 org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_assignment=16 org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16 org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 org.eclipse.jdt.core.formatter.alignment_for_enum_constants=16 org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16 org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16 org.eclipse.jdt.core.formatter.blank_lines_after_imports=1 org.eclipse.jdt.core.formatter.blank_lines_after_package=1 org.eclipse.jdt.core.formatter.blank_lines_before_field=0 org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0 org.eclipse.jdt.core.formatter.blank_lines_before_imports=1 org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1 org.eclipse.jdt.core.formatter.blank_lines_before_method=1 org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1 org.eclipse.jdt.core.formatter.blank_lines_before_package=0 org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1 org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1 org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=next_line org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=next_line org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line org.eclipse.jdt.core.formatter.brace_position_for_block=next_line org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=next_line org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=next_line org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=next_line org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=next_line org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=next_line org.eclipse.jdt.core.formatter.brace_position_for_switch=next_line org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=next_line org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false org.eclipse.jdt.core.formatter.comment.format_block_comments=true org.eclipse.jdt.core.formatter.comment.format_header=false org.eclipse.jdt.core.formatter.comment.format_html=true org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true org.eclipse.jdt.core.formatter.comment.format_line_comments=true org.eclipse.jdt.core.formatter.comment.format_source_code=true org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true org.eclipse.jdt.core.formatter.comment.indent_root_tags=true org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert org.eclipse.jdt.core.formatter.comment.line_length=120 org.eclipse.jdt.core.formatter.compact_else_if=true org.eclipse.jdt.core.formatter.continuation_indentation=2 org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2 org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true org.eclipse.jdt.core.formatter.indent_empty_lines=false org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=true org.eclipse.jdt.core.formatter.indentation.size=4 org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member=insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=insert org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=insert org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=insert org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=insert org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=insert org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert org.eclipse.jdt.core.formatter.join_lines_in_comments=true org.eclipse.jdt.core.formatter.join_wrapped_lines=false org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false org.eclipse.jdt.core.formatter.lineSplit=120 org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=true org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0 org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true org.eclipse.jdt.core.formatter.tabulation.char=space org.eclipse.jdt.core.formatter.tabulation.size=4 org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true gs-collections-5.1.0/collections/.settings/org.eclipse.jdt.ui.prefs000066400000000000000000000237041234315411400253510ustar00rootroot00000000000000#Fri Feb 12 11:50:45 EST 2010 cleanup.add_default_serial_version_id=false cleanup.add_generated_serial_version_id=true cleanup.add_missing_annotations=true cleanup.add_missing_deprecated_annotations=true cleanup.add_missing_methods=false cleanup.add_missing_nls_tags=false cleanup.add_missing_override_annotations=true cleanup.add_serial_version_id=false cleanup.always_use_blocks=true cleanup.always_use_parentheses_in_expressions=false cleanup.always_use_this_for_non_static_field_access=true cleanup.always_use_this_for_non_static_method_access=true cleanup.convert_to_enhanced_for_loop=false cleanup.correct_indentation=false cleanup.format_source_code=false cleanup.format_source_code_changes_only=false cleanup.make_local_variable_final=false cleanup.make_parameters_final=false cleanup.make_private_fields_final=true cleanup.make_type_abstract_if_missing_method=false cleanup.make_variable_declarations_final=true cleanup.never_use_blocks=false cleanup.never_use_parentheses_in_expressions=true cleanup.organize_imports=true cleanup.qualify_static_field_accesses_with_declaring_class=false cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true cleanup.qualify_static_member_accesses_with_declaring_class=true cleanup.qualify_static_method_accesses_with_declaring_class=false cleanup.remove_private_constructors=true cleanup.remove_trailing_whitespaces=true cleanup.remove_trailing_whitespaces_all=true cleanup.remove_trailing_whitespaces_ignore_empty=false cleanup.remove_unnecessary_casts=true cleanup.remove_unnecessary_nls_tags=true cleanup.remove_unused_imports=true cleanup.remove_unused_local_variables=false cleanup.remove_unused_private_fields=true cleanup.remove_unused_private_members=false cleanup.remove_unused_private_methods=true cleanup.remove_unused_private_types=true cleanup.sort_members=false cleanup.sort_members_all=false cleanup.use_blocks=true cleanup.use_blocks_only_for_return_and_throw=false cleanup.use_parentheses_in_expressions=false cleanup.use_this_for_non_static_field_access=true cleanup.use_this_for_non_static_field_access_only_if_necessary=false cleanup.use_this_for_non_static_method_access=true cleanup.use_this_for_non_static_method_access_only_if_necessary=false cleanup_profile=_Collections cleanup_settings_version=2 eclipse.preferences.version=1 editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true formatter_profile=_Collections formatter_settings_version=11 org.eclipse.jdt.ui.ignorelowercasenames=false org.eclipse.jdt.ui.importorder=java;javax; org.eclipse.jdt.ui.javadoc=true org.eclipse.jdt.ui.ondemandthreshold=99 org.eclipse.jdt.ui.staticondemandthreshold=99 org.eclipse.jdt.ui.text.custom_code_templates= sp_cleanup.add_default_serial_version_id=true sp_cleanup.add_generated_serial_version_id=false sp_cleanup.add_missing_annotations=true sp_cleanup.add_missing_deprecated_annotations=true sp_cleanup.add_missing_methods=false sp_cleanup.add_missing_nls_tags=false sp_cleanup.add_missing_override_annotations=true sp_cleanup.add_serial_version_id=false sp_cleanup.always_use_blocks=true sp_cleanup.always_use_parentheses_in_expressions=false sp_cleanup.always_use_this_for_non_static_field_access=true sp_cleanup.always_use_this_for_non_static_method_access=true sp_cleanup.convert_to_enhanced_for_loop=false sp_cleanup.correct_indentation=false sp_cleanup.format_source_code=false sp_cleanup.format_source_code_changes_only=true sp_cleanup.make_local_variable_final=false sp_cleanup.make_parameters_final=false sp_cleanup.make_private_fields_final=true sp_cleanup.make_type_abstract_if_missing_method=false sp_cleanup.make_variable_declarations_final=true sp_cleanup.never_use_blocks=false sp_cleanup.never_use_parentheses_in_expressions=true sp_cleanup.on_save_use_additional_actions=true sp_cleanup.organize_imports=true sp_cleanup.qualify_static_field_accesses_with_declaring_class=false sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true sp_cleanup.qualify_static_member_accesses_with_declaring_class=true sp_cleanup.qualify_static_method_accesses_with_declaring_class=false sp_cleanup.remove_private_constructors=true sp_cleanup.remove_trailing_whitespaces=true sp_cleanup.remove_trailing_whitespaces_all=true sp_cleanup.remove_trailing_whitespaces_ignore_empty=false sp_cleanup.remove_unnecessary_casts=true sp_cleanup.remove_unnecessary_nls_tags=true sp_cleanup.remove_unused_imports=true sp_cleanup.remove_unused_local_variables=false sp_cleanup.remove_unused_private_fields=true sp_cleanup.remove_unused_private_members=false sp_cleanup.remove_unused_private_methods=true sp_cleanup.remove_unused_private_types=true sp_cleanup.sort_members=false sp_cleanup.sort_members_all=false sp_cleanup.use_blocks=true sp_cleanup.use_blocks_only_for_return_and_throw=false sp_cleanup.use_parentheses_in_expressions=false sp_cleanup.use_this_for_non_static_field_access=true sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=false sp_cleanup.use_this_for_non_static_method_access=true sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=false gs-collections-5.1.0/collections/.settings/org.maven.ide.eclipse.prefs000066400000000000000000000004061234315411400260140ustar00rootroot00000000000000#Wed Feb 03 15:04:25 EST 2010 activeProfiles= eclipse.preferences.version=1 fullBuildGoals=process-test-resources includeModules=false resolveWorkspaceProjects=true resourceFilterGoals=process-resources resources\:testResources skipCompilerPlugin=true version=1 gs-collections-5.1.0/collections/build.xml000066400000000000000000000046621234315411400206070ustar00rootroot00000000000000 gs-collections-5.1.0/collections/gs-collections.iml000066400000000000000000000017421234315411400224120ustar00rootroot00000000000000 gs-collections-5.1.0/collections/ivy.xml000066400000000000000000000050111234315411400203040ustar00rootroot00000000000000 gs-collections-5.1.0/collections/pom.xml000066400000000000000000000357761234315411400203150ustar00rootroot00000000000000 4.0.0 com.goldmansachs gs-collections 5.1.0 bundle Goldman Sachs Collections Main Library GS Collections is a collections framework for Java. It has JDK-compatible List, Set and Map implementations with a rich API and set of utility classes that work with any JDK compatible Collections, Arrays, Maps or Strings. The iteration protocol was inspired by the Smalltalk collection framework. https://github.com/goldmansachs/gs-collections 2004 The Apache Software License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0.txt repo https://github.com/goldmansachs/gs-collections scm:git:https://github.com/goldmansachs/gs-collections.git scm:git:https://github.com/goldmansachs/gs-collections.git Craig P. Motlin craig.motlin@gs.com Donald Raab donald.raab@gs.com Bhavana Hindupur bhavana.hindupur@gs.com UTF-8 3.2.2 2.10 ${project.basedir}/target/site/clover/clover.xml ${project.basedir}/target/clover/surefire-reports ${build.is.personal} 3.0 com.goldmansachs gs-collections-api 5.1.0 net.jcip jcip-annotations 1.0 true maven-antrun-plugin 1.7 maven-assembly-plugin 2.4 maven-clean-plugin 2.5 maven-compiler-plugin 2.5.1 maven-dependency-plugin 2.8 maven-deploy-plugin 2.8.1 maven-install-plugin 2.5.1 maven-jar-plugin 2.4 maven-javadoc-plugin 2.9.1 maven-release-plugin 2.4.2 maven-resources-plugin 2.6 maven-site-plugin 3.3 maven-source-plugin 2.2.1 maven-enforcer-plugin 1.3.1 org.codehaus.mojo versions-maven-plugin 2.1 org.codehaus.mojo clirr-maven-plugin 2.6.1 org.apache.felix maven-bundle-plugin 2.4.0 org.scala-tools maven-scala-plugin 2.15.2 maven-surefire-plugin 2.16 maven-project-info-reports-plugin 2.7 com.fortify.ps.maven.plugin maven-sca-plugin 2.6 com.goldmansachs gs-collections-code-generator-maven-plugin 5.1.0 generate-sources generate impl maven-compiler-plugin 1.5 1.5 maven-surefire-plugin **/*Test.java -XX:-OmitStackTraceInFastThrow random never maven-source-plugin 2.1.2 verify jar-no-fork org.apache.felix maven-bundle-plugin 2.4.0 true com.gs.collections.impl J2SE-1.5,JavaSE-1.6 net.jcip.annotations;resolution:=optional,* ${project.version} org.codehaus.mojo sonar-maven-plugin 2.2 maven-checkstyle-plugin ${checkstyle.version} checkstyle-configuration.xml true true org.codehaus.mojo findbugs-maven-plugin 2.5.3 Max Default true true findbugs-exclude.xml maven-javadoc-plugin Goldman Sachs Collections - ${project.version} Goldman Sachs Collections - ${project.version} public http://java.sun.com/j2se/1.5.0/docs/api/ ${project.version} -Xdoclint:none maven-enforcer-plugin enforce com.goldmansachs:gs-collections-code-generator-maven-plugin 1.7.0 3.0.2 enforce org.codehaus.mojo clirr-maven-plugin 2.5 com.goldmansachs gs-collections 5.1.0 ${project.build.directory}/clirr.txt clover com.atlassian.maven.plugins maven-clover2-plugin ${clover.version} ${clover.license} @deprecated true ${user.home}/clover/${project.artifactId} true block setup process-sources setup gs-collections-5.1.0/collections/src/000077500000000000000000000000001234315411400175455ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/000077500000000000000000000000001234315411400204715ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/000077500000000000000000000000001234315411400214125ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/000077500000000000000000000000001234315411400221705ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/000077500000000000000000000000001234315411400226015ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/000077500000000000000000000000001234315411400251175ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/000077500000000000000000000000001234315411400260605ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/AbstractRichIterable.java000066400000000000000000000455751234315411400327640ustar00rootroot00000000000000/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl; import java.lang.reflect.Array; import java.util.Collection; import java.util.Comparator; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.RichIterable; import com.gs.collections.api.bag.MutableBag; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.DoubleObjectToDoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.FloatObjectToFloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.IntObjectToIntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.LongObjectToLongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.collection.primitive.MutableBooleanCollection; import com.gs.collections.api.collection.primitive.MutableByteCollection; import com.gs.collections.api.collection.primitive.MutableCharCollection; import com.gs.collections.api.collection.primitive.MutableDoubleCollection; import com.gs.collections.api.collection.primitive.MutableFloatCollection; import com.gs.collections.api.collection.primitive.MutableIntCollection; import com.gs.collections.api.collection.primitive.MutableLongCollection; import com.gs.collections.api.collection.primitive.MutableShortCollection; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.map.MutableMap; import com.gs.collections.api.map.sorted.MutableSortedMap; import com.gs.collections.api.multimap.MutableMultimap; import com.gs.collections.api.set.MutableSet; import com.gs.collections.api.set.sorted.MutableSortedSet; import com.gs.collections.api.tuple.Pair; import com.gs.collections.impl.bag.mutable.HashBag; import com.gs.collections.impl.block.factory.Comparators; import com.gs.collections.impl.block.factory.Predicates; import com.gs.collections.impl.block.procedure.CollectIfProcedure; import com.gs.collections.impl.block.procedure.CollectProcedure; import com.gs.collections.impl.block.procedure.MultimapEachPutProcedure; import com.gs.collections.impl.block.procedure.MultimapPutProcedure; import com.gs.collections.impl.block.procedure.RejectProcedure; import com.gs.collections.impl.block.procedure.SelectProcedure; import com.gs.collections.impl.block.procedure.primitive.CollectBooleanProcedure; import com.gs.collections.impl.block.procedure.primitive.CollectByteProcedure; import com.gs.collections.impl.block.procedure.primitive.CollectCharProcedure; import com.gs.collections.impl.block.procedure.primitive.CollectDoubleProcedure; import com.gs.collections.impl.block.procedure.primitive.CollectFloatProcedure; import com.gs.collections.impl.block.procedure.primitive.CollectIntProcedure; import com.gs.collections.impl.block.procedure.primitive.CollectLongProcedure; import com.gs.collections.impl.block.procedure.primitive.CollectShortProcedure; import com.gs.collections.impl.factory.Lists; import com.gs.collections.impl.map.mutable.UnifiedMap; import com.gs.collections.impl.map.sorted.mutable.TreeSortedMap; import com.gs.collections.impl.set.mutable.UnifiedSet; import com.gs.collections.impl.set.sorted.mutable.TreeSortedSet; import com.gs.collections.impl.utility.ArrayIterate; import com.gs.collections.impl.utility.Iterate; import com.gs.collections.impl.utility.LazyIterate; import com.gs.collections.impl.utility.internal.IterableIterate; public abstract class AbstractRichIterable implements RichIterable { public boolean contains(Object object) { return this.anySatisfy(Predicates.equal(object)); } public boolean containsAllIterable(Iterable source) { return Iterate.allSatisfy(source, Predicates.in(this)); } public boolean containsAllArguments(Object... elements) { return ArrayIterate.allSatisfy(elements, Predicates.in(this)); } public Object[] toArray() { final Object[] result = new Object[this.size()]; this.forEachWithIndex(new ObjectIntProcedure() { public void value(T each, int index) { result[index] = each; } }); return result; } public E[] toArray(E[] array) { final E[] result = array.length < this.size() ? (E[]) Array.newInstance(array.getClass().getComponentType(), this.size()) : array; this.forEachWithIndex(new ObjectIntProcedure() { public void value(Object each, int index) { result[index] = (E) each; } }); if (result.length > this.size()) { result[this.size()] = null; } return result; } public boolean isEmpty() { return this.size() == 0; } public boolean notEmpty() { return this.size() > 0; } public MutableList toList() { return Lists.mutable.ofAll(this); } public MutableList toSortedList() { return this.toList().sortThis(); } public MutableList toSortedList(Comparator comparator) { return this.toList().sortThis(comparator); } public > MutableList toSortedListBy(Function function) { return this.toSortedList(Comparators.byFunction(function)); } public MutableSortedSet toSortedSet() { return TreeSortedSet.newSet(null, this); } public MutableSortedSet toSortedSet(Comparator comparator) { return TreeSortedSet.newSet(comparator, this); } public > MutableSortedSet toSortedSetBy(Function function) { return this.toSortedSet(Comparators.byFunction(function)); } public MutableSet toSet() { return UnifiedSet.newSet(this); } public MutableBag toBag() { return HashBag.newBag(this); } public MutableMap toMap( Function keyFunction, Function valueFunction) { return UnifiedMap.newMap(this.size()).collectKeysAndValues(this, keyFunction, valueFunction); } public MutableSortedMap toSortedMap( Function keyFunction, Function valueFunction) { return TreeSortedMap.newMap().collectKeysAndValues(this, keyFunction, valueFunction); } public MutableSortedMap toSortedMap(Comparator comparator, Function keyFunction, Function valueFunction) { return TreeSortedMap.newMap(comparator).collectKeysAndValues(this, keyFunction, valueFunction); } public > R select(Predicate predicate, R target) { this.forEach(new SelectProcedure(predicate, target)); return target; } public > R selectWith( Predicate2 predicate, P parameter, R targetCollection) { return IterableIterate.selectWith(this, predicate, parameter, targetCollection); } public > R reject(Predicate predicate, R target) { this.forEach(new RejectProcedure(predicate, target)); return target; } public > R rejectWith( Predicate2 predicate, P parameter, R targetCollection) { return IterableIterate.rejectWith(this, predicate, parameter, targetCollection); } public > R collect(Function function, R target) { this.forEach(new CollectProcedure(function, target)); return target; } public > R collectWith( Function2 function, P parameter, R targetCollection) { return IterableIterate.collectWith(this, function, parameter, targetCollection); } public > R collectIf( Predicate predicate, Function function, R target) { this.forEach(new CollectIfProcedure(target, function, predicate)); return target; } public T detectIfNone(Predicate predicate, Function0 function) { T result = this.detect(predicate); return result == null ? function.value() : result; } public

T detectWithIfNone(Predicate2 predicate, P parameter, Function0 function) { T result = this.detectWith(predicate, parameter); return result == null ? function.value() : result; } public T min(Comparator comparator) { return Iterate.min(this, comparator); } public T max(Comparator comparator) { return Iterate.max(this, comparator); } public T min() { return Iterate.min(this); } public T max() { return Iterate.max(this); } public > T minBy(Function function) { return IterableIterate.minBy(this, function); } public > T maxBy(Function function) { return IterableIterate.maxBy(this, function); } public LazyIterable asLazy() { return LazyIterate.adapt(this); } public > R flatCollect( Function> function, R target) { return IterableIterate.flatCollect(this, function, target); } public T detect(Predicate predicate) { return IterableIterate.detect(this, predicate); } public

T detectWith(Predicate2 predicate, P parameter) { return IterableIterate.detectWith(this, predicate, parameter); } public int count(Predicate predicate) { return IterableIterate.count(this, predicate); } public

int countWith(Predicate2 predicate, P parameter) { return IterableIterate.countWith(this, predicate, parameter); } public boolean anySatisfy(Predicate predicate) { return IterableIterate.anySatisfy(this, predicate); } public boolean allSatisfy(Predicate predicate) { return IterableIterate.allSatisfy(this, predicate); } public boolean noneSatisfy(Predicate predicate) { return IterableIterate.noneSatisfy(this, predicate); } public

boolean anySatisfyWith(Predicate2 predicate, P parameter) { return IterableIterate.anySatisfyWith(this, predicate, parameter); } public

boolean allSatisfyWith(Predicate2 predicate, P parameter) { return IterableIterate.allSatisfyWith(this, predicate, parameter); } public

boolean noneSatisfyWith(Predicate2 predicate, P parameter) { return IterableIterate.noneSatisfyWith(this, predicate, parameter); } public IV injectInto(IV injectedValue, Function2 function) { return IterableIterate.injectInto(injectedValue, this, function); } public int injectInto(int injectedValue, IntObjectToIntFunction function) { return IterableIterate.injectInto(injectedValue, this, function); } public long injectInto(long injectedValue, LongObjectToLongFunction function) { return IterableIterate.injectInto(injectedValue, this, function); } public double injectInto(double injectedValue, DoubleObjectToDoubleFunction function) { return IterableIterate.injectInto(injectedValue, this, function); } public float injectInto(float injectedValue, FloatObjectToFloatFunction function) { return IterableIterate.injectInto(injectedValue, this, function); } public long sumOfInt(IntFunction function) { return IterableIterate.sumOfInt(this, function); } public double sumOfFloat(FloatFunction function) { return IterableIterate.sumOfFloat(this, function); } public long sumOfLong(LongFunction function) { return IterableIterate.sumOfLong(this, function); } public double sumOfDouble(DoubleFunction function) { return IterableIterate.sumOfDouble(this, function); } public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { IterableIterate.forEachWithIndex(this, objectIntProcedure); } public

void forEachWith(Procedure2 procedure, P parameter) { IterableIterate.forEachWith(this, procedure, parameter); } public >> R zip(Iterable that, R target) { return IterableIterate.zip(this, that, target); } public >> R zipWithIndex(R target) { return IterableIterate.zipWithIndex(this, target); } /** * Returns a string representation of this collection. The string representation consists of a list of the * collection's elements in the order they are returned by its iterator, enclosed in square brackets * ("[]"). Adjacent elements are separated by the characters ", " (comma and space). Elements * are converted to strings as by String.valueOf(Object).

*

* This implementation creates an empty string buffer, appends a left square bracket, and iterates over the * collection appending the string representation of each element in turn. After appending each element except the * last, the string ", " is appended. Finally a right bracket is appended. A string is obtained from the * string buffer, and returned. * * @return a string representation of this collection. */ @Override public String toString() { return this.makeString("[", ", ", "]"); } public String makeString() { return this.makeString(", "); } public String makeString(String separator) { return this.makeString("", separator, ""); } public String makeString(String start, String separator, String end) { Appendable stringBuilder = new StringBuilder(); this.appendString(stringBuilder, start, separator, end); return stringBuilder.toString(); } public void appendString(Appendable appendable) { this.appendString(appendable, ", "); } public void appendString(Appendable appendable, String separator) { this.appendString(appendable, "", separator, ""); } public void appendString( Appendable appendable, String start, String separator, String end) { IterableIterate.appendString(this, appendable, start, separator, end); } public boolean containsAll(Collection collection) { return this.containsAllIterable(collection); } public R collectBoolean(BooleanFunction booleanFunction, R target) { this.forEach(new CollectBooleanProcedure(booleanFunction, target)); return target; } public R collectByte(ByteFunction byteFunction, R target) { this.forEach(new CollectByteProcedure(byteFunction, target)); return target; } public R collectChar(CharFunction charFunction, R target) { this.forEach(new CollectCharProcedure(charFunction, target)); return target; } public R collectDouble(DoubleFunction doubleFunction, R target) { this.forEach(new CollectDoubleProcedure(doubleFunction, target)); return target; } public R collectFloat(FloatFunction floatFunction, R target) { this.forEach(new CollectFloatProcedure(floatFunction, target)); return target; } public R collectInt(IntFunction intFunction, R target) { this.forEach(new CollectIntProcedure(intFunction, target)); return target; } public R collectLong(LongFunction longFunction, R target) { this.forEach(new CollectLongProcedure(longFunction, target)); return target; } public R collectShort(ShortFunction shortFunction, R target) { this.forEach(new CollectShortProcedure(shortFunction, target)); return target; } public > R groupBy( Function function, R target) { this.forEach(MultimapPutProcedure.on(target, function)); return target; } public > R groupByEach( Function> function, R target) { this.forEach(MultimapEachPutProcedure.on(target, function)); return target; } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/Counter.java000066400000000000000000000047441234315411400303530ustar00rootroot00000000000000/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl; import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; import com.gs.collections.api.block.function.primitive.IntFunction; /** * A Counter can be used to increment and return an integer count. A Counter can be used in Anonymous * inner classes if it is declared final, unlike an int, which once declared final cannot be modified. */ public final class Counter implements Externalizable { public static final IntFunction TO_COUNT = new IntFunction() { public int intValueOf(Counter counter) { return counter.getCount(); } }; private static final long serialVersionUID = 1L; private int count; public Counter(int startCount) { this.count = startCount; } public Counter() { this(0); } public void increment() { this.count++; } public void decrement() { this.count--; } public void add(int value) { this.count += value; } public int getCount() { return this.count; } public void reset() { this.count = 0; } @Override public String toString() { return String.valueOf(this.count); } @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof Counter)) { return false; } Counter counter = (Counter) o; return this.count == counter.count; } @Override public int hashCode() { return this.count; } public void writeExternal(ObjectOutput out) throws IOException { out.writeInt(this.count); } public void readExternal(ObjectInput in) throws IOException { this.count = in.readInt(); } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/EmptyIterator.java000066400000000000000000000037261234315411400315430ustar00rootroot00000000000000/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl; import java.util.ListIterator; import java.util.NoSuchElementException; import net.jcip.annotations.Immutable; /** * A Singleton iterator which is empty and can be used by all empty collections. */ @Immutable public final class EmptyIterator implements ListIterator { private static final EmptyIterator INSTANCE = new EmptyIterator(); private EmptyIterator() { } public static EmptyIterator getInstance() { return (EmptyIterator) INSTANCE; } public boolean hasNext() { return false; } public T next() { throw new NoSuchElementException(); } public void remove() { throw new UnsupportedOperationException("Cannot call remove() on " + this.getClass().getSimpleName()); } public boolean hasPrevious() { return false; } public T previous() { throw new NoSuchElementException(); } public int nextIndex() { return 0; } public int previousIndex() { return -1; } public void set(T t) { throw new UnsupportedOperationException("Cannot call set() on " + this.getClass().getSimpleName()); } public void add(T t) { throw new UnsupportedOperationException("Cannot call add() on " + this.getClass().getSimpleName()); } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/SynchronizedRichIterable.java000066400000000000000000000661251234315411400336720ustar00rootroot00000000000000/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl; import java.io.Serializable; import java.util.Collection; import java.util.Comparator; import java.util.Iterator; import com.gs.collections.api.BooleanIterable; import com.gs.collections.api.ByteIterable; import com.gs.collections.api.CharIterable; import com.gs.collections.api.DoubleIterable; import com.gs.collections.api.FloatIterable; import com.gs.collections.api.IntIterable; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.LongIterable; import com.gs.collections.api.RichIterable; import com.gs.collections.api.ShortIterable; import com.gs.collections.api.bag.MutableBag; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.DoubleObjectToDoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.FloatObjectToFloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.IntObjectToIntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.LongObjectToLongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.collection.primitive.MutableBooleanCollection; import com.gs.collections.api.collection.primitive.MutableByteCollection; import com.gs.collections.api.collection.primitive.MutableCharCollection; import com.gs.collections.api.collection.primitive.MutableDoubleCollection; import com.gs.collections.api.collection.primitive.MutableFloatCollection; import com.gs.collections.api.collection.primitive.MutableIntCollection; import com.gs.collections.api.collection.primitive.MutableLongCollection; import com.gs.collections.api.collection.primitive.MutableShortCollection; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.map.MapIterable; import com.gs.collections.api.map.MutableMap; import com.gs.collections.api.map.sorted.MutableSortedMap; import com.gs.collections.api.multimap.Multimap; import com.gs.collections.api.multimap.MutableMultimap; import com.gs.collections.api.partition.PartitionIterable; import com.gs.collections.api.set.MutableSet; import com.gs.collections.api.set.sorted.MutableSortedSet; import com.gs.collections.api.tuple.Pair; import net.jcip.annotations.GuardedBy; /** * A synchronized view of a RichIterable. * * @since 5.0 */ public class SynchronizedRichIterable implements RichIterable, Serializable { private static final long serialVersionUID = 1L; private final Object lock; @GuardedBy("this.lock") private final RichIterable iterable; protected SynchronizedRichIterable(RichIterable iterable) { this(iterable, null); } protected SynchronizedRichIterable(RichIterable iterable, Object newLock) { if (iterable == null) { throw new IllegalArgumentException("Cannot create a SynchronizedRichIterable on a null collection"); } this.iterable = iterable; this.lock = newLock == null ? this : newLock; } /** * This method will take a RichIterable and wrap it directly in a SynchronizedRichIterable. */ public static SynchronizedRichIterable of(RichIterable iterable) { return new SynchronizedRichIterable(iterable); } /** * This method will take a RichIterable and wrap it directly in a SynchronizedRichIterable. Additionally, * a developer specifies which lock to use with the collection. */ public static SynchronizedRichIterable of(RichIterable iterable, Object lock) { return new SynchronizedRichIterable(iterable, lock); } public int size() { synchronized (this.lock) { return this.iterable.size(); } } public boolean isEmpty() { synchronized (this.lock) { return this.iterable.isEmpty(); } } public boolean notEmpty() { synchronized (this.lock) { return this.iterable.notEmpty(); } } public T getFirst() { synchronized (this.lock) { return this.iterable.getFirst(); } } public T getLast() { synchronized (this.lock) { return this.iterable.getLast(); } } public boolean contains(Object object) { synchronized (this.lock) { return this.iterable.contains(object); } } public boolean containsAllIterable(Iterable source) { synchronized (this.lock) { return this.iterable.containsAllIterable(source); } } public boolean containsAll(Collection source) { synchronized (this.lock) { return this.iterable.containsAll(source); } } public boolean containsAllArguments(Object... elements) { synchronized (this.lock) { return this.iterable.containsAllArguments(elements); } } public RichIterable select(Predicate predicate) { synchronized (this.lock) { return this.iterable.select(predicate); } } public > R select(Predicate predicate, R target) { synchronized (this.lock) { return this.iterable.select(predicate, target); } } public

RichIterable selectWith(Predicate2 predicate, P parameter) { synchronized (this.lock) { return this.iterable.selectWith(predicate, parameter); } } public > R selectWith(Predicate2 predicate, P parameter, R targetCollection) { synchronized (this.lock) { return this.iterable.selectWith(predicate, parameter, targetCollection); } } public RichIterable reject(Predicate predicate) { synchronized (this.lock) { return this.iterable.reject(predicate); } } public

RichIterable rejectWith(Predicate2 predicate, P parameter) { synchronized (this.lock) { return this.iterable.rejectWith(predicate, parameter); } } public > R reject(Predicate predicate, R target) { synchronized (this.lock) { return this.iterable.reject(predicate, target); } } public > R rejectWith(Predicate2 predicate, P parameter, R targetCollection) { synchronized (this.lock) { return this.iterable.rejectWith(predicate, parameter, targetCollection); } } public PartitionIterable partition(Predicate predicate) { synchronized (this.lock) { return this.iterable.partition(predicate); } } public

PartitionIterable partitionWith(Predicate2 predicate, P parameter) { synchronized (this.lock) { return this.iterable.partitionWith(predicate, parameter); } } public RichIterable selectInstancesOf(Class clazz) { synchronized (this.lock) { return this.iterable.selectInstancesOf(clazz); } } public RichIterable collect(Function function) { synchronized (this.lock) { return this.iterable.collect(function); } } public BooleanIterable collectBoolean(BooleanFunction booleanFunction) { synchronized (this.lock) { return this.iterable.collectBoolean(booleanFunction); } } public R collectBoolean(BooleanFunction booleanFunction, R target) { synchronized (this.lock) { return this.iterable.collectBoolean(booleanFunction, target); } } public ByteIterable collectByte(ByteFunction byteFunction) { synchronized (this.lock) { return this.iterable.collectByte(byteFunction); } } public R collectByte(ByteFunction byteFunction, R target) { synchronized (this.lock) { return this.iterable.collectByte(byteFunction, target); } } public CharIterable collectChar(CharFunction charFunction) { synchronized (this.lock) { return this.iterable.collectChar(charFunction); } } public R collectChar(CharFunction charFunction, R target) { synchronized (this.lock) { return this.iterable.collectChar(charFunction, target); } } public DoubleIterable collectDouble(DoubleFunction doubleFunction) { synchronized (this.lock) { return this.iterable.collectDouble(doubleFunction); } } public R collectDouble(DoubleFunction doubleFunction, R target) { synchronized (this.lock) { return this.iterable.collectDouble(doubleFunction, target); } } public FloatIterable collectFloat(FloatFunction floatFunction) { synchronized (this.lock) { return this.iterable.collectFloat(floatFunction); } } public R collectFloat(FloatFunction floatFunction, R target) { synchronized (this.lock) { return this.iterable.collectFloat(floatFunction, target); } } public IntIterable collectInt(IntFunction intFunction) { synchronized (this.lock) { return this.iterable.collectInt(intFunction); } } public R collectInt(IntFunction intFunction, R target) { synchronized (this.lock) { return this.iterable.collectInt(intFunction, target); } } public LongIterable collectLong(LongFunction longFunction) { synchronized (this.lock) { return this.iterable.collectLong(longFunction); } } public R collectLong(LongFunction longFunction, R target) { synchronized (this.lock) { return this.iterable.collectLong(longFunction, target); } } public ShortIterable collectShort(ShortFunction shortFunction) { synchronized (this.lock) { return this.iterable.collectShort(shortFunction); } } public R collectShort(ShortFunction shortFunction, R target) { synchronized (this.lock) { return this.iterable.collectShort(shortFunction, target); } } public > R collect(Function function, R target) { synchronized (this.lock) { return this.iterable.collect(function, target); } } public RichIterable collectWith(Function2 function, P parameter) { synchronized (this.lock) { return this.iterable.collectWith(function, parameter); } } public > R collectWith(Function2 function, P parameter, R targetCollection) { synchronized (this.lock) { return this.iterable.collectWith(function, parameter, targetCollection); } } public RichIterable collectIf(Predicate predicate, Function function) { synchronized (this.lock) { return this.iterable.collectIf(predicate, function); } } public > R collectIf(Predicate predicate, Function function, R target) { synchronized (this.lock) { return this.iterable.collectIf(predicate, function, target); } } public RichIterable flatCollect(Function> function) { synchronized (this.lock) { return this.iterable.flatCollect(function); } } public > R flatCollect(Function> function, R target) { synchronized (this.lock) { return this.iterable.flatCollect(function, target); } } public T detect(Predicate predicate) { synchronized (this.lock) { return this.iterable.detect(predicate); } } public

T detectWith(Predicate2 predicate, P parameter) { synchronized (this.lock) { return this.iterable.detectWith(predicate, parameter); } } public T detectIfNone(Predicate predicate, Function0 function) { synchronized (this.lock) { return this.iterable.detectIfNone(predicate, function); } } public

T detectWithIfNone(Predicate2 predicate, P parameter, Function0 function) { synchronized (this.lock) { return this.iterable.detectWithIfNone(predicate, parameter, function); } } public int count(Predicate predicate) { synchronized (this.lock) { return this.iterable.count(predicate); } } public

int countWith(Predicate2 predicate, P parameter) { synchronized (this.lock) { return this.iterable.countWith(predicate, parameter); } } public boolean anySatisfy(Predicate predicate) { synchronized (this.lock) { return this.iterable.anySatisfy(predicate); } } public

boolean anySatisfyWith(Predicate2 predicate, P parameter) { synchronized (this.lock) { return this.iterable.anySatisfyWith(predicate, parameter); } } public boolean allSatisfy(Predicate predicate) { synchronized (this.lock) { return this.iterable.allSatisfy(predicate); } } public

boolean allSatisfyWith(Predicate2 predicate, P parameter) { synchronized (this.lock) { return this.iterable.allSatisfyWith(predicate, parameter); } } public boolean noneSatisfy(Predicate predicate) { synchronized (this.lock) { return this.iterable.noneSatisfy(predicate); } } public

boolean noneSatisfyWith(Predicate2 predicate, P parameter) { synchronized (this.lock) { return this.iterable.noneSatisfyWith(predicate, parameter); } } public IV injectInto(IV injectedValue, Function2 function) { synchronized (this.lock) { return this.iterable.injectInto(injectedValue, function); } } public int injectInto(int injectedValue, IntObjectToIntFunction function) { synchronized (this.lock) { return this.iterable.injectInto(injectedValue, function); } } public long injectInto(long injectedValue, LongObjectToLongFunction function) { synchronized (this.lock) { return this.iterable.injectInto(injectedValue, function); } } public float injectInto(float injectedValue, FloatObjectToFloatFunction function) { synchronized (this.lock) { return this.iterable.injectInto(injectedValue, function); } } public double injectInto(double injectedValue, DoubleObjectToDoubleFunction function) { synchronized (this.lock) { return this.iterable.injectInto(injectedValue, function); } } public MutableList toList() { synchronized (this.lock) { return this.iterable.toList(); } } public MutableList toSortedList() { synchronized (this.lock) { return this.iterable.toSortedList(); } } public MutableList toSortedList(Comparator comparator) { synchronized (this.lock) { return this.iterable.toSortedList(comparator); } } public > MutableList toSortedListBy(Function function) { synchronized (this.lock) { return this.iterable.toSortedListBy(function); } } public MutableSet toSet() { synchronized (this.lock) { return this.iterable.toSet(); } } public MutableSortedSet toSortedSet() { synchronized (this.lock) { return this.iterable.toSortedSet(); } } public MutableSortedSet toSortedSet(Comparator comparator) { synchronized (this.lock) { return this.iterable.toSortedSet(comparator); } } public > MutableSortedSet toSortedSetBy(Function function) { synchronized (this.lock) { return this.iterable.toSortedSetBy(function); } } public MutableBag toBag() { synchronized (this.lock) { return this.iterable.toBag(); } } public MutableMap toMap(Function keyFunction, Function valueFunction) { synchronized (this.lock) { return this.iterable.toMap(keyFunction, valueFunction); } } public MutableSortedMap toSortedMap(Function keyFunction, Function valueFunction) { synchronized (this.lock) { return this.iterable.toSortedMap(keyFunction, valueFunction); } } public MutableSortedMap toSortedMap(Comparator comparator, Function keyFunction, Function valueFunction) { synchronized (this.lock) { return this.iterable.toSortedMap(comparator, keyFunction, valueFunction); } } public LazyIterable asLazy() { synchronized (this.lock) { return this.iterable.asLazy(); } } public Object[] toArray() { synchronized (this.lock) { return this.iterable.toArray(); } } public T1[] toArray(T1[] target) { synchronized (this.lock) { return this.iterable.toArray(target); } } public T min(Comparator comparator) { synchronized (this.lock) { return this.iterable.min(comparator); } } public T max(Comparator comparator) { synchronized (this.lock) { return this.iterable.max(comparator); } } public T min() { synchronized (this.lock) { return this.iterable.min(); } } public T max() { synchronized (this.lock) { return this.iterable.max(); } } public > T minBy(Function function) { synchronized (this.lock) { return this.iterable.minBy(function); } } public > T maxBy(Function function) { synchronized (this.lock) { return this.iterable.maxBy(function); } } public long sumOfInt(IntFunction function) { synchronized (this.lock) { return this.iterable.sumOfInt(function); } } public double sumOfFloat(FloatFunction function) { synchronized (this.lock) { return this.iterable.sumOfFloat(function); } } public long sumOfLong(LongFunction function) { synchronized (this.lock) { return this.iterable.sumOfLong(function); } } public double sumOfDouble(DoubleFunction function) { synchronized (this.lock) { return this.iterable.sumOfDouble(function); } } public String makeString() { synchronized (this.lock) { return this.iterable.makeString(); } } public String makeString(String separator) { synchronized (this.lock) { return this.iterable.makeString(separator); } } public String makeString(String start, String separator, String end) { synchronized (this.lock) { return this.iterable.makeString(start, separator, end); } } public void appendString(Appendable appendable) { synchronized (this.lock) { this.appendString(appendable, ", "); } } public void appendString(Appendable appendable, String separator) { synchronized (this.lock) { this.appendString(appendable, "", separator, ""); } } public void appendString(Appendable appendable, String start, String separator, String end) { synchronized (this.lock) { this.iterable.appendString(appendable, start, separator, end); } } public Multimap groupBy(Function function) { synchronized (this.lock) { return this.iterable.groupBy(function); } } public > R groupBy(Function function, R target) { synchronized (this.lock) { return this.iterable.groupBy(function, target); } } public Multimap groupByEach(Function> function) { synchronized (this.lock) { return this.iterable.groupByEach(function); } } public > R groupByEach(Function> function, R target) { synchronized (this.lock) { return this.iterable.groupByEach(function, target); } } public MapIterable groupByUniqueKey(Function function) { synchronized (this.lock) { return this.iterable.groupByUniqueKey(function); } } @Override public String toString() { synchronized (this.lock) { return this.iterable.toString(); } } public RichIterable> zip(Iterable that) { synchronized (this.lock) { return this.iterable.zip(that); } } public >> R zip(Iterable that, R target) { synchronized (this.lock) { return this.iterable.zip(that, target); } } public RichIterable> zipWithIndex() { synchronized (this.lock) { return this.iterable.zipWithIndex(); } } public >> R zipWithIndex(R target) { synchronized (this.lock) { return this.iterable.zipWithIndex(target); } } public RichIterable> chunk(int size) { synchronized (this.lock) { return this.iterable.chunk(size); } } public MapIterable aggregateInPlaceBy(Function groupBy, Function0 zeroValueFactory, Procedure2 mutatingAggregator) { synchronized (this.lock) { return this.iterable.aggregateInPlaceBy(groupBy, zeroValueFactory, mutatingAggregator); } } public MapIterable aggregateBy(Function groupBy, Function0 zeroValueFactory, Function2 nonMutatingAggregator) { synchronized (this.lock) { return this.iterable.aggregateBy(groupBy, zeroValueFactory, nonMutatingAggregator); } } public void forEach(Procedure procedure) { synchronized (this.lock) { this.iterable.forEach(procedure); } } public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { synchronized (this.lock) { this.iterable.forEachWithIndex(objectIntProcedure); } } public

void forEachWith(Procedure2 procedure, P parameter) { synchronized (this.lock) { this.iterable.forEachWith(procedure, parameter); } } /** * Must be called in a synchronized block. */ public Iterator iterator() { return this.iterable.iterator(); } } UnmodifiableIteratorAdapter.java000066400000000000000000000025061234315411400342600ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl; import java.util.Iterator; /** * An iterator that adapts another iterator and throws unsupported operation exceptions when calls * to the remove method are made. */ public class UnmodifiableIteratorAdapter implements Iterator { private final Iterator iterator; public UnmodifiableIteratorAdapter(Iterator iterator) { this.iterator = iterator; } public boolean hasNext() { return this.iterator.hasNext(); } public E next() { return this.iterator.next(); } public void remove() { throw new UnsupportedOperationException("Cannot call remove() on " + this.getClass().getSimpleName()); } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/UnmodifiableMap.java000066400000000000000000000055431234315411400317660ustar00rootroot00000000000000/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl; import java.io.Serializable; import java.util.Collection; import java.util.Collections; import java.util.Map; import java.util.Set; /** * An unmodifiable view of a Map. */ public class UnmodifiableMap implements Map, Serializable { private static final long serialVersionUID = 1L; protected final Map delegate; public UnmodifiableMap(Map delegate) { if (delegate == null) { throw new NullPointerException(); } this.delegate = delegate; } public int size() { return this.delegate.size(); } public boolean isEmpty() { return this.delegate.isEmpty(); } public boolean containsKey(Object key) { return this.delegate.containsKey(key); } public boolean containsValue(Object value) { return this.delegate.containsValue(value); } public V get(Object key) { return this.delegate.get(key); } public V put(K key, V value) { throw new UnsupportedOperationException("Cannot call put() on " + this.getClass().getSimpleName()); } public V remove(Object key) { throw new UnsupportedOperationException("Cannot call remove() on " + this.getClass().getSimpleName()); } public void putAll(Map t) { throw new UnsupportedOperationException("Cannot call putAll() on " + this.getClass().getSimpleName()); } public void clear() { throw new UnsupportedOperationException("Cannot call clear() on " + this.getClass().getSimpleName()); } public Set keySet() { return Collections.unmodifiableSet(this.delegate.keySet()); } public Set> entrySet() { return Collections.unmodifiableMap(this.delegate).entrySet(); } public Collection values() { return Collections.unmodifiableCollection(this.delegate.values()); } @Override public boolean equals(Object o) { return o == this || this.delegate.equals(o); } @Override public int hashCode() { return this.delegate.hashCode(); } @Override public String toString() { return this.delegate.toString(); } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/UnmodifiableRichIterable.java000066400000000000000000000511441234315411400336040ustar00rootroot00000000000000/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl; import java.io.Serializable; import java.util.Collection; import java.util.Comparator; import java.util.Iterator; import com.gs.collections.api.BooleanIterable; import com.gs.collections.api.ByteIterable; import com.gs.collections.api.CharIterable; import com.gs.collections.api.DoubleIterable; import com.gs.collections.api.FloatIterable; import com.gs.collections.api.IntIterable; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.LongIterable; import com.gs.collections.api.RichIterable; import com.gs.collections.api.ShortIterable; import com.gs.collections.api.bag.MutableBag; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.DoubleObjectToDoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.FloatObjectToFloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.IntObjectToIntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.LongObjectToLongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.collection.primitive.MutableBooleanCollection; import com.gs.collections.api.collection.primitive.MutableByteCollection; import com.gs.collections.api.collection.primitive.MutableCharCollection; import com.gs.collections.api.collection.primitive.MutableDoubleCollection; import com.gs.collections.api.collection.primitive.MutableFloatCollection; import com.gs.collections.api.collection.primitive.MutableIntCollection; import com.gs.collections.api.collection.primitive.MutableLongCollection; import com.gs.collections.api.collection.primitive.MutableShortCollection; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.map.MapIterable; import com.gs.collections.api.map.MutableMap; import com.gs.collections.api.map.sorted.MutableSortedMap; import com.gs.collections.api.multimap.Multimap; import com.gs.collections.api.multimap.MutableMultimap; import com.gs.collections.api.partition.PartitionIterable; import com.gs.collections.api.set.MutableSet; import com.gs.collections.api.set.sorted.MutableSortedSet; import com.gs.collections.api.tuple.Pair; /** * An unmodifiable view of a RichIterable. */ public class UnmodifiableRichIterable implements RichIterable, Serializable { private static final long serialVersionUID = 1L; protected final RichIterable iterable; protected UnmodifiableRichIterable(RichIterable richIterable) { this.iterable = richIterable; } /** * This method will take a RichIterable and wrap it directly in a UnmodifiableRichIterable. */ public static > UnmodifiableRichIterable of(RI iterable) { if (iterable == null) { throw new IllegalArgumentException("cannot create a UnmodifiableRichIterable for null"); } return new UnmodifiableRichIterable(iterable); } public > R select(Predicate predicate, R target) { return this.iterable.select(predicate, target); } public

RichIterable selectWith(Predicate2 predicate, P parameter) { return this.iterable.selectWith(predicate, parameter); } public > R selectWith(Predicate2 predicate, P parameter, R targetCollection) { return this.iterable.selectWith(predicate, parameter, targetCollection); } public > R reject(Predicate predicate, R target) { return this.iterable.reject(predicate, target); } public

RichIterable rejectWith(Predicate2 predicate, P parameter) { return this.iterable.rejectWith(predicate, parameter); } public > R rejectWith(Predicate2 predicate, P parameter, R targetCollection) { return this.iterable.rejectWith(predicate, parameter, targetCollection); } public PartitionIterable partition(Predicate predicate) { return this.iterable.partition(predicate); } public

PartitionIterable partitionWith(Predicate2 predicate, P parameter) { return this.iterable.partitionWith(predicate, parameter); } public > R collect(Function function, R target) { return this.iterable.collect(function, target); } public RichIterable collectWith(Function2 function, P parameter) { return this.iterable.collectWith(function, parameter); } public > R collectWith(Function2 function, P parameter, R targetCollection) { return this.iterable.collectWith(function, parameter, targetCollection); } public > R collectIf(Predicate predicate, Function function, R target) { return this.iterable.collectIf(predicate, function, target); } public > R flatCollect(Function> function, R target) { return this.iterable.flatCollect(function, target); } public boolean contains(Object object) { return this.iterable.contains(object); } public boolean containsAllIterable(Iterable source) { return this.iterable.containsAllIterable(source); } public boolean containsAll(Collection source) { return this.iterable.containsAll(source); } public boolean containsAllArguments(Object... elements) { return this.iterable.containsAllArguments(elements); } public Object[] toArray() { return this.iterable.toArray(); } public T[] toArray(T[] a) { return this.iterable.toArray(a); } public void forEach(Procedure procedure) { this.iterable.forEach(procedure); } public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { this.iterable.forEachWithIndex(objectIntProcedure); } public

void forEachWith(Procedure2 procedure, P parameter) { this.iterable.forEachWith(procedure, parameter); } public boolean notEmpty() { return this.iterable.notEmpty(); } public boolean isEmpty() { return this.iterable.isEmpty(); } public int size() { return this.iterable.size(); } public T getFirst() { return this.iterable.getFirst(); } public T getLast() { return this.iterable.getLast(); } public RichIterable select(Predicate predicate) { return this.iterable.select(predicate); } public RichIterable reject(Predicate predicate) { return this.iterable.reject(predicate); } public RichIterable selectInstancesOf(Class clazz) { return this.iterable.selectInstancesOf(clazz); } public RichIterable collect(Function function) { return this.iterable.collect(function); } public BooleanIterable collectBoolean(BooleanFunction booleanFunction) { return this.iterable.collectBoolean(booleanFunction); } public R collectBoolean(BooleanFunction booleanFunction, R target) { return this.iterable.collectBoolean(booleanFunction, target); } public ByteIterable collectByte(ByteFunction byteFunction) { return this.iterable.collectByte(byteFunction); } public R collectByte(ByteFunction byteFunction, R target) { return this.iterable.collectByte(byteFunction, target); } public CharIterable collectChar(CharFunction charFunction) { return this.iterable.collectChar(charFunction); } public R collectChar(CharFunction charFunction, R target) { return this.iterable.collectChar(charFunction, target); } public DoubleIterable collectDouble(DoubleFunction doubleFunction) { return this.iterable.collectDouble(doubleFunction); } public R collectDouble(DoubleFunction doubleFunction, R target) { return this.iterable.collectDouble(doubleFunction, target); } public FloatIterable collectFloat(FloatFunction floatFunction) { return this.iterable.collectFloat(floatFunction); } public R collectFloat(FloatFunction floatFunction, R target) { return this.iterable.collectFloat(floatFunction, target); } public IntIterable collectInt(IntFunction intFunction) { return this.iterable.collectInt(intFunction); } public R collectInt(IntFunction intFunction, R target) { return this.iterable.collectInt(intFunction, target); } public LongIterable collectLong(LongFunction longFunction) { return this.iterable.collectLong(longFunction); } public R collectLong(LongFunction longFunction, R target) { return this.iterable.collectLong(longFunction, target); } public ShortIterable collectShort(ShortFunction shortFunction) { return this.iterable.collectShort(shortFunction); } public R collectShort(ShortFunction shortFunction, R target) { return this.iterable.collectShort(shortFunction, target); } public RichIterable flatCollect(Function> function) { return this.iterable.flatCollect(function); } public RichIterable collectIf(Predicate predicate, Function function) { return this.iterable.collectIf(predicate, function); } public T detect(Predicate predicate) { return this.iterable.detect(predicate); } public

T detectWith(Predicate2 predicate, P parameter) { return this.iterable.detectWith(predicate, parameter); } public T min(Comparator comparator) { return this.iterable.min(comparator); } public T max(Comparator comparator) { return this.iterable.max(comparator); } public T min() { return this.iterable.min(); } public T max() { return this.iterable.max(); } public > T minBy(Function function) { return this.iterable.minBy(function); } public > T maxBy(Function function) { return this.iterable.maxBy(function); } public T detectIfNone(Predicate predicate, Function0 function) { return this.iterable.detectIfNone(predicate, function); } public

T detectWithIfNone(Predicate2 predicate, P parameter, Function0 function) { return this.iterable.detectWithIfNone(predicate, parameter, function); } public int count(Predicate predicate) { return this.iterable.count(predicate); } public

int countWith(Predicate2 predicate, P parameter) { return this.iterable.countWith(predicate, parameter); } public boolean anySatisfy(Predicate predicate) { return this.iterable.anySatisfy(predicate); } public

boolean anySatisfyWith(Predicate2 predicate, P parameter) { return this.iterable.anySatisfyWith(predicate, parameter); } public boolean allSatisfy(Predicate predicate) { return this.iterable.allSatisfy(predicate); } public

boolean allSatisfyWith(Predicate2 predicate, P parameter) { return this.iterable.allSatisfyWith(predicate, parameter); } public boolean noneSatisfy(Predicate predicate) { return this.iterable.noneSatisfy(predicate); } public

boolean noneSatisfyWith(Predicate2 predicate, P parameter) { return this.iterable.noneSatisfyWith(predicate, parameter); } public IV injectInto(IV injectedValue, Function2 function) { return this.iterable.injectInto(injectedValue, function); } public int injectInto(int injectedValue, IntObjectToIntFunction function) { return this.iterable.injectInto(injectedValue, function); } public long injectInto(long injectedValue, LongObjectToLongFunction function) { return this.iterable.injectInto(injectedValue, function); } public double injectInto(double injectedValue, DoubleObjectToDoubleFunction function) { return this.iterable.injectInto(injectedValue, function); } public float injectInto(float injectedValue, FloatObjectToFloatFunction function) { return this.iterable.injectInto(injectedValue, function); } public long sumOfInt(IntFunction function) { return this.iterable.sumOfInt(function); } public double sumOfFloat(FloatFunction function) { return this.iterable.sumOfFloat(function); } public long sumOfLong(LongFunction function) { return this.iterable.sumOfLong(function); } public double sumOfDouble(DoubleFunction function) { return this.iterable.sumOfDouble(function); } public MutableList toList() { return this.iterable.toList(); } public MutableList toSortedList() { return this.iterable.toSortedList(); } public MutableList toSortedList(Comparator comparator) { return this.iterable.toSortedList(comparator); } public > MutableList toSortedListBy(Function function) { return this.iterable.toSortedListBy(function); } public MutableSortedSet toSortedSet() { return this.iterable.toSortedSet(); } public MutableSortedSet toSortedSet(Comparator comparator) { return this.iterable.toSortedSet(comparator); } public > MutableSortedSet toSortedSetBy(Function function) { return this.iterable.toSortedSetBy(function); } public MutableSet toSet() { return this.iterable.toSet(); } public MutableBag toBag() { return this.iterable.toBag(); } public MutableMap toMap( Function keyFunction, Function valueFunction) { return this.iterable.toMap(keyFunction, valueFunction); } public MutableSortedMap toSortedMap( Function keyFunction, Function valueFunction) { return this.iterable.toSortedMap(keyFunction, valueFunction); } public MutableSortedMap toSortedMap(Comparator comparator, Function keyFunction, Function valueFunction) { return this.iterable.toSortedMap(comparator, keyFunction, valueFunction); } public LazyIterable asLazy() { return this.iterable.asLazy(); } public Iterator iterator() { return new UnmodifiableIteratorAdapter(this.iterable.iterator()); } @Override public String toString() { return this.iterable.toString(); } public String makeString() { return this.iterable.makeString(); } public String makeString(String separator) { return this.iterable.makeString(separator); } public String makeString(String start, String separator, String end) { return this.iterable.makeString(start, separator, end); } public void appendString(Appendable appendable) { this.iterable.appendString(appendable); } public void appendString(Appendable appendable, String separator) { this.iterable.appendString(appendable, separator); } public void appendString(Appendable appendable, String start, String separator, String end) { this.iterable.appendString(appendable, start, separator, end); } public Multimap groupBy(Function function) { return this.iterable.groupBy(function); } public > R groupBy( Function function, R target) { return this.iterable.groupBy(function, target); } public Multimap groupByEach(Function> function) { return this.iterable.groupByEach(function); } public > R groupByEach( Function> function, R target) { return this.iterable.groupByEach(function, target); } public MapIterable groupByUniqueKey(Function function) { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".groupByUniqueKey() not implemented yet"); } public RichIterable> zip(Iterable that) { return this.iterable.zip(that); } public >> R zip(Iterable that, R target) { return this.iterable.zip(that, target); } public RichIterable> zipWithIndex() { return this.iterable.zipWithIndex(); } public >> R zipWithIndex(R target) { return this.iterable.zipWithIndex(target); } public RichIterable> chunk(int size) { return this.iterable.chunk(size); } public MapIterable aggregateInPlaceBy(Function groupBy, Function0 zeroValueFactory, Procedure2 mutatingAggregator) { return this.iterable.aggregateInPlaceBy(groupBy, zeroValueFactory, mutatingAggregator); } public MapIterable aggregateBy(Function groupBy, Function0 zeroValueFactory, Function2 nonMutatingAggregator) { return this.iterable.aggregateBy(groupBy, zeroValueFactory, nonMutatingAggregator); } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/bag/000077500000000000000000000000001234315411400266115ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/bag/immutable/000077500000000000000000000000001234315411400305705ustar00rootroot00000000000000AbstractImmutableBag.java000066400000000000000000000214461234315411400354000ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/bag/immutable/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.bag.immutable; import com.gs.collections.api.bag.ImmutableBag; import com.gs.collections.api.bag.primitive.ImmutableBooleanBag; import com.gs.collections.api.bag.primitive.ImmutableByteBag; import com.gs.collections.api.bag.primitive.ImmutableCharBag; import com.gs.collections.api.bag.primitive.ImmutableDoubleBag; import com.gs.collections.api.bag.primitive.ImmutableFloatBag; import com.gs.collections.api.bag.primitive.ImmutableIntBag; import com.gs.collections.api.bag.primitive.ImmutableLongBag; import com.gs.collections.api.bag.primitive.ImmutableShortBag; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.collection.MutableCollection; import com.gs.collections.api.partition.bag.PartitionImmutableBag; import com.gs.collections.api.partition.bag.PartitionMutableBag; import com.gs.collections.impl.bag.mutable.primitive.BooleanHashBag; import com.gs.collections.impl.bag.mutable.primitive.ByteHashBag; import com.gs.collections.impl.bag.mutable.primitive.CharHashBag; import com.gs.collections.impl.bag.mutable.primitive.DoubleHashBag; import com.gs.collections.impl.bag.mutable.primitive.FloatHashBag; import com.gs.collections.impl.bag.mutable.primitive.IntHashBag; import com.gs.collections.impl.bag.mutable.primitive.LongHashBag; import com.gs.collections.impl.bag.mutable.primitive.ShortHashBag; import com.gs.collections.impl.block.factory.Functions; import com.gs.collections.impl.block.factory.Predicates; import com.gs.collections.impl.block.procedure.PartitionPredicate2Procedure; import com.gs.collections.impl.block.procedure.PartitionProcedure; import com.gs.collections.impl.collection.immutable.AbstractImmutableCollection; import com.gs.collections.impl.factory.Bags; import com.gs.collections.impl.partition.bag.PartitionHashBag; /** * @since 1.0 */ public abstract class AbstractImmutableBag extends AbstractImmutableCollection implements ImmutableBag { @Override protected MutableCollection newMutable(int size) { return Bags.mutable.of(); } public

ImmutableBag selectWith(Predicate2 predicate, P parameter) { return this.select(Predicates.bind(predicate, parameter)); } public

ImmutableBag rejectWith(Predicate2 predicate, P parameter) { return this.reject(Predicates.bind(predicate, parameter)); } public PartitionImmutableBag partition(Predicate predicate) { PartitionMutableBag partitionMutableBag = new PartitionHashBag(); this.forEach(new PartitionProcedure(predicate, partitionMutableBag)); return partitionMutableBag.toImmutable(); } public

PartitionImmutableBag partitionWith(Predicate2 predicate, P parameter) { PartitionMutableBag partitionMutableBag = new PartitionHashBag(); this.forEach(new PartitionPredicate2Procedure(predicate, parameter, partitionMutableBag)); return partitionMutableBag.toImmutable(); } public ImmutableBooleanBag collectBoolean(final BooleanFunction booleanFunction) { final BooleanHashBag result = new BooleanHashBag(); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { result.addOccurrences(booleanFunction.booleanValueOf(each), occurrences); } }); return result.toImmutable(); } public ImmutableByteBag collectByte(final ByteFunction byteFunction) { final ByteHashBag result = new ByteHashBag(this.size()); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { result.addOccurrences(byteFunction.byteValueOf(each), occurrences); } }); return result.toImmutable(); } public ImmutableCharBag collectChar(final CharFunction charFunction) { final CharHashBag result = new CharHashBag(this.size()); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { result.addOccurrences(charFunction.charValueOf(each), occurrences); } }); return result.toImmutable(); } public ImmutableDoubleBag collectDouble(final DoubleFunction doubleFunction) { final DoubleHashBag result = new DoubleHashBag(this.size()); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { result.addOccurrences(doubleFunction.doubleValueOf(each), occurrences); } }); return result.toImmutable(); } public ImmutableFloatBag collectFloat(final FloatFunction floatFunction) { final FloatHashBag result = new FloatHashBag(this.size()); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { result.addOccurrences(floatFunction.floatValueOf(each), occurrences); } }); return result.toImmutable(); } public ImmutableIntBag collectInt(final IntFunction intFunction) { final IntHashBag result = new IntHashBag(this.size()); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { result.addOccurrences(intFunction.intValueOf(each), occurrences); } }); return result.toImmutable(); } public ImmutableLongBag collectLong(final LongFunction longFunction) { final LongHashBag result = new LongHashBag(this.size()); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { result.addOccurrences(longFunction.longValueOf(each), occurrences); } }); return result.toImmutable(); } public ImmutableShortBag collectShort(final ShortFunction shortFunction) { final ShortHashBag result = new ShortHashBag(this.size()); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { result.addOccurrences(shortFunction.shortValueOf(each), occurrences); } }); return result.toImmutable(); } public ImmutableBag collectWith(Function2 function, P parameter) { return this.collect(Functions.bind(function, parameter)); } public String toStringOfItemToCount() { if (this.isEmpty()) { return "{}"; } final StringBuilder builder = new StringBuilder().append('{'); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { builder.append(each.toString()); builder.append('='); builder.append(occurrences); builder.append(", "); } }); builder.deleteCharAt(builder.length() - 1); builder.deleteCharAt(builder.length() - 1); return builder.append('}').toString(); } } ImmutableArrayBag.java000066400000000000000000000364341234315411400347160ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/bag/immutable/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.bag.immutable; import java.io.Serializable; import java.util.Collection; import java.util.Comparator; import java.util.Iterator; import java.util.NoSuchElementException; import com.gs.collections.api.bag.Bag; import com.gs.collections.api.bag.ImmutableBag; import com.gs.collections.api.bag.MutableBag; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.predicate.primitive.IntPredicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.map.ImmutableMap; import com.gs.collections.api.map.MutableMap; import com.gs.collections.api.multimap.MutableMultimap; import com.gs.collections.api.multimap.bag.ImmutableBagMultimap; import com.gs.collections.api.set.ImmutableSet; import com.gs.collections.api.tuple.Pair; import com.gs.collections.impl.bag.mutable.HashBag; import com.gs.collections.impl.block.factory.Predicates; import com.gs.collections.impl.block.factory.Predicates2; import com.gs.collections.impl.block.procedure.FlatCollectProcedure; import com.gs.collections.impl.block.procedure.MultimapEachPutProcedure; import com.gs.collections.impl.block.procedure.MultimapPutProcedure; import com.gs.collections.impl.factory.Bags; import com.gs.collections.impl.map.mutable.UnifiedMap; import com.gs.collections.impl.multimap.bag.HashBagMultimap; import com.gs.collections.impl.set.mutable.UnifiedSet; import com.gs.collections.impl.utility.ArrayIterate; import com.gs.collections.impl.utility.Iterate; import com.gs.collections.impl.utility.internal.IterableIterate; /** * @since 1.0 */ public class ImmutableArrayBag extends AbstractImmutableBag implements Serializable { static final int MAXIMUM_USEFUL_ARRAY_BAG_SIZE = 20; private static final long serialVersionUID = 1L; private final T[] keys; private final int[] counts; ImmutableArrayBag(T[] keys, int[] counts) { this.keys = keys; this.counts = counts; if (this.keys.length != this.counts.length) { throw new IllegalArgumentException(); } } public static ImmutableArrayBag newBagWith(T... elements) { return ImmutableArrayBag.copyFrom(Bags.mutable.of(elements)); } public static ImmutableArrayBag copyFrom(Bag bag) { int distinctItemCount = bag.sizeDistinct(); final T[] newKeys = (T[]) new Object[distinctItemCount]; final int[] newCounts = new int[distinctItemCount]; bag.forEachWithOccurrences(new ObjectIntProcedure() { private int index; public void value(T each, int count) { newKeys[this.index] = each; newCounts[this.index] = count; this.index++; } }); return new ImmutableArrayBag(newKeys, newCounts); } public int size() { int sum = 0; for (int value : this.counts) { sum += value; } return sum; } public int sizeDistinct() { return this.keys.length; } public int occurrencesOf(Object item) { int index = ArrayIterate.detectIndexWith(this.keys, Predicates2.equal(), item); if (index > -1) { return this.counts[index]; } return 0; } public void forEachWithOccurrences(ObjectIntProcedure objectIntProcedure) { for (int i = 0; i < this.keys.length; i++) { objectIntProcedure.value(this.keys[i], this.counts[i]); } } public ImmutableBag newWith(T element) { int elementIndex = ArrayIterate.detectIndexWith(this.keys, Predicates2.equal(), element); int distinctItemCount = this.sizeDistinct() + (elementIndex == -1 ? 1 : 0); if (distinctItemCount > MAXIMUM_USEFUL_ARRAY_BAG_SIZE) { return HashBag.newBag(this).with(element).toImmutable(); } return this.newArrayBagWith(element, elementIndex, distinctItemCount); } private ImmutableBag newArrayBagWith(T element, int elementIndex, int distinctItemCount) { T[] newKeys = (T[]) new Object[distinctItemCount]; int[] newCounts = new int[distinctItemCount]; System.arraycopy(this.keys, 0, newKeys, 0, this.keys.length); System.arraycopy(this.counts, 0, newCounts, 0, this.counts.length); if (elementIndex == -1) { newKeys[distinctItemCount - 1] = element; newCounts[distinctItemCount - 1] = 1; } else { newCounts[elementIndex]++; } return new ImmutableArrayBag(newKeys, newCounts); } public ImmutableBag newWithout(T element) { int elementIndex = ArrayIterate.detectIndexWith(this.keys, Predicates2.equal(), element); if (elementIndex > -1) { int distinctItemCount = this.sizeDistinct() - (this.counts[elementIndex] == 1 ? 1 : 0); T[] newKeys = (T[]) new Object[distinctItemCount]; int[] newCounts = new int[distinctItemCount]; if (distinctItemCount == this.sizeDistinct()) { System.arraycopy(this.keys, 0, newKeys, 0, distinctItemCount); System.arraycopy(this.counts, 0, newCounts, 0, distinctItemCount); newCounts[elementIndex]--; } else { System.arraycopy(this.keys, 0, newKeys, 0, elementIndex); System.arraycopy(this.counts, 0, newCounts, 0, elementIndex); System.arraycopy(this.keys, elementIndex + 1, newKeys, elementIndex, newKeys.length - elementIndex); System.arraycopy(this.counts, elementIndex + 1, newCounts, elementIndex, newCounts.length - elementIndex); } return new ImmutableArrayBag(newKeys, newCounts); } return this; } public MutableMap toMapOfItemToCount() { final MutableMap map = UnifiedMap.newMap(this.size()); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T item, int count) { map.put(item, count); } }); return map; } public ImmutableBag toImmutable() { return this; } public ImmutableBag newWithAll(Iterable elements) { return Bags.immutable.ofAll(Iterate.addAllTo(elements, HashBag.newBag(this))); } public ImmutableBag newWithoutAll(Iterable elements) { return this.reject(Predicates.in(elements)); } public ImmutableBag selectByOccurrences(final IntPredicate predicate) { final MutableBag result = HashBag.newBag(); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { if (predicate.accept(occurrences)) { result.addOccurrences(each, occurrences); } } }); return result.toImmutable(); } public ImmutableBag select(final Predicate predicate) { final MutableBag result = HashBag.newBag(); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { if (predicate.accept(each)) { result.addOccurrences(each, occurrences); } } }); return result.toImmutable(); } @Override public > R selectWith( Predicate2 predicate, P parameter, R targetCollection) { return IterableIterate.selectWith(this, predicate, parameter, targetCollection); } public ImmutableBag reject(Predicate predicate) { return this.select(Predicates.not(predicate)); } @Override public > R rejectWith( Predicate2 predicate, P parameter, R targetCollection) { return IterableIterate.rejectWith(this, predicate, parameter, targetCollection); } public ImmutableBag selectInstancesOf(final Class clazz) { final MutableBag result = HashBag.newBag(); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int index) { if (clazz.isInstance(each)) { result.addOccurrences((S) each, index); } } }); return ImmutableArrayBag.copyFrom(result); } public ImmutableBag collect(final Function function) { final MutableBag result = HashBag.newBag(); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int index) { result.addOccurrences(function.valueOf(each), index); } }); return ImmutableArrayBag.copyFrom(result); } public ImmutableBag collectIf( Predicate predicate, Function function) { return ImmutableArrayBag.copyFrom(IterableIterate.collectIf(this, predicate, function, HashBag.newBag())); } public ImmutableBagMultimap groupBy(Function function) { return this.groupBy(function, HashBagMultimap.newMultimap()).toImmutable(); } public ImmutableBagMultimap groupByEach(Function> function) { return this.groupByEach(function, HashBagMultimap.newMultimap()).toImmutable(); } public ImmutableMap groupByUniqueKey(Function function) { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".groupByUniqueKey() not implemented yet"); } public T getFirst() { return ArrayIterate.getFirst(this.keys); } public T getLast() { return ArrayIterate.getLast(this.keys); } public ImmutableBag flatCollect(Function> function) { FlatCollectProcedure procedure = new FlatCollectProcedure(function, HashBag.newBag()); this.forEach(procedure); return ((MutableBag) procedure.getCollection()).toImmutable(); } @Override public > R groupBy( Function function, R target) { this.forEach(MultimapPutProcedure.on(target, function)); return target; } @Override public > R groupByEach( Function> function, R target) { this.forEach(MultimapEachPutProcedure.on(target, function)); return target; } @Override public boolean equals(Object other) { if (this == other) { return true; } if (!(other instanceof Bag)) { return false; } Bag bag = (Bag) other; if (this.size() != bag.size()) { return false; } for (int i = 0; i < this.keys.length; i++) { if (this.counts[i] != bag.occurrencesOf(this.keys[i])) { return false; } } return true; } @Override public int hashCode() { int sum = 0; for (int i = 0; i < this.keys.length; i++) { T each = this.keys[i]; sum += (each == null ? 0 : each.hashCode()) ^ this.counts[i]; } return sum; } public void forEach(Procedure procedure) { for (int i = 0; i < this.keys.length; i++) { T key = this.keys[i]; for (int j = 1; j <= this.counts[i]; j++) { procedure.value(key); } } } public Iterator iterator() { return new ArrayBagIterator(); } private final class ArrayBagIterator implements Iterator { private int keyCount = -1; private int countCount = -1; private ArrayBagIterator() { this.keyCount = ImmutableArrayBag.this.keys.length - 1; this.countCount = this.keyCount < 0 ? -1 : ImmutableArrayBag.this.counts[ImmutableArrayBag.this.keys.length - 1]; } public boolean hasNext() { return this.keyCount >= 0; } public T next() { if (!this.hasNext()) { throw new NoSuchElementException(); } T result = ImmutableArrayBag.this.keys[this.keyCount]; --this.countCount; if (this.countCount == 0) { --this.keyCount; this.countCount = this.keyCount < 0 ? 0 : ImmutableArrayBag.this.counts[this.keyCount]; } return result; } public void remove() { throw new UnsupportedOperationException("Cannot remove from an ImmutableArrayBag"); } } @Override public T min(Comparator comparator) { return ArrayIterate.min(this.keys, comparator); } @Override public T max(Comparator comparator) { return ArrayIterate.max(this.keys, comparator); } @Override public T min() { return ArrayIterate.min(this.keys); } @Override public T max() { return ArrayIterate.max(this.keys); } @Override public > T minBy(Function function) { return ArrayIterate.minBy(this.keys, function); } @Override public > T maxBy(Function function) { return ArrayIterate.maxBy(this.keys, function); } public ImmutableBag> zip(Iterable that) { return this.zip(that, HashBag.>newBag()).toImmutable(); } public ImmutableSet> zipWithIndex() { return this.zipWithIndex(UnifiedSet.>newSet()).toImmutable(); } protected Object writeReplace() { return new ImmutableBagSerializationProxy(this); } } ImmutableBagFactoryImpl.java000066400000000000000000000054111234315411400360600ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/bag/immutable/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.bag.immutable; import com.gs.collections.api.bag.Bag; import com.gs.collections.api.bag.ImmutableBag; import com.gs.collections.api.factory.bag.ImmutableBagFactory; import com.gs.collections.impl.utility.Iterate; import net.jcip.annotations.Immutable; @Immutable public final class ImmutableBagFactoryImpl implements ImmutableBagFactory { public ImmutableBag of() { return this.with(); } public ImmutableBag with() { return (ImmutableBag) ImmutableEmptyBag.INSTANCE; } public ImmutableBag of(T element) { return this.with(element); } public ImmutableBag with(T element) { return new ImmutableSingletonBag(element); } public ImmutableBag of(T... elements) { return this.with(elements); } public ImmutableBag with(T... elements) { if (elements == null || elements.length == 0) { return this.of(); } if (elements.length == 1) { return this.of(elements[0]); } if (elements.length < ImmutableArrayBag.MAXIMUM_USEFUL_ARRAY_BAG_SIZE) { return ImmutableArrayBag.newBagWith(elements); } return ImmutableHashBag.newBagWith(elements); } public ImmutableBag ofAll(Iterable items) { return this.withAll(items); } public ImmutableBag withAll(Iterable items) { if (items instanceof ImmutableBag) { return (ImmutableBag) items; } if (items instanceof Bag) { Bag bag = (Bag) items; if (bag.isEmpty()) { return this.with(); } if (bag.size() == 1) { return this.with(bag.getFirst()); } if (bag.sizeDistinct() < ImmutableArrayBag.MAXIMUM_USEFUL_ARRAY_BAG_SIZE) { return ImmutableArrayBag.copyFrom(bag); } return new ImmutableHashBag(bag); } return this.of((T[]) Iterate.toArray(items)); } } ImmutableBagSerializationProxy.java000066400000000000000000000050001234315411400375000ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/bag/immutable/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.bag.immutable; import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; import com.gs.collections.api.bag.MutableBag; import com.gs.collections.api.bag.UnsortedBag; import com.gs.collections.impl.bag.mutable.HashBag; import com.gs.collections.impl.block.procedure.checked.CheckedObjectIntProcedure; class ImmutableBagSerializationProxy implements Externalizable { private static final long serialVersionUID = 1L; private UnsortedBag bag; @SuppressWarnings("UnusedDeclaration") public ImmutableBagSerializationProxy() { // Empty constructor for Externalizable class } ImmutableBagSerializationProxy(UnsortedBag bag) { this.bag = bag; } public void writeExternal(final ObjectOutput out) throws IOException { out.writeInt(this.bag.sizeDistinct()); try { this.bag.forEachWithOccurrences(new CheckedObjectIntProcedure() { @Override public void safeValue(T object, int index) throws IOException { out.writeObject(object); out.writeInt(index); } }); } catch (RuntimeException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw e; } } public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { int size = in.readInt(); MutableBag deserializedBag = new HashBag(size); for (int i = 0; i < size; i++) { deserializedBag.addOccurrences((T) in.readObject(), in.readInt()); } this.bag = deserializedBag; } protected Object readResolve() { return this.bag.toImmutable(); } } ImmutableEmptyBag.java000066400000000000000000000535611234315411400347360ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/bag/immutable/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.bag.immutable; import java.io.IOException; import java.io.Serializable; import java.util.Collection; import java.util.Comparator; import java.util.Iterator; import java.util.NoSuchElementException; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.RichIterable; import com.gs.collections.api.bag.Bag; import com.gs.collections.api.bag.ImmutableBag; import com.gs.collections.api.bag.MutableBag; import com.gs.collections.api.bag.primitive.ImmutableBooleanBag; import com.gs.collections.api.bag.primitive.ImmutableByteBag; import com.gs.collections.api.bag.primitive.ImmutableCharBag; import com.gs.collections.api.bag.primitive.ImmutableDoubleBag; import com.gs.collections.api.bag.primitive.ImmutableFloatBag; import com.gs.collections.api.bag.primitive.ImmutableIntBag; import com.gs.collections.api.bag.primitive.ImmutableLongBag; import com.gs.collections.api.bag.primitive.ImmutableShortBag; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.DoubleObjectToDoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.FloatObjectToFloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.IntObjectToIntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.LongObjectToLongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.predicate.primitive.IntPredicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.collection.primitive.MutableBooleanCollection; import com.gs.collections.api.collection.primitive.MutableByteCollection; import com.gs.collections.api.collection.primitive.MutableCharCollection; import com.gs.collections.api.collection.primitive.MutableDoubleCollection; import com.gs.collections.api.collection.primitive.MutableFloatCollection; import com.gs.collections.api.collection.primitive.MutableIntCollection; import com.gs.collections.api.collection.primitive.MutableLongCollection; import com.gs.collections.api.collection.primitive.MutableShortCollection; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.map.ImmutableMap; import com.gs.collections.api.map.MutableMap; import com.gs.collections.api.map.sorted.MutableSortedMap; import com.gs.collections.api.multimap.MutableMultimap; import com.gs.collections.api.multimap.bag.ImmutableBagMultimap; import com.gs.collections.api.partition.bag.PartitionImmutableBag; import com.gs.collections.api.set.ImmutableSet; import com.gs.collections.api.set.MutableSet; import com.gs.collections.api.set.sorted.MutableSortedSet; import com.gs.collections.api.stack.MutableStack; import com.gs.collections.api.tuple.Pair; import com.gs.collections.impl.EmptyIterator; import com.gs.collections.impl.bag.mutable.HashBag; import com.gs.collections.impl.block.factory.Comparators; import com.gs.collections.impl.factory.Bags; import com.gs.collections.impl.factory.Lists; import com.gs.collections.impl.factory.Maps; import com.gs.collections.impl.factory.Sets; import com.gs.collections.impl.factory.Stacks; import com.gs.collections.impl.factory.primitive.BooleanBags; import com.gs.collections.impl.factory.primitive.ByteBags; import com.gs.collections.impl.factory.primitive.CharBags; import com.gs.collections.impl.factory.primitive.DoubleBags; import com.gs.collections.impl.factory.primitive.FloatBags; import com.gs.collections.impl.factory.primitive.IntBags; import com.gs.collections.impl.factory.primitive.LongBags; import com.gs.collections.impl.factory.primitive.ShortBags; import com.gs.collections.impl.map.mutable.UnifiedMap; import com.gs.collections.impl.map.sorted.mutable.TreeSortedMap; import com.gs.collections.impl.multimap.bag.HashBagMultimap; import com.gs.collections.impl.partition.bag.PartitionHashBag; import com.gs.collections.impl.set.mutable.UnifiedSet; import com.gs.collections.impl.set.sorted.mutable.TreeSortedSet; import com.gs.collections.impl.utility.ArrayIterate; import com.gs.collections.impl.utility.Iterate; import com.gs.collections.impl.utility.LazyIterate; import net.jcip.annotations.Immutable; /** * This is a zero element {@link ImmutableBag} which is created by calling the Bags.immutable.of(). * * @since 1.0 */ @Immutable final class ImmutableEmptyBag implements ImmutableBag, Serializable { static final ImmutableBag INSTANCE = new ImmutableEmptyBag(); private static final long serialVersionUID = 1L; private static final LazyIterable LAZY_ITERABLE = LazyIterate.adapt(INSTANCE); private static final Object[] TO_ARRAY = new Object[0]; private static final PartitionImmutableBag IMMUTABLE_EMPTY_PARTITION = new PartitionHashBag().toImmutable(); @Override public boolean equals(Object obj) { if (obj == this) { return true; } return obj instanceof Bag && ((Bag) obj).isEmpty(); } public int sizeDistinct() { return 0; } public String toStringOfItemToCount() { return ""; } public int occurrencesOf(Object item) { return 0; } public void forEachWithOccurrences(ObjectIntProcedure objectIntProcedure) { } public MutableMap toMapOfItemToCount() { return Maps.mutable.of(); } public ImmutableBag toImmutable() { return this; } @Override public int hashCode() { return 0; } public int size() { return 0; } public boolean isEmpty() { return true; } public boolean notEmpty() { return false; } public boolean contains(Object object) { return false; } public boolean containsAll(Collection source) { return this.containsAllIterable(source); } public boolean containsAllIterable(Iterable source) { return Iterate.isEmpty(source); } public boolean containsAllArguments(Object... elements) { return ArrayIterate.isEmpty(elements); } public void forEach(Procedure procedure) { } public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { } public

void forEachWith(Procedure2 procedure, P parameter) { } public T getFirst() { return null; } public T getLast() { return null; } public Iterator iterator() { return EmptyIterator.getInstance(); } public ImmutableBag newWith(T element) { return Bags.immutable.of(element); } public ImmutableBag newWithout(T element) { return this; } public ImmutableBag newWithAll(Iterable elements) { return HashBag.newBag(elements).toImmutable(); } public ImmutableBag newWithoutAll(Iterable elements) { return this; } public ImmutableBag selectByOccurrences(IntPredicate predicate) { return this; } public ImmutableBag select(Predicate predicate) { return this; } public > R select(Predicate predicate, R target) { return target; } public

ImmutableBag selectWith(Predicate2 predicate, P parameter) { return this; } public > R selectWith( Predicate2 predicate, P parameter, R targetCollection) { return targetCollection; } public ImmutableBag reject(Predicate predicate) { return this; } public > R reject(Predicate predicate, R target) { return target; } public

ImmutableBag rejectWith(Predicate2 predicate, P parameter) { return this; } public > R rejectWith( Predicate2 predicate, P parameter, R targetCollection) { return targetCollection; } public PartitionImmutableBag partition(Predicate predicate) { return (PartitionImmutableBag) IMMUTABLE_EMPTY_PARTITION; } public

PartitionImmutableBag partitionWith(Predicate2 predicate, P parameter) { return (PartitionImmutableBag) IMMUTABLE_EMPTY_PARTITION; } public ImmutableBag selectInstancesOf(Class clazz) { return (ImmutableBag) INSTANCE; } public ImmutableBag collect(Function function) { return (ImmutableBag) INSTANCE; } public ImmutableBooleanBag collectBoolean(BooleanFunction booleanFunction) { return BooleanBags.immutable.of(); } public R collectBoolean(BooleanFunction booleanFunction, R target) { return target; } public ImmutableByteBag collectByte(ByteFunction byteFunction) { return ByteBags.immutable.of(); } public R collectByte(ByteFunction byteFunction, R target) { return target; } public ImmutableCharBag collectChar(CharFunction charFunction) { return CharBags.immutable.of(); } public R collectChar(CharFunction charFunction, R target) { return target; } public ImmutableDoubleBag collectDouble(DoubleFunction doubleFunction) { return DoubleBags.immutable.of(); } public R collectDouble(DoubleFunction doubleFunction, R target) { return target; } public ImmutableFloatBag collectFloat(FloatFunction floatFunction) { return FloatBags.immutable.of(); } public R collectFloat(FloatFunction floatFunction, R target) { return target; } public ImmutableIntBag collectInt(IntFunction intFunction) { return IntBags.immutable.of(); } public R collectInt(IntFunction intFunction, R target) { return target; } public ImmutableLongBag collectLong(LongFunction longFunction) { return LongBags.immutable.of(); } public R collectLong(LongFunction longFunction, R target) { return target; } public ImmutableShortBag collectShort(ShortFunction shortFunction) { return ShortBags.immutable.of(); } public R collectShort(ShortFunction shortFunction, R target) { return target; } public > R collect(Function function, R target) { return target; } public ImmutableBag collectWith(Function2 function, P parameter) { return (ImmutableBag) INSTANCE; } public > R collectWith( Function2 function, P parameter, R targetCollection) { return targetCollection; } public ImmutableBag collectIf( Predicate predicate, Function function) { return (ImmutableBag) INSTANCE; } public > R collectIf( Predicate predicate, Function function, R target) { return target; } public ImmutableBag flatCollect(Function> function) { return (ImmutableBag) INSTANCE; } public > R flatCollect( Function> function, R target) { return target; } public ImmutableBagMultimap groupBy(Function function) { // TODO: Create a Singleton ImmutableEmptyBagMultimap for efficiency return HashBagMultimap.newMultimap().toImmutable(); } public ImmutableBagMultimap groupByEach(Function> function) { // TODO: Create a Singleton ImmutableEmptyBagMultimap for efficiency return HashBagMultimap.newMultimap().toImmutable(); } public > R groupBy( Function function, R target) { return target; } public > R groupByEach( Function> function, R target) { return target; } public ImmutableMap groupByUniqueKey(Function function) { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".groupByUniqueKey() not implemented yet"); } public T detect(Predicate predicate) { return null; } public

T detectWith(Predicate2 predicate, P parameter) { return null; } public T detectIfNone(Predicate predicate, Function0 function) { return function.value(); } public

T detectWithIfNone(Predicate2 predicate, P parameter, Function0 function) { return function.value(); } public int count(Predicate predicate) { return 0; } public

int countWith(Predicate2 predicate, P parameter) { return 0; } public boolean anySatisfy(Predicate predicate) { return false; } public boolean allSatisfy(Predicate predicate) { return true; } public boolean noneSatisfy(Predicate predicate) { return true; } public

boolean anySatisfyWith(Predicate2 predicate, P parameter) { return false; } public

boolean allSatisfyWith(Predicate2 predicate, P parameter) { return true; } public

boolean noneSatisfyWith(Predicate2 predicate, P parameter) { return true; } public IV injectInto(IV injectedValue, Function2 function) { return injectedValue; } public int injectInto(int injectedValue, IntObjectToIntFunction function) { return injectedValue; } public long injectInto(long injectedValue, LongObjectToLongFunction function) { return injectedValue; } public double injectInto(double injectedValue, DoubleObjectToDoubleFunction function) { return injectedValue; } public float injectInto(float injectedValue, FloatObjectToFloatFunction function) { return injectedValue; } public long sumOfInt(IntFunction function) { return 0; } public double sumOfFloat(FloatFunction function) { return 0.0F; } public long sumOfLong(LongFunction function) { return 0L; } public double sumOfDouble(DoubleFunction function) { return 0.0d; } public MutableList toList() { return Lists.mutable.of(); } public MutableList toSortedList() { return Lists.mutable.of(); } public MutableList toSortedList(Comparator comparator) { return Lists.mutable.of(); } public > MutableList toSortedListBy(Function function) { return Lists.mutable.of(); } public MutableSortedSet toSortedSet() { return TreeSortedSet.newSet(); } public MutableSortedSet toSortedSet(Comparator comparator) { return TreeSortedSet.newSet(comparator); } public > MutableSortedSet toSortedSetBy(Function function) { return TreeSortedSet.newSet(Comparators.byFunction(function)); } public MutableSet toSet() { return UnifiedSet.newSet(); } public MutableBag toBag() { return Bags.mutable.of(); } public MutableStack toStack() { return Stacks.mutable.of(); } public MutableMap toMap( Function keyFunction, Function valueFunction) { return UnifiedMap.newMap(); } public MutableSortedMap toSortedMap( Function keyFunction, Function valueFunction) { return TreeSortedMap.newMap(); } public MutableSortedMap toSortedMap(Comparator comparator, Function keyFunction, Function valueFunction) { return TreeSortedMap.newMap(comparator); } public LazyIterable asLazy() { return (LazyIterable) LAZY_ITERABLE; } public Object[] toArray() { return TO_ARRAY; } public T[] toArray(T[] a) { if (a.length > 0) { a[0] = null; } return a; } public T min(Comparator comparator) { throw new NoSuchElementException(); } public T max(Comparator comparator) { throw new NoSuchElementException(); } public T min() { throw new NoSuchElementException(); } public T max() { throw new NoSuchElementException(); } public > T minBy(Function function) { throw new NoSuchElementException(); } public > T maxBy(Function function) { throw new NoSuchElementException(); } @Override public String toString() { return "[]"; } public String makeString() { return ""; } public String makeString(String separator) { return ""; } public String makeString(String start, String separator, String end) { return start + end; } public void appendString(Appendable appendable) { } public void appendString(Appendable appendable, String separator) { } public void appendString(Appendable appendable, String start, String separator, String end) { try { appendable.append(start); appendable.append(end); } catch (IOException e) { throw new RuntimeException(e); } } public ImmutableBag> zip(Iterable that) { return Bags.immutable.of(); } public >> R zip(Iterable that, R target) { return target; } public ImmutableSet> zipWithIndex() { return Sets.immutable.of(); } public >> R zipWithIndex(R target) { return target; } public RichIterable> chunk(int size) { if (size <= 0) { throw new IllegalArgumentException("Size for groups must be positive but was: " + size); } return Bags.immutable.of(); } private Object writeReplace() { return new ImmutableBagSerializationProxy(this); } public ImmutableMap aggregateInPlaceBy( Function groupBy, Function0 zeroValueFactory, Procedure2 mutatingAggregator) { return Maps.immutable.of(); } public ImmutableMap aggregateBy( Function groupBy, Function0 zeroValueFactory, Function2 nonMutatingAggregator) { return Maps.immutable.of(); } } ImmutableHashBag.java000066400000000000000000000352041234315411400345150ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/bag/immutable/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.bag.immutable; import java.io.Serializable; import java.util.Arrays; import java.util.Collection; import java.util.Comparator; import java.util.Iterator; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.bag.Bag; import com.gs.collections.api.bag.ImmutableBag; import com.gs.collections.api.bag.MutableBag; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.predicate.primitive.IntPredicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.map.ImmutableMap; import com.gs.collections.api.map.MapIterable; import com.gs.collections.api.map.MutableMap; import com.gs.collections.api.multimap.MutableMultimap; import com.gs.collections.api.multimap.bag.ImmutableBagMultimap; import com.gs.collections.api.partition.bag.PartitionImmutableBag; import com.gs.collections.api.set.ImmutableSet; import com.gs.collections.api.set.MutableSet; import com.gs.collections.api.tuple.Pair; import com.gs.collections.impl.UnmodifiableIteratorAdapter; import com.gs.collections.impl.bag.mutable.HashBag; import com.gs.collections.impl.block.factory.Predicates; import com.gs.collections.impl.factory.Bags; import com.gs.collections.impl.utility.Iterate; /** * @since 1.0 */ public class ImmutableHashBag extends AbstractImmutableBag implements Serializable { private static final long serialVersionUID = 1L; private final MutableBag delegate; public ImmutableHashBag() { this.delegate = Bags.mutable.of(); } public ImmutableHashBag(Iterable source) { this.delegate = HashBag.newBag(source); } public ImmutableHashBag(Bag source) { this.delegate = HashBag.newBag(source); } public static ImmutableHashBag newBag() { return new ImmutableHashBag(); } public static ImmutableHashBag newBag(Iterable source) { return new ImmutableHashBag(source); } public static ImmutableHashBag newBagWith(T... elements) { return ImmutableHashBag.newBag(Arrays.asList(elements)); } public static ImmutableHashBag newBagWith(Bag bag) { return new ImmutableHashBag(bag); } public ImmutableBag newWith(T element) { return HashBag.newBag(this.delegate).with(element).toImmutable(); } public ImmutableBag newWithout(T element) { HashBag hashBag = HashBag.newBag(this.delegate); hashBag.remove(element); return hashBag.toImmutable(); } public ImmutableBag newWithAll(Iterable elements) { return Iterate.addAllTo(elements, HashBag.newBag(this.delegate)).toImmutable(); } public ImmutableBag newWithoutAll(Iterable elements) { return this.reject(Predicates.in(elements)); } public int size() { return this.delegate.size(); } public ImmutableBagMultimap groupBy(Function function) { return this.delegate.groupBy(function).toImmutable(); } @Override public > R groupBy( Function function, R target) { return this.delegate.groupBy(function, target); } public ImmutableBagMultimap groupByEach(Function> function) { return this.delegate.groupByEach(function).toImmutable(); } @Override public > R groupByEach( Function> function, R target) { return this.delegate.groupByEach(function, target); } public ImmutableMap groupByUniqueKey(Function function) { return this.delegate.groupByUniqueKey(function).toImmutable(); } @Override public boolean isEmpty() { return this.delegate.isEmpty(); } @Override public boolean notEmpty() { return this.delegate.notEmpty(); } public T getFirst() { return this.delegate.getFirst(); } public T getLast() { return this.delegate.getLast(); } @Override public T min(Comparator comparator) { return this.delegate.min(comparator); } @Override public T max(Comparator comparator) { return this.delegate.max(comparator); } @Override public T min() { return this.delegate.min(); } @Override public T max() { return this.delegate.max(); } @Override public > T minBy(Function function) { return this.delegate.minBy(function); } @Override public > T maxBy(Function function) { return this.delegate.maxBy(function); } @Override public boolean contains(Object object) { return this.delegate.contains(object); } @Override public boolean containsAllIterable(Iterable source) { return this.delegate.containsAllIterable(source); } @Override public boolean containsAllArguments(Object... elements) { return this.delegate.containsAllArguments(elements); } @Override public MutableMap toMap( Function keyFunction, Function valueFunction) { return this.delegate.toMap(keyFunction, valueFunction); } public void forEach(Procedure procedure) { this.delegate.forEach(procedure); } @Override public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { this.delegate.forEachWithIndex(objectIntProcedure); } @Override public

void forEachWith(Procedure2 procedure, P parameter) { this.delegate.forEachWith(procedure, parameter); } public ImmutableBag selectByOccurrences(IntPredicate predicate) { return this.delegate.selectByOccurrences(predicate).toImmutable(); } public ImmutableBag select(Predicate predicate) { return this.delegate.select(predicate).toImmutable(); } public ImmutableBag reject(Predicate predicate) { return this.delegate.reject(predicate).toImmutable(); } @Override public PartitionImmutableBag partition(Predicate predicate) { return this.delegate.partition(predicate).toImmutable(); } @Override public

PartitionImmutableBag partitionWith(Predicate2 predicate, P parameter) { return this.delegate.partitionWith(predicate, parameter).toImmutable(); } public ImmutableBag selectInstancesOf(Class clazz) { return this.delegate.selectInstancesOf(clazz).toImmutable(); } public ImmutableBag collect(Function function) { return this.delegate.collect(function).toImmutable(); } public ImmutableBag collectIf( Predicate predicate, Function function) { return this.delegate.collectIf(predicate, function).toImmutable(); } public ImmutableBag flatCollect(Function> function) { return this.delegate.flatCollect(function).toImmutable(); } @Override public MutableList toList() { return this.delegate.toList(); } public int sizeDistinct() { return this.delegate.sizeDistinct(); } public int occurrencesOf(Object item) { return this.delegate.occurrencesOf(item); } public void forEachWithOccurrences(ObjectIntProcedure objectIntProcedure) { this.delegate.forEachWithOccurrences(objectIntProcedure); } @Override public MutableList toSortedList() { return this.delegate.toSortedList(); } @Override public MutableList toSortedList(Comparator comparator) { return this.delegate.toSortedList(comparator); } @Override public > R select(Predicate predicate, R target) { return this.delegate.select(predicate, target); } @Override public > R selectWith( Predicate2 predicate, P parameter, R targetCollection) { return this.delegate.selectWith(predicate, parameter, targetCollection); } @Override public > R reject(Predicate predicate, R target) { return this.delegate.reject(predicate, target); } @Override public > R rejectWith( Predicate2 predicate, P parameter, R targetCollection) { return this.delegate.rejectWith(predicate, parameter, targetCollection); } @Override public > R collect(Function function, R target) { return this.delegate.collect(function, target); } @Override public > R collectWith( Function2 function, P parameter, R targetCollection) { return this.delegate.collectWith(function, parameter, targetCollection); } @Override public > R flatCollect( Function> function, R target) { return this.delegate.flatCollect(function, target); } @Override public > R collectIf( Predicate predicate, Function function, R target) { return this.delegate.collectIf(predicate, function, target); } @Override public T detect(Predicate predicate) { return this.delegate.detect(predicate); } @Override public T detectIfNone(Predicate predicate, Function0 function) { return this.delegate.detectIfNone(predicate, function); } @Override public int count(Predicate predicate) { return this.delegate.count(predicate); } @Override public boolean anySatisfy(Predicate predicate) { return this.delegate.anySatisfy(predicate); } @Override public boolean allSatisfy(Predicate predicate) { return this.delegate.allSatisfy(predicate); } @Override public boolean noneSatisfy(Predicate predicate) { return this.delegate.noneSatisfy(predicate); } @Override public IV injectInto(IV injectedValue, Function2 function) { return this.delegate.injectInto(injectedValue, function); } @Override public boolean equals(Object obj) { return this.delegate.equals(obj); } @Override public int hashCode() { return this.delegate.hashCode(); } public MapIterable toMapOfItemToCount() { return this.delegate.toMapOfItemToCount(); } @Override public MutableSet toSet() { return this.delegate.toSet(); } @Override public MutableBag toBag() { return this.delegate.toBag(); } public ImmutableBag toImmutable() { return this; } @Override public LazyIterable asLazy() { return this.delegate.asLazy(); } @Override public Object[] toArray() { return this.delegate.toArray(); } @Override public T[] toArray(T[] a) { return this.delegate.toArray(a); } @Override public String toString() { return this.makeString("[", ", ", "]"); } @Override public String makeString() { return this.delegate.makeString(); } @Override public String makeString(String separator) { return this.delegate.makeString(separator); } @Override public String makeString(String start, String separator, String end) { return this.delegate.makeString(start, separator, end); } @Override public void appendString(Appendable appendable) { this.delegate.appendString(appendable); } @Override public void appendString(Appendable appendable, String separator) { this.delegate.appendString(appendable, separator); } @Override public void appendString(Appendable appendable, String start, String separator, String end) { this.delegate.appendString(appendable, start, separator, end); } public ImmutableBag> zip(Iterable that) { return this.delegate.zip(that).toImmutable(); } @Override public >> R zip(Iterable that, R target) { return this.delegate.zip(that, target); } public ImmutableSet> zipWithIndex() { return this.delegate.zipWithIndex().toImmutable(); } @Override public >> R zipWithIndex(R target) { return this.delegate.zipWithIndex(target); } public Iterator iterator() { return new UnmodifiableIteratorAdapter(this.delegate.iterator()); } protected Object writeReplace() { return new ImmutableBagSerializationProxy(this); } } ImmutableSingletonBag.java000066400000000000000000000311561234315411400355760ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/bag/immutable/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.bag.immutable; import java.io.Serializable; import java.util.Collection; import java.util.Comparator; import java.util.Iterator; import java.util.NoSuchElementException; import com.gs.collections.api.bag.Bag; import com.gs.collections.api.bag.ImmutableBag; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.predicate.primitive.IntPredicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.map.ImmutableMap; import com.gs.collections.api.map.MutableMap; import com.gs.collections.api.multimap.MutableMultimap; import com.gs.collections.api.multimap.bag.ImmutableBagMultimap; import com.gs.collections.api.set.ImmutableSet; import com.gs.collections.api.tuple.Pair; import com.gs.collections.impl.bag.mutable.HashBag; import com.gs.collections.impl.block.factory.Comparators; import com.gs.collections.impl.block.factory.Predicates; import com.gs.collections.impl.block.factory.Predicates2; import com.gs.collections.impl.block.procedure.MultimapEachPutProcedure; import com.gs.collections.impl.factory.Bags; import com.gs.collections.impl.factory.Sets; import com.gs.collections.impl.map.mutable.UnifiedMap; import com.gs.collections.impl.multimap.bag.HashBagMultimap; import com.gs.collections.impl.tuple.Tuples; import com.gs.collections.impl.utility.ArrayIterate; import com.gs.collections.impl.utility.Iterate; /** * @since 1.0 */ final class ImmutableSingletonBag extends AbstractImmutableBag implements Serializable { private static final long serialVersionUID = 1L; private final T value; ImmutableSingletonBag(T object) { this.value = object; } @Override public boolean allSatisfy(Predicate predicate) { return predicate.accept(this.value); } @Override public boolean noneSatisfy(Predicate predicate) { return !predicate.accept(this.value); } @Override public IV injectInto(IV injectedValue, Function2 function) { return function.value(injectedValue, this.value); } @Override public T min(Comparator comparator) { return this.value; } @Override public T max(Comparator comparator) { return this.value; } @Override public T min() { return this.value; } @Override public T max() { return this.value; } @Override public > T minBy(Function function) { return this.value; } @Override public > T maxBy(Function function) { return this.value; } public ImmutableBag newWith(T element) { return Bags.immutable.of(this.value, element); } public ImmutableBag newWithout(T element) { return this.emptyIfMatchesOrThis(Predicates.equal(element)); } private ImmutableBag emptyIfMatchesOrThis(Predicate predicate) { return predicate.accept(this.value) ? Bags.immutable.of() : this; } public ImmutableBag newWithAll(Iterable elements) { return HashBag.newBag(elements).with(this.value).toImmutable(); } public ImmutableBag newWithoutAll(Iterable elements) { return this.emptyIfMatchesOrThis(Predicates.in(elements)); } public int size() { return 1; } @Override public boolean isEmpty() { return false; } @Override public boolean notEmpty() { return true; } public T getFirst() { return this.value; } public T getLast() { return this.value; } @Override public boolean contains(Object object) { return Comparators.nullSafeEquals(this.value, object); } @Override public boolean containsAllIterable(Iterable source) { return Iterate.allSatisfy(source, Predicates.equal(this.value)); } @Override public boolean containsAllArguments(Object... elements) { return ArrayIterate.allSatisfy(elements, Predicates.equal(this.value)); } public ImmutableBag selectByOccurrences(IntPredicate predicate) { return predicate.accept(1) ? this : Bags.immutable.of(); } public ImmutableBag select(Predicate predicate) { return predicate.accept(this.value) ? this : Bags.immutable.of(); } @Override public > R select(Predicate predicate, R target) { if (predicate.accept(this.value)) { target.add(this.value); } return target; } @Override public > R selectWith( Predicate2 predicate, P parameter, R targetCollection) { if (predicate.accept(this.value, parameter)) { targetCollection.add(this.value); } return targetCollection; } public ImmutableBag reject(Predicate predicate) { return this.select(Predicates.not(predicate)); } @Override public > R reject(Predicate predicate, R target) { return this.select(Predicates.not(predicate), target); } @Override public > R rejectWith( Predicate2 predicate, P parameter, R targetCollection) { return this.selectWith(Predicates2.not(predicate), parameter, targetCollection); } public ImmutableBag selectInstancesOf(Class clazz) { return clazz.isInstance(this.value) ? (ImmutableBag) this : Bags.immutable.of(); } public ImmutableBag collect(Function function) { return Bags.immutable.of(function.valueOf(this.value)); } public ImmutableBag collectIf( Predicate predicate, Function function) { return predicate.accept(this.value) ? Bags.immutable.of(function.valueOf(this.value)) : Bags.immutable.of(); } @Override public > R collectIf( Predicate predicate, Function function, R target) { if (predicate.accept(this.value)) { target.add(function.valueOf(this.value)); } return target; } public ImmutableBag flatCollect(Function> function) { return this.flatCollect(function, HashBag.newBag()).toImmutable(); } @Override public > R flatCollect( Function> function, R target) { Iterate.addAllTo(function.valueOf(this.value), target); return target; } @Override public T detect(Predicate predicate) { return predicate.accept(this.value) ? this.value : null; } @Override public T detectIfNone(Predicate predicate, Function0 function) { return predicate.accept(this.value) ? this.value : function.value(); } @Override public int count(Predicate predicate) { return predicate.accept(this.value) ? 1 : 0; } @Override public boolean anySatisfy(Predicate predicate) { return predicate.accept(this.value); } public ImmutableBagMultimap groupBy(Function function) { return this.groupBy(function, HashBagMultimap.newMultimap()).toImmutable(); } @Override public > R groupBy(Function function, R target) { target.putAll(function.valueOf(this.value), this); return target; } public ImmutableBagMultimap groupByEach(Function> function) { return this.groupByEach(function, HashBagMultimap.newMultimap()).toImmutable(); } @Override public > R groupByEach(Function> function, R target) { this.forEach(MultimapEachPutProcedure.on(target, function)); return target; } public ImmutableMap groupByUniqueKey(Function function) { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".groupByUniqueKey() not implemented yet"); } public int sizeDistinct() { return 1; } public int occurrencesOf(Object item) { return Comparators.nullSafeEquals(this.value, item) ? 1 : 0; } public void forEachWithOccurrences(ObjectIntProcedure objectIntProcedure) { objectIntProcedure.value(this.value, 1); } public MutableMap toMapOfItemToCount() { return UnifiedMap.newWithKeysValues(this.value, 1); } public ImmutableBag toImmutable() { return this; } public void forEach(Procedure procedure) { procedure.value(this.value); } @Override public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { objectIntProcedure.value(this.value, 0); } @Override public

void forEachWith(Procedure2 procedure, P parameter) { procedure.value(this.value, parameter); } public ImmutableBag> zip(Iterable that) { Iterator iterator = that.iterator(); if (!iterator.hasNext()) { return Bags.immutable.of(); } return Bags.immutable.of(Tuples.pair(this.value, iterator.next())); } public ImmutableSet> zipWithIndex() { return Sets.immutable.of(Tuples.pair(this.value, 0)); } public Iterator iterator() { return new SingletonIterator(); } private class SingletonIterator implements Iterator { private boolean next = true; public boolean hasNext() { return this.next; } public T next() { if (this.next) { this.next = false; return ImmutableSingletonBag.this.value; } throw new NoSuchElementException("i=" + this.next); } public void remove() { throw new UnsupportedOperationException("Cannot remove from an ImmutableBag"); } } @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof Bag)) { return false; } Bag bag = (Bag) obj; if (this.size() != bag.size()) { return false; } return this.occurrencesOf(this.value) == bag.occurrencesOf(this.value); } @Override public String toString() { return '[' + this.makeString() + ']'; } @Override public int hashCode() { return (this.value == null ? 0 : this.value.hashCode()) ^ 1; } private Object writeReplace() { return new ImmutableBagSerializationProxy(this); } } package-info.java000066400000000000000000000040441234315411400337020ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/bag/immutable/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains implementations of the {@link com.gs.collections.api.bag.ImmutableBag} interface. *

* An {@link com.gs.collections.api.bag.ImmutableBag} is an immutable collection which contains elements that are unordered, and may contain duplicate entries. *

*

* This package contains 4 immutable bag implementations: *

    *
  • * {@link com.gs.collections.impl.bag.immutable.ImmutableArrayBag} - an {@link com.gs.collections.api.bag.ImmutableBag} which uses an array as its underlying data store. *
  • *
  • * {@link com.gs.collections.impl.bag.immutable.ImmutableEmptyBag} - an empty {@link com.gs.collections.api.bag.ImmutableBag}. *
  • *
  • * {@link com.gs.collections.impl.bag.immutable.ImmutableHashBag} - an {@link com.gs.collections.api.bag.ImmutableBag} which uses a hashtable as its underlying data store. *
  • *
  • * {@link com.gs.collections.impl.bag.immutable.ImmutableSingletonBag} - an {@link com.gs.collections.api.bag.ImmutableBag} which contains only one element. *
  • *
*

*

* This package contains one factory implementation: *

    *
  • * {@link com.gs.collections.impl.bag.immutable.ImmutableBagFactoryImpl} - a factory which creates instances of type {@link com.gs.collections.api.bag.ImmutableBag}. *
  • *
*

*/ package com.gs.collections.impl.bag.immutable; gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/bag/immutable/primitive/000077500000000000000000000000001234315411400326005ustar00rootroot00000000000000package-info.java000066400000000000000000000016061234315411400357130ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/bag/immutable/primitive/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains implementations of the immutable primitive bag interfaces. *

* A immutable primitive bag is similar to an {@link com.gs.collections.api.bag.ImmutableBag}, but is memory-optimized for primitives. *

*/ package com.gs.collections.impl.bag.immutable.primitive; gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/bag/mutable/000077500000000000000000000000001234315411400302425ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/bag/mutable/HashBag.java000066400000000000000000001301371234315411400324070ustar00rootroot00000000000000/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.bag.mutable; import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; import java.util.Arrays; import java.util.Collection; import java.util.Comparator; import java.util.Iterator; import java.util.NoSuchElementException; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.bag.Bag; import com.gs.collections.api.bag.ImmutableBag; import com.gs.collections.api.bag.MutableBag; import com.gs.collections.api.bag.ParallelUnsortedBag; import com.gs.collections.api.bag.primitive.MutableBooleanBag; import com.gs.collections.api.bag.primitive.MutableByteBag; import com.gs.collections.api.bag.primitive.MutableCharBag; import com.gs.collections.api.bag.primitive.MutableDoubleBag; import com.gs.collections.api.bag.primitive.MutableFloatBag; import com.gs.collections.api.bag.primitive.MutableIntBag; import com.gs.collections.api.bag.primitive.MutableLongBag; import com.gs.collections.api.bag.primitive.MutableShortBag; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.predicate.primitive.IntPredicate; import com.gs.collections.api.block.predicate.primitive.ObjectIntPredicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.map.MutableMap; import com.gs.collections.api.map.primitive.MutableObjectIntMap; import com.gs.collections.api.multimap.MutableMultimap; import com.gs.collections.api.partition.bag.PartitionMutableBag; import com.gs.collections.api.set.MutableSet; import com.gs.collections.api.tuple.Pair; import com.gs.collections.api.tuple.primitive.ObjectIntPair; import com.gs.collections.impl.Counter; import com.gs.collections.impl.bag.mutable.primitive.BooleanHashBag; import com.gs.collections.impl.bag.mutable.primitive.ByteHashBag; import com.gs.collections.impl.bag.mutable.primitive.CharHashBag; import com.gs.collections.impl.bag.mutable.primitive.DoubleHashBag; import com.gs.collections.impl.bag.mutable.primitive.FloatHashBag; import com.gs.collections.impl.bag.mutable.primitive.IntHashBag; import com.gs.collections.impl.bag.mutable.primitive.LongHashBag; import com.gs.collections.impl.bag.mutable.primitive.ShortHashBag; import com.gs.collections.impl.block.factory.Predicates2; import com.gs.collections.impl.block.factory.primitive.IntToIntFunctions; import com.gs.collections.impl.block.procedure.CollectionAddProcedure; import com.gs.collections.impl.block.procedure.MultimapEachPutProcedure; import com.gs.collections.impl.block.procedure.MultimapPutProcedure; import com.gs.collections.impl.collection.AbstractMutableBag; import com.gs.collections.impl.factory.Bags; import com.gs.collections.impl.lazy.AbstractLazyIterable; import com.gs.collections.impl.lazy.parallel.AbstractBatch; import com.gs.collections.impl.lazy.parallel.bag.AbstractParallelUnsortedBag; import com.gs.collections.impl.lazy.parallel.bag.CollectUnsortedBagBatch; import com.gs.collections.impl.lazy.parallel.bag.RootUnsortedBagBatch; import com.gs.collections.impl.lazy.parallel.bag.SelectUnsortedBagBatch; import com.gs.collections.impl.lazy.parallel.bag.UnsortedBagBatch; import com.gs.collections.impl.list.mutable.FastList; import com.gs.collections.impl.map.mutable.UnifiedMap; import com.gs.collections.impl.map.mutable.primitive.ObjectIntHashMap; import com.gs.collections.impl.multimap.bag.HashBagMultimap; import com.gs.collections.impl.partition.bag.PartitionHashBag; import com.gs.collections.impl.set.mutable.UnifiedSet; import com.gs.collections.impl.utility.ArrayIterate; import com.gs.collections.impl.utility.Iterate; /** * A HashBag is a MutableBag which uses a Map as its underlying data store. Each key in the Map represents some item, * and the value in the map represents the current number of occurrences of that item. * * @since 1.0 */ public class HashBag extends AbstractMutableBag implements Externalizable, MutableBag { private static final long serialVersionUID = 1L; private MutableObjectIntMap items; private int size; public HashBag() { this.items = ObjectIntHashMap.newMap(); } public HashBag(int size) { this.items = new ObjectIntHashMap(size); } private HashBag(MutableObjectIntMap map) { this.items = map; this.size = (int) map.sum(); } public static HashBag newBag() { return new HashBag(); } public static HashBag newBag(int size) { return new HashBag(size); } public static HashBag newBag(Bag source) { final HashBag result = HashBag.newBag(); source.forEachWithOccurrences(new ObjectIntProcedure() { public void value(E each, int occurrences) { result.addOccurrences(each, occurrences); } }); return result; } public static HashBag newBag(Iterable source) { return HashBag.newBagWith((E[]) Iterate.toArray(source)); } public static HashBag newBagWith(E... elements) { HashBag result = HashBag.newBag(); ArrayIterate.addAllTo(elements, result); return result; } public void addOccurrences(T item, int occurrences) { if (occurrences < 0) { throw new IllegalArgumentException("Cannot add a negative number of occurrences"); } if (occurrences > 0) { this.items.updateValue(item, 0, IntToIntFunctions.add(occurrences)); this.size += occurrences; } } @Override public boolean equals(Object other) { if (this == other) { return true; } if (!(other instanceof Bag)) { return false; } final Bag bag = (Bag) other; if (this.sizeDistinct() != bag.sizeDistinct()) { return false; } return this.items.keyValuesView().allSatisfy(new Predicate>() { public boolean accept(ObjectIntPair each) { return bag.occurrencesOf(each.getOne()) == each.getTwo(); } }); } public int sizeDistinct() { return this.items.size(); } @Override public int hashCode() { final Counter counter = new Counter(); this.items.forEachKeyValue(new ObjectIntProcedure() { public void value(T item, int count) { counter.add((item == null ? 0 : item.hashCode()) ^ count); } }); return counter.getCount(); } public int occurrencesOf(Object item) { return this.items.get(item); } public void forEachWithOccurrences(final ObjectIntProcedure objectIntProcedure) { this.items.forEachKeyValue(new ObjectIntProcedure() { public void value(T item, int count) { objectIntProcedure.value(item, count); } }); } public MutableBag selectByOccurrences(final IntPredicate predicate) { MutableObjectIntMap map = this.items.select(new ObjectIntPredicate() { public boolean accept(T each, int occurrences) { return predicate.accept(occurrences); } }); return new HashBag(map); } public MutableMap toMapOfItemToCount() { final MutableMap map = UnifiedMap.newMap(this.items.size()); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T item, int count) { map.put(item, count); } }); return map; } public String toStringOfItemToCount() { return this.items.toString(); } @Override public boolean remove(Object item) { int newValue = this.items.updateValue((T) item, 0, IntToIntFunctions.decrement()); if (newValue <= 0) { this.items.removeKey((T) item); if (newValue == -1) { return false; } } this.size--; return true; } @Override public boolean removeAll(Collection collection) { return this.removeAllIterable(collection); } @Override public boolean retainAll(Collection collection) { return this.retainAllIterable(collection); } public void clear() { this.items.clear(); this.size = 0; } @Override public boolean isEmpty() { return this.items.isEmpty(); } public void writeExternal(ObjectOutput out) throws IOException { ((ObjectIntHashMap) this.items).writeExternal(out); } public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { this.items = new ObjectIntHashMap(); ((ObjectIntHashMap) this.items).readExternal(in); this.size = (int) this.items.sum(); } public void forEach(final Procedure procedure) { this.items.forEachKeyValue(new ObjectIntProcedure() { public void value(T key, int count) { for (int i = 0; i < count; i++) { procedure.value(key); } } }); } @Override public void forEachWithIndex(final ObjectIntProcedure objectIntProcedure) { final Counter index = new Counter(); this.items.forEachKeyValue(new ObjectIntProcedure() { public void value(T key, int count) { for (int i = 0; i < count; i++) { objectIntProcedure.value(key, index.getCount()); index.increment(); } } }); } @Override public

void forEachWith(final Procedure2 procedure, final P parameter) { this.items.forEachKeyValue(new ObjectIntProcedure() { public void value(T key, int count) { for (int i = 0; i < count; i++) { procedure.value(key, parameter); } } }); } public Iterator iterator() { return new InternalIterator(); } public boolean removeOccurrences(Object item, int occurrences) { if (occurrences < 0) { throw new IllegalArgumentException("Cannot remove a negative number of occurrences"); } if (occurrences == 0) { return false; } int newValue = this.items.updateValue((T) item, 0, IntToIntFunctions.subtract(occurrences)); if (newValue <= 0) { this.size -= occurrences + newValue; this.items.remove((T) item); return newValue + occurrences != 0; } this.size -= occurrences; return true; } public boolean setOccurrences(T item, int occurrences) { if (occurrences < 0) { throw new IllegalArgumentException("Cannot set a negative number of occurrences"); } int originalOccurrences = this.items.get(item); if (originalOccurrences == occurrences) { return false; } if (occurrences == 0) { this.items.remove(item); } else { this.items.put(item, occurrences); } this.size -= originalOccurrences - occurrences; return true; } public HashBag without(T element) { this.remove(element); return this; } public MutableBag newEmpty() { return HashBag.newBag(); } public MutableBag collectWith( final Function2 function, final P parameter) { final HashBag result = HashBag.newBag(this.items.size()); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { result.addOccurrences(function.value(each, parameter), occurrences); } }); return result; } public HashBag with(T element) { this.add(element); return this; } public SynchronizedBag asSynchronized() { return new SynchronizedBag(this); } public HashBag withAll(Iterable iterable) { this.addAllIterable(iterable); return this; } public HashBag withoutAll(Iterable iterable) { this.removeAllIterable(iterable); return this; } public

MutableBag selectWith(final Predicate2 predicate, final P parameter) { final MutableBag result = HashBag.newBag(); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { if (predicate.accept(each, parameter)) { result.addOccurrences(each, occurrences); } } }); return result; } public

MutableBag rejectWith(final Predicate2 predicate, final P parameter) { final MutableBag result = HashBag.newBag(); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int index) { if (!predicate.accept(each, parameter)) { result.addOccurrences(each, index); } } }); return result; } @Override public void removeIf(Predicate predicate) { for (Iterator iterator = this.items.keySet().iterator(); iterator.hasNext(); ) { T key = iterator.next(); if (predicate.accept(key)) { this.size -= this.items.get(key); iterator.remove(); } } } @Override public

void removeIfWith(Predicate2 predicate, P parameter) { for (Iterator iterator = this.items.keySet().iterator(); iterator.hasNext(); ) { T key = iterator.next(); if (predicate.accept(key, parameter)) { this.size -= this.items.get(key); iterator.remove(); } } } @Override public

T detectWith(final Predicate2 predicate, final P parameter) { return this.items.keysView().detect(new Predicate() { public boolean accept(T each) { return predicate.accept(each, parameter); } }); } @Override public

T detectWithIfNone( final Predicate2 predicate, final P parameter, Function0 function) { return this.items.keysView().detectIfNone(new Predicate() { public boolean accept(T each) { return predicate.accept(each, parameter); } }, function); } @Override public

int countWith(final Predicate2 predicate, final P parameter) { final Counter result = new Counter(); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { if (predicate.accept(each, parameter)) { result.add(occurrences); } } }); return result.getCount(); } @Override public

boolean anySatisfyWith(final Predicate2 predicate, final P parameter) { return this.items.keysView().anySatisfy(new Predicate() { public boolean accept(T each) { return predicate.accept(each, parameter); } }); } @Override public

boolean allSatisfyWith(final Predicate2 predicate, final P parameter) { return this.items.keysView().allSatisfy(new Predicate() { public boolean accept(T each) { return predicate.accept(each, parameter); } }); } @Override public

boolean noneSatisfyWith(final Predicate2 predicate, final P parameter) { return this.items.keysView().noneSatisfy(new Predicate() { public boolean accept(T each) { return predicate.accept(each, parameter); } }); } public UnmodifiableBag asUnmodifiable() { return UnmodifiableBag.of(this); } public ImmutableBag toImmutable() { return Bags.immutable.withAll(this); } @Override public boolean removeAllIterable(Iterable iterable) { int oldSize = this.size; for (Object each : iterable) { int removed = this.items.removeKeyIfAbsent((T) each, 0); this.size -= removed; } return this.size != oldSize; } @Override public boolean retainAllIterable(Iterable iterable) { int oldSize = this.size; this.removeIfWith(Predicates2.notIn(), UnifiedSet.newSet(iterable)); return this.size != oldSize; } public int size() { return this.size; } @Override public boolean contains(Object o) { return this.items.containsKey(o); } public MutableBag select(final Predicate predicate) { final MutableBag result = HashBag.newBag(); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { if (predicate.accept(each)) { result.addOccurrences(each, occurrences); } } }); return result; } public PartitionMutableBag partition(final Predicate predicate) { final PartitionMutableBag result = new PartitionHashBag(); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int index) { MutableBag bucket = predicate.accept(each) ? result.getSelected() : result.getRejected(); bucket.addOccurrences(each, index); } }); return result; } public

PartitionMutableBag partitionWith(final Predicate2 predicate, final P parameter) { final PartitionMutableBag result = new PartitionHashBag(); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int index) { MutableBag bucket = predicate.accept(each, parameter) ? result.getSelected() : result.getRejected(); bucket.addOccurrences(each, index); } }); return result; } public MutableBag selectInstancesOf(final Class clazz) { final MutableBag result = HashBag.newBag(); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { if (clazz.isInstance(each)) { result.addOccurrences((S) each, occurrences); } } }); return result; } public MutableBooleanBag collectBoolean(BooleanFunction booleanFunction) { return this.collectBoolean(booleanFunction, new BooleanHashBag()); } public MutableByteBag collectByte(ByteFunction byteFunction) { return this.collectByte(byteFunction, new ByteHashBag()); } public MutableCharBag collectChar(CharFunction charFunction) { return this.collectChar(charFunction, new CharHashBag()); } public MutableDoubleBag collectDouble(DoubleFunction doubleFunction) { return this.collectDouble(doubleFunction, new DoubleHashBag()); } public T getFirst() { return this.items.keysView().getFirst(); } public HashBagMultimap groupBy(Function function) { return this.groupBy(function, HashBagMultimap.newMultimap()); } public MutableMap groupByUniqueKey(Function function) { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".groupByUniqueKey() not implemented yet"); } public MutableSet> zipWithIndex() { return this.zipWithIndex(UnifiedSet.>newSet()); } public T getLast() { return this.items.keysView().getLast(); } @Override public > R select(final Predicate predicate, final R target) { this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { if (predicate.accept(each)) { for (int i = 0; i < occurrences; i++) { target.add(each); } } } }); return target; } @Override public > R selectWith( final Predicate2 predicate, final P parameter, final R target) { this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { if (predicate.accept(each, parameter)) { for (int i = 0; i < occurrences; i++) { target.add(each); } } } }); return target; } @Override public > R reject(final Predicate predicate, final R target) { this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { if (!predicate.accept(each)) { for (int i = 0; i < occurrences; i++) { target.add(each); } } } }); return target; } public MutableBag reject(final Predicate predicate) { final MutableBag result = HashBag.newBag(); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int index) { if (!predicate.accept(each)) { result.addOccurrences(each, index); } } }); return result; } @Override public > R rejectWith( final Predicate2 predicate, final P parameter, final R target) { this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { if (!predicate.accept(each, parameter)) { for (int i = 0; i < occurrences; i++) { target.add(each); } } } }); return target; } public MutableBag collect(final Function function) { final HashBag result = HashBag.newBag(this.items.size()); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { result.addOccurrences(function.valueOf(each), occurrences); } }); return result; } public MutableFloatBag collectFloat(FloatFunction floatFunction) { return this.collectFloat(floatFunction, new FloatHashBag()); } public MutableIntBag collectInt(IntFunction intFunction) { return this.collectInt(intFunction, new IntHashBag()); } public MutableLongBag collectLong(LongFunction longFunction) { return this.collectLong(longFunction, new LongHashBag()); } public MutableShortBag collectShort(ShortFunction shortFunction) { return this.collectShort(shortFunction, new ShortHashBag()); } public MutableBag collectIf( final Predicate predicate, final Function function) { final MutableBag result = HashBag.newBag(); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { if (predicate.accept(each)) { result.addOccurrences(function.valueOf(each), occurrences); } } }); return result; } public MutableBag flatCollect(final Function> function) { final MutableBag result = HashBag.newBag(); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, final int occurrences) { Iterable values = function.valueOf(each); Iterate.forEach(values, new Procedure() { public void value(V each) { result.addOccurrences(each, occurrences); } }); } }); return result; } @Override public > R collect(final Function function, final R target) { this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { V value = function.valueOf(each); for (int i = 0; i < occurrences; i++) { target.add(value); } } }); return target; } public HashBagMultimap groupByEach(Function> function) { return this.groupByEach(function, HashBagMultimap.newMultimap()); } public MutableBag> zip(Iterable that) { return this.zip(that, HashBag.>newBag()); } @Override public > R collectIf( final Predicate predicate, final Function function, final R target) { this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { if (predicate.accept(each)) { V value = function.valueOf(each); for (int i = 0; i < occurrences; i++) { target.add(value); } } } }); return target; } @Override public > R flatCollect(final Function> function, final R target) { this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, final int occurrences) { Iterable values = function.valueOf(each); Iterate.forEach(values, new Procedure() { public void value(V each) { for (int i = 0; i < occurrences; i++) { target.add(each); } } }); } }); return target; } @Override public T detect(Predicate predicate) { return this.items.keysView().detect(predicate); } @Override public T detectIfNone(Predicate predicate, Function0 function) { return this.items.keysView().detectIfNone(predicate, function); } @Override public int count(final Predicate predicate) { final Counter result = new Counter(); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { if (predicate.accept(each)) { result.add(occurrences); } } }); return result.getCount(); } @Override public boolean anySatisfy(Predicate predicate) { return this.items.keysView().anySatisfy(predicate); } @Override public boolean allSatisfy(Predicate predicate) { return this.items.keysView().allSatisfy(predicate); } @Override public boolean noneSatisfy(Predicate predicate) { return this.items.keysView().noneSatisfy(predicate); } @Override public MutableList toList() { return FastList.newList(this); } @Override public MutableSet toSet() { MutableSet result = UnifiedSet.newSet(this.sizeDistinct()); this.items.forEachKey(CollectionAddProcedure.on(result)); return result; } @Override public MutableBag toBag() { return HashBag.newBag(this); } @Override public T min(Comparator comparator) { return this.items.keysView().min(comparator); } @Override public T max(Comparator comparator) { return this.items.keysView().max(comparator); } @Override public T min() { return this.items.keysView().min(); } @Override public T max() { return this.items.keysView().max(); } @Override public > T minBy(Function function) { return this.items.keysView().minBy(function); } @Override public > T maxBy(Function function) { return this.items.keysView().maxBy(function); } @Override public long sumOfInt(final IntFunction function) { final long[] sum = {0L}; this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { int intValue = function.intValueOf(each); sum[0] += (long) intValue * (long) occurrences; } }); return sum[0]; } @Override public double sumOfFloat(final FloatFunction function) { final double[] sum = {0.0}; this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { float floatValue = function.floatValueOf(each); sum[0] += floatValue * (double) occurrences; } }); return sum[0]; } @Override public long sumOfLong(final LongFunction function) { final long[] sum = {0L}; this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { long longValue = function.longValueOf(each); sum[0] += longValue * (long) occurrences; } }); return sum[0]; } @Override public double sumOfDouble(final DoubleFunction function) { final double[] sum = {0.0}; this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { double doubleValue = function.doubleValueOf(each); sum[0] += doubleValue * (double) occurrences; } }); return sum[0]; } @Override public > R groupBy( Function function, R target) { this.forEach(MultimapPutProcedure.on(target, function)); return target; } @Override public > R groupByEach( Function> function, R target) { this.forEach(MultimapEachPutProcedure.on(target, function)); return target; } public HashBag with(T... elements) { this.addAll(Arrays.asList(elements)); return this; } public HashBag with(T element1, T element2) { this.add(element1); this.add(element2); return this; } @Override public boolean add(T item) { this.items.updateValue(item, 0, IntToIntFunctions.increment()); this.size++; return true; } public HashBag with(T element1, T element2, T element3) { this.add(element1); this.add(element2); this.add(element3); return this; } private class InternalIterator implements Iterator { private int position; private boolean isCurrentKeySet; private int currentKeyPosition; private int currentKeyOccurrences; private Iterator> keyValueIterator = HashBag.this.items.keyValuesView().iterator(); private ObjectIntPair currentKeyValue; public boolean hasNext() { return this.position != HashBag.this.size; } public T next() { if (!this.hasNext()) { throw new NoSuchElementException(); } this.isCurrentKeySet = true; if (this.currentKeyPosition < this.currentKeyOccurrences) { this.currentKeyPosition++; this.position++; return this.currentKeyValue.getOne(); } this.currentKeyValue = this.keyValueIterator.next(); this.currentKeyPosition = 1; this.currentKeyOccurrences = this.currentKeyValue.getTwo(); this.position++; return this.currentKeyValue.getOne(); } public void remove() { if (!this.isCurrentKeySet) { throw new IllegalStateException(); } this.isCurrentKeySet = false; this.position--; HashBag.this.remove(this.currentKeyValue.getOne()); this.keyValueIterator = HashBag.this.items.keyValuesView().iterator(); this.currentKeyOccurrences--; this.currentKeyPosition--; } } @Beta public ParallelUnsortedBag asParallel(ExecutorService executorService, int batchSize) { if (executorService == null) { throw new NullPointerException(); } if (batchSize < 1) { throw new IllegalArgumentException(); } return new HashBagParallelIterable(executorService, batchSize); } private final class HashUnsortedBagBatch extends AbstractBatch implements UnsortedBagBatch { private final int chunkStartIndex; private final int chunkEndIndex; private HashUnsortedBagBatch(int chunkStartIndex, int chunkEndIndex) { this.chunkStartIndex = chunkStartIndex; this.chunkEndIndex = chunkEndIndex; } public void forEach(Procedure procedure) { throw new UnsupportedOperationException("not implemented yet"); /* for (int i = this.chunkStartIndex; i < this.chunkEndIndex; i++) { if (ObjectIntHashMap.isNonSentinel(HashBag.this.items.keys[i])) { T each = HashBag.this.items.toNonSentinel(HashBag.this.items.keys[i]); int occurrences = HashBag.this.items.values[i]; for (int j = 0; j < occurrences; j++) { procedure.value(each); } } } */ } public void forEachWithOccurrences(ObjectIntProcedure procedure) { throw new UnsupportedOperationException("not implemented yet"); /* for (int i = this.chunkStartIndex; i < this.chunkEndIndex; i++) { if (ObjectIntHashMap.isNonSentinel(HashBag.this.items.keys[i])) { T each = HashBag.this.items.toNonSentinel(HashBag.this.items.keys[i]); int occurrences = HashBag.this.items.values[i]; procedure.value(each, occurrences); } } */ } public boolean anySatisfy(Predicate predicate) { throw new UnsupportedOperationException("not implemented yet"); } public boolean allSatisfy(Predicate predicate) { throw new UnsupportedOperationException("not implemented yet"); } public T detect(Predicate predicate) { throw new UnsupportedOperationException("not implemented yet"); } public UnsortedBagBatch select(Predicate predicate) { return new SelectUnsortedBagBatch(this, predicate); } public UnsortedBagBatch collect(Function function) { return new CollectUnsortedBagBatch(this, function); } } private final class HashBagParallelIterable extends AbstractParallelUnsortedBag> { private final ExecutorService executorService; private final int batchSize; private HashBagParallelIterable(ExecutorService executorService, int batchSize) { this.executorService = executorService; this.batchSize = batchSize; } @Override public ExecutorService getExecutorService() { return this.executorService; } @Override public LazyIterable> split() { return new HashBagParallelBatchLazyIterable(); } public void forEach(Procedure procedure) { forEach(this, procedure); } public boolean anySatisfy(Predicate predicate) { return anySatisfy(this, predicate); } public boolean allSatisfy(Predicate predicate) { return allSatisfy(this, predicate); } public void forEachWithOccurrences(final ObjectIntProcedure procedure) { LazyIterable> chunks = this.split(); LazyIterable> callables = chunks.collect(new Function, Callable>() { public Callable valueOf(final UnsortedBagBatch chunk) { return new Callable() { public Void call() { chunk.forEachWithOccurrences(procedure); return null; } }; } }); try { this.executorService.invokeAll(callables.toList(), Integer.MAX_VALUE, TimeUnit.DAYS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } } public T detect(Predicate predicate) { return detect(this, predicate); } private class HashBagParallelBatchIterator implements Iterator> { protected int chunkIndex; public boolean hasNext() { return this.chunkIndex * HashBagParallelIterable.this.batchSize < HashBag.this.items.size(); } public RootUnsortedBagBatch next() { throw new UnsupportedOperationException("not implemented yet"); /* int chunkStartIndex = this.chunkIndex * HashBagParallelIterable.this.batchSize; int chunkEndIndex = (this.chunkIndex + 1) * HashBagParallelIterable.this.batchSize; int truncatedChunkEndIndex = Math.min(chunkEndIndex, HashBag.this.items.keys.length); this.chunkIndex++; return new HashBagBatch(chunkStartIndex, truncatedChunkEndIndex); */ } public void remove() { throw new UnsupportedOperationException("cannot remove from a ParallelIterable"); } } private class HashBagParallelBatchLazyIterable extends AbstractLazyIterable> { public void forEach(Procedure> procedure) { for (RootUnsortedBagBatch chunk : this) { procedure.value(chunk); } } public

void forEachWith(Procedure2, ? super P> procedure, P parameter) { for (RootUnsortedBagBatch chunk : this) { procedure.value(chunk, parameter); } } public void forEachWithIndex(ObjectIntProcedure> objectIntProcedure) { throw new UnsupportedOperationException("not implemented yet"); } public Iterator> iterator() { return new HashBagParallelBatchIterator(); } } } } MultiReaderHashBag.java000066400000000000000000000706671234315411400345010ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/bag/mutable/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.bag.mutable; import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; import java.util.Iterator; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.RichIterable; import com.gs.collections.api.bag.ImmutableBag; import com.gs.collections.api.bag.MutableBag; import com.gs.collections.api.bag.primitive.MutableBooleanBag; import com.gs.collections.api.bag.primitive.MutableByteBag; import com.gs.collections.api.bag.primitive.MutableCharBag; import com.gs.collections.api.bag.primitive.MutableDoubleBag; import com.gs.collections.api.bag.primitive.MutableFloatBag; import com.gs.collections.api.bag.primitive.MutableIntBag; import com.gs.collections.api.bag.primitive.MutableLongBag; import com.gs.collections.api.bag.primitive.MutableShortBag; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.predicate.primitive.IntPredicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.collection.primitive.MutableBooleanCollection; import com.gs.collections.api.collection.primitive.MutableByteCollection; import com.gs.collections.api.collection.primitive.MutableCharCollection; import com.gs.collections.api.collection.primitive.MutableDoubleCollection; import com.gs.collections.api.collection.primitive.MutableFloatCollection; import com.gs.collections.api.collection.primitive.MutableIntCollection; import com.gs.collections.api.collection.primitive.MutableLongCollection; import com.gs.collections.api.collection.primitive.MutableShortCollection; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.map.MapIterable; import com.gs.collections.api.map.MutableMap; import com.gs.collections.api.multimap.bag.MutableBagMultimap; import com.gs.collections.api.partition.bag.PartitionMutableBag; import com.gs.collections.api.set.MutableSet; import com.gs.collections.api.tuple.Pair; import com.gs.collections.impl.collection.mutable.AbstractMultiReaderMutableCollection; import com.gs.collections.impl.factory.Bags; import com.gs.collections.impl.factory.Iterables; import com.gs.collections.impl.utility.LazyIterate; /** * MultiReaderHashBag provides a thread-safe wrapper around a HashBag, using a ReentrantReadWriteLock. In order to * provide true thread-safety, MultiReaderHashBag does not implement iterator() as this method requires an external lock * to be taken to provide thread-safe iteration. All of these methods are available however, if you use the * withReadLockAndDelegate() or withWriteLockAndDelegate() methods. Both of these methods take a parameter of type * Procedure, and a wrapped version of the underlying HashBag is returned. This wrapper guarantees that * no external pointer can ever reference the underlying HashBag outside of a locked procedure. In the case of the * read lock method, an Unmodifiable version of the collection is offered, which will throw UnsupportedOperationExceptions * on any write methods like add or remove. */ public final class MultiReaderHashBag extends AbstractMultiReaderMutableCollection implements Externalizable, MutableBag { private static final long serialVersionUID = 1L; private transient ReadWriteLock lock; private MutableBag delegate; @SuppressWarnings("UnusedDeclaration") public MultiReaderHashBag() { // For Externalizable use only } private MultiReaderHashBag(MutableBag newDelegate) { this(newDelegate, new ReentrantReadWriteLock()); } private MultiReaderHashBag(MutableBag newDelegate, ReadWriteLock newLock) { this.lock = newLock; this.delegate = newDelegate; } public static MultiReaderHashBag newBag() { return new MultiReaderHashBag(HashBag.newBag()); } public static MultiReaderHashBag newBag(int capacity) { return new MultiReaderHashBag(HashBag.newBag(capacity)); } public static MultiReaderHashBag newBag(Iterable iterable) { return new MultiReaderHashBag(HashBag.newBag(iterable)); } public static MultiReaderHashBag newBagWith(T... elements) { return new MultiReaderHashBag(HashBag.newBagWith(elements)); } @Override protected MutableBag getDelegate() { return this.delegate; } @Override protected ReadWriteLock getLock() { return this.lock; } UntouchableMutableBag asReadUntouchable() { return new UntouchableMutableBag(this.delegate.asUnmodifiable()); } UntouchableMutableBag asWriteUntouchable() { return new UntouchableMutableBag(this.delegate); } public void withReadLockAndDelegate(Procedure> procedure) { this.acquireReadLock(); try { UntouchableMutableBag bag = this.asReadUntouchable(); procedure.value(bag); bag.becomeUseless(); } finally { this.unlockReadLock(); } } public void withWriteLockAndDelegate(Procedure> procedure) { this.acquireWriteLock(); try { UntouchableMutableBag bag = this.asWriteUntouchable(); procedure.value(bag); bag.becomeUseless(); } finally { this.unlockWriteLock(); } } public MutableBag asSynchronized() { this.acquireReadLock(); try { return SynchronizedBag.of(this); } finally { this.unlockReadLock(); } } public MutableBag asUnmodifiable() { this.acquireReadLock(); try { return UnmodifiableBag.of(this); } finally { this.unlockReadLock(); } } public ImmutableBag toImmutable() { this.acquireReadLock(); try { return Bags.immutable.ofAll(this.delegate); } finally { this.unlockReadLock(); } } public void addOccurrences(T item, int occurrences) { this.acquireWriteLock(); try { this.delegate.addOccurrences(item, occurrences); } finally { this.unlockWriteLock(); } } public boolean removeOccurrences(Object item, int occurrences) { this.acquireWriteLock(); try { return this.delegate.removeOccurrences(item, occurrences); } finally { this.unlockWriteLock(); } } public boolean setOccurrences(T item, int occurrences) { this.acquireWriteLock(); try { return this.delegate.setOccurrences(item, occurrences); } finally { this.unlockWriteLock(); } } public int occurrencesOf(Object item) { this.acquireReadLock(); try { return this.delegate.occurrencesOf(item); } finally { this.unlockReadLock(); } } public int sizeDistinct() { this.acquireReadLock(); try { return this.delegate.sizeDistinct(); } finally { this.unlockReadLock(); } } public MutableBag collect(Function function) { this.acquireReadLock(); try { return this.delegate.collect(function); } finally { this.unlockReadLock(); } } public MutableBooleanBag collectBoolean(BooleanFunction booleanFunction) { this.acquireReadLock(); try { return this.delegate.collectBoolean(booleanFunction); } finally { this.unlockReadLock(); } } public MutableByteBag collectByte(ByteFunction byteFunction) { this.acquireReadLock(); try { return this.delegate.collectByte(byteFunction); } finally { this.unlockReadLock(); } } public MutableCharBag collectChar(CharFunction charFunction) { this.acquireReadLock(); try { return this.delegate.collectChar(charFunction); } finally { this.unlockReadLock(); } } public MutableDoubleBag collectDouble(DoubleFunction doubleFunction) { this.acquireReadLock(); try { return this.delegate.collectDouble(doubleFunction); } finally { this.unlockReadLock(); } } public MutableFloatBag collectFloat(FloatFunction floatFunction) { this.acquireReadLock(); try { return this.delegate.collectFloat(floatFunction); } finally { this.unlockReadLock(); } } public MutableIntBag collectInt(IntFunction intFunction) { this.acquireReadLock(); try { return this.delegate.collectInt(intFunction); } finally { this.unlockReadLock(); } } public MutableLongBag collectLong(LongFunction longFunction) { this.acquireReadLock(); try { return this.delegate.collectLong(longFunction); } finally { this.unlockReadLock(); } } public MutableShortBag collectShort(ShortFunction shortFunction) { this.acquireReadLock(); try { return this.delegate.collectShort(shortFunction); } finally { this.unlockReadLock(); } } public MutableBag flatCollect( Function> function) { this.acquireReadLock(); try { return this.delegate.flatCollect(function); } finally { this.unlockReadLock(); } } public MutableBag collectIf( Predicate predicate, Function function) { this.acquireReadLock(); try { return this.delegate.collectIf(predicate, function); } finally { this.unlockReadLock(); } } public MutableBag collectWith( Function2 function, P parameter) { this.acquireReadLock(); try { return this.delegate.collectWith(function, parameter); } finally { this.unlockReadLock(); } } public MutableBag newEmpty() { return MultiReaderHashBag.newBag(); } public MutableBag reject(Predicate predicate) { this.acquireReadLock(); try { return this.delegate.reject(predicate); } finally { this.unlockReadLock(); } } public

MutableBag rejectWith( Predicate2 predicate, P parameter) { this.acquireReadLock(); try { return this.delegate.rejectWith(predicate, parameter); } finally { this.unlockReadLock(); } } public MutableBag select(Predicate predicate) { this.acquireReadLock(); try { return this.delegate.select(predicate); } finally { this.unlockReadLock(); } } public

MutableBag selectWith( Predicate2 predicate, P parameter) { this.acquireReadLock(); try { return this.delegate.selectWith(predicate, parameter); } finally { this.unlockReadLock(); } } public MutableBag selectByOccurrences(IntPredicate predicate) { this.acquireReadLock(); try { return this.delegate.selectByOccurrences(predicate); } finally { this.unlockReadLock(); } } public MutableBag selectInstancesOf(Class clazz) { this.acquireReadLock(); try { return this.delegate.selectInstancesOf(clazz); } finally { this.unlockReadLock(); } } public PartitionMutableBag partition(Predicate predicate) { this.acquireReadLock(); try { return this.delegate.partition(predicate); } finally { this.unlockReadLock(); } } public

PartitionMutableBag partitionWith(Predicate2 predicate, P parameter) { this.acquireReadLock(); try { return this.delegate.partitionWith(predicate, parameter); } finally { this.unlockReadLock(); } } public MutableBag with(T element) { this.add(element); return this; } public MutableBag without(T element) { this.remove(element); return this; } public MutableBag withAll(Iterable elements) { this.addAllIterable(elements); return this; } public MutableBag withoutAll(Iterable elements) { this.removeAllIterable(elements); return this; } public MapIterable toMapOfItemToCount() { this.acquireReadLock(); try { return this.delegate.toMapOfItemToCount(); } finally { this.unlockReadLock(); } } public String toStringOfItemToCount() { this.acquireReadLock(); try { return this.delegate.toStringOfItemToCount(); } finally { this.unlockReadLock(); } } public MutableBagMultimap groupBy(Function function) { this.acquireReadLock(); try { return this.delegate.groupBy(function); } finally { this.unlockReadLock(); } } public MutableBagMultimap groupByEach(Function> function) { this.acquireReadLock(); try { return this.delegate.groupByEach(function); } finally { this.unlockReadLock(); } } public MutableMap groupByUniqueKey(Function function) { this.acquireReadLock(); try { return this.delegate.groupByUniqueKey(function); } finally { this.unlockReadLock(); } } public MutableBag> zip(Iterable that) { this.acquireReadLock(); try { return this.delegate.zip(that); } finally { this.unlockReadLock(); } } public MutableSet> zipWithIndex() { this.acquireReadLock(); try { return this.delegate.zipWithIndex(); } finally { this.unlockReadLock(); } } public RichIterable> chunk(int size) { this.acquireReadLock(); try { return this.delegate.chunk(size); } finally { this.unlockReadLock(); } } public void forEachWithOccurrences(ObjectIntProcedure procedure) { this.acquireReadLock(); try { this.delegate.forEachWithOccurrences(procedure); } finally { this.unlockReadLock(); } } @Override public boolean equals(Object o) { this.acquireReadLock(); try { return this.delegate.equals(o); } finally { this.unlockReadLock(); } } @Override public int hashCode() { this.acquireReadLock(); try { return this.delegate.hashCode(); } finally { this.unlockReadLock(); } } public void writeExternal(ObjectOutput out) throws IOException { out.writeObject(this.delegate); } public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { this.delegate = (MutableBag) in.readObject(); this.lock = new ReentrantReadWriteLock(); } //Exposed for testing static final class UntouchableMutableBag extends UntouchableMutableCollection implements MutableBag { private final MutableList> requestedIterators = Iterables.mList(); private UntouchableMutableBag(MutableBag newDelegate) { this.delegate = newDelegate; } public void becomeUseless() { this.delegate = null; this.requestedIterators.forEach(new Procedure>() { public void value(UntouchableIterator each) { each.becomeUseless(); } }); } public MutableBag with(T element) { this.add(element); return this; } public MutableBag without(T element) { this.remove(element); return this; } public MutableBag withAll(Iterable elements) { this.addAllIterable(elements); return this; } public MutableBag withoutAll(Iterable elements) { this.removeAllIterable(elements); return this; } public MutableBag asSynchronized() { throw new UnsupportedOperationException("cannot wrap an UntouchableMutableBag"); } public MutableBag asUnmodifiable() { throw new UnsupportedOperationException("cannot wrap an UntouchableMutableBag"); } public ImmutableBag toImmutable() { return Bags.immutable.ofAll(this.getDelegate()); } public LazyIterable asLazy() { return LazyIterate.adapt(this); } public Iterator iterator() { UntouchableIterator iterator = new UntouchableIterator(this.delegate.iterator()); this.requestedIterators.add(iterator); return iterator; } public void addOccurrences(T item, int occurrences) { this.getDelegate().addOccurrences(item, occurrences); } public boolean removeOccurrences(Object item, int occurrences) { return this.getDelegate().removeOccurrences(item, occurrences); } public boolean setOccurrences(T item, int occurrences) { return this.getDelegate().setOccurrences(item, occurrences); } public int occurrencesOf(Object item) { return this.getDelegate().occurrencesOf(item); } public int sizeDistinct() { return this.getDelegate().sizeDistinct(); } public MutableBag collect(Function function) { return this.getDelegate().collect(function); } public MutableBooleanBag collectBoolean(BooleanFunction booleanFunction) { return this.getDelegate().collectBoolean(booleanFunction); } public R collectBoolean(BooleanFunction booleanFunction, R target) { return this.getDelegate().collectBoolean(booleanFunction, target); } public MutableByteBag collectByte(ByteFunction byteFunction) { return this.getDelegate().collectByte(byteFunction); } public R collectByte(ByteFunction byteFunction, R target) { return this.getDelegate().collectByte(byteFunction, target); } public MutableCharBag collectChar(CharFunction charFunction) { return this.getDelegate().collectChar(charFunction); } public R collectChar(CharFunction charFunction, R target) { return this.getDelegate().collectChar(charFunction, target); } public MutableDoubleBag collectDouble(DoubleFunction doubleFunction) { return this.getDelegate().collectDouble(doubleFunction); } public R collectDouble(DoubleFunction doubleFunction, R target) { return this.getDelegate().collectDouble(doubleFunction, target); } public MutableFloatBag collectFloat(FloatFunction floatFunction) { return this.getDelegate().collectFloat(floatFunction); } public R collectFloat(FloatFunction floatFunction, R target) { return this.getDelegate().collectFloat(floatFunction, target); } public MutableIntBag collectInt(IntFunction intFunction) { return this.getDelegate().collectInt(intFunction); } public R collectInt(IntFunction intFunction, R target) { return this.getDelegate().collectInt(intFunction, target); } public MutableLongBag collectLong(LongFunction longFunction) { return this.getDelegate().collectLong(longFunction); } public R collectLong(LongFunction longFunction, R target) { return this.getDelegate().collectLong(longFunction, target); } public MutableShortBag collectShort(ShortFunction shortFunction) { return this.getDelegate().collectShort(shortFunction); } public R collectShort(ShortFunction shortFunction, R target) { return this.getDelegate().collectShort(shortFunction, target); } public MutableBag flatCollect(Function> function) { return this.getDelegate().flatCollect(function); } public MutableBag collectIf( Predicate predicate, Function function) { return this.getDelegate().collectIf(predicate, function); } public MutableBag collectWith( Function2 function, P parameter) { return this.getDelegate().collectWith(function, parameter); } public MutableBagMultimap groupBy(Function function) { return this.getDelegate().groupBy(function); } public MutableBagMultimap groupByEach(Function> function) { return this.getDelegate().groupByEach(function); } public MutableMap groupByUniqueKey(Function function) { return this.getDelegate().groupByUniqueKey(function); } public MutableBag newEmpty() { return this.getDelegate().newEmpty(); } public MutableBag reject(Predicate predicate) { return this.getDelegate().reject(predicate); } public

MutableBag rejectWith( Predicate2 predicate, P parameter) { return this.getDelegate().rejectWith(predicate, parameter); } public MutableBag select(Predicate predicate) { return this.getDelegate().select(predicate); } public

MutableBag selectWith( Predicate2 predicate, P parameter) { return this.getDelegate().selectWith(predicate, parameter); } public MutableBag selectByOccurrences(IntPredicate predicate) { return this.getDelegate().selectByOccurrences(predicate); } public MutableBag selectInstancesOf(Class clazz) { return this.getDelegate().selectInstancesOf(clazz); } public void forEachWithOccurrences(ObjectIntProcedure procedure) { this.getDelegate().forEachWithOccurrences(procedure); } public PartitionMutableBag partition(Predicate predicate) { return this.getDelegate().partition(predicate); } public

PartitionMutableBag partitionWith(Predicate2 predicate, P parameter) { return this.getDelegate().partitionWith(predicate, parameter); } public MutableBag> zip(Iterable that) { return this.getDelegate().zip(that); } public MutableSet> zipWithIndex() { return this.getDelegate().zipWithIndex(); } public MapIterable toMapOfItemToCount() { return this.getDelegate().toMapOfItemToCount(); } public String toStringOfItemToCount() { return this.getDelegate().toStringOfItemToCount(); } private MutableBag getDelegate() { return (MutableBag) this.delegate; } } private static final class UntouchableIterator implements Iterator { private Iterator delegate; private UntouchableIterator(Iterator newDelegate) { this.delegate = newDelegate; } public boolean hasNext() { return this.delegate.hasNext(); } public T next() { return this.delegate.next(); } public void remove() { this.delegate.remove(); } public void becomeUseless() { this.delegate = null; } } } MutableBagFactoryImpl.java000066400000000000000000000023241234315411400352040ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/bag/mutable/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.bag.mutable; import com.gs.collections.api.bag.MutableBag; import com.gs.collections.api.factory.bag.MutableBagFactory; import net.jcip.annotations.Immutable; @Immutable public final class MutableBagFactoryImpl implements MutableBagFactory { public MutableBag of() { return this.with(); } public MutableBag with() { return HashBag.newBag(); } public MutableBag of(T... elements) { return this.with(elements); } public MutableBag with(T... elements) { return HashBag.newBagWith(elements); } } SynchronizedBag.java000066400000000000000000000312421234315411400341210ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/bag/mutable/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.bag.mutable; import java.io.Serializable; import java.util.Collection; import java.util.Collections; import com.gs.collections.api.bag.ImmutableBag; import com.gs.collections.api.bag.MutableBag; import com.gs.collections.api.bag.primitive.MutableBooleanBag; import com.gs.collections.api.bag.primitive.MutableByteBag; import com.gs.collections.api.bag.primitive.MutableCharBag; import com.gs.collections.api.bag.primitive.MutableDoubleBag; import com.gs.collections.api.bag.primitive.MutableFloatBag; import com.gs.collections.api.bag.primitive.MutableIntBag; import com.gs.collections.api.bag.primitive.MutableLongBag; import com.gs.collections.api.bag.primitive.MutableShortBag; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.predicate.primitive.IntPredicate; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.map.MapIterable; import com.gs.collections.api.multimap.bag.MutableBagMultimap; import com.gs.collections.api.partition.bag.PartitionMutableBag; import com.gs.collections.api.set.MutableSet; import com.gs.collections.api.tuple.Pair; import com.gs.collections.impl.collection.mutable.AbstractSynchronizedMutableCollection; import com.gs.collections.impl.collection.mutable.SynchronizedCollectionSerializationProxy; import com.gs.collections.impl.factory.Bags; import net.jcip.annotations.GuardedBy; /** * A synchronized view of a {@link MutableBag}. It is imperative that the user manually synchronize on the collection when iterating over it using the * standard JDK iterator or JDK 5 for loop, as per {@link Collections#synchronizedCollection(Collection)}. * * @see MutableBag#asSynchronized() * @since 1.0 */ public class SynchronizedBag extends AbstractSynchronizedMutableCollection implements MutableBag, Serializable { SynchronizedBag(MutableBag bag) { super(bag); } public SynchronizedBag(MutableBag bag, Object newLock) { super(bag, newLock); } /** * This method will take a MutableBag and wrap it directly in a SynchronizedBag. */ public static > SynchronizedBag of(B bag) { return new SynchronizedBag(bag); } @GuardedBy("getLock()") private MutableBag getMutableBag() { return (MutableBag) this.getCollection(); } @Override public MutableBag asUnmodifiable() { synchronized (this.getLock()) { return UnmodifiableBag.of(this); } } @Override public ImmutableBag toImmutable() { return Bags.immutable.ofAll(this); } @Override public MutableBag asSynchronized() { return this; } @Override public MutableBag collect(Function function) { synchronized (this.getLock()) { return this.getMutableBag().collect(function); } } @Override public MutableBooleanBag collectBoolean(BooleanFunction booleanFunction) { synchronized (this.getLock()) { return this.getMutableBag().collectBoolean(booleanFunction); } } @Override public MutableByteBag collectByte(ByteFunction byteFunction) { synchronized (this.getLock()) { return this.getMutableBag().collectByte(byteFunction); } } @Override public MutableCharBag collectChar(CharFunction charFunction) { synchronized (this.getLock()) { return this.getMutableBag().collectChar(charFunction); } } @Override public MutableDoubleBag collectDouble(DoubleFunction doubleFunction) { synchronized (this.getLock()) { return this.getMutableBag().collectDouble(doubleFunction); } } @Override public MutableFloatBag collectFloat(FloatFunction floatFunction) { synchronized (this.getLock()) { return this.getMutableBag().collectFloat(floatFunction); } } @Override public MutableIntBag collectInt(IntFunction function) { synchronized (this.getLock()) { return this.getMutableBag().collectInt(function); } } @Override public MutableLongBag collectLong(LongFunction longFunction) { synchronized (this.getLock()) { return this.getMutableBag().collectLong(longFunction); } } @Override public MutableShortBag collectShort(ShortFunction shortFunction) { synchronized (this.getLock()) { return this.getMutableBag().collectShort(shortFunction); } } @Override public MutableBag flatCollect(Function> function) { synchronized (this.getLock()) { return this.getMutableBag().flatCollect(function); } } @Override public MutableBag collectIf( Predicate predicate, Function function) { synchronized (this.getLock()) { return this.getMutableBag().collectIf(predicate, function); } } @Override public MutableBag collectWith(Function2 function, P parameter) { synchronized (this.getLock()) { return this.getMutableBag().collectWith(function, parameter); } } @Override public MutableBagMultimap groupBy(Function function) { synchronized (this.getLock()) { return this.getMutableBag().groupBy(function); } } @Override public MutableBagMultimap groupByEach(Function> function) { synchronized (this.getLock()) { return this.getMutableBag().groupByEach(function); } } @Override public MutableBag newEmpty() { synchronized (this.getLock()) { return this.getMutableBag().newEmpty(); } } @Override public MutableBag reject(Predicate predicate) { synchronized (this.getLock()) { return this.getMutableBag().reject(predicate); } } @Override public

MutableBag rejectWith(Predicate2 predicate, P parameter) { synchronized (this.getLock()) { return this.getMutableBag().rejectWith(predicate, parameter); } } public MutableBag selectByOccurrences(IntPredicate predicate) { synchronized (this.getLock()) { return this.getMutableBag().selectByOccurrences(predicate); } } @Override public MutableBag select(Predicate predicate) { synchronized (this.getLock()) { return this.getMutableBag().select(predicate); } } @Override public

MutableBag selectWith(Predicate2 predicate, P parameter) { synchronized (this.getLock()) { return this.getMutableBag().selectWith(predicate, parameter); } } @Override public PartitionMutableBag partition(Predicate predicate) { synchronized (this.getLock()) { return this.getMutableBag().partition(predicate); } } @Override public

PartitionMutableBag partitionWith(Predicate2 predicate, P parameter) { synchronized (this.getLock()) { return this.getMutableBag().partitionWith(predicate, parameter); } } @Override public MutableBag selectInstancesOf(Class clazz) { synchronized (this.getLock()) { return this.getMutableBag().selectInstancesOf(clazz); } } @Override public boolean equals(Object obj) { synchronized (this.getLock()) { return this.getMutableBag().equals(obj); } } @Override public int hashCode() { synchronized (this.getLock()) { return this.getMutableBag().hashCode(); } } public void addOccurrences(T item, int occurrences) { synchronized (this.getLock()) { this.getMutableBag().addOccurrences(item, occurrences); } } public boolean removeOccurrences(Object item, int occurrences) { synchronized (this.getLock()) { return this.getMutableBag().removeOccurrences(item, occurrences); } } public boolean setOccurrences(T item, int occurrences) { synchronized (this.getLock()) { return this.getMutableBag().setOccurrences(item, occurrences); } } public int sizeDistinct() { synchronized (this.getLock()) { return this.getMutableBag().sizeDistinct(); } } public int occurrencesOf(Object item) { synchronized (this.getLock()) { return this.getMutableBag().occurrencesOf(item); } } public void forEachWithOccurrences(ObjectIntProcedure objectIntProcedure) { synchronized (this.getLock()) { this.getMutableBag().forEachWithOccurrences(objectIntProcedure); } } public MapIterable toMapOfItemToCount() { synchronized (this.getLock()) { return this.getMutableBag().toMapOfItemToCount(); } } @Override public MutableBag> zip(Iterable that) { synchronized (this.getLock()) { return this.getMutableBag().zip(that); } } @Override public >> R zip(Iterable that, R target) { synchronized (this.getLock()) { return this.getMutableBag().zip(that, target); } } @Override public MutableSet> zipWithIndex() { synchronized (this.getLock()) { return this.getMutableBag().zipWithIndex(); } } public String toStringOfItemToCount() { synchronized (this.getLock()) { return this.getMutableBag().toStringOfItemToCount(); } } @Override public >> R zipWithIndex(R target) { synchronized (this.getLock()) { return this.getMutableBag().zipWithIndex(target); } } @Override public MutableBag with(T element) { this.add(element); return this; } @Override public MutableBag without(T element) { this.remove(element); return this; } @Override public MutableBag withAll(Iterable elements) { this.addAllIterable(elements); return this; } @Override public MutableBag withoutAll(Iterable elements) { this.removeAllIterable(elements); return this; } protected Object writeReplace() { return new SynchronizedCollectionSerializationProxy(this.getMutableBag()); } } UnmodifiableBag.java000066400000000000000000000265351234315411400340510ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/bag/mutable/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.bag.mutable; import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; import java.io.Serializable; import com.gs.collections.api.bag.ImmutableBag; import com.gs.collections.api.bag.MutableBag; import com.gs.collections.api.bag.primitive.MutableBooleanBag; import com.gs.collections.api.bag.primitive.MutableByteBag; import com.gs.collections.api.bag.primitive.MutableCharBag; import com.gs.collections.api.bag.primitive.MutableDoubleBag; import com.gs.collections.api.bag.primitive.MutableFloatBag; import com.gs.collections.api.bag.primitive.MutableIntBag; import com.gs.collections.api.bag.primitive.MutableLongBag; import com.gs.collections.api.bag.primitive.MutableShortBag; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.predicate.primitive.IntPredicate; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.map.MapIterable; import com.gs.collections.api.multimap.bag.MutableBagMultimap; import com.gs.collections.api.partition.bag.PartitionMutableBag; import com.gs.collections.api.set.MutableSet; import com.gs.collections.api.tuple.Pair; import com.gs.collections.impl.collection.mutable.AbstractUnmodifiableMutableCollection; import com.gs.collections.impl.factory.Bags; /** * An unmodifiable view of a bag. * * @see MutableBag#asUnmodifiable() * @since 1.0 */ public class UnmodifiableBag extends AbstractUnmodifiableMutableCollection implements MutableBag, Serializable { UnmodifiableBag(MutableBag mutableBag) { super(mutableBag); } /** * This method will take a MutableBag and wrap it directly in a UnmodifiableBag. */ public static > UnmodifiableBag of(B bag) { if (bag == null) { throw new IllegalArgumentException("cannot create an UnmodifiableBag for null"); } return new UnmodifiableBag(bag); } protected MutableBag getMutableBag() { return (MutableBag) this.getMutableCollection(); } @Override public MutableBag asUnmodifiable() { return this; } @Override public MutableBag asSynchronized() { return SynchronizedBag.of(this); } @Override public ImmutableBag toImmutable() { return Bags.immutable.ofAll(this); } @Override public boolean equals(Object obj) { return this.getMutableBag().equals(obj); } @Override public int hashCode() { return this.getMutableBag().hashCode(); } public String toStringOfItemToCount() { return this.getMutableBag().toStringOfItemToCount(); } @Override public MutableBag newEmpty() { return this.getMutableBag().newEmpty(); } public MutableBag selectByOccurrences(IntPredicate predicate) { return this.getMutableBag().selectByOccurrences(predicate); } @Override public MutableBag select(Predicate predicate) { return this.getMutableBag().select(predicate); } @Override public

MutableBag selectWith(Predicate2 predicate, P parameter) { return this.getMutableBag().selectWith(predicate, parameter); } @Override public MutableBag reject(Predicate predicate) { return this.getMutableBag().reject(predicate); } @Override public

MutableBag rejectWith(Predicate2 predicate, P parameter) { return this.getMutableBag().rejectWith(predicate, parameter); } @Override public PartitionMutableBag partition(Predicate predicate) { return this.getMutableBag().partition(predicate); } @Override public

PartitionMutableBag partitionWith(Predicate2 predicate, P parameter) { return this.getMutableBag().partitionWith(predicate, parameter); } @Override public MutableBag selectInstancesOf(Class clazz) { return this.getMutableBag().selectInstancesOf(clazz); } @Override public MutableBag collect(Function function) { return this.getMutableBag().collect(function); } @Override public MutableBooleanBag collectBoolean(BooleanFunction booleanFunction) { return this.getMutableBag().collectBoolean(booleanFunction); } @Override public MutableByteBag collectByte(ByteFunction byteFunction) { return this.getMutableBag().collectByte(byteFunction); } @Override public MutableCharBag collectChar(CharFunction charFunction) { return this.getMutableBag().collectChar(charFunction); } @Override public MutableDoubleBag collectDouble(DoubleFunction doubleFunction) { return this.getMutableBag().collectDouble(doubleFunction); } @Override public MutableFloatBag collectFloat(FloatFunction floatFunction) { return this.getMutableBag().collectFloat(floatFunction); } @Override public MutableIntBag collectInt(IntFunction intFunction) { return this.getMutableBag().collectInt(intFunction); } @Override public MutableLongBag collectLong(LongFunction longFunction) { return this.getMutableBag().collectLong(longFunction); } @Override public MutableShortBag collectShort(ShortFunction shortFunction) { return this.getMutableBag().collectShort(shortFunction); } @Override public MutableBag flatCollect(Function> function) { return this.getMutableBag().flatCollect(function); } @Override public MutableBag collectWith(Function2 function, P parameter) { return this.getMutableBag().collectWith(function, parameter); } @Override public MutableBag collectIf( Predicate predicate, Function function) { return this.getMutableBag().collectIf(predicate, function); } @Override public MutableBagMultimap groupBy(Function function) { return this.getMutableBag().groupBy(function); } @Override public MutableBagMultimap groupByEach(Function> function) { return this.getMutableBag().groupByEach(function); } public void addOccurrences(T item, int occurrences) { throw new UnsupportedOperationException("Cannot call addOccurrences() on " + this.getClass().getSimpleName()); } public boolean removeOccurrences(Object item, int occurrences) { throw new UnsupportedOperationException("Cannot call removeOccurrences() on " + this.getClass().getSimpleName()); } public boolean setOccurrences(T item, int occurrences) { throw new UnsupportedOperationException("Cannot call setOccurrences() on " + this.getClass().getSimpleName()); } public int sizeDistinct() { return this.getMutableBag().sizeDistinct(); } public int occurrencesOf(Object item) { return this.getMutableBag().occurrencesOf(item); } public void forEachWithOccurrences(ObjectIntProcedure objectIntProcedure) { this.getMutableBag().forEachWithOccurrences(objectIntProcedure); } public MapIterable toMapOfItemToCount() { return this.getMutableBag().toMapOfItemToCount(); } @Override public MutableBag> zip(Iterable that) { return this.getMutableBag().zip(that); } @Override public MutableSet> zipWithIndex() { return this.getMutableBag().zipWithIndex(); } @Override public MutableBag with(T element) { throw new UnsupportedOperationException("Cannot call with() on " + this.getClass().getSimpleName()); } @Override public MutableBag without(T element) { throw new UnsupportedOperationException("Cannot call without() on " + this.getClass().getSimpleName()); } @Override public MutableBag withAll(Iterable elements) { throw new UnsupportedOperationException("Cannot call withAll() on " + this.getClass().getSimpleName()); } @Override public MutableBag withoutAll(Iterable elements) { throw new UnsupportedOperationException("Cannot call withoutAll() on " + this.getClass().getSimpleName()); } protected Object writeReplace() { return new UnmodifiableBagSerializationProxy(this.getMutableBag()); } private static class UnmodifiableBagSerializationProxy implements Externalizable { private static final long serialVersionUID = 1L; private MutableBag mutableBag; @SuppressWarnings("UnusedDeclaration") public UnmodifiableBagSerializationProxy() { // Empty constructor for Externalizable class } private UnmodifiableBagSerializationProxy(MutableBag bag) { this.mutableBag = bag; } public void writeExternal(ObjectOutput out) throws IOException { try { out.writeObject(this.mutableBag); } catch (RuntimeException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw e; } } public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { this.mutableBag = (MutableBag) in.readObject(); } protected Object readResolve() { return this.mutableBag.asUnmodifiable(); } } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/bag/mutable/package-info.java000066400000000000000000000034341234315411400334350ustar00rootroot00000000000000/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains implementations of the {@link com.gs.collections.api.bag.MutableBag} interface. *

* A MutableBag is a {@link java.util.Collection} which contains elements that are unordered and may contain duplicate entries. It adds a protocol for * adding, removing, and determining the number of occurrences for an item. *

*

* This package contains 3 bag implementations: *

    *
  • * {@link com.gs.collections.impl.bag.mutable.HashBag} - a {@link com.gs.collections.api.bag.MutableBag} which uses a hashtable as its underlying data store. *
  • *
  • * {@link com.gs.collections.impl.bag.mutable.SynchronizedBag} - a synchronized view of a bag. *
  • *
  • * {@link com.gs.collections.impl.bag.mutable.UnmodifiableBag} - an unmodifiable view of a bag. *
  • *
*

*

* This package contains one factory implementation: *

    *
  • * {@link com.gs.collections.impl.bag.mutable.MutableBagFactoryImpl} - a factory which creates instances of type {@link com.gs.collections.api.bag.MutableBag}. *
  • *
*

*/ package com.gs.collections.impl.bag.mutable; gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/bag/mutable/primitive/000077500000000000000000000000001234315411400322525ustar00rootroot00000000000000BooleanHashBag.java000066400000000000000000000454701234315411400356450ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/bag/mutable/primitive/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.bag.mutable.primitive; import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; import java.util.NoSuchElementException; import com.gs.collections.api.BooleanIterable; import com.gs.collections.api.LazyBooleanIterable; import com.gs.collections.api.bag.MutableBag; import com.gs.collections.api.bag.primitive.BooleanBag; import com.gs.collections.api.bag.primitive.ImmutableBooleanBag; import com.gs.collections.api.bag.primitive.MutableBooleanBag; import com.gs.collections.api.block.function.primitive.BooleanToObjectFunction; import com.gs.collections.api.block.function.primitive.ObjectBooleanToObjectFunction; import com.gs.collections.api.block.predicate.primitive.BooleanPredicate; import com.gs.collections.api.block.procedure.primitive.BooleanIntProcedure; import com.gs.collections.api.block.procedure.primitive.BooleanProcedure; import com.gs.collections.api.iterator.BooleanIterator; import com.gs.collections.api.list.primitive.MutableBooleanList; import com.gs.collections.api.set.primitive.BooleanSet; import com.gs.collections.api.set.primitive.MutableBooleanSet; import com.gs.collections.impl.bag.mutable.HashBag; import com.gs.collections.impl.factory.primitive.BooleanBags; import com.gs.collections.impl.lazy.primitive.LazyBooleanIterableAdapter; import com.gs.collections.impl.list.mutable.primitive.BooleanArrayList; import com.gs.collections.impl.set.mutable.primitive.BooleanHashSet; import net.jcip.annotations.NotThreadSafe; /** * BooleanHashBag is similar to {@link HashBag}, and is memory-optimized for boolean primitives. * * @since 3.0. */ @NotThreadSafe public final class BooleanHashBag implements MutableBooleanBag, Externalizable { private static final long serialVersionUID = 1L; private int falseCount; private int trueCount; public BooleanHashBag() { } public BooleanHashBag(BooleanIterable iterable) { this(); this.addAll(iterable); } public BooleanHashBag(BooleanHashBag bag) { this.falseCount = bag.falseCount; this.trueCount = bag.trueCount; } public static BooleanHashBag newBagWith(boolean... source) { BooleanHashBag result = new BooleanHashBag(); result.addAll(source); return result; } public static BooleanHashBag newBag(BooleanIterable source) { if (source instanceof BooleanHashBag) { return new BooleanHashBag((BooleanHashBag) source); } return new BooleanHashBag(source); } private boolean containsFalse() { return this.falseCount > 0; } private boolean containsTrue() { return this.trueCount > 0; } public boolean isEmpty() { return !this.containsFalse() && !this.containsTrue(); } public boolean notEmpty() { return this.containsFalse() || this.containsTrue(); } public int size() { return this.falseCount + this.trueCount; } public int sizeDistinct() { return (this.containsFalse() ? 1 : 0) + (this.containsTrue() ? 1 : 0); } public void clear() { this.falseCount = 0; this.trueCount = 0; } public BooleanHashBag with(boolean element) { this.add(element); return this; } public BooleanHashBag with(boolean element1, boolean element2) { this.add(element1); this.add(element2); return this; } public BooleanHashBag with(boolean element1, boolean element2, boolean element3) { this.add(element1); this.add(element2); this.add(element3); return this; } public BooleanHashBag withAll(BooleanIterable iterable) { this.addAll(iterable); return this; } public BooleanHashBag without(boolean element) { this.remove(element); return this; } public BooleanHashBag withoutAll(BooleanIterable iterable) { this.removeAll(iterable); return this; } public MutableBooleanBag asUnmodifiable() { return new UnmodifiableBooleanBag(this); } public MutableBooleanBag asSynchronized() { return new SynchronizedBooleanBag(this); } public ImmutableBooleanBag toImmutable() { return BooleanBags.immutable.withAll(this); } public boolean contains(boolean value) { return value ? this.containsTrue() : this.containsFalse(); } public boolean containsAll(boolean... source) { for (boolean each : source) { if (!this.contains(each)) { return false; } } return true; } public boolean containsAll(BooleanIterable source) { return source.allSatisfy(new BooleanPredicate() { public boolean accept(boolean each) { return BooleanHashBag.this.contains(each); } }); } public int occurrencesOf(boolean item) { return item ? this.trueCount : this.falseCount; } public void forEachWithOccurrences(BooleanIntProcedure procedure) { if (this.containsFalse()) { procedure.value(false, this.falseCount); } if (this.containsTrue()) { procedure.value(true, this.trueCount); } } public boolean add(boolean item) { if (item) { this.trueCount++; } else { this.falseCount++; } return true; } public boolean remove(boolean item) { if (item) { if (!this.containsTrue()) { return false; } this.trueCount--; } else { if (!this.containsFalse()) { return false; } this.falseCount--; } return true; } public boolean addAll(boolean... source) { if (source.length < 1) { return false; } for (boolean each : source) { this.add(each); } return true; } public boolean addAll(BooleanIterable source) { if (source.isEmpty()) { return false; } if (source instanceof BooleanBag) { BooleanBag otherBag = (BooleanBag) source; otherBag.forEachWithOccurrences(new BooleanIntProcedure() { public void value(boolean each, int occurrences) { BooleanHashBag.this.addOccurrences(each, occurrences); } }); } else { BooleanIterator iterator = source.booleanIterator(); while (iterator.hasNext()) { boolean each = iterator.next(); this.add(each); } } return true; } public boolean removeAll(boolean... source) { if (source.length == 0) { return false; } int oldSize = this.size(); for (boolean each : source) { if (each) { this.trueCount = 0; } else { this.falseCount = 0; } } return this.size() != oldSize; } public boolean removeAll(BooleanIterable source) { if (source.isEmpty()) { return false; } int oldSize = this.size(); if (source instanceof BooleanBag) { BooleanBag otherBag = (BooleanBag) source; otherBag.forEachWithOccurrences(new BooleanIntProcedure() { public void value(boolean each, int occurrences) { if (each) { BooleanHashBag.this.trueCount = 0; } else { BooleanHashBag.this.falseCount = 0; } } }); } else { BooleanIterator iterator = source.booleanIterator(); while (iterator.hasNext()) { boolean each = iterator.next(); if (each) { this.trueCount = 0; } else { this.falseCount = 0; } } } return this.size() != oldSize; } public boolean retainAll(BooleanIterable elements) { int oldSize = this.size(); BooleanSet set = elements instanceof BooleanSet ? (BooleanSet) elements : elements.toSet(); if (!set.contains(true) && this.containsTrue()) { this.trueCount = 0; } if (!set.contains(false) && this.containsFalse()) { this.falseCount = 0; } return this.size() != oldSize; } public boolean retainAll(boolean... source) { return this.retainAll(BooleanHashSet.newSetWith(source)); } public void addOccurrences(boolean item, int occurrences) { if (occurrences < 0) { throw new IllegalArgumentException("Cannot add a negative number of occurrences"); } if (occurrences > 0) { if (item) { this.trueCount += occurrences; } else { this.falseCount += occurrences; } } } public boolean removeOccurrences(boolean item, int occurrences) { if (occurrences < 0) { throw new IllegalArgumentException("Cannot remove a negative number of occurrences"); } if (occurrences == 0) { return false; } if (item) { if (!this.containsTrue()) { return false; } this.trueCount -= occurrences; if (this.trueCount < 0) { this.trueCount = 0; } } else { if (!this.containsFalse()) { return false; } this.falseCount -= occurrences; if (this.falseCount < 0) { this.falseCount = 0; } } return true; } public void forEach(BooleanProcedure procedure) { for (int i = 0; i < this.falseCount; i++) { procedure.value(false); } for (int i = 0; i < this.trueCount; i++) { procedure.value(true); } } public MutableBooleanBag select(final BooleanPredicate predicate) { final MutableBooleanBag result = new BooleanHashBag(); this.forEachWithOccurrences(new BooleanIntProcedure() { public void value(boolean each, int occurrences) { if (predicate.accept(each)) { result.addOccurrences(each, occurrences); } } }); return result; } public MutableBooleanBag reject(final BooleanPredicate predicate) { final MutableBooleanBag result = new BooleanHashBag(); this.forEachWithOccurrences(new BooleanIntProcedure() { public void value(boolean each, int occurrences) { if (!predicate.accept(each)) { result.addOccurrences(each, occurrences); } } }); return result; } public T injectInto(T injectedValue, ObjectBooleanToObjectFunction function) { T result = injectedValue; BooleanIterator it = this.booleanIterator(); while (it.hasNext()) { result = function.valueOf(result, it.next()); } return result; } @Override public boolean equals(Object otherBag) { if (otherBag == this) { return true; } if (!(otherBag instanceof BooleanBag)) { return false; } BooleanBag bag = (BooleanBag) otherBag; if (this.sizeDistinct() != bag.sizeDistinct()) { return false; } return this.falseCount == bag.occurrencesOf(false) && this.trueCount == bag.occurrencesOf(true); } @Override public int hashCode() { int result = 0; if (this.containsFalse()) { result = 1237 ^ this.falseCount; } if (this.containsTrue()) { result += 1231 ^ this.trueCount; } return result; } @Override public String toString() { return this.makeString("[", ", ", "]"); } public String makeString() { return this.makeString(", "); } public String makeString(String separator) { return this.makeString("", separator, ""); } public String makeString(String start, String separator, String end) { Appendable stringBuilder = new StringBuilder(); this.appendString(stringBuilder, start, separator, end); return stringBuilder.toString(); } public void appendString(Appendable appendable) { this.appendString(appendable, ", "); } public void appendString(Appendable appendable, String separator) { this.appendString(appendable, "", separator, ""); } public void appendString( Appendable appendable, String start, String separator, String end) { try { appendable.append(start); boolean firstItem = true; for (int i = 0; i < this.falseCount; i++) { if (!firstItem) { appendable.append(separator); } appendable.append("false"); firstItem = false; } for (int i = 0; i < this.trueCount; i++) { if (!firstItem) { appendable.append(separator); } appendable.append("true"); firstItem = false; } appendable.append(end); } catch (IOException e) { throw new RuntimeException(e); } } public int count(BooleanPredicate predicate) { int result = 0; if (this.containsFalse() && predicate.accept(false)) { result = this.falseCount; } if (this.containsTrue() && predicate.accept(true)) { result += this.trueCount; } return result; } public boolean anySatisfy(BooleanPredicate predicate) { return this.containsFalse() && predicate.accept(false) || this.containsTrue() && predicate.accept(true); } public boolean allSatisfy(BooleanPredicate predicate) { return (!this.containsFalse() || predicate.accept(false)) && (!this.containsTrue() || predicate.accept(true)); } public boolean noneSatisfy(BooleanPredicate predicate) { return (!this.containsFalse() || !predicate.accept(false)) && (!this.containsTrue() || !predicate.accept(true)); } public boolean detectIfNone(BooleanPredicate predicate, boolean ifNone) { if (this.containsFalse() && predicate.accept(false)) { return false; } if (this.containsTrue() && predicate.accept(true)) { return true; } return ifNone; } public MutableBag collect(BooleanToObjectFunction function) { HashBag result = HashBag.newBag(); if (this.containsFalse()) { result.addOccurrences(function.valueOf(false), this.falseCount); } if (this.containsTrue()) { result.addOccurrences(function.valueOf(true), this.trueCount); } return result; } public boolean[] toArray() { final boolean[] array = new boolean[this.size()]; final int[] index = {0}; this.forEachWithOccurrences(new BooleanIntProcedure() { public void value(boolean each, int occurrences) { for (int i = 0; i < occurrences; i++) { array[index[0]] = each; index[0]++; } } }); return array; } public MutableBooleanList toList() { return BooleanArrayList.newList(this); } public MutableBooleanSet toSet() { return BooleanHashSet.newSet(this); } public MutableBooleanBag toBag() { return BooleanHashBag.newBag(this); } public LazyBooleanIterable asLazy() { return new LazyBooleanIterableAdapter(this); } public BooleanIterator booleanIterator() { return new InternalIterator(this.falseCount, this.trueCount); } public void writeExternal(ObjectOutput out) throws IOException { out.writeInt(this.falseCount); out.writeInt(this.trueCount); } public void readExternal(ObjectInput in) throws IOException { this.falseCount = in.readInt(); this.trueCount = in.readInt(); } private static final class InternalIterator implements BooleanIterator { private int falseCount; private int trueCount; private InternalIterator(int falseCount, int trueCount) { this.falseCount = falseCount; this.trueCount = trueCount; } public boolean hasNext() { return this.falseCount > 0 || this.trueCount > 0; } public boolean next() { if (this.falseCount > 0) { this.falseCount--; return false; } if (this.trueCount > 0) { this.trueCount--; return true; } throw new NoSuchElementException("next() called, but the iterator is exhausted"); } } } package-info.java000066400000000000000000000015751234315411400353720ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/bag/mutable/primitive/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains implementations of the mutable primitive bag interfaces. *

* A mutable primitive bag is similar to a {@link com.gs.collections.api.bag.MutableBag}, but is memory-optimized for primitives. *

*/ package com.gs.collections.impl.bag.mutable.primitive; gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/bag/sorted/000077500000000000000000000000001234315411400301115ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/bag/sorted/mutable/000077500000000000000000000000001234315411400315425ustar00rootroot00000000000000TreeBag.java000066400000000000000000001205121234315411400336400ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/bag/sorted/mutable/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.bag.sorted.mutable; import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; import java.util.Arrays; import java.util.Collection; import java.util.Comparator; import java.util.Iterator; import java.util.Map; import java.util.NoSuchElementException; import java.util.Set; import java.util.concurrent.ExecutorService; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.bag.Bag; import com.gs.collections.api.bag.MutableBag; import com.gs.collections.api.bag.sorted.ImmutableSortedBag; import com.gs.collections.api.bag.sorted.MutableSortedBag; import com.gs.collections.api.bag.sorted.ParallelSortedBag; import com.gs.collections.api.bag.sorted.SortedBag; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.predicate.primitive.IntPredicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.list.primitive.MutableBooleanList; import com.gs.collections.api.list.primitive.MutableByteList; import com.gs.collections.api.list.primitive.MutableCharList; import com.gs.collections.api.list.primitive.MutableDoubleList; import com.gs.collections.api.list.primitive.MutableFloatList; import com.gs.collections.api.list.primitive.MutableIntList; import com.gs.collections.api.list.primitive.MutableLongList; import com.gs.collections.api.list.primitive.MutableShortList; import com.gs.collections.api.map.MutableMap; import com.gs.collections.api.map.sorted.MutableSortedMap; import com.gs.collections.api.multimap.MutableMultimap; import com.gs.collections.api.partition.bag.sorted.PartitionMutableSortedBag; import com.gs.collections.api.set.MutableSet; import com.gs.collections.api.set.sorted.MutableSortedSet; import com.gs.collections.api.stack.MutableStack; import com.gs.collections.api.tuple.Pair; import com.gs.collections.impl.Counter; import com.gs.collections.impl.bag.mutable.HashBag; import com.gs.collections.impl.block.factory.Predicates2; import com.gs.collections.impl.block.procedure.CollectionAddProcedure; import com.gs.collections.impl.block.procedure.MultimapEachPutProcedure; import com.gs.collections.impl.block.procedure.MultimapPutProcedure; import com.gs.collections.impl.block.procedure.checked.CheckedProcedure2; import com.gs.collections.impl.collection.AbstractMutableBag; import com.gs.collections.impl.list.mutable.FastList; import com.gs.collections.impl.list.mutable.primitive.BooleanArrayList; import com.gs.collections.impl.list.mutable.primitive.ByteArrayList; import com.gs.collections.impl.list.mutable.primitive.CharArrayList; import com.gs.collections.impl.list.mutable.primitive.DoubleArrayList; import com.gs.collections.impl.list.mutable.primitive.FloatArrayList; import com.gs.collections.impl.list.mutable.primitive.IntArrayList; import com.gs.collections.impl.list.mutable.primitive.LongArrayList; import com.gs.collections.impl.list.mutable.primitive.ShortArrayList; import com.gs.collections.impl.map.sorted.mutable.TreeSortedMap; import com.gs.collections.impl.multimap.bag.sorted.TreeBagMultimap; import com.gs.collections.impl.partition.bag.sorted.PartitionTreeBag; import com.gs.collections.impl.set.mutable.UnifiedSet; import com.gs.collections.impl.set.sorted.mutable.TreeSortedSet; import com.gs.collections.impl.stack.mutable.ArrayStack; import com.gs.collections.impl.utility.Iterate; import com.gs.collections.impl.utility.internal.IterableIterate; /** * A TreeBag is a MutableSortedBag which uses a SortedMap as its underlying data store. Each key in the SortedMap represents some item, * and the value in the map represents the current number of occurrences of that item. * * @since 4.2 */ public class TreeBag extends AbstractMutableBag implements Externalizable, MutableSortedBag { private static final Function0 NEW_COUNTER_BLOCK = new Function0() { public Counter value() { return new Counter(); } }; private static final long serialVersionUID = 1L; private MutableSortedMap items; private int size; public TreeBag() { this.items = TreeSortedMap.newMap(); } private TreeBag(MutableSortedMap map) { this.items = map; this.size = (int) map.valuesView().sumOfInt(Counter.TO_COUNT); } public TreeBag(Comparator comparator) { this.items = TreeSortedMap.newMap(comparator); } public TreeBag(SortedBag sortedBag) { this(sortedBag.comparator(), sortedBag); } public TreeBag(Comparator comparator, Iterable iterable) { this(comparator); this.addAllIterable(iterable); } public static TreeBag newBag() { return new TreeBag(); } public static TreeBag newBag(Comparator comparator) { return new TreeBag(comparator); } public static TreeBag newBag(Iterable source) { if (source instanceof SortedBag) { return new TreeBag((SortedBag) source); } return Iterate.addAllTo(source, TreeBag.newBag()); } public static TreeBag newBag(Comparator comparator, Iterable iterable) { return new TreeBag(comparator, iterable); } public static TreeBag newBagWith(E... elements) { //noinspection SSBasedInspection return TreeBag.newBag(Arrays.asList(elements)); } public static TreeBag newBagWith(Comparator comparator, E... elements) { //noinspection SSBasedInspection return TreeBag.newBag(comparator, Arrays.asList(elements)); } private static int compare(SortedBag bagA, SortedBag bagB) { Iterator itrA = bagA.iterator(); Iterator itrB = bagB.iterator(); if (bagA.comparator() != null) { Comparator comparator = bagA.comparator(); while (itrA.hasNext()) { if (itrB.hasNext()) { int val = comparator.compare(itrA.next(), itrB.next()); if (val != 0) { return val; } } else { return 1; } } return itrB.hasNext() ? -1 : 0; } while (itrA.hasNext()) { if (itrB.hasNext()) { int val = ((Comparable) itrA.next()).compareTo(itrB.next()); if (val != 0) { return val; } } else { return 1; } } return itrB.hasNext() ? -1 : 0; } @Override public TreeBag clone() { try { TreeBag clone = (TreeBag) super.clone(); clone.items = this.items.clone(); return clone; } catch (CloneNotSupportedException e) { throw new AssertionError(e); } } @Override public boolean equals(Object other) { if (this == other) { return true; } if (!(other instanceof Bag)) { return false; } final Bag bag = (Bag) other; if (this.sizeDistinct() != bag.sizeDistinct()) { return false; } return this.items.keyValuesView().allSatisfy(new Predicate>() { public boolean accept(Pair each) { return bag.occurrencesOf(each.getOne()) == each.getTwo().getCount(); } }); } public int sizeDistinct() { return this.items.size(); } @Override public int hashCode() { final Counter counter = new Counter(); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int count) { counter.add((each == null ? 0 : each.hashCode()) ^ count); } }); return counter.getCount(); } public void forEachWithOccurrences(final ObjectIntProcedure procedure) { this.items.forEachKeyValue(new Procedure2() { public void value(T item, Counter count) { procedure.value(item, count.getCount()); } }); } public MutableSortedBag selectByOccurrences(final IntPredicate predicate) { MutableSortedMap map = this.items.select(new Predicate2() { public boolean accept(T each, Counter occurrences) { return predicate.accept(occurrences.getCount()); } }); return new TreeBag(map); } public int occurrencesOf(Object item) { Counter counter = this.items.get(item); return counter == null ? 0 : counter.getCount(); } public MutableSortedMap toMapOfItemToCount() { final MutableSortedMap map = TreeSortedMap.newMap(this.comparator()); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T item, int count) { map.put(item, count); } }); return map; } public String toStringOfItemToCount() { return this.items.toString(); } @Override public boolean isEmpty() { return this.items.isEmpty(); } @Override public boolean remove(Object item) { Counter counter = this.items.get(item); if (counter != null) { if (counter.getCount() > 1) { counter.decrement(); } else { this.items.remove(item); } this.size--; return true; } return false; } @Override public boolean removeAll(Collection collection) { return this.removeAllIterable(collection); } @Override public boolean retainAll(Collection collection) { return this.retainAllIterable(collection); } public void clear() { this.items.clear(); this.size = 0; } @Override public boolean contains(Object o) { return this.items.containsKey(o); } public int compareTo(SortedBag otherBag) { return TreeBag.compare(this, otherBag); } public void writeExternal(final ObjectOutput out) throws IOException { out.writeObject(this.comparator()); out.writeInt(this.items.size()); try { this.items.forEachKeyValue(new CheckedProcedure2() { @Override public void safeValue(T object, Counter parameter) throws Exception { out.writeObject(object); out.writeInt(parameter.getCount()); } }); } catch (RuntimeException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw e; } } public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { this.items = new TreeSortedMap((Comparator) in.readObject()); int size = in.readInt(); for (int i = 0; i < size; i++) { this.addOccurrences((T) in.readObject(), in.readInt()); } } public void forEach(final Procedure procedure) { this.items.forEachKeyValue(new Procedure2() { public void value(T key, Counter value) { for (int i = 0; i < value.getCount(); i++) { procedure.value(key); } } }); } @Override public void forEachWithIndex(final ObjectIntProcedure objectIntProcedure) { final Counter index = new Counter(); this.items.forEachKeyValue(new Procedure2() { public void value(T key, Counter value) { for (int i = 0; i < value.getCount(); i++) { objectIntProcedure.value(key, index.getCount()); index.increment(); } } }); } @Override public

void forEachWith(final Procedure2 procedure, final P parameter) { this.items.forEachKeyValue(new Procedure2() { public void value(T key, Counter value) { for (int i = 0; i < value.getCount(); i++) { procedure.value(key, parameter); } } }); } public Iterator iterator() { return new InternalIterator(); } public void addOccurrences(T item, int occurrences) { if (occurrences < 0) { throw new IllegalArgumentException("Cannot add a negative number of occurrences"); } if (occurrences > 0) { this.items.getIfAbsentPut(item, NEW_COUNTER_BLOCK).add(occurrences); this.size += occurrences; } } public boolean removeOccurrences(Object item, int occurrences) { if (occurrences < 0) { throw new IllegalArgumentException("Cannot remove a negative number of occurrences"); } if (occurrences == 0) { return false; } Counter counter = this.items.get(item); if (counter == null) { return false; } int startCount = counter.getCount(); if (occurrences >= startCount) { this.items.remove(item); this.size -= startCount; return true; } counter.add(occurrences * -1); this.size -= occurrences; return true; } public TreeBag without(T element) { this.remove(element); return this; } public TreeBag withAll(Iterable iterable) { this.addAllIterable(iterable); return this; } public TreeBag withoutAll(Iterable iterable) { this.removeAllIterable(iterable); return this; } public ImmutableSortedBag toImmutable() { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".toImmutable() not implemented yet"); } public MutableList collectWith( final Function2 function, final P parameter) { final MutableList result = FastList.newList(); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { V value = function.value(each, parameter); for (int i = 0; i < occurrences; i++) { result.add(value); } } }); return result; } public TreeBag with(T element) { this.add(element); return this; } public MutableSortedBag newEmpty() { return TreeBag.newBag(this.items.comparator()); } public

MutableSortedBag selectWith(final Predicate2 predicate, final P parameter) { final MutableSortedBag result = TreeBag.newBag(this.comparator()); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { if (predicate.accept(each, parameter)) { result.addOccurrences(each, occurrences); } } }); return result; } public

MutableSortedBag rejectWith(final Predicate2 predicate, final P parameter) { final MutableSortedBag result = TreeBag.newBag(this.comparator()); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int index) { if (!predicate.accept(each, parameter)) { result.addOccurrences(each, index); } } }); return result; } @Override public void removeIf(Predicate predicate) { Set> entries = this.items.entrySet(); for (Iterator> iterator = entries.iterator(); iterator.hasNext(); ) { Map.Entry entry = iterator.next(); if (predicate.accept(entry.getKey())) { this.size -= entry.getValue().getCount(); iterator.remove(); } } } @Override public

void removeIfWith(Predicate2 predicate, P parameter) { Set> entries = this.items.entrySet(); for (Iterator> iterator = entries.iterator(); iterator.hasNext(); ) { Map.Entry entry = iterator.next(); if (predicate.accept(entry.getKey(), parameter)) { this.size -= entry.getValue().getCount(); iterator.remove(); } } } @Override public

T detectWith(final Predicate2 predicate, final P parameter) { return this.items.keysView().detect(new Predicate() { public boolean accept(T each) { return predicate.accept(each, parameter); } }); } @Override public

T detectWithIfNone( final Predicate2 predicate, final P parameter, Function0 function) { return this.items.keysView().detectIfNone(new Predicate() { public boolean accept(T each) { return predicate.accept(each, parameter); } }, function); } @Override public

int countWith(final Predicate2 predicate, final P parameter) { final Counter result = new Counter(); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { if (predicate.accept(each, parameter)) { result.add(occurrences); } } }); return result.getCount(); } @Override public

boolean anySatisfyWith(final Predicate2 predicate, final P parameter) { return this.items.keysView().anySatisfy(new Predicate() { public boolean accept(T each) { return predicate.accept(each, parameter); } }); } @Override public

boolean allSatisfyWith(final Predicate2 predicate, final P parameter) { return this.items.keysView().allSatisfy(new Predicate() { public boolean accept(T each) { return predicate.accept(each, parameter); } }); } @Override public

boolean noneSatisfyWith(final Predicate2 predicate, final P parameter) { return this.items.keysView().noneSatisfy(new Predicate() { public boolean accept(T each) { return predicate.accept(each, parameter); } }); } public UnmodifiableSortedBag asUnmodifiable() { return UnmodifiableSortedBag.of(this); } public MutableSortedBag asSynchronized() { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".asSynchronized() not implemented yet"); } @Beta public ParallelSortedBag asParallel(ExecutorService executorService, int batchSize) { if (executorService == null) { throw new NullPointerException(); } if (batchSize < 1) { throw new IllegalArgumentException(); } throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".asParallel() not implemented yet"); } @Override public boolean removeAllIterable(Iterable iterable) { int oldSize = this.size; for (Object each : iterable) { Counter removed = this.items.remove(each); if (removed != null) { this.size -= removed.getCount(); } } return this.size != oldSize; } @Override public boolean retainAllIterable(Iterable iterable) { int oldSize = this.size; this.removeIfWith(Predicates2.notIn(), UnifiedSet.newSet(iterable)); return this.size != oldSize; } public int size() { return this.size; } public MutableSortedBag reject(final Predicate predicate) { final MutableSortedBag result = TreeBag.newBag(this.comparator()); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int index) { if (!predicate.accept(each)) { result.addOccurrences(each, index); } } }); return result; } public PartitionMutableSortedBag partition(final Predicate predicate) { final PartitionMutableSortedBag result = new PartitionTreeBag(this.comparator()); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int index) { MutableSortedBag bucket = predicate.accept(each) ? result.getSelected() : result.getRejected(); bucket.addOccurrences(each, index); } }); return result; } public

PartitionMutableSortedBag partitionWith(final Predicate2 predicate, final P parameter) { final PartitionMutableSortedBag result = new PartitionTreeBag(this.comparator()); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int index) { MutableSortedBag bucket = predicate.accept(each, parameter) ? result.getSelected() : result.getRejected(); bucket.addOccurrences(each, index); } }); return result; } public PartitionMutableSortedBag partitionWhile(Predicate predicate) { PartitionTreeBag result = new PartitionTreeBag(this.comparator()); return IterableIterate.partitionWhile(this, predicate, result); } public MutableSortedBag selectInstancesOf(final Class clazz) { Comparator comparator = (Comparator) this.comparator(); final MutableSortedBag result = TreeBag.newBag(comparator); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { if (clazz.isInstance(each)) { result.addOccurrences(clazz.cast(each), occurrences); } } }); return result; } public TreeBagMultimap groupBy(Function function) { return this.groupBy(function, TreeBagMultimap.newMultimap(this.comparator())); } public TreeBagMultimap groupByEach(Function> function) { return this.groupByEach(function, TreeBagMultimap.newMultimap(this.comparator())); } public MutableMap groupByUniqueKey(Function function) { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".groupByUniqueKey() not implemented yet"); } public MutableByteList collectByte(final ByteFunction byteFunction) { final MutableByteList result = new ByteArrayList(); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { byte element = byteFunction.byteValueOf(each); for (int i = 0; i < occurrences; i++) { result.add(element); } } }); return result; } public T getFirst() { return this.items.keysView().getFirst(); } public MutableSortedSet> zipWithIndex() { return this.zipWithIndex(TreeSortedSet.>newSet()); } public T getLast() { return this.items.keysView().getLast(); } public MutableList collect(final Function function) { final MutableList result = FastList.newList(); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { V value = function.valueOf(each); for (int i = 0; i < occurrences; i++) { result.add(value); } } }); return result; } public MutableList flatCollect(final Function> function) { final MutableList result = FastList.newList(); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, final int occurrences) { Iterable values = function.valueOf(each); Iterate.forEach(values, new Procedure() { public void value(V each) { for (int i = 0; i < occurrences; i++) { result.add(each); } } }); } }); return result; } public MutableSortedSet distinct() { return TreeSortedSet.newSet(this.comparator(), this.items.keySet()); } public MutableSortedBag takeWhile(Predicate predicate) { MutableSortedBag result = TreeBag.newBag(this.comparator()); return IterableIterate.takeWhile(this, predicate, result); } public MutableSortedBag dropWhile(Predicate predicate) { MutableSortedBag result = TreeBag.newBag(this.comparator()); return IterableIterate.dropWhile(this, predicate, result); } @Override public > R select(final Predicate predicate, final R target) { this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { if (predicate.accept(each)) { for (int i = 0; i < occurrences; i++) { target.add(each); } } } }); return target; } @Override public > R selectWith( final Predicate2 predicate, final P parameter, final R target) { this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { if (predicate.accept(each, parameter)) { for (int i = 0; i < occurrences; i++) { target.add(each); } } } }); return target; } public MutableSortedBag select(final Predicate predicate) { final MutableSortedBag result = TreeBag.newBag(this.comparator()); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { if (predicate.accept(each)) { result.addOccurrences(each, occurrences); } } }); return result; } @Override public > R reject(final Predicate predicate, final R target) { this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { if (!predicate.accept(each)) { for (int i = 0; i < occurrences; i++) { target.add(each); } } } }); return target; } @Override public > R rejectWith( final Predicate2 predicate, final P parameter, final R target) { this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { if (!predicate.accept(each, parameter)) { for (int i = 0; i < occurrences; i++) { target.add(each); } } } }); return target; } public MutableBooleanList collectBoolean(BooleanFunction booleanFunction) { return this.collectBoolean(booleanFunction, new BooleanArrayList()); } public MutableCharList collectChar(CharFunction charFunction) { return this.collectChar(charFunction, new CharArrayList()); } public MutableDoubleList collectDouble(DoubleFunction doubleFunction) { return this.collectDouble(doubleFunction, new DoubleArrayList()); } public MutableFloatList collectFloat(FloatFunction floatFunction) { return this.collectFloat(floatFunction, new FloatArrayList()); } public MutableIntList collectInt(IntFunction intFunction) { return this.collectInt(intFunction, new IntArrayList()); } public MutableLongList collectLong(LongFunction longFunction) { return this.collectLong(longFunction, new LongArrayList()); } public MutableShortList collectShort(ShortFunction shortFunction) { return this.collectShort(shortFunction, new ShortArrayList()); } public MutableList collectIf( final Predicate predicate, final Function function) { final MutableList result = FastList.newList(); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { if (predicate.accept(each)) { V element = function.valueOf(each); for (int i = 0; i < occurrences; i++) { result.add(element); } } } }); return result; } public MutableList> zip(Iterable that) { return this.zip(that, FastList.>newList()); } @Override public T detect(Predicate predicate) { return this.items.keysView().detect(predicate); } @Override public T detectIfNone(Predicate predicate, Function0 function) { return this.items.keysView().detectIfNone(predicate, function); } @Override public int count(final Predicate predicate) { final Counter result = new Counter(); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { if (predicate.accept(each)) { result.add(occurrences); } } }); return result.getCount(); } @Override public boolean anySatisfy(Predicate predicate) { return this.items.keysView().anySatisfy(predicate); } @Override public boolean allSatisfy(Predicate predicate) { return this.items.keysView().allSatisfy(predicate); } @Override public boolean noneSatisfy(Predicate predicate) { return this.items.keysView().noneSatisfy(predicate); } @Override public MutableList toList() { return FastList.newList(this); } @Override public MutableSet toSet() { UnifiedSet result = UnifiedSet.newSet(this.sizeDistinct()); this.items.forEachKey(CollectionAddProcedure.on(result)); return result; } @Override public MutableBag toBag() { return HashBag.newBag(this); } public MutableStack toStack() { return ArrayStack.newStack(this); } @Override public T min(Comparator comparator) { return this.items.keysView().min(comparator); } @Override public T max(Comparator comparator) { return this.items.keysView().max(comparator); } @Override public T min() { return this.items.keysView().min(); } @Override public T max() { return this.items.keysView().max(); } @Override public > T minBy(Function function) { return this.items.keysView().minBy(function); } @Override public > T maxBy(Function function) { return this.items.keysView().maxBy(function); } @Override public long sumOfInt(final IntFunction function) { final long[] sum = {0L}; this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { int intValue = function.intValueOf(each); sum[0] += (long) intValue * (long) occurrences; } }); return sum[0]; } @Override public double sumOfFloat(final FloatFunction function) { final double[] sum = {0.0}; this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { float floatValue = function.floatValueOf(each); sum[0] += floatValue * (double) occurrences; } }); return sum[0]; } @Override public long sumOfLong(final LongFunction function) { final long[] sum = {0L}; this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { long longValue = function.longValueOf(each); sum[0] += longValue * (long) occurrences; } }); return sum[0]; } @Override public double sumOfDouble(final DoubleFunction function) { final double[] sum = {0.0}; this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { double doubleValue = function.doubleValueOf(each); sum[0] += doubleValue * (double) occurrences; } }); return sum[0]; } @Override public > R groupBy( Function function, R target) { this.forEach(MultimapPutProcedure.on(target, function)); return target; } @Override public > R groupByEach( Function> function, R target) { this.forEach(MultimapEachPutProcedure.on(target, function)); return target; } public Comparator comparator() { return this.items.comparator(); } public TreeBag with(T... elements) { this.addAll(Arrays.asList(elements)); return this; } public TreeBag with(T element1, T element2) { this.add(element1); this.add(element2); return this; } @Override public boolean add(T item) { Counter counter = this.items.getIfAbsentPut(item, NEW_COUNTER_BLOCK); counter.increment(); this.size++; return true; } public TreeBag with(T element1, T element2, T element3) { this.add(element1); this.add(element2); this.add(element3); return this; } private class InternalIterator implements Iterator { private int position; private boolean isCurrentKeySet; private int currentKeyPosition; private int currentKeyOccurrences; private Iterator> keyValueIterator = TreeBag.this.items.keyValuesView().iterator(); private Pair currentKeyValue; public boolean hasNext() { return this.position != TreeBag.this.size; } public T next() { if (!this.hasNext()) { throw new NoSuchElementException(); } this.isCurrentKeySet = true; if (this.currentKeyPosition < this.currentKeyOccurrences) { this.currentKeyPosition++; this.position++; return this.currentKeyValue.getOne(); } this.currentKeyValue = this.keyValueIterator.next(); this.currentKeyPosition = 1; this.currentKeyOccurrences = this.currentKeyValue.getTwo().getCount(); this.position++; return this.currentKeyValue.getOne(); } public void remove() { if (!this.isCurrentKeySet) { throw new IllegalStateException(); } this.isCurrentKeySet = false; this.position--; TreeBag.this.remove(this.currentKeyValue.getOne()); this.keyValueIterator = TreeBag.this.items.keyValuesView().iterator(); this.currentKeyOccurrences--; this.currentKeyPosition--; } } } UnmodifiableSortedBag.java000066400000000000000000000274111234315411400365240ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/bag/sorted/mutable/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.bag.sorted.mutable; import java.io.Serializable; import java.util.Collection; import java.util.Comparator; import com.gs.collections.api.bag.sorted.ImmutableSortedBag; import com.gs.collections.api.bag.sorted.MutableSortedBag; import com.gs.collections.api.bag.sorted.SortedBag; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.predicate.primitive.IntPredicate; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.list.primitive.MutableBooleanList; import com.gs.collections.api.list.primitive.MutableByteList; import com.gs.collections.api.list.primitive.MutableCharList; import com.gs.collections.api.list.primitive.MutableDoubleList; import com.gs.collections.api.list.primitive.MutableFloatList; import com.gs.collections.api.list.primitive.MutableIntList; import com.gs.collections.api.list.primitive.MutableLongList; import com.gs.collections.api.list.primitive.MutableShortList; import com.gs.collections.api.map.sorted.MutableSortedMap; import com.gs.collections.api.multimap.sortedbag.MutableSortedBagMultimap; import com.gs.collections.api.partition.bag.sorted.PartitionMutableSortedBag; import com.gs.collections.api.set.sorted.MutableSortedSet; import com.gs.collections.api.stack.MutableStack; import com.gs.collections.api.tuple.Pair; import com.gs.collections.impl.collection.mutable.AbstractUnmodifiableMutableCollection; import com.gs.collections.impl.collection.mutable.UnmodifiableCollectionSerializationProxy; /** * An unmodifiable view of a SortedBag. * * @see MutableSortedBag#asUnmodifiable() * @since 4.2 */ public class UnmodifiableSortedBag extends AbstractUnmodifiableMutableCollection implements MutableSortedBag, Serializable { UnmodifiableSortedBag(MutableSortedBag sortedBag) { super(sortedBag); } /** * This method will take a MutableSortedBag and wrap it directly in a UnmodifiableSortedBag. */ public static > UnmodifiableSortedBag of(S bag) { if (bag == null) { throw new IllegalArgumentException("cannot create an UnmodifiableSortedBag for null"); } return new UnmodifiableSortedBag(bag); } protected MutableSortedBag getSortedBag() { return (MutableSortedBag) this.getMutableCollection(); } @Override public MutableSortedBag asUnmodifiable() { return this; } @Override public MutableSortedBag asSynchronized() { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".asSynchronized() not implemented yet"); } @Override public ImmutableSortedBag toImmutable() { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".toImmutable() not implemented yet"); } @Override public UnmodifiableSortedBag clone() { return this; } @Override public boolean equals(Object obj) { return this.getSortedBag().equals(obj); } @Override public int hashCode() { return this.getSortedBag().hashCode(); } @Override public MutableSortedBag newEmpty() { return this.getSortedBag().newEmpty(); } public void addOccurrences(T item, int occurrences) { throw new UnsupportedOperationException("Cannot call addOccurrences() on " + this.getClass().getSimpleName()); } public boolean removeOccurrences(Object item, int occurrences) { throw new UnsupportedOperationException("Cannot call removeOccurences() on " + this.getClass().getSimpleName()); } @Override public MutableSortedBag select(Predicate predicate) { return this.getSortedBag().select(predicate); } @Override public

MutableSortedBag selectWith(Predicate2 predicate, P parameter) { return this.getSortedBag().selectWith(predicate, parameter); } @Override public MutableSortedBag reject(Predicate predicate) { return this.getSortedBag().reject(predicate); } @Override public

MutableSortedBag rejectWith(Predicate2 predicate, P parameter) { return this.getSortedBag().rejectWith(predicate, parameter); } @Override public PartitionMutableSortedBag partition(Predicate predicate) { return this.getSortedBag().partition(predicate); } @Override public

PartitionMutableSortedBag partitionWith(Predicate2 predicate, P parameter) { return this.getSortedBag().partitionWith(predicate, parameter); } public PartitionMutableSortedBag partitionWhile(Predicate predicate) { return this.getSortedBag().partition(predicate); } public int sizeDistinct() { return this.getSortedBag().sizeDistinct(); } public int occurrencesOf(Object item) { return this.getSortedBag().occurrencesOf(item); } public void forEachWithOccurrences(ObjectIntProcedure procedure) { this.getSortedBag().forEachWithOccurrences(procedure); } public MutableSortedMap toMapOfItemToCount() { return this.getSortedBag().toMapOfItemToCount(); } public String toStringOfItemToCount() { return this.getSortedBag().toStringOfItemToCount(); } public MutableSortedBag selectByOccurrences(IntPredicate predicate) { return this.getSortedBag().selectByOccurrences(predicate); } @Override public MutableSortedBag selectInstancesOf(Class clazz) { return this.getSortedBag().selectInstancesOf(clazz); } @Override public MutableList collect(Function function) { return this.getSortedBag().collect(function); } @Override public MutableBooleanList collectBoolean(BooleanFunction booleanFunction) { return this.getSortedBag().collectBoolean(booleanFunction); } @Override public MutableByteList collectByte(ByteFunction byteFunction) { return this.getSortedBag().collectByte(byteFunction); } @Override public MutableCharList collectChar(CharFunction charFunction) { return this.getSortedBag().collectChar(charFunction); } @Override public MutableDoubleList collectDouble(DoubleFunction doubleFunction) { return this.getSortedBag().collectDouble(doubleFunction); } @Override public MutableFloatList collectFloat(FloatFunction floatFunction) { return this.getSortedBag().collectFloat(floatFunction); } @Override public MutableIntList collectInt(IntFunction intFunction) { return this.getSortedBag().collectInt(intFunction); } @Override public MutableLongList collectLong(LongFunction longFunction) { return this.getSortedBag().collectLong(longFunction); } @Override public MutableShortList collectShort(ShortFunction shortFunction) { return this.getSortedBag().collectShort(shortFunction); } @Override public MutableList flatCollect(Function> function) { return this.getSortedBag().flatCollect(function); } public MutableSortedSet distinct() { return this.getSortedBag().distinct(); } public MutableStack toStack() { return this.getSortedBag().toStack(); } public MutableSortedBag takeWhile(Predicate predicate) { return this.getSortedBag().takeWhile(predicate); } public MutableSortedBag dropWhile(Predicate predicate) { return this.getSortedBag().dropWhile(predicate); } @Override public MutableList collectWith(Function2 function, P parameter) { return this.getSortedBag().collectWith(function, parameter); } @Override public MutableList collectIf( Predicate predicate, Function function) { return this.getSortedBag().collectIf(predicate, function); } @Override public MutableSortedBagMultimap groupBy(Function function) { return this.getSortedBag().groupBy(function); } @Override public MutableSortedBagMultimap groupByEach(Function> function) { return this.getSortedBag().groupByEach(function); } @Override public MutableList> zip(Iterable that) { return this.getSortedBag().zip(that); } @Override public >> R zip(Iterable that, R target) { return this.getSortedBag().zip(that, target); } @Override public MutableSortedSet> zipWithIndex() { return this.getSortedBag().zipWithIndex(); } @Override public >> R zipWithIndex(R target) { return this.getSortedBag().zipWithIndex(target); } public Comparator comparator() { return this.getSortedBag().comparator(); } @Override public MutableSortedBag with(T element) { throw new UnsupportedOperationException("Cannot call with() on " + this.getClass().getSimpleName()); } @Override public MutableSortedBag without(T element) { throw new UnsupportedOperationException("Cannot call without() on " + this.getClass().getSimpleName()); } @Override public MutableSortedBag withAll(Iterable elements) { throw new UnsupportedOperationException("Cannot call withAll() on " + this.getClass().getSimpleName()); } @Override public MutableSortedBag withoutAll(Iterable elements) { throw new UnsupportedOperationException("Cannot call withoutAll() on " + this.getClass().getSimpleName()); } public int compareTo(SortedBag o) { return this.getSortedBag().compareTo(o); } protected Object writeReplace() { return new UnmodifiableCollectionSerializationProxy(this.getSortedBag()); } } package-info.java000066400000000000000000000022241234315411400346520ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/bag/sorted/mutable/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains implementations of {@link com.gs.collections.api.bag.sorted.MutableSortedBag}. *

* *

*

* This package contains 2 sorted mutable bag implementation: *

    *
  • * {@link com.gs.collections.impl.bag.sorted.mutable.TreeBag} - a sorted bag backed by Tree data structure.. *
  • *
  • * {@link com.gs.collections.impl.bag.sorted.mutable.UnmodifiableSortedBag} - an unmodifiable view of a SortedBag. *
  • *
*

*/ package com.gs.collections.impl.bag.sorted.mutable; gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/bimap/000077500000000000000000000000001234315411400271505ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/bimap/mutable/000077500000000000000000000000001234315411400306015ustar00rootroot00000000000000AbstractMutableBiMap.java000066400000000000000000001356331234315411400353660ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/bimap/mutable/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.bimap.mutable; import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; import java.lang.reflect.Array; import java.util.Collection; import java.util.Comparator; import java.util.Iterator; import java.util.Map; import java.util.Set; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.RichIterable; import com.gs.collections.api.bag.MutableBag; import com.gs.collections.api.bimap.ImmutableBiMap; import com.gs.collections.api.bimap.MutableBiMap; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.DoubleObjectToDoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.FloatObjectToFloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.IntObjectToIntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.LongObjectToLongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.collection.MutableCollection; import com.gs.collections.api.collection.primitive.MutableBooleanCollection; import com.gs.collections.api.collection.primitive.MutableByteCollection; import com.gs.collections.api.collection.primitive.MutableCharCollection; import com.gs.collections.api.collection.primitive.MutableDoubleCollection; import com.gs.collections.api.collection.primitive.MutableFloatCollection; import com.gs.collections.api.collection.primitive.MutableIntCollection; import com.gs.collections.api.collection.primitive.MutableLongCollection; import com.gs.collections.api.collection.primitive.MutableShortCollection; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.map.MutableMap; import com.gs.collections.api.map.sorted.MutableSortedMap; import com.gs.collections.api.multimap.MutableMultimap; import com.gs.collections.api.multimap.set.MutableSetMultimap; import com.gs.collections.api.partition.PartitionMutableCollection; import com.gs.collections.api.set.MutableSet; import com.gs.collections.api.set.sorted.MutableSortedSet; import com.gs.collections.api.tuple.Pair; import com.gs.collections.impl.block.procedure.MapCollectProcedure; import com.gs.collections.impl.list.fixed.ArrayAdapter; import com.gs.collections.impl.map.mutable.UnifiedMap; import com.gs.collections.impl.utility.Iterate; import com.gs.collections.impl.utility.MapIterate; abstract class AbstractMutableBiMap implements MutableBiMap { private UnifiedMap delegate; private AbstractMutableBiMap inverse; private AbstractMutableBiMap(Map delegate, AbstractMutableBiMap valuesToKeys) { this.delegate = UnifiedMap.newMap(delegate); this.inverse = valuesToKeys; } AbstractMutableBiMap(Map map) { this.delegate = UnifiedMap.newMap(); this.inverse = new Inverse(UnifiedMap.newMap(), this); this.putAll(map); } AbstractMutableBiMap(Map delegate, Map inverse) { this.checkNull(delegate, inverse); this.checkSame(delegate, inverse); this.delegate = UnifiedMap.newMap(delegate); this.inverse = new Inverse(inverse, this); } private void checkNull(Map delegate, Map inverse) { if (delegate == null || inverse == null) { throw new IllegalArgumentException("The delegate maps cannot be null."); } } private void checkSame(Map keysToValues, Map valuesToKeys) { if (keysToValues == valuesToKeys) { throw new IllegalArgumentException("The delegate maps cannot be same."); } } private static boolean nullSafeEquals(Object value, Object other) { if (value == null) { if (other == null) { return true; } } else if (other == value || value.equals(other)) { return true; } return false; } public MutableSetMultimap flip() { // TODO: We could optimize this since we know the values are unique return MapIterate.flip(this); } @Override public MutableBiMap clone() { return new HashBiMap(this); } @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof Map)) { return false; } Map map = (Map) obj; return this.delegate.equals(map); } @Override public int hashCode() { return this.delegate.hashCode(); } @Override public String toString() { return this.delegate.toString(); } public V put(K key, V value) { if (this.inverse.delegate.containsKey(value)) { if (AbstractMutableBiMap.nullSafeEquals(key, this.inverse.delegate.get(value))) { return value; } throw new IllegalArgumentException("Value " + value + " already exists in map!"); } boolean containsKey = this.delegate.containsKey(key); V put = this.delegate.put(key, value); if (containsKey) { this.inverse.delegate.removeKey(put); } this.inverse.delegate.put(value, key); return put; } public V forcePut(K key, V value) { boolean containsValue = this.inverse.delegate.containsKey(value); if (containsValue) { if (AbstractMutableBiMap.nullSafeEquals(key, this.inverse.delegate.get(value))) { return value; } } boolean containsKey = this.delegate.containsKey(key); V put = this.delegate.put(key, value); if (containsKey) { this.inverse.delegate.removeKey(put); } K oldKey = this.inverse.delegate.put(value, key); if (containsValue) { this.delegate.removeKey(oldKey); } return put; } public V remove(Object key) { if (!this.delegate.containsKey(key)) { return null; } V oldValue = this.delegate.remove(key); this.inverse.delegate.remove(oldValue); return oldValue; } public void putAll(Map map) { Set> entries = map.entrySet(); for (Map.Entry entry : entries) { this.put(entry.getKey(), entry.getValue()); } } public void clear() { this.delegate.clear(); this.inverse.delegate.clear(); } public Set keySet() { return new KeySet(); } public Collection values() { return new ValuesCollection(); } public Set> entrySet() { return new EntrySet(); } public boolean containsKey(Object key) { return this.delegate.containsKey(key); } public int size() { return this.delegate.size(); } public boolean isEmpty() { return this.delegate.isEmpty(); } public boolean notEmpty() { return this.delegate.notEmpty(); } public V getFirst() { return this.delegate.getFirst(); } public V getLast() { return this.delegate.getLast(); } public boolean contains(Object object) { return this.inverse.delegate.containsKey(object); } public boolean containsAllIterable(Iterable source) { return this.inverse.delegate.keysView().containsAllIterable(source); } public boolean containsAll(Collection source) { return this.inverse.delegate.keysView().containsAll(source); } public boolean containsAllArguments(Object... elements) { return this.inverse.delegate.keysView().containsAllArguments(elements); } public > R select(Predicate predicate, R target) { return this.delegate.select(predicate, target); } public

RichIterable selectWith(Predicate2 predicate, P parameter) { return this.delegate.selectWith(predicate, parameter); } public

RichIterable rejectWith(Predicate2 predicate, P parameter) { return this.delegate.rejectWith(predicate, parameter); } public MutableCollection collect(Function function) { return this.delegate.collect(function); } public MutableBooleanCollection collectBoolean(BooleanFunction booleanFunction) { return this.delegate.collectBoolean(booleanFunction); } public R collectBoolean(BooleanFunction booleanFunction, R target) { return this.delegate.collectBoolean(booleanFunction, target); } public MutableByteCollection collectByte(ByteFunction byteFunction) { return this.delegate.collectByte(byteFunction); } public R collectByte(ByteFunction byteFunction, R target) { return this.delegate.collectByte(byteFunction, target); } public MutableCharCollection collectChar(CharFunction charFunction) { return this.delegate.collectChar(charFunction); } public R collectChar(CharFunction charFunction, R target) { return this.delegate.collectChar(charFunction, target); } public > R selectWith(Predicate2 predicate, P parameter, R targetCollection) { return this.delegate.selectWith(predicate, parameter, targetCollection); } public MutableDoubleCollection collectDouble(DoubleFunction doubleFunction) { return this.delegate.collectDouble(doubleFunction); } public R collectDouble(DoubleFunction doubleFunction, R target) { return this.delegate.collectDouble(doubleFunction, target); } public MutableFloatCollection collectFloat(FloatFunction floatFunction) { return this.delegate.collectFloat(floatFunction); } public R collectFloat(FloatFunction floatFunction, R target) { return this.delegate.collectFloat(floatFunction, target); } public MutableIntCollection collectInt(IntFunction intFunction) { return this.delegate.collectInt(intFunction); } public R collectInt(IntFunction intFunction, R target) { return this.delegate.collectInt(intFunction, target); } public MutableLongCollection collectLong(LongFunction longFunction) { return this.delegate.collectLong(longFunction); } public R collectLong(LongFunction longFunction, R target) { return this.delegate.collectLong(longFunction, target); } public MutableShortCollection collectShort(ShortFunction shortFunction) { return this.delegate.collectShort(shortFunction); } public R collectShort(ShortFunction shortFunction, R target) { return this.delegate.collectShort(shortFunction, target); } public MutableCollection collectIf(Predicate predicate, Function function) { return this.delegate.collectIf(predicate, function); } public MutableCollection reject(Predicate predicate) { return this.delegate.reject(predicate); } public MutableCollection select(Predicate predicate) { return this.delegate.select(predicate); } public PartitionMutableCollection partition(Predicate predicate) { return this.delegate.partition(predicate); } public

PartitionMutableCollection partitionWith(Predicate2 predicate, P parameter) { return this.delegate.partitionWith(predicate, parameter); } public MutableCollection selectInstancesOf(Class clazz) { return this.delegate.selectInstancesOf(clazz); } public MutableCollection> zipWithIndex() { return this.delegate.zipWithIndex(); } public > R reject(Predicate predicate, R target) { return this.delegate.reject(predicate, target); } public > R rejectWith(Predicate2 predicate, P parameter, R targetCollection) { return this.delegate.rejectWith(predicate, parameter, targetCollection); } public MutableMap aggregateBy(Function groupBy, Function0 zeroValueFactory, Function2 nonMutatingAggregator) { return this.delegate.aggregateBy(groupBy, zeroValueFactory, nonMutatingAggregator); } public > R collect(Function function, R target) { return this.delegate.collect(function, target); } public MutableList collectWith(Function2 function, P parameter) { return this.delegate.collectWith(function, parameter); } public > R collectWith(Function2 function, P parameter, R targetCollection) { return this.delegate.collectWith(function, parameter, targetCollection); } public > R collectIf(Predicate predicate, Function function, R target) { return this.delegate.collectIf(predicate, function, target); } public MutableCollection flatCollect(Function> function) { return this.delegate.flatCollect(function); } public > R flatCollect(Function> function, R target) { return this.delegate.flatCollect(function, target); } public V detect(Predicate predicate) { return this.delegate.detect(predicate); } public

V detectWith(Predicate2 predicate, P parameter) { return this.delegate.detectWith(predicate, parameter); } public V detectIfNone(Predicate predicate, Function0 function) { return this.delegate.detectIfNone(predicate, function); } public

V detectWithIfNone(Predicate2 predicate, P parameter, Function0 function) { return this.delegate.detectWithIfNone(predicate, parameter, function); } public int count(Predicate predicate) { return this.delegate.count(predicate); } public

int countWith(Predicate2 predicate, P parameter) { return this.delegate.countWith(predicate, parameter); } public boolean anySatisfy(Predicate predicate) { return this.delegate.anySatisfy(predicate); } public

boolean anySatisfyWith(Predicate2 predicate, P parameter) { return this.delegate.anySatisfyWith(predicate, parameter); } public boolean allSatisfy(Predicate predicate) { return this.delegate.allSatisfy(predicate); } public

boolean allSatisfyWith(Predicate2 predicate, P parameter) { return this.delegate.allSatisfyWith(predicate, parameter); } public boolean noneSatisfy(Predicate predicate) { return this.delegate.noneSatisfy(predicate); } public

boolean noneSatisfyWith(Predicate2 predicate, P parameter) { return this.delegate.noneSatisfyWith(predicate, parameter); } public IV injectInto(IV injectedValue, Function2 function) { return this.delegate.injectInto(injectedValue, function); } public int injectInto(int injectedValue, IntObjectToIntFunction function) { return this.delegate.injectInto(injectedValue, function); } public long injectInto(long injectedValue, LongObjectToLongFunction function) { return this.delegate.injectInto(injectedValue, function); } public float injectInto(float injectedValue, FloatObjectToFloatFunction function) { return this.delegate.injectInto(injectedValue, function); } public double injectInto(double injectedValue, DoubleObjectToDoubleFunction function) { return this.delegate.injectInto(injectedValue, function); } public MutableList toList() { return this.delegate.toList(); } public MutableList toSortedList() { return this.delegate.toSortedList(); } public MutableList toSortedList(Comparator comparator) { return this.delegate.toSortedList(comparator); } public > MutableList toSortedListBy(Function function) { return this.delegate.toSortedListBy(function); } public MutableSet toSet() { return this.delegate.toSet(); } public MutableSortedSet toSortedSet() { return this.delegate.toSortedSet(); } public MutableSortedSet toSortedSet(Comparator comparator) { return this.delegate.toSortedSet(comparator); } public > MutableSortedSet toSortedSetBy(Function function) { return this.delegate.toSortedSetBy(function); } public MutableBag toBag() { return this.delegate.toBag(); } public MutableMap toMap(Function keyFunction, Function valueFunction) { return this.delegate.toMap(keyFunction, valueFunction); } public MutableSortedMap toSortedMap(Function keyFunction, Function valueFunction) { return this.delegate.toSortedMap(keyFunction, valueFunction); } public MutableSortedMap toSortedMap(Comparator comparator, Function keyFunction, Function valueFunction) { return this.delegate.toSortedMap(comparator, keyFunction, valueFunction); } public LazyIterable asLazy() { return this.delegate.asLazy(); } public Object[] toArray() { return this.delegate.toArray(); } public T[] toArray(T[] a) { return this.delegate.toArray(a); } public V min(Comparator comparator) { return this.delegate.min(comparator); } public V max(Comparator comparator) { return this.delegate.max(comparator); } public V min() { return this.delegate.min(); } public V max() { return this.delegate.max(); } public > V minBy(Function function) { return this.delegate.minBy(function); } public > V maxBy(Function function) { return this.delegate.maxBy(function); } public long sumOfInt(IntFunction function) { return this.delegate.sumOfInt(function); } public double sumOfFloat(FloatFunction function) { return this.delegate.sumOfFloat(function); } public long sumOfLong(LongFunction function) { return this.delegate.sumOfLong(function); } public double sumOfDouble(DoubleFunction function) { return this.delegate.sumOfDouble(function); } public String makeString() { return this.delegate.makeString(); } public String makeString(String separator) { return this.delegate.makeString(separator); } public String makeString(String start, String separator, String end) { return this.delegate.makeString(start, separator, end); } public void appendString(Appendable appendable) { this.delegate.appendString(appendable); } public void appendString(Appendable appendable, String separator) { this.delegate.appendString(appendable, separator); } public void appendString(Appendable appendable, String start, String separator, String end) { this.delegate.appendString(appendable, start, separator, end); } public MutableMultimap groupBy(Function function) { return this.delegate.groupBy(function); } public > R groupBy(Function function, R target) { return this.delegate.groupBy(function, target); } public MutableMultimap groupByEach(Function> function) { return this.delegate.groupByEach(function); } public > R groupByEach(Function> function, R target) { return this.delegate.groupByEach(function, target); } public MutableMap groupByUniqueKey(Function function) { return this.delegate.groupByUniqueKey(function); } public MutableCollection> zip(Iterable that) { return this.delegate.zip(that); } public >> R zip(Iterable that, R target) { return this.delegate.zip(that, target); } public >> R zipWithIndex(R target) { return this.delegate.zipWithIndex(target); } public RichIterable> chunk(int size) { return this.delegate.chunk(size); } public MutableMap aggregateInPlaceBy(Function groupBy, Function0 zeroValueFactory, Procedure2 mutatingAggregator) { return this.delegate.aggregateInPlaceBy(groupBy, zeroValueFactory, mutatingAggregator); } public boolean containsValue(Object value) { return this.inverse.delegate.containsKey(value); } public V get(Object key) { return this.delegate.get(key); } public HashBiMap select(final Predicate2 predicate) { final HashBiMap result = HashBiMap.newMap(); this.delegate.forEachKeyValue(new Procedure2() { public void value(K key, V value) { if (predicate.accept(key, value)) { result.put(key, value); } } }); return result; } public HashBiMap collectValues(final Function2 function) { final HashBiMap result = HashBiMap.newMap(); this.delegate.forEachKeyValue(new Procedure2() { public void value(K key, V value) { result.put(key, function.value(key, value)); } }); return result; } public HashBiMap collect(final Function2> function) { final HashBiMap result = HashBiMap.newMap(); this.delegate.forEachKeyValue(new Procedure2() { public void value(K key, V value) { Pair pair = function.value(key, value); result.put(pair.getOne(), pair.getTwo()); } }); return result; } public HashBiMap reject(final Predicate2 predicate) { final HashBiMap result = HashBiMap.newMap(); this.delegate.forEachKeyValue(new Procedure2() { public void value(K key, V value) { if (!predicate.accept(key, value)) { result.put(key, value); } } }); return result; } public void forEachValue(Procedure procedure) { this.inverse.delegate.forEachKey(procedure); } public void forEachKey(Procedure procedure) { this.delegate.forEachKey(procedure); } public void forEachKeyValue(Procedure2 procedure) { this.delegate.forEachKeyValue(procedure); } public MutableBiMap flipUniqueValues() { return new HashBiMap(this.inverse()); } public V getIfAbsent(K key, Function0 function) { return this.delegate.getIfAbsent(key, function); } public V getIfAbsentValue(K key, V value) { return this.delegate.getIfAbsentValue(key, value); } public

V getIfAbsentWith(K key, Function function, P parameter) { return this.delegate.getIfAbsentWith(key, function, parameter); } public A ifPresentApply(K key, Function function) { return this.delegate.ifPresentApply(key, function); } public RichIterable keysView() { return this.delegate.keysView(); } public RichIterable valuesView() { return this.delegate.valuesView(); } public RichIterable> keyValuesView() { return this.delegate.keyValuesView(); } public Pair detect(Predicate2 predicate) { return this.delegate.detect(predicate); } public ImmutableBiMap toImmutable() { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".toImmutable() not implemented yet"); } public MutableBiMap asSynchronized() { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".asSynchronized() not implemented yet"); } public MutableBiMap asUnmodifiable() { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".asUnmodifiable() not implemented yet"); } public MutableMap collectKeysAndValues(Iterable iterable, Function keyFunction, Function valueFunction) { Iterate.forEach(iterable, new MapCollectProcedure(this, keyFunction, valueFunction)); return this; } public V removeKey(K key) { return this.remove(key); } public V getIfAbsentPut(K key, Function0 function) { V value = this.delegate.get(key); if (value != null || this.delegate.containsKey(key)) { return value; } V newValue = function.value(); this.put(key, newValue); return newValue; } public V getIfAbsentPut(K key, V value) { V oldValue = this.delegate.get(key); if (oldValue != null || this.delegate.containsKey(key)) { return oldValue; } this.put(key, value); return value; } public V getIfAbsentPutWithKey(K key, Function function) { V value = this.delegate.get(key); if (value != null || this.delegate.containsKey(key)) { return value; } V newValue = function.valueOf(key); this.put(key, newValue); return newValue; } public

V getIfAbsentPutWith(K key, Function function, P parameter) { V value = this.delegate.get(key); if (value != null || this.delegate.containsKey(key)) { return value; } V newValue = function.valueOf(parameter); this.put(key, newValue); return newValue; } public V add(Pair keyValuePair) { return this.put(keyValuePair.getOne(), keyValuePair.getTwo()); } public MutableBiMap withKeyValue(K key, V value) { this.put(key, value); return this; } public MutableBiMap withAllKeyValues(Iterable> keyValues) { for (Pair keyVal : keyValues) { this.put(keyVal.getOne(), keyVal.getTwo()); } return this; } public MutableBiMap withAllKeyValueArguments(Pair... keyValuePairs) { return this.withAllKeyValues(ArrayAdapter.adapt(keyValuePairs)); } public MutableBiMap withoutKey(K key) { this.removeKey(key); return this; } public MutableMap withoutAllKeys(Iterable keys) { for (K key : keys) { this.removeKey(key); } return this; } public HashBiMap newEmpty() { return new HashBiMap(); } public V updateValue(K key, Function0 factory, Function function) { if (this.delegate.containsKey(key)) { V newValue = function.valueOf(this.delegate.get(key)); this.put(key, newValue); return newValue; } V newValue = function.valueOf(factory.value()); this.put(key, newValue); return newValue; } public

V updateValueWith(K key, Function0 factory, Function2 function, P parameter) { if (this.delegate.containsKey(key)) { V newValue = function.value(this.delegate.get(key), parameter); this.put(key, newValue); return newValue; } V newValue = function.value(factory.value(), parameter); this.put(key, newValue); return newValue; } public MutableBiMap inverse() { return this.inverse; } public void forEach(Procedure procedure) { this.inverse.delegate.forEachKey(procedure); } public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { this.delegate.forEachWithIndex(objectIntProcedure); } public

void forEachWith(Procedure2 procedure, P parameter) { this.delegate.forEachWith(procedure, parameter); } public Iterator iterator() { return new InternalIterator(); } public void writeExternal(ObjectOutput out) throws IOException { this.delegate.writeExternal(out); } public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { this.delegate = UnifiedMap.newMap(); this.delegate.readExternal(in); final UnifiedMap inverseDelegate = UnifiedMap.newMap(); this.delegate.forEachKeyValue(new Procedure2() { public void value(K key, V value) { inverseDelegate.put(value, key); } }); this.inverse = new Inverse(inverseDelegate, this); } private class InternalIterator implements Iterator { private final Iterator iterator = AbstractMutableBiMap.this.delegate.iterator(); private V currentValue; public boolean hasNext() { return this.iterator.hasNext(); } public V next() { V next = this.iterator.next(); this.currentValue = next; return next; } public void remove() { this.iterator.remove(); AbstractMutableBiMap.this.inverse.delegate.remove(this.currentValue); } } private class KeySet implements Set { @Override public boolean equals(Object obj) { return AbstractMutableBiMap.this.delegate.keySet().equals(obj); } @Override public int hashCode() { return AbstractMutableBiMap.this.delegate.keySet().hashCode(); } public int size() { return AbstractMutableBiMap.this.size(); } public boolean isEmpty() { return AbstractMutableBiMap.this.isEmpty(); } public boolean contains(Object key) { return AbstractMutableBiMap.this.delegate.containsKey(key); } public Object[] toArray() { return AbstractMutableBiMap.this.delegate.keySet().toArray(); } public T[] toArray(T[] a) { return AbstractMutableBiMap.this.delegate.keySet().toArray(a); } public boolean add(K key) { throw new UnsupportedOperationException("Cannot call add() on " + this.getClass().getSimpleName()); } public boolean remove(Object key) { int oldSize = AbstractMutableBiMap.this.size(); AbstractMutableBiMap.this.remove(key); return AbstractMutableBiMap.this.size() != oldSize; } public boolean containsAll(Collection source) { for (Object key : source) { if (!AbstractMutableBiMap.this.delegate.containsKey(key)) { return false; } } return true; } public boolean addAll(Collection source) { throw new UnsupportedOperationException("Cannot call addAll() on " + this.getClass().getSimpleName()); } public boolean retainAll(Collection collection) { int oldSize = AbstractMutableBiMap.this.size(); Iterator iterator = this.iterator(); while (iterator.hasNext()) { K next = iterator.next(); if (!collection.contains(next)) { this.remove(next); } } return oldSize != AbstractMutableBiMap.this.size(); } public boolean removeAll(Collection collection) { int oldSize = AbstractMutableBiMap.this.size(); for (Object object : collection) { AbstractMutableBiMap.this.remove(object); } return oldSize != AbstractMutableBiMap.this.size(); } public void clear() { AbstractMutableBiMap.this.clear(); } public Iterator iterator() { return AbstractMutableBiMap.this.inverse().iterator(); } @Override public String toString() { return Iterate.makeString(this, "[", ", ", "]"); } } private class ValuesCollection implements Collection { public int size() { return AbstractMutableBiMap.this.size(); } public boolean isEmpty() { return AbstractMutableBiMap.this.isEmpty(); } public boolean contains(Object key) { return AbstractMutableBiMap.this.inverse.delegate.containsKey(key); } public Object[] toArray() { return AbstractMutableBiMap.this.delegate.values().toArray(); } public T[] toArray(T[] a) { return AbstractMutableBiMap.this.delegate.values().toArray(a); } public boolean add(V v) { throw new UnsupportedOperationException("Cannot call add() on " + this.getClass().getSimpleName()); } public boolean remove(Object value) { int oldSize = AbstractMutableBiMap.this.size(); AbstractMutableBiMap.this.inverse().remove(value); return oldSize != AbstractMutableBiMap.this.size(); } public boolean containsAll(Collection collection) { for (Object key : collection) { if (!AbstractMutableBiMap.this.inverse.delegate.containsKey(key)) { return false; } } return true; } public boolean addAll(Collection collection) { throw new UnsupportedOperationException("Cannot call addAll() on " + this.getClass().getSimpleName()); } public boolean removeAll(Collection collection) { int oldSize = AbstractMutableBiMap.this.size(); for (Object object : collection) { this.remove(object); } return oldSize != AbstractMutableBiMap.this.size(); } public boolean retainAll(Collection collection) { int oldSize = AbstractMutableBiMap.this.size(); Iterator iterator = this.iterator(); while (iterator.hasNext()) { V next = iterator.next(); if (!collection.contains(next)) { this.remove(next); } } return oldSize != AbstractMutableBiMap.this.size(); } public void clear() { AbstractMutableBiMap.this.clear(); } public Iterator iterator() { return AbstractMutableBiMap.this.iterator(); } @Override public String toString() { return Iterate.makeString(this, "[", ", ", "]"); } } private class EntrySet implements Set> { @Override public boolean equals(Object obj) { if (obj instanceof Set) { Set other = (Set) obj; if (other.size() == this.size()) { return this.containsAll(other); } } return false; } @Override public int hashCode() { return AbstractMutableBiMap.this.hashCode(); } public int size() { return AbstractMutableBiMap.this.size(); } public boolean isEmpty() { return AbstractMutableBiMap.this.isEmpty(); } public boolean contains(Object o) { if (!(o instanceof Map.Entry)) { return false; } Map.Entry entry = (Map.Entry) o; K key = entry.getKey(); V actualValue = AbstractMutableBiMap.this.get(key); if (actualValue != null) { return actualValue.equals(entry.getValue()); } return entry.getValue() == null && AbstractMutableBiMap.this.containsKey(key); } public Object[] toArray() { Object[] result = new Object[AbstractMutableBiMap.this.size()]; return this.copyEntries(result); } public T[] toArray(T[] result) { int size = AbstractMutableBiMap.this.size(); if (result.length < size) { result = (T[]) Array.newInstance(result.getClass().getComponentType(), size); } this.copyEntries(result); if (size < result.length) { result[size] = null; } return result; } public boolean add(Map.Entry entry) { throw new UnsupportedOperationException(); } public boolean remove(Object e) { if (!(e instanceof Map.Entry)) { return false; } Map.Entry entry = (Map.Entry) e; K key = (K) entry.getKey(); V value = (V) entry.getValue(); V actualValue = AbstractMutableBiMap.this.delegate.get(key); if (actualValue != null) { if (actualValue.equals(value)) { AbstractMutableBiMap.this.remove(key); return true; } return false; } if (value == null && AbstractMutableBiMap.this.delegate.containsKey(key)) { AbstractMutableBiMap.this.remove(key); return true; } return false; } public boolean containsAll(Collection collection) { for (Object obj : collection) { if (!this.contains(obj)) { return false; } } return true; } public boolean addAll(Collection> collection) { throw new UnsupportedOperationException("Cannot call addAll() on " + this.getClass().getSimpleName()); } public boolean retainAll(Collection collection) { int oldSize = AbstractMutableBiMap.this.size(); Iterator> iterator = this.iterator(); while (iterator.hasNext()) { Map.Entry next = iterator.next(); if (!collection.contains(next)) { iterator.remove(); } } return oldSize != AbstractMutableBiMap.this.size(); } public boolean removeAll(Collection collection) { boolean changed = false; for (Object obj : collection) { if (this.remove(obj)) { changed = true; } } return changed; } public void clear() { AbstractMutableBiMap.this.clear(); } public Iterator> iterator() { return new InternalEntrySetIterator(); } private Object[] copyEntries(Object[] result) { int count = 0; for (Pair pair : AbstractMutableBiMap.this.keyValuesView()) { result[count] = new InternalEntry(pair.getOne(), pair.getTwo()); count++; } return result; } private class InternalEntrySetIterator implements Iterator> { private final Iterator> iterator = AbstractMutableBiMap.this.delegate.entrySet().iterator(); private V currentValue; public boolean hasNext() { return this.iterator.hasNext(); } public Entry next() { Entry next = this.iterator.next(); Entry result = new InternalEntry(next.getKey(), next.getValue()); this.currentValue = result.getValue(); return result; } public void remove() { this.iterator.remove(); AbstractMutableBiMap.this.inverse.delegate.removeKey(this.currentValue); } } private final class InternalEntry implements Entry { private final K key; private V value; private InternalEntry(K key, V value) { this.key = key; this.value = value; } public K getKey() { return this.key; } public V getValue() { return this.value; } @Override public boolean equals(Object obj) { if (obj instanceof Entry) { Entry other = (Entry) obj; Object otherKey = other.getKey(); Object otherValue = other.getValue(); return AbstractMutableBiMap.nullSafeEquals(this.key, otherKey) && AbstractMutableBiMap.nullSafeEquals(this.value, otherValue); } return false; } @Override public int hashCode() { return (this.key == null ? 0 : this.key.hashCode()) ^ (this.value == null ? 0 : this.value.hashCode()); } @Override public String toString() { return this.key + "=" + this.value; } public V setValue(V value) { V result = AbstractMutableBiMap.this.put(this.key, value); this.value = value; return result; } } } private static class Inverse extends AbstractMutableBiMap implements Externalizable { private static final long serialVersionUID = 1L; public Inverse() { // Empty constructor for Externalizable class super(UnifiedMap.newMap(), UnifiedMap.newMap()); } Inverse(Map delegate, AbstractMutableBiMap inverse) { super(delegate, inverse); } } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/bimap/mutable/HashBiMap.java000066400000000000000000000062211234315411400332410ustar00rootroot00000000000000/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.bimap.mutable; import java.io.Externalizable; import java.util.Map; import com.gs.collections.api.bimap.MutableBiMap; import com.gs.collections.impl.map.mutable.UnifiedMap; /** * A {@link MutableBiMap} which uses two hash tables as its underlying data store. * * @since 4.2 */ public class HashBiMap extends AbstractMutableBiMap implements Externalizable { private static final long serialVersionUID = 1L; public HashBiMap() { super(UnifiedMap.newMap(), UnifiedMap.newMap()); } public HashBiMap(int initialSize) { super(UnifiedMap.newMap(initialSize), UnifiedMap.newMap(initialSize)); } public HashBiMap(Map map) { super(map); } HashBiMap(Map keysToValues, Map valuesToKeys) { super(keysToValues, valuesToKeys); } public static HashBiMap newMap() { return new HashBiMap(); } public static HashBiMap newWithKeysValues(K key, V value) { return new HashBiMap(1).withKeysValues(key, value); } public static HashBiMap newWithKeysValues(K key1, V value1, K key2, V value2) { return new HashBiMap(2).withKeysValues(key1, value1, key2, value2); } public static HashBiMap newWithKeysValues(K key1, V value1, K key2, V value2, K key3, V value3) { return new HashBiMap(3).withKeysValues(key1, value1, key2, value2, key3, value3); } public static HashBiMap newWithKeysValues(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4) { return new HashBiMap(4).withKeysValues(key1, value1, key2, value2, key3, value3, key4, value4); } public HashBiMap withKeysValues(K key, V value) { this.put(key, value); return this; } public HashBiMap withKeysValues(K key1, V value1, K key2, V value2) { this.put(key1, value1); this.put(key2, value2); return this; } public HashBiMap withKeysValues(K key1, V value1, K key2, V value2, K key3, V value3) { this.put(key1, value1); this.put(key2, value2); this.put(key3, value3); return this; } public HashBiMap withKeysValues(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4) { this.put(key1, value1); this.put(key2, value2); this.put(key3, value3); this.put(key4, value4); return this; } } package-info.java000066400000000000000000000020051234315411400337060ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/bimap/mutable/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains implementations of the {@link com.gs.collections.api.bimap.MutableBiMap} interface. *

* This package contains: *

*

*/ package com.gs.collections.impl.bimap.mutable; gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/000077500000000000000000000000001234315411400271525ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/comparator/000077500000000000000000000000001234315411400313215ustar00rootroot00000000000000FunctionComparator.java000066400000000000000000000031131234315411400357200ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/comparator/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.comparator; import java.util.Comparator; import com.gs.collections.api.block.SerializableComparator; import com.gs.collections.api.block.function.Function; /** * Simple {@link Comparator} that uses a {@link Function} * to select a value from the underlying object and compare it against a known value to determine ordering. */ public class FunctionComparator implements SerializableComparator { private static final long serialVersionUID = 1L; private final Function function; private final Comparator comparator; public FunctionComparator(Function function, Comparator comparator) { this.function = function; this.comparator = comparator; } public int compare(T o1, T o2) { V attrValue1 = this.function.valueOf(o1); V attrValue2 = this.function.valueOf(o2); return this.comparator.compare(attrValue1, attrValue2); } } package-info.java000066400000000000000000000020721234315411400344320ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/comparator/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains implementations of the {@link com.gs.collections.api.block.SerializableComparator} interface. *

* This package contains the following implementations: *

    *
  • * {@link com.gs.collections.impl.block.comparator.FunctionComparator} - a simple {@link java.util.Comparator} that uses a {@link com.gs.collections.api.block.function.Function}. *
  • *
*

*/ package com.gs.collections.impl.block.comparator; gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/comparator/primitive/000077500000000000000000000000001234315411400333315ustar00rootroot00000000000000package-info.java000066400000000000000000000014741234315411400364470ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/comparator/primitive/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains implementations of the {@link com.gs.collections.api.block.SerializableComparator} interface to compare primitive double, int and long. */ package com.gs.collections.impl.block.comparator.primitive; gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/factory/000077500000000000000000000000001234315411400306215ustar00rootroot00000000000000Comparators.java000066400000000000000000000353541234315411400337110ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/factory/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.factory; import java.util.Collection; import java.util.Comparator; import com.gs.collections.api.block.SerializableComparator; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.set.sorted.SortedSetIterable; import com.gs.collections.api.tuple.Pair; import com.gs.collections.impl.block.comparator.FunctionComparator; public final class Comparators { private static final SerializableComparator NATURAL_ORDER_COMPARATOR = new NaturalOrderComparator(); private static final SerializableComparator REVERSE_NATURAL_ORDER_COMPARATOR = new ReverseComparator(NATURAL_ORDER_COMPARATOR); private static final SerializableComparator POWER_SET_COMPARATOR = new PowerSetComparator(); private static final SerializableComparator> ASCENDING_COLLECTION_SIZE_COMPARATOR = new AscendingCollectionSizeComparator(); private static final SerializableComparator> DESCENDING_COLLECTION_SIZE_COMPARATOR = new DescendingCollectionSizeComparator(); private Comparators() { throw new AssertionError("Suppress default constructor for noninstantiability"); } /** * Uses the natural compareTo methods of the objects which will throw if there are any nulls. */ public static SerializableComparator naturalOrder() { return (SerializableComparator) NATURAL_ORDER_COMPARATOR; } /** * Uses the natural compareTo methods of the objects which will throw if there are any nulls. */ public static SerializableComparator reverseNaturalOrder() { return (SerializableComparator) REVERSE_NATURAL_ORDER_COMPARATOR; } /** * @param comparator original comparator whose order will be reversed * @return A comparator that reverses the order of any other Serializable Comparator. */ public static SerializableComparator reverse(Comparator comparator) { if (comparator == null) { throw new NullPointerException(); } return new ReverseComparator(comparator); } public static SerializableComparator safeNullsLow(Comparator notNullSafeComparator) { return new SafeNullsLowComparator(notNullSafeComparator); } public static SerializableComparator safeNullsHigh(Comparator notNullSafeComparator) { return new SafeNullsHighComparator(notNullSafeComparator); } public static SerializableComparator chain(Comparator... comparators) { if (comparators.length == 0) { throw new IllegalArgumentException("Nothing to chain"); } return new ChainedComparator(comparators); } public static > SerializableComparator fromFunctions( Function one) { return Comparators.byFunction(one); } public static , V2 extends Comparable> SerializableComparator fromFunctions( Function one, Function two) { return Comparators.chain( Comparators.byFunction(one), Comparators.byFunction(two)); } public static , V2 extends Comparable, V3 extends Comparable> SerializableComparator fromFunctions( Function one, Function two, Function three) { return Comparators.chain( Comparators.byFunction(one), Comparators.byFunction(two), Comparators.byFunction(three)); } public static SerializableComparator> powerSet() { return (SerializableComparator>) POWER_SET_COMPARATOR; } public static SerializableComparator> ascendingCollectionSizeComparator() { return ASCENDING_COLLECTION_SIZE_COMPARATOR; } public static SerializableComparator> descendingCollectionSizeComparator() { return DESCENDING_COLLECTION_SIZE_COMPARATOR; } /** * Creates a comparator for pairs by using an existing comparator that only compares the first element of the pair * * @param comparator original comparator that compares the first element of the pair * @return A comparator that compares pairs only by their first element */ public static SerializableComparator> byFirstOfPair(Comparator comparator) { return new ByFirstOfPairComparator(comparator); } /** * Creates a comparator for pairs by using an existing comparator that only compares the second element of the pair * * @param comparator original comparator that compares the second element of the pair * @return A comparator that compares pairs only by their second element */ public static SerializableComparator> bySecondOfPair(Comparator comparator) { return new BySecondOfPairComparator(comparator); } private static final class NaturalOrderComparator> implements SerializableComparator { private static final long serialVersionUID = 1L; public int compare(T o1, T o2) { if (o1 == null || o2 == null) { throw new NullPointerException(); } return o1.compareTo(o2); } } private static final class ReverseComparator implements SerializableComparator { private static final long serialVersionUID = 1L; private final Comparator comparator; private ReverseComparator(Comparator comparator) { this.comparator = comparator; } public int compare(T o1, T o2) { return this.comparator.compare(o2, o1); } } private static final class SafeNullsLowComparator implements SerializableComparator { private static final long serialVersionUID = 1L; private final Comparator notNullSafeComparator; private SafeNullsLowComparator(Comparator newNotNullSafeComparator) { this.notNullSafeComparator = newNotNullSafeComparator; } public int compare(T value1, T value2) { if (value1 != null && value2 != null) { return this.notNullSafeComparator.compare(value1, value2); } if (value1 == null && value2 == null) { return 0; } return value1 == null ? -1 : 1; } } private static final class SafeNullsHighComparator implements SerializableComparator { private static final long serialVersionUID = 1L; private final Comparator notNullSafeComparator; private SafeNullsHighComparator(Comparator newNotNullSafeComparator) { this.notNullSafeComparator = newNotNullSafeComparator; } public int compare(T value1, T value2) { if (value1 != null && value2 != null) { return this.notNullSafeComparator.compare(value1, value2); } if (value1 == null && value2 == null) { return 0; } return value1 == null ? 1 : -1; } } private static final class ChainedComparator implements SerializableComparator { private static final long serialVersionUID = 1L; private final Comparator[] comparators; private ChainedComparator(Comparator[] comparators) { this.comparators = comparators; } public int compare(T value1, T value2) { for (Comparator comparator : this.comparators) { int result = comparator.compare(value1, value2); if (result != 0) { return result; } } return 0; } } private static final class PowerSetComparator implements SerializableComparator> { private static final long serialVersionUID = 1L; public int compare(SortedSetIterable setA, SortedSetIterable setB) { int compareTo = Integer.valueOf(setA.size()).compareTo(setB.size()); if (compareTo == 0) { return setA.compareTo(setB); } return compareTo; } } private static final class AscendingCollectionSizeComparator implements SerializableComparator> { private static final long serialVersionUID = 1L; public int compare(Collection c1, Collection c2) { return c1.size() - c2.size(); } } private static final class DescendingCollectionSizeComparator implements SerializableComparator> { private static final long serialVersionUID = 1L; public int compare(Collection c1, Collection c2) { return c2.size() - c1.size(); } } public static > SerializableComparator byFunction(Function function) { if (function instanceof BooleanFunction) { return Functions.toBooleanComparator((BooleanFunction) function); } if (function instanceof ByteFunction) { return Functions.toByteComparator((ByteFunction) function); } if (function instanceof CharFunction) { return Functions.toCharComparator((CharFunction) function); } if (function instanceof DoubleFunction) { return Functions.toDoubleComparator((DoubleFunction) function); } if (function instanceof FloatFunction) { return Functions.toFloatComparator((FloatFunction) function); } if (function instanceof IntFunction) { return Functions.toIntComparator((IntFunction) function); } if (function instanceof LongFunction) { return Functions.toLongComparator((LongFunction) function); } if (function instanceof ShortFunction) { return Functions.toShortComparator((ShortFunction) function); } return Comparators.byFunction(function, naturalOrder()); } public static SerializableComparator byBooleanFunction(BooleanFunction function) { return Functions.toBooleanComparator(function); } public static SerializableComparator byByteFunction(ByteFunction function) { return Functions.toByteComparator(function); } public static SerializableComparator byCharFunction(CharFunction function) { return Functions.toCharComparator(function); } public static SerializableComparator byDoubleFunction(DoubleFunction function) { return Functions.toDoubleComparator(function); } public static SerializableComparator byFloatFunction(FloatFunction function) { return Functions.toFloatComparator(function); } public static SerializableComparator byIntFunction(IntFunction function) { return Functions.toIntComparator(function); } public static SerializableComparator byLongFunction(LongFunction function) { return Functions.toLongComparator(function); } public static SerializableComparator byShortFunction(ShortFunction function) { return Functions.toShortComparator(function); } public static SerializableComparator byFunction( Function function, Comparator comparator) { return new FunctionComparator(function, comparator); } public static boolean nullSafeEquals(Object value1, Object value2) { return value1 == null ? value2 == null : value1.equals(value2); } public static > int nullSafeCompare(T value1, T value2) { if (value1 != null && value2 != null) { return value1.compareTo(value2); } if (value1 == null && value2 == null) { return 0; } return value1 == null ? -1 : 1; } private static final class ByFirstOfPairComparator implements SerializableComparator> { private static final long serialVersionUID = 1L; private final Comparator comparator; private ByFirstOfPairComparator(Comparator comparator) { this.comparator = comparator; } public int compare(Pair p1, Pair p2) { return this.comparator.compare(p1.getOne(), p2.getOne()); } } private static final class BySecondOfPairComparator implements SerializableComparator> { private static final long serialVersionUID = 1L; private final Comparator comparator; private BySecondOfPairComparator(Comparator comparator) { this.comparator = comparator; } public int compare(Pair p1, Pair p2) { return this.comparator.compare(p1.getTwo(), p2.getTwo()); } } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/factory/Functions.java000066400000000000000000001032011234315411400334310ustar00rootroot00000000000000/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.factory; import java.util.Map; import com.gs.collections.api.block.SerializableComparator; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.tuple.Pair; import com.gs.collections.impl.block.comparator.primitive.BooleanFunctionComparator; import com.gs.collections.impl.block.comparator.primitive.ByteFunctionComparator; import com.gs.collections.impl.block.comparator.primitive.CharFunctionComparator; import com.gs.collections.impl.block.comparator.primitive.DoubleFunctionComparator; import com.gs.collections.impl.block.comparator.primitive.FloatFunctionComparator; import com.gs.collections.impl.block.comparator.primitive.IntFunctionComparator; import com.gs.collections.impl.block.comparator.primitive.LongFunctionComparator; import com.gs.collections.impl.block.comparator.primitive.ShortFunctionComparator; import com.gs.collections.impl.block.function.CaseFunction; import com.gs.collections.impl.block.function.IfFunction; import com.gs.collections.impl.block.function.checked.CheckedFunction; import com.gs.collections.impl.block.function.primitive.IntegerFunctionImpl; import com.gs.collections.impl.tuple.Tuples; import com.gs.collections.impl.utility.Iterate; import com.gs.collections.impl.utility.StringIterate; public final class Functions { private static final Function DOUBLE_PASS_THRU_FUNCTION = new DoublePassThruFunction(); private static final Function INTEGER_PASS_THRU_FUNCTION = new IntegerPassThruFunction(); private static final Function LONG_PASS_THRU_FUNCTION = new LongPassThruFunction(); private static final Function PASS_THRU_FUNCTION = new PassThruFunction(); private static final Function STRING_TRIM_FUNCTION = new StringTrimFunction(); private static final Function> CLASS_FUNCTION = new ClassFunction(); private static final Function MATH_SIN_FUNCTION = new MathSinFunction(); private static final Function SQUARED_INTEGER = new SquaredIntegerFunction(); private static final Function TO_STRING_FUNCTION = new ToStringFunction(); private static final Function STRING_TO_INTEGER_FUNCTION = new StringToIntegerFunction(); private static final Function MAP_KEY_FUNCTION = new MapKeyFunction(); private static final Function MAP_VALUE_FUNCTION = new MapValueFunction(); private static final Function, Integer> SIZE_FUNCTION = new SizeFunction(); private static final FirstOfPairFunction FIRST_OF_PAIR_FUNCTION = new FirstOfPairFunction(); private static final SecondOfPairFunction SECOND_OF_PAIR_FUNCTION = new SecondOfPairFunction(); private static final CheckedFunction> CLASS_FOR_NAME = new ClassForNameFunction(); private Functions() { throw new AssertionError("Suppress default constructor for noninstantiability"); } private static class PassThruFunction implements Function { private static final long serialVersionUID = 1L; public T valueOf(T anObject) { return anObject; } } private static class StringTrimFunction implements Function { private static final long serialVersionUID = 1L; public String valueOf(String s) { return s.trim(); } } private static final class FixedValueFunction implements Function { private static final long serialVersionUID = 1L; private final V value; private FixedValueFunction(V value) { this.value = value; } public V valueOf(T object) { return this.value; } } private static final class ClassFunction implements Function> { private static final long serialVersionUID = 1L; public Class valueOf(Object anObject) { return anObject.getClass(); } @Override public String toString() { return "object.getClass()"; } } private static final class MathSinFunction implements Function { private static final long serialVersionUID = 1L; public Double valueOf(Number number) { return Math.sin(number.doubleValue()); } @Override public String toString() { return "Math.sin()"; } } private static final class SquaredIntegerFunction implements Function { private static final long serialVersionUID = 1L; public Integer valueOf(Integer value) { return value * value; } } private static final class ToStringFunction implements Function { private static final long serialVersionUID = 1L; public String valueOf(Object anObject) { return String.valueOf(anObject); } @Override public String toString() { return "toString"; } } private static final class StringToIntegerFunction implements Function { private static final long serialVersionUID = 1L; public Integer valueOf(String string) { return Integer.valueOf(string); } @Override public String toString() { return "stringToInteger"; } } public static Function getPassThru() { return (Function) PASS_THRU_FUNCTION; } public static Function getFixedValue(V value) { return new FixedValueFunction(value); } public static Function> getToClass() { return CLASS_FUNCTION; } public static Function getMathSinFunction() { return MATH_SIN_FUNCTION; } public static Function getNumberPassThru() { return (Function) PASS_THRU_FUNCTION; } public static Function getIntegerPassThru() { return INTEGER_PASS_THRU_FUNCTION; } public static Function getLongPassThru() { return LONG_PASS_THRU_FUNCTION; } public static Function getDoublePassThru() { return DOUBLE_PASS_THRU_FUNCTION; } public static Function getStringPassThru() { return (Function) PASS_THRU_FUNCTION; } public static Function getStringTrim() { return STRING_TRIM_FUNCTION; } public static Function getToString() { return TO_STRING_FUNCTION; } public static Function getNullSafeToString(String defaultValue) { return Functions.nullSafe(TO_STRING_FUNCTION, defaultValue); } public static SerializableComparator toBooleanComparator(BooleanFunction function) { return new BooleanFunctionComparator(function); } public static SerializableComparator toByteComparator(ByteFunction function) { return new ByteFunctionComparator(function); } public static SerializableComparator toCharComparator(CharFunction function) { return new CharFunctionComparator(function); } public static SerializableComparator toFloatComparator(FloatFunction function) { return new FloatFunctionComparator(function); } public static SerializableComparator toShortComparator(ShortFunction function) { return new ShortFunctionComparator(function); } public static SerializableComparator toIntComparator(IntFunction function) { return new IntFunctionComparator(function); } public static SerializableComparator toDoubleComparator(DoubleFunction function) { return new DoubleFunctionComparator(function); } public static SerializableComparator toLongComparator(LongFunction function) { return new LongFunctionComparator(function); } public static Function getStringToInteger() { return STRING_TO_INTEGER_FUNCTION; } public static Function withDefault(Function function, V defaultValue) { return new DefaultFunction(function, defaultValue); } public static Function nullSafe(Function function) { return new NullSafeFunction(function, null); } public static Function nullSafe(Function function, V nullValue) { return new NullSafeFunction(function, nullValue); } public static Function, V1> firstOfPair() { return (Function, V1>) FIRST_OF_PAIR_FUNCTION; } public static Function, V2> secondOfPair() { return (Function, V2>) SECOND_OF_PAIR_FUNCTION; } /** * Bind the parameter passed to a Function2 into a new Function. * * @param function The Function2 to delegate the invocation to. * @param parameter The parameter the use in the invocation of the delegate function. * @return A new Function */ public static Function bind(Function2 function, P parameter) { return new BindFunction2(function, parameter); } /** * Bind the input of a Procedure to the result of an function, returning a new Procedure. * * @param delegate The Procedure to delegate the invocation to. * @param function The Function that will create the input for the delegate * @return A new Procedure */ public static Procedure bind( Procedure delegate, Function function) { return new BindProcedure(delegate, function); } /** * Bind the input of a ObjectIntProcedure to the result of an function, returning a new ObjectIntProcedure. * * @param delegate The ObjectIntProcedure to delegate the invocation to. * @param function The Function that will create the input for the delegate * @return A new ObjectIntProcedure */ public static ObjectIntProcedure bind( ObjectIntProcedure delegate, Function function) { return new BindObjectIntProcedure(delegate, function); } /** * Bind the input of the first argument of a Procedure2 to the result of an function, returning a new Procedure2. * * @param delegate The Procedure2 to delegate the invocation to. * @param function The Function that will create the input for the delegate * @return A new Procedure2 */ public static Procedure2 bind( Procedure2 delegate, Function function) { return new BindProcedure2(delegate, function); } public static Function squaredInteger() { return SQUARED_INTEGER; } public static Function firstNotNullValue(Function... functions) { return new FirstNotNullFunction(functions); } public static Function firstNotEmptyStringValue( Function... functions) { return new FirstNotEmptyStringFunction(functions); } public static > Function firstNotEmptyCollectionValue( Function... functions) { return new FirstNotEmptyCollectionFunction(functions); } public static Function ifTrue( Predicate predicate, Function function) { return new IfFunction(predicate, function); } public static Function ifElse( Predicate predicate, Function trueFunction, Function falseFunction) { return new IfFunction(predicate, trueFunction, falseFunction); } public static , V> CaseFunction caseDefault( Function defaultFunction) { return new CaseFunction(defaultFunction); } public static , V> CaseFunction caseDefault( Function defaultFunction, Predicate predicate, Function function) { CaseFunction caseFunction = Functions.caseDefault(defaultFunction); return caseFunction.addCase(predicate, function); } public static Function synchronizedEach(Function function) { return new SynchronizedFunction(function); } public static Function> classForName() { return CLASS_FOR_NAME; } private static final class FirstNotNullFunction implements Function { private static final long serialVersionUID = 1L; private final Function[] functions; private FirstNotNullFunction(Function... functions) { this.functions = functions; } public V valueOf(T object) { for (Function function : this.functions) { V result = function.valueOf(object); if (result != null) { return result; } } return null; } } private static final class FirstNotEmptyStringFunction implements Function { private static final long serialVersionUID = 1L; private final Function[] functions; private FirstNotEmptyStringFunction(Function... functions) { this.functions = functions; } public String valueOf(T object) { for (Function function : this.functions) { String result = function.valueOf(object); if (StringIterate.notEmpty(result)) { return result; } } return null; } } private static final class FirstNotEmptyCollectionFunction> implements Function { private static final long serialVersionUID = 1L; private final Function[] functions; private FirstNotEmptyCollectionFunction(Function[] functions) { this.functions = functions; } public I valueOf(T1 object) { for (Function function : this.functions) { I result = function.valueOf(object); if (Iterate.notEmpty(result)) { return result; } } return null; } } private static final class SynchronizedFunction implements Function { private static final long serialVersionUID = 1L; private final Function function; private SynchronizedFunction(Function function) { this.function = function; } public V valueOf(T each) { synchronized (each) { return this.function.valueOf(each); } } } public static FunctionChain chain(Function function1, Function function2) { return new FunctionChain(function1, function2); } public static BooleanFunctionChain chainBoolean(Function function1, BooleanFunction function2) { return new BooleanFunctionChain(function1, function2); } public static ByteFunctionChain chainByte(Function function1, ByteFunction function2) { return new ByteFunctionChain(function1, function2); } public static CharFunctionChain chainChar(Function function1, CharFunction function2) { return new CharFunctionChain(function1, function2); } public static DoubleFunctionChain chainDouble(Function function1, DoubleFunction function2) { return new DoubleFunctionChain(function1, function2); } public static FloatFunctionChain chainFloat(Function function1, FloatFunction function2) { return new FloatFunctionChain(function1, function2); } public static IntFunctionChain chainInt(Function function1, IntFunction function2) { return new IntFunctionChain(function1, function2); } public static LongFunctionChain chainLong(Function function1, LongFunction function2) { return new LongFunctionChain(function1, function2); } public static ShortFunctionChain chainShort(Function function1, ShortFunction function2) { return new ShortFunctionChain(function1, function2); } private static class DoublePassThruFunction implements Function, DoubleFunction { private static final long serialVersionUID = 1L; public double doubleValueOf(Double each) { return each.doubleValue(); } public Double valueOf(Double each) { return each; } @Override public String toString() { return DoublePassThruFunction.class.getSimpleName(); } } private static class IntegerPassThruFunction implements Function, IntFunction { private static final long serialVersionUID = 1L; public int intValueOf(Integer each) { return each.intValue(); } public Integer valueOf(Integer each) { return each; } @Override public String toString() { return IntegerPassThruFunction.class.getSimpleName(); } } private static class LongPassThruFunction implements Function, LongFunction { private static final long serialVersionUID = 1L; public long longValueOf(Long each) { return each.longValue(); } public Long valueOf(Long each) { return each; } @Override public String toString() { return LongPassThruFunction.class.getSimpleName(); } } private static final class DefaultFunction implements Function { private static final long serialVersionUID = 1L; private final Function function; private final V defaultValue; private DefaultFunction(Function newFunction, V newDefaultValue) { this.function = newFunction; this.defaultValue = newDefaultValue; } public V valueOf(T anObject) { V returnValue = this.function.valueOf(anObject); if (returnValue == null) { return this.defaultValue; } return returnValue; } } private static final class NullSafeFunction implements Function { private static final long serialVersionUID = 1L; private final Function function; private final V nullValue; private NullSafeFunction(Function function, V nullValue) { this.function = function; this.nullValue = nullValue; } public V valueOf(T object) { return object == null ? this.nullValue : this.function.valueOf(object); } } public static Function> pair( final Function function1, final Function function2) { return new Function>() { public Pair valueOf(T t) { return Tuples.pair(function1.valueOf(t), function2.valueOf(t)); } }; } /** * @return A function that gets the key out of a {@link java.util.Map.Entry} */ public static Function, K> getKeyFunction() { return (Function, K>) MAP_KEY_FUNCTION; } /** * @return A function that gets the value out of a {@link java.util.Map.Entry} */ public static Function, V> getValueFunction() { return (Function, V>) MAP_VALUE_FUNCTION; } private static class MapKeyFunction implements Function, K> { private static final long serialVersionUID = 1L; public K valueOf(Map.Entry entry) { return entry.getKey(); } } private static class MapValueFunction implements Function, V> { private static final long serialVersionUID = 1L; public V valueOf(Map.Entry entry) { return entry.getValue(); } } /** * @return A function that gets the size of an {@code Iterable} */ public static Function, Integer> getSizeOf() { return SIZE_FUNCTION; } public static class SizeFunction extends IntegerFunctionImpl> { private static final long serialVersionUID = 1L; public int intValueOf(Iterable iterable) { return Iterate.sizeOf(iterable); } } public static final class FunctionChain implements Function { private static final long serialVersionUID = 1L; private final Function function1; private final Function function2; private FunctionChain(Function function1, Function function2) { this.function1 = function1; this.function2 = function2; } public T3 valueOf(T1 object) { return this.function2.valueOf(this.function1.valueOf(object)); } public FunctionChain chain(Function function) { return new FunctionChain(this, function); } public BooleanFunctionChain chainBoolean(BooleanFunction function) { return new BooleanFunctionChain(this, function); } public ByteFunctionChain chainByte(ByteFunction function) { return new ByteFunctionChain(this, function); } public CharFunctionChain chainChar(CharFunction function) { return new CharFunctionChain(this, function); } public DoubleFunctionChain chainDouble(DoubleFunction function) { return new DoubleFunctionChain(this, function); } public FloatFunctionChain chainFloat(FloatFunction function) { return new FloatFunctionChain(this, function); } public IntFunctionChain chainInt(IntFunction function) { return new IntFunctionChain(this, function); } public LongFunctionChain chainLong(LongFunction function) { return new LongFunctionChain(this, function); } public ShortFunctionChain chainShort(ShortFunction function) { return new ShortFunctionChain(this, function); } } public static final class BooleanFunctionChain implements BooleanFunction { private static final long serialVersionUID = 1L; private final Function function1; private final BooleanFunction function2; private BooleanFunctionChain(Function function1, BooleanFunction function2) { this.function1 = function1; this.function2 = function2; } public boolean booleanValueOf(T1 object) { return this.function2.booleanValueOf(this.function1.valueOf(object)); } } public static final class ByteFunctionChain implements ByteFunction { private static final long serialVersionUID = 1L; private final Function function1; private final ByteFunction function2; private ByteFunctionChain(Function function1, ByteFunction function2) { this.function1 = function1; this.function2 = function2; } public byte byteValueOf(T1 object) { return this.function2.byteValueOf(this.function1.valueOf(object)); } } public static final class CharFunctionChain implements CharFunction { private static final long serialVersionUID = 1L; private final Function function1; private final CharFunction function2; private CharFunctionChain(Function function1, CharFunction function2) { this.function1 = function1; this.function2 = function2; } public char charValueOf(T1 object) { return this.function2.charValueOf(this.function1.valueOf(object)); } } public static final class DoubleFunctionChain implements DoubleFunction { private static final long serialVersionUID = 1L; private final Function function1; private final DoubleFunction function2; private DoubleFunctionChain(Function function1, DoubleFunction function2) { this.function1 = function1; this.function2 = function2; } public double doubleValueOf(T1 object) { return this.function2.doubleValueOf(this.function1.valueOf(object)); } } public static final class FloatFunctionChain implements FloatFunction { private static final long serialVersionUID = 1L; private final Function function1; private final FloatFunction function2; private FloatFunctionChain(Function function1, FloatFunction function2) { this.function1 = function1; this.function2 = function2; } public float floatValueOf(T1 object) { return this.function2.floatValueOf(this.function1.valueOf(object)); } } public static final class IntFunctionChain implements IntFunction { private static final long serialVersionUID = 1L; private final Function function1; private final IntFunction function2; private IntFunctionChain(Function function1, IntFunction function2) { this.function1 = function1; this.function2 = function2; } public int intValueOf(T1 object) { return this.function2.intValueOf(this.function1.valueOf(object)); } } public static final class LongFunctionChain implements LongFunction { private static final long serialVersionUID = 1L; private final Function function1; private final LongFunction function2; private LongFunctionChain(Function function1, LongFunction function2) { this.function1 = function1; this.function2 = function2; } public long longValueOf(T1 object) { return this.function2.longValueOf(this.function1.valueOf(object)); } } public static final class ShortFunctionChain implements ShortFunction { private static final long serialVersionUID = 1L; private final Function function1; private final ShortFunction function2; private ShortFunctionChain(Function function1, ShortFunction function2) { this.function1 = function1; this.function2 = function2; } public short shortValueOf(T1 object) { return this.function2.shortValueOf(this.function1.valueOf(object)); } } private static class FirstOfPairFunction implements Function, T> { private static final long serialVersionUID = 1L; public T valueOf(Pair pair) { return pair.getOne(); } } private static class SecondOfPairFunction implements Function, T> { private static final long serialVersionUID = 1L; public T valueOf(Pair pair) { return pair.getTwo(); } } private static class ClassForNameFunction extends CheckedFunction> { private static final long serialVersionUID = 1L; @Override public Class safeValueOf(String className) throws ClassNotFoundException { return Class.forName(className); } } private static final class BindObjectIntProcedure implements ObjectIntProcedure { private static final long serialVersionUID = 1L; private final ObjectIntProcedure delegate; private final Function function; private BindObjectIntProcedure(ObjectIntProcedure delegate, Function function) { this.delegate = delegate; this.function = function; } public void value(T1 each, int index) { this.delegate.value(this.function.valueOf(each), index); } } private static final class BindProcedure implements Procedure { private static final long serialVersionUID = 1L; private final Procedure delegate; private final Function function; private BindProcedure(Procedure delegate, Function function) { this.delegate = delegate; this.function = function; } public void value(T1 each) { this.delegate.value(this.function.valueOf(each)); } } private static final class BindProcedure2 implements Procedure2 { private static final long serialVersionUID = 1L; private final Procedure2 delegate; private final Function function; private BindProcedure2(Procedure2 delegate, Function function) { this.delegate = delegate; this.function = function; } public void value(T1 each, T3 constant) { this.delegate.value(this.function.valueOf(each), constant); } } private static final class BindFunction2 implements Function { private static final long serialVersionUID = 1L; private final Function2 delegate; private final T2 parameter; private BindFunction2(Function2 delegate, T2 parameter) { this.delegate = delegate; this.parameter = parameter; } public T3 valueOf(T1 object) { return this.delegate.value(object, this.parameter); } } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/factory/Functions0.java000066400000000000000000000121231234315411400335130ustar00rootroot00000000000000/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.factory; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; import com.gs.collections.api.bag.MutableBag; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.map.MutableMap; import com.gs.collections.api.set.MutableSet; import com.gs.collections.impl.block.function.PassThruFunction0; import com.gs.collections.impl.factory.Bags; import com.gs.collections.impl.factory.Lists; import com.gs.collections.impl.factory.Maps; import com.gs.collections.impl.factory.Sets; public final class Functions0 { private static final NewFastListFunction NEW_FAST_LIST_FUNCTION = new NewFastListFunction(); private static final NewUnifiedSetFunction NEW_UNIFIED_SET_FUNCTION = new NewUnifiedSetFunction(); private static final NewHashBagFunction NEW_HASH_BAG_FUNCTION = new NewHashBagFunction(); private static final NewUnifiedMapFunction NEW_UNIFIED_MAP_FUNCTION = new NewUnifiedMapFunction(); private static final NullFunction NULL_FUNCTION = new NullFunction(); private static final AtomicIntegerZeroFunction ATOMIC_INTEGER_ZERO = new AtomicIntegerZeroFunction(); private static final AtomicLongZeroFunction ATOMIC_LONG_ZERO = new AtomicLongZeroFunction(); private static final IntegerZeroFunction INTEGER_ZERO = new IntegerZeroFunction(); private Functions0() { throw new AssertionError("Suppress default constructor for noninstantiability"); } public static Function0> newFastList() { return (Function0>) NEW_FAST_LIST_FUNCTION; } public static Function0> newUnifiedSet() { return (Function0>) NEW_UNIFIED_SET_FUNCTION; } public static Function0> newHashBag() { return (Function0>) NEW_HASH_BAG_FUNCTION; } public static Function0> newUnifiedMap() { return (Function0>) NEW_UNIFIED_MAP_FUNCTION; } public static Function0 nullValue() { return (Function0) NULL_FUNCTION; } public static Function0 value(T t) { return new PassThruFunction0(t); } public static Function0 zeroAtomicInteger() { return ATOMIC_INTEGER_ZERO; } public static Function0 zeroAtomicLong() { return ATOMIC_LONG_ZERO; } private static final class NewFastListFunction implements Function0> { private static final long serialVersionUID = 1L; public MutableList value() { return Lists.mutable.of(); } } private static final class NewUnifiedMapFunction implements Function0> { private static final long serialVersionUID = 1L; public MutableMap value() { return Maps.mutable.of(); } } private static final class NewUnifiedSetFunction implements Function0> { private static final long serialVersionUID = 1L; public MutableSet value() { return Sets.mutable.of(); } } private static final class NewHashBagFunction implements Function0> { private static final long serialVersionUID = 1L; public MutableBag value() { return Bags.mutable.of(); } } private static class NullFunction implements Function0 { private static final long serialVersionUID = 1L; public T value() { return null; } } private static class IntegerZeroFunction implements Function0 { private static final long serialVersionUID = 1L; public Integer value() { return Integer.valueOf(0); } } private static class AtomicIntegerZeroFunction implements Function0 { private static final long serialVersionUID = 1L; public AtomicInteger value() { return new AtomicInteger(0); } } private static class AtomicLongZeroFunction implements Function0 { private static final long serialVersionUID = 1L; public AtomicLong value() { return new AtomicLong(0); } } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/factory/Functions2.java000066400000000000000000000041351234315411400335210ustar00rootroot00000000000000/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.factory; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; /** * Contains factory methods for creating {@link Function2} instances. */ public final class Functions2 { private static final Function2 INTEGER_ADDITION = new IntegerAddition(); private Functions2() { throw new AssertionError("Suppress default constructor for noninstantiability"); } public static Function2 fromFunction(Function function) { return new FunctionAdapter(function); } public static Function2 integerAddition() { return INTEGER_ADDITION; } private static final class FunctionAdapter implements Function2 { private static final long serialVersionUID = 1L; private final Function function; private FunctionAdapter(Function function) { this.function = function; } public V value(T each, P parameter) { return this.function.valueOf(each); } } private static class IntegerAddition implements Function2 { private static final long serialVersionUID = 1L; public Integer value(Integer aggregate, Integer value) { return aggregate + value; } } } HashingStrategies.java000066400000000000000000000327011234315411400350240ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/factory/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.factory; import com.gs.collections.api.block.HashingStrategy; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; public final class HashingStrategies { private static final HashingStrategy DEFAULT_HASHING_STRATEGY = new DefaultStrategy(); private static final HashingStrategy IDENTITY_HASHING_STRATEGY = new IdentityHashingStrategy(); private HashingStrategies() { throw new AssertionError("Suppress default constructor for noninstantiability"); } public static HashingStrategy defaultStrategy() { return (HashingStrategy) DEFAULT_HASHING_STRATEGY; } public static HashingStrategy nullSafeHashingStrategy(HashingStrategy nonNullSafeStrategy) { return new NullSafeHashingStrategy(nonNullSafeStrategy); } public static HashingStrategy fromFunction(Function function) { return new FunctionHashingStrategy(function); } public static HashingStrategy identityStrategy() { return IDENTITY_HASHING_STRATEGY; } public static HashingStrategy chain(HashingStrategy... hashingStrategies) { if (hashingStrategies.length == 0) { throw new IllegalArgumentException("Nothing to chain"); } return new ChainedHashingStrategy(hashingStrategies); } public static HashingStrategy fromFunctions(Function one, Function two) { return HashingStrategies.chain( HashingStrategies.fromFunction(one), HashingStrategies.fromFunction(two)); } public static HashingStrategy fromFunctions(Function one, Function two, Function three) { return HashingStrategies.chain( HashingStrategies.fromFunction(one), HashingStrategies.fromFunction(two), HashingStrategies.fromFunction(three)); } public static HashingStrategy fromBooleanFunction(BooleanFunction function) { return new BooleanFunctionHashingStrategy(function); } public static HashingStrategy fromByteFunction(ByteFunction function) { return new ByteFunctionHashingStrategy(function); } public static HashingStrategy fromCharFunction(CharFunction function) { return new CharFunctionHashingStrategy(function); } public static HashingStrategy fromDoubleFunction(DoubleFunction function) { return new DoubleFunctionHashingStrategy(function); } public static HashingStrategy fromFloatFunction(FloatFunction function) { return new FloatFunctionHashingStrategy(function); } public static HashingStrategy fromIntFunction(IntFunction function) { return new IntFunctionHashingStrategy(function); } public static HashingStrategy fromLongFunction(LongFunction function) { return new LongFunctionHashingStrategy(function); } public static HashingStrategy fromShortFunction(ShortFunction function) { return new ShortFunctionHashingStrategy(function); } private static class DefaultStrategy implements HashingStrategy { private static final long serialVersionUID = 1L; public int computeHashCode(Object object) { return object.hashCode(); } public boolean equals(Object object1, Object object2) { return object1.equals(object2); } } private static final class NullSafeHashingStrategy implements HashingStrategy { private static final long serialVersionUID = 1L; private final HashingStrategy nonNullSafeStrategy; private NullSafeHashingStrategy(HashingStrategy nonNullSafeStrategy) { this.nonNullSafeStrategy = nonNullSafeStrategy; } public int computeHashCode(T object) { return object == null ? 0 : this.nonNullSafeStrategy.computeHashCode(object); } public boolean equals(T object1, T object2) { return object1 == null || object2 == null ? object1 == object2 : this.nonNullSafeStrategy.equals(object1, object2); } } private static final class FunctionHashingStrategy implements HashingStrategy { private static final long serialVersionUID = 1L; private final Function function; private FunctionHashingStrategy(Function function) { this.function = function; } public int computeHashCode(T object) { return this.function.valueOf(object).hashCode(); } public boolean equals(T object1, T object2) { return this.function.valueOf(object1).equals(this.function.valueOf(object2)); } } private static final class BooleanFunctionHashingStrategy implements HashingStrategy { private static final long serialVersionUID = 1L; private final BooleanFunction function; private BooleanFunctionHashingStrategy(BooleanFunction function) { this.function = function; } public int computeHashCode(T object) { return this.function.booleanValueOf(object) ? Boolean.TRUE.hashCode() : Boolean.FALSE.hashCode(); } public boolean equals(T object1, T object2) { return this.function.booleanValueOf(object1) == this.function.booleanValueOf(object2); } } private static final class ByteFunctionHashingStrategy implements HashingStrategy { private static final long serialVersionUID = 1L; private final ByteFunction function; private ByteFunctionHashingStrategy(ByteFunction function) { this.function = function; } public int computeHashCode(T object) { return this.function.byteValueOf(object); } public boolean equals(T object1, T object2) { return this.function.byteValueOf(object1) == this.function.byteValueOf(object2); } } private static final class CharFunctionHashingStrategy implements HashingStrategy { private static final long serialVersionUID = 1L; private final CharFunction function; private CharFunctionHashingStrategy(CharFunction function) { this.function = function; } public int computeHashCode(T object) { return this.function.charValueOf(object); } public boolean equals(T object1, T object2) { return this.function.charValueOf(object1) == this.function.charValueOf(object2); } } private static final class DoubleFunctionHashingStrategy implements HashingStrategy { private static final long serialVersionUID = 1L; private final DoubleFunction function; private DoubleFunctionHashingStrategy(DoubleFunction function) { this.function = function; } public int computeHashCode(T object) { return HashingStrategies.longHashCode(Double.doubleToLongBits(this.function.doubleValueOf(object))); } public boolean equals(T object1, T object2) { return Double.compare(this.function.doubleValueOf(object1), this.function.doubleValueOf(object2)) == 0; } } private static final class FloatFunctionHashingStrategy implements HashingStrategy { private static final long serialVersionUID = 1L; private final FloatFunction function; private FloatFunctionHashingStrategy(FloatFunction function) { this.function = function; } public int computeHashCode(T object) { return Float.floatToIntBits(this.function.floatValueOf(object)); } public boolean equals(T object1, T object2) { return Float.compare(this.function.floatValueOf(object1), this.function.floatValueOf(object2)) == 0; } } private static final class IntFunctionHashingStrategy implements HashingStrategy { private static final long serialVersionUID = 1L; private final IntFunction function; private IntFunctionHashingStrategy(IntFunction function) { this.function = function; } public int computeHashCode(T object) { return this.function.intValueOf(object); } public boolean equals(T object1, T object2) { return this.function.intValueOf(object1) == this.function.intValueOf(object2); } } private static final class LongFunctionHashingStrategy implements HashingStrategy { private static final long serialVersionUID = 1L; private final LongFunction function; private LongFunctionHashingStrategy(LongFunction function) { this.function = function; } public int computeHashCode(T object) { return HashingStrategies.longHashCode(this.function.longValueOf(object)); } public boolean equals(T object1, T object2) { return this.function.longValueOf(object1) == this.function.longValueOf(object2); } } private static final class ShortFunctionHashingStrategy implements HashingStrategy { private static final long serialVersionUID = 1L; private final ShortFunction function; private ShortFunctionHashingStrategy(ShortFunction function) { this.function = function; } public int computeHashCode(T object) { return this.function.shortValueOf(object); } public boolean equals(T object1, T object2) { return this.function.shortValueOf(object1) == this.function.shortValueOf(object2); } } private static final class IdentityHashingStrategy implements HashingStrategy { private static final long serialVersionUID = 1L; public int computeHashCode(Object object) { return System.identityHashCode(object); } public boolean equals(Object object1, Object object2) { return object1 == object2; } } private static final class ChainedHashingStrategy implements HashingStrategy { private static final long serialVersionUID = 1L; private final HashingStrategy[] hashingStrategies; private ChainedHashingStrategy(HashingStrategy... hashingStrategies) { this.hashingStrategies = hashingStrategies; } public int computeHashCode(T object) { int hashCode = this.hashingStrategies[0].computeHashCode(object); for (int i = 1; i < this.hashingStrategies.length; i++) { hashCode = hashCode * 31 + this.hashingStrategies[i].computeHashCode(object); } return hashCode; } public boolean equals(T object1, T object2) { for (HashingStrategy hashingStrategy : this.hashingStrategies) { if (!hashingStrategy.equals(object1, object2)) { return false; } } return true; } } /** * This implementation is equivalent to the JDK Long hashcode because there is no public static hashCode(long value) method on Long. * This method will be introduced in Java 1.8, at which point this can be replaced. * * @param value the long value to hash * @return hashcode for long, based on the {@link Long#hashCode()} */ private static int longHashCode(long value) { return (int) (value ^ (value >>> 32)); } } IntegerPredicates.java000066400000000000000000000073521234315411400350150ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/factory/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.factory; import com.gs.collections.api.block.function.Function; public final class IntegerPredicates { private static final Predicates IS_ODD = new IntegerIsOdd(); private static final Predicates IS_EVEN = new IntegerIsEven(); private static final Predicates IS_POSITIVE = new IntegerIsPositive(); private static final Predicates IS_NEGATIVE = new IntegerIsNegative(); private static final Predicates IS_ZERO = new IntegerIsZero(); private IntegerPredicates() { throw new AssertionError("Suppress default constructor for noninstantiability"); } public static Predicates isOdd() { return IS_ODD; } public static Predicates isEven() { return IS_EVEN; } public static Predicates isPositive() { return IS_POSITIVE; } public static Predicates isNegative() { return IS_NEGATIVE; } public static Predicates isZero() { return IS_ZERO; } public static Predicates attributeIsEven(Function function) { return Predicates.attributePredicate(function, IntegerPredicates.isEven()); } public static Predicates attributeIsOdd(Function function) { return Predicates.attributePredicate(function, IntegerPredicates.isOdd()); } public static Predicates attributeIsZero(Function function) { return Predicates.attributePredicate(function, IntegerPredicates.isZero()); } public static Predicates attributeIsPositive(Function function) { return Predicates.attributePredicate(function, IntegerPredicates.isPositive()); } public static Predicates attributeIsNegative(Function function) { return Predicates.attributePredicate(function, IntegerPredicates.isNegative()); } private static class IntegerIsPositive extends Predicates { private static final long serialVersionUID = 1L; public boolean accept(Integer i) { return i.intValue() > 0; } } private static class IntegerIsNegative extends Predicates { private static final long serialVersionUID = 1L; public boolean accept(Integer i) { return i.intValue() < 0; } } private static class IntegerIsZero extends Predicates { private static final long serialVersionUID = 1L; public boolean accept(Integer i) { return i.intValue() == 0; } } private static class IntegerIsOdd extends Predicates { private static final long serialVersionUID = 1L; public boolean accept(Integer i) { return i.intValue() % 2 != 0; } } private static class IntegerIsEven extends Predicates { private static final long serialVersionUID = 1L; public boolean accept(Integer i) { return i.intValue() % 2 == 0; } } } LongPredicates.java000066400000000000000000000071611234315411400343150ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/factory/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.factory; import com.gs.collections.api.block.function.Function; public final class LongPredicates { private static final Predicates IS_ODD = new LongIsOdd(); private static final Predicates IS_EVEN = new LongIsEven(); private static final Predicates IS_POSITIVE = new LongIsPositive(); private static final Predicates IS_NEGATIVE = new LongIsNegative(); private static final Predicates IS_ZERO = new LongIsZero(); private LongPredicates() { throw new AssertionError("Suppress default constructor for noninstantiability"); } public static Predicates isOdd() { return IS_ODD; } public static Predicates isEven() { return IS_EVEN; } public static Predicates isPositive() { return IS_POSITIVE; } public static Predicates isNegative() { return IS_NEGATIVE; } public static Predicates isZero() { return IS_ZERO; } public static Predicates attributeIsEven(Function function) { return Predicates.attributePredicate(function, LongPredicates.isEven()); } public static Predicates attributeIsOdd(Function function) { return Predicates.attributePredicate(function, LongPredicates.isOdd()); } public static Predicates attributeIsZero(Function function) { return Predicates.attributePredicate(function, LongPredicates.isZero()); } public static Predicates attributeIsPositive(Function function) { return Predicates.attributePredicate(function, LongPredicates.isPositive()); } public static Predicates attributeIsNegative(Function function) { return Predicates.attributePredicate(function, LongPredicates.isNegative()); } private static class LongIsOdd extends Predicates { private static final long serialVersionUID = 1L; public boolean accept(Long l) { return l.longValue() % 2 != 0; } } private static class LongIsEven extends Predicates { private static final long serialVersionUID = 1L; public boolean accept(Long l) { return l.longValue() % 2 == 0; } } private static class LongIsPositive extends Predicates { private static final long serialVersionUID = 1L; public boolean accept(Long l) { return l.longValue() > 0; } } private static class LongIsNegative extends Predicates { private static final long serialVersionUID = 1L; public boolean accept(Long l) { return l.longValue() < 0; } } private static class LongIsZero extends Predicates { private static final long serialVersionUID = 1L; public boolean accept(Long l) { return l.longValue() == 0; } } } MultimapFunctions.java000066400000000000000000000031721234315411400350710ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/factory/* * Copyright 2012 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.factory; import com.gs.collections.api.RichIterable; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.multimap.Multimap; public final class MultimapFunctions { private MultimapFunctions() { throw new AssertionError("Suppress default constructor for noninstantiability"); } /** * @return Function delegating to {@link Multimap#get(Object)} */ public static Function> get(Multimap multimap) { return new MultimapGetFunction(multimap); } private static final class MultimapGetFunction implements Function> { private static final long serialVersionUID = 1L; private final Multimap multimap; private MultimapGetFunction(Multimap multimap) { this.multimap = multimap; } public RichIterable valueOf(K subject) { return this.multimap.get(subject); } } } ObjectIntProcedures.java000066400000000000000000000031501234315411400353210ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/factory/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.factory; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; /** * Contains factory methods for creating {@link ObjectIntProcedure} instances. */ public final class ObjectIntProcedures { private ObjectIntProcedures() { throw new AssertionError("Suppress default constructor for noninstantiability"); } public static ObjectIntProcedure fromProcedure(Procedure procedure) { return new ProcedureAdapter(procedure); } private static final class ProcedureAdapter implements ObjectIntProcedure { private static final long serialVersionUID = 1L; private final Procedure procedure; private ProcedureAdapter(Procedure procedure) { this.procedure = procedure; } public void value(T each, int count) { this.procedure.value(each); } } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/factory/Predicates.java000066400000000000000000001135251234315411400335560ustar00rootroot00000000000000/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.factory; import java.util.Arrays; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.impl.utility.Iterate; /** * The Predicates class can be used to build common Predicates to be used by methods such * as detect:, select: and reject: on the Iterate, MapIterate, and ArrayIterate classes. Predicates supports * equals, not equals, less than, greater than, less than or equal to, greater than or equal to, in, not in * and, or, and several other Predicate type operations. */ public abstract class Predicates implements Predicate { private static final long serialVersionUID = 1L; private static final Predicates ALWAYS_TRUE = new AlwaysTrue(); private static final Predicates ALWAYS_FALSE = new AlwaysFalse(); private static final Predicates IS_NULL = new IsNull(); private static final Predicates NOT_NULL = new NotNull(); public static Predicates adapt(Predicate predicate) { return new PredicateAdapter(predicate); } public static Predicate bind(Predicate2 predicate, P parameter) { return new BindPredicate2(predicate, parameter); } public static Predicate synchronizedEach(Predicate predicate) { return new SynchronizedPredicate(predicate); } public static Predicates or(Iterable> predicates) { return new OrIterablePredicate(predicates); } public static Predicates or(Predicate predicate1, Predicate predicate2) { return new OrPredicate(predicate1, predicate2); } public static Predicates or(Predicate... predicates) { return new OrIterablePredicate(Arrays.asList(predicates)); } public static Predicates and(Iterable> predicates) { return new AndIterablePredicate(predicates); } public static Predicates and(Predicate predicate1, Predicate predicate2) { return new AndPredicate(predicate1, predicate2); } public static Predicates and(Predicate... predicates) { return new AndIterablePredicate(Arrays.asList(predicates)); } public static Predicates not(Predicate predicate) { return new NotPredicate(predicate); } public Predicates not() { return Predicates.not(this); } public static Predicates neither(Predicate operation1, Predicate operation2) { return new NeitherPredicate(operation1, operation2); } public static Predicates noneOf(Predicate... operations) { return new NoneOfIterablePredicate(Arrays.asList(operations)); } public static Predicates noneOf(Iterable> operations) { return new NoneOfIterablePredicate(operations); } /** * Tests for equality. */ public static Predicates equal(Object object) { if (object == null) { return Predicates.isNull(); } return new EqualPredicate(object); } /** * Creates a predicate which returns true if an object passed to accept method is within the range, inclusive * of the from and to values. */ public static > Predicates betweenInclusive(T from, T to) { Predicates.failIfDifferentTypes(from, to); return new BetweenInclusive(from, to); } private static void failIfDifferentTypes(Object from, Object to) { if (!from.getClass().equals(to.getClass())) { throw new IllegalArgumentException("Trying to do a between comparison with two different types " + from.getClass() + ':' + to.getClass()); } } /** * Creates a predicate which returns true if an object passed to accept method is within the range, exclusive * of the from and to values. */ public static > Predicates betweenExclusive(T from, T to) { Predicates.failIfDifferentTypes(from, to); return new BetweenExclusive(from, to); } /** * Creates a predicate which returns true if an object passed to accept method is within the range, inclusive * of the from and exclusive from the to value. */ public static > Predicates betweenInclusiveFrom(T from, T to) { Predicates.failIfDifferentTypes(from, to); return new BetweenInclusiveFrom(from, to); } /** * Creates a predicate which returns true if an object passed to accept method is within the range, exclusive * of the from and inclusive of the to value. */ public static > Predicates betweenInclusiveTo(T from, T to) { Predicates.failIfDifferentTypes(from, to); return new BetweenInclusiveTo(from, to); } /** * Creates a predicate which returns true if an object passed to accept method is contained in the iterable. * This will clearly work faster if the specified iterable is a Set. */ public static Predicates in(Iterable iterable) { return new InPredicate(iterable); } public static Predicates in(Object... array) { return new InPredicate(Arrays.asList(array)); } /** * Creates a predicate which returns true if an attribute selected from an object passed to accept method * is contained in the iterable. This will clearly work faster if the specified iterable is a Set. */ public static Predicates attributeIn( Function function, Iterable iterable) { return new AttributePredicate(function, Predicates.in(iterable)); } public static > Predicates attributeBetweenInclusive( Function function, V from, V to) { return new AttributePredicate(function, Predicates.betweenInclusive(from, to)); } public static > Predicates attributeBetweenExclusive( Function function, V from, V to) { return new AttributePredicate(function, Predicates.betweenExclusive(from, to)); } public static > Predicates attributeBetweenInclusiveFrom( Function function, V from, V to) { return new AttributePredicate(function, Predicates.betweenInclusiveFrom(from, to)); } public static > Predicates attributeBetweenInclusiveTo( Function function, V from, V to) { return new AttributePredicate(function, Predicates.betweenInclusiveTo(from, to)); } /** * Creates a predicate which returns true if an object passed to accept method is not contained in * the iterable. This will clearly work faster if the specified iterable is a Set. */ public static Predicates notIn(Iterable iterable) { return new NotInPredicate(iterable); } public static Predicates notIn(Object... array) { return new NotInPredicate(Arrays.asList(array)); } /** * Creates a predicate which returns true if an attribute selected from an object passed to accept method * is not contained in the iterable. This will clearly work faster if the specified iterable is a Set. */ public static Predicates attributeNotIn( Function function, Iterable iterable) { return new AttributePredicate(function, Predicates.notIn(iterable)); } public static > Predicates lessThan(T object) { return new LessThanPredicate(object); } public static > Predicates attributeLessThan( Function function, V object) { return new AttributePredicate(function, new LessThanPredicate(object)); } public static > Predicates lessThanOrEqualTo(T object) { return new LessThanOrEqualPredicate(object); } public static > Predicates attributeLessThanOrEqualTo( Function function, V object) { return new AttributePredicate(function, new LessThanOrEqualPredicate(object)); } public static > Predicates greaterThan(T object) { return new GreaterThanPredicate(object); } public static > Predicates attributeGreaterThan( Function function, V object) { return new AttributePredicate(function, new GreaterThanPredicate(object)); } public static > Predicates greaterThanOrEqualTo(T object) { return new GreaterThanOrEqualPredicate(object); } public static > Predicates attributeGreaterThanOrEqualTo( Function function, V object) { return new AttributePredicate(function, new GreaterThanOrEqualPredicate(object)); } public static Predicates attributePredicate( Function function, Predicate predicate) { return new AttributePredicate(function, predicate); } public static Predicates attributeEqual( Function function, Object object) { return new AttributePredicate(function, Predicates.equal(object)); } public static Predicates> anySatisfy(Predicate predicate) { return new AnySatisfy(predicate); } public static Predicates> allSatisfy(Predicate predicate) { return new AllSatisfy(predicate); } public static Predicates> noneSatisfy(Predicate predicate) { return new NoneSatisfy(predicate); } public static Predicates attributeAnySatisfy( Function> function, Predicate predicate) { return Predicates.attributePredicate(function, Predicates.anySatisfy(predicate)); } public static Predicates attributeAllSatisfy( Function> function, Predicate predicate) { return Predicates.attributePredicate(function, Predicates.allSatisfy(predicate)); } public static Predicates attributeNoneSatisfy( Function> function, Predicate predicate) { return Predicates.attributePredicate(function, Predicates.noneSatisfy(predicate)); } public static Predicates notEqual(Object object) { if (object == null) { return Predicates.notNull(); } return new NotEqualPredicate(object); } public static Predicates ifTrue(Function function) { return new AttributeTrue(function); } public static Predicates ifFalse(Function function) { return new AttributeFalse(function); } public static Predicates attributeNotEqual( Function function, Object object) { return new AttributePredicate(function, Predicates.notEqual(object)); } public static Predicates isNull() { return IS_NULL; } public static Predicates attributeIsNull(Function function) { return new AttributePredicate(function, Predicates.isNull()); } public static Predicates notNull() { return NOT_NULL; } public static Predicates attributeNotNull(Function function) { return new AttributePredicate(function, Predicates.notNull()); } public static Predicates sameAs(Object object) { return new IdentityPredicate(object); } public static Predicates notSameAs(Object object) { return new NotIdentityPredicate(object); } public static Predicates instanceOf(Class clazz) { return new InstanceOfPredicate(clazz); } public static Predicates assignableFrom(Class clazz) { return new AssignableFromPredicate(clazz); } public static Predicates notInstanceOf(Class clazz) { return new NotInstanceOfPredicate(clazz); } public static Predicates alwaysTrue() { return ALWAYS_TRUE; } public static Predicates alwaysFalse() { return ALWAYS_FALSE; } public Predicates and(Predicate op) { return Predicates.and(this, op); } public Predicates or(Predicate op) { return Predicates.or(this, op); } public static Predicates> subClass(Class aClass) { return new SubclassPredicate(aClass); } public static Predicates> superClass(Class aClass) { return new SuperclassPredicate(aClass); } private static final class PredicateAdapter extends Predicates { private static final long serialVersionUID = 1L; private final Predicate predicate; private PredicateAdapter(Predicate newPredicate) { this.predicate = newPredicate; } public boolean accept(T o) { return this.predicate.accept(o); } @Override public String toString() { return "Predicates.adapt(" + this.predicate + ')'; } } protected static class AttributePredicate extends Predicates { private static final long serialVersionUID = 1L; protected final Function function; protected final Predicate predicate; protected AttributePredicate( Function newFunction, Predicate newPredicate) { this.function = newFunction; this.predicate = newPredicate; } public boolean accept(T anObject) { return this.predicate.accept(this.function.valueOf(anObject)); } @Override public String toString() { return "Predicates.attributePredicate(" + this.function + ", " + this.predicate + ')'; } } private static class FalseEquals implements Predicate { private static final long serialVersionUID = 1L; public boolean accept(Boolean anObject) { return Boolean.FALSE.equals(anObject); } } private static class TrueEquals implements Predicate { private static final long serialVersionUID = 1L; public boolean accept(Boolean anObject) { return Boolean.TRUE.equals(anObject); } } private static final class AttributeFalse extends AttributePredicate { private static final long serialVersionUID = 1L; private static final FalseEquals FALSE_EQUALS = new FalseEquals(); private AttributeFalse(Function newFunction) { super(newFunction, FALSE_EQUALS); } @Override public String toString() { return "Predicates.ifFalse(" + this.function + ')'; } } private static final class AttributeTrue extends AttributePredicate { private static final long serialVersionUID = 1L; private static final TrueEquals TRUE_EQUALS = new TrueEquals(); private AttributeTrue(Function newFunction) { super(newFunction, TRUE_EQUALS); } @Override public String toString() { return "Predicates.ifTrue(" + this.function + ')'; } } public static class AnySatisfy extends Predicates> { private static final long serialVersionUID = 1L; private final Predicate predicate; public AnySatisfy(Predicate predicate) { this.predicate = predicate; } public boolean accept(Iterable iterable) { return Iterate.anySatisfy(iterable, this.predicate); } } public static class AllSatisfy extends Predicates> { private static final long serialVersionUID = 1L; private final Predicate predicate; public AllSatisfy(Predicate predicate) { this.predicate = predicate; } public boolean accept(Iterable iterable) { return Iterate.allSatisfy(iterable, this.predicate); } } public static class NoneSatisfy extends Predicates> { private static final long serialVersionUID = 1L; private final Predicate predicate; public NoneSatisfy(Predicate predicate) { this.predicate = predicate; } public boolean accept(Iterable iterable) { return Iterate.noneSatisfy(iterable, this.predicate); } } private abstract static class CompareToPredicate> extends Predicates { private static final long serialVersionUID = 1L; protected final T compareTo; private CompareToPredicate(T newCompareTo) { this.compareTo = newCompareTo; } } protected static class LessThanPredicate> extends CompareToPredicate { private static final long serialVersionUID = 1L; protected LessThanPredicate(T newCompareTo) { super(newCompareTo); } public boolean accept(T o) { return o.compareTo(this.compareTo) < 0; } @Override public String toString() { return "Predicates.lessThan(" + this.compareTo + ')'; } } protected abstract static class RangePredicate> extends CompareToPredicate { private static final long serialVersionUID = 1L; protected final T compareFrom; protected RangePredicate(T newCompareFrom, T newCompareTo) { super(newCompareTo); this.compareFrom = newCompareFrom; } } private static final class BetweenInclusive> extends RangePredicate { private static final long serialVersionUID = 1L; private BetweenInclusive(T newCompareFrom, T newCompareTo) { super(newCompareFrom, newCompareTo); } public boolean accept(T o) { return o.compareTo(this.compareFrom) >= 0 && o.compareTo(this.compareTo) <= 0; } } private static final class BetweenInclusiveTo> extends RangePredicate { private static final long serialVersionUID = 1L; private BetweenInclusiveTo(T newCompareFrom, T newCompareTo) { super(newCompareFrom, newCompareTo); } public boolean accept(T o) { return o.compareTo(this.compareFrom) > 0 && o.compareTo(this.compareTo) <= 0; } } private static final class BetweenInclusiveFrom> extends RangePredicate { private static final long serialVersionUID = 1L; private BetweenInclusiveFrom(T newCompareFrom, T newCompareTo) { super(newCompareFrom, newCompareTo); } public boolean accept(T o) { return o.compareTo(this.compareFrom) >= 0 && o.compareTo(this.compareTo) < 0; } } private static final class BetweenExclusive> extends RangePredicate { private static final long serialVersionUID = 1L; private BetweenExclusive(T newCompareFrom, T newCompareTo) { super(newCompareFrom, newCompareTo); } public boolean accept(T o) { return o.compareTo(this.compareFrom) > 0 && o.compareTo(this.compareTo) < 0; } } protected static class LessThanOrEqualPredicate> extends CompareToPredicate { private static final long serialVersionUID = 1L; protected LessThanOrEqualPredicate(T newCompareTo) { super(newCompareTo); } public boolean accept(T o) { return o.compareTo(this.compareTo) <= 0; } @Override public String toString() { return "Predicates.lessThanOrEqualTo(" + this.compareTo + ')'; } } protected static class GreaterThanPredicate> extends CompareToPredicate { private static final long serialVersionUID = 1L; protected GreaterThanPredicate(T newCompareTo) { super(newCompareTo); } public boolean accept(T o) { return o.compareTo(this.compareTo) > 0; } @Override public String toString() { return "Predicates.greaterThan(" + this.compareTo + ')'; } } protected static class GreaterThanOrEqualPredicate> extends CompareToPredicate { private static final long serialVersionUID = 1L; protected GreaterThanOrEqualPredicate(T newCompareTo) { super(newCompareTo); } public boolean accept(T o) { return o.compareTo(this.compareTo) >= 0; } @Override public String toString() { return "Predicates.greaterThanOrEqualTo(" + this.compareTo + ')'; } } private static final class AndIterablePredicate extends AbstractIterablePredicate { private static final long serialVersionUID = 1L; private AndIterablePredicate(Iterable> predicates) { super(predicates); } @Override protected String getTypeName() { return "and"; } public boolean accept(final T anObject) { Predicate> predicate = new Predicate>() { public boolean accept(Predicate aPredicate) { return aPredicate.accept(anObject); } }; return Iterate.allSatisfy(this.predicates, predicate); } } private static final class OrIterablePredicate extends AbstractIterablePredicate { private static final long serialVersionUID = 1L; private OrIterablePredicate(Iterable> predicates) { super(predicates); } @Override protected String getTypeName() { return "or"; } public boolean accept(final T anObject) { Predicate> predicate = new Predicate>() { public boolean accept(Predicate aPredicate) { return aPredicate.accept(anObject); } }; return Iterate.anySatisfy(this.predicates, predicate); } } private static final class NoneOfIterablePredicate extends AbstractIterablePredicate { private static final long serialVersionUID = 1L; private NoneOfIterablePredicate(Iterable> predicates) { super(predicates); } @Override protected String getTypeName() { return "noneOf"; } public boolean accept(final T anObject) { Predicate> predicate = new Predicate>() { public boolean accept(Predicate aPredicate) { return !aPredicate.accept(anObject); } }; return Iterate.allSatisfy(this.predicates, predicate); } } private abstract static class AbstractIterablePredicate extends Predicates { private static final long serialVersionUID = 1L; protected final Iterable> predicates; private AbstractIterablePredicate(Iterable> predicates) { this.predicates = predicates; } protected abstract String getTypeName(); @Override public String toString() { return "Predicates." + this.getTypeName() + '(' + this.predicates + ')'; } } private static final class AndPredicate extends Predicates { private static final long serialVersionUID = 1L; private final Predicate left; private final Predicate right; private AndPredicate(Predicate one, Predicate two) { this.left = one; this.right = two; } public boolean accept(T anObject) { return this.left.accept(anObject) && this.right.accept(anObject); } @Override public String toString() { return this.left + ".and(" + this.right + ')'; } } private static final class NeitherPredicate extends Predicates { private static final long serialVersionUID = 1L; private final Predicate left; private final Predicate right; private NeitherPredicate(Predicate one, Predicate two) { this.left = one; this.right = two; } public boolean accept(T anObject) { return !this.left.accept(anObject) && !this.right.accept(anObject); } @Override public String toString() { return "Predicates.neither(" + this.left + ", " + this.right + ')'; } } private static final class OrPredicate extends Predicates { private static final long serialVersionUID = 1L; private final Predicate left; private final Predicate right; private OrPredicate(Predicate one, Predicate two) { this.left = one; this.right = two; } public boolean accept(T anObject) { return this.left.accept(anObject) || this.right.accept(anObject); } @Override public String toString() { return this.left + ".or(" + this.right + ')'; } } private static final class NotPredicate extends Predicates { private static final long serialVersionUID = 1L; private final Predicate predicate; private NotPredicate(Predicate newPredicate) { this.predicate = newPredicate; } public boolean accept(T anObject) { return !this.predicate.accept(anObject); } @Override public String toString() { return "Predicates.not(" + this.predicate + ')'; } } private static final class EqualPredicate extends Predicates { private static final long serialVersionUID = 1L; private final Object compareObject; private EqualPredicate(Object newCompareObject) { this.compareObject = newCompareObject; } public boolean accept(Object anObject) { return this.compareObject.equals(anObject); } @Override public String toString() { return "Predicates.equal(" + this.compareObject + ')'; } } private static final class InPredicate extends Predicates { private static final long serialVersionUID = 1L; private final Iterable iterable; private InPredicate(Iterable iterable) { this.iterable = iterable; } public boolean accept(Object anObject) { return Iterate.contains(this.iterable, anObject); } @Override public String toString() { return "Predicates.in(" + this.iterable + ')'; } } private static final class NotInPredicate extends Predicates { private static final long serialVersionUID = 1L; private final Iterable iterable; private NotInPredicate(Iterable iterable) { this.iterable = iterable; } public boolean accept(Object anObject) { return !Iterate.contains(this.iterable, anObject); } @Override public String toString() { return "Predicates.notIn(" + this.iterable + ')'; } } private static final class NotEqualPredicate extends Predicates { private static final long serialVersionUID = 1L; private final Object compareObject; private NotEqualPredicate(Object newCompareObject) { this.compareObject = newCompareObject; } public boolean accept(Object anObject) { return !this.compareObject.equals(anObject); } @Override public String toString() { return "Predicates.notEqual(" + this.compareObject + ')'; } } private static final class IsNull extends Predicates { private static final long serialVersionUID = 1L; public boolean accept(Object anObject) { return anObject == null; } @Override public String toString() { return "Predicates.isNull()"; } } private static final class NotNull extends Predicates { private static final long serialVersionUID = 1L; public boolean accept(Object anObject) { return anObject != null; } @Override public String toString() { return "Predicates.notNull()"; } } private static final class AssignableFromPredicate extends Predicates { private static final long serialVersionUID = 1L; private final Class clazz; private AssignableFromPredicate(Class newClass) { this.clazz = newClass; } public boolean accept(Object anObject) { return this.clazz.isAssignableFrom(anObject.getClass()); } @Override public String toString() { return "Predicates.assignableFrom(" + this.clazz.getName() + ".class)"; } } private static final class InstanceOfPredicate extends Predicates { private static final long serialVersionUID = 1L; private final Class clazz; private InstanceOfPredicate(Class newClass) { this.clazz = newClass; } public boolean accept(Object anObject) { return this.clazz.isInstance(anObject); } @Override public String toString() { return "Predicates.instanceOf(" + this.clazz.getName() + ".class)"; } } private static final class NotInstanceOfPredicate extends Predicates { private static final long serialVersionUID = 1L; private final Class clazz; private NotInstanceOfPredicate(Class newClass) { this.clazz = newClass; } public boolean accept(Object anObject) { return !this.clazz.isInstance(anObject); } @Override public String toString() { return "Predicates.notInstanceOf(" + this.clazz.getName() + ".class)"; } } private static final class AlwaysTrue extends Predicates { private static final long serialVersionUID = 1L; public boolean accept(Object anObject) { return true; } @Override public String toString() { return "Predicates.alwaysTrue()"; } } private static final class AlwaysFalse extends Predicates { private static final long serialVersionUID = 1L; public boolean accept(Object anObject) { return false; } @Override public String toString() { return "Predicates.alwaysFalse()"; } } private static final class IdentityPredicate extends Predicates { private static final long serialVersionUID = 1L; private final Object twin; private IdentityPredicate(Object object) { this.twin = object; } public boolean accept(Object anObject) { return this.twin == anObject; } @Override public String toString() { return "Predicates.sameAs(" + this.twin + ')'; } } private static final class NotIdentityPredicate extends Predicates { private static final long serialVersionUID = 1L; private final Object twin; private NotIdentityPredicate(Object object) { this.twin = object; } public boolean accept(Object anObject) { return this.twin != anObject; } @Override public String toString() { return "Predicates.notSameAs(" + this.twin + ')'; } } private static final class SynchronizedPredicate implements Predicate { private static final long serialVersionUID = 1L; private final Predicate predicate; private SynchronizedPredicate(Predicate predicate) { this.predicate = predicate; } public boolean accept(T each) { synchronized (each) { return this.predicate.accept(each); } } } private static final class SubclassPredicate extends Predicates> { private static final long serialVersionUID = 1L; private final Class aClass; private SubclassPredicate(Class aClass) { this.aClass = aClass; } public boolean accept(Class each) { return this.aClass.isAssignableFrom(each); } } private static final class SuperclassPredicate extends Predicates> { private static final long serialVersionUID = 1L; private final Class aClass; private SuperclassPredicate(Class aClass) { this.aClass = aClass; } public boolean accept(Class each) { return each.isAssignableFrom(this.aClass); } } private static final class BindPredicate2 implements Predicate { private static final long serialVersionUID = 1L; private final Predicate2 predicate; private final P parameter; private BindPredicate2(Predicate2 predicate, P parameter) { this.predicate = predicate; this.parameter = parameter; } public boolean accept(T each) { return this.predicate.accept(each, this.parameter); } @Override public String toString() { return "Predicates.bind(" + this.predicate + ", " + this.parameter + ")"; } } } Predicates2.java000066400000000000000000000400221234315411400335500ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/factory/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.factory; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.impl.utility.Iterate; /** * Predicates2 is a static version of Predicates. All of its values are statically initialized, with the exception * of and, or, not and all of the attribute combination methods. Predicates2 can only work with one parameter, * so it is limited to handling only conditions of a simple nature. */ public abstract class Predicates2 implements Predicate2 { private static final long serialVersionUID = 1L; private static final Predicates2 NOT_EQUAL = new NotEqual(); private static final Predicates2> IN = new In(); private static final Predicates2 EQUAL = new Equal(); private static final Predicates2> NOT_IN = new NotIn(); private static final Predicates2 LESS_THAN = new LessThan(); private static final Predicates2 LESS_THAN_OR_EQUAL = new LessThanOrEqual(); private static final Predicates2 GREATER_THAN = new GreaterThan(); private static final Predicates2 GREATER_THAN_OR_EQUAL = new GreaterThanOrEqual(); private static final Predicates2> INSTANCE_OF = new IsInstanceOf(); private static final Predicates2 IS_IDENTICAL = new IsIdentical(); private static final Predicates2 NOT_IDENTITICAL = new NotIdentitical(); private static final Predicates2> NOT_INSTANCE_OF = new NotInstanceOf(); private static final Predicates2 ALWAYS_TRUE = new AlwaysTrue(); private static final Predicates2 ALWAYS_FALSE = new AlwaysFalse(); private static final Predicates2 IS_NULL = new IsNull(); private static final Predicates2 NOT_NULL = new NotNull(); public Predicates2 and(Predicate2 op) { return Predicates2.and(this, op); } public Predicates2 or(Predicate2 op) { return Predicates2.or(this, op); } public static Predicates2 not(Predicate2 predicate) { return new Not(predicate); } public static Predicates2 or( Predicate2 left, Predicate2 right) { return new Or(left, right); } public static Predicates2 and( Predicate2 left, Predicate2 right) { return new And(left, right); } public static Predicates2> attributeIn(Function function) { return new AttributePredicates2(function, Predicates2.in()); } public static Predicates2> attributeNotIn(Function function) { return new AttributePredicates2(function, Predicates2.notIn()); } public static Predicates2 alwaysTrue() { return ALWAYS_TRUE; } public static Predicates2 alwaysFalse() { return ALWAYS_FALSE; } public static Predicates2 isNull() { return IS_NULL; } public static Predicates2 notNull() { return NOT_NULL; } public static Predicates2 equal() { return EQUAL; } public static Predicates2 notEqual() { return NOT_EQUAL; } public static Predicates2> in() { return IN; } public static Predicates2> notIn() { return NOT_IN; } public static > Predicates2 lessThan() { return (Predicates2) LESS_THAN; } public static > Predicates2 lessThanOrEqualTo() { return (Predicates2) LESS_THAN_OR_EQUAL; } public static > Predicates2 greaterThan() { return (Predicates2) GREATER_THAN; } public static Predicates2 sameAs() { return IS_IDENTICAL; } public static Predicates2 notSameAs() { return NOT_IDENTITICAL; } public static Predicates2> instanceOf() { return INSTANCE_OF; } public static Predicates2> notInstanceOf() { return NOT_INSTANCE_OF; } public static > Predicates2 greaterThanOrEqualTo() { return (Predicates2) GREATER_THAN_OR_EQUAL; } public static Predicates2 attributeNotEqual(Function function) { return new AttributePredicates2(function, Predicates2.notEqual()); } public static > Predicates2 attributeLessThan(Function function) { return new AttributePredicates2(function, (Predicate2) LESS_THAN); } public static > Predicates2 attributeLessThanOrEqualTo( Function function) { return new AttributePredicates2(function, (Predicate2) LESS_THAN_OR_EQUAL); } public static > Predicates2 attributeGreaterThan(Function function) { return new AttributePredicates2(function, (Predicate2) GREATER_THAN); } public static > Predicates2 attributeGreaterThanOrEqualTo( Function function) { return new AttributePredicates2(function, (Predicate2) GREATER_THAN_OR_EQUAL); } public static Predicates2 attributeEqual(Function function) { return new AttributePredicates2(function, Predicates2.equal()); } private static final class Or extends Predicates2 { private static final long serialVersionUID = 1L; private final Predicate2 left; private final Predicate2 right; private Or(Predicate2 one, Predicate2 two) { this.left = one; this.right = two; } public boolean accept(T each, P injectedValue) { return this.left.accept(each, injectedValue) || this.right.accept(each, injectedValue); } @Override public String toString() { return "(" + this.left + " or " + this.right + ')'; } } private static final class And extends Predicates2 { private static final long serialVersionUID = 1L; private final Predicate2 left; private final Predicate2 right; private And(Predicate2 one, Predicate2 two) { this.left = one; this.right = two; } public boolean accept(T each, P injectedValue) { return this.left.accept(each, injectedValue) && this.right.accept(each, injectedValue); } @Override public String toString() { return "(" + this.left + " and " + this.right + ')'; } } private static final class AttributePredicates2 extends Predicates2 { private static final long serialVersionUID = 1L; private final Function function; private final Predicate2 predicate; private AttributePredicates2( Function function, Predicate2 predicate) { this.function = function; this.predicate = predicate; } public boolean accept(T each, P injectedValue) { return this.predicate.accept(this.function.valueOf(each), injectedValue); } @Override public String toString() { return this.function + " " + this.predicate; } } private static final class Not extends Predicates2 { private static final long serialVersionUID = 1L; private final Predicate2 predicate; private Not(Predicate2 predicate) { this.predicate = predicate; } public boolean accept(T each, P injectedValue) { return !this.predicate.accept(each, injectedValue); } @Override public String toString() { return "not " + this.predicate; } } private static final class Equal extends Predicates2 { private static final long serialVersionUID = 1L; public boolean accept(Object each, Object compareTo) { if (compareTo == null) { return each == null; } return compareTo.equals(each); } @Override public String toString() { return "= "; } } private static final class In extends Predicates2> { private static final long serialVersionUID = 1L; public boolean accept(Object each, Iterable injectedIterable) { return Iterate.contains(injectedIterable, each); } @Override public String toString() { return "in "; } } private static final class NotIn extends Predicates2> { private static final long serialVersionUID = 1L; public boolean accept(Object each, Iterable injectedIterable) { return !Iterate.contains(injectedIterable, each); } @Override public String toString() { return "not in "; } } private static class LessThan> extends Predicates2 { private static final long serialVersionUID = 1L; public boolean accept(T each, T comparison) { return each.compareTo(comparison) < 0; } @Override public String toString() { return "< "; } } private static class LessThanOrEqual> extends Predicates2 { private static final long serialVersionUID = 1L; public boolean accept(T each, T comparison) { return each.compareTo(comparison) <= 0; } @Override public String toString() { return "<= "; } } private static class GreaterThan> extends Predicates2 { private static final long serialVersionUID = 1L; public boolean accept(T each, T comparison) { return each.compareTo(comparison) > 0; } @Override public String toString() { return "> "; } } private static class GreaterThanOrEqual> extends Predicates2 { private static final long serialVersionUID = 1L; public boolean accept(T each, T comparison) { return each.compareTo(comparison) >= 0; } @Override public String toString() { return ">= "; } } private static final class NotEqual extends Predicates2 { private static final long serialVersionUID = 1L; public boolean accept(Object each, Object compareTo) { if (compareTo == null) { return each != null; } return !compareTo.equals(each); } @Override public String toString() { return "not = "; } } private static final class IsInstanceOf extends Predicates2> { private static final long serialVersionUID = 1L; public boolean accept(Object each, Class injectedClass) { return injectedClass.isInstance(each); } @Override public String toString() { return "is a(n) "; } } private static final class NotInstanceOf extends Predicates2> { private static final long serialVersionUID = 1L; public boolean accept(Object each, Class injectedClass) { return !injectedClass.isInstance(each); } @Override public String toString() { return "is not a(n) "; } } private static final class IsIdentical extends Predicates2 { private static final long serialVersionUID = 1L; public boolean accept(Object each, Object injectedValue) { return each == injectedValue; } @Override public String toString() { return "is identical to "; } } private static final class NotIdentitical extends Predicates2 { private static final long serialVersionUID = 1L; public boolean accept(Object each, Object injectedValue) { return each != injectedValue; } @Override public String toString() { return "is not identical to "; } } private static final class IsNull extends Predicates2 { private static final long serialVersionUID = 1L; public boolean accept(Object each, Object notImportant) { return each == null; } @Override public String toString() { return "is null"; } } private static final class NotNull extends Predicates2 { private static final long serialVersionUID = 1L; public boolean accept(Object each, Object notImportant) { return each != null; } @Override public String toString() { return "not null"; } } private static final class AlwaysTrue extends Predicates2 { private static final long serialVersionUID = 1L; public boolean accept(Object each, Object notImportant) { return true; } @Override public String toString() { return "always true"; } } private static final class AlwaysFalse extends Predicates2 { private static final long serialVersionUID = 1L; public boolean accept(Object each, Object notImportant) { return false; } @Override public String toString() { return "always false"; } } } PrimitiveFunctions.java000066400000000000000000000174441234315411400352600ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/factory/* * Copyright 2012 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.factory; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; public final class PrimitiveFunctions { private static final IntegerIsPositive INTEGER_IS_POSITIVE = new IntegerIsPositive(); private static final UnboxNumberToInt UNBOX_NUMBER_TO_INT = new UnboxNumberToInt(); private static final UnboxIntegerToByte UNBOX_INTEGER_TO_BYTE = new UnboxIntegerToByte(); private static final UnboxIntegerToChar UNBOX_INTEGER_TO_CHAR = new UnboxIntegerToChar(); private static final UnboxIntegerToInt UNBOX_INTEGER_TO_INT = new UnboxIntegerToInt(); private static final UnboxIntegerToFloat UNBOX_INTEGER_TO_FLOAT = new UnboxIntegerToFloat(); private static final UnboxIntegerToLong UNBOX_INTEGER_TO_LONG = new UnboxIntegerToLong(); private static final UnboxIntegerToShort UNBOX_INTEGER_TO_SHORT = new UnboxIntegerToShort(); private static final UnboxIntegerToDouble UNBOX_INTEGER_TO_DOUBLE = new UnboxIntegerToDouble(); private static final UnboxDoubleToDouble UNBOX_DOUBLE_TO_DOUBLE = new UnboxDoubleToDouble(); private static final UnboxFloatToFloat UNBOX_FLOAT_TO_FLOAT = new UnboxFloatToFloat(); private static final UnboxNumberToFloat UNBOX_NUMBER_TO_FLOAT = new UnboxNumberToFloat(); private static final UnboxNumberToLong UNBOX_NUMBER_TO_LONG = new UnboxNumberToLong(); private static final UnboxNumberToDouble UNBOX_NUMBER_TO_DOUBLE = new UnboxNumberToDouble(); private PrimitiveFunctions() { throw new AssertionError("Suppress default constructor for noninstantiability"); } public static BooleanFunction integerIsPositive() { return INTEGER_IS_POSITIVE; } public static IntFunction unboxNumberToInt() { return UNBOX_NUMBER_TO_INT; } public static ByteFunction unboxIntegerToByte() { return UNBOX_INTEGER_TO_BYTE; } public static CharFunction unboxIntegerToChar() { return UNBOX_INTEGER_TO_CHAR; } public static IntFunction unboxIntegerToInt() { return UNBOX_INTEGER_TO_INT; } public static FloatFunction unboxNumberToFloat() { return UNBOX_NUMBER_TO_FLOAT; } public static LongFunction unboxNumberToLong() { return UNBOX_NUMBER_TO_LONG; } public static DoubleFunction unboxNumberToDouble() { return UNBOX_NUMBER_TO_DOUBLE; } public static FloatFunction unboxIntegerToFloat() { return UNBOX_INTEGER_TO_FLOAT; } public static LongFunction unboxIntegerToLong() { return UNBOX_INTEGER_TO_LONG; } public static ShortFunction unboxIntegerToShort() { return UNBOX_INTEGER_TO_SHORT; } public static DoubleFunction unboxIntegerToDouble() { return UNBOX_INTEGER_TO_DOUBLE; } public static DoubleFunction unboxDoubleToDouble() { return UNBOX_DOUBLE_TO_DOUBLE; } public static FloatFunction unboxFloatToFloat() { return UNBOX_FLOAT_TO_FLOAT; } private static class IntegerIsPositive implements BooleanFunction { private static final long serialVersionUID = 1L; public boolean booleanValueOf(Integer integer) { return integer.intValue() > 0; } } private static class UnboxNumberToInt implements IntFunction { private static final long serialVersionUID = 1L; public int intValueOf(Number number) { return number.intValue(); } } private static class UnboxIntegerToByte implements ByteFunction { private static final long serialVersionUID = 1L; public byte byteValueOf(Integer integer) { return integer.byteValue(); } } private static class UnboxIntegerToChar implements CharFunction { private static final long serialVersionUID = 1L; public char charValueOf(Integer integer) { return (char) integer.intValue(); } } private static class UnboxIntegerToInt implements IntFunction { private static final long serialVersionUID = 1L; public int intValueOf(Integer integer) { return integer; } } private static class UnboxIntegerToFloat implements FloatFunction { private static final long serialVersionUID = 1L; public float floatValueOf(Integer integer) { return integer; } } private static class UnboxIntegerToLong implements LongFunction { private static final long serialVersionUID = 1L; public long longValueOf(Integer integer) { return integer; } } private static class UnboxIntegerToShort implements ShortFunction { private static final long serialVersionUID = 1L; public short shortValueOf(Integer integer) { return integer.shortValue(); } } private static class UnboxIntegerToDouble implements DoubleFunction { private static final long serialVersionUID = 1L; public double doubleValueOf(Integer integer) { return integer; } } private static class UnboxDoubleToDouble implements DoubleFunction { private static final long serialVersionUID = 1L; public double doubleValueOf(Double aDouble) { return aDouble; } } private static class UnboxFloatToFloat implements FloatFunction { private static final long serialVersionUID = 1L; public float floatValueOf(Float aFloat) { return aFloat; } } private static class UnboxNumberToFloat implements FloatFunction { private static final long serialVersionUID = 1L; public float floatValueOf(Number number) { return number.floatValue(); } } private static class UnboxNumberToLong implements LongFunction { private static final long serialVersionUID = 1L; public long longValueOf(Number number) { return number.longValue(); } } private static class UnboxNumberToDouble implements DoubleFunction { private static final long serialVersionUID = 1L; public double doubleValueOf(Number number) { return number.doubleValue(); } } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/factory/Procedures.java000066400000000000000000000142011234315411400335750ustar00rootroot00000000000000/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.factory; import java.io.IOException; import java.io.PrintStream; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.impl.block.procedure.CaseProcedure; import com.gs.collections.impl.block.procedure.IfProcedure; /** * Factory class for commonly used procedures. */ public final class Procedures { private Procedures() { throw new AssertionError("Suppress default constructor for noninstantiability"); } /** * Allows a Java 8 lambda and method to be used in a forEach method without requiring a cast. */ public static Procedure cast(Procedure procedure) { return procedure; } public static Procedure println(PrintStream stream) { return new PrintlnProcedure(stream); } public static Procedure append(Appendable appendable) { return new AppendProcedure(appendable); } /** * @deprecated since 1.2 - Inlineable */ @Deprecated public static Procedure fromProcedureWithInt(ObjectIntProcedure objectIntProcedure) { return Procedures.fromObjectIntProcedure(objectIntProcedure); } public static Procedure fromObjectIntProcedure(ObjectIntProcedure objectIntProcedure) { return new ObjectIntProcedureAdapter(objectIntProcedure); } public static Procedure ifTrue(Predicate predicate, Procedure block) { return new IfProcedure(predicate, block); } public static Procedure ifElse( Predicate predicate, Procedure trueProcedure, Procedure falseProcedure) { return new IfProcedure(predicate, trueProcedure, falseProcedure); } public static CaseProcedure caseDefault(Procedure defaultProcedure) { return new CaseProcedure(defaultProcedure); } public static CaseProcedure caseDefault( Procedure defaultProcedure, Predicate predicate, Procedure procedure) { return Procedures.caseDefault(defaultProcedure).addCase(predicate, procedure); } public static Procedure synchronizedEach(Procedure procedure) { return new Procedures.SynchronizedProcedure(procedure); } public static Procedure bind(Procedure2 procedure, P parameter) { return new BindProcedure(procedure, parameter); } private static final class PrintlnProcedure implements Procedure { private static final long serialVersionUID = 1L; private final PrintStream stream; private PrintlnProcedure(PrintStream stream) { this.stream = stream; } public void value(T each) { this.stream.println(each); } } private static final class AppendProcedure implements Procedure { private static final long serialVersionUID = 1L; private final Appendable appendable; private AppendProcedure(Appendable appendable) { this.appendable = appendable; } public void value(T each) { try { this.appendable.append(String.valueOf(each)); } catch (IOException e) { throw new RuntimeException(e); } } @Override public String toString() { return this.appendable.toString(); } } private static final class ObjectIntProcedureAdapter implements Procedure { private static final long serialVersionUID = 2L; private int count; private final ObjectIntProcedure objectIntProcedure; private ObjectIntProcedureAdapter(ObjectIntProcedure objectIntProcedure) { this.objectIntProcedure = objectIntProcedure; } public void value(T each) { this.objectIntProcedure.value(each, this.count); this.count++; } } public static final class SynchronizedProcedure implements Procedure { private static final long serialVersionUID = 1L; private final Procedure procedure; private SynchronizedProcedure(Procedure procedure) { this.procedure = procedure; } public void value(T each) { if (each == null) { this.procedure.value(null); } else { synchronized (each) { this.procedure.value(each); } } } } private static final class BindProcedure implements Procedure { private static final long serialVersionUID = 1L; private final Procedure2 procedure; private final P parameter; private BindProcedure(Procedure2 procedure, P parameter) { this.procedure = procedure; this.parameter = parameter; } public void value(T each) { this.procedure.value(each, this.parameter); } } } Procedures2.java000066400000000000000000000041221234315411400336010ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/factory/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.factory; import java.util.Collection; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; /** * Contains factory methods for creating {@link Procedure2} instances. */ public final class Procedures2 { public static final Procedure2 ADD_TO_COLLECTION = new AddToCollection(); private Procedures2() { throw new AssertionError("Suppress default constructor for noninstantiability"); } public static Procedure2 fromProcedure(Procedure procedure) { return new ProcedureAdapter(procedure); } public static Procedure2> addToCollection() { return (Procedure2>) ADD_TO_COLLECTION; } private static final class ProcedureAdapter implements Procedure2 { private static final long serialVersionUID = 1L; private final Procedure procedure; private ProcedureAdapter(Procedure procedure) { this.procedure = procedure; } public void value(T each, P parameter) { this.procedure.value(each); } } private static class AddToCollection implements Procedure2> { private static final long serialVersionUID = 1L; public void value(T each, Collection target) { target.add(each); } } } StringFunctions.java000066400000000000000000000257141234315411400345550ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/factory/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.factory; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.impl.block.function.primitive.IntegerFunctionImpl; public final class StringFunctions { private static final Function TO_UPPER_CASE = new ToUpperCaseFunction(); private static final Function TO_LOWER_CASE = new ToLowerCaseFunction(); private static final IntegerFunctionImpl LENGTH = new LengthFunction(); private static final Function TRIM = new TrimFunction(); private static final Function FIRST_LETTER = new FirstLetterFunction(); private static final Function TO_INTEGER = new ToIntegerFunction(); private static final BooleanFunction TO_PRIMITIVE_BOOLEAN = new ToPrimitiveBooleanFunction(); private static final ByteFunction TO_PRIMITIVE_BYTE = new ToPrimitiveByteFunction(); private static final CharFunction TO_PRIMITIVE_CHAR = new ToPrimitiveCharFunction(); private static final CharFunction TO_FIRST_CHAR = new ToFirstCharFunction(); private static final DoubleFunction TO_PRIMITIVE_DOUBLE = new ToPrimitiveDoubleFunction(); private static final FloatFunction TO_PRIMITIVE_FLOAT = new ToPrimitiveFloatFunction(); private static final IntFunction TO_PRIMITIVE_INT = new ToPrimitiveIntFunction(); private static final LongFunction TO_PRIMITIVE_LONG = new ToPrimitiveLongFunction(); private static final ShortFunction TO_PRIMITIVE_SHORT = new ToPrimitiveShortFunction(); private StringFunctions() { throw new AssertionError("Suppress default constructor for noninstantiability"); } public static Function toUpperCase() { return TO_UPPER_CASE; } public static Function toLowerCase() { return TO_LOWER_CASE; } public static Function toInteger() { return TO_INTEGER; } public static BooleanFunction toPrimitiveBoolean() { return TO_PRIMITIVE_BOOLEAN; } public static ByteFunction toPrimitiveByte() { return TO_PRIMITIVE_BYTE; } public static CharFunction toPrimitiveChar() { return TO_PRIMITIVE_CHAR; } /** * @throws StringIndexOutOfBoundsException if the String is empty */ public static CharFunction toFirstChar() { return TO_FIRST_CHAR; } public static DoubleFunction toPrimitiveDouble() { return TO_PRIMITIVE_DOUBLE; } public static FloatFunction toPrimitiveFloat() { return TO_PRIMITIVE_FLOAT; } public static IntFunction toPrimitiveInt() { return TO_PRIMITIVE_INT; } public static LongFunction toPrimitiveLong() { return TO_PRIMITIVE_LONG; } public static ShortFunction toPrimitiveShort() { return TO_PRIMITIVE_SHORT; } public static IntegerFunctionImpl length() { return LENGTH; } public static Function firstLetter() { return FIRST_LETTER; } public static Function subString(int beginIndex, int endIndex) { return new SubStringFunction(beginIndex, endIndex); } /** * Returns a function that returns a copy of a {@link String}, with leading and trailing whitespace * omitted. * * @see String#trim() */ public static Function trim() { return TRIM; } public static Function append(String valueToAppend) { return new AppendFunction(valueToAppend); } public static Function prepend(String valueToPrepend) { return new PrependFunction(valueToPrepend); } private static final class ToUpperCaseFunction implements Function { private static final long serialVersionUID = 1L; public String valueOf(String object) { return object.toUpperCase(); } @Override public String toString() { return "string.toUpperCase()"; } } private static final class ToLowerCaseFunction implements Function { private static final long serialVersionUID = 1L; public String valueOf(String object) { return object.toLowerCase(); } @Override public String toString() { return "string.toLowerCase()"; } } private static final class LengthFunction extends IntegerFunctionImpl { private static final long serialVersionUID = 1L; public int intValueOf(String string) { return string.length(); } @Override public String toString() { return "string.length()"; } } private static final class TrimFunction implements Function { private static final long serialVersionUID = 1L; public String valueOf(String string) { return string.trim(); } @Override public String toString() { return "string.trim()"; } } private static final class FirstLetterFunction implements Function { private static final long serialVersionUID = 1L; public Character valueOf(String object) { return object == null || object.length() < 1 ? null : object.charAt(0); } } private static final class ToIntegerFunction implements Function { private static final long serialVersionUID = 1L; public Integer valueOf(String string) { return Integer.valueOf(string); } } private static final class ToPrimitiveBooleanFunction implements BooleanFunction { private static final long serialVersionUID = 1L; public boolean booleanValueOf(String string) { return Boolean.parseBoolean(string); } } private static final class ToPrimitiveByteFunction implements ByteFunction { private static final long serialVersionUID = 1L; public byte byteValueOf(String string) { return Byte.parseByte(string); } } private static final class ToFirstCharFunction implements CharFunction { private static final long serialVersionUID = 1L; public char charValueOf(String string) { return string.charAt(0); } } private static final class ToPrimitiveCharFunction implements CharFunction { private static final long serialVersionUID = 1L; public char charValueOf(String string) { return (char) Integer.parseInt(string); } } private static final class ToPrimitiveDoubleFunction implements DoubleFunction { private static final long serialVersionUID = 1L; public double doubleValueOf(String string) { return Double.parseDouble(string); } } private static final class ToPrimitiveFloatFunction implements FloatFunction { private static final long serialVersionUID = 1L; public float floatValueOf(String string) { return Float.parseFloat(string); } } private static final class ToPrimitiveIntFunction implements IntFunction { private static final long serialVersionUID = 1L; public int intValueOf(String string) { return Integer.parseInt(string); } } private static final class ToPrimitiveLongFunction implements LongFunction { private static final long serialVersionUID = 1L; public long longValueOf(String string) { return Long.parseLong(string); } } private static final class ToPrimitiveShortFunction implements ShortFunction { private static final long serialVersionUID = 1L; public short shortValueOf(String string) { return Short.parseShort(string); } } private static final class SubStringFunction implements Function { private static final long serialVersionUID = 1L; private final int beginIndex; private final int endIndex; private SubStringFunction(int beginIndex, int endIndex) { this.beginIndex = beginIndex; this.endIndex = endIndex; } public String valueOf(String string) { return string.substring(this.beginIndex, this.endIndex); } @Override public String toString() { return "string.subString(" + this.beginIndex + ',' + this.endIndex + ')'; } } private static final class AppendFunction implements Function { private static final long serialVersionUID = 1L; private final String valueToAppend; private AppendFunction(String valueToAppend) { this.valueToAppend = valueToAppend; } public String valueOf(String string) { return string + this.valueToAppend; } } private static final class PrependFunction implements Function { private static final long serialVersionUID = 1L; private final String valueToPrepend; private PrependFunction(String valueToPrepend) { this.valueToPrepend = valueToPrepend; } public String valueOf(String string) { return this.valueToPrepend + string; } } } StringPredicates.java000066400000000000000000000515401234315411400346640ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/factory/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.factory; import com.gs.collections.impl.block.predicate.CodePointPredicate; import com.gs.collections.impl.utility.StringIterate; /** * The StringPredicates class is a factory that produces Predicates that work with Strings. */ public final class StringPredicates { private static final Predicates EMPTY = new Empty(); private static final Predicates NOT_EMPTY = new NotEmpty(); private static final Predicates HAS_LETTERS = new HasLetters(); private static final Predicates HAS_DIGITS = new HasDigits(); private static final Predicates HAS_LETTERS_OR_DIGITS = new HasLettersOrDigits(); private static final Predicates HAS_LETTERS_AND_DIGITS = new HasLettersAndDigits(); private static final Predicates HAS_SPACES = new HasSpaces(); private static final Predicates HAS_UPPERCASE = new HasUppercase(); private static final Predicates HAS_LOWERCASE = new HasLowercase(); private static final Predicates HAS_UNDEFINED = new HasUndefined(); private static final Predicates IS_NUMERIC = new IsNumeric(); private static final Predicates IS_ALPHANUMERIC = new IsAlphanumeric(); private static final Predicates IS_BLANK = new IsBlank(); private static final Predicates NOT_BLANK = new NotBlank(); private static final Predicates IS_ALPHA = new IsAlpha(); private StringPredicates() { throw new AssertionError("Suppress default constructor for noninstantiability"); } public static Predicates empty() { return EMPTY; } public static Predicates notEmpty() { return NOT_EMPTY; } /** * Returns true if a String specified on the predicate is contained within a String passed to the the accept * method. */ public static Predicates contains(String otherString) { return new ContainsString(otherString); } /** * Returns true if a String specified on the predicate is contained within a String passed to the the accept * method. * * @since 5.0 */ public static Predicates notContains(String otherString) { return new NotContainsString(otherString); } /** * Returns true if a char specified on the predicate is contained within a String passed to the the accept * method. */ public static Predicates contains(char character) { return new ContainsCharacter(character); } /** * Returns true if a String passed to the the accept method starts with the string specified on the predicate. */ public static Predicates startsWith(String substring) { return new StartsWith(substring); } /** * Returns true if a String passed to the the accept method ends with the string specified on the predicate. */ public static Predicates endsWith(String substring) { return new EndsWith(substring); } public static Predicates size(int size) { return new Size(size); } public static Predicates equalsIgnoreCase(String otherString) { return new EqualsIgnoreCase(otherString); } public static Predicates matches(String regex) { return new MatchesRegex(regex); } public static Predicates lessThan(String string) { return new LessThan(string); } public static Predicates lessThanOrEqualTo(String string) { return new LessThanOrEqualTo(string); } public static Predicates greaterThan(String string) { return new GreaterThan(string); } public static Predicates greaterThanOrEqualTo(String string) { return new GreaterThanOrEqualTo(string); } public static Predicates hasLetters() { return HAS_LETTERS; } public static Predicates hasDigits() { return HAS_DIGITS; } public static Predicates hasLettersOrDigits() { return HAS_LETTERS_OR_DIGITS; } public static Predicates hasLettersAndDigits() { return HAS_LETTERS_AND_DIGITS; } public static Predicates hasSpaces() { return HAS_SPACES; } public static Predicates hasUpperCase() { return HAS_UPPERCASE; } public static Predicates hasLowerCase() { return HAS_LOWERCASE; } public static Predicates hasUndefined() { return HAS_UNDEFINED; } public static Predicates isNumeric() { return IS_NUMERIC; } public static Predicates isAlphanumeric() { return IS_ALPHANUMERIC; } public static Predicates isBlank() { return IS_BLANK; } public static Predicates notBlank() { return NOT_BLANK; } public static Predicates isAlpha() { return IS_ALPHA; } private static class Empty extends Predicates { private static final long serialVersionUID = 1L; public boolean accept(String anObject) { return anObject != null && anObject.length() == 0; } @Override public String toString() { return false ? "empty" : "StringPredicates.empty()"; } } private static class NotEmpty extends Predicates { private static final long serialVersionUID = 1L; public boolean accept(String anObject) { return anObject != null && anObject.length() > 0; } @Override public String toString() { return false ? "not empty" : "StringPredicates.notEmpty()"; } } private static class HasLetters extends Predicates { private static final long serialVersionUID = 1L; public boolean accept(String anObject) { return StringIterate.anySatisfy(anObject, CodePointPredicate.IS_LETTER); } @Override public String toString() { return false ? "has letters" : "StringPredicates.hasLetters()"; } } private static class HasDigits extends Predicates { private static final long serialVersionUID = 1L; public boolean accept(String anObject) { return StringIterate.anySatisfy(anObject, CodePointPredicate.IS_DIGIT); } @Override public String toString() { return false ? "has digits" : "StringPredicates.hasDigits()"; } } private static class HasLettersOrDigits extends Predicates { private static final long serialVersionUID = 1L; public boolean accept(String anObject) { return StringIterate.anySatisfy(anObject, CodePointPredicate.IS_LETTER_OR_DIGIT); } @Override public String toString() { return false ? "has letters or digits" : "StringPredicates.hasLettersOrDigits()"; } } private static class HasLettersAndDigits extends Predicates { private static final long serialVersionUID = 1L; public boolean accept(String string) { boolean hasLetter = false; boolean hasDigit = false; for (int i = 0; i < string.length(); i++) { if (Character.isLetter(string.codePointAt(i))) { hasLetter = true; } if (Character.isDigit(string.codePointAt(i))) { hasDigit = true; } if (hasLetter && hasDigit) { return true; } } return false; } @Override public String toString() { return false ? "has letters and digits" : "StringPredicates.hasLettersAndDigits()"; } } private static class HasSpaces extends Predicates { private static final long serialVersionUID = 1L; public boolean accept(String anObject) { return StringIterate.anySatisfy(anObject, CodePointPredicate.IS_WHITESPACE); } @Override public String toString() { return false ? "has spaces" : "StringPredicates.hasSpaces()"; } } private static class HasUppercase extends Predicates { private static final long serialVersionUID = 1L; public boolean accept(String anObject) { return StringIterate.anySatisfy(anObject, CodePointPredicate.IS_UPPERCASE); } @Override public String toString() { return false ? "has uppercase" : "StringPredicates.hasUpperCase()"; } } private static class HasLowercase extends Predicates { private static final long serialVersionUID = 1L; public boolean accept(String anObject) { return StringIterate.anySatisfy(anObject, CodePointPredicate.IS_LOWERCASE); } @Override public String toString() { return false ? "has lowercase" : "StringPredicates.hasLowerCase()"; } } private static class HasUndefined extends Predicates { private static final long serialVersionUID = 1L; public boolean accept(String anObject) { return StringIterate.anySatisfy(anObject, CodePointPredicate.IS_UNDEFINED); } @Override public String toString() { return false ? "has undefined" : "StringPredicates.hasUndefined()"; } } private static class IsNumeric extends Predicates { private static final long serialVersionUID = 1L; public boolean accept(String anObject) { return StringIterate.allSatisfy(anObject, CodePointPredicate.IS_DIGIT); } @Override public String toString() { return false ? "is numeric" : "StringPredicates.isNumeric()"; } } private static class IsAlphanumeric extends Predicates { private static final long serialVersionUID = 1L; public boolean accept(String anObject) { return StringIterate.allSatisfy(anObject, CodePointPredicate.IS_LETTER_OR_DIGIT); } @Override public String toString() { return false ? "is alphanumeric" : "StringPredicates.isAlphanumeric()"; } } private static class IsBlank extends Predicates { private static final long serialVersionUID = 1L; public boolean accept(String string) { return StringIterate.isEmptyOrWhitespace(string); } @Override public String toString() { return false ? "is blank" : "StringPredicates.isBlank()"; } } private static class NotBlank extends Predicates { private static final long serialVersionUID = 1L; public boolean accept(String string) { return StringIterate.notEmptyOrWhitespace(string); } @Override public String toString() { return false ? "not blank" : "StringPredicates.notBlank()"; } } private static class IsAlpha extends Predicates { private static final long serialVersionUID = 1L; public boolean accept(String anObject) { return anObject != null && StringIterate.allSatisfy(anObject, CodePointPredicate.IS_LETTER); } @Override public String toString() { return false ? "is alpha" : "StringPredicates.isAlpha()"; } } private static final class ContainsString extends Predicates { private static final long serialVersionUID = 1L; private final String otherString; private ContainsString(String newOtherString) { this.otherString = newOtherString; } public boolean accept(String string) { return StringIterate.notEmpty(string) && string.contains(this.otherString); } @Override public String toString() { return false ? "contains [" + this.otherString + ']' : "StringPredicates.contains(\"" + this.otherString + "\")"; } } private static final class NotContainsString extends Predicates { private static final long serialVersionUID = 1L; private final String otherString; private NotContainsString(String newOtherString) { this.otherString = newOtherString; } public boolean accept(String string) { return StringIterate.isEmpty(string) || !string.contains(this.otherString); } @Override public String toString() { return false ? "not contains [" + this.otherString + ']' : "StringPredicates.notContains(\"" + this.otherString + "\")"; } } private static final class ContainsCharacter extends Predicates { private static final long serialVersionUID = 1L; private final char character; private ContainsCharacter(char newCharacter) { this.character = newCharacter; } public boolean accept(String string) { return StringIterate.notEmpty(string) && string.indexOf(this.character) > -1; } @Override public String toString() { return false ? "contains [" + this.character + ']' : "StringPredicates.contains(\"" + this.character + "\")"; } } private static final class StartsWith extends Predicates { private static final long serialVersionUID = 1L; private final String substring; private StartsWith(String newSubstring) { this.substring = newSubstring; } public boolean accept(String anObject) { return anObject != null && anObject.startsWith(this.substring); } @Override public String toString() { return false ? "starts with [" + this.substring + ']' : "StringPredicates.startsWith(\"" + this.substring + "\")"; } } private static final class EndsWith extends Predicates { private static final long serialVersionUID = 1L; private final String substring; private EndsWith(String newSubstring) { this.substring = newSubstring; } public boolean accept(String anObject) { return anObject != null && anObject.endsWith(this.substring); } @Override public String toString() { return false ? "ends with [" + this.substring + ']' : "StringPredicates.endsWith(\"" + this.substring + "\")"; } } private static final class Size extends Predicates { private static final long serialVersionUID = 1L; private final int size; private Size(int newSize) { this.size = newSize; } public boolean accept(String anObject) { return anObject != null && anObject.length() == this.size; } @Override public String toString() { return false ? "size = " + this.size : "StringPredicates.size(" + this.size + ')'; } } private static final class EqualsIgnoreCase extends Predicates { private static final long serialVersionUID = 1L; private final String otherString; private EqualsIgnoreCase(String newOtherString) { this.otherString = newOtherString; } public boolean accept(String anObject) { return anObject != null && anObject.equalsIgnoreCase(this.otherString); } @Override public String toString() { return false ? "= (ignore case) [" + this.otherString + ']' : "StringPredicates.equalsIgnoreCase(\"" + this.otherString + "\")"; } } private static final class MatchesRegex extends Predicates { private static final long serialVersionUID = 1L; private final String regex; private MatchesRegex(String newRegex) { this.regex = newRegex; } public boolean accept(String anObject) { return anObject != null && anObject.matches(this.regex); } @Override public String toString() { return false ? "matches [" + this.regex + ']' : "StringPredicates.matches(\"" + this.regex + "\")"; } } private static final class LessThan extends Predicates { private static final long serialVersionUID = 1L; private final String string; private LessThan(String newString) { this.string = newString; } public boolean accept(String anObject) { return anObject != null && anObject.compareTo(this.string) < 0; } @Override public String toString() { return false ? "< " + this.string : "StringPredicates.lessThan(\"" + this.string + "\")"; } } private static final class LessThanOrEqualTo extends Predicates { private static final long serialVersionUID = 1L; private final String string; private LessThanOrEqualTo(String newString) { this.string = newString; } public boolean accept(String anObject) { return anObject != null && anObject.compareTo(this.string) <= 0; } @Override public String toString() { return false ? "<= " + this.string : "StringPredicates.lessThanOrEqualTo(\"" + this.string + "\")"; } } private static final class GreaterThan extends Predicates { private static final long serialVersionUID = 1L; private final String string; private GreaterThan(String newString) { this.string = newString; } public boolean accept(String anObject) { return anObject != null && anObject.compareTo(this.string) > 0; } @Override public String toString() { return false ? "> " + this.string : "StringPredicates.greaterThan(\"" + this.string + "\")"; } } private static final class GreaterThanOrEqualTo extends Predicates { private static final long serialVersionUID = 1L; private final String string; private GreaterThanOrEqualTo(String newString) { this.string = newString; } public boolean accept(String anObject) { return anObject != null && anObject.compareTo(this.string) >= 0; } @Override public String toString() { return false ? ">= " + this.string : "StringPredicates.greaterThanOrEqualTo(\"" + this.string + "\")"; } } } StringPredicates2.java000066400000000000000000000163371234315411400347530ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/factory/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.factory; import com.gs.collections.impl.utility.StringIterate; /** * The StringPredicates2 class is a factory that produces Predicate2 instances that work with Strings. */ public final class StringPredicates2 { private static final ContainsString CONTAINS_STRING = new ContainsString(); private static final NotContainsString NOT_CONTAINS_STRING = new NotContainsString(); private static final StartsWith STARTS_WITH = new StartsWith(); private static final NotStartsWith NOT_STARTS_WITH = new NotStartsWith(); private static final EndsWith ENDS_WITH = new EndsWith(); private static final NotEndsWith NOT_ENDS_WITH = new NotEndsWith(); private static final EqualsIgnoreCase EQUALS_IGNORE_CASE = new EqualsIgnoreCase(); private static final NotEqualsIgnoreCase NOT_EQUALS_IGNORE_CASE = new NotEqualsIgnoreCase(); private static final MatchesRegex MATCHES_REGEX = new MatchesRegex(); private StringPredicates2() { throw new AssertionError("Suppress default constructor for noninstantiability"); } /** * Returns true if a String specified on the predicate is contained within a String passed to the the accept * method. */ public static Predicates2 contains() { return CONTAINS_STRING; } /** * Returns true if a String specified on the predicate is contained within a String passed to the the accept * method. * * @since 5.0 */ public static Predicates2 notContains() { return NOT_CONTAINS_STRING; } /** * Returns true if a String passed to the the accept method starts with the string specified on the predicate. */ public static Predicates2 startsWith() { return STARTS_WITH; } /** * Returns false if a String passed to the the accept method starts with the string specified on the predicate. * @since 5.0 */ public static Predicates2 notStartsWith() { return NOT_STARTS_WITH; } /** * Returns true if a String passed to the the accept method ends with the string specified on the predicate. */ public static Predicates2 endsWith() { return ENDS_WITH; } /** * Returns false if a String passed to the the accept method ends with the string specified on the predicate. * @since 5.0 */ public static Predicates2 notEndsWith() { return NOT_ENDS_WITH; } public static Predicates2 equalsIgnoreCase() { return EQUALS_IGNORE_CASE; } /** * @since 5.0 */ public static Predicates2 notEqualsIgnoreCase() { return NOT_EQUALS_IGNORE_CASE; } public static Predicates2 matches() { return MATCHES_REGEX; } private static final class ContainsString extends Predicates2 { private static final long serialVersionUID = 1L; public boolean accept(String each, String parameter) { return StringIterate.notEmpty(each) && each.contains(parameter); } @Override public String toString() { return "StringPredicates2.contains()"; } } private static final class NotContainsString extends Predicates2 { private static final long serialVersionUID = 1L; public boolean accept(String each, String parameter) { return StringIterate.isEmpty(each) || !each.contains(parameter); } @Override public String toString() { return "StringPredicates2.notContains()"; } } private static final class StartsWith extends Predicates2 { private static final long serialVersionUID = 1L; public boolean accept(String each, String parameter) { return each != null && each.startsWith(parameter); } @Override public String toString() { return "StringPredicates2.startsWith()"; } } private static final class NotStartsWith extends Predicates2 { private static final long serialVersionUID = 1L; public boolean accept(String each, String parameter) { return each == null || !each.startsWith(parameter); } @Override public String toString() { return "StringPredicates2.notStartsWith()"; } } private static final class EndsWith extends Predicates2 { private static final long serialVersionUID = 1L; public boolean accept(String each, String parameter) { return each != null && each.endsWith(parameter); } @Override public String toString() { return "StringPredicates2.endsWith()"; } } private static final class NotEndsWith extends Predicates2 { private static final long serialVersionUID = 1L; public boolean accept(String each, String parameter) { return each == null || !each.endsWith(parameter); } @Override public String toString() { return "StringPredicates2.notEndsWith()"; } } private static final class EqualsIgnoreCase extends Predicates2 { private static final long serialVersionUID = 1L; public boolean accept(String each, String parameter) { return each != null && each.equalsIgnoreCase(parameter); } @Override public String toString() { return "StringPredicates2.equalsIgnoreCase()"; } } private static final class NotEqualsIgnoreCase extends Predicates2 { private static final long serialVersionUID = 1L; public boolean accept(String each, String parameter) { return each == null || !each.equalsIgnoreCase(parameter); } @Override public String toString() { return "StringPredicates2.notEqualsIgnoreCase()"; } } private static final class MatchesRegex extends Predicates2 { private static final long serialVersionUID = 1L; public boolean accept(String each, String parameter) { return each != null && each.matches(parameter); } @Override public String toString() { return "StringPredicates2.matches()"; } } } package-info.java000066400000000000000000000016571234315411400337420ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/factory/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains factory implementations for {@link com.gs.collections.api.block.function.Function}, {@link com.gs.collections.api.block.predicate.Predicate}, {@link com.gs.collections.api.block.SerializableComparator} and {@link com.gs.collections.api.block.procedure.Procedure}. */ package com.gs.collections.impl.block.factory; gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/factory/primitive/000077500000000000000000000000001234315411400326315ustar00rootroot00000000000000BooleanPredicates.java000066400000000000000000000153201234315411400370010ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/factory/primitive/* * Copyright 2012 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.factory.primitive; import com.gs.collections.api.block.predicate.primitive.BooleanPredicate; /** * Provides a set of common predicates for boolean values. */ public final class BooleanPredicates { private static final BooleanPredicate IS_TRUE_BOOLEAN_PREDICATE = new IsTrueBooleanPredicate(); private static final BooleanPredicate IS_FALSE_BOOLEAN_PREDICATE = new IsFalseBooleanPredicate(); private static final BooleanPredicate FALSE_PREDICATE = new FalsePredicate(); private static final BooleanPredicate TRUE_PREDICATE = new TruePredicate(); private static final BooleanPredicate ALWAYS_TRUE = new AlwaysTrueBooleanPredicate(); private static final BooleanPredicate ALWAYS_FALSE = new AlwaysFalseBooleanPredicate(); private BooleanPredicates() { throw new AssertionError("Suppress default constructor for noninstantiability"); } @SuppressWarnings("MisspelledEquals") public static BooleanPredicate equal(boolean expected) { return expected ? IS_TRUE_BOOLEAN_PREDICATE : IS_FALSE_BOOLEAN_PREDICATE; } public static BooleanPredicate not(boolean expected) { return expected ? IS_FALSE_BOOLEAN_PREDICATE : IS_TRUE_BOOLEAN_PREDICATE; } public static BooleanPredicate isTrue() { return IS_TRUE_BOOLEAN_PREDICATE; } public static BooleanPredicate isFalse() { return IS_FALSE_BOOLEAN_PREDICATE; } public static BooleanPredicate alwaysTrue() { return ALWAYS_TRUE; } public static BooleanPredicate alwaysFalse() { return ALWAYS_FALSE; } public static BooleanPredicate and(BooleanPredicate one, BooleanPredicate two) { if (one == IS_TRUE_BOOLEAN_PREDICATE && two == IS_TRUE_BOOLEAN_PREDICATE) { return IS_TRUE_BOOLEAN_PREDICATE; } if (one == IS_FALSE_BOOLEAN_PREDICATE && two == IS_TRUE_BOOLEAN_PREDICATE || one == IS_TRUE_BOOLEAN_PREDICATE && two == IS_FALSE_BOOLEAN_PREDICATE) { return FALSE_PREDICATE; } if (one == IS_FALSE_BOOLEAN_PREDICATE && two == IS_FALSE_BOOLEAN_PREDICATE) { return IS_FALSE_BOOLEAN_PREDICATE; } return new AndBooleanPredicate(one, two); } public static BooleanPredicate or(BooleanPredicate one, BooleanPredicate two) { if (one == IS_TRUE_BOOLEAN_PREDICATE && two == IS_TRUE_BOOLEAN_PREDICATE) { return IS_TRUE_BOOLEAN_PREDICATE; } if (one == IS_FALSE_BOOLEAN_PREDICATE && two == IS_TRUE_BOOLEAN_PREDICATE || one == IS_TRUE_BOOLEAN_PREDICATE && two == IS_FALSE_BOOLEAN_PREDICATE) { return TRUE_PREDICATE; } if (one == IS_FALSE_BOOLEAN_PREDICATE && two == IS_FALSE_BOOLEAN_PREDICATE) { return IS_FALSE_BOOLEAN_PREDICATE; } return new OrBooleanPredicate(one, two); } public static BooleanPredicate not(BooleanPredicate negate) { if (negate == IS_TRUE_BOOLEAN_PREDICATE) { return IS_FALSE_BOOLEAN_PREDICATE; } if (negate == IS_FALSE_BOOLEAN_PREDICATE) { return IS_TRUE_BOOLEAN_PREDICATE; } return new NotBooleanPredicate(negate); } private static final class IsTrueBooleanPredicate implements BooleanPredicate { private static final long serialVersionUID = 1L; public boolean accept(boolean value) { return value; } } private static final class IsFalseBooleanPredicate implements BooleanPredicate { private static final long serialVersionUID = 1L; public boolean accept(boolean value) { return !value; } } private static final class AndBooleanPredicate implements BooleanPredicate { private static final long serialVersionUID = 1L; private final BooleanPredicate one; private final BooleanPredicate two; private AndBooleanPredicate(BooleanPredicate one, BooleanPredicate two) { this.one = one; this.two = two; } public boolean accept(boolean actual) { return this.one.accept(actual) && this.two.accept(actual); } } private static final class OrBooleanPredicate implements BooleanPredicate { private static final long serialVersionUID = 1L; private final BooleanPredicate one; private final BooleanPredicate two; private OrBooleanPredicate(BooleanPredicate one, BooleanPredicate two) { this.one = one; this.two = two; } public boolean accept(boolean actual) { return this.one.accept(actual) || this.two.accept(actual); } } private static final class NotBooleanPredicate implements BooleanPredicate { private static final long serialVersionUID = 1L; private final BooleanPredicate negate; private NotBooleanPredicate(BooleanPredicate negate) { this.negate = negate; } public boolean accept(boolean actual) { return !this.negate.accept(actual); } } private static final class FalsePredicate implements BooleanPredicate { private static final long serialVersionUID = 1L; public boolean accept(boolean value) { return false; } } private static final class TruePredicate implements BooleanPredicate { private static final long serialVersionUID = 1L; public boolean accept(boolean value) { return true; } } private static final class AlwaysTrueBooleanPredicate implements BooleanPredicate { private static final long serialVersionUID = 1L; public boolean accept(boolean value) { return true; } } private static final class AlwaysFalseBooleanPredicate implements BooleanPredicate { private static final long serialVersionUID = 1L; public boolean accept(boolean value) { return false; } } } CharToCharFunctions.java000066400000000000000000000034551234315411400372730ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/factory/primitive/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.factory.primitive; import com.gs.collections.api.block.function.primitive.CharToCharFunction; public final class CharToCharFunctions { private static final CharToCharFunction TO_UPPERCASE = new ToUpperCaseCharToCharFunction(); private static final CharToCharFunction TO_LOWERCASE = new ToLowerCaseCharToCharFunction(); private CharToCharFunctions() { throw new AssertionError("Suppress default constructor for noninstantiability"); } public static CharToCharFunction toUpperCase() { return TO_UPPERCASE; } public static CharToCharFunction toLowerCase() { return TO_LOWERCASE; } private static class ToUpperCaseCharToCharFunction implements CharToCharFunction { private static final long serialVersionUID = 1L; public char valueOf(char character) { return Character.toUpperCase(character); } } private static class ToLowerCaseCharToCharFunction implements CharToCharFunction { private static final long serialVersionUID = 1L; public char valueOf(char character) { return Character.toLowerCase(character); } } } IntToIntFunctions.java000066400000000000000000000054561234315411400370300ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/factory/primitive/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.factory.primitive; import com.gs.collections.api.block.function.primitive.IntToIntFunction; public final class IntToIntFunctions { private static final IntToIntFunction INCREMENT = new IncrementIntToIntFunction(); private static final IntToIntFunction DECREMENT = new DecrementIntToIntFunction(); private IntToIntFunctions() { throw new AssertionError("Suppress default constructor for noninstantiability"); } public static IntToIntFunction increment() { return INCREMENT; } public static IntToIntFunction decrement() { return DECREMENT; } public static IntToIntFunction add(int intToAdd) { return new AddIntToIntFunction(intToAdd); } public static IntToIntFunction subtract(int intToSubtract) { return new SubtractIntToIntFunction(intToSubtract); } private static class IncrementIntToIntFunction implements IntToIntFunction { private static final long serialVersionUID = 1L; public int valueOf(int intParameter) { return intParameter + 1; } } private static class DecrementIntToIntFunction implements IntToIntFunction { private static final long serialVersionUID = 1L; public int valueOf(int intParameter) { return intParameter - 1; } } private static final class AddIntToIntFunction implements IntToIntFunction { private static final long serialVersionUID = 1L; private final int intToAdd; private AddIntToIntFunction(int intToAdd) { this.intToAdd = intToAdd; } public int valueOf(int intParameter) { return intParameter + this.intToAdd; } } private static final class SubtractIntToIntFunction implements IntToIntFunction { private static final long serialVersionUID = 1L; private final int intToSubtract; private SubtractIntToIntFunction(int intToSubtract) { this.intToSubtract = intToSubtract; } public int valueOf(int intParameter) { return intParameter - this.intToSubtract; } } } package-info.java000066400000000000000000000014501234315411400357410ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/factory/primitive/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains factory implementations for primitive functions, primitive predicates, primitive procedures and primitive comparators. */ package com.gs.collections.impl.block.factory.primitive; gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/function/000077500000000000000000000000001234315411400307775ustar00rootroot00000000000000AddFunction.java000066400000000000000000000135301234315411400337630ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/function/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.function; import java.util.Collection; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.DoubleObjectToDoubleFunction; import com.gs.collections.api.block.function.primitive.FloatObjectToFloatFunction; import com.gs.collections.api.block.function.primitive.IntObjectToIntFunction; import com.gs.collections.api.block.function.primitive.LongObjectToLongFunction; /** * Provides static Function2s which can be used by Iterate.injectInto for adding primitives or to a collection */ public final class AddFunction { public static final IntObjectToIntFunction INTEGER_TO_INT = new AddIntegerToIntFunction(); public static final LongObjectToLongFunction INTEGER_TO_LONG = new AddIntegerToLongFunction(); public static final DoubleObjectToDoubleFunction INTEGER_TO_DOUBLE = new AddIntegerToDoubleFunction(); public static final FloatObjectToFloatFunction INTEGER_TO_FLOAT = new AddIntegerToFloatFunction(); public static final DoubleObjectToDoubleFunction DOUBLE_TO_DOUBLE = new AddDoubleToDoubleFunction(); public static final Function2 INTEGER = new AddIntegerFunction(); public static final Function2 DOUBLE = new AddDoubleFunction(); public static final Function2 FLOAT = new AddFloatFunction(); public static final Function2 LONG = new AddLongFunction(); public static final Function2 STRING = new AddStringFunction(); public static final Function2, ?, Collection> COLLECTION = new AddCollectionFunction(); private AddFunction() { throw new AssertionError("Suppress default constructor for noninstantiability"); } private static class AddIntegerToIntFunction implements IntObjectToIntFunction { private static final long serialVersionUID = 1L; public int intValueOf(int intParameter, Integer objectParameter) { return intParameter + objectParameter; } } private static class AddIntegerToLongFunction implements LongObjectToLongFunction { private static final long serialVersionUID = 1L; public long longValueOf(long longParameter, Integer objectParameter) { return longParameter + objectParameter.longValue(); } } private static class AddIntegerToDoubleFunction implements DoubleObjectToDoubleFunction { private static final long serialVersionUID = 1L; public double doubleValueOf(double doubleParameter, Integer objectParameter) { return doubleParameter + objectParameter; } } private static class AddIntegerToFloatFunction implements FloatObjectToFloatFunction { private static final long serialVersionUID = 1L; public float floatValueOf(float floatParameter, Integer objectParameter) { return floatParameter + objectParameter; } } private static class AddDoubleToDoubleFunction implements DoubleObjectToDoubleFunction { private static final long serialVersionUID = 1L; public double doubleValueOf(double doubleParameter, Double objectParameter) { return doubleParameter + objectParameter; } } private static class AddIntegerFunction implements Function2 { private static final long serialVersionUID = 1L; public Integer value(Integer argument1, Integer argument2) { return argument1 + argument2; } } private static class AddDoubleFunction implements Function2 { private static final long serialVersionUID = 1L; public Double value(Double argument1, Double argument2) { return argument1 + argument2; } } private static class AddFloatFunction implements Function2 { private static final long serialVersionUID = 1L; public Float value(Float argument1, Float argument2) { return argument1 + argument2; } } private static class AddLongFunction implements Function2 { private static final long serialVersionUID = 1L; public Long value(Long argument1, Long argument2) { return argument1 + argument2; } } private static class AddStringFunction implements Function2 { private static final long serialVersionUID = 1L; public String value(String argument1, String argument2) { if (argument1 != null && argument2 != null) { return argument1 + argument2; } return argument1 == null ? argument2 : argument1; } } private static class AddCollectionFunction implements Function2, T, Collection> { private static final long serialVersionUID = 1L; public Collection value(Collection collection, T addElement) { collection.add(addElement); return collection; } } } CaseFunction.java000066400000000000000000000046751234315411400341600ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/function/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.function; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.tuple.Pair; import com.gs.collections.impl.factory.Lists; import com.gs.collections.impl.tuple.Tuples; public class CaseFunction, V> implements Function { private static final long serialVersionUID = 1L; private final MutableList, Function>> predicateFunctions = Lists.mutable.of(); private Function defaultFunction; public CaseFunction() { } public CaseFunction(Function newDefaultFunction) { this.defaultFunction = newDefaultFunction; } public CaseFunction addCase( Predicate predicate, Function function) { this.predicateFunctions.add(Tuples., Function>pair(predicate, function)); return this; } public CaseFunction setDefault(Function function) { this.defaultFunction = function; return this; } public V valueOf(T argument) { for (Pair, Function> pair : this.predicateFunctions) { if (pair.getOne().accept(argument)) { return pair.getTwo().valueOf(argument); } } if (this.defaultFunction != null) { return this.defaultFunction.valueOf(argument); } return null; } @Override public String toString() { return "new CaseFunction(" + this.predicateFunctions + ')'; } } IfFunction.java000066400000000000000000000036741234315411400336410ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/function/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.function; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.predicate.Predicate; public class IfFunction implements Function { private static final long serialVersionUID = 1L; private final Predicate predicate; private final Function function; private final Function elseFunction; public IfFunction( Predicate newPredicate, Function function) { this(newPredicate, function, null); } public IfFunction(Predicate predicate, Function function, Function elseFunction) { this.predicate = predicate; this.function = function; this.elseFunction = elseFunction; } public V valueOf(T object) { if (this.predicate.accept(object)) { return this.function.valueOf(object); } if (this.elseFunction != null) { return this.elseFunction.valueOf(object); } return null; } @Override public String toString() { return "new IfFunction(" + this.predicate + ", " + this.function + ", " + this.elseFunction + ')'; } } MaxFunction.java000066400000000000000000000054051234315411400340220ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/function/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.function; import com.gs.collections.api.block.function.Function2; /** * MaxFunction contains iterator aware implementations of Max() for integers, doubles, and longs. */ public final class MaxFunction { public static final Function2 INTEGER = new MaxIntegerFunction(); public static final Function2 DOUBLE = new MaxDoubleFunction(); public static final Function2 LONG = new MaxLongFunction(); private MaxFunction() { throw new AssertionError("Suppress default constructor for noninstantiability"); } private static class MaxIntegerFunction implements Function2 { private static final long serialVersionUID = 1L; public Integer value(Integer argument1, Integer argument2) { if (argument1 == null) { return argument2; } if (argument2 == null) { return argument1; } return argument1.intValue() > argument2.intValue() ? argument1 : argument2; } } private static class MaxDoubleFunction implements Function2 { private static final long serialVersionUID = 1L; public Double value(Double argument1, Double argument2) { if (argument1 == null) { return argument2; } if (argument2 == null) { return argument1; } return argument1.doubleValue() > argument2.doubleValue() ? argument1 : argument2; } } private static class MaxLongFunction implements Function2 { private static final long serialVersionUID = 1L; public Long value(Long argument1, Long argument2) { if (argument1 == null) { return argument2; } if (argument2 == null) { return argument1; } return argument1.longValue() > argument2.longValue() ? argument1 : argument2; } } } MaxSizeFunction.java000066400000000000000000000043431234315411400346550ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/function/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.function; import java.util.Collection; import java.util.Map; import com.gs.collections.api.block.function.Function2; /** * MaxSizeFunction compares the size of strings, collections, or maps to determine the max size. */ public final class MaxSizeFunction { public static final Function2 STRING = new MaxSizeStringFunction(); public static final Function2, Integer> COLLECTION = new MaxSizeCollectionFunction(); public static final Function2, Integer> MAP = new MaxSizeMapFunction(); private MaxSizeFunction() { throw new AssertionError("Suppress default constructor for noninstantiability"); } private static class MaxSizeStringFunction implements Function2 { private static final long serialVersionUID = 1L; public Integer value(Integer previousMax, String s) { return Math.max(previousMax, s.length()); } } private static class MaxSizeCollectionFunction implements Function2, Integer> { private static final long serialVersionUID = 1L; public Integer value(Integer previousMax, Collection collection) { return Math.max(previousMax, collection.size()); } } private static class MaxSizeMapFunction implements Function2, Integer> { private static final long serialVersionUID = 1L; public Integer value(Integer previousMax, Map map) { return Math.max(previousMax, map.size()); } } } MinFunction.java000066400000000000000000000054051234315411400340200ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/function/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.function; import com.gs.collections.api.block.function.Function2; /** * MinFunction contains iterator aware implementations of Min() for integers, doubles, and longs. */ public final class MinFunction { public static final Function2 INTEGER = new MinIntegerFunction(); public static final Function2 DOUBLE = new MinDoubleFunction(); public static final Function2 LONG = new MinLongFunction(); private MinFunction() { throw new AssertionError("Suppress default constructor for noninstantiability"); } private static class MinIntegerFunction implements Function2 { private static final long serialVersionUID = 1L; public Integer value(Integer argument1, Integer argument2) { if (argument1 == null) { return argument2; } if (argument2 == null) { return argument1; } return argument1.intValue() < argument2.intValue() ? argument1 : argument2; } } private static class MinDoubleFunction implements Function2 { private static final long serialVersionUID = 1L; public Double value(Double argument1, Double argument2) { if (argument1 == null) { return argument2; } if (argument2 == null) { return argument1; } return argument1.doubleValue() < argument2.doubleValue() ? argument1 : argument2; } } private static class MinLongFunction implements Function2 { private static final long serialVersionUID = 1L; public Long value(Long argument1, Long argument2) { if (argument1 == null) { return argument2; } if (argument2 == null) { return argument1; } return argument1.longValue() < argument2.longValue() ? argument1 : argument2; } } } MinSizeFunction.java000066400000000000000000000043431234315411400346530ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/function/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.function; import java.util.Collection; import java.util.Map; import com.gs.collections.api.block.function.Function2; /** * MinSizeFunction compares the size of strings, collections, or maps to determine the min size. */ public final class MinSizeFunction { public static final Function2 STRING = new MinSizeStringFunction(); public static final Function2, Integer> COLLECTION = new MinSizeCollectionFunction(); public static final Function2, Integer> MAP = new MinSizeMapFunction(); private MinSizeFunction() { throw new AssertionError("Suppress default constructor for noninstantiability"); } private static class MinSizeStringFunction implements Function2 { private static final long serialVersionUID = 1L; public Integer value(Integer previousMin, String s) { return Math.min(previousMin, s.length()); } } private static class MinSizeCollectionFunction implements Function2, Integer> { private static final long serialVersionUID = 1L; public Integer value(Integer previousMin, Collection collection) { return Math.min(previousMin, collection.size()); } } private static class MinSizeMapFunction implements Function2, Integer> { private static final long serialVersionUID = 1L; public Integer value(Integer previousMin, Map map) { return Math.min(previousMin, map.size()); } } } MultiplyFunction.java000066400000000000000000000037531234315411400351200ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/function/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.function; import com.gs.collections.api.block.function.Function2; public final class MultiplyFunction { public static final Function2 INTEGER = new MultiplyIntegerFunction(); public static final Function2 DOUBLE = new MultiplyDoubleFunction(); public static final Function2 LONG = new MultiplyLongFunction(); private MultiplyFunction() { throw new AssertionError("Suppress default constructor for noninstantiability"); } private static class MultiplyIntegerFunction implements Function2 { private static final long serialVersionUID = 1L; public Integer value(Integer argument1, Integer argument2) { return argument1 * argument2; } } private static class MultiplyDoubleFunction implements Function2 { private static final long serialVersionUID = 1L; public Double value(Double argument1, Double argument2) { return argument1 * argument2; } } private static class MultiplyLongFunction implements Function2 { private static final long serialVersionUID = 1L; public Long value(Long argument1, Long argument2) { return argument1 * argument2; } } } PassThruFunction0.java000066400000000000000000000020671234315411400351270ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/function/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.function; import com.gs.collections.api.block.function.Function0; /** * A passthru Function0 which returns the value specified. */ public final class PassThruFunction0 implements Function0 { private static final long serialVersionUID = 1L; private final T result; public PassThruFunction0(T newResult) { this.result = newResult; } public T value() { return this.result; } } SubtractFunction.java000066400000000000000000000041421234315411400350610ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/function/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.function; import com.gs.collections.api.block.function.Function2; /** * Provides static Function2s which can be used by Iterate.injectInto for adding primitives or to a collection */ public final class SubtractFunction { public static final Function2 INTEGER = new SubtractIntegerFunction(); public static final Function2 DOUBLE = new SubtractDoubleFunction(); public static final Function2 LONG = new SubtractLongFunction(); private SubtractFunction() { throw new AssertionError("Suppress default constructor for noninstantiability"); } private static class SubtractIntegerFunction implements Function2 { private static final long serialVersionUID = 1L; public Integer value(Integer argument1, Integer argument2) { return argument1 - argument2; } } private static class SubtractDoubleFunction implements Function2 { private static final long serialVersionUID = 1L; public Double value(Double argument1, Double argument2) { return argument1 - argument2; } } private static class SubtractLongFunction implements Function2 { private static final long serialVersionUID = 1L; public Long value(Long argument1, Long argument2) { return argument1 - argument2; } } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/function/checked/000077500000000000000000000000001234315411400323655ustar00rootroot00000000000000CheckedFunction.java000066400000000000000000000024251234315411400362100ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/function/checked/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.function.checked; import com.gs.collections.api.block.function.Function; public abstract class CheckedFunction implements Function { private static final long serialVersionUID = 1L; public final V valueOf(T anObject) { try { return this.safeValueOf(anObject); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException("Checked exception caught in Function", e); } } @SuppressWarnings("ProhibitedExceptionDeclared") public abstract V safeValueOf(T object) throws Exception; } CheckedFunction0.java000066400000000000000000000023631234315411400362710ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/function/checked/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.function.checked; import com.gs.collections.api.block.function.Function0; public abstract class CheckedFunction0 implements Function0 { private static final long serialVersionUID = 1L; public final R value() { try { return this.safeValue(); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException("Checked exception caught in Function0", e); } } @SuppressWarnings("ProhibitedExceptionDeclared") public abstract R safeValue() throws Exception; } CheckedFunction2.java000066400000000000000000000025131234315411400362700ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/function/checked/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.function.checked; import com.gs.collections.api.block.function.Function2; public abstract class CheckedFunction2 implements Function2 { private static final long serialVersionUID = 1L; public final R value(T1 argument1, T2 argument2) { try { return this.safeValue(argument1, argument2); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException("Checked exception caught in Function2", e); } } @SuppressWarnings("ProhibitedExceptionDeclared") public abstract R safeValue(T1 argument1, T2 argument2) throws Exception; } package-info.java000066400000000000000000000015711234315411400355010ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/function/checked/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains abstract implementations of {@link com.gs.collections.api.block.function.Function}, {@link com.gs.collections.api.block.function.Function0} and {@link com.gs.collections.api.block.function.Function2}. */ package com.gs.collections.impl.block.function.checked; package-info.java000066400000000000000000000015501234315411400341100ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/function/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains implementations of {@link com.gs.collections.api.block.function.Function}, {@link com.gs.collections.api.block.function.Function0} and {@link com.gs.collections.api.block.function.Function2}. */ package com.gs.collections.impl.block.function; gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/function/primitive/000077500000000000000000000000001234315411400330075ustar00rootroot00000000000000CharFunction.java000066400000000000000000000027311234315411400361610ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/function/primitive/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.function.primitive; import java.io.Serializable; import com.gs.collections.api.block.function.primitive.CharToCharFunction; /** * A CharFunction can be used to convert one character to another. * * @deprecated since 3.0. Use {@link CharToCharFunction} instead. */ @Deprecated public interface CharFunction extends Serializable { CharFunction TO_UPPERCASE = new CharFunction() { private static final long serialVersionUID = 1L; public char valueOf(char character) { return Character.toUpperCase(character); } }; CharFunction TO_LOWERCASE = new CharFunction() { private static final long serialVersionUID = 1L; public char valueOf(char character) { return Character.toLowerCase(character); } }; char valueOf(char character); } CodePointFunction.java000066400000000000000000000025171234315411400371720ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/function/primitive/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.function.primitive; import java.io.Serializable; /** * A CharFunction can be used to convert one character to another. */ public interface CodePointFunction extends Serializable { CodePointFunction TO_UPPERCASE = new CodePointFunction() { private static final long serialVersionUID = 1L; public int valueOf(int codePoint) { return Character.toUpperCase(codePoint); } }; CodePointFunction TO_LOWERCASE = new CodePointFunction() { private static final long serialVersionUID = 1L; public int valueOf(int codePoint) { return Character.toLowerCase(codePoint); } }; int valueOf(int codePoint); } DoubleFunctionImpl.java000066400000000000000000000025701234315411400373410ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/function/primitive/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.function.primitive; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.primitive.DoubleFunction; /** * DoubleFunctionImpl is an abstract implementation of the DoubleFunction interface which can be subclassed * explicitly or as an anonymous inner class, without needing to override the valueOf method defined in * Function. */ public abstract class DoubleFunctionImpl implements Function, DoubleFunction { private static final long serialVersionUID = 1L; private static final Double DOUBLE_ZERO = 0.0; public Double valueOf(T anObject) { double value = this.doubleValueOf(anObject); return value == 0.0 ? DOUBLE_ZERO : Double.valueOf(value); } } IntegerFunctionImpl.java000066400000000000000000000023611234315411400375220ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/function/primitive/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.function.primitive; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.primitive.IntFunction; /** * IntegerFunctionImpl is an abstract implementation of the IntFunction interface which can be subclassed * explicitly or as an anonymous inner class, without needing to override the valueOf method defined in * Function. */ public abstract class IntegerFunctionImpl implements IntFunction, Function { private static final long serialVersionUID = 1L; public Integer valueOf(T anObject) { return this.intValueOf(anObject); } } LongFunctionImpl.java000066400000000000000000000023511234315411400370230ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/function/primitive/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.function.primitive; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.primitive.LongFunction; /** * LongFunctionImpl is an abstract implementation of the LongFunction interface which can be subclassed * explicitly or as an anonymous inner class, without needing to override the valueOf method defined in * Function. */ public abstract class LongFunctionImpl implements Function, LongFunction { private static final long serialVersionUID = 1L; public Long valueOf(T anObject) { return this.longValueOf(anObject); } } package-info.java000066400000000000000000000013321234315411400361160ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/function/primitive/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains implementations of primitive functions. */ package com.gs.collections.impl.block.function.primitive; gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/predicate/000077500000000000000000000000001234315411400311125ustar00rootroot00000000000000CodePointPredicate.java000066400000000000000000000050501234315411400354030ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/predicate/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.predicate; import java.io.Serializable; /** * A Predicate that accepts an int value */ public interface CodePointPredicate extends Serializable { CodePointPredicate IS_UPPERCASE = new CodePointPredicate() { private static final long serialVersionUID = 1L; public boolean accept(int codePoint) { return Character.isUpperCase(codePoint); } }; CodePointPredicate IS_LOWERCASE = new CodePointPredicate() { private static final long serialVersionUID = 1L; public boolean accept(int codePoint) { return Character.isLowerCase(codePoint); } }; CodePointPredicate IS_DIGIT = new CodePointPredicate() { private static final long serialVersionUID = 1L; public boolean accept(int codePoint) { return Character.isDigit(codePoint); } }; CodePointPredicate IS_LETTER = new CodePointPredicate() { private static final long serialVersionUID = 1L; public boolean accept(int codePoint) { return Character.isLetter(codePoint); } }; CodePointPredicate IS_LETTER_OR_DIGIT = new CodePointPredicate() { private static final long serialVersionUID = 1L; public boolean accept(int codePoint) { return Character.isLetterOrDigit(codePoint); } }; CodePointPredicate IS_WHITESPACE = new CodePointPredicate() { private static final long serialVersionUID = 1L; public boolean accept(int codePoint) { return Character.isWhitespace(codePoint); } }; CodePointPredicate IS_UNDEFINED = new CodePointPredicate() { private static final long serialVersionUID = 1L; public boolean accept(int codePoint) { return !Character.isDefined(codePoint); } }; boolean accept(int codePoint); } DropIterablePredicate.java000066400000000000000000000020661234315411400360770ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/predicate/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.predicate; import com.gs.collections.api.block.predicate.Predicate; public class DropIterablePredicate implements Predicate { private static final long serialVersionUID = 1L; private final int count; private int index; public DropIterablePredicate(int count) { this.count = count; this.index = 0; } public boolean accept(T each) { return this.index++ >= this.count; } } MapEntryPredicate.java000066400000000000000000000020771234315411400352640ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/predicate/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.predicate; import java.util.Map; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; public abstract class MapEntryPredicate implements Predicate>, Predicate2 { private static final long serialVersionUID = 1L; public boolean accept(Map.Entry entry) { return this.accept(entry.getKey(), entry.getValue()); } } PairPredicate.java000066400000000000000000000020771234315411400344200ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/predicate/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.predicate; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.tuple.Pair; public abstract class PairPredicate implements Predicate>, Predicate2 { private static final long serialVersionUID = 1L; public boolean accept(Pair pair) { return this.accept(pair.getOne(), pair.getTwo()); } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/predicate/checked/000077500000000000000000000000001234315411400325005ustar00rootroot00000000000000CheckedPredicate.java000066400000000000000000000024361234315411400364400ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/predicate/checked/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.predicate.checked; import com.gs.collections.api.block.predicate.Predicate; public abstract class CheckedPredicate implements Predicate { private static final long serialVersionUID = 1L; public final boolean accept(T anObject) { try { return this.safeAccept(anObject); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException("Checked exception caught in Predicate", e); } } @SuppressWarnings("ProhibitedExceptionDeclared") public abstract boolean safeAccept(T object) throws Exception; } CheckedPredicate2.java000066400000000000000000000024621234315411400365210ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/predicate/checked/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.predicate.checked; import com.gs.collections.api.block.predicate.Predicate2; public abstract class CheckedPredicate2 implements Predicate2 { private static final long serialVersionUID = 1L; public boolean accept(T item, P param) { try { return this.safeAccept(item, param); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException("Checked exception caught in Predicate", e); } } @SuppressWarnings("ProhibitedExceptionDeclared") public abstract boolean safeAccept(T object, P param) throws Exception; } package-info.java000066400000000000000000000015051234315411400356110ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/predicate/checked/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains abstract implementations of {@link com.gs.collections.api.block.predicate.Predicate} and {@link com.gs.collections.api.block.predicate.Predicate2}. */ package com.gs.collections.impl.block.predicate.checked; package-info.java000066400000000000000000000014641234315411400342270ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/predicate/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains implementations of {@link com.gs.collections.api.block.predicate.Predicate} and {@link com.gs.collections.api.block.predicate.Predicate2}. */ package com.gs.collections.impl.block.predicate; gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/predicate/primitive/000077500000000000000000000000001234315411400331225ustar00rootroot00000000000000CharPredicate.java000066400000000000000000000055631234315411400364150ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/predicate/primitive/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.predicate.primitive; import java.io.Serializable; /** * A Predicate that accepts a char value * * @deprecated since 3.0. Use {@link com.gs.collections.api.block.predicate.primitive.CharPredicate} instead. */ @Deprecated public interface CharPredicate extends Serializable { CharPredicate IS_UPPERCASE = new CharPredicate() { private static final long serialVersionUID = 1L; public boolean accept(char character) { return Character.isUpperCase(character); } }; CharPredicate IS_LOWERCASE = new CharPredicate() { private static final long serialVersionUID = 1L; public boolean accept(char character) { return Character.isLowerCase(character); } }; CharPredicate IS_DIGIT = new CharPredicate() { private static final long serialVersionUID = 1L; public boolean accept(char character) { return Character.isDigit(character); } }; CharPredicate IS_DIGIT_OR_DOT = new CharPredicate() { private static final long serialVersionUID = 1L; public boolean accept(char character) { return Character.isDigit(character) || character == '.'; } }; CharPredicate IS_LETTER = new CharPredicate() { private static final long serialVersionUID = 1L; public boolean accept(char character) { return Character.isLetter(character); } }; CharPredicate IS_LETTER_OR_DIGIT = new CharPredicate() { private static final long serialVersionUID = 1L; public boolean accept(char character) { return Character.isLetterOrDigit(character); } }; CharPredicate IS_WHITESPACE = new CharPredicate() { private static final long serialVersionUID = 1L; public boolean accept(char character) { return Character.isWhitespace(character); } }; CharPredicate IS_UNDEFINED = new CharPredicate() { private static final long serialVersionUID = 1L; public boolean accept(char character) { return !Character.isDefined(character); } }; boolean accept(char character); } package-info.java000066400000000000000000000013341234315411400362330ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/predicate/primitive/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains implementations of primitive predicates. */ package com.gs.collections.impl.block.predicate.primitive; gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/000077500000000000000000000000001234315411400311425ustar00rootroot00000000000000AtomicCountProcedure.java000066400000000000000000000026741234315411400360350ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure; import java.util.concurrent.atomic.AtomicInteger; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; /** * Applies a predicate to an object and increments a count if it returns true. */ public class AtomicCountProcedure implements Procedure { private static final long serialVersionUID = 1L; private final Predicate predicate; private final AtomicInteger count = new AtomicInteger(0); public AtomicCountProcedure(Predicate predicate) { this.predicate = predicate; } public void value(T object) { if (this.predicate.accept(object)) { this.count.incrementAndGet(); } } public int getCount() { return this.count.get(); } } BagAddOccurrencesProcedure.java000066400000000000000000000030211234315411400370710ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure; import com.gs.collections.api.bag.MutableBag; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; /** * @since 5.0. */ public final class BagAddOccurrencesProcedure implements ObjectIntProcedure { private static final long serialVersionUID = 1L; private final MutableBag mutableBag; public BagAddOccurrencesProcedure(MutableBag mutableBag) { this.mutableBag = mutableBag; } public static BagAddOccurrencesProcedure on(MutableBag mutableBag) { return new BagAddOccurrencesProcedure(mutableBag); } public void value(T each, int occurrences) { this.mutableBag.addOccurrences(each, occurrences); } public MutableBag getResult() { return this.mutableBag; } @Override public String toString() { return "MutableBag.addOccurrences()"; } } CaseProcedure.java000066400000000000000000000051411234315411400344530ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure; import java.util.List; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.tuple.Pair; import com.gs.collections.impl.factory.Lists; import com.gs.collections.impl.tuple.Tuples; /** * CaseProcedure allows developers to create an object form of a case statement, which instead of being based on * a single switch value is based on a list of predicate / procedure combinations. For the first predicate * that returns true for a given value in the case statement, the corresponding procedure will be executed. */ public final class CaseProcedure implements Procedure { private static final long serialVersionUID = 1L; private final List, Procedure>> predicateProcedures = Lists.mutable.of(); private Procedure defaultProcedure; public CaseProcedure(Procedure defaultProcedure) { this.defaultProcedure = defaultProcedure; } public CaseProcedure() { } public CaseProcedure addCase(Predicate predicate, Procedure procedure) { this.predicateProcedures.add(Tuples., Procedure>pair(predicate, procedure)); return this; } public CaseProcedure setDefault(Procedure procedure) { this.defaultProcedure = procedure; return this; } public void value(T argument) { for (Pair, Procedure> pair : this.predicateProcedures) { if (pair.getOne().accept(argument)) { pair.getTwo().value(argument); return; } } if (this.defaultProcedure != null) { this.defaultProcedure.value(argument); } } @Override public String toString() { return "new CaseProcedure(" + this.predicateProcedures + ')'; } } ChainedProcedure.java000066400000000000000000000034771234315411400351450ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure; import java.util.List; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.impl.list.mutable.FastList; /** * ChainedProcedure allows a developer to chain together procedure to be executed in sequence. */ public final class ChainedProcedure implements Procedure { private static final long serialVersionUID = 1L; private final List> procedures = FastList.newList(3); public static ChainedProcedure with(Procedure procedure1, Procedure procedure2) { ChainedProcedure chainedProcedure = new ChainedProcedure(); chainedProcedure.addProcedure(procedure1); chainedProcedure.addProcedure(procedure2); return chainedProcedure; } public void addProcedure(Procedure procedure) { this.procedures.add(procedure); } public void value(T object) { int size = this.procedures.size(); for (int i = 0; i < size; i++) { this.procedures.get(i).value(object); } } @Override public String toString() { return "ChainedProcedure.with(" + this.procedures + ')'; } } CollectIfProcedure.java000066400000000000000000000036171234315411400354520ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure; import java.util.Collection; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.impl.list.mutable.FastList; public final class CollectIfProcedure implements Procedure { private static final long serialVersionUID = 1L; private final Function function; private final Predicate predicate; private final Collection collection; public CollectIfProcedure(int taskSize, Function function, Predicate predicate) { this(FastList.newList(taskSize), function, predicate); } public CollectIfProcedure(Collection targetCollection, Function function, Predicate predicate) { this.function = function; this.predicate = predicate; this.collection = targetCollection; } public void value(T object) { if (this.predicate.accept(object)) { this.collection.add(this.function.valueOf(object)); } } public Collection getCollection() { return this.collection; } } CollectProcedure.java000066400000000000000000000027561234315411400351760ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2012 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure; import java.util.Collection; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.procedure.Procedure; /** * Applies a function to an object and adds the result to a target collection. */ public final class CollectProcedure implements Procedure { private static final long serialVersionUID = 1L; private final Function function; private final Collection collection; public CollectProcedure(Function function, Collection targetCollection) { this.function = function; this.collection = targetCollection; } public void value(T object) { V value = this.function.valueOf(object); this.collection.add(value); } public Collection getCollection() { return this.collection; } } CollectionAddProcedure.java000066400000000000000000000030201234315411400362760ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure; import java.util.Collection; import com.gs.collections.api.block.procedure.Procedure; /** * CollectionAddProcedure adds elements to the specified collection when one of the block methods are called. */ public final class CollectionAddProcedure implements Procedure { private static final long serialVersionUID = 1L; private final Collection collection; public CollectionAddProcedure(Collection newCollection) { this.collection = newCollection; } public static CollectionAddProcedure on(Collection newCollection) { return new CollectionAddProcedure(newCollection); } public void value(T object) { this.collection.add(object); } public Collection getResult() { return this.collection; } @Override public String toString() { return "Collection.add()"; } } CollectionRemoveProcedure.java000066400000000000000000000030551234315411400370530ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure; import java.util.Collection; import com.gs.collections.api.block.procedure.Procedure; /** * CollectionRemoveProcedure removes element from the specified collection when one of the procedure methods are called. */ public final class CollectionRemoveProcedure implements Procedure { private static final long serialVersionUID = 1L; private final Collection collection; public CollectionRemoveProcedure(Collection newCollection) { this.collection = newCollection; } public static CollectionRemoveProcedure on(Collection newCollection) { return new CollectionRemoveProcedure(newCollection); } public void value(T object) { this.collection.remove(object); } public Collection getResult() { return this.collection; } @Override public String toString() { return "Collection.remove()"; } } ComparatorProcedure.java000066400000000000000000000024441234315411400357120ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure; import java.util.Comparator; import java.util.NoSuchElementException; import com.gs.collections.api.block.procedure.Procedure; public abstract class ComparatorProcedure implements Procedure { private static final long serialVersionUID = 1L; protected final Comparator comparator; protected boolean visitedAtLeastOnce; protected T result; protected ComparatorProcedure(Comparator comparator) { this.comparator = comparator; } public T getResult() { if (!this.visitedAtLeastOnce) { throw new NoSuchElementException(); } return this.result; } } CountProcedure.java000066400000000000000000000027171234315411400346760ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.impl.block.factory.Predicates; /** * Applies a predicate to an object and increments a count if it returns true. */ public class CountProcedure implements Procedure { private static final long serialVersionUID = 1L; private final Predicate predicate; private int count; public CountProcedure(Predicate newPredicate) { this.predicate = newPredicate; } public CountProcedure() { this(Predicates.alwaysTrue()); } public void value(T object) { if (this.predicate.accept(object)) { this.count++; } } public int getCount() { return this.count; } } CounterProcedure.java000066400000000000000000000027251234315411400352240ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure; import com.gs.collections.api.block.procedure.Procedure; /** * CounterProcedure wraps a specified procedure and keeps track of the number of times it is executed. */ public final class CounterProcedure implements Procedure { private static final long serialVersionUID = 1L; private int count = 0; private final Procedure procedure; public CounterProcedure(Procedure procedure) { this.procedure = procedure; } public void value(T object) { this.incrementCounter(); this.procedure.value(object); } private void incrementCounter() { this.count++; } public int getCount() { return this.count; } @Override public String toString() { return "counter: " + this.count + " procedure: " + this.procedure; } } FastListCollectIfProcedure.java000066400000000000000000000033251234315411400371200ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2012 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.impl.list.mutable.FastList; public final class FastListCollectIfProcedure implements Procedure { private static final long serialVersionUID = 1L; private final Function function; private final Predicate predicate; private final FastList fastList; public FastListCollectIfProcedure( FastList targetCollection, Function function, Predicate predicate) { this.function = function; this.predicate = predicate; this.fastList = targetCollection; } public void value(T object) { if (this.predicate.accept(object)) { V value = this.function.valueOf(object); this.fastList.add(value); } } public FastList getFastList() { return this.fastList; } } FastListCollectProcedure.java000066400000000000000000000030041234315411400366330ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2012 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.impl.list.mutable.FastList; /** * Applies a function to an object and adds the result to a target fastList. */ public final class FastListCollectProcedure implements Procedure { private static final long serialVersionUID = 1L; private final Function function; private final FastList fastList; public FastListCollectProcedure(Function function, FastList targetCollection) { this.function = function; this.fastList = targetCollection; } public void value(T object) { V value = this.function.valueOf(object); this.fastList.add(value); } public FastList getFastList() { return this.fastList; } } FastListRejectProcedure.java000066400000000000000000000030271234315411400364670ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2012 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.impl.list.mutable.FastList; /** * Applies a predicate to an object to determine if it should be added to a target fastList. */ public final class FastListRejectProcedure implements Procedure { private static final long serialVersionUID = 1L; private final Predicate predicate; private final FastList fastList; public FastListRejectProcedure(Predicate newPredicate, FastList targetCollection) { this.predicate = newPredicate; this.fastList = targetCollection; } public void value(T object) { if (!this.predicate.accept(object)) { this.fastList.add(object); } } public FastList getFastList() { return this.fastList; } } FastListSelectProcedure.java000066400000000000000000000030471234315411400364740ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2012 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.impl.list.mutable.FastList; /** * Applies a predicate to an object to determine if it should be added to a target fastList. * * @since 1.0 */ public final class FastListSelectProcedure implements Procedure { private static final long serialVersionUID = 1L; private final Predicate predicate; private final FastList fastList; public FastListSelectProcedure(Predicate newPredicate, FastList targetCollection) { this.predicate = newPredicate; this.fastList = targetCollection; } public void value(T object) { if (this.predicate.accept(object)) { this.fastList.add(object); } } public FastList getFastList() { return this.fastList; } } FlatCollectProcedure.java000066400000000000000000000031161234315411400357740ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure; import java.util.Collection; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.impl.utility.Iterate; /** * Applies a function to an object and adds the result to a target collection. */ public final class FlatCollectProcedure implements Procedure { private static final long serialVersionUID = 1L; private final Function> function; private final Collection collection; public FlatCollectProcedure( Function> function, Collection targetCollection) { this.function = function; this.collection = targetCollection; } public void value(T object) { Iterate.addAllIterable(this.function.valueOf(object), this.collection); } public Collection getCollection() { return this.collection; } } IfObjectIntProcedure.java000066400000000000000000000032671234315411400357470ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.impl.Counter; /** * A conditional ObjectIntProcedure that effectively filters which objects should be used */ public final class IfObjectIntProcedure implements Procedure { private static final long serialVersionUID = 2L; private final Counter index = new Counter(); private final ObjectIntProcedure objectIntProcedure; private final Predicate predicate; public IfObjectIntProcedure(Predicate newPredicate, ObjectIntProcedure objectIntProcedure) { this.predicate = newPredicate; this.objectIntProcedure = objectIntProcedure; } public void value(T object) { if (this.predicate.accept(object)) { this.objectIntProcedure.value(object, this.index.getCount()); this.index.increment(); } } } IfProcedure.java000066400000000000000000000042451234315411400341420ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; /** * IfProcedure allows developers to evaluate the specified procedure only when either predicate returns true. * If the result of evaluating the predicate is false, and the developer has specified that there * is an elseProcedure, then the elseProcedure is evaluated. */ public final class IfProcedure implements Procedure { private static final long serialVersionUID = 1L; private final Predicate predicate; private final Procedure procedure; private final Procedure elseProcedure; public IfProcedure( Predicate predicate, Procedure procedure, Procedure elseProcedure) { this.predicate = predicate; this.procedure = procedure; this.elseProcedure = elseProcedure; } public IfProcedure(Predicate predicate, Procedure procedure) { this(predicate, procedure, null); } public void value(T object) { if (this.predicate.accept(object)) { this.procedure.value(object); } else { if (this.elseProcedure != null) { this.elseProcedure.value(object); } } } @Override public String toString() { return "new IfProcedure(" + this.predicate + ", " + this.procedure + ", " + this.elseProcedure + ')'; } } IfProcedureWith.java000066400000000000000000000027071234315411400347770ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure2; /** * A conditional parameterized two argument procedure that effectively filters which objects should be used */ public final class IfProcedureWith implements Procedure2 { private static final long serialVersionUID = 1L; private final Procedure2 procedure; private final Predicate predicate; public IfProcedureWith(Predicate newPredicate, Procedure2 procedure) { this.predicate = newPredicate; this.procedure = procedure; } public void value(T each, P parm) { if (this.predicate.accept(each)) { this.procedure.value(each, parm); } } } MapCollectProcedure.java000066400000000000000000000035341234315411400356270ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure; import java.util.Map; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.impl.block.factory.Functions; /** * MapCollectProcedure uses an Function to calculate the key for an object and puts the object with the key * into the specified Map. */ public final class MapCollectProcedure implements Procedure { private static final long serialVersionUID = 1L; private final Map map; private final Function keyFunction; private final Function valueFunction; public MapCollectProcedure(Map newMap, Function newKeyFunction) { this(newMap, newKeyFunction, (Function) Functions.getPassThru()); } public MapCollectProcedure(Map newMap, Function newKeyFunction, Function newValueFunction) { this.map = newMap; this.keyFunction = newKeyFunction; this.valueFunction = newValueFunction; } public void value(T object) { this.map.put(this.keyFunction.valueOf(object), this.valueFunction.valueOf(object)); } } MapEntryToProcedure2.java000066400000000000000000000027251234315411400357310ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure; import java.util.Map; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; /** * MapEntryToProcedure2 translates the result of calling entrySet() on a Map, which results in a collection * of Map.Entry objects into corresponding Procedure2s. This removes the need to deal with Map.Entry when * iterating over an entrySet. */ public final class MapEntryToProcedure2 implements Procedure> { private static final long serialVersionUID = 1L; private final Procedure2 procedure; public MapEntryToProcedure2(Procedure2 procedure) { this.procedure = procedure; } public void value(Map.Entry entry) { this.procedure.value(entry.getKey(), entry.getValue()); } } MapPutProcedure.java000066400000000000000000000021441234315411400350060ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure; import java.util.Map; import com.gs.collections.api.block.procedure.Procedure2; /** * Transfers keys and values from one map to another */ public class MapPutProcedure implements Procedure2 { private static final long serialVersionUID = 1L; private final Map newMap; public MapPutProcedure(Map newMap) { this.newMap = newMap; } public void value(K key, V value) { this.newMap.put(key, value); } } MaxComparatorProcedure.java000066400000000000000000000025771234315411400363670ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure; import java.util.Comparator; import com.gs.collections.api.block.procedure.Procedure; /** * Implementation of {@link Procedure } that holds on to the maximum element seen so far, * determined by the {@link Comparator} */ public class MaxComparatorProcedure extends ComparatorProcedure { private static final long serialVersionUID = 1L; public MaxComparatorProcedure(Comparator comparator) { super(comparator); } public void value(T each) { if (!this.visitedAtLeastOnce) { this.visitedAtLeastOnce = true; this.result = each; } else if (this.comparator.compare(each, this.result) > 0) { this.result = each; } } } MinComparatorProcedure.java000066400000000000000000000025731234315411400363610ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure; import java.util.Comparator; import com.gs.collections.api.block.procedure.Procedure; /** * Implementation of {@link Procedure} that holds on to the minimum element seen so far, * determined by the {@link Comparator} */ public class MinComparatorProcedure extends ComparatorProcedure { private static final long serialVersionUID = 1L; public MinComparatorProcedure(Comparator comparator) { super(comparator); } public void value(T each) { if (!this.visitedAtLeastOnce) { this.visitedAtLeastOnce = true; this.result = each; } else if (this.comparator.compare(each, this.result) < 0) { this.result = each; } } } MultimapEachPutProcedure.java000066400000000000000000000042271234315411400366460ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.multimap.MutableMultimap; import com.gs.collections.impl.utility.Iterate; /** * MultimapEachPutProcedure uses an Function to calculate the keys for an object and puts the object with each of * the keys into the specified {@link MutableMultimap}. */ public final class MultimapEachPutProcedure implements Procedure { private static final long serialVersionUID = 1L; private final MutableMultimap multimap; private final Function> keyFunction; private final Procedure2 eachProcedure = new Procedure2() { public void value(K key, V value) { MultimapEachPutProcedure.this.multimap.put(key, value); } }; public MultimapEachPutProcedure( MutableMultimap multimap, Function> keyFunction) { this.multimap = multimap; this.keyFunction = keyFunction; } public static MultimapEachPutProcedure on( MutableMultimap multimap, Function> keyFunction) { return new MultimapEachPutProcedure(multimap, keyFunction); } public void value(V each) { Iterate.forEachWith(this.keyFunction.valueOf(each), this.eachProcedure, each); } } MultimapPutProcedure.java000066400000000000000000000034301234315411400360600ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2012 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.multimap.MutableMultimap; /** * MultimapPutProcedure uses an Function to calculate the key for an object and puts the object with the key * into the specified {@link MutableMultimap}. */ public final class MultimapPutProcedure implements Procedure { private static final long serialVersionUID = 1L; private final MutableMultimap multimap; private final Function keyFunction; public MultimapPutProcedure( MutableMultimap multimap, Function keyFunction) { this.multimap = multimap; this.keyFunction = keyFunction; } public static MultimapPutProcedure on( MutableMultimap multimap, Function keyFunction) { return new MultimapPutProcedure(multimap, keyFunction); } public void value(V each) { K key = this.keyFunction.valueOf(each); this.multimap.put(key, each); } } MutatingAggregationProcedure.java000066400000000000000000000041311234315411400375360ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2012 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.map.MutableMap; /** * This procedure is used to apply an aggregate function like sum on a grouped set of data. The values in the * grouping must be mutable using this procedure. An example would be using an AtomicInteger which can be mutated * vs. an Integer which cannot. */ public final class MutatingAggregationProcedure implements Procedure { private static final long serialVersionUID = 1L; private final MutableMap map; private final Function groupBy; private final Function0 zeroValueFactory; private final Procedure2 mutatingAggregator; public MutatingAggregationProcedure(MutableMap map, Function groupBy, Function0 zeroValueFactory, Procedure2 mutatingAggregator) { this.map = map; this.groupBy = groupBy; this.zeroValueFactory = zeroValueFactory; this.mutatingAggregator = mutatingAggregator; } public void value(T each) { K key = this.groupBy.valueOf(each); V value = this.map.getIfAbsentPut(key, this.zeroValueFactory); this.mutatingAggregator.value(value, each); } } NonMutatingAggregationProcedure.java000066400000000000000000000041461234315411400402170ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2012 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.map.MutableMap; /** * This procedure is used to apply an aggregate function like sum on a grouped set of data. The values in the * grouping must be immutable using this procedure. An example would be using an Integer which is immutable * vs. an AtomicInteger which is not. */ public final class NonMutatingAggregationProcedure implements Procedure { private static final long serialVersionUID = 1L; private final MutableMap map; private final Function groupBy; private final Function0 zeroValueFactory; private final Function2 nonMutatingAggregator; public NonMutatingAggregationProcedure(MutableMap map, Function groupBy, Function0 zeroValueFactory, Function2 nonMutatingAggregator) { this.map = map; this.groupBy = groupBy; this.zeroValueFactory = zeroValueFactory; this.nonMutatingAggregator = nonMutatingAggregator; } public void value(T each) { K key = this.groupBy.valueOf(each); this.map.updateValueWith(key, this.zeroValueFactory, this.nonMutatingAggregator, each); } } PartitionPredicate2Procedure.java000066400000000000000000000033661234315411400374630ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.collection.MutableCollection; import com.gs.collections.api.partition.PartitionMutableCollection; public class PartitionPredicate2Procedure implements Procedure { private static final long serialVersionUID = 1L; private final Predicate2 predicate; private final P parameter; private final PartitionMutableCollection partitionMutableCollection; public PartitionPredicate2Procedure(Predicate2 predicate, P parameter, PartitionMutableCollection partitionMutableCollection) { this.predicate = predicate; this.parameter = parameter; this.partitionMutableCollection = partitionMutableCollection; } public void value(T each) { MutableCollection bucket = this.predicate.accept(each, this.parameter) ? this.partitionMutableCollection.getSelected() : this.partitionMutableCollection.getRejected(); bucket.add(each); } } PartitionProcedure.java000066400000000000000000000031461234315411400355540ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.collection.MutableCollection; import com.gs.collections.api.partition.PartitionMutableCollection; public class PartitionProcedure implements Procedure { private static final long serialVersionUID = 1L; private final Predicate predicate; private final PartitionMutableCollection partitionMutableCollection; public PartitionProcedure(Predicate predicate, PartitionMutableCollection partitionMutableCollection) { this.predicate = predicate; this.partitionMutableCollection = partitionMutableCollection; } public void value(T each) { MutableCollection bucket = this.predicate.accept(each) ? this.partitionMutableCollection.getSelected() : this.partitionMutableCollection.getRejected(); bucket.add(each); } } RejectProcedure.java000066400000000000000000000030011234315411400350050ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure; import java.util.Collection; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; /** * Applies a predicate to an object to determine if it should be added to a target collection. */ public final class RejectProcedure implements Procedure { private static final long serialVersionUID = 1L; private final Predicate predicate; private final Collection collection; public RejectProcedure(Predicate newPredicate, Collection targetCollection) { this.predicate = newPredicate; this.collection = targetCollection; } public void value(T object) { if (!this.predicate.accept(object)) { this.collection.add(object); } } public Collection getCollection() { return this.collection; } } SelectInstancesOfProcedure.java000066400000000000000000000027411234315411400371570ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2012 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure; import java.util.Collection; import com.gs.collections.api.block.procedure.Procedure; /** * Calls {@link Class#isInstance(Object)} on an object to determine if it should be added to a target collection. * * @since 2.0 */ public final class SelectInstancesOfProcedure implements Procedure { private static final long serialVersionUID = 1L; private final Class clazz; private final Collection collection; public SelectInstancesOfProcedure(Class clazz, Collection targetCollection) { this.clazz = clazz; this.collection = targetCollection; } public void value(Object object) { if (this.clazz.isInstance(object)) { this.collection.add((T) object); } } public Collection getCollection() { return this.collection; } } SelectProcedure.java000066400000000000000000000030211234315411400350120ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure; import java.util.Collection; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; /** * Applies a predicate to an object to determine if it should be added to a target collection. * * @since 1.0 */ public final class SelectProcedure implements Procedure { private static final long serialVersionUID = 1L; private final Predicate predicate; private final Collection collection; public SelectProcedure(Predicate newPredicate, Collection targetCollection) { this.predicate = newPredicate; this.collection = targetCollection; } public void value(T object) { if (this.predicate.accept(object)) { this.collection.add(object); } } public Collection getCollection() { return this.collection; } } ZipWithIndexProcedure.java000066400000000000000000000030371234315411400361700ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure; import java.util.Collection; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.tuple.Pair; import com.gs.collections.impl.tuple.Tuples; /** * Creates a PairImpl of objects and their indexes and adds the result to a target collection. */ public final class ZipWithIndexProcedure>> implements Procedure { private static final long serialVersionUID = 1L; private int index = 0; private final R target; public ZipWithIndexProcedure(R target) { this.target = target; } public static >> ZipWithIndexProcedure create(RR target) { return new ZipWithIndexProcedure(target); } public void value(T each) { this.target.add(Tuples.pair(each, Integer.valueOf(this.index))); this.index += 1; } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/checked/000077500000000000000000000000001234315411400325305ustar00rootroot00000000000000CheckedObjectIntProcedure.java000066400000000000000000000025141234315411400403170ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/checked/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure.checked; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; public abstract class CheckedObjectIntProcedure implements ObjectIntProcedure { private static final long serialVersionUID = 1L; public final void value(T object, int index) { try { this.safeValue(object, index); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException("Checked exception caught in Procedure", e); } } @SuppressWarnings("ProhibitedExceptionDeclared") public abstract void safeValue(T object, int index) throws Exception; } CheckedProcedure.java000066400000000000000000000024021234315411400365110ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/checked/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure.checked; import com.gs.collections.api.block.procedure.Procedure; public abstract class CheckedProcedure implements Procedure { private static final long serialVersionUID = 1L; public final void value(T object) { try { this.safeValue(object); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException("Checked exception caught in Procedure", e); } } @SuppressWarnings("ProhibitedExceptionDeclared") public abstract void safeValue(T object) throws Exception; } CheckedProcedure2.java000066400000000000000000000024461234315411400366030ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/checked/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure.checked; import com.gs.collections.api.block.procedure.Procedure2; public abstract class CheckedProcedure2 implements Procedure2 { private static final long serialVersionUID = 1L; public void value(T item, P parameter) { try { this.safeValue(item, parameter); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException("Checked exception caught in Predicate", e); } } @SuppressWarnings("ProhibitedExceptionDeclared") public abstract void safeValue(T object, P parameter) throws Exception; } MultimapKeyValuesSerializingProcedure.java000066400000000000000000000027621234315411400430160ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/checked/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure.checked; import java.io.IOException; import java.io.ObjectOutput; import com.gs.collections.api.RichIterable; public class MultimapKeyValuesSerializingProcedure extends CheckedProcedure2> { private static final long serialVersionUID = 1L; private final ObjectOutput out; public MultimapKeyValuesSerializingProcedure(ObjectOutput out) { this.out = out; } @Override public void safeValue(K key, RichIterable iterable) throws IOException { this.out.writeObject(key); this.out.writeInt(iterable.size()); iterable.forEach(new CheckedProcedure() { @Override public void safeValue(V object) throws IOException { MultimapKeyValuesSerializingProcedure.this.out.writeObject(object); } }); } } package-info.java000066400000000000000000000015051234315411400356410ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/checked/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains abstract implementations of {@link com.gs.collections.api.block.procedure.Procedure} and {@link com.gs.collections.api.block.procedure.Procedure2}. */ package com.gs.collections.impl.block.procedure.checked; 000077500000000000000000000000001234315411400344615ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/checked/primitiveCheckedBooleanIntProcedure.java000066400000000000000000000027341234315411400425040ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/checked/primitive/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure.checked.primitive; import com.gs.collections.api.block.procedure.primitive.BooleanIntProcedure; /** * This file was automatically generated from template file checkedPrimitivePrimitiveProcedure.stg. * * @since 4.0. */ public abstract class CheckedBooleanIntProcedure implements BooleanIntProcedure { private static final long serialVersionUID = 1L; public final void value(boolean item1, int item2) { try { this.safeValue(item1, item2); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException("Checked exception caught in BooleanIntProcedure", e); } } @SuppressWarnings("ProhibitedExceptionDeclared") public abstract void safeValue(boolean item1, int item2) throws Exception; } package-info.java000066400000000000000000000013551234315411400376540ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/checked/primitive/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains abstract implementations of primitive procedures. */ package com.gs.collections.impl.block.procedure.checked.primitive; package-info.java000066400000000000000000000014641234315411400342570ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains implementations of {@link com.gs.collections.api.block.procedure.Procedure} and {@link com.gs.collections.api.block.procedure.Procedure2}. */ package com.gs.collections.impl.block.procedure; gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/primitive/000077500000000000000000000000001234315411400331525ustar00rootroot00000000000000CharProcedure.java000066400000000000000000000015161234315411400364670ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/primitive/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure.primitive; /** * @deprecated since 3.0 use {@link com.gs.collections.api.block.procedure.primitive.CharProcedure} */ @Deprecated public interface CharProcedure { void value(char character); } CodePointProcedure.java000066400000000000000000000013321234315411400374720ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/primitive/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure.primitive; public interface CodePointProcedure { void value(int codePoint); } CollectBooleanProcedure.java000066400000000000000000000032721234315411400405000ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/primitive/* * Copyright 2012 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure.primitive; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.collection.primitive.MutableBooleanCollection; /** * Applies a booleanFunction to an object and adds the result to a target boolean collection. */ public final class CollectBooleanProcedure implements Procedure { private static final long serialVersionUID = 1L; private final BooleanFunction booleanFunction; private final MutableBooleanCollection booleanCollection; public CollectBooleanProcedure(BooleanFunction booleanFunction, MutableBooleanCollection targetCollection) { this.booleanFunction = booleanFunction; this.booleanCollection = targetCollection; } public void value(T object) { boolean value = this.booleanFunction.booleanValueOf(object); this.booleanCollection.add(value); } public MutableBooleanCollection getBooleanCollection() { return this.booleanCollection; } } CollectByteProcedure.java000066400000000000000000000031651234315411400400250ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/primitive/* * Copyright 2012 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure.primitive; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.collection.primitive.MutableByteCollection; /** * Applies a byteFunction to an object and adds the result to a target byte collection. */ public final class CollectByteProcedure implements Procedure { private static final long serialVersionUID = 1L; private final ByteFunction byteFunction; private final MutableByteCollection byteCollection; public CollectByteProcedure(ByteFunction byteFunction, MutableByteCollection targetCollection) { this.byteFunction = byteFunction; this.byteCollection = targetCollection; } public void value(T object) { byte value = this.byteFunction.byteValueOf(object); this.byteCollection.add(value); } public MutableByteCollection getByteCollection() { return this.byteCollection; } } CollectCharProcedure.java000066400000000000000000000031651234315411400377770ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/primitive/* * Copyright 2012 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure.primitive; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.collection.primitive.MutableCharCollection; /** * Applies a charFunction to an object and adds the result to a target char collection. */ public final class CollectCharProcedure implements Procedure { private static final long serialVersionUID = 1L; private final CharFunction charFunction; private final MutableCharCollection charCollection; public CollectCharProcedure(CharFunction charFunction, MutableCharCollection targetCollection) { this.charFunction = charFunction; this.charCollection = targetCollection; } public void value(T object) { char value = this.charFunction.charValueOf(object); this.charCollection.add(value); } public MutableCharCollection getCharCollection() { return this.charCollection; } } CollectDoubleProcedure.java000066400000000000000000000032431234315411400403310ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/primitive/* * Copyright 2012 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure.primitive; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.collection.primitive.MutableDoubleCollection; /** * Applies a doubleFunction to an object and adds the result to a target double collection. */ public final class CollectDoubleProcedure implements Procedure { private static final long serialVersionUID = 1L; private final DoubleFunction doubleFunction; private final MutableDoubleCollection doubleCollection; public CollectDoubleProcedure(DoubleFunction doubleFunction, MutableDoubleCollection targetCollection) { this.doubleFunction = doubleFunction; this.doubleCollection = targetCollection; } public void value(T object) { double value = this.doubleFunction.doubleValueOf(object); this.doubleCollection.add(value); } public MutableDoubleCollection getDoubleCollection() { return this.doubleCollection; } } CollectFloatProcedure.java000066400000000000000000000032141234315411400401620ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/primitive/* * Copyright 2012 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure.primitive; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.collection.primitive.MutableFloatCollection; /** * Applies a floatFunction to an object and adds the result to a target float collection. */ public final class CollectFloatProcedure implements Procedure { private static final long serialVersionUID = 1L; private final FloatFunction floatFunction; private final MutableFloatCollection floatCollection; public CollectFloatProcedure(FloatFunction floatFunction, MutableFloatCollection targetCollection) { this.floatFunction = floatFunction; this.floatCollection = targetCollection; } public void value(T object) { float value = this.floatFunction.floatValueOf(object); this.floatCollection.add(value); } public MutableFloatCollection getFloatCollection() { return this.floatCollection; } } CollectIntProcedure.java000066400000000000000000000031371234315411400376530ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/primitive/* * Copyright 2012 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure.primitive; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.collection.primitive.MutableIntCollection; /** * Applies an intFunction to an object and adds the result to a target int collection. */ public final class CollectIntProcedure implements Procedure { private static final long serialVersionUID = 1L; private final IntFunction intFunction; private final MutableIntCollection intCollection; public CollectIntProcedure(IntFunction intFunction, MutableIntCollection targetCollection) { this.intFunction = intFunction; this.intCollection = targetCollection; } public void value(T object) { int value = this.intFunction.intValueOf(object); this.intCollection.add(value); } public MutableIntCollection getIntCollection() { return this.intCollection; } } CollectLongProcedure.java000066400000000000000000000031651234315411400400210ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/primitive/* * Copyright 2012 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure.primitive; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.collection.primitive.MutableLongCollection; /** * Applies a longFunction to an object and adds the result to a target long collection. */ public final class CollectLongProcedure implements Procedure { private static final long serialVersionUID = 1L; private final LongFunction longFunction; private final MutableLongCollection longCollection; public CollectLongProcedure(LongFunction longFunction, MutableLongCollection targetCollection) { this.longFunction = longFunction; this.longCollection = targetCollection; } public void value(T object) { long value = this.longFunction.longValueOf(object); this.longCollection.add(value); } public MutableLongCollection getLongCollection() { return this.longCollection; } } CollectShortProcedure.java000066400000000000000000000032141234315411400402140ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/primitive/* * Copyright 2012 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure.primitive; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.collection.primitive.MutableShortCollection; /** * Applies a shortFunction to an object and adds the result to a target short collection. */ public final class CollectShortProcedure implements Procedure { private static final long serialVersionUID = 1L; private final ShortFunction shortFunction; private final MutableShortCollection shortCollection; public CollectShortProcedure(ShortFunction shortFunction, MutableShortCollection targetCollection) { this.shortFunction = shortFunction; this.shortCollection = targetCollection; } public void value(T object) { short value = this.shortFunction.shortValueOf(object); this.shortCollection.add(value); } public MutableShortCollection getShortCollection() { return this.shortCollection; } } IntIntProcedure.java000066400000000000000000000020211234315411400370070ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/primitive/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure.primitive; import java.io.Serializable; /** * An IntIntProcedure is a two argument Closure which has no return argument and takes an int as the first and * second arguments. * * @deprecated since 3.0 use {@link com.gs.collections.api.block.procedure.primitive.IntIntProcedure} */ @Deprecated public interface IntIntProcedure extends Serializable { void value(int each, int index); } IntObjectProcedure.java000066400000000000000000000015421234315411400374720ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/primitive/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure.primitive; /** * @deprecated since 3.0 use {@link com.gs.collections.api.block.procedure.primitive.IntObjectProcedure} */ @Deprecated public interface IntObjectProcedure { void value(int each, T parameter); } IntProcedure.java000066400000000000000000000015061234315411400363430ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/primitive/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure.primitive; /** * @deprecated since 3.0 use {@link com.gs.collections.api.block.procedure.primitive.IntProcedure} */ @Deprecated public interface IntProcedure { void value(int each); } IntProcedureWithInt.java000066400000000000000000000020661234315411400376540ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/primitive/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.block.procedure.primitive; import java.io.Serializable; /** * A IntProcedureWithInt is a two argument Closure which has no return argument and takes an int as a first and second * argument. The second argument is usually the index of the current element of a collection. * * @deprecated since 1.2 use {@link IntIntProcedure} */ @Deprecated public interface IntProcedureWithInt extends Serializable { void value(int each, int index); } package-info.java000066400000000000000000000013341234315411400362630ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/block/procedure/primitive/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains implementations of primitive procedures. */ package com.gs.collections.impl.block.procedure.primitive; gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/collection/000077500000000000000000000000001234315411400302135ustar00rootroot00000000000000AbstractMutableBag.java000066400000000000000000000252071234315411400344740ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/collection/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.collection; import com.gs.collections.api.bag.primitive.MutableBooleanBag; import com.gs.collections.api.bag.primitive.MutableByteBag; import com.gs.collections.api.bag.primitive.MutableCharBag; import com.gs.collections.api.bag.primitive.MutableDoubleBag; import com.gs.collections.api.bag.primitive.MutableFloatBag; import com.gs.collections.api.bag.primitive.MutableIntBag; import com.gs.collections.api.bag.primitive.MutableLongBag; import com.gs.collections.api.bag.primitive.MutableShortBag; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.collection.primitive.MutableBooleanCollection; import com.gs.collections.api.collection.primitive.MutableByteCollection; import com.gs.collections.api.collection.primitive.MutableCharCollection; import com.gs.collections.api.collection.primitive.MutableDoubleCollection; import com.gs.collections.api.collection.primitive.MutableFloatCollection; import com.gs.collections.api.collection.primitive.MutableIntCollection; import com.gs.collections.api.collection.primitive.MutableLongCollection; import com.gs.collections.api.collection.primitive.MutableShortCollection; import com.gs.collections.impl.collection.mutable.AbstractMutableCollection; public abstract class AbstractMutableBag extends AbstractMutableCollection { public abstract void forEachWithOccurrences(ObjectIntProcedure procedure); @Override public R collectBoolean(final BooleanFunction booleanFunction, final R target) { if (target instanceof MutableBooleanBag) { final MutableBooleanBag targetBag = (MutableBooleanBag) target; this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { targetBag.addOccurrences(booleanFunction.booleanValueOf(each), occurrences); } }); } else { this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { boolean value = booleanFunction.booleanValueOf(each); for (int i = 0; i < occurrences; i++) { target.add(value); } } }); } return target; } @Override public R collectByte(final ByteFunction byteFunction, final R target) { if (target instanceof MutableByteBag) { final MutableByteBag targetBag = (MutableByteBag) target; this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { targetBag.addOccurrences(byteFunction.byteValueOf(each), occurrences); } }); } else { this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { byte value = byteFunction.byteValueOf(each); for (int i = 0; i < occurrences; i++) { target.add(value); } } }); } return target; } @Override public R collectChar(final CharFunction charFunction, final R target) { if (target instanceof MutableCharBag) { final MutableCharBag targetBag = (MutableCharBag) target; this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { targetBag.addOccurrences(charFunction.charValueOf(each), occurrences); } }); } else { this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { char value = charFunction.charValueOf(each); for (int i = 0; i < occurrences; i++) { target.add(value); } } }); } return target; } @Override public R collectDouble(final DoubleFunction doubleFunction, final R target) { if (target instanceof MutableDoubleBag) { final MutableDoubleBag targetBag = (MutableDoubleBag) target; this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { targetBag.addOccurrences(doubleFunction.doubleValueOf(each), occurrences); } }); } else { this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { double value = doubleFunction.doubleValueOf(each); for (int i = 0; i < occurrences; i++) { target.add(value); } } }); } return target; } @Override public R collectFloat(final FloatFunction floatFunction, final R target) { if (target instanceof MutableFloatBag) { final MutableFloatBag targetBag = (MutableFloatBag) target; this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { targetBag.addOccurrences(floatFunction.floatValueOf(each), occurrences); } }); } else { this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { float value = floatFunction.floatValueOf(each); for (int i = 0; i < occurrences; i++) { target.add(value); } } }); } return target; } @Override public R collectInt(final IntFunction intFunction, final R target) { if (target instanceof MutableIntBag) { final MutableIntBag targetBag = (MutableIntBag) target; this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { targetBag.addOccurrences(intFunction.intValueOf(each), occurrences); } }); } else { this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { int value = intFunction.intValueOf(each); for (int i = 0; i < occurrences; i++) { target.add(value); } } }); } return target; } @Override public R collectLong(final LongFunction longFunction, final R target) { if (target instanceof MutableLongBag) { final MutableLongBag targetBag = (MutableLongBag) target; this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { targetBag.addOccurrences(longFunction.longValueOf(each), occurrences); } }); } else { this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { long value = longFunction.longValueOf(each); for (int i = 0; i < occurrences; i++) { target.add(value); } } }); } return target; } @Override public R collectShort(final ShortFunction shortFunction, final R target) { if (target instanceof MutableShortBag) { final MutableShortBag targetBag = (MutableShortBag) target; this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { targetBag.addOccurrences(shortFunction.shortValueOf(each), occurrences); } }); } else { this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { short value = shortFunction.shortValueOf(each); for (int i = 0; i < occurrences; i++) { target.add(value); } } }); } return target; } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/collection/immutable/000077500000000000000000000000001234315411400321725ustar00rootroot00000000000000AbstractImmutableCollection.java000066400000000000000000000117541234315411400404050ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/collection/immutable/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.collection.immutable; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Set; import com.gs.collections.api.RichIterable; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.collection.ImmutableCollection; import com.gs.collections.api.collection.MutableCollection; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.map.ImmutableMap; import com.gs.collections.api.map.MutableMap; import com.gs.collections.impl.AbstractRichIterable; import com.gs.collections.impl.block.procedure.MutatingAggregationProcedure; import com.gs.collections.impl.block.procedure.NonMutatingAggregationProcedure; import com.gs.collections.impl.factory.Lists; import com.gs.collections.impl.map.mutable.UnifiedMap; import com.gs.collections.impl.set.mutable.UnifiedSet; public abstract class AbstractImmutableCollection extends AbstractRichIterable implements ImmutableCollection, Collection { protected abstract MutableCollection newMutable(int size); public ImmutableMap aggregateInPlaceBy( Function groupBy, Function0 zeroValueFactory, Procedure2 mutatingAggregator) { MutableMap map = UnifiedMap.newMap(); this.forEach(new MutatingAggregationProcedure(map, groupBy, zeroValueFactory, mutatingAggregator)); return map.toImmutable(); } public ImmutableMap aggregateBy( Function groupBy, Function0 zeroValueFactory, Function2 nonMutatingAggregator) { MutableMap map = UnifiedMap.newMap(); this.forEach(new NonMutatingAggregationProcedure(map, groupBy, zeroValueFactory, nonMutatingAggregator)); return map.toImmutable(); } public boolean add(T t) { throw new UnsupportedOperationException("Cannot call add() on " + this.getClass().getSimpleName()); } public boolean remove(Object o) { throw new UnsupportedOperationException("Cannot call remove() on " + this.getClass().getSimpleName()); } public boolean addAll(Collection collection) { throw new UnsupportedOperationException("Cannot call addAll() on " + this.getClass().getSimpleName()); } public boolean removeAll(Collection collection) { throw new UnsupportedOperationException("Cannot call removeAll() on " + this.getClass().getSimpleName()); } public boolean retainAll(Collection collection) { throw new UnsupportedOperationException("Cannot call retainAll() on " + this.getClass().getSimpleName()); } public void clear() { throw new UnsupportedOperationException("Cannot call clear() on " + this.getClass().getSimpleName()); } protected void removeAllFrom(Iterable elements, MutableCollection result) { if (elements instanceof Set) { result.removeAll((Set) elements); } else if (elements instanceof List) { List toBeRemoved = (List) elements; if (this.size() * toBeRemoved.size() > 10000) { result.removeAll(UnifiedSet.newSet(elements)); } else { result.removeAll(toBeRemoved); } } else { result.removeAll(UnifiedSet.newSet(elements)); } } public RichIterable> chunk(int size) { if (size <= 0) { throw new IllegalArgumentException("Size for groups must be positive but was: " + size); } Iterator iterator = this.iterator(); MutableList> result = Lists.mutable.of(); while (iterator.hasNext()) { MutableCollection batch = this.newMutable(size); for (int i = 0; i < size && iterator.hasNext(); i++) { batch.add(iterator.next()); } result.add(batch.toImmutable()); } return result.toImmutable(); } } package-info.java000066400000000000000000000014161234315411400353040ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/collection/immutable/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains implementations of the {@link com.gs.collections.api.collection.ImmutableCollection} interface. */ package com.gs.collections.impl.collection.immutable; gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/collection/mutable/000077500000000000000000000000001234315411400316445ustar00rootroot00000000000000AbstractCollectionAdapter.java000066400000000000000000000621661234315411400375230ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/collection/mutable/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.collection.mutable; import java.util.Collection; import java.util.Comparator; import java.util.Iterator; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.RichIterable; import com.gs.collections.api.bag.MutableBag; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.Function3; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.DoubleObjectToDoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.FloatObjectToFloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.IntObjectToIntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.LongObjectToLongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.collection.MutableCollection; import com.gs.collections.api.collection.primitive.MutableBooleanCollection; import com.gs.collections.api.collection.primitive.MutableByteCollection; import com.gs.collections.api.collection.primitive.MutableCharCollection; import com.gs.collections.api.collection.primitive.MutableDoubleCollection; import com.gs.collections.api.collection.primitive.MutableFloatCollection; import com.gs.collections.api.collection.primitive.MutableIntCollection; import com.gs.collections.api.collection.primitive.MutableLongCollection; import com.gs.collections.api.collection.primitive.MutableShortCollection; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.map.MutableMap; import com.gs.collections.api.map.sorted.MutableSortedMap; import com.gs.collections.api.multimap.MutableMultimap; import com.gs.collections.api.partition.PartitionMutableCollection; import com.gs.collections.api.set.MutableSet; import com.gs.collections.api.set.sorted.MutableSortedSet; import com.gs.collections.api.tuple.Pair; import com.gs.collections.api.tuple.Twin; import com.gs.collections.impl.bag.mutable.HashBag; import com.gs.collections.impl.block.factory.Comparators; import com.gs.collections.impl.block.factory.Predicates2; import com.gs.collections.impl.block.procedure.MutatingAggregationProcedure; import com.gs.collections.impl.block.procedure.NonMutatingAggregationProcedure; import com.gs.collections.impl.factory.Lists; import com.gs.collections.impl.map.mutable.UnifiedMap; import com.gs.collections.impl.map.sorted.mutable.TreeSortedMap; import com.gs.collections.impl.set.mutable.UnifiedSet; import com.gs.collections.impl.set.sorted.mutable.TreeSortedSet; import com.gs.collections.impl.utility.ArrayIterate; import com.gs.collections.impl.utility.Iterate; import com.gs.collections.impl.utility.LazyIterate; import com.gs.collections.impl.utility.internal.IterableIterate; import com.gs.collections.impl.utility.internal.MutableCollectionIterate; public abstract class AbstractCollectionAdapter implements MutableCollection { protected abstract Collection getDelegate(); protected MutableCollection wrap(Collection collection) { return CollectionAdapter.adapt(collection); } public boolean notEmpty() { return !this.getDelegate().isEmpty(); } public T getFirst() { return Iterate.getFirst(this.getDelegate()); } public T getLast() { return Iterate.getLast(this.getDelegate()); } public void forEach(Procedure procedure) { Iterate.forEach(this.getDelegate(), procedure); } public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { Iterate.forEachWithIndex(this.getDelegate(), objectIntProcedure); } public void removeIf(Predicate predicate) { Iterate.removeIf(this.getDelegate(), predicate); } public

void removeIfWith(Predicate2 predicate, P parameter) { Iterate.removeIfWith(this.getDelegate(), predicate, parameter); } public T detect(Predicate predicate) { return Iterate.detect(this.getDelegate(), predicate); } public T min(Comparator comparator) { return Iterate.min(this, comparator); } public T max(Comparator comparator) { return Iterate.max(this, comparator); } public T min() { return Iterate.min(this); } public T max() { return Iterate.max(this); } public > T minBy(Function function) { return IterableIterate.minBy(this, function); } public > T maxBy(Function function) { return IterableIterate.maxBy(this, function); } public T detectIfNone(Predicate predicate, Function0 function) { T result = this.detect(predicate); return result == null ? function.value() : result; } public int count(Predicate predicate) { return Iterate.count(this.getDelegate(), predicate); } public boolean anySatisfy(Predicate predicate) { return Iterate.anySatisfy(this.getDelegate(), predicate); } public boolean allSatisfy(Predicate predicate) { return Iterate.allSatisfy(this.getDelegate(), predicate); } public boolean noneSatisfy(Predicate predicate) { return Iterate.noneSatisfy(this.getDelegate(), predicate); } public IV injectInto(IV injectedValue, Function2 function) { return Iterate.injectInto(injectedValue, this.getDelegate(), function); } public int injectInto(int injectedValue, IntObjectToIntFunction function) { return Iterate.injectInto(injectedValue, this.getDelegate(), function); } public long injectInto(long injectedValue, LongObjectToLongFunction function) { return Iterate.injectInto(injectedValue, this.getDelegate(), function); } public double injectInto(double injectedValue, DoubleObjectToDoubleFunction function) { return Iterate.injectInto(injectedValue, this.getDelegate(), function); } public float injectInto(float injectedValue, FloatObjectToFloatFunction function) { return Iterate.injectInto(injectedValue, this.getDelegate(), function); } public long sumOfInt(IntFunction function) { return Iterate.sumOfInt(this.getDelegate(), function); } public double sumOfFloat(FloatFunction function) { return Iterate.sumOfFloat(this.getDelegate(), function); } public long sumOfLong(LongFunction function) { return Iterate.sumOfLong(this.getDelegate(), function); } public double sumOfDouble(DoubleFunction function) { return Iterate.sumOfDouble(this.getDelegate(), function); } public MutableCollection select(Predicate predicate) { return this.wrap(Iterate.select(this.getDelegate(), predicate)); } public > R select(Predicate predicate, R target) { return Iterate.select(this.getDelegate(), predicate, target); } public MutableCollection reject(Predicate predicate) { return this.wrap(Iterate.reject(this.getDelegate(), predicate)); } public > R reject(Predicate predicate, R target) { return Iterate.reject(this.getDelegate(), predicate, target); } public MutableCollection selectInstancesOf(Class clazz) { return this.wrap(Iterate.selectInstancesOf(this.getDelegate(), clazz)); } public MutableCollection collect(Function function) { return this.wrap(Iterate.collect(this.getDelegate(), function)); } public MutableBooleanCollection collectBoolean(BooleanFunction booleanFunction) { return Iterate.collectBoolean(this.getDelegate(), booleanFunction); } public R collectBoolean(BooleanFunction booleanFunction, R target) { return Iterate.collectBoolean(this.getDelegate(), booleanFunction, target); } public MutableByteCollection collectByte(ByteFunction byteFunction) { return Iterate.collectByte(this.getDelegate(), byteFunction); } public R collectByte(ByteFunction byteFunction, R target) { return Iterate.collectByte(this.getDelegate(), byteFunction, target); } public MutableCharCollection collectChar(CharFunction charFunction) { return Iterate.collectChar(this.getDelegate(), charFunction); } public R collectChar(CharFunction charFunction, R target) { return Iterate.collectChar(this.getDelegate(), charFunction, target); } public MutableDoubleCollection collectDouble(DoubleFunction doubleFunction) { return Iterate.collectDouble(this.getDelegate(), doubleFunction); } public R collectDouble(DoubleFunction doubleFunction, R target) { return Iterate.collectDouble(this.getDelegate(), doubleFunction, target); } public MutableFloatCollection collectFloat(FloatFunction floatFunction) { return Iterate.collectFloat(this.getDelegate(), floatFunction); } public R collectFloat(FloatFunction floatFunction, R target) { return Iterate.collectFloat(this.getDelegate(), floatFunction, target); } public MutableIntCollection collectInt(IntFunction intFunction) { return Iterate.collectInt(this.getDelegate(), intFunction); } public R collectInt(IntFunction intFunction, R target) { return Iterate.collectInt(this.getDelegate(), intFunction, target); } public MutableLongCollection collectLong(LongFunction longFunction) { return Iterate.collectLong(this.getDelegate(), longFunction); } public R collectLong(LongFunction longFunction, R target) { return Iterate.collectLong(this.getDelegate(), longFunction, target); } public MutableShortCollection collectShort(ShortFunction shortFunction) { return Iterate.collectShort(this.getDelegate(), shortFunction); } public R collectShort(ShortFunction shortFunction, R target) { return Iterate.collectShort(this.getDelegate(), shortFunction, target); } public > R collect(Function function, R target) { return Iterate.collect(this.getDelegate(), function, target); } public MutableCollection flatCollect(Function> function) { return this.wrap(Iterate.flatCollect(this.getDelegate(), function)); } public > R flatCollect( Function> function, R target) { return Iterate.flatCollect(this.getDelegate(), function, target); } public MutableCollection collectIf( Predicate predicate, Function function) { return this.wrap(Iterate.collectIf(this.getDelegate(), predicate, function)); } public > R collectIf( Predicate predicate, Function function, R target) { return Iterate.collectIf(this.getDelegate(), predicate, function, target); } public

Twin> selectAndRejectWith( Predicate2 predicate, P parameter) { return Iterate.selectAndRejectWith(this.getDelegate(), predicate, parameter); } public PartitionMutableCollection partition(Predicate predicate) { return (PartitionMutableCollection) Iterate.partition(this.getDelegate(), predicate); } public

PartitionMutableCollection partitionWith(Predicate2 predicate, P parameter) { return (PartitionMutableCollection) Iterate.partitionWith(this.getDelegate(), predicate, parameter); } public int size() { return this.getDelegate().size(); } public boolean isEmpty() { return this.getDelegate().isEmpty(); } public boolean contains(Object o) { return this.getDelegate().contains(o); } public Iterator iterator() { return this.getDelegate().iterator(); } public Object[] toArray() { return this.getDelegate().toArray(); } public E[] toArray(E[] a) { return this.getDelegate().toArray(a); } public boolean add(T o) { return this.getDelegate().add(o); } public boolean remove(Object o) { return this.getDelegate().remove(o); } public boolean containsAll(Collection collection) { return this.getDelegate().containsAll(collection); } public boolean containsAllIterable(Iterable source) { return Iterate.allSatisfyWith(source, Predicates2.in(), this.getDelegate()); } public boolean containsAllArguments(Object... elements) { return ArrayIterate.allSatisfyWith(elements, Predicates2.in(), this.getDelegate()); } public boolean addAll(Collection collection) { boolean result = false; for (T each : collection) { result |= this.add(each); } return result; } public boolean addAllIterable(Iterable iterable) { return Iterate.addAllIterable(iterable, this); } public boolean removeAll(Collection collection) { int currentSize = this.size(); this.removeIfWith(Predicates2.in(), collection); return currentSize != this.size(); } public boolean removeAllIterable(Iterable iterable) { return this.removeAll(CollectionAdapter.wrapSet(iterable)); } public boolean retainAll(Collection collection) { int currentSize = this.size(); this.removeIfWith(Predicates2.notIn(), collection); return currentSize != this.size(); } public boolean retainAllIterable(Iterable iterable) { return this.retainAll(CollectionAdapter.wrapSet(iterable)); } public void clear() { this.getDelegate().clear(); } public

void forEachWith(Procedure2 procedure, P parameter) { Iterate.forEachWith(this.getDelegate(), procedure, parameter); } public

MutableCollection selectWith( Predicate2 predicate, P parameter) { return this.wrap(Iterate.selectWith(this.getDelegate(), predicate, parameter)); } public > R selectWith( Predicate2 predicate, P parameter, R targetCollection) { return Iterate.selectWith(this.getDelegate(), predicate, parameter, targetCollection); } public

MutableCollection rejectWith( Predicate2 predicate, P parameter) { return this.wrap(Iterate.rejectWith(this.getDelegate(), predicate, parameter)); } public > R rejectWith( Predicate2 predicate, P parameter, R targetCollection) { return Iterate.rejectWith(this.getDelegate(), predicate, parameter, targetCollection); } public MutableCollection collectWith( Function2 function, P parameter) { return this.wrap(Iterate.collectWith(this.getDelegate(), function, parameter)); } public > R collectWith( Function2 function, P parameter, R targetCollection) { return Iterate.collectWith(this.getDelegate(), function, parameter, targetCollection); } public IV injectIntoWith( IV injectValue, Function3 function, P parameter) { return Iterate.injectIntoWith(injectValue, this.getDelegate(), function, parameter); } public MutableList toList() { return Lists.mutable.ofAll(this.getDelegate()); } public MutableList toSortedList() { return this.toList().sortThis(); } public MutableList toSortedList(Comparator comparator) { return this.toList().sortThis(comparator); } public > MutableList toSortedListBy(Function function) { return this.toSortedList(Comparators.byFunction(function)); } public MutableSortedSet toSortedSet() { return TreeSortedSet.newSet(null, this); } public MutableSortedSet toSortedSet(Comparator comparator) { return TreeSortedSet.newSet(comparator, this); } public > MutableSortedSet toSortedSetBy( Function function) { return this.toSortedSet(Comparators.byFunction(function)); } public MutableSet toSet() { return UnifiedSet.newSet(this.getDelegate()); } public MutableBag toBag() { return HashBag.newBag(this.getDelegate()); } public MutableMap toMap( Function keyFunction, Function valueFunction) { UnifiedMap map = UnifiedMap.newMap(this.size()); map.collectKeysAndValues(this.getDelegate(), keyFunction, valueFunction); return map; } public MutableSortedMap toSortedMap( Function keyFunction, Function valueFunction) { return TreeSortedMap.newMap().collectKeysAndValues(this.getDelegate(), keyFunction, valueFunction); } public MutableSortedMap toSortedMap( Comparator comparator, Function keyFunction, Function valueFunction) { return TreeSortedMap.newMap(comparator).collectKeysAndValues(this.getDelegate(), keyFunction, valueFunction); } public LazyIterable asLazy() { return LazyIterate.adapt(this); } public

T detectWith(Predicate2 predicate, P parameter) { return Iterate.detectWith(this.getDelegate(), predicate, parameter); } public

T detectWithIfNone( Predicate2 predicate, P parameter, Function0 function) { T result = this.detectWith(predicate, parameter); return result == null ? function.value() : result; } public

int countWith(Predicate2 predicate, P parameter) { return Iterate.countWith(this.getDelegate(), predicate, parameter); } public

boolean anySatisfyWith(Predicate2 predicate, P parameter) { return Iterate.anySatisfyWith(this.getDelegate(), predicate, parameter); } public

boolean allSatisfyWith(Predicate2 predicate, P parameter) { return Iterate.allSatisfyWith(this.getDelegate(), predicate, parameter); } public

boolean noneSatisfyWith(Predicate2 predicate, P parameter) { return Iterate.noneSatisfyWith(this.getDelegate(), predicate, parameter); } @Override public String toString() { return this.makeString("[", ", ", "]"); } public String makeString() { return this.makeString(", "); } public String makeString(String separator) { return this.makeString("", separator, ""); } public String makeString(String start, String separator, String end) { Appendable stringBuilder = new StringBuilder(); this.appendString(stringBuilder, start, separator, end); return stringBuilder.toString(); } public void appendString(Appendable appendable) { this.appendString(appendable, ", "); } public void appendString(Appendable appendable, String separator) { this.appendString(appendable, "", separator, ""); } public void appendString(Appendable appendable, String start, String separator, String end) { IterableIterate.appendString(this, appendable, start, separator, end); } public MutableMultimap groupBy( Function function) { return Iterate.groupBy(this.getDelegate(), function); } public > R groupBy( Function function, R target) { return Iterate.groupBy(this.getDelegate(), function, target); } public MutableMultimap groupByEach( Function> function) { return Iterate.groupByEach(this.getDelegate(), function); } public MutableMap groupByUniqueKey(Function function) { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".groupByUniqueKey() not implemented yet"); } public > R groupByEach( Function> function, R target) { return Iterate.groupByEach(this.getDelegate(), function, target); } public MutableCollection> zip(Iterable that) { return this.wrap(Iterate.zip(this.getDelegate(), that)); } public >> R zip(Iterable that, R target) { return Iterate.zip(this.getDelegate(), that, target); } public MutableCollection> zipWithIndex() { return this.wrap(Iterate.zipWithIndex(this.getDelegate())); } public >> R zipWithIndex(R target) { return Iterate.zipWithIndex(this.getDelegate(), target); } public RichIterable> chunk(int size) { return MutableCollectionIterate.chunk(this, size); } public MutableMap aggregateInPlaceBy( Function groupBy, Function0 zeroValueFactory, Procedure2 mutatingAggregator) { MutableMap map = UnifiedMap.newMap(); this.forEach(new MutatingAggregationProcedure(map, groupBy, zeroValueFactory, mutatingAggregator)); return map; } public MutableMap aggregateBy( Function groupBy, Function0 zeroValueFactory, Function2 nonMutatingAggregator) { MutableMap map = UnifiedMap.newMap(); this.forEach(new NonMutatingAggregationProcedure(map, groupBy, zeroValueFactory, nonMutatingAggregator)); return map; } } AbstractMultiReaderMutableCollection.java000066400000000000000000001431741234315411400416710ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/collection/mutable/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.collection.mutable; import java.util.Collection; import java.util.Comparator; import java.util.Iterator; import java.util.concurrent.locks.ReadWriteLock; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.RichIterable; import com.gs.collections.api.bag.MutableBag; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.Function3; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.DoubleObjectToDoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.FloatObjectToFloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.IntObjectToIntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.LongObjectToLongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.collection.MutableCollection; import com.gs.collections.api.collection.primitive.MutableBooleanCollection; import com.gs.collections.api.collection.primitive.MutableByteCollection; import com.gs.collections.api.collection.primitive.MutableCharCollection; import com.gs.collections.api.collection.primitive.MutableDoubleCollection; import com.gs.collections.api.collection.primitive.MutableFloatCollection; import com.gs.collections.api.collection.primitive.MutableIntCollection; import com.gs.collections.api.collection.primitive.MutableLongCollection; import com.gs.collections.api.collection.primitive.MutableShortCollection; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.map.MutableMap; import com.gs.collections.api.map.sorted.MutableSortedMap; import com.gs.collections.api.multimap.MutableMultimap; import com.gs.collections.api.set.MutableSet; import com.gs.collections.api.set.sorted.MutableSortedSet; import com.gs.collections.api.tuple.Pair; import com.gs.collections.api.tuple.Twin; import com.gs.collections.impl.block.procedure.MutatingAggregationProcedure; import com.gs.collections.impl.block.procedure.NonMutatingAggregationProcedure; import com.gs.collections.impl.map.mutable.UnifiedMap; /** * AbstractMultiReaderMutableCollection is a common abstraction that provides thread-safe collection behaviors. * Subclasses of this class must provide implementations of getDelegate() and getLock(). */ public abstract class AbstractMultiReaderMutableCollection implements MutableCollection { protected abstract MutableCollection getDelegate(); protected abstract ReadWriteLock getLock(); protected void acquireWriteLock() { this.getLock().writeLock().lock(); } protected void unlockWriteLock() { this.getLock().writeLock().unlock(); } protected void acquireReadLock() { this.getLock().readLock().lock(); } protected void unlockReadLock() { this.getLock().readLock().unlock(); } protected void withReadLockRun(Runnable block) { this.acquireReadLock(); try { block.run(); } finally { this.unlockReadLock(); } } public boolean contains(Object item) { this.acquireReadLock(); try { return this.getDelegate().contains(item); } finally { this.unlockReadLock(); } } public boolean containsAll(Collection collection) { this.acquireReadLock(); try { return this.getDelegate().containsAll(collection); } finally { this.unlockReadLock(); } } public boolean containsAllIterable(Iterable source) { this.acquireReadLock(); try { return this.getDelegate().containsAllIterable(source); } finally { this.unlockReadLock(); } } public boolean containsAllArguments(Object... elements) { this.acquireReadLock(); try { return this.getDelegate().containsAllArguments(elements); } finally { this.unlockReadLock(); } } public boolean noneSatisfy(Predicate predicate) { this.acquireReadLock(); try { return this.getDelegate().noneSatisfy(predicate); } finally { this.unlockReadLock(); } } public

boolean noneSatisfyWith( Predicate2 predicate, P parameter) { this.acquireReadLock(); try { return this.getDelegate().noneSatisfyWith(predicate, parameter); } finally { this.unlockReadLock(); } } public boolean allSatisfy(Predicate predicate) { this.acquireReadLock(); try { return this.getDelegate().allSatisfy(predicate); } finally { this.unlockReadLock(); } } public

boolean allSatisfyWith( Predicate2 predicate, P parameter) { this.acquireReadLock(); try { return this.getDelegate().allSatisfyWith(predicate, parameter); } finally { this.unlockReadLock(); } } public boolean anySatisfy(Predicate predicate) { this.acquireReadLock(); try { return this.getDelegate().anySatisfy(predicate); } finally { this.unlockReadLock(); } } public

boolean anySatisfyWith( Predicate2 predicate, P parameter) { this.acquireReadLock(); try { return this.getDelegate().anySatisfyWith(predicate, parameter); } finally { this.unlockReadLock(); } } public MutableList toList() { this.acquireReadLock(); try { return this.getDelegate().toList(); } finally { this.unlockReadLock(); } } public MutableMap toMap( Function keyFunction, Function valueFunction) { this.acquireReadLock(); try { return this.getDelegate().toMap(keyFunction, valueFunction); } finally { this.unlockReadLock(); } } public MutableSortedMap toSortedMap( Function keyFunction, Function valueFunction) { this.acquireReadLock(); try { return this.getDelegate().toSortedMap(keyFunction, valueFunction); } finally { this.unlockReadLock(); } } public MutableSortedMap toSortedMap(Comparator comparator, Function keyFunction, Function valueFunction) { this.acquireReadLock(); try { return this.getDelegate().toSortedMap(comparator, keyFunction, valueFunction); } finally { this.unlockReadLock(); } } public LazyIterable asLazy() { this.acquireReadLock(); try { return this.getDelegate().asLazy(); } finally { this.unlockReadLock(); } } public MutableSet toSet() { this.acquireReadLock(); try { return this.getDelegate().toSet(); } finally { this.unlockReadLock(); } } public MutableBag toBag() { this.acquireReadLock(); try { return this.getDelegate().toBag(); } finally { this.unlockReadLock(); } } public MutableList toSortedList() { this.acquireReadLock(); try { return this.getDelegate().toSortedList(); } finally { this.unlockReadLock(); } } public MutableList toSortedList(Comparator comparator) { this.acquireReadLock(); try { return this.getDelegate().toSortedList(comparator); } finally { this.unlockReadLock(); } } public > MutableList toSortedListBy( Function function) { this.acquireReadLock(); try { return this.getDelegate().toSortedListBy(function); } finally { this.unlockReadLock(); } } public MutableSortedSet toSortedSet() { this.acquireReadLock(); try { return this.getDelegate().toSortedSet(); } finally { this.unlockReadLock(); } } public MutableSortedSet toSortedSet(Comparator comparator) { this.acquireReadLock(); try { return this.getDelegate().toSortedSet(comparator); } finally { this.unlockReadLock(); } } public > MutableSortedSet toSortedSetBy( Function function) { this.acquireReadLock(); try { return this.getDelegate().toSortedSetBy(function); } finally { this.unlockReadLock(); } } public int count(Predicate predicate) { this.acquireReadLock(); try { return this.getDelegate().count(predicate); } finally { this.unlockReadLock(); } } public

int countWith( Predicate2 predicate, P parameter) { this.acquireReadLock(); try { return this.getDelegate().countWith(predicate, parameter); } finally { this.unlockReadLock(); } } public T detect(Predicate predicate) { this.acquireReadLock(); try { return this.getDelegate().detect(predicate); } finally { this.unlockReadLock(); } } public T min(Comparator comparator) { this.acquireReadLock(); try { return this.getDelegate().min(comparator); } finally { this.unlockReadLock(); } } public T max(Comparator comparator) { this.acquireReadLock(); try { return this.getDelegate().max(comparator); } finally { this.unlockReadLock(); } } public T min() { this.acquireReadLock(); try { return this.getDelegate().min(); } finally { this.unlockReadLock(); } } public T max() { this.acquireReadLock(); try { return this.getDelegate().max(); } finally { this.unlockReadLock(); } } public > T minBy(Function function) { this.acquireReadLock(); try { return this.getDelegate().minBy(function); } finally { this.unlockReadLock(); } } public > T maxBy(Function function) { this.acquireReadLock(); try { return this.getDelegate().maxBy(function); } finally { this.unlockReadLock(); } } public T detectIfNone( Predicate predicate, Function0 function) { this.acquireReadLock(); try { return this.getDelegate().detectIfNone(predicate, function); } finally { this.unlockReadLock(); } } public

T detectWith( Predicate2 predicate, P parameter) { this.acquireReadLock(); try { return this.getDelegate().detectWith(predicate, parameter); } finally { this.unlockReadLock(); } } public

T detectWithIfNone( Predicate2 predicate, P parameter, Function0 function) { this.acquireReadLock(); try { return this.getDelegate().detectWithIfNone(predicate, parameter, function); } finally { this.unlockReadLock(); } } public T getFirst() { this.acquireReadLock(); try { return this.getDelegate().getFirst(); } finally { this.unlockReadLock(); } } public T getLast() { this.acquireReadLock(); try { return this.getDelegate().getLast(); } finally { this.unlockReadLock(); } } public boolean notEmpty() { this.acquireReadLock(); try { return this.getDelegate().notEmpty(); } finally { this.unlockReadLock(); } } public

Twin> selectAndRejectWith( Predicate2 predicate, P parameter) { this.acquireReadLock(); try { return this.getDelegate().selectAndRejectWith(predicate, parameter); } finally { this.unlockReadLock(); } } public > R collect( Function function, R target) { this.acquireReadLock(); try { return this.getDelegate().collect(function, target); } finally { this.unlockReadLock(); } } public R collectBoolean(BooleanFunction booleanFunction, R target) { this.acquireReadLock(); try { return this.getDelegate().collectBoolean(booleanFunction, target); } finally { this.unlockReadLock(); } } public R collectByte(ByteFunction byteFunction, R target) { this.acquireReadLock(); try { return this.getDelegate().collectByte(byteFunction, target); } finally { this.unlockReadLock(); } } public R collectChar(CharFunction charFunction, R target) { this.acquireReadLock(); try { return this.getDelegate().collectChar(charFunction, target); } finally { this.unlockReadLock(); } } public R collectDouble(DoubleFunction doubleFunction, R target) { this.acquireReadLock(); try { return this.getDelegate().collectDouble(doubleFunction, target); } finally { this.unlockReadLock(); } } public R collectFloat(FloatFunction floatFunction, R target) { this.acquireReadLock(); try { return this.getDelegate().collectFloat(floatFunction, target); } finally { this.unlockReadLock(); } } public R collectInt(IntFunction intFunction, R target) { this.acquireReadLock(); try { return this.getDelegate().collectInt(intFunction, target); } finally { this.unlockReadLock(); } } public R collectLong(LongFunction longFunction, R target) { this.acquireReadLock(); try { return this.getDelegate().collectLong(longFunction, target); } finally { this.unlockReadLock(); } } public R collectShort(ShortFunction shortFunction, R target) { this.acquireReadLock(); try { return this.getDelegate().collectShort(shortFunction, target); } finally { this.unlockReadLock(); } } public > R flatCollect( Function> function, R target) { this.acquireReadLock(); try { return this.getDelegate().flatCollect(function, target); } finally { this.unlockReadLock(); } } public > R collectIf( Predicate predicate, Function function, R target) { this.acquireReadLock(); try { return this.getDelegate().collectIf(predicate, function, target); } finally { this.unlockReadLock(); } } public > R collectWith( Function2 function, P parameter, R targetCollection) { this.acquireReadLock(); try { return this.getDelegate().collectWith(function, parameter, targetCollection); } finally { this.unlockReadLock(); } } public > R selectWith( Predicate2 predicate, P parameter, R targetCollection) { this.acquireReadLock(); try { return this.getDelegate().selectWith(predicate, parameter, targetCollection); } finally { this.unlockReadLock(); } } public > R reject( Predicate predicate, R target) { this.acquireReadLock(); try { return this.getDelegate().reject(predicate, target); } finally { this.unlockReadLock(); } } public > R rejectWith( Predicate2 predicate, P parameter, R targetCollection) { this.acquireReadLock(); try { return this.getDelegate().rejectWith(predicate, parameter, targetCollection); } finally { this.unlockReadLock(); } } public > R select(Predicate predicate, R target) { this.acquireReadLock(); try { return this.getDelegate().select(predicate, target); } finally { this.unlockReadLock(); } } public IV injectInto( IV injectedValue, Function2 function) { this.acquireReadLock(); try { return this.getDelegate().injectInto(injectedValue, function); } finally { this.unlockReadLock(); } } public int injectInto(int injectedValue, IntObjectToIntFunction function) { this.acquireReadLock(); try { return this.getDelegate().injectInto(injectedValue, function); } finally { this.unlockReadLock(); } } public long injectInto(long injectedValue, LongObjectToLongFunction function) { this.acquireReadLock(); try { return this.getDelegate().injectInto(injectedValue, function); } finally { this.unlockReadLock(); } } public double injectInto(double injectedValue, DoubleObjectToDoubleFunction function) { this.acquireReadLock(); try { return this.getDelegate().injectInto(injectedValue, function); } finally { this.unlockReadLock(); } } public float injectInto(float injectedValue, FloatObjectToFloatFunction function) { this.acquireReadLock(); try { return this.getDelegate().injectInto(injectedValue, function); } finally { this.unlockReadLock(); } } public long sumOfInt(IntFunction function) { this.acquireReadLock(); try { return this.getDelegate().sumOfInt(function); } finally { this.unlockReadLock(); } } public double sumOfFloat(FloatFunction function) { this.acquireReadLock(); try { return this.getDelegate().sumOfFloat(function); } finally { this.unlockReadLock(); } } public long sumOfLong(LongFunction function) { this.acquireReadLock(); try { return this.getDelegate().sumOfLong(function); } finally { this.unlockReadLock(); } } public double sumOfDouble(DoubleFunction function) { this.acquireReadLock(); try { return this.getDelegate().sumOfDouble(function); } finally { this.unlockReadLock(); } } public IV injectIntoWith( IV injectValue, Function3 function, P parameter) { this.acquireReadLock(); try { return this.getDelegate().injectIntoWith(injectValue, function, parameter); } finally { this.unlockReadLock(); } } public void removeIf(Predicate predicate) { this.acquireWriteLock(); try { this.getDelegate().removeIf(predicate); } finally { this.unlockWriteLock(); } } public

void removeIfWith( Predicate2 predicate, P parameter) { this.acquireWriteLock(); try { this.getDelegate().removeIfWith(predicate, parameter); } finally { this.unlockWriteLock(); } } public boolean add(T item) { this.acquireWriteLock(); try { return this.getDelegate().add(item); } finally { this.unlockWriteLock(); } } public boolean addAll(Collection collection) { this.acquireWriteLock(); try { return this.getDelegate().addAll(collection); } finally { this.unlockWriteLock(); } } public boolean addAllIterable(Iterable iterable) { this.acquireWriteLock(); try { return this.getDelegate().addAllIterable(iterable); } finally { this.unlockWriteLock(); } } public void clear() { this.acquireWriteLock(); try { this.getDelegate().clear(); } finally { this.unlockWriteLock(); } } public boolean isEmpty() { this.acquireReadLock(); try { return this.getDelegate().isEmpty(); } finally { this.unlockReadLock(); } } /** * This method is not supported directly on MultiReader collections because it is not thread-safe. If you would like * to use an iterator with a MultiReader collection, then you must do the following: *

*

     * multiReaderList.withReadLockAndDelegate(new Procedure>()
     * {
     *     public void value(MutableList people)
     *     {
     *         Iterator it = people.iterator();
     *         ....
     *     }
     * });
     * 
*

*

     * final Collection jdkSet = new HashSet();
     * final boolean containsAll = new boolean[1];
     * multiReaderList.withReadLockAndDelegate(new Procedure>()
     * {
     *     public void value(MutableList people)
     *     {
     *         set.addAll(people); // addAll uses iterator() in AbstractCollection
     *         containsAll[0] = set.containsAll(people); // containsAll uses iterator() in AbstractCollection
     *     }
     * });
     * 
*/ public Iterator iterator() { throw new UnsupportedOperationException( "Iterator is not supported directly on MultiReader collections. " + "If you would like to use an iterator, you must either use withReadLockAndDelegate() or withWriteLockAndDelegate()."); } public boolean remove(Object item) { this.acquireWriteLock(); try { return this.getDelegate().remove(item); } finally { this.unlockWriteLock(); } } public boolean removeAll(Collection collection) { this.acquireWriteLock(); try { return this.getDelegate().removeAll(collection); } finally { this.unlockWriteLock(); } } public boolean removeAllIterable(Iterable iterable) { this.acquireWriteLock(); try { return this.getDelegate().removeAllIterable(iterable); } finally { this.unlockWriteLock(); } } public boolean retainAll(Collection collection) { this.acquireWriteLock(); try { return this.getDelegate().retainAll(collection); } finally { this.unlockWriteLock(); } } public boolean retainAllIterable(Iterable iterable) { this.acquireWriteLock(); try { return this.getDelegate().retainAllIterable(iterable); } finally { this.unlockWriteLock(); } } public int size() { this.acquireReadLock(); try { return this.getDelegate().size(); } finally { this.unlockReadLock(); } } public Object[] toArray() { this.acquireReadLock(); try { return this.getDelegate().toArray(); } finally { this.unlockReadLock(); } } public E[] toArray(E[] a) { this.acquireReadLock(); try { return this.getDelegate().toArray(a); } finally { this.unlockReadLock(); } } public void forEach(Procedure procedure) { this.acquireReadLock(); try { this.getDelegate().forEach(procedure); } finally { this.unlockReadLock(); } } public

void forEachWith(Procedure2 procedure, P parameter) { this.acquireReadLock(); try { this.getDelegate().forEachWith(procedure, parameter); } finally { this.unlockReadLock(); } } public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { this.acquireReadLock(); try { this.getDelegate().forEachWithIndex(objectIntProcedure); } finally { this.unlockReadLock(); } } @Override public String toString() { this.acquireReadLock(); try { return this.getDelegate().toString(); } finally { this.unlockReadLock(); } } public String makeString() { this.acquireReadLock(); try { return this.getDelegate().makeString(); } finally { this.unlockReadLock(); } } public String makeString(String separator) { this.acquireReadLock(); try { return this.getDelegate().makeString(separator); } finally { this.unlockReadLock(); } } public String makeString(String start, String separator, String end) { this.acquireReadLock(); try { return this.getDelegate().makeString(start, separator, end); } finally { this.unlockReadLock(); } } public void appendString(Appendable appendable) { this.acquireReadLock(); try { this.getDelegate().appendString(appendable); } finally { this.unlockReadLock(); } } public void appendString(Appendable appendable, String separator) { this.acquireReadLock(); try { this.getDelegate().appendString(appendable, separator); } finally { this.unlockReadLock(); } } public void appendString(Appendable appendable, String start, String separator, String end) { this.acquireReadLock(); try { this.getDelegate().appendString(appendable, start, separator, end); } finally { this.unlockReadLock(); } } public > R groupBy( Function function, R target) { this.acquireReadLock(); try { return this.getDelegate().groupBy(function, target); } finally { this.unlockReadLock(); } } public > R groupByEach( Function> function, R target) { this.acquireReadLock(); try { return this.getDelegate().groupByEach(function, target); } finally { this.unlockReadLock(); } } public >> R zip(Iterable that, R target) { this.acquireReadLock(); try { return this.getDelegate().zip(that, target); } finally { this.unlockReadLock(); } } public >> R zipWithIndex(R target) { this.acquireReadLock(); try { return this.getDelegate().zipWithIndex(target); } finally { this.unlockReadLock(); } } public MutableMap aggregateInPlaceBy( Function groupBy, Function0 zeroValueFactory, Procedure2 mutatingAggregator) { MutableMap map = UnifiedMap.newMap(); this.forEach(new MutatingAggregationProcedure(map, groupBy, zeroValueFactory, mutatingAggregator)); return map; } public MutableMap aggregateBy( Function groupBy, Function0 zeroValueFactory, Function2 nonMutatingAggregator) { MutableMap map = UnifiedMap.newMap(); this.forEach(new NonMutatingAggregationProcedure(map, groupBy, zeroValueFactory, nonMutatingAggregator)); return map; } protected abstract static class UntouchableMutableCollection implements MutableCollection { protected MutableCollection delegate; public boolean allSatisfy(Predicate predicate) { return this.delegate.allSatisfy(predicate); } public

boolean allSatisfyWith( Predicate2 predicate, P parameter) { return this.delegate.allSatisfyWith(predicate, parameter); } public boolean noneSatisfy(Predicate predicate) { return this.delegate.noneSatisfy(predicate); } public

boolean noneSatisfyWith( Predicate2 predicate, P parameter) { return this.delegate.noneSatisfyWith(predicate, parameter); } public boolean anySatisfy(Predicate predicate) { return this.delegate.anySatisfy(predicate); } public

boolean anySatisfyWith( Predicate2 predicate, P parameter) { return this.delegate.anySatisfyWith(predicate, parameter); } public MutableList toList() { return this.delegate.toList(); } public MutableMap toMap( Function keyFunction, Function valueFunction) { return this.delegate.toMap(keyFunction, valueFunction); } public MutableSortedMap toSortedMap( Function keyFunction, Function valueFunction) { return this.delegate.toSortedMap(keyFunction, valueFunction); } public MutableSortedMap toSortedMap(Comparator comparator, Function keyFunction, Function valueFunction) { return this.delegate.toSortedMap(comparator, keyFunction, valueFunction); } public MutableSet toSet() { return this.delegate.toSet(); } public MutableBag toBag() { return this.delegate.toBag(); } public MutableList toSortedList() { return this.delegate.toSortedList(); } public MutableList toSortedList(Comparator comparator) { return this.delegate.toSortedList(comparator); } public > MutableList toSortedListBy(Function function) { return this.delegate.toSortedListBy(function); } public MutableSortedSet toSortedSet() { return this.delegate.toSortedSet(); } public MutableSortedSet toSortedSet(Comparator comparator) { return this.delegate.toSortedSet(comparator); } public > MutableSortedSet toSortedSetBy(Function function) { return this.delegate.toSortedSetBy(function); } public > R collect( Function function, R target) { return this.delegate.collect(function, target); } public > R flatCollect( Function> function, R target) { return this.delegate.flatCollect(function, target); } public > R collectIf( Predicate predicate, Function function, R target) { return this.delegate.collectIf(predicate, function, target); } public > R collectWith( Function2 function, P parameter, R targetCollection) { return this.delegate.collectWith(function, parameter, targetCollection); } public > R groupBy( Function function, R target) { return this.delegate.groupBy(function, target); } public > R groupByEach( Function> function, R target) { return this.delegate.groupByEach(function, target); } public int count(Predicate predicate) { return this.delegate.count(predicate); } public

int countWith(Predicate2 predicate, P parameter) { return this.delegate.countWith(predicate, parameter); } public T detect(Predicate predicate) { return this.delegate.detect(predicate); } public T min(Comparator comparator) { return this.delegate.min(comparator); } public T max(Comparator comparator) { return this.delegate.max(comparator); } public T min() { return this.delegate.min(); } public T max() { return this.delegate.max(); } public > T minBy(Function function) { return this.delegate.minBy(function); } public > T maxBy(Function function) { return this.delegate.maxBy(function); } public T detectIfNone(Predicate predicate, Function0 function) { return this.delegate.detectIfNone(predicate, function); } public

T detectWith(Predicate2 predicate, P parameter) { return this.delegate.detectWith(predicate, parameter); } public

T detectWithIfNone( Predicate2 predicate, P parameter, Function0 function) { return this.delegate.detectWithIfNone(predicate, parameter, function); } public T getFirst() { return this.delegate.getFirst(); } public T getLast() { return this.delegate.getLast(); } public IV injectInto( IV injectedValue, Function2 function) { return this.delegate.injectInto(injectedValue, function); } public int injectInto(int injectedValue, IntObjectToIntFunction function) { return this.delegate.injectInto(injectedValue, function); } public long injectInto(long injectedValue, LongObjectToLongFunction function) { return this.delegate.injectInto(injectedValue, function); } public double injectInto(double injectedValue, DoubleObjectToDoubleFunction function) { return this.delegate.injectInto(injectedValue, function); } public float injectInto(float injectedValue, FloatObjectToFloatFunction function) { return this.delegate.injectInto(injectedValue, function); } public long sumOfInt(IntFunction function) { return this.delegate.sumOfInt(function); } public double sumOfFloat(FloatFunction function) { return this.delegate.sumOfFloat(function); } public long sumOfLong(LongFunction function) { return this.delegate.sumOfLong(function); } public double sumOfDouble(DoubleFunction function) { return this.delegate.sumOfDouble(function); } public IV injectIntoWith( IV injectValue, Function3 function, P parameter) { return this.delegate.injectIntoWith(injectValue, function, parameter); } public boolean notEmpty() { return this.delegate.notEmpty(); } public > R reject(Predicate predicate, R target) { return this.delegate.reject(predicate, target); } public > R rejectWith( Predicate2 predicate, P parameter, R targetCollection) { return this.delegate.rejectWith(predicate, parameter, targetCollection); } public void removeIf(Predicate predicate) { this.delegate.removeIf(predicate); } public

void removeIfWith( Predicate2 predicate, P parameter) { this.delegate.removeIfWith(predicate, parameter); } public > R select(Predicate predicate, R target) { return this.delegate.select(predicate, target); } public

Twin> selectAndRejectWith( Predicate2 predicate, P parameter) { return this.delegate.selectAndRejectWith(predicate, parameter); } public > R selectWith( Predicate2 predicate, P parameter, R targetCollection) { return this.delegate.selectWith(predicate, parameter, targetCollection); } public boolean add(T o) { return this.delegate.add(o); } public boolean addAll(Collection collection) { return this.delegate.addAll(collection); } public boolean addAllIterable(Iterable iterable) { return this.delegate.addAllIterable(iterable); } public void clear() { this.delegate.clear(); } public boolean contains(Object o) { return this.delegate.contains(o); } public boolean containsAll(Collection collection) { return this.delegate.containsAll(collection); } public boolean containsAllIterable(Iterable source) { return this.delegate.containsAllIterable(source); } public boolean containsAllArguments(Object... elements) { return this.delegate.containsAllArguments(elements); } @Override public boolean equals(Object o) { return this.delegate.equals(o); } @Override public int hashCode() { return this.delegate.hashCode(); } public boolean isEmpty() { return this.delegate.isEmpty(); } public boolean remove(Object o) { return this.delegate.remove(o); } public boolean removeAll(Collection collection) { return this.delegate.removeAll(collection); } public boolean removeAllIterable(Iterable iterable) { return this.delegate.removeAllIterable(iterable); } public boolean retainAll(Collection collection) { return this.delegate.retainAll(collection); } public boolean retainAllIterable(Iterable iterable) { return this.delegate.retainAllIterable(iterable); } public int size() { return this.delegate.size(); } public Object[] toArray() { return this.delegate.toArray(); } public T[] toArray(T[] a) { return this.delegate.toArray(a); } public void forEach(Procedure procedure) { this.delegate.forEach(procedure); } public

void forEachWith(Procedure2 procedure, P parameter) { this.delegate.forEachWith(procedure, parameter); } public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { this.delegate.forEachWithIndex(objectIntProcedure); } @Override public String toString() { return this.delegate.toString(); } public String makeString() { return this.delegate.makeString(); } public String makeString(String separator) { return this.delegate.makeString(separator); } public String makeString(String start, String separator, String end) { return this.delegate.makeString(start, separator, end); } public void appendString(Appendable appendable) { this.delegate.appendString(appendable); } public void appendString(Appendable appendable, String separator) { this.delegate.appendString(appendable, separator); } public void appendString(Appendable appendable, String start, String separator, String end) { this.delegate.appendString(appendable, start, separator, end); } public >> R zip(Iterable that, R target) { return this.delegate.zip(that, target); } public >> R zipWithIndex(R target) { return this.delegate.zipWithIndex(target); } public RichIterable> chunk(int size) { return this.delegate.chunk(size); } public MutableMap aggregateInPlaceBy( final Function groupBy, final Function0 zeroValueFactory, final Procedure2 mutatingAggregator) { final MutableMap map = UnifiedMap.newMap(); this.forEach(new Procedure() { public void value(T each) { K key = groupBy.valueOf(each); V value = map.getIfAbsentPut(key, zeroValueFactory); mutatingAggregator.value(value, each); } }); return map; } public MutableMap aggregateBy( final Function groupBy, final Function0 zeroValueFactory, final Function2 nonMutatingAggregator) { final MutableMap map = UnifiedMap.newMap(); this.forEach(new Procedure() { public void value(T each) { K key = groupBy.valueOf(each); V value = map.getIfAbsentPut(key, zeroValueFactory); map.put(key, nonMutatingAggregator.value(value, each)); } }); return map; } } } AbstractMutableCollection.java000066400000000000000000000137241234315411400375300ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/collection/mutable/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.collection.mutable; import java.util.Collection; import java.util.Iterator; import com.gs.collections.api.RichIterable; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.Function3; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.collection.MutableCollection; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.map.MutableMap; import com.gs.collections.api.tuple.Twin; import com.gs.collections.impl.AbstractRichIterable; import com.gs.collections.impl.block.factory.Comparators; import com.gs.collections.impl.block.procedure.CollectionAddProcedure; import com.gs.collections.impl.block.procedure.MutatingAggregationProcedure; import com.gs.collections.impl.block.procedure.NonMutatingAggregationProcedure; import com.gs.collections.impl.factory.Lists; import com.gs.collections.impl.map.mutable.UnifiedMap; import com.gs.collections.impl.utility.internal.IterableIterate; public abstract class AbstractMutableCollection extends AbstractRichIterable implements MutableCollection { public

Twin> selectAndRejectWith( Predicate2 predicate, P parameter) { return IterableIterate.selectAndRejectWith(this, predicate, parameter); } public void removeIf(Predicate predicate) { IterableIterate.removeIf(this, predicate); } public

void removeIfWith(Predicate2 predicate, P parameter) { IterableIterate.removeIfWith(this, predicate, parameter); } public IV injectIntoWith( IV injectValue, Function3 function, P parameter) { return IterableIterate.injectIntoWith(injectValue, this, function, parameter); } public boolean addAllIterable(Iterable iterable) { int oldSize = this.size(); IterableIterate.forEach(iterable, CollectionAddProcedure.on(this)); return oldSize != this.size(); } public boolean removeAllIterable(Iterable iterable) { return this.removeAll(CollectionAdapter.wrapSet(iterable)); } public boolean retainAllIterable(Iterable iterable) { return this.retainAll(CollectionAdapter.wrapSet(iterable)); } public RichIterable> chunk(int size) { if (size <= 0) { throw new IllegalArgumentException("Size for groups must be positive but was: " + size); } Iterator iterator = this.iterator(); MutableList> result = Lists.mutable.of(); while (iterator.hasNext()) { MutableCollection batch = this.newEmpty(); for (int i = 0; i < size && iterator.hasNext(); i++) { batch.add(iterator.next()); } result.add(batch); } return result; } public MutableMap aggregateInPlaceBy( Function groupBy, Function0 zeroValueFactory, Procedure2 mutatingAggregator) { MutableMap map = UnifiedMap.newMap(); this.forEach(new MutatingAggregationProcedure(map, groupBy, zeroValueFactory, mutatingAggregator)); return map; } public MutableMap aggregateBy( Function groupBy, Function0 zeroValueFactory, Function2 nonMutatingAggregator) { MutableMap map = UnifiedMap.newMap(); this.forEach(new NonMutatingAggregationProcedure(map, groupBy, zeroValueFactory, nonMutatingAggregator)); return map; } public boolean add(T element) { throw new UnsupportedOperationException("Cannot call add() on " + this.getClass().getSimpleName()); } public boolean remove(Object o) { Iterator iterator = this.iterator(); while (iterator.hasNext()) { if (Comparators.nullSafeEquals(o, iterator.next())) { iterator.remove(); return true; } } return false; } public boolean addAll(Collection source) { return this.addAllIterable(source); } public boolean removeAll(Collection source) { int oldSize = this.size(); Iterator iterator = this.iterator(); while (iterator.hasNext()) { if (source.contains(iterator.next())) { iterator.remove(); } } return this.size() != oldSize; } public boolean retainAll(Collection source) { int oldSize = this.size(); Iterator iterator = this.iterator(); while (iterator.hasNext()) { if (!source.contains(iterator.next())) { iterator.remove(); } } return this.size() != oldSize; } } AbstractSynchronizedMutableCollection.java000066400000000000000000000760051234315411400421310ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/collection/mutable/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.collection.mutable; import java.util.Collection; import java.util.Comparator; import java.util.Iterator; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.RichIterable; import com.gs.collections.api.bag.MutableBag; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.Function3; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.DoubleObjectToDoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.FloatObjectToFloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.IntObjectToIntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.LongObjectToLongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.collection.ImmutableCollection; import com.gs.collections.api.collection.MutableCollection; import com.gs.collections.api.collection.primitive.MutableBooleanCollection; import com.gs.collections.api.collection.primitive.MutableByteCollection; import com.gs.collections.api.collection.primitive.MutableCharCollection; import com.gs.collections.api.collection.primitive.MutableDoubleCollection; import com.gs.collections.api.collection.primitive.MutableFloatCollection; import com.gs.collections.api.collection.primitive.MutableIntCollection; import com.gs.collections.api.collection.primitive.MutableLongCollection; import com.gs.collections.api.collection.primitive.MutableShortCollection; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.map.MutableMap; import com.gs.collections.api.map.sorted.MutableSortedMap; import com.gs.collections.api.multimap.MutableMultimap; import com.gs.collections.api.partition.PartitionMutableCollection; import com.gs.collections.api.set.MutableSet; import com.gs.collections.api.set.sorted.MutableSortedSet; import com.gs.collections.api.tuple.Pair; import com.gs.collections.api.tuple.Twin; import com.gs.collections.impl.block.factory.Comparators; import com.gs.collections.impl.block.procedure.MutatingAggregationProcedure; import com.gs.collections.impl.block.procedure.NonMutatingAggregationProcedure; import com.gs.collections.impl.map.mutable.UnifiedMap; import com.gs.collections.impl.set.sorted.mutable.TreeSortedSet; import com.gs.collections.impl.utility.LazyIterate; import com.gs.collections.impl.utility.internal.IterableIterate; import net.jcip.annotations.GuardedBy; import net.jcip.annotations.ThreadSafe; @ThreadSafe public class AbstractSynchronizedMutableCollection implements MutableCollection { private final Object lock; @GuardedBy("this.lock") private final MutableCollection collection; protected AbstractSynchronizedMutableCollection(MutableCollection newCollection) { this(newCollection, null); } protected AbstractSynchronizedMutableCollection(MutableCollection newCollection, Object newLock) { if (newCollection == null) { throw new IllegalArgumentException("Cannot create a SynchronizedMutableCollection on a null collection"); } this.collection = newCollection; this.lock = newLock == null ? this : newLock; } protected Object getLock() { return this.lock; } protected MutableCollection getCollection() { return this.collection; } public int size() { synchronized (this.lock) { return this.collection.size(); } } public boolean isEmpty() { synchronized (this.lock) { return this.collection.isEmpty(); } } public boolean contains(Object o) { synchronized (this.lock) { return this.collection.contains(o); } } public Object[] toArray() { synchronized (this.lock) { return this.collection.toArray(); } } public T[] toArray(T[] a) { synchronized (this.lock) { return this.collection.toArray(a); } } @Override public String toString() { synchronized (this.lock) { return this.collection.toString(); } } /** * Must be called in a synchronized block. */ public Iterator iterator() { return this.collection.iterator(); } public boolean add(T o) { synchronized (this.lock) { return this.collection.add(o); } } public boolean remove(Object o) { synchronized (this.lock) { return this.collection.remove(o); } } public boolean containsAll(Collection coll) { synchronized (this.lock) { return this.collection.containsAll(coll); } } public boolean containsAllIterable(Iterable source) { synchronized (this.lock) { return this.collection.containsAllIterable(source); } } public boolean containsAllArguments(Object... elements) { synchronized (this.lock) { return this.collection.containsAllArguments(elements); } } public boolean addAll(Collection coll) { synchronized (this.lock) { return this.collection.addAll(coll); } } public boolean removeAll(Collection coll) { synchronized (this.lock) { return this.collection.removeAll(coll); } } public boolean retainAll(Collection coll) { synchronized (this.lock) { return this.collection.retainAll(coll); } } public void clear() { synchronized (this.lock) { this.collection.clear(); } } public void forEach(Procedure procedure) { synchronized (this.lock) { this.collection.forEach(procedure); } } public

void forEachWith(Procedure2 procedure, P parameter) { synchronized (this.lock) { this.collection.forEachWith(procedure, parameter); } } public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { synchronized (this.lock) { this.collection.forEachWithIndex(objectIntProcedure); } } public boolean allSatisfy(Predicate predicate) { synchronized (this.lock) { return this.collection.allSatisfy(predicate); } } public

boolean allSatisfyWith(Predicate2 predicate, P parameter) { synchronized (this.lock) { return this.collection.allSatisfyWith(predicate, parameter); } } public boolean noneSatisfy(Predicate predicate) { synchronized (this.lock) { return this.collection.noneSatisfy(predicate); } } public

boolean noneSatisfyWith(Predicate2 predicate, P parameter) { synchronized (this.lock) { return this.collection.noneSatisfyWith(predicate, parameter); } } public boolean anySatisfy(Predicate predicate) { synchronized (this.lock) { return this.collection.anySatisfy(predicate); } } public

boolean anySatisfyWith(Predicate2 predicate, P parameter) { synchronized (this.lock) { return this.collection.anySatisfyWith(predicate, parameter); } } public MutableList toList() { synchronized (this.lock) { return this.collection.toList(); } } public MutableMap toMap( Function keyFunction, Function valueFunction) { synchronized (this.lock) { return this.collection.toMap(keyFunction, valueFunction); } } public MutableSortedMap toSortedMap( Function keyFunction, Function valueFunction) { synchronized (this.lock) { return this.collection.toSortedMap(keyFunction, valueFunction); } } public MutableSortedMap toSortedMap(Comparator comparator, Function keyFunction, Function valueFunction) { synchronized (this.lock) { return this.collection.toSortedMap(comparator, keyFunction, valueFunction); } } public LazyIterable asLazy() { return LazyIterate.adapt(this); } public MutableSet toSet() { synchronized (this.lock) { return this.collection.toSet(); } } public MutableBag toBag() { synchronized (this.lock) { return this.collection.toBag(); } } public MutableList toSortedList() { synchronized (this.lock) { return this.collection.toSortedList(); } } public MutableList toSortedList(Comparator comparator) { synchronized (this.lock) { return this.collection.toSortedList(comparator); } } public > MutableList toSortedListBy(Function function) { synchronized (this.lock) { return this.collection.toSortedList(Comparators.byFunction(function)); } } public MutableSortedSet toSortedSet() { synchronized (this.lock) { return TreeSortedSet.newSet(null, this); } } public MutableSortedSet toSortedSet(Comparator comparator) { synchronized (this.lock) { return TreeSortedSet.newSet(comparator, this); } } public > MutableSortedSet toSortedSetBy(Function function) { synchronized (this.lock) { return this.toSortedSet(Comparators.byFunction(function)); } } public MutableCollection asUnmodifiable() { synchronized (this.lock) { return new UnmodifiableMutableCollection(this); } } public MutableCollection asSynchronized() { return this; } public ImmutableCollection toImmutable() { synchronized (this.lock) { return this.collection.toImmutable(); } } public MutableCollection collect(Function function) { synchronized (this.lock) { return this.collection.collect(function); } } public MutableBooleanCollection collectBoolean(BooleanFunction booleanFunction) { synchronized (this.lock) { return this.collection.collectBoolean(booleanFunction); } } public R collectBoolean(BooleanFunction booleanFunction, R target) { synchronized (this.lock) { return this.collection.collectBoolean(booleanFunction, target); } } public MutableByteCollection collectByte(ByteFunction byteFunction) { synchronized (this.lock) { return this.collection.collectByte(byteFunction); } } public R collectByte(ByteFunction byteFunction, R target) { synchronized (this.lock) { return this.collection.collectByte(byteFunction, target); } } public MutableCharCollection collectChar(CharFunction charFunction) { synchronized (this.lock) { return this.collection.collectChar(charFunction); } } public R collectChar(CharFunction charFunction, R target) { synchronized (this.lock) { return this.collection.collectChar(charFunction, target); } } public MutableDoubleCollection collectDouble(DoubleFunction doubleFunction) { synchronized (this.lock) { return this.collection.collectDouble(doubleFunction); } } public R collectDouble(DoubleFunction doubleFunction, R target) { synchronized (this.lock) { return this.collection.collectDouble(doubleFunction, target); } } public MutableFloatCollection collectFloat(FloatFunction floatFunction) { synchronized (this.lock) { return this.collection.collectFloat(floatFunction); } } public R collectFloat(FloatFunction floatFunction, R target) { synchronized (this.lock) { return this.collection.collectFloat(floatFunction, target); } } public MutableIntCollection collectInt(IntFunction intFunction) { synchronized (this.lock) { return this.collection.collectInt(intFunction); } } public R collectInt(IntFunction intFunction, R target) { synchronized (this.lock) { return this.collection.collectInt(intFunction, target); } } public MutableLongCollection collectLong(LongFunction longFunction) { synchronized (this.lock) { return this.collection.collectLong(longFunction); } } public R collectLong(LongFunction longFunction, R target) { synchronized (this.lock) { return this.collection.collectLong(longFunction, target); } } public MutableShortCollection collectShort(ShortFunction shortFunction) { synchronized (this.lock) { return this.collection.collectShort(shortFunction); } } public R collectShort(ShortFunction shortFunction, R target) { synchronized (this.lock) { return this.collection.collectShort(shortFunction, target); } } public > R collect(Function function, R target) { synchronized (this.lock) { return this.collection.collect(function, target); } } public MutableCollection flatCollect(Function> function) { synchronized (this.lock) { return this.collection.flatCollect(function); } } public > R flatCollect(Function> function, R target) { synchronized (this.lock) { return this.collection.flatCollect(function, target); } } public MutableCollection collectIf( Predicate predicate, Function function) { synchronized (this.lock) { return this.collection.collectIf(predicate, function); } } public > R collectIf( Predicate predicate, Function function, R target) { synchronized (this.lock) { return this.collection.collectIf(predicate, function, target); } } public MutableCollection collectWith(Function2 function, P parameter) { synchronized (this.lock) { return this.collection.collectWith(function, parameter); } } public > R collectWith( Function2 function, P parameter, R targetCollection) { synchronized (this.lock) { return this.collection.collectWith(function, parameter, targetCollection); } } public int count(Predicate predicate) { synchronized (this.lock) { return this.collection.count(predicate); } } public

int countWith(Predicate2 predicate, P parameter) { synchronized (this.lock) { return this.collection.countWith(predicate, parameter); } } public T detect(Predicate predicate) { synchronized (this.lock) { return this.collection.detect(predicate); } } public T min(Comparator comparator) { synchronized (this.lock) { return this.collection.min(comparator); } } public T max(Comparator comparator) { synchronized (this.lock) { return this.collection.max(comparator); } } public T min() { synchronized (this.lock) { return this.collection.min(); } } public T max() { synchronized (this.lock) { return this.collection.max(); } } public > T minBy(Function function) { synchronized (this.lock) { return this.collection.minBy(function); } } public > T maxBy(Function function) { synchronized (this.lock) { return this.collection.maxBy(function); } } public T detectIfNone(Predicate predicate, Function0 function) { synchronized (this.lock) { return this.collection.detectIfNone(predicate, function); } } public

T detectWith(Predicate2 predicate, P parameter) { synchronized (this.lock) { return this.collection.detectWith(predicate, parameter); } } public

T detectWithIfNone( Predicate2 predicate, P parameter, Function0 function) { synchronized (this.lock) { return this.collection.detectWithIfNone(predicate, parameter, function); } } public T getFirst() { synchronized (this.lock) { return this.collection.getFirst(); } } public T getLast() { synchronized (this.lock) { return this.collection.getLast(); } } public IV injectInto(IV injectedValue, Function2 function) { synchronized (this.lock) { return this.collection.injectInto(injectedValue, function); } } public int injectInto(int injectedValue, IntObjectToIntFunction function) { synchronized (this.lock) { return this.collection.injectInto(injectedValue, function); } } public long injectInto(long injectedValue, LongObjectToLongFunction function) { synchronized (this.lock) { return this.collection.injectInto(injectedValue, function); } } public double injectInto(double injectedValue, DoubleObjectToDoubleFunction function) { synchronized (this.lock) { return this.collection.injectInto(injectedValue, function); } } public float injectInto(float injectedValue, FloatObjectToFloatFunction function) { synchronized (this.lock) { return this.collection.injectInto(injectedValue, function); } } public long sumOfInt(IntFunction function) { synchronized (this.lock) { return this.collection.sumOfInt(function); } } public double sumOfFloat(FloatFunction function) { synchronized (this.lock) { return this.collection.sumOfFloat(function); } } public long sumOfLong(LongFunction function) { synchronized (this.lock) { return this.collection.sumOfLong(function); } } public double sumOfDouble(DoubleFunction function) { synchronized (this.lock) { return this.collection.sumOfDouble(function); } } public IV injectIntoWith( IV injectValue, Function3 function, P parameter) { synchronized (this.lock) { return this.collection.injectIntoWith(injectValue, function, parameter); } } public MutableCollection newEmpty() { synchronized (this.lock) { return this.collection.newEmpty(); } } public boolean notEmpty() { synchronized (this.lock) { return this.collection.notEmpty(); } } public MutableCollection reject(Predicate predicate) { synchronized (this.lock) { return this.collection.reject(predicate); } } public > R reject(Predicate predicate, R target) { synchronized (this.lock) { return this.collection.reject(predicate, target); } } public

MutableCollection rejectWith( Predicate2 predicate, P parameter) { synchronized (this.lock) { return this.collection.rejectWith(predicate, parameter); } } public > R rejectWith( Predicate2 predicate, P parameter, R targetCollection) { synchronized (this.lock) { return this.collection.rejectWith(predicate, parameter, targetCollection); } } public void removeIf(Predicate predicate) { synchronized (this.lock) { this.collection.removeIf(predicate); } } public

void removeIfWith(Predicate2 predicate, P parameter) { synchronized (this.lock) { this.collection.removeIfWith(predicate, parameter); } } public MutableCollection select(Predicate predicate) { synchronized (this.lock) { return this.collection.select(predicate); } } public > R select(Predicate predicate, R target) { synchronized (this.lock) { return this.collection.select(predicate, target); } } public

Twin> selectAndRejectWith( Predicate2 predicate, P parameter) { synchronized (this.lock) { return this.collection.selectAndRejectWith(predicate, parameter); } } public PartitionMutableCollection partition(Predicate predicate) { synchronized (this.lock) { return this.collection.partition(predicate); } } public

PartitionMutableCollection partitionWith(Predicate2 predicate, P parameter) { synchronized (this.lock) { return this.collection.partitionWith(predicate, parameter); } } public

MutableCollection selectWith( Predicate2 predicate, P parameter) { synchronized (this.lock) { return this.collection.selectWith(predicate, parameter); } } public > R selectWith( Predicate2 predicate, P parameter, R targetCollection) { synchronized (this.lock) { return this.collection.selectWith(predicate, parameter, targetCollection); } } public MutableCollection selectInstancesOf(Class clazz) { synchronized (this.lock) { return this.collection.selectInstancesOf(clazz); } } public String makeString() { return this.makeString(", "); } public String makeString(String separator) { return this.makeString("", separator, ""); } public String makeString(String start, String separator, String end) { Appendable stringBuilder = new StringBuilder(); this.appendString(stringBuilder, start, separator, end); return stringBuilder.toString(); } public void appendString(Appendable appendable) { this.appendString(appendable, ", "); } public void appendString(Appendable appendable, String separator) { this.appendString(appendable, "", separator, ""); } public void appendString(Appendable appendable, String start, String separator, String end) { synchronized (this.lock) { IterableIterate.appendString(this, appendable, start, separator, end); } } public MutableMultimap groupBy(Function function) { synchronized (this.lock) { return this.collection.groupBy(function); } } public MutableMultimap groupByEach(Function> function) { synchronized (this.lock) { return this.collection.groupByEach(function); } } public > R groupBy( Function function, R target) { synchronized (this.lock) { return this.collection.groupBy(function, target); } } public > R groupByEach( Function> function, R target) { synchronized (this.lock) { return this.collection.groupByEach(function, target); } } public MutableMap groupByUniqueKey(Function function) { synchronized (this.lock) { return this.collection.groupByUniqueKey(function); } } public MutableCollection> zip(Iterable that) { synchronized (this.lock) { return this.collection.zip(that); } } public >> R zip(Iterable that, R target) { synchronized (this.lock) { return this.collection.zip(that, target); } } public MutableCollection> zipWithIndex() { synchronized (this.lock) { return this.collection.zipWithIndex(); } } public >> R zipWithIndex(R target) { synchronized (this.lock) { return this.collection.zipWithIndex(target); } } public RichIterable> chunk(int size) { synchronized (this.lock) { return this.collection.chunk(size); } } public boolean addAllIterable(Iterable iterable) { synchronized (this.lock) { return this.collection.addAllIterable(iterable); } } public boolean removeAllIterable(Iterable iterable) { synchronized (this.lock) { return this.collection.removeAllIterable(iterable); } } public boolean retainAllIterable(Iterable iterable) { synchronized (this.lock) { return this.collection.retainAllIterable(iterable); } } public MutableCollection with(T element) { this.add(element); return this; } public MutableCollection without(T element) { this.remove(element); return this; } public MutableCollection withAll(Iterable elements) { this.addAllIterable(elements); return this; } public MutableCollection withoutAll(Iterable elements) { this.removeAllIterable(elements); return this; } public MutableMap aggregateInPlaceBy( Function groupBy, Function0 zeroValueFactory, Procedure2 mutatingAggregator) { MutableMap map = UnifiedMap.newMap(); this.forEach(new MutatingAggregationProcedure(map, groupBy, zeroValueFactory, mutatingAggregator)); return map; } public MutableMap aggregateBy( Function groupBy, Function0 zeroValueFactory, Function2 nonMutatingAggregator) { MutableMap map = UnifiedMap.newMap(); this.forEach(new NonMutatingAggregationProcedure(map, groupBy, zeroValueFactory, nonMutatingAggregator)); return map; } } AbstractUnmodifiableMutableCollection.java000066400000000000000000000641471234315411400420540ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/collection/mutable/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.collection.mutable; import java.util.Collection; import java.util.Comparator; import java.util.Iterator; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.RichIterable; import com.gs.collections.api.bag.MutableBag; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.Function3; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.DoubleObjectToDoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.FloatObjectToFloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.IntObjectToIntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.LongObjectToLongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.collection.ImmutableCollection; import com.gs.collections.api.collection.MutableCollection; import com.gs.collections.api.collection.primitive.MutableBooleanCollection; import com.gs.collections.api.collection.primitive.MutableByteCollection; import com.gs.collections.api.collection.primitive.MutableCharCollection; import com.gs.collections.api.collection.primitive.MutableDoubleCollection; import com.gs.collections.api.collection.primitive.MutableFloatCollection; import com.gs.collections.api.collection.primitive.MutableIntCollection; import com.gs.collections.api.collection.primitive.MutableLongCollection; import com.gs.collections.api.collection.primitive.MutableShortCollection; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.map.MutableMap; import com.gs.collections.api.map.sorted.MutableSortedMap; import com.gs.collections.api.multimap.MutableMultimap; import com.gs.collections.api.partition.PartitionMutableCollection; import com.gs.collections.api.set.MutableSet; import com.gs.collections.api.set.sorted.MutableSortedSet; import com.gs.collections.api.tuple.Pair; import com.gs.collections.api.tuple.Twin; import com.gs.collections.impl.UnmodifiableIteratorAdapter; import com.gs.collections.impl.block.factory.Comparators; import com.gs.collections.impl.block.procedure.MutatingAggregationProcedure; import com.gs.collections.impl.block.procedure.NonMutatingAggregationProcedure; import com.gs.collections.impl.map.mutable.UnifiedMap; import com.gs.collections.impl.utility.LazyIterate; public class AbstractUnmodifiableMutableCollection implements MutableCollection { private final MutableCollection collection; protected AbstractUnmodifiableMutableCollection(MutableCollection mutableCollection) { if (mutableCollection == null) { throw new NullPointerException("cannot create a UnmodifiableMutableCollection for null"); } this.collection = mutableCollection; } public int size() { return this.collection.size(); } public boolean isEmpty() { return this.collection.isEmpty(); } public boolean contains(Object o) { return this.collection.contains(o); } public Iterator iterator() { return new UnmodifiableIteratorAdapter(this.collection.iterator()); } public Object[] toArray() { return this.collection.toArray(); } public S[] toArray(S[] a) { return this.collection.toArray(a); } public boolean add(T o) { throw new UnsupportedOperationException("Cannot call add() on " + this.getClass().getSimpleName()); } public boolean remove(Object o) { throw new UnsupportedOperationException("Cannot call remove() on " + this.getClass().getSimpleName()); } public boolean containsAll(Collection c) { return this.collection.containsAll(c); } public boolean addAll(Collection c) { throw new UnsupportedOperationException("Cannot call addAll() on " + this.getClass().getSimpleName()); } public boolean retainAll(Collection c) { throw new UnsupportedOperationException("Cannot call retainAll() on " + this.getClass().getSimpleName()); } public boolean removeAll(Collection c) { throw new UnsupportedOperationException("Cannot call removeAll() on " + this.getClass().getSimpleName()); } public void clear() { throw new UnsupportedOperationException("Cannot call clear() on " + this.getClass().getSimpleName()); } protected MutableCollection getMutableCollection() { return (MutableCollection) this.collection; } public boolean addAllIterable(Iterable iterable) { throw new UnsupportedOperationException("Cannot call addAllIterable() on " + this.getClass().getSimpleName()); } public boolean removeAllIterable(Iterable iterable) { throw new UnsupportedOperationException("Cannot call removeAllIterable() on " + this.getClass().getSimpleName()); } public boolean retainAllIterable(Iterable iterable) { throw new UnsupportedOperationException("Cannot call retainAllIterable() on " + this.getClass().getSimpleName()); } public MutableCollection asUnmodifiable() { return this; } public MutableCollection asSynchronized() { return SynchronizedMutableCollection.of(this); } public ImmutableCollection toImmutable() { return this.getMutableCollection().toImmutable(); } public LazyIterable asLazy() { return LazyIterate.adapt(this); } public void forEach(Procedure procedure) { this.getMutableCollection().forEach(procedure); } public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { this.getMutableCollection().forEachWithIndex(objectIntProcedure); } public

void forEachWith(Procedure2 procedure, P parameter) { this.getMutableCollection().forEachWith(procedure, parameter); } public boolean containsAllIterable(Iterable source) { return this.getMutableCollection().containsAllIterable(source); } public boolean containsAllArguments(Object... elements) { return this.getMutableCollection().containsAllArguments(elements); } public boolean notEmpty() { return this.getMutableCollection().notEmpty(); } public MutableCollection newEmpty() { return this.getMutableCollection().newEmpty(); } public T getFirst() { return this.getMutableCollection().getFirst(); } public T getLast() { return this.getMutableCollection().getLast(); } public MutableCollection select(Predicate predicate) { return this.getMutableCollection().select(predicate); } public > R select(Predicate predicate, R target) { return this.getMutableCollection().select(predicate, target); } public

MutableCollection selectWith(Predicate2 predicate, P parameter) { return this.getMutableCollection().selectWith(predicate, parameter); } public > R selectWith( Predicate2 predicate, P parameter, R targetCollection) { return this.getMutableCollection().selectWith(predicate, parameter, targetCollection); } public MutableCollection reject(Predicate predicate) { return this.getMutableCollection().reject(predicate); } public > R reject(Predicate predicate, R target) { return this.getMutableCollection().reject(predicate, target); } public

MutableCollection rejectWith(Predicate2 predicate, P parameter) { return this.getMutableCollection().rejectWith(predicate, parameter); } public > R rejectWith( Predicate2 predicate, P parameter, R targetCollection) { return this.getMutableCollection().rejectWith(predicate, parameter, targetCollection); } public

Twin> selectAndRejectWith( Predicate2 predicate, P parameter) { return this.getMutableCollection().selectAndRejectWith(predicate, parameter); } public PartitionMutableCollection partition(Predicate predicate) { return this.getMutableCollection().partition(predicate); } public

PartitionMutableCollection partitionWith(Predicate2 predicate, P parameter) { return this.getMutableCollection().partitionWith(predicate, parameter); } public MutableCollection selectInstancesOf(Class clazz) { return this.getMutableCollection().selectInstancesOf(clazz); } public void removeIf(Predicate predicate) { throw new UnsupportedOperationException("Cannot call removeIf() on " + this.getClass().getSimpleName()); } public

void removeIfWith(Predicate2 predicate, P parameter) { throw new UnsupportedOperationException("Cannot call removeIfWith() on " + this.getClass().getSimpleName()); } public MutableCollection collect(Function function) { return this.getMutableCollection().collect(function); } public MutableBooleanCollection collectBoolean(BooleanFunction booleanFunction) { return this.getMutableCollection().collectBoolean(booleanFunction); } public R collectBoolean(BooleanFunction booleanFunction, R target) { return this.getMutableCollection().collectBoolean(booleanFunction, target); } public MutableByteCollection collectByte(ByteFunction byteFunction) { return this.getMutableCollection().collectByte(byteFunction); } public R collectByte(ByteFunction byteFunction, R target) { return this.getMutableCollection().collectByte(byteFunction, target); } public MutableCharCollection collectChar(CharFunction charFunction) { return this.getMutableCollection().collectChar(charFunction); } public R collectChar(CharFunction charFunction, R target) { return this.getMutableCollection().collectChar(charFunction, target); } public MutableDoubleCollection collectDouble(DoubleFunction doubleFunction) { return this.getMutableCollection().collectDouble(doubleFunction); } public R collectDouble(DoubleFunction doubleFunction, R target) { return this.getMutableCollection().collectDouble(doubleFunction, target); } public MutableFloatCollection collectFloat(FloatFunction floatFunction) { return this.getMutableCollection().collectFloat(floatFunction); } public R collectFloat(FloatFunction floatFunction, R target) { return this.getMutableCollection().collectFloat(floatFunction, target); } public MutableIntCollection collectInt(IntFunction intFunction) { return this.getMutableCollection().collectInt(intFunction); } public R collectInt(IntFunction intFunction, R target) { return this.getMutableCollection().collectInt(intFunction, target); } public MutableLongCollection collectLong(LongFunction longFunction) { return this.getMutableCollection().collectLong(longFunction); } public R collectLong(LongFunction longFunction, R target) { return this.getMutableCollection().collectLong(longFunction, target); } public MutableShortCollection collectShort(ShortFunction shortFunction) { return this.getMutableCollection().collectShort(shortFunction); } public R collectShort(ShortFunction shortFunction, R target) { return this.getMutableCollection().collectShort(shortFunction, target); } public > R collect(Function function, R target) { return this.getMutableCollection().collect(function, target); } public MutableCollection flatCollect(Function> function) { return this.getMutableCollection().flatCollect(function); } public > R flatCollect(Function> function, R target) { return this.getMutableCollection().flatCollect(function, target); } public MutableCollection collectWith(Function2 function, P parameter) { return this.getMutableCollection().collectWith(function, parameter); } public > R collectWith( Function2 function, P parameter, R targetCollection) { return this.getMutableCollection().collectWith(function, parameter, targetCollection); } public MutableCollection collectIf( Predicate predicate, Function function) { return this.getMutableCollection().collectIf(predicate, function); } public > R collectIf( Predicate predicate, Function function, R target) { return this.getMutableCollection().collectIf(predicate, function, target); } public T detect(Predicate predicate) { return this.getMutableCollection().detect(predicate); } public T min(Comparator comparator) { return this.getMutableCollection().min(comparator); } public T max(Comparator comparator) { return this.getMutableCollection().max(comparator); } public T min() { return this.getMutableCollection().min(); } public T max() { return this.getMutableCollection().max(); } public > T minBy(Function function) { return this.getMutableCollection().minBy(function); } public > T maxBy(Function function) { return this.getMutableCollection().maxBy(function); } public T detectIfNone(Predicate predicate, Function0 function) { return this.getMutableCollection().detectIfNone(predicate, function); } public

T detectWith(Predicate2 predicate, P parameter) { return this.getMutableCollection().detectWith(predicate, parameter); } public

T detectWithIfNone( Predicate2 predicate, P parameter, Function0 function) { return this.getMutableCollection().detectWithIfNone(predicate, parameter, function); } public int count(Predicate predicate) { return this.getMutableCollection().count(predicate); } public

int countWith(Predicate2 predicate, P parameter) { return this.getMutableCollection().countWith(predicate, parameter); } public boolean anySatisfy(Predicate predicate) { return this.getMutableCollection().anySatisfy(predicate); } public

boolean anySatisfyWith(Predicate2 predicate, P parameter) { return this.getMutableCollection().anySatisfyWith(predicate, parameter); } public boolean allSatisfy(Predicate predicate) { return this.getMutableCollection().allSatisfy(predicate); } public

boolean allSatisfyWith(Predicate2 predicate, P parameter) { return this.getMutableCollection().allSatisfyWith(predicate, parameter); } public boolean noneSatisfy(Predicate predicate) { return this.getMutableCollection().noneSatisfy(predicate); } public

boolean noneSatisfyWith(Predicate2 predicate, P parameter) { return this.getMutableCollection().noneSatisfyWith(predicate, parameter); } public IV injectInto(IV injectedValue, Function2 function) { return this.getMutableCollection().injectInto(injectedValue, function); } public int injectInto(int injectedValue, IntObjectToIntFunction function) { return this.getMutableCollection().injectInto(injectedValue, function); } public long injectInto(long injectedValue, LongObjectToLongFunction function) { return this.getMutableCollection().injectInto(injectedValue, function); } public double injectInto(double injectedValue, DoubleObjectToDoubleFunction function) { return this.getMutableCollection().injectInto(injectedValue, function); } public float injectInto(float injectedValue, FloatObjectToFloatFunction function) { return this.getMutableCollection().injectInto(injectedValue, function); } public long sumOfInt(IntFunction function) { return this.getMutableCollection().sumOfInt(function); } public double sumOfFloat(FloatFunction function) { return this.getMutableCollection().sumOfFloat(function); } public long sumOfLong(LongFunction function) { return this.getMutableCollection().sumOfLong(function); } public double sumOfDouble(DoubleFunction function) { return this.getMutableCollection().sumOfDouble(function); } public IV injectIntoWith( IV injectValue, Function3 function, P parameter) { return this.getMutableCollection().injectIntoWith(injectValue, function, parameter); } public MutableList toList() { return this.getMutableCollection().toList(); } public MutableList toSortedList() { return this.getMutableCollection().toSortedList(); } public MutableList toSortedList(Comparator comparator) { return this.getMutableCollection().toSortedList(comparator); } public > MutableList toSortedListBy(Function function) { return this.getMutableCollection().toSortedList(Comparators.byFunction(function)); } public MutableSortedSet toSortedSet() { return this.getMutableCollection().toSortedSet(); } public MutableSortedSet toSortedSet(Comparator comparator) { return this.getMutableCollection().toSortedSet(comparator); } public > MutableSortedSet toSortedSetBy(Function function) { return this.getMutableCollection().toSortedSetBy(function); } public MutableSet toSet() { return this.getMutableCollection().toSet(); } public MutableBag toBag() { return this.getMutableCollection().toBag(); } public MutableMap toMap( Function keyFunction, Function valueFunction) { return this.getMutableCollection().toMap(keyFunction, valueFunction); } public MutableSortedMap toSortedMap( Function keyFunction, Function valueFunction) { return this.getMutableCollection().toSortedMap(keyFunction, valueFunction); } public MutableSortedMap toSortedMap(Comparator comparator, Function keyFunction, Function valueFunction) { return this.getMutableCollection().toSortedMap(comparator, keyFunction, valueFunction); } @Override public String toString() { return this.getMutableCollection().toString(); } public String makeString() { return this.getMutableCollection().makeString(); } public String makeString(String separator) { return this.getMutableCollection().makeString(separator); } public String makeString(String start, String separator, String end) { return this.getMutableCollection().makeString(start, separator, end); } public void appendString(Appendable appendable) { this.getMutableCollection().appendString(appendable); } public void appendString(Appendable appendable, String separator) { this.getMutableCollection().appendString(appendable, separator); } public void appendString(Appendable appendable, String start, String separator, String end) { this.getMutableCollection().appendString(appendable, start, separator, end); } public MutableMultimap groupBy(Function function) { return this.getMutableCollection().groupBy(function); } public > R groupBy( Function function, R target) { return this.getMutableCollection().groupBy(function, target); } public MutableMultimap groupByEach(Function> function) { return this.getMutableCollection().groupByEach(function); } public > R groupByEach( Function> function, R target) { return this.getMutableCollection().groupByEach(function, target); } public MutableMap groupByUniqueKey(Function function) { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".groupByUniqueKey() not implemented yet"); } public MutableCollection> zip(Iterable that) { return this.getMutableCollection().zip(that); } public >> R zip(Iterable that, R target) { return this.getMutableCollection().zip(that, target); } public MutableCollection> zipWithIndex() { return this.getMutableCollection().zipWithIndex(); } public >> R zipWithIndex(R target) { return this.getMutableCollection().zipWithIndex(target); } public RichIterable> chunk(int size) { return this.getMutableCollection().chunk(size); } public MutableCollection with(T element) { throw new UnsupportedOperationException("Cannot call with() on " + this.getClass().getSimpleName()); } public MutableCollection without(T element) { throw new UnsupportedOperationException("Cannot call without() on " + this.getClass().getSimpleName()); } public MutableCollection withAll(Iterable elements) { throw new UnsupportedOperationException("Cannot call withAll() on " + this.getClass().getSimpleName()); } public MutableCollection withoutAll(Iterable elements) { throw new UnsupportedOperationException("Cannot call withoutAll() on " + this.getClass().getSimpleName()); } public MutableMap aggregateInPlaceBy( Function groupBy, Function0 zeroValueFactory, Procedure2 mutatingAggregator) { MutableMap map = UnifiedMap.newMap(); this.forEach(new MutatingAggregationProcedure(map, groupBy, zeroValueFactory, mutatingAggregator)); return map; } public MutableMap aggregateBy( Function groupBy, Function0 zeroValueFactory, Function2 nonMutatingAggregator) { MutableMap map = UnifiedMap.newMap(); this.forEach(new NonMutatingAggregationProcedure(map, groupBy, zeroValueFactory, nonMutatingAggregator)); return map; } } CollectionAdapter.java000066400000000000000000000145061234315411400360320ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/collection/mutable/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.collection.mutable; import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.RandomAccess; import java.util.Set; import com.gs.collections.api.collection.ImmutableCollection; import com.gs.collections.api.collection.MutableCollection; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.set.MutableSet; import com.gs.collections.impl.block.factory.Comparators; import com.gs.collections.impl.block.procedure.CollectionAddProcedure; import com.gs.collections.impl.block.procedure.CollectionRemoveProcedure; import com.gs.collections.impl.factory.Lists; import com.gs.collections.impl.factory.Sets; import com.gs.collections.impl.list.mutable.ArrayListAdapter; import com.gs.collections.impl.list.mutable.FastList; import com.gs.collections.impl.list.mutable.ListAdapter; import com.gs.collections.impl.list.mutable.RandomAccessListAdapter; import com.gs.collections.impl.set.mutable.SetAdapter; import com.gs.collections.impl.set.mutable.UnifiedSet; import com.gs.collections.impl.utility.ArrayIterate; import com.gs.collections.impl.utility.Iterate; /** * This class provides a MutableCollection interface wrapper around a JDK Collections Collection interface instance. All * of the MutableCollection interface methods are supported in addition to the JDK Collection interface methods. *

* To create a new instance that wraps a collection with the MutableSet interface, use the {@link #wrapSet(Iterable)} * factory method. To create a new instance that wraps a collection with the MutableList interface, use the * {@link #wrapList(Iterable)} factory method. To wrap a collection with the MutableCollection interface alone, use * the {@link #adapt(Collection)} factory method. */ public final class CollectionAdapter extends AbstractCollectionAdapter implements Serializable { private static final long serialVersionUID = 1L; private final Collection delegate; public CollectionAdapter(Collection newDelegate) { if (newDelegate == null) { throw new NullPointerException("CollectionAdapter may not wrap null"); } this.delegate = newDelegate; } @Override protected Collection getDelegate() { return this.delegate; } public MutableCollection asUnmodifiable() { return UnmodifiableMutableCollection.of(this); } public MutableCollection asSynchronized() { return SynchronizedMutableCollection.of(this); } public ImmutableCollection toImmutable() { return this.delegate instanceof Set ? Sets.immutable.ofAll(this.delegate) : Lists.immutable.ofAll(this.delegate); } public static MutableSet wrapSet(Iterable iterable) { if (iterable instanceof MutableSet) { return (MutableSet) iterable; } if (iterable instanceof Set) { return SetAdapter.adapt((Set) iterable); } return UnifiedSet.newSet(iterable); } public static MutableList wrapList(Iterable iterable) { if (iterable instanceof MutableList) { return (MutableList) iterable; } if (iterable instanceof ArrayList) { return ArrayListAdapter.adapt((ArrayList) iterable); } if (iterable instanceof RandomAccess) { return RandomAccessListAdapter.adapt((List) iterable); } if (iterable instanceof List) { return ListAdapter.adapt((List) iterable); } return FastList.newList(iterable); } public static MutableCollection adapt(Collection collection) { if (collection instanceof MutableCollection) { return (MutableCollection) collection; } if (collection instanceof List) { return CollectionAdapter.wrapList(collection); } if (collection instanceof Set) { return SetAdapter.adapt((Set) collection); } return new CollectionAdapter(collection); } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || this.getClass() != o.getClass()) { return false; } CollectionAdapter that = (CollectionAdapter) o; return Comparators.nullSafeEquals(this.delegate, that.delegate); } @Override public int hashCode() { return this.delegate.hashCode(); } public CollectionAdapter with(T... elements) { ArrayIterate.forEach(elements, new CollectionAddProcedure(this.delegate)); return this; } public CollectionAdapter with(T element) { this.delegate.add(element); return this; } public CollectionAdapter without(T element) { this.delegate.remove(element); return this; } public CollectionAdapter withAll(Iterable elements) { Iterate.forEach(elements, new CollectionAddProcedure(this.delegate)); return this; } public CollectionAdapter withoutAll(Iterable elements) { Iterate.forEach(elements, new CollectionRemoveProcedure(this.delegate)); return this; } /** * @deprecated use {@link FastList#newList()} or {@link UnifiedSet#newSet()} instead */ @Deprecated public MutableCollection newEmpty() { if (this.delegate instanceof Set) { return UnifiedSet.newSet(); } return Lists.mutable.of(); } } SynchronizedCollectionSerializationProxy.java000066400000000000000000000033111234315411400427210ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/collection/mutable/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.collection.mutable; import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; import com.gs.collections.api.collection.MutableCollection; public class SynchronizedCollectionSerializationProxy implements Externalizable { private static final long serialVersionUID = 1L; private MutableCollection mutableCollection; @SuppressWarnings("UnusedDeclaration") public SynchronizedCollectionSerializationProxy() { // Empty constructor for Externalizable class } public SynchronizedCollectionSerializationProxy(MutableCollection collection) { this.mutableCollection = collection; } public void writeExternal(ObjectOutput out) throws IOException { out.writeObject(this.mutableCollection); } public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { this.mutableCollection = (MutableCollection) in.readObject(); } protected Object readResolve() { return this.mutableCollection.asSynchronized(); } } SynchronizedMutableCollection.java000066400000000000000000000053521234315411400404420ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/collection/mutable/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.collection.mutable; import java.io.Serializable; import java.util.Collection; import java.util.Collections; import com.gs.collections.api.collection.MutableCollection; import net.jcip.annotations.ThreadSafe; /** * A synchronized view of a {@link MutableCollection}. It is imperative that the user manually synchronize on the collection when iterating over it using the * standard JDK iterator or JDK 5 for loop, as per {@link Collections#synchronizedCollection(Collection)}. * * @see MutableCollection#asSynchronized() */ @ThreadSafe public class SynchronizedMutableCollection extends AbstractSynchronizedMutableCollection implements Serializable { SynchronizedMutableCollection(MutableCollection newCollection) { this(newCollection, null); } SynchronizedMutableCollection(MutableCollection newCollection, Object newLock) { super(newCollection, newLock); } /** * This method will take a MutableCollection and wrap it directly in a SynchronizedMutableCollection. It will * take any other non-GS-collection and first adapt it will a CollectionAdapter, and then return a * SynchronizedMutableCollection that wraps the adapter. */ public static > SynchronizedMutableCollection of(C collection) { return new SynchronizedMutableCollection(CollectionAdapter.adapt(collection)); } /** * This method will take a MutableCollection and wrap it directly in a SynchronizedMutableCollection. It will * take any other non-GS-collection and first adapt it will a CollectionAdapter, and then return a * SynchronizedMutableCollection that wraps the adapter. Additionally, a developer specifies which lock to use * with the collection. */ public static > SynchronizedMutableCollection of(C collection, Object lock) { return new SynchronizedMutableCollection(CollectionAdapter.adapt(collection), lock); } protected Object writeReplace() { return new SynchronizedCollectionSerializationProxy(this.getCollection()); } } UnmodifiableCollectionSerializationProxy.java000066400000000000000000000033111234315411400426400ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/collection/mutable/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.collection.mutable; import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; import com.gs.collections.api.collection.MutableCollection; public class UnmodifiableCollectionSerializationProxy implements Externalizable { private static final long serialVersionUID = 1L; private MutableCollection mutableCollection; @SuppressWarnings("UnusedDeclaration") public UnmodifiableCollectionSerializationProxy() { // Empty constructor for Externalizable class } public UnmodifiableCollectionSerializationProxy(MutableCollection collection) { this.mutableCollection = collection; } public void writeExternal(ObjectOutput out) throws IOException { out.writeObject(this.mutableCollection); } public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { this.mutableCollection = (MutableCollection) in.readObject(); } protected Object readResolve() { return this.mutableCollection.asUnmodifiable(); } } UnmodifiableMutableCollection.java000066400000000000000000000035751234315411400403660ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/collection/mutable/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.collection.mutable; import java.io.Serializable; import java.util.Collection; import com.gs.collections.api.collection.MutableCollection; /** * An unmodifiable view of a collection. * * @see MutableCollection#asUnmodifiable() */ public class UnmodifiableMutableCollection extends AbstractUnmodifiableMutableCollection implements Serializable { UnmodifiableMutableCollection(MutableCollection collection) { super(collection); } /** * This method will take a MutableCollection and wrap it directly in a UnmodifiableMutableCollection. It will * take any other non-GS-collection and first adapt it will a CollectionAdapter, and then return a * UnmodifiableMutableCollection that wraps the adapter. */ public static > UnmodifiableMutableCollection of(C collection) { if (collection == null) { throw new IllegalArgumentException("cannot create a UnmodifiableMutableCollection for null"); } return new UnmodifiableMutableCollection(CollectionAdapter.adapt(collection)); } protected Object writeReplace() { return new UnmodifiableCollectionSerializationProxy(this.getMutableCollection()); } } package-info.java000066400000000000000000000020621234315411400347540ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/collection/mutable/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains implementations of the {@link com.gs.collections.api.collection.MutableCollection} interface. *

* This package contains the following implementations: *

*

*/ package com.gs.collections.impl.collection.mutable; gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/collection/mutable/primitive/000077500000000000000000000000001234315411400336545ustar00rootroot00000000000000package-info.java000066400000000000000000000013661234315411400367720ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/collection/mutable/primitive/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains implementations of the mutable primitive collection interfaces. */ package com.gs.collections.impl.collection.mutable.primitive; gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/factory/000077500000000000000000000000001234315411400275275ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/factory/Bags.java000066400000000000000000000023611234315411400312500ustar00rootroot00000000000000/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.factory; import com.gs.collections.api.factory.bag.ImmutableBagFactory; import com.gs.collections.api.factory.bag.MutableBagFactory; import com.gs.collections.impl.bag.immutable.ImmutableBagFactoryImpl; import com.gs.collections.impl.bag.mutable.MutableBagFactoryImpl; @SuppressWarnings("ConstantNamingConvention") public final class Bags { public static final ImmutableBagFactory immutable = new ImmutableBagFactoryImpl(); public static final MutableBagFactory mutable = new MutableBagFactoryImpl(); private Bags() { throw new AssertionError("Suppress default constructor for noninstantiability"); } } HashingStrategyMaps.java000066400000000000000000000026531234315411400342460ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/factory/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.factory; import com.gs.collections.api.factory.map.strategy.ImmutableHashingStrategyMapFactory; import com.gs.collections.api.factory.map.strategy.MutableHashingStrategyMapFactory; import com.gs.collections.impl.map.strategy.immutable.ImmutableHashingStrategyMapFactoryImpl; import com.gs.collections.impl.map.strategy.mutable.MutableHashingStrategyMapFactoryImpl; @SuppressWarnings("ConstantNamingConvention") public final class HashingStrategyMaps { public static final ImmutableHashingStrategyMapFactory immutable = new ImmutableHashingStrategyMapFactoryImpl(); public static final MutableHashingStrategyMapFactory mutable = new MutableHashingStrategyMapFactoryImpl(); private HashingStrategyMaps() { throw new AssertionError("Suppress default constructor for noninstantiability"); } } HashingStrategySets.java000066400000000000000000000026531234315411400342640ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/factory/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.factory; import com.gs.collections.api.factory.set.strategy.ImmutableHashingStrategySetFactory; import com.gs.collections.api.factory.set.strategy.MutableHashingStrategySetFactory; import com.gs.collections.impl.set.strategy.immutable.ImmutableHashingStrategySetFactoryImpl; import com.gs.collections.impl.set.strategy.mutable.MutableHashingStrategySetFactoryImpl; @SuppressWarnings("ConstantNamingConvention") public final class HashingStrategySets { public static final ImmutableHashingStrategySetFactory immutable = new ImmutableHashingStrategySetFactoryImpl(); public static final MutableHashingStrategySetFactory mutable = new MutableHashingStrategySetFactoryImpl(); private HashingStrategySets() { throw new AssertionError("Suppress default constructor for noninstantiability"); } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/factory/Iterables.java000066400000000000000000000272561234315411400323200ustar00rootroot00000000000000/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.factory; import java.util.Comparator; import com.gs.collections.api.bag.ImmutableBag; import com.gs.collections.api.bag.MutableBag; import com.gs.collections.api.list.ImmutableList; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.map.ImmutableMap; import com.gs.collections.api.map.MutableMap; import com.gs.collections.api.map.sorted.ImmutableSortedMap; import com.gs.collections.api.map.sorted.MutableSortedMap; import com.gs.collections.api.set.ImmutableSet; import com.gs.collections.api.set.MutableSet; import com.gs.collections.api.set.sorted.ImmutableSortedSet; import com.gs.collections.api.set.sorted.MutableSortedSet; public final class Iterables { private Iterables() { throw new AssertionError("Suppress default constructor for noninstantiability"); } public static MutableList mList() { return Lists.mutable.of(); } public static MutableList mList(T... elements) { return Lists.mutable.of(elements); } public static MutableSet mSet() { return Sets.mutable.of(); } public static MutableSet mSet(T... elements) { return Sets.mutable.of(elements); } public static MutableBag mBag() { return Bags.mutable.of(); } public static MutableBag mBag(T... elements) { return Bags.mutable.of(elements); } public static MutableMap mMap() { return Maps.mutable.of(); } public static MutableMap mMap(K key, V value) { return Maps.mutable.of(key, value); } public static MutableMap mMap(K key1, V value1, K key2, V value2) { return Maps.mutable.of(key1, value1, key2, value2); } public static MutableMap mMap(K key1, V value1, K key2, V value2, K key3, V value3) { return Maps.mutable.of(key1, value1, key2, value2, key3, value3); } public static MutableMap mMap(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4) { return Maps.mutable.of(key1, value1, key2, value2, key3, value3, key4, value4); } public static MutableSortedSet mSortedSet() { return SortedSets.mutable.of(); } public static MutableSortedSet mSortedSet(T... elements) { return SortedSets.mutable.of(elements); } public static MutableSortedSet mSortedSet(Comparator comparator) { return SortedSets.mutable.of(comparator); } public static MutableSortedSet mSortedSet(Comparator comparator, T... elements) { return SortedSets.mutable.of(comparator, elements); } public static MutableSortedMap mSortedMap() { return SortedMaps.mutable.of(); } public static MutableSortedMap mSortedMap(K key, V value) { return SortedMaps.mutable.of(key, value); } public static MutableSortedMap mSortedMap(K key1, V value1, K key2, V value2) { return SortedMaps.mutable.of(key1, value1, key2, value2); } public static MutableSortedMap mSortedMap(K key1, V value1, K key2, V value2, K key3, V value3) { return SortedMaps.mutable.of(key1, value1, key2, value2, key3, value3); } public static MutableSortedMap mSortedMap(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4) { return SortedMaps.mutable.of(key1, value1, key2, value2, key3, value3, key4, value4); } public static MutableSortedMap mSortedMap(Comparator comparator) { return SortedMaps.mutable.of(comparator); } public static MutableSortedMap mSortedMap(Comparator comparator, K key, V value) { return SortedMaps.mutable.of(comparator, key, value); } public static MutableSortedMap mSortedMap( Comparator comparator, K key1, V value1, K key2, V value2) { return SortedMaps.mutable.of(comparator, key1, value1, key2, value2); } public static MutableSortedMap mSortedMap( Comparator comparator, K key1, V value1, K key2, V value2, K key3, V value3) { return SortedMaps.mutable.of(comparator, key1, value1, key2, value2, key3, value3); } public static MutableSortedMap mSortedMap( Comparator comparator, K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4) { return SortedMaps.mutable.of(comparator, key1, value1, key2, value2, key3, value3, key4, value4); } public static ImmutableList iList() { return Lists.immutable.of(); } public static ImmutableList iList(T one) { return Lists.immutable.of(one); } public static ImmutableList iList(T one, T two) { return Lists.immutable.of(one, two); } public static ImmutableList iList(T one, T two, T three) { return Lists.immutable.of(one, two, three); } public static ImmutableList iList(T one, T two, T three, T four) { return Lists.immutable.of(one, two, three, four); } public static ImmutableList iList(T one, T two, T three, T four, T five) { return Lists.immutable.of(one, two, three, four, five); } public static ImmutableList iList(T one, T two, T three, T four, T five, T six) { return Lists.immutable.of(one, two, three, four, five, six); } public static ImmutableList iList(T one, T two, T three, T four, T five, T six, T seven) { return Lists.immutable.of(one, two, three, four, five, six, seven); } public static ImmutableList iList(T one, T two, T three, T four, T five, T six, T seven, T eight) { return Lists.immutable.of(one, two, three, four, five, six, seven, eight); } public static ImmutableList iList(T one, T two, T three, T four, T five, T six, T seven, T eight, T nine) { return Lists.immutable.of(one, two, three, four, five, six, seven, eight, nine); } public static ImmutableList iList(T one, T two, T three, T four, T five, T six, T seven, T eight, T nine, T ten) { return Lists.immutable.of(one, two, three, four, five, six, seven, eight, nine, ten); } public static ImmutableList iList(T... elements) { return Lists.immutable.of(elements); } public static ImmutableSet iSet() { return Sets.immutable.of(); } public static ImmutableSet iSet(T one) { return Sets.immutable.of(one); } public static ImmutableSet iSet(T one, T two) { return Sets.immutable.of(one, two); } public static ImmutableSet iSet(T one, T two, T three) { return Sets.immutable.of(one, two, three); } public static ImmutableSet iSet(T one, T two, T three, T four) { return Sets.immutable.of(one, two, three, four); } public static ImmutableSet iSet(T... elements) { return Sets.immutable.of(elements); } public static ImmutableBag iBag() { return Bags.immutable.of(); } public static ImmutableBag iBag(T one) { return Bags.immutable.of(one); } public static ImmutableBag iBag(T... elements) { return Bags.immutable.of(elements); } public static ImmutableMap iMap() { return Maps.immutable.of(); } public static ImmutableMap iMap(K key, V value) { return Maps.immutable.of(key, value); } public static ImmutableMap iMap(K key1, V value1, K key2, V value2) { return Maps.immutable.of(key1, value1, key2, value2); } public static ImmutableMap iMap(K key1, V value1, K key2, V value2, K key3, V value3) { return Maps.immutable.of(key1, value1, key2, value2, key3, value3); } public static ImmutableMap iMap(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4) { return Maps.immutable.of(key1, value1, key2, value2, key3, value3, key4, value4); } public static ImmutableSortedSet iSortedSet() { return SortedSets.immutable.of(); } public static ImmutableSortedSet iSortedSet(T... elements) { return SortedSets.immutable.of(elements); } public static ImmutableSortedSet iSortedSet(Comparator comparator) { return SortedSets.immutable.of(comparator); } public static ImmutableSortedSet iSortedSet(Comparator comparator, T... elements) { return SortedSets.immutable.of(comparator, elements); } public static ImmutableSortedMap iSortedMap() { return SortedMaps.immutable.of(); } public static ImmutableSortedMap iSortedMap(K key, V value) { return SortedMaps.immutable.of(key, value); } public static ImmutableSortedMap iSortedMap(K key1, V value1, K key2, V value2) { return SortedMaps.immutable.of(key1, value1, key2, value2); } public static ImmutableSortedMap iSortedMap(K key1, V value1, K key2, V value2, K key3, V value3) { return SortedMaps.immutable.of(key1, value1, key2, value2, key3, value3); } public static ImmutableSortedMap iSortedMap(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4) { return SortedMaps.immutable.of(key1, value1, key2, value2, key3, value3, key4, value4); } public static ImmutableSortedMap iSortedMap(Comparator comparator) { return SortedMaps.immutable.of(comparator); } public static ImmutableSortedMap iSortedMap(Comparator comparator, K key, V value) { return SortedMaps.immutable.of(comparator, key, value); } public static ImmutableSortedMap iSortedMap( Comparator comparator, K key1, V value1, K key2, V value2) { return SortedMaps.immutable.of(comparator, key1, value1, key2, value2); } public static ImmutableSortedMap iSortedMap( Comparator comparator, K key1, V value1, K key2, V value2, K key3, V value3) { return SortedMaps.immutable.of(comparator, key1, value1, key2, value2, key3, value3); } public static ImmutableSortedMap iSortedMap( Comparator comparator, K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4) { return SortedMaps.immutable.of(comparator, key1, value1, key2, value2, key3, value3, key4, value4); } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/factory/Lists.java000066400000000000000000000027351234315411400314770ustar00rootroot00000000000000/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.factory; import com.gs.collections.api.factory.list.FixedSizeListFactory; import com.gs.collections.api.factory.list.ImmutableListFactory; import com.gs.collections.api.factory.list.MutableListFactory; import com.gs.collections.impl.list.fixed.FixedSizeListFactoryImpl; import com.gs.collections.impl.list.immutable.ImmutableListFactoryImpl; import com.gs.collections.impl.list.mutable.MutableListFactoryImpl; @SuppressWarnings("ConstantNamingConvention") public final class Lists { public static final ImmutableListFactory immutable = new ImmutableListFactoryImpl(); public static final MutableListFactory mutable = new MutableListFactoryImpl(); public static final FixedSizeListFactory fixedSize = new FixedSizeListFactoryImpl(); private Lists() { throw new AssertionError("Suppress default constructor for noninstantiability"); } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/factory/Maps.java000066400000000000000000000027111234315411400312730ustar00rootroot00000000000000/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.factory; import com.gs.collections.api.factory.map.FixedSizeMapFactory; import com.gs.collections.api.factory.map.ImmutableMapFactory; import com.gs.collections.api.factory.map.MutableMapFactory; import com.gs.collections.impl.map.fixed.FixedSizeMapFactoryImpl; import com.gs.collections.impl.map.immutable.ImmutableMapFactoryImpl; import com.gs.collections.impl.map.mutable.MutableMapFactoryImpl; @SuppressWarnings("ConstantNamingConvention") public final class Maps { public static final ImmutableMapFactory immutable = new ImmutableMapFactoryImpl(); public static final FixedSizeMapFactory fixedSize = new FixedSizeMapFactoryImpl(); public static final MutableMapFactory mutable = new MutableMapFactoryImpl(); private Maps() { throw new AssertionError("Suppress default constructor for noninstantiability"); } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/factory/Multimaps.java000066400000000000000000000360251234315411400323530ustar00rootroot00000000000000/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.factory; import java.util.Comparator; import com.gs.collections.api.bag.ImmutableBag; import com.gs.collections.api.list.ImmutableList; import com.gs.collections.api.multimap.bag.ImmutableBagMultimap; import com.gs.collections.api.multimap.bag.MutableBagMultimap; import com.gs.collections.api.multimap.list.ImmutableListMultimap; import com.gs.collections.api.multimap.list.MutableListMultimap; import com.gs.collections.api.multimap.set.ImmutableSetMultimap; import com.gs.collections.api.multimap.set.MutableSetMultimap; import com.gs.collections.api.multimap.sortedset.ImmutableSortedSetMultimap; import com.gs.collections.api.multimap.sortedset.MutableSortedSetMultimap; import com.gs.collections.api.set.ImmutableSet; import com.gs.collections.api.set.sorted.ImmutableSortedSet; import com.gs.collections.impl.multimap.bag.HashBagMultimap; import com.gs.collections.impl.multimap.bag.ImmutableBagMultimapImpl; import com.gs.collections.impl.multimap.list.FastListMultimap; import com.gs.collections.impl.multimap.list.ImmutableListMultimapImpl; import com.gs.collections.impl.multimap.set.ImmutableSetMultimapImpl; import com.gs.collections.impl.multimap.set.UnifiedSetMultimap; import com.gs.collections.impl.multimap.set.sorted.ImmutableSortedSetMultimapImpl; import com.gs.collections.impl.multimap.set.sorted.TreeSortedSetMultimap; @SuppressWarnings("ConstantNamingConvention") public final class Multimaps { public static final ImmutableMultimaps immutable = new ImmutableMultimaps(); public static final MutableMultimaps mutable = new MutableMultimaps(); private Multimaps() { throw new AssertionError("Suppress default constructor for noninstantiability"); } @SuppressWarnings("PublicField") public static final class ImmutableMultimaps { public final ImmutableListMultimapFactory list = new ImmutableListMultimapFactory(); public final ImmutableSetMultimapFactory set = new ImmutableSetMultimapFactory(); public final ImmutableSortedSetMultimapFactory sortedSet = new ImmutableSortedSetMultimapFactory(); public final ImmutableBagMultimapFactory bag = new ImmutableBagMultimapFactory(); private ImmutableMultimaps() { } public static final class ImmutableListMultimapFactory { public static final ImmutableListMultimap EMPTY = new ImmutableListMultimapImpl(Maps.immutable.>with()); private ImmutableListMultimapFactory() { } public ImmutableListMultimap with() { return (ImmutableListMultimap) EMPTY; } public ImmutableListMultimap with(K key, V value) { return new ImmutableListMultimapImpl(Maps.immutable.with(key, Lists.immutable.with(value))); } public ImmutableListMultimap with(K key1, V value1, K key2, V value2) { FastListMultimap fastListMultimap = FastListMultimap.newMultimap(); fastListMultimap.put(key1, value1); fastListMultimap.put(key2, value2); return fastListMultimap.toImmutable(); } public ImmutableListMultimap with(K key1, V value1, K key2, V value2, K key3, V value3) { FastListMultimap fastListMultimap = FastListMultimap.newMultimap(); fastListMultimap.put(key1, value1); fastListMultimap.put(key2, value2); fastListMultimap.put(key3, value3); return fastListMultimap.toImmutable(); } } public static final class ImmutableSetMultimapFactory { public static final ImmutableSetMultimap EMPTY = new ImmutableSetMultimapImpl(Maps.immutable.>with()); private ImmutableSetMultimapFactory() { } public ImmutableSetMultimap with() { return (ImmutableSetMultimap) EMPTY; } public ImmutableSetMultimap with(K key, V value) { return new ImmutableSetMultimapImpl(Maps.immutable.with(key, Sets.immutable.with(value))); } public ImmutableSetMultimap with(K key1, V value1, K key2, V value2) { UnifiedSetMultimap unifiedSetMultimap = UnifiedSetMultimap.newMultimap(); unifiedSetMultimap.put(key1, value1); unifiedSetMultimap.put(key2, value2); return unifiedSetMultimap.toImmutable(); } public ImmutableSetMultimap with(K key1, V value1, K key2, V value2, K key3, V value3) { UnifiedSetMultimap unifiedSetMultimap = UnifiedSetMultimap.newMultimap(); unifiedSetMultimap.put(key1, value1); unifiedSetMultimap.put(key2, value2); unifiedSetMultimap.put(key3, value3); return unifiedSetMultimap.toImmutable(); } } public static final class ImmutableSortedSetMultimapFactory { private ImmutableSortedSetMultimapFactory() { } public ImmutableSortedSetMultimap with(Comparator comparator) { return new ImmutableSortedSetMultimapImpl(Maps.immutable.>with(), comparator); } public ImmutableSortedSetMultimap with(Comparator comparator, K key, V value) { return new ImmutableSortedSetMultimapImpl(Maps.immutable.with(key, SortedSets.immutable.with(comparator, value)), comparator); } public ImmutableSortedSetMultimap with(Comparator comparator, K key1, V value1, K key2, V value2) { TreeSortedSetMultimap treeSortedSetMultimap = TreeSortedSetMultimap.newMultimap(comparator); treeSortedSetMultimap.put(key1, value1); treeSortedSetMultimap.put(key2, value2); return treeSortedSetMultimap.toImmutable(); } public ImmutableSortedSetMultimap with(Comparator comparator, K key1, V value1, K key2, V value2, K key3, V value3) { TreeSortedSetMultimap treeSortedSetMultimap = TreeSortedSetMultimap.newMultimap(comparator); treeSortedSetMultimap.put(key1, value1); treeSortedSetMultimap.put(key2, value2); treeSortedSetMultimap.put(key3, value3); return treeSortedSetMultimap.toImmutable(); } } public static final class ImmutableBagMultimapFactory { public static final ImmutableBagMultimap EMPTY = new ImmutableBagMultimapImpl(Maps.immutable.>with()); private ImmutableBagMultimapFactory() { } public ImmutableBagMultimap with() { return (ImmutableBagMultimap) EMPTY; } public ImmutableBagMultimap with(K key, V value) { return new ImmutableBagMultimapImpl(Maps.immutable.with(key, Bags.immutable.with(value))); } public ImmutableBagMultimap with(K key1, V value1, K key2, V value2) { HashBagMultimap hashBagMultimap = HashBagMultimap.newMultimap(); hashBagMultimap.put(key1, value1); hashBagMultimap.put(key2, value2); return hashBagMultimap.toImmutable(); } public ImmutableBagMultimap with(K key1, V value1, K key2, V value2, K key3, V value3) { HashBagMultimap hashBagMultimap = HashBagMultimap.newMultimap(); hashBagMultimap.put(key1, value1); hashBagMultimap.put(key2, value2); hashBagMultimap.put(key3, value3); return hashBagMultimap.toImmutable(); } } } @SuppressWarnings("PublicField") public static final class MutableMultimaps { public final MutableListMultimapFactory list = new MutableListMultimapFactory(); public final MutableSetMultimapFactory set = new MutableSetMultimapFactory(); public final MutableSortedSetMultimapFactory sortedSet = new MutableSortedSetMultimapFactory(); public final MutableBagMultimapFactory bag = new MutableBagMultimapFactory(); private MutableMultimaps() { } public static final class MutableListMultimapFactory { private MutableListMultimapFactory() { } public MutableListMultimap with() { return FastListMultimap.newMultimap(); } public MutableListMultimap with(K key, V value) { FastListMultimap fastListMultimap = FastListMultimap.newMultimap(); fastListMultimap.put(key, value); return fastListMultimap; } public MutableListMultimap with(K key1, V value1, K key2, V value2) { FastListMultimap fastListMultimap = FastListMultimap.newMultimap(); fastListMultimap.put(key1, value1); fastListMultimap.put(key2, value2); return fastListMultimap; } public MutableListMultimap with(K key1, V value1, K key2, V value2, K key3, V value3) { FastListMultimap fastListMultimap = FastListMultimap.newMultimap(); fastListMultimap.put(key1, value1); fastListMultimap.put(key2, value2); fastListMultimap.put(key3, value3); return fastListMultimap; } } public static final class MutableSetMultimapFactory { private MutableSetMultimapFactory() { } public MutableSetMultimap with() { return UnifiedSetMultimap.newMultimap(); } public MutableSetMultimap with(K key, V value) { UnifiedSetMultimap unifiedSetMultimap = UnifiedSetMultimap.newMultimap(); unifiedSetMultimap.put(key, value); return unifiedSetMultimap; } public MutableSetMultimap with(K key1, V value1, K key2, V value2) { UnifiedSetMultimap unifiedSetMultimap = UnifiedSetMultimap.newMultimap(); unifiedSetMultimap.put(key1, value1); unifiedSetMultimap.put(key2, value2); return unifiedSetMultimap; } public MutableSetMultimap with(K key1, V value1, K key2, V value2, K key3, V value3) { UnifiedSetMultimap unifiedSetMultimap = UnifiedSetMultimap.newMultimap(); unifiedSetMultimap.put(key1, value1); unifiedSetMultimap.put(key2, value2); unifiedSetMultimap.put(key3, value3); return unifiedSetMultimap; } } public static final class MutableSortedSetMultimapFactory { private MutableSortedSetMultimapFactory() { } public MutableSortedSetMultimap with(Comparator comparator) { return TreeSortedSetMultimap.newMultimap(comparator); } public MutableSortedSetMultimap with(Comparator comparator, K key, V value) { TreeSortedSetMultimap treeSortedSetMultimap = TreeSortedSetMultimap.newMultimap(comparator); treeSortedSetMultimap.put(key, value); return treeSortedSetMultimap; } public MutableSortedSetMultimap with(Comparator comparator, K key1, V value1, K key2, V value2) { TreeSortedSetMultimap treeSortedSetMultimap = TreeSortedSetMultimap.newMultimap(comparator); treeSortedSetMultimap.put(key1, value1); treeSortedSetMultimap.put(key2, value2); return treeSortedSetMultimap; } public MutableSortedSetMultimap with(Comparator comparator, K key1, V value1, K key2, V value2, K key3, V value3) { TreeSortedSetMultimap treeSortedSetMultimap = TreeSortedSetMultimap.newMultimap(comparator); treeSortedSetMultimap.put(key1, value1); treeSortedSetMultimap.put(key2, value2); treeSortedSetMultimap.put(key3, value3); return treeSortedSetMultimap; } } public static final class MutableBagMultimapFactory { private MutableBagMultimapFactory() { } public MutableBagMultimap with() { return HashBagMultimap.newMultimap(); } public MutableBagMultimap with(K key, V value) { HashBagMultimap hashBagMultimap = HashBagMultimap.newMultimap(); hashBagMultimap.put(key, value); return hashBagMultimap; } public MutableBagMultimap with(K key1, V value1, K key2, V value2) { HashBagMultimap hashBagMultimap = HashBagMultimap.newMultimap(); hashBagMultimap.put(key1, value1); hashBagMultimap.put(key2, value2); return hashBagMultimap; } public MutableBagMultimap with(K key1, V value1, K key2, V value2, K key3, V value3) { HashBagMultimap hashBagMultimap = HashBagMultimap.newMultimap(); hashBagMultimap.put(key1, value1); hashBagMultimap.put(key2, value2); hashBagMultimap.put(key3, value3); return hashBagMultimap; } } } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/factory/Sets.java000066400000000000000000000254421234315411400313170ustar00rootroot00000000000000/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.factory; import java.util.Collection; import java.util.Comparator; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.factory.set.FixedSizeSetFactory; import com.gs.collections.api.factory.set.ImmutableSetFactory; import com.gs.collections.api.factory.set.MutableSetFactory; import com.gs.collections.api.set.MutableSet; import com.gs.collections.api.tuple.Pair; import com.gs.collections.impl.block.factory.Comparators; import com.gs.collections.impl.set.fixed.FixedSizeSetFactoryImpl; import com.gs.collections.impl.set.immutable.ImmutableSetFactoryImpl; import com.gs.collections.impl.set.mutable.MutableSetFactoryImpl; import com.gs.collections.impl.set.mutable.SetAdapter; import com.gs.collections.impl.set.mutable.UnifiedSet; import com.gs.collections.impl.tuple.Tuples; import com.gs.collections.impl.utility.ArrayIterate; import com.gs.collections.impl.utility.Iterate; import com.gs.collections.impl.utility.LazyIterate; /** * Set algebra operations. *

* Most operations are non-destructive, i.e. no input sets are modified during execution. * The exception is operations ending in "Into." These accept the target collection of * the final calculation as the first parameter. *

* Some effort is made to return a SortedSet if any input set is sorted, but * this is not guaranteed (e.g., this will not be the case for collections proxied by * Hibernate). When in doubt, specify the target collection explicitly with the "Into" * version. */ @SuppressWarnings("ConstantNamingConvention") public final class Sets { public static final ImmutableSetFactory immutable = new ImmutableSetFactoryImpl(); public static final FixedSizeSetFactory fixedSize = new FixedSizeSetFactoryImpl(); public static final MutableSetFactory mutable = new MutableSetFactoryImpl(); private static final Predicate> INSTANCE_OF_SORTED_SET_PREDICATE = new Predicate>() { public boolean accept(Set set) { return set instanceof SortedSet; } }; private static final Predicate> HAS_NON_NULL_COMPARATOR = new Predicate>() { public boolean accept(Set set) { return ((SortedSet) set).comparator() != null; } }; private Sets() { throw new AssertionError("Suppress default constructor for noninstantiability"); } public static MutableSet union( Set setA, Set setB) { return unionInto(newSet(setA, setB), setA, setB); } public static > R unionInto( R targetSet, Set setA, Set setB) { return setA.size() > setB.size() ? fillSet(targetSet, Sets.addAllProcedure(), setA, setB) : fillSet(targetSet, Sets.addAllProcedure(), setB, setA); } public static MutableSet unionAll(Set... sets) { return unionAllInto(newSet(sets), sets); } public static > R unionAllInto( R targetSet, Set... sets) { ArrayIterate.sort(sets, sets.length, Comparators.descendingCollectionSizeComparator()); return fillSet(targetSet, Sets.addAllProcedure(), sets); } public static MutableSet intersect( Set setA, Set setB) { return intersectInto(newSet(setA, setB), setA, setB); } public static > R intersectInto( R targetSet, Set setA, Set setB) { return setA.size() < setB.size() ? fillSet(targetSet, Sets.retainAllProcedure(), setA, setB) : fillSet(targetSet, Sets.retainAllProcedure(), setB, setA); } public static MutableSet intersectAll(Set... sets) { return intersectAllInto(newSet(sets), sets); } public static > R intersectAllInto( R targetSet, Set... sets) { ArrayIterate.sort(sets, sets.length, Comparators.ascendingCollectionSizeComparator()); return fillSet(targetSet, Sets.retainAllProcedure(), sets); } public static MutableSet difference( Set minuendSet, Set subtrahendSet) { return differenceInto(newSet(minuendSet, subtrahendSet), minuendSet, subtrahendSet); } public static > R differenceInto( R targetSet, Set minuendSet, Set subtrahendSet) { return fillSet(targetSet, Sets.removeAllProcedure(), minuendSet, subtrahendSet); } public static MutableSet differenceAll(Set... sets) { return differenceAllInto(newSet(sets), sets); } public static > R differenceAllInto( R targetSet, Set... sets) { return fillSet(targetSet, Sets.removeAllProcedure(), sets); } public static MutableSet symmetricDifference( Set setA, Set setB) { return symmetricDifferenceInto(newSet(setA, setB), setA, setB); } public static > R symmetricDifferenceInto( R targetSet, Set setA, Set setB) { return unionInto( targetSet, differenceInto(newSet(setA, setB), setA, setB), differenceInto(newSet(setA, setB), setB, setA)); } public static boolean isSubsetOf( Set candidateSubset, Set candidateSuperset) { return candidateSubset.size() <= candidateSuperset.size() && candidateSuperset.containsAll(candidateSubset); } public static boolean isProperSubsetOf( Set candidateSubset, Set candidateSuperset) { return candidateSubset.size() < candidateSuperset.size() && candidateSuperset.containsAll(candidateSubset); } private static MutableSet newSet(Set... sets) { Comparator comparator = extractComparator(sets); if (comparator != null) { // TODO: this should return a SortedSetAdapter once implemented return SetAdapter.adapt(new TreeSet(comparator)); } return UnifiedSet.newSet(); } private static Comparator extractComparator(Set... sets) { Collection> sortedSetCollection = ArrayIterate.select(sets, INSTANCE_OF_SORTED_SET_PREDICATE); if (sortedSetCollection.isEmpty()) { return null; } SortedSet sortedSetWithComparator = (SortedSet) Iterate.detect(sortedSetCollection, HAS_NON_NULL_COMPARATOR); if (sortedSetWithComparator != null) { return sortedSetWithComparator.comparator(); } return Comparators.safeNullsLow(Comparators.naturalOrder()); } private static > R fillSet( R targetSet, Procedure2, R> procedure, Set... sets) { targetSet.addAll(sets[0]); for (int i = 1; i < sets.length; i++) { procedure.value(sets[i], targetSet); } return targetSet; } private static > Procedure2, R> addAllProcedure() { return new Procedure2, R>() { public void value(Set argumentSet, R targetSet) { targetSet.addAll(argumentSet); } }; } private static > Procedure2, R> retainAllProcedure() { return new Procedure2, R>() { public void value(Set argumentSet, R targetSet) { targetSet.retainAll(argumentSet); } }; } private static > Procedure2, R> removeAllProcedure() { return new Procedure2, R>() { public void value(Set argumentSet, R targetSet) { targetSet.removeAll(argumentSet); } }; } public static MutableSet> powerSet(Set set) { MutableSet> seed = UnifiedSet.>newSetWith(UnifiedSet.newSet()); return Iterate.injectInto(seed, set, new Function2>, T, MutableSet>>() { public MutableSet> value(MutableSet> accumulator, final T element) { return Sets.union(accumulator, accumulator.collect(new Function, MutableSet>() { public MutableSet valueOf(MutableSet innerSet) { return innerSet.toSet().with(element); } })); } }); } public static LazyIterable> cartesianProduct(Set set1, final Set set2) { return LazyIterate.flatCollect(set1, new Function>>() { public LazyIterable> valueOf(final A first) { return LazyIterate.collect(set2, new Function>() { public Pair valueOf(B second) { return Tuples.pair(first, second); } }); } }); } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/factory/SortedMaps.java000066400000000000000000000025111234315411400324520ustar00rootroot00000000000000/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.factory; import com.gs.collections.api.factory.map.sorted.ImmutableSortedMapFactory; import com.gs.collections.api.factory.map.sorted.MutableSortedMapFactory; import com.gs.collections.impl.map.sorted.immutable.ImmutableSortedMapFactoryImpl; import com.gs.collections.impl.map.sorted.mutable.MutableSortedMapFactoryImpl; @SuppressWarnings("ConstantNamingConvention") public final class SortedMaps { public static final ImmutableSortedMapFactory immutable = new ImmutableSortedMapFactoryImpl(); public static final MutableSortedMapFactory mutable = new MutableSortedMapFactoryImpl(); private SortedMaps() { throw new AssertionError("Suppress default constructor for noninstantiability"); } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/factory/SortedSets.java000066400000000000000000000025111234315411400324700ustar00rootroot00000000000000/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.factory; import com.gs.collections.api.factory.set.sorted.ImmutableSortedSetFactory; import com.gs.collections.api.factory.set.sorted.MutableSortedSetFactory; import com.gs.collections.impl.set.sorted.immutable.ImmutableSortedSetFactoryImpl; import com.gs.collections.impl.set.sorted.mutable.MutableSortedSetFactoryImpl; @SuppressWarnings("ConstantNamingConvention") public final class SortedSets { public static final ImmutableSortedSetFactory immutable = new ImmutableSortedSetFactoryImpl(); public static final MutableSortedSetFactory mutable = new MutableSortedSetFactoryImpl(); private SortedSets() { throw new AssertionError("Suppress default constructor for noninstantiability"); } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/factory/Stacks.java000066400000000000000000000024151234315411400316240ustar00rootroot00000000000000/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.factory; import com.gs.collections.api.factory.stack.ImmutableStackFactory; import com.gs.collections.api.factory.stack.MutableStackFactory; import com.gs.collections.impl.stack.immutable.ImmutableStackFactoryImpl; import com.gs.collections.impl.stack.mutable.MutableStackFactoryImpl; @SuppressWarnings("ConstantNamingConvention") public final class Stacks { public static final ImmutableStackFactory immutable = new ImmutableStackFactoryImpl(); public static final MutableStackFactory mutable = new MutableStackFactoryImpl(); private Stacks() { throw new AssertionError("Suppress default constructor for noninstantiability"); } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/factory/package-info.java000066400000000000000000000013531234315411400327200ustar00rootroot00000000000000/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains static utilities for creating mutable and immutable collection factories. */ package com.gs.collections.impl.factory; gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/factory/primitive/000077500000000000000000000000001234315411400315375ustar00rootroot00000000000000BooleanSets.java000066400000000000000000000024041234315411400345410ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/factory/primitive/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.factory.primitive; import com.gs.collections.api.factory.set.primitive.ImmutableBooleanSetFactory; import com.gs.collections.impl.set.immutable.primitive.ImmutableBooleanSetFactoryImpl; /** * BooleanSets is a static utility for creating {@link com.gs.collections.api.factory.set.primitive.ImmutableBooleanSetFactory}. * * @since 4.0. */ @SuppressWarnings("ConstantNamingConvention") public final class BooleanSets { public static final ImmutableBooleanSetFactory immutable = new ImmutableBooleanSetFactoryImpl(); private BooleanSets() { throw new AssertionError("Suppress default constructor for noninstantiability"); } } package-info.java000066400000000000000000000013631234315411400346520ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/factory/primitive/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains static utilities for creating immutable primitive collection factories. */ package com.gs.collections.impl.factory.primitive; gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/000077500000000000000000000000001234315411400270375ustar00rootroot00000000000000AbstractLazyIterable.java000066400000000000000000000614351234315411400337070ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy; import java.lang.reflect.Array; import java.util.Collection; import java.util.Comparator; import com.gs.collections.api.LazyBooleanIterable; import com.gs.collections.api.LazyByteIterable; import com.gs.collections.api.LazyCharIterable; import com.gs.collections.api.LazyDoubleIterable; import com.gs.collections.api.LazyFloatIterable; import com.gs.collections.api.LazyIntIterable; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.LazyLongIterable; import com.gs.collections.api.LazyShortIterable; import com.gs.collections.api.RichIterable; import com.gs.collections.api.bag.MutableBag; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.DoubleObjectToDoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.FloatObjectToFloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.IntObjectToIntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.LongObjectToLongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.collection.primitive.MutableBooleanCollection; import com.gs.collections.api.collection.primitive.MutableByteCollection; import com.gs.collections.api.collection.primitive.MutableCharCollection; import com.gs.collections.api.collection.primitive.MutableDoubleCollection; import com.gs.collections.api.collection.primitive.MutableFloatCollection; import com.gs.collections.api.collection.primitive.MutableIntCollection; import com.gs.collections.api.collection.primitive.MutableLongCollection; import com.gs.collections.api.collection.primitive.MutableShortCollection; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.map.MapIterable; import com.gs.collections.api.map.MutableMap; import com.gs.collections.api.map.sorted.MutableSortedMap; import com.gs.collections.api.multimap.ImmutableMultimap; import com.gs.collections.api.multimap.MutableMultimap; import com.gs.collections.api.partition.list.PartitionMutableList; import com.gs.collections.api.set.MutableSet; import com.gs.collections.api.set.sorted.MutableSortedSet; import com.gs.collections.api.stack.MutableStack; import com.gs.collections.api.tuple.Pair; import com.gs.collections.impl.block.factory.Comparators; import com.gs.collections.impl.block.factory.Functions; import com.gs.collections.impl.block.factory.Predicates; import com.gs.collections.impl.block.factory.Procedures2; import com.gs.collections.impl.block.procedure.CountProcedure; import com.gs.collections.impl.block.procedure.MapCollectProcedure; import com.gs.collections.impl.block.procedure.MutatingAggregationProcedure; import com.gs.collections.impl.block.procedure.NonMutatingAggregationProcedure; import com.gs.collections.impl.factory.Bags; import com.gs.collections.impl.factory.Lists; import com.gs.collections.impl.lazy.primitive.CollectBooleanIterable; import com.gs.collections.impl.lazy.primitive.CollectByteIterable; import com.gs.collections.impl.lazy.primitive.CollectCharIterable; import com.gs.collections.impl.lazy.primitive.CollectDoubleIterable; import com.gs.collections.impl.lazy.primitive.CollectFloatIterable; import com.gs.collections.impl.lazy.primitive.CollectIntIterable; import com.gs.collections.impl.lazy.primitive.CollectLongIterable; import com.gs.collections.impl.lazy.primitive.CollectShortIterable; import com.gs.collections.impl.map.mutable.UnifiedMap; import com.gs.collections.impl.map.sorted.mutable.TreeSortedMap; import com.gs.collections.impl.multimap.list.FastListMultimap; import com.gs.collections.impl.set.mutable.UnifiedSet; import com.gs.collections.impl.set.sorted.mutable.TreeSortedSet; import com.gs.collections.impl.stack.mutable.ArrayStack; import com.gs.collections.impl.utility.ArrayIterate; import com.gs.collections.impl.utility.Iterate; import com.gs.collections.impl.utility.LazyIterate; import com.gs.collections.impl.utility.internal.IterableIterate; import net.jcip.annotations.Immutable; /** * AbstractLazyIterable provides a base from which deferred iterables such as SelectIterable, * RejectIterable and CollectIterable can be derived. */ @Immutable public abstract class AbstractLazyIterable implements LazyIterable { public LazyIterable asLazy() { return this; } public > R into(R target) { this.forEachWith(Procedures2.addToCollection(), target); return target; } @Override public String toString() { return this.makeString("[", ", ", "]"); } public Object[] toArray() { return this.toList().toArray(); } public E[] toArray(E[] array) { int size = this.size(); final E[] result = array.length < size ? (E[]) Array.newInstance(array.getClass().getComponentType(), size) : array; this.forEachWithIndex(new ObjectIntProcedure() { public void value(Object each, int index) { result[index] = (E) each; } }); if (result.length > size) { result[size] = null; } return result; } public boolean contains(Object object) { return this.anySatisfy(Predicates.equal(object)); } public boolean containsAllIterable(Iterable source) { return Iterate.allSatisfy(source, new Predicate() { public boolean accept(Object each) { return AbstractLazyIterable.this.contains(each); } }); } public boolean containsAll(Collection source) { return this.containsAllIterable(source); } public boolean containsAllArguments(Object... elements) { return ArrayIterate.allSatisfy(elements, new Predicate() { public boolean accept(Object each) { return AbstractLazyIterable.this.contains(each); } }); } public int size() { return this.count(Predicates.alwaysTrue()); } public boolean isEmpty() { return IterableIterate.isEmpty(this); } public boolean notEmpty() { return IterableIterate.notEmpty(this); } public T getFirst() { return IterableIterate.getFirst(this); } public T getLast() { return IterableIterate.getLast(this); } public LazyIterable select(Predicate predicate) { return LazyIterate.select(this, predicate); } public

LazyIterable selectWith(Predicate2 predicate, P parameter) { return LazyIterate.select(this, Predicates.bind(predicate, parameter)); } public > R select(Predicate predicate, R target) { return IterableIterate.select(this, predicate, target); } public > R selectWith(Predicate2 predicate, P parameter, R targetCollection) { return IterableIterate.selectWith(this, predicate, parameter, targetCollection); } public LazyIterable reject(Predicate predicate) { return LazyIterate.reject(this, predicate); } public

LazyIterable rejectWith(Predicate2 predicate, P parameter) { return LazyIterate.reject(this, Predicates.bind(predicate, parameter)); } public > R reject(Predicate predicate, R target) { return IterableIterate.reject(this, predicate, target); } public > R rejectWith(Predicate2 predicate, P parameter, R targetCollection) { return IterableIterate.rejectWith(this, predicate, parameter, targetCollection); } public PartitionMutableList partition(Predicate predicate) { return IterableIterate.partition(this, predicate); } public

PartitionMutableList partitionWith(Predicate2 predicate, P parameter) { return IterableIterate.partitionWith(this, predicate, parameter); } public LazyIterable selectInstancesOf(Class clazz) { return LazyIterate.selectInstancesOf(this, clazz); } public LazyIterable collect(Function function) { return LazyIterate.collect(this, function); } public LazyBooleanIterable collectBoolean(BooleanFunction booleanFunction) { return new CollectBooleanIterable(this, booleanFunction); } public R collectBoolean(BooleanFunction booleanFunction, R target) { return IterableIterate.collectBoolean(this, booleanFunction, target); } public LazyByteIterable collectByte(ByteFunction byteFunction) { return new CollectByteIterable(this, byteFunction); } public R collectByte(ByteFunction byteFunction, R target) { return IterableIterate.collectByte(this, byteFunction, target); } public LazyCharIterable collectChar(CharFunction charFunction) { return new CollectCharIterable(this, charFunction); } public R collectChar(CharFunction charFunction, R target) { return IterableIterate.collectChar(this, charFunction, target); } public LazyDoubleIterable collectDouble(DoubleFunction doubleFunction) { return new CollectDoubleIterable(this, doubleFunction); } public R collectDouble(DoubleFunction doubleFunction, R target) { return IterableIterate.collectDouble(this, doubleFunction, target); } public LazyFloatIterable collectFloat(FloatFunction floatFunction) { return new CollectFloatIterable(this, floatFunction); } public R collectFloat(FloatFunction floatFunction, R target) { return IterableIterate.collectFloat(this, floatFunction, target); } public LazyIntIterable collectInt(IntFunction intFunction) { return new CollectIntIterable(this, intFunction); } public R collectInt(IntFunction intFunction, R target) { return IterableIterate.collectInt(this, intFunction, target); } public LazyLongIterable collectLong(LongFunction longFunction) { return new CollectLongIterable(this, longFunction); } public R collectLong(LongFunction longFunction, R target) { return IterableIterate.collectLong(this, longFunction, target); } public LazyShortIterable collectShort(ShortFunction shortFunction) { return new CollectShortIterable(this, shortFunction); } public R collectShort(ShortFunction shortFunction, R target) { return IterableIterate.collectShort(this, shortFunction, target); } public > R collect(Function function, R target) { return IterableIterate.collect(this, function, target); } public LazyIterable collectWith(Function2 function, P parameter) { return LazyIterate.collect(this, Functions.bind(function, parameter)); } public > R collectWith(Function2 function, P parameter, R targetCollection) { return IterableIterate.collectWith(this, function, parameter, targetCollection); } public LazyIterable flatCollect(Function> function) { return LazyIterate.flatCollect(this, function); } public LazyIterable concatenate(Iterable iterable) { return LazyIterate.concatenate(this, iterable); } public > R flatCollect(Function> function, R target) { return IterableIterate.flatCollect(this, function, target); } public LazyIterable collectIf(Predicate predicate, Function function) { return LazyIterate.collectIf(this, predicate, function); } public > R collectIf(Predicate predicate, Function function, R target) { return IterableIterate.collectIf(this, predicate, function, target); } public LazyIterable take(int count) { return LazyIterate.take(this, count); } public LazyIterable drop(int count) { return LazyIterate.drop(this, count); } public LazyIterable distinct() { return LazyIterate.distinct(this); } public T detect(Predicate predicate) { return IterableIterate.detect(this, predicate); } public

T detectWith(Predicate2 predicate, P parameter) { return IterableIterate.detectWith(this, predicate, parameter); } public T min(Comparator comparator) { return Iterate.min(this, comparator); } public T max(Comparator comparator) { return Iterate.max(this, comparator); } public T min() { return Iterate.min(this); } public T max() { return Iterate.max(this); } public > T minBy(Function function) { return IterableIterate.minBy(this, function); } public > T maxBy(Function function) { return IterableIterate.maxBy(this, function); } public T detectIfNone(Predicate predicate, Function0 function) { T result = this.detect(predicate); return result == null ? function.value() : result; } public

T detectWithIfNone(Predicate2 predicate, P parameter, Function0 function) { T result = this.detectWith(predicate, parameter); return result == null ? function.value() : result; } public int count(Predicate predicate) { CountProcedure procedure = new CountProcedure(predicate); this.forEach(procedure); return procedure.getCount(); } public

int countWith(Predicate2 predicate, P parameter) { return IterableIterate.countWith(this, predicate, parameter); } public boolean anySatisfy(Predicate predicate) { return IterableIterate.anySatisfy(this, predicate); } public boolean allSatisfy(Predicate predicate) { return IterableIterate.allSatisfy(this, predicate); } public boolean noneSatisfy(Predicate predicate) { return IterableIterate.noneSatisfy(this, predicate); } public

boolean anySatisfyWith(Predicate2 predicate, P parameter) { return IterableIterate.anySatisfyWith(this, predicate, parameter); } public

boolean allSatisfyWith(Predicate2 predicate, P parameter) { return IterableIterate.allSatisfyWith(this, predicate, parameter); } public

boolean noneSatisfyWith(Predicate2 predicate, P parameter) { return IterableIterate.noneSatisfyWith(this, predicate, parameter); } public IV injectInto(IV injectedValue, Function2 function) { return IterableIterate.injectInto(injectedValue, this, function); } public int injectInto(int injectedValue, IntObjectToIntFunction function) { return IterableIterate.injectInto(injectedValue, this, function); } public long injectInto(long injectedValue, LongObjectToLongFunction function) { return IterableIterate.injectInto(injectedValue, this, function); } public double injectInto(double injectedValue, DoubleObjectToDoubleFunction function) { return IterableIterate.injectInto(injectedValue, this, function); } public float injectInto(float injectedValue, FloatObjectToFloatFunction function) { return IterableIterate.injectInto(injectedValue, this, function); } public long sumOfInt(IntFunction function) { return IterableIterate.sumOfInt(this, function); } public double sumOfFloat(FloatFunction function) { return IterableIterate.sumOfFloat(this, function); } public long sumOfLong(LongFunction function) { return IterableIterate.sumOfLong(this, function); } public double sumOfDouble(DoubleFunction function) { return IterableIterate.sumOfDouble(this, function); } public MutableList toList() { MutableList list = Lists.mutable.of(); this.forEachWith(Procedures2.addToCollection(), list); return list; } public MutableList toSortedList() { return this.toList().sortThis(); } public MutableList toSortedList(Comparator comparator) { return this.toList().sortThis(comparator); } public > MutableList toSortedListBy(Function function) { return this.toSortedList(Comparators.byFunction(function)); } public MutableSortedSet toSortedSet() { MutableSortedSet treeSet = TreeSortedSet.newSet(); this.forEachWith(Procedures2.addToCollection(), treeSet); return treeSet; } public MutableSortedSet toSortedSet(Comparator comparator) { MutableSortedSet treeSet = TreeSortedSet.newSet(comparator); this.forEachWith(Procedures2.addToCollection(), treeSet); return treeSet; } public > MutableSortedSet toSortedSetBy(Function function) { return this.toSortedSet(Comparators.byFunction(function)); } public MutableSet toSet() { MutableSet set = UnifiedSet.newSet(); this.forEachWith(Procedures2.addToCollection(), set); return set; } public MutableBag toBag() { MutableBag bag = Bags.mutable.of(); this.forEachWith(Procedures2.addToCollection(), bag); return bag; } public MutableStack toStack() { return ArrayStack.newStack(this); } public MutableMap toMap( Function keyFunction, Function valueFunction) { UnifiedMap map = UnifiedMap.newMap(); this.forEach(new MapCollectProcedure(map, keyFunction, valueFunction)); return map; } public MutableSortedMap toSortedMap( Function keyFunction, Function valueFunction) { TreeSortedMap sortedMap = TreeSortedMap.newMap(); this.forEach(new MapCollectProcedure(sortedMap, keyFunction, valueFunction)); return sortedMap; } public MutableSortedMap toSortedMap(Comparator comparator, Function keyFunction, Function valueFunction) { TreeSortedMap sortedMap = TreeSortedMap.newMap(comparator); this.forEach(new MapCollectProcedure(sortedMap, keyFunction, valueFunction)); return sortedMap; } public String makeString() { return this.makeString(", "); } public String makeString(String separator) { return this.makeString("", separator, ""); } public String makeString(String start, String separator, String end) { Appendable stringBuilder = new StringBuilder(); this.appendString(stringBuilder, start, separator, end); return stringBuilder.toString(); } public void appendString(Appendable appendable) { this.appendString(appendable, ", "); } public void appendString(Appendable appendable, String separator) { this.appendString(appendable, "", separator, ""); } public void appendString(Appendable appendable, String start, String separator, String end) { IterableIterate.appendString(this, appendable, start, separator, end); } public ImmutableMultimap groupBy(Function function) { return IterableIterate.groupBy(this, function, FastListMultimap.newMultimap()).toImmutable(); } public > R groupBy( Function function, R target) { return IterableIterate.groupBy(this, function, target); } public ImmutableMultimap groupByEach(Function> function) { return IterableIterate.groupByEach(this, function, FastListMultimap.newMultimap()).toImmutable(); } public > R groupByEach( Function> function, R target) { return IterableIterate.groupByEach(this, function, target); } public MapIterable groupByUniqueKey(Function function) { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".groupByUniqueKey() not implemented yet"); } public LazyIterable> zip(Iterable that) { return LazyIterate.zip(this, that); } public >> R zip(Iterable that, R target) { return IterableIterate.zip(this, that, target); } public LazyIterable> zipWithIndex() { return LazyIterate.zipWithIndex(this); } public >> R zipWithIndex(R target) { return IterableIterate.zipWithIndex(this, target); } public LazyIterable> chunk(int size) { return LazyIterate.chunk(this, size); } public MapIterable aggregateInPlaceBy( Function groupBy, Function0 zeroValueFactory, Procedure2 mutatingAggregator) { MutableMap map = UnifiedMap.newMap(); this.forEach(new MutatingAggregationProcedure(map, groupBy, zeroValueFactory, mutatingAggregator)); return map; } public MapIterable aggregateBy( Function groupBy, Function0 zeroValueFactory, Function2 nonMutatingAggregator) { MutableMap map = UnifiedMap.newMap(); this.forEach(new NonMutatingAggregationProcedure(map, groupBy, zeroValueFactory, nonMutatingAggregator)); return map; } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/ChunkIterable.java000066400000000000000000000042771234315411400324340ustar00rootroot00000000000000/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy; import java.util.Iterator; import com.gs.collections.api.RichIterable; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.impl.lazy.iterator.ChunkIterator; import com.gs.collections.impl.utility.internal.IterableIterate; import net.jcip.annotations.Immutable; /** * A ChunkIterable is an iterable that partitions a source iterable into fixed size chunks as it iterates. */ @Immutable public class ChunkIterable extends AbstractLazyIterable> { private final Iterable iterable; private final int size; public ChunkIterable(Iterable iterable, int size) { if (size <= 0) { throw new IllegalArgumentException("Size for groups must be positive but was: " + size); } this.iterable = iterable; this.size = size; } public Iterator> iterator() { return new ChunkIterator(this.iterable, this.size); } public void forEach(Procedure> procedure) { IterableIterate.forEach(this, procedure); } public void forEachWithIndex(ObjectIntProcedure> objectIntProcedure) { IterableIterate.forEachWithIndex(this, objectIntProcedure); } public

void forEachWith(Procedure2, ? super P> procedure, P parameter) { IterableIterate.forEachWith(this, procedure, parameter); } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/CollectIterable.java000066400000000000000000000053631234315411400327460ustar00rootroot00000000000000/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy; import java.util.Iterator; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.impl.block.factory.Functions; import com.gs.collections.impl.lazy.iterator.CollectIterator; import com.gs.collections.impl.utility.Iterate; import net.jcip.annotations.Immutable; /** * A CollectIterable is an iterable that transforms a source iterable using a function as it iterates. */ @Immutable public class CollectIterable extends AbstractLazyIterable { private final Iterable adapted; private final Function function; public CollectIterable(Iterable newAdapted, Function function) { this.adapted = newAdapted; this.function = function; } public void forEach(Procedure procedure) { Iterate.forEach(this.adapted, Functions.bind(procedure, this.function)); } public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { Iterate.forEachWithIndex(this.adapted, Functions.bind(objectIntProcedure, this.function)); } public

void forEachWith(Procedure2 procedure, P parameter) { Iterate.forEachWith(this.adapted, Functions.bind(procedure, this.function), parameter); } public Iterator iterator() { return new CollectIterator(this.adapted, this.function); } @Override public int size() { return Iterate.sizeOf(this.adapted); } @Override public boolean isEmpty() { return Iterate.isEmpty(this.adapted); } @Override public boolean notEmpty() { return !this.isEmpty(); } @Override public Object[] toArray() { Object[] array = Iterate.toArray(this.adapted); for (int i = 0; i < array.length; i++) { array[i] = this.function.valueOf((T) array[i]); } return array; } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/CompositeIterable.java000066400000000000000000000103611234315411400333150ustar00rootroot00000000000000/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy; import java.util.Iterator; import java.util.NoSuchElementException; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.list.MutableList; import com.gs.collections.impl.Counter; import com.gs.collections.impl.EmptyIterator; import com.gs.collections.impl.list.mutable.FastList; import com.gs.collections.impl.utility.Iterate; import net.jcip.annotations.Immutable; @Immutable public final class CompositeIterable extends AbstractLazyIterable { private final MutableList> iterables; private CompositeIterable(MutableList> newIterables) { this.iterables = newIterables; } public CompositeIterable() { this(FastList.>newList()); } public static CompositeIterable with(Iterable... iterables) { return new CompositeIterable(FastList.newListWith(iterables)); } public void forEach(final Procedure procedure) { this.iterables.forEach(new Procedure>() { public void value(Iterable iterable) { Iterate.forEach(iterable, procedure); } }); } public void forEachWithIndex(final ObjectIntProcedure objectIntProcedure) { final Counter index = new Counter(); this.iterables.forEach(new Procedure>() { public void value(Iterable iterable) { Iterate.forEach(iterable, new Procedure() { public void value(E object) { objectIntProcedure.value(object, index.getCount()); index.increment(); } }); } }); } public

void forEachWith(final Procedure2 procedure, final P parameter) { this.iterables.forEach(new Procedure>() { public void value(Iterable iterable) { Iterate.forEachWith(iterable, procedure, parameter); } }); } public void add(Iterable iterable) { this.iterables.add(iterable); } public Iterator iterator() { return new CompositeIterator(this.iterables); } private final class CompositeIterator implements Iterator { private final Iterator> iterablesIterator; private Iterator innerIterator; private CompositeIterator(MutableList> iterables) { this.iterablesIterator = iterables.listIterator(); this.innerIterator = EmptyIterator.getInstance(); } public boolean hasNext() { while (true) { if (this.innerIterator.hasNext()) { return true; } if (!this.iterablesIterator.hasNext()) { return false; } this.innerIterator = this.iterablesIterator.next().iterator(); } } public E next() { if (!this.hasNext()) { throw new NoSuchElementException(); } return this.innerIterator.next(); } public void remove() { throw new UnsupportedOperationException("Cannot remove from a composite iterator"); } } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/DistinctIterable.java000066400000000000000000000040151234315411400331330ustar00rootroot00000000000000/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy; import java.util.Iterator; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.impl.lazy.iterator.DistinctIterator; import com.gs.collections.impl.utility.internal.IterableIterate; import net.jcip.annotations.Immutable; /** * A DistinctIterable is an iterable that eliminates duplicates from a source iterable as it iterates. * * @since 5.0 */ @Immutable public class DistinctIterable extends AbstractLazyIterable { private final Iterable adapted; public DistinctIterable(Iterable newAdapted) { this.adapted = newAdapted; } @Override public LazyIterable distinct() { return this; } public void forEach(Procedure procedure) { IterableIterate.forEach(this, procedure); } public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { IterableIterate.forEachWithIndex(this, objectIntProcedure); } public

void forEachWith(Procedure2 procedure, P parameter) { IterableIterate.forEachWith(this, procedure, parameter); } public Iterator iterator() { return new DistinctIterator(this.adapted); } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/DropIterable.java000066400000000000000000000050511234315411400322570ustar00rootroot00000000000000/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy; import java.util.Iterator; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.impl.block.predicate.DropIterablePredicate; import com.gs.collections.impl.block.procedure.IfObjectIntProcedure; import com.gs.collections.impl.block.procedure.IfProcedure; import com.gs.collections.impl.block.procedure.IfProcedureWith; import com.gs.collections.impl.lazy.iterator.DropIterator; import com.gs.collections.impl.utility.Iterate; import net.jcip.annotations.Immutable; /** * Iterates over the elements of the adapted Iterable skipping the first count elements or the full adapted Iterable if * the count is non-positive. */ @Immutable public class DropIterable extends AbstractLazyIterable { private final Iterable adapted; private final int count; public DropIterable(Iterable newAdapted, int count) { if (count < 0) { throw new IllegalArgumentException("Count must be greater than zero, but was: " + count); } this.adapted = newAdapted; this.count = count; } public void forEach(Procedure procedure) { Iterate.forEach(this.adapted, new IfProcedure(new DropIterablePredicate(this.count), procedure)); } public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { Iterate.forEach(this.adapted, new IfObjectIntProcedure(new DropIterablePredicate(this.count), objectIntProcedure)); } public

void forEachWith(Procedure2 procedure, P parameter) { Iterate.forEachWith(this.adapted, new IfProcedureWith(new DropIterablePredicate(this.count), procedure), parameter); } public Iterator iterator() { return new DropIterator(this.adapted, this.count); } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/FlatCollectIterable.java000066400000000000000000000065751234315411400335630ustar00rootroot00000000000000/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy; import java.util.Iterator; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.impl.Counter; import com.gs.collections.impl.lazy.iterator.FlatCollectIterator; import com.gs.collections.impl.utility.Iterate; import net.jcip.annotations.Immutable; @Immutable public class FlatCollectIterable extends AbstractLazyIterable { private final Iterable adapted; private final Function> function; public FlatCollectIterable(Iterable newAdapted, Function> function) { this.adapted = newAdapted; this.function = function; } public void forEach(final Procedure procedure) { Iterate.forEach(this.adapted, new Procedure() { public void value(T each) { Iterate.forEach(FlatCollectIterable.this.function.valueOf(each), procedure); } }); } public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { final Procedure innerProcedure = new AdaptObjectIntProcedureToProcedure(objectIntProcedure); Iterate.forEach(this.adapted, new Procedure() { public void value(T each) { Iterable iterable = FlatCollectIterable.this.function.valueOf(each); Iterate.forEach(iterable, innerProcedure); } }); } public

void forEachWith(final Procedure2 procedure, final P parameter) { Iterate.forEach(this.adapted, new Procedure() { public void value(T each) { Iterate.forEachWith(FlatCollectIterable.this.function.valueOf(each), procedure, parameter); } }); } public Iterator iterator() { return new FlatCollectIterator(this.adapted, this.function); } private static final class AdaptObjectIntProcedureToProcedure implements Procedure { private static final long serialVersionUID = 1L; private final Counter index; private final ObjectIntProcedure objectIntProcedure; private AdaptObjectIntProcedureToProcedure(ObjectIntProcedure objectIntProcedure) { this.objectIntProcedure = objectIntProcedure; this.index = new Counter(); } public void value(V each) { this.objectIntProcedure.value(each, this.index.getCount()); this.index.increment(); } } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/LazyIterableAdapter.java000066400000000000000000000072221234315411400335750ustar00rootroot00000000000000/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy; import java.util.Collection; import java.util.Iterator; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.impl.UnmodifiableIteratorAdapter; import com.gs.collections.impl.utility.Iterate; import com.gs.collections.impl.utility.LazyIterate; import net.jcip.annotations.Immutable; /** * A LazyIterableAdapter wraps any iterable with the LazyIterable interface. */ @Immutable public class LazyIterableAdapter extends AbstractLazyIterable { private final Iterable adapted; public LazyIterableAdapter(Iterable newAdapted) { this.adapted = newAdapted; } public void forEach(Procedure procedure) { Iterate.forEach(this.adapted, procedure); } public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { Iterate.forEachWithIndex(this.adapted, objectIntProcedure); } public

void forEachWith(Procedure2 procedure, P parameter) { Iterate.forEachWith(this.adapted, procedure, parameter); } public Iterator iterator() { return new UnmodifiableIteratorAdapter(this.adapted.iterator()); } @Override public > R into(R target) { Iterate.addAllIterable(this.adapted, target); return target; } @Override public LazyIterable select(Predicate predicate) { return LazyIterate.select(this.adapted, predicate); } @Override public LazyIterable reject(Predicate predicate) { return LazyIterate.reject(this.adapted, predicate); } @Override public LazyIterable collect(Function function) { return LazyIterate.collect(this.adapted, function); } @Override public LazyIterable flatCollect(Function> function) { return LazyIterate.flatCollect(this.adapted, function); } @Override public LazyIterable collectIf(Predicate predicate, Function function) { return LazyIterate.collectIf(this.adapted, predicate, function); } @Override public LazyIterable take(int count) { return LazyIterate.take(this.adapted, count); } @Override public LazyIterable drop(int count) { return LazyIterate.drop(this.adapted, count); } @Override public LazyIterable distinct() { return LazyIterate.distinct(this.adapted); } @Override public Object[] toArray() { return Iterate.toArray(this.adapted); } @Override public int size() { return Iterate.sizeOf(this.adapted); } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/RejectIterable.java000066400000000000000000000050021234315411400325630ustar00rootroot00000000000000/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy; import java.util.Iterator; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.impl.block.factory.Predicates; import com.gs.collections.impl.block.procedure.IfObjectIntProcedure; import com.gs.collections.impl.block.procedure.IfProcedure; import com.gs.collections.impl.block.procedure.IfProcedureWith; import com.gs.collections.impl.lazy.iterator.SelectIterator; import com.gs.collections.impl.utility.Iterate; import net.jcip.annotations.Immutable; /** * A RejectIterable is an iterable that filters a source iterable on a negative condition as it iterates. */ @Immutable public class RejectIterable extends AbstractLazyIterable { private final Iterable adapted; private final Predicate predicate; public RejectIterable(Iterable newAdapted, Predicate newPredicate) { this.adapted = newAdapted; this.predicate = Predicates.not(newPredicate); } public void forEach(Procedure procedure) { Iterate.forEach(this.adapted, new IfProcedure(this.predicate, procedure)); } public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { Iterate.forEach(this.adapted, new IfObjectIntProcedure(this.predicate, objectIntProcedure)); } public

void forEachWith(Procedure2 procedure, P parameter) { Iterate.forEachWith(this.adapted, new IfProcedureWith(this.predicate, procedure), parameter); } /** * We use a SelectIterator, since we have already negated the predicate */ public Iterator iterator() { return new SelectIterator(this.adapted, this.predicate); } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/ReverseIterable.java000066400000000000000000000055241234315411400327730ustar00rootroot00000000000000/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy; import java.util.Iterator; import java.util.ListIterator; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.list.ListIterable; import com.gs.collections.impl.block.factory.Procedures; import net.jcip.annotations.Immutable; /** * A ReverseIterable is an iterable that wraps another iterable and iterates in reverse order. */ @Immutable public class ReverseIterable extends AbstractLazyIterable { private final ListIterable adapted; public ReverseIterable(ListIterable newAdapted) { this.adapted = newAdapted; } public static ReverseIterable adapt(ListIterable listIterable) { return new ReverseIterable(listIterable); } public void forEach(Procedure procedure) { this.adapted.reverseForEach(procedure); } public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { this.adapted.reverseForEach(Procedures.fromObjectIntProcedure(objectIntProcedure)); } public

void forEachWith(Procedure2 procedure, P parameter) { this.adapted.reverseForEach(Procedures.bind(procedure, parameter)); } @Override public int size() { return this.adapted.size(); } public Iterator iterator() { ListIterator listIterator = this.adapted.listIterator(this.adapted.size()); return new ReverseIterator(listIterator); } private static final class ReverseIterator implements Iterator { private final ListIterator listIterator; private ReverseIterator(ListIterator listIterator) { this.listIterator = listIterator; } public boolean hasNext() { return this.listIterator.hasPrevious(); } public T next() { return this.listIterator.previous(); } public void remove() { throw new UnsupportedOperationException("Cannot call remove() on " + this.getClass().getSimpleName()); } } } SelectInstancesOfIterable.java000066400000000000000000000046731234315411400346610ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/* * Copyright 2012 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy; import java.util.Iterator; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.impl.block.factory.Predicates; import com.gs.collections.impl.block.procedure.IfObjectIntProcedure; import com.gs.collections.impl.block.procedure.IfProcedure; import com.gs.collections.impl.block.procedure.IfProcedureWith; import com.gs.collections.impl.lazy.iterator.SelectInstancesOfIterator; import com.gs.collections.impl.utility.Iterate; import net.jcip.annotations.Immutable; /** * A SelectIterable is an iterable that filters a source iterable for instances of a Class as it iterates. */ @Immutable public class SelectInstancesOfIterable extends AbstractLazyIterable { private final Iterable adapted; private final Class clazz; public SelectInstancesOfIterable(Iterable newAdapted, Class clazz) { this.adapted = newAdapted; this.clazz = clazz; } public void forEach(Procedure procedure) { Iterate.forEach((Iterable) this.adapted, new IfProcedure(Predicates.instanceOf(this.clazz), procedure)); } public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { Iterate.forEach((Iterable) this.adapted, new IfObjectIntProcedure(Predicates.instanceOf(this.clazz), objectIntProcedure)); } public

void forEachWith(Procedure2 procedure, P parameter) { Iterate.forEachWith((Iterable) this.adapted, new IfProcedureWith(Predicates.instanceOf(this.clazz), procedure), parameter); } public Iterator iterator() { return new SelectInstancesOfIterator(this.adapted, this.clazz); } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/SelectIterable.java000066400000000000000000000045371234315411400326020ustar00rootroot00000000000000/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy; import java.util.Iterator; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.impl.block.procedure.IfObjectIntProcedure; import com.gs.collections.impl.block.procedure.IfProcedure; import com.gs.collections.impl.block.procedure.IfProcedureWith; import com.gs.collections.impl.lazy.iterator.SelectIterator; import com.gs.collections.impl.utility.Iterate; import net.jcip.annotations.Immutable; /** * A SelectIterable is an iterable that filters a source iterable on a condition as it iterates. */ @Immutable public class SelectIterable extends AbstractLazyIterable { private final Iterable adapted; private final Predicate predicate; public SelectIterable(Iterable newAdapted, Predicate newPredicate) { this.adapted = newAdapted; this.predicate = newPredicate; } public void forEach(Procedure procedure) { Iterate.forEach(this.adapted, new IfProcedure(this.predicate, procedure)); } public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { Iterate.forEach(this.adapted, new IfObjectIntProcedure(this.predicate, objectIntProcedure)); } public

void forEachWith(Procedure2 procedure, P parameter) { Iterate.forEachWith(this.adapted, new IfProcedureWith(this.predicate, procedure), parameter); } public Iterator iterator() { return new SelectIterator(this.adapted.iterator(), this.predicate); } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/TakeIterable.java000066400000000000000000000056401234315411400322430ustar00rootroot00000000000000/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy; import java.util.Iterator; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.impl.lazy.iterator.TakeIterator; import net.jcip.annotations.Immutable; /** * Iterates over the first count elements of the adapted Iterable or the full size of the adapted * iterable if the count is greater than the length of the receiver. */ @Immutable public class TakeIterable extends AbstractLazyIterable { private final Iterable adapted; private final int count; public TakeIterable(Iterable newAdapted, int count) { if (count < 0) { throw new IllegalArgumentException("Count must be greater than zero, but was: " + count); } this.adapted = newAdapted; this.count = count; } // TODO: implement in terms of LazyIterate.whileDo() when it is added. public void forEach(Procedure procedure) { int i = 0; Iterator iterator = this.adapted.iterator(); while (i < this.count && iterator.hasNext()) { procedure.value(iterator.next()); i++; } } public void forEachWithIndex(ObjectIntProcedure procedure) { int i = 0; Iterator iterator = this.adapted.iterator(); while (i < this.count && iterator.hasNext()) { procedure.value(iterator.next(), i); i++; } } public

void forEachWith(Procedure2 procedure, P parameter) { int i = 0; Iterator iterator = this.adapted.iterator(); while (i < this.count && iterator.hasNext()) { procedure.value(iterator.next(), parameter); i++; } } @Override public Object[] toArray() { final Object[] result = new Object[this.count]; this.forEachWithIndex(new ObjectIntProcedure() { public void value(T each, int index) { result[index] = each; } }); return result; } public Iterator iterator() { return new TakeIterator(this.adapted, this.count); } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/ZipIterable.java000066400000000000000000000037571234315411400321300ustar00rootroot00000000000000/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy; import java.util.Iterator; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.tuple.Pair; import com.gs.collections.impl.lazy.iterator.ZipIterator; import com.gs.collections.impl.utility.internal.IterableIterate; import net.jcip.annotations.Immutable; /** * A ZipIterable is an iterable that transforms a source iterable on a condition as it iterates. */ @Immutable public class ZipIterable extends AbstractLazyIterable> { private final Iterable xs; private final Iterable ys; public ZipIterable(Iterable xs, Iterable ys) { this.xs = xs; this.ys = ys; } public Iterator> iterator() { return new ZipIterator(this.xs, this.ys); } public void forEach(Procedure> procedure) { IterableIterate.forEach(this, procedure); } public void forEachWithIndex(ObjectIntProcedure> objectIntProcedure) { IterableIterate.forEachWithIndex(this, objectIntProcedure); } public

void forEachWith(Procedure2, ? super P> procedure, P parameter) { IterableIterate.forEachWith(this, procedure, parameter); } } ZipWithIndexIterable.java000066400000000000000000000037741234315411400336740ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy; import java.util.Iterator; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.tuple.Pair; import com.gs.collections.impl.lazy.iterator.ZipWithIndexIterator; import com.gs.collections.impl.utility.internal.IterableIterate; import net.jcip.annotations.Immutable; /** * A CollectIterable is an iterable that transforms a source iterable on a condition as it iterates. */ @Immutable public class ZipWithIndexIterable extends AbstractLazyIterable> { private final Iterable iterable; public ZipWithIndexIterable(Iterable iterable) { this.iterable = iterable; } public Iterator> iterator() { return new ZipWithIndexIterator(this.iterable); } public void forEach(Procedure> procedure) { IterableIterate.forEach(this, procedure); } public void forEachWithIndex(ObjectIntProcedure> objectIntProcedure) { IterableIterate.forEachWithIndex(this, objectIntProcedure); } public

void forEachWith(Procedure2, ? super P> procedure, P parameter) { IterableIterate.forEachWith(this, procedure, parameter); } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/iterator/000077500000000000000000000000001234315411400306705ustar00rootroot00000000000000ChunkIterator.java000066400000000000000000000052651234315411400342460ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/iterator/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.iterator; import java.util.Iterator; import java.util.NoSuchElementException; import com.gs.collections.api.RichIterable; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.collection.MutableCollection; import com.gs.collections.impl.factory.Lists; import net.jcip.annotations.Immutable; @Immutable public final class ChunkIterator implements Iterator> { private final Iterator iterator; private final int size; private final Function0> speciesNewStrategy; public ChunkIterator(final Iterable iterable, int size) { if (size <= 0) { throw new IllegalArgumentException("Size for groups must be positive but was: " + size); } this.size = size; this.iterator = iterable.iterator(); if (iterable instanceof MutableCollection) { this.speciesNewStrategy = new Function0>() { public MutableCollection value() { return ((MutableCollection) iterable).newEmpty(); } }; } else { this.speciesNewStrategy = new Function0>() { public MutableCollection value() { return Lists.mutable.of(); } }; } } public void remove() { throw new UnsupportedOperationException("Cannot call remove() on " + this.getClass().getSimpleName()); } public boolean hasNext() { return this.iterator.hasNext(); } public RichIterable next() { if (!this.iterator.hasNext()) { throw new NoSuchElementException(); } int i = this.size; MutableCollection result = this.speciesNewStrategy.value(); while (i > 0 && this.iterator.hasNext()) { result.add(this.iterator.next()); i -= 1; } return result; } } CollectIterator.java000066400000000000000000000032771234315411400345640ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/iterator/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.iterator; import java.util.Iterator; import java.util.NoSuchElementException; import com.gs.collections.api.block.function.Function; import net.jcip.annotations.Immutable; @Immutable public final class CollectIterator implements Iterator { private final Iterator iterator; private final Function function; public CollectIterator(Iterable iterable, Function function) { this(iterable.iterator(), function); } public CollectIterator(Iterator newIterator, Function function) { this.iterator = newIterator; this.function = function; } public void remove() { throw new UnsupportedOperationException("Cannot remove from a collect iterator"); } public boolean hasNext() { return this.iterator.hasNext(); } public V next() { if (this.hasNext()) { return this.function.valueOf(this.iterator.next()); } throw new NoSuchElementException(); } } DistinctIterator.java000066400000000000000000000037501234315411400347540ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/iterator/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.iterator; import java.util.Iterator; import java.util.NoSuchElementException; import com.gs.collections.api.set.MutableSet; import com.gs.collections.impl.set.mutable.UnifiedSet; public final class DistinctIterator implements Iterator { private static final Object NULL = new Object(); private final Iterator iterator; private final MutableSet seenSoFar = UnifiedSet.newSet(); private Object next = NULL; public DistinctIterator(Iterable iterable) { this(iterable.iterator()); } public DistinctIterator(Iterator iterator) { this.iterator = iterator; } public void remove() { throw new UnsupportedOperationException("Cannot remove from a distinct iterator"); } public boolean hasNext() { if (this.next != NULL) { return true; } while (this.iterator.hasNext()) { T temp = this.iterator.next(); if (this.seenSoFar.add(temp)) { this.next = temp; return true; } } return false; } public T next() { if (this.next != NULL || this.hasNext()) { Object temp = this.next; this.next = NULL; return (T) temp; } throw new NoSuchElementException(); } } DropIterator.java000066400000000000000000000031311234315411400340700ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/iterator/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.iterator; import java.util.Iterator; import com.gs.collections.impl.block.predicate.DropIterablePredicate; import net.jcip.annotations.Immutable; /** * Iterates over the elements of the iterator skipping the first count elements or the full iterator if the count is * non-positive. */ @Immutable public final class DropIterator implements Iterator { private final Iterator delegateIterator; public DropIterator(Iterable iterable, int count) { this(iterable.iterator(), count); } public DropIterator(Iterator iterator, int count) { this.delegateIterator = new SelectIterator(iterator, new DropIterablePredicate(count)); } public boolean hasNext() { return this.delegateIterator.hasNext(); } public T next() { return this.delegateIterator.next(); } public void remove() { throw new UnsupportedOperationException("Cannot remove from a drop iterator"); } } FlatCollectIterator.java000066400000000000000000000041701234315411400353640ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/iterator/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.iterator; import java.util.Iterator; import java.util.NoSuchElementException; import com.gs.collections.api.block.function.Function; import com.gs.collections.impl.EmptyIterator; public final class FlatCollectIterator implements Iterator { private final Iterator iterator; private final Function> function; private Iterator innerIterator = EmptyIterator.getInstance(); public FlatCollectIterator( Iterable iterable, Function> newFunction) { this(iterable.iterator(), newFunction); } public FlatCollectIterator( Iterator newIterator, Function> newFunction) { this.iterator = newIterator; this.function = newFunction; } public void remove() { throw new UnsupportedOperationException("Cannot remove from a flatCollect iterator"); } public boolean hasNext() { while (true) { if (this.innerIterator.hasNext()) { return true; } if (!this.iterator.hasNext()) { return false; } this.innerIterator = this.function.valueOf(this.iterator.next()).iterator(); } } public V next() { if (!this.hasNext()) { throw new NoSuchElementException(); } return this.innerIterator.next(); } } SelectInstancesOfIterator.java000066400000000000000000000037201234315411400365440ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/iterator/* * Copyright 2012 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.iterator; import java.util.Iterator; import java.util.NoSuchElementException; public final class SelectInstancesOfIterator implements Iterator { private static final Object NULL = new Object(); private final Iterator iterator; private final Class clazz; private Object next = NULL; public SelectInstancesOfIterator(Iterable iterable, Class clazz) { this(iterable.iterator(), clazz); } public SelectInstancesOfIterator(Iterator iterator, Class clazz) { this.iterator = iterator; this.clazz = clazz; } public void remove() { throw new UnsupportedOperationException("Cannot remove from a selectInstances iterator"); } public boolean hasNext() { if (this.next != NULL) { return true; } while (this.iterator.hasNext()) { Object temp = this.iterator.next(); if (this.clazz.isInstance(temp)) { this.next = temp; return true; } } return false; } public T next() { if (this.next != NULL || this.hasNext()) { Object temp = this.next; this.next = NULL; return (T) temp; } throw new NoSuchElementException(); } } SelectIterator.java000066400000000000000000000040271234315411400344100ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/iterator/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.iterator; import java.util.Iterator; import java.util.NoSuchElementException; import com.gs.collections.api.block.predicate.Predicate; public final class SelectIterator implements Iterator { private static final Object NULL = new Object(); private final Iterator iterator; private final Predicate predicate; private Object next = NULL; public SelectIterator(Iterable iterable, Predicate predicate) { this(iterable.iterator(), predicate); } public SelectIterator(Iterator iterator, Predicate predicate) { this.iterator = iterator; this.predicate = predicate; } public void remove() { throw new UnsupportedOperationException("Cannot remove from a select iterator"); } public boolean hasNext() { if (this.next != NULL) { return true; } while (this.iterator.hasNext()) { T temp = this.iterator.next(); if (this.predicate.accept(temp)) { this.next = temp; return true; } } return false; } public T next() { if (this.next != NULL || this.hasNext()) { Object temp = this.next; this.next = NULL; return (T) temp; } throw new NoSuchElementException(); } } TakeIterator.java000066400000000000000000000032711234315411400340550ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/iterator/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.iterator; import java.util.Iterator; import java.util.NoSuchElementException; /** * Iterates over the first count elements of the iterator or the full size of the iterator * if the count is greater than the length of the receiver. */ public final class TakeIterator implements Iterator { private final Iterator iterator; private final int count; private int currentIndex; public TakeIterator(Iterable iterable, int count) { this(iterable.iterator(), count); } public TakeIterator(Iterator iterator, int count) { this.iterator = iterator; this.count = count; } public boolean hasNext() { return this.currentIndex < this.count && this.iterator.hasNext(); } public T next() { if (this.hasNext()) { this.currentIndex++; return this.iterator.next(); } throw new NoSuchElementException(); } public void remove() { throw new UnsupportedOperationException("Cannot remove from a take iterator"); } } ZipIterator.java000066400000000000000000000027341234315411400337360ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/iterator/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.iterator; import java.util.Iterator; import com.gs.collections.api.tuple.Pair; import com.gs.collections.impl.tuple.Tuples; import net.jcip.annotations.Immutable; @Immutable public final class ZipIterator implements Iterator> { private final Iterator xIterator; private final Iterator yIterator; public ZipIterator(Iterable xs, Iterable ys) { this.xIterator = xs.iterator(); this.yIterator = ys.iterator(); } public void remove() { throw new UnsupportedOperationException("Cannot call remove() on " + this.getClass().getSimpleName()); } public boolean hasNext() { return this.xIterator.hasNext() && this.yIterator.hasNext(); } public Pair next() { return Tuples.pair(this.xIterator.next(), this.yIterator.next()); } } ZipWithIndexIterator.java000066400000000000000000000027051234315411400355600ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/iterator/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.iterator; import java.util.Iterator; import com.gs.collections.api.tuple.Pair; import com.gs.collections.impl.tuple.Tuples; public final class ZipWithIndexIterator implements Iterator> { private final Iterator iterator; private int index = 0; public ZipWithIndexIterator(Iterable iterable) { this.iterator = iterable.iterator(); } public void remove() { throw new UnsupportedOperationException("Cannot call remove() on " + this.getClass().getSimpleName()); } public boolean hasNext() { return this.iterator.hasNext(); } public Pair next() { try { return Tuples.pair(this.iterator.next(), this.index); } finally { this.index += 1; } } } package-info.java000066400000000000000000000013441234315411400340020ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/iterator/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains implementations of the {@link java.util.Iterator} interface. */ package com.gs.collections.impl.lazy.iterator; gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/package-info.java000066400000000000000000000015641234315411400322340ustar00rootroot00000000000000/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains implementations of the {@link com.gs.collections.api.LazyIterable} interface. *

* A LazyIterable is RichIterable which will defer evaluation for certain methods like select, reject, collect, etc. *

*/ package com.gs.collections.impl.lazy; gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/000077500000000000000000000000001234315411400306335ustar00rootroot00000000000000AbstractBatch.java000066400000000000000000000030511234315411400341230ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.parallel; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.impl.block.procedure.CountProcedure; public abstract class AbstractBatch implements Batch { public int count(Predicate predicate) { CountProcedure procedure = new CountProcedure(predicate); this.forEach(procedure); return procedure.getCount(); } public String makeString(final String separator) { final StringBuilder stringBuilder = new StringBuilder(); this.forEach(new Procedure() { public void value(T each) { if (stringBuilder.length() != 0) { stringBuilder.append(separator); } stringBuilder.append(each); } }); return stringBuilder.toString(); } } AbstractParallelIterable.java000066400000000000000000000570001234315411400363110ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.parallel; import java.io.IOException; import java.util.Collections; import java.util.Comparator; import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.CompletionService; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorCompletionService; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.ParallelIterable; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.bag.MutableBag; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.map.MapIterable; import com.gs.collections.api.map.MutableMap; import com.gs.collections.api.map.sorted.MutableSortedMap; import com.gs.collections.api.set.MutableSet; import com.gs.collections.api.set.sorted.MutableSortedSet; import com.gs.collections.impl.Counter; import com.gs.collections.impl.bag.mutable.HashBag; import com.gs.collections.impl.block.factory.Comparators; import com.gs.collections.impl.block.factory.Predicates; import com.gs.collections.impl.block.factory.Procedures; import com.gs.collections.impl.block.procedure.CollectionAddProcedure; import com.gs.collections.impl.block.procedure.MapCollectProcedure; import com.gs.collections.impl.block.procedure.MutatingAggregationProcedure; import com.gs.collections.impl.block.procedure.NonMutatingAggregationProcedure; import com.gs.collections.impl.block.procedure.checked.CheckedProcedure2; import com.gs.collections.impl.list.mutable.CompositeFastList; import com.gs.collections.impl.list.mutable.FastList; import com.gs.collections.impl.map.mutable.ConcurrentHashMapUnsafe; import com.gs.collections.impl.map.mutable.UnifiedMap; import com.gs.collections.impl.map.sorted.mutable.TreeSortedMap; import com.gs.collections.impl.set.mutable.SetAdapter; import com.gs.collections.impl.set.mutable.UnifiedSet; import com.gs.collections.impl.set.sorted.mutable.TreeSortedSet; @Beta public abstract class AbstractParallelIterable> implements ParallelIterable { protected static void forEach(final AbstractParallelIterable> parallelIterable, final Procedure procedure) { LazyIterable> futures = parallelIterable.split().collect(new Function, Future>() { public Future valueOf(final RootBatch chunk) { return parallelIterable.getExecutorService().submit(new Runnable() { public void run() { chunk.forEach(procedure); } }); } }); // The call to to toList() is important to stop the lazy evaluation and force all the Runnables to start executing. MutableList> futuresList = futures.toList(); for (Future future : futuresList) { try { future.get(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } catch (ExecutionException e) { throw new RuntimeException(e); } } } protected static boolean anySatisfy(AbstractParallelIterable> parallelIterable, final Predicate predicate) { final CompletionService completionService = new ExecutorCompletionService(parallelIterable.getExecutorService()); MutableSet> futures = parallelIterable.split().collect(new Function, Future>() { public Future valueOf(final RootBatch batch) { return completionService.submit(new Callable() { public Boolean call() { return batch.anySatisfy(predicate); } }); } }, UnifiedSet.>newSet()); while (futures.notEmpty()) { try { Future future = completionService.take(); if (future.get()) { for (Future eachFuture : futures) { eachFuture.cancel(true); } return true; } futures.remove(future); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } catch (ExecutionException e) { throw new RuntimeException(e); } } return false; } protected static boolean allSatisfy(AbstractParallelIterable> parallelIterable, final Predicate predicate) { final CompletionService completionService = new ExecutorCompletionService(parallelIterable.getExecutorService()); MutableSet> futures = parallelIterable.split().collect(new Function, Future>() { public Future valueOf(final RootBatch batch) { return completionService.submit(new Callable() { public Boolean call() { return batch.allSatisfy(predicate); } }); } }, UnifiedSet.>newSet()); while (futures.notEmpty()) { try { Future future = completionService.take(); if (!future.get()) { for (Future eachFuture : futures) { eachFuture.cancel(true); } return false; } futures.remove(future); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } catch (ExecutionException e) { throw new RuntimeException(e); } } return true; } protected static T detect(final AbstractParallelIterable> parallelIterable, final Predicate predicate) { LazyIterable> chunks = parallelIterable.split(); LazyIterable> futures = chunks.collect(new Function, Future>() { public Future valueOf(final RootBatch chunk) { return parallelIterable.getExecutorService().submit(new Callable() { public T call() { return chunk.detect(predicate); } }); } }); // The call to to toList() is important to stop the lazy evaluation and force all the Runnables to start executing. MutableList> futuresList = futures.toList(); for (Future future : futuresList) { try { T eachResult = future.get(); if (eachResult != null) { for (Future eachFutureToCancel : futuresList) { eachFutureToCancel.cancel(true); } return eachResult; } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } catch (ExecutionException e) { throw new RuntimeException(e); } } return null; } public abstract ExecutorService getExecutorService(); public abstract LazyIterable split(); protected abstract boolean isOrdered(); protected void collectCombine(Function, V> function, Procedure2 combineProcedure, S state) { if (this.isOrdered()) { this.collectCombineOrdered(function, combineProcedure, state); } else { this.collectCombineUnordered(function, combineProcedure, state); } } private void collectCombineOrdered(final Function, V> function, Procedure2 combineProcedure, S state) { LazyIterable> chunks = this.split(); LazyIterable> futures = chunks.collect(new Function, Future>() { public Future valueOf(final Batch chunk) { return AbstractParallelIterable.this.getExecutorService().submit(new Callable() { public V call() { return function.valueOf(chunk); } }); } }); // The call to to toList() is important to stop the lazy evaluation and force all the Runnables to start executing. MutableList> futuresList = futures.toList(); for (Future future : futuresList) { try { combineProcedure.value(state, future.get()); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } catch (ExecutionException e) { throw new RuntimeException(e); } } } private void collectCombineUnordered(final Function, V> function, Procedure2 combineProcedure, S state) { LazyIterable> chunks = this.split(); MutableList> callables = chunks.collect(new Function, Callable>() { public Callable valueOf(final Batch chunk) { return new Callable() { public V call() { return function.valueOf(chunk); } }; } }).toList(); final ExecutorCompletionService completionService = new ExecutorCompletionService(this.getExecutorService()); callables.forEach(new Procedure>() { public void value(Callable callable) { completionService.submit(callable); } }); int numTasks = callables.size(); while (numTasks > 0) { try { Future future = completionService.take(); combineProcedure.value(state, future.get()); numTasks--; } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } catch (ExecutionException e) { throw new RuntimeException(e); } } } @Override public String toString() { return this.makeString("[", ", ", "]"); } public String makeString() { return this.makeString(", "); } public String makeString(String separator) { return this.makeString("", separator, ""); } public String makeString(String start, String separator, String end) { Appendable stringBuilder = new StringBuilder(); this.appendString(stringBuilder, start, separator, end); return stringBuilder.toString(); } public void appendString(Appendable appendable) { this.appendString(appendable, ", "); } public void appendString(Appendable appendable, String separator) { this.appendString(appendable, "", separator, ""); } public void appendString(final Appendable appendable, String start, final String separator, String end) { try { appendable.append(start); Function, String> map = new Function, String>() { public String valueOf(Batch batch) { return batch.makeString(separator); } }; Procedure2 reduce = new CheckedProcedure2() { private boolean first = true; public void safeValue(Appendable accumulator, String each) throws IOException { if ("".equals(each)) { return; } if (this.first) { this.first = false; } else { appendable.append(separator); } appendable.append(each); } }; this.collectCombine(map, reduce, appendable); appendable.append(end); } catch (IOException e) { throw new RuntimeException(e); } } public

void forEachWith(Procedure2 procedure, P parameter) { this.forEach(Procedures.bind(procedure, parameter)); } public

boolean anySatisfyWith(Predicate2 predicate, P parameter) { return this.anySatisfy(Predicates.bind(predicate, parameter)); } public

boolean allSatisfyWith(Predicate2 predicate, P parameter) { return this.allSatisfy(Predicates.bind(predicate, parameter)); } public boolean noneSatisfy(Predicate predicate) { return this.allSatisfy(Predicates.not(predicate)); } public

boolean noneSatisfyWith(Predicate2 predicate, P parameter) { return this.noneSatisfy(Predicates.bind(predicate, parameter)); } public

T detectWith(Predicate2 predicate, P parameter) { return this.detect(Predicates.bind(predicate, parameter)); } public T detectIfNone(Predicate predicate, Function0 function) { T result = this.detect(predicate); return result == null ? function.value() : result; } public

T detectWithIfNone(Predicate2 predicate, P parameter, Function0 function) { return this.detectIfNone(Predicates.bind(predicate, parameter), function); } public Object[] toArray() { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".toArray() not implemented yet"); } public E[] toArray(E[] array) { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".toArray() not implemented yet"); } public MutableList toList() { Function, FastList> map = new Function, FastList>() { public FastList valueOf(Batch batch) { FastList list = FastList.newList(); batch.forEach(CollectionAddProcedure.on(list)); return list; } }; Procedure2, FastList> reduce = new Procedure2, FastList>() { public void value(MutableList accumulator, FastList each) { accumulator.addAll(each); } }; MutableList state = new CompositeFastList(); this.collectCombine(map, reduce, state); return state; } public MutableList toSortedList() { return this.toList().toSortedList(); } public MutableList toSortedList(Comparator comparator) { return this.toList().toSortedList(comparator); } public > MutableList toSortedListBy(Function function) { return this.toSortedList(Comparators.byFunction(function)); } public MutableSet toSet() { ConcurrentHashMapUnsafe map = ConcurrentHashMapUnsafe.newMap(); Set result = Collections.newSetFromMap(map); this.forEach(CollectionAddProcedure.on(result)); return SetAdapter.adapt(map.keySet()); } public MutableSortedSet toSortedSet() { MutableSortedSet result = TreeSortedSet.newSet().asSynchronized(); this.forEach(CollectionAddProcedure.on(result)); return result; } public > MutableSortedSet toSortedSetBy(Function function) { return this.toSortedSet(Comparators.byFunction(function)); } public MutableBag toBag() { MutableBag result = HashBag.newBag().asSynchronized(); this.forEach(CollectionAddProcedure.on(result)); return result; } public MutableSortedSet toSortedSet(Comparator comparator) { MutableSortedSet result = TreeSortedSet.newSet(comparator).asSynchronized(); this.forEach(CollectionAddProcedure.on(result)); return result; } public MutableMap toMap( Function keyFunction, Function valueFunction) { MutableMap map = UnifiedMap.newMap().asSynchronized(); this.forEach(new MapCollectProcedure(map, keyFunction, valueFunction)); return map; } public MutableSortedMap toSortedMap( Function keyFunction, Function valueFunction) { MutableSortedMap sortedMap = TreeSortedMap.newMap().asSynchronized(); this.forEach(new MapCollectProcedure(sortedMap, keyFunction, valueFunction)); return sortedMap; } public MutableSortedMap toSortedMap(Comparator comparator, Function keyFunction, Function valueFunction) { MutableSortedMap sortedMap = TreeSortedMap.newMap(comparator).asSynchronized(); this.forEach(new MapCollectProcedure(sortedMap, keyFunction, valueFunction)); return sortedMap; } public MapIterable aggregateBy( Function groupBy, Function0 zeroValueFactory, Function2 nonMutatingAggregator) { MutableMap map = ConcurrentHashMapUnsafe.newMap(); this.forEach(new NonMutatingAggregationProcedure(map, groupBy, zeroValueFactory, nonMutatingAggregator)); return map; } public MapIterable aggregateInPlaceBy( Function groupBy, Function0 zeroValueFactory, Procedure2 mutatingAggregator) { MutableMap map = ConcurrentHashMapUnsafe.newMap(); this.forEach(new MutatingAggregationProcedure(map, groupBy, zeroValueFactory, mutatingAggregator)); return map; } public int count(final Predicate predicate) { Function, Integer> map = new Function, Integer>() { public Integer valueOf(Batch batch) { return batch.count(predicate); } }; Procedure2 combineProcedure = new Procedure2() { public void value(Counter counter, Integer eachCount) { counter.add(eachCount); } }; Counter state = new Counter(); this.collectCombineUnordered(map, combineProcedure, state); return state.getCount(); } public

int countWith(Predicate2 predicate, P parameter) { return this.count(Predicates.bind(predicate, parameter)); } public T min(Comparator comparator) { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".min() not implemented yet"); } public T max(Comparator comparator) { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".max() not implemented yet"); } public T min() { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".min() not implemented yet"); } public T max() { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".max() not implemented yet"); } public > T minBy(Function function) { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".minBy() not implemented yet"); } public > T maxBy(Function function) { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".maxBy() not implemented yet"); } public long sumOfInt(IntFunction function) { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".sumOfInt() not implemented yet"); } public double sumOfFloat(FloatFunction function) { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".sumOfFloat() not implemented yet"); } public long sumOfLong(LongFunction function) { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".sumOfLong() not implemented yet"); } public double sumOfDouble(DoubleFunction function) { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".sumOfDouble() not implemented yet"); } } AbstractParallelIterableImpl.java000066400000000000000000000107651234315411400371420ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.parallel; import com.gs.collections.api.ParallelIterable; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.map.MapIterable; import com.gs.collections.api.multimap.bag.MutableBagMultimap; import com.gs.collections.api.multimap.bag.UnsortedBagMultimap; import com.gs.collections.api.set.ParallelUnsortedSetIterable; import com.gs.collections.impl.block.factory.Functions; import com.gs.collections.impl.block.factory.Predicates; import com.gs.collections.impl.lazy.parallel.set.ParallelCollectIterable; import com.gs.collections.impl.multimap.bag.SynchronizedPutHashBagMultimap; @Beta public abstract class AbstractParallelIterableImpl> extends AbstractParallelIterable { @Override protected boolean isOrdered() { return false; } public ParallelUnsortedSetIterable asUnique() { return new ParallelDistinctIterable(this); } public ParallelIterable select(Predicate predicate) { return new ParallelSelectIterable(this, predicate); } public

ParallelIterable selectWith(Predicate2 predicate, P parameter) { return this.select(Predicates.bind(predicate, parameter)); } public ParallelIterable selectInstancesOf(Class clazz) { return (ParallelIterable) this.select(Predicates.instanceOf(clazz)); } public ParallelIterable reject(Predicate predicate) { return this.select(Predicates.not(predicate)); } public

ParallelIterable rejectWith(Predicate2 predicate, P parameter) { return this.reject(Predicates.bind(predicate, parameter)); } public ParallelIterable collect(Function function) { return new ParallelCollectIterable(this, function); } public ParallelIterable collectWith(Function2 function, P parameter) { return this.collect(Functions.bind(function, parameter)); } public ParallelIterable collectIf(Predicate predicate, Function function) { return this.select(predicate).collect(function); } public ParallelIterable flatCollect(Function> function) { throw new UnsupportedOperationException(); } public UnsortedBagMultimap groupBy(final Function function) { final MutableBagMultimap result = SynchronizedPutHashBagMultimap.newMultimap(); this.forEach(new Procedure() { public void value(T each) { V key = function.valueOf(each); result.put(key, each); } }); return result; } public UnsortedBagMultimap groupByEach(final Function> function) { final MutableBagMultimap result = SynchronizedPutHashBagMultimap.newMultimap(); this.forEach(new Procedure() { public void value(T each) { Iterable keys = function.valueOf(each); for (V key : keys) { result.put(key, each); } } }); return result; } public MapIterable groupByUniqueKey(Function function) { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".groupByUniqueKey() not implemented yet"); } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/Batch.java000066400000000000000000000022151234315411400325170ustar00rootroot00000000000000/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.parallel; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; @Beta public interface Batch { void forEach(Procedure procedure); Batch select(Predicate predicate); Batch collect(Function function); int count(Predicate predicate); String makeString(String separator); } ParallelDistinctIterable.java000066400000000000000000000110161234315411400363240ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.parallel; import java.util.concurrent.ExecutorService; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.set.ParallelUnsortedSetIterable; import com.gs.collections.impl.lazy.parallel.list.DistinctBatch; import com.gs.collections.impl.lazy.parallel.set.AbstractParallelUnsortedSetIterable; import com.gs.collections.impl.lazy.parallel.set.UnsortedSetBatch; import com.gs.collections.impl.map.mutable.ConcurrentHashMap; @Beta public class ParallelDistinctIterable extends AbstractParallelUnsortedSetIterable> { private final AbstractParallelIterable> parallelIterable; public ParallelDistinctIterable(AbstractParallelIterable> parallelIterable) { this.parallelIterable = parallelIterable; } @Override public ExecutorService getExecutorService() { return this.parallelIterable.getExecutorService(); } @Override public LazyIterable> split() { // TODO: Replace the map with a concurrent set once it's implemented final ConcurrentHashMap distinct = new ConcurrentHashMap(); return this.parallelIterable.split().collect(new Function, UnsortedSetBatch>() { public UnsortedSetBatch valueOf(Batch batch) { return new DistinctBatch(batch, distinct); } }); } @Override public ParallelUnsortedSetIterable asUnique() { return this; } public void forEach(final Procedure procedure) { // TODO: Replace the map with a concurrent set once it's implemented final ConcurrentHashMap distinct = new ConcurrentHashMap(); this.parallelIterable.forEach(new Procedure() { public void value(T each) { if (distinct.put(each, true) == null) { procedure.value(each); } } }); } public boolean anySatisfy(Predicate predicate) { return this.parallelIterable.anySatisfy(new DistinctAndPredicate(predicate)); } public boolean allSatisfy(Predicate predicate) { return this.parallelIterable.allSatisfy(new DistinctOrPredicate(predicate)); } public T detect(Predicate predicate) { return this.parallelIterable.detect(new DistinctAndPredicate(predicate)); } private static final class DistinctAndPredicate implements Predicate { // TODO: Replace the map with a concurrent set once it's implemented private final ConcurrentHashMap distinct = new ConcurrentHashMap(); private final Predicate predicate; private DistinctAndPredicate(Predicate predicate) { this.predicate = predicate; } public boolean accept(T each) { return this.distinct.put(each, true) == null && this.predicate.accept(each); } } private static final class DistinctOrPredicate implements Predicate { // TODO: Replace the map with a concurrent set once it's implemented private final ConcurrentHashMap distinct = new ConcurrentHashMap(); private final Predicate predicate; private DistinctOrPredicate(Predicate predicate) { this.predicate = predicate; } public boolean accept(T each) { return this.distinct.put(each, true) != null || this.predicate.accept(each); } } } ParallelSelectIterable.java000066400000000000000000000062271234315411400357720ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.parallel; import java.util.concurrent.ExecutorService; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.impl.block.factory.Predicates; import com.gs.collections.impl.block.procedure.IfProcedure; @Beta public class ParallelSelectIterable extends AbstractParallelIterableImpl> { private final AbstractParallelIterable> parallelIterable; private final Predicate predicate; public ParallelSelectIterable(AbstractParallelIterable> parallelIterable, Predicate predicate) { this.parallelIterable = parallelIterable; this.predicate = predicate; } @Override public ExecutorService getExecutorService() { return this.parallelIterable.getExecutorService(); } @Override public LazyIterable> split() { return this.parallelIterable.split().collect(new Function, Batch>() { public Batch valueOf(Batch eachBatch) { return eachBatch.select(ParallelSelectIterable.this.predicate); } }); } public void forEach(Procedure procedure) { this.parallelIterable.forEach(new IfProcedure(this.predicate, procedure)); } public boolean anySatisfy(Predicate predicate) { return this.parallelIterable.anySatisfy(Predicates.and(this.predicate, predicate)); } public boolean allSatisfy(Predicate predicate) { return this.parallelIterable.allSatisfy(new SelectAllSatisfyPredicate(this.predicate, predicate)); } public T detect(Predicate predicate) { return this.parallelIterable.detect(Predicates.and(this.predicate, predicate)); } private static final class SelectAllSatisfyPredicate implements Predicate { private final Predicate left; private final Predicate right; private SelectAllSatisfyPredicate(Predicate left, Predicate right) { this.left = left; this.right = right; } public boolean accept(T each) { boolean leftResult = this.left.accept(each); return !leftResult || this.right.accept(each); } } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/RootBatch.java000066400000000000000000000021221234315411400333600ustar00rootroot00000000000000/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.parallel; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.block.predicate.Predicate; /** * A {@link com.gs.collections.impl.lazy.parallel.Batch} that must be at the root of the chain, * not wrapped in other Batches. */ @Beta public interface RootBatch extends Batch { boolean anySatisfy(Predicate predicate); boolean allSatisfy(Predicate predicate); T detect(Predicate predicate); } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/bag/000077500000000000000000000000001234315411400313645ustar00rootroot00000000000000AbstractParallelUnsortedBag.java000066400000000000000000000126211234315411400375300ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/bag/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.parallel.bag; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.bag.MutableBag; import com.gs.collections.api.bag.ParallelUnsortedBag; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.map.MapIterable; import com.gs.collections.api.multimap.bag.MutableBagMultimap; import com.gs.collections.api.multimap.bag.UnsortedBagMultimap; import com.gs.collections.api.set.ParallelUnsortedSetIterable; import com.gs.collections.impl.bag.mutable.HashBag; import com.gs.collections.impl.block.factory.Functions; import com.gs.collections.impl.block.factory.Predicates; import com.gs.collections.impl.block.procedure.BagAddOccurrencesProcedure; import com.gs.collections.impl.lazy.parallel.AbstractParallelIterable; import com.gs.collections.impl.multimap.bag.SynchronizedPutHashBagMultimap; @Beta public abstract class AbstractParallelUnsortedBag> extends AbstractParallelIterable implements ParallelUnsortedBag { @Override protected boolean isOrdered() { return false; } public ParallelUnsortedSetIterable asUnique() { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".asUnique() not implemented yet"); } public ParallelUnsortedBag select(Predicate predicate) { return new ParallelSelectUnsortedBag(this, predicate); } public

ParallelUnsortedBag selectWith(Predicate2 predicate, P parameter) { return this.select(Predicates.bind(predicate, parameter)); } public ParallelUnsortedBag selectInstancesOf(Class clazz) { return (ParallelUnsortedBag) this.select(Predicates.instanceOf(clazz)); } public ParallelUnsortedBag reject(Predicate predicate) { return this.select(Predicates.not(predicate)); } public

ParallelUnsortedBag rejectWith(Predicate2 predicate, P parameter) { return this.reject(Predicates.bind(predicate, parameter)); } public ParallelUnsortedBag collect(Function function) { return new ParallelCollectUnsortedBag(this, function); } public ParallelUnsortedBag collectWith(Function2 function, P parameter) { return this.collect(Functions.bind(function, parameter)); } public ParallelUnsortedBag collectIf(Predicate predicate, Function function) { return this.select(predicate).collect(function); } public ParallelUnsortedBag flatCollect(Function> function) { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".flatCollect() not implemented yet"); } @Override public MutableBag toBag() { MutableBag result = HashBag.newBag().asSynchronized(); this.forEachWithOccurrences(BagAddOccurrencesProcedure.on(result)); return result; } public UnsortedBagMultimap groupBy(final Function function) { final MutableBagMultimap result = SynchronizedPutHashBagMultimap.newMultimap(); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { V key = function.valueOf(each); for (int i = 0; i < occurrences; i++) { result.put(key, each); } } }); return result; } public UnsortedBagMultimap groupByEach(final Function> function) { final MutableBagMultimap result = SynchronizedPutHashBagMultimap.newMultimap(); this.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { Iterable keys = function.valueOf(each); for (V key : keys) { for (int i = 0; i < occurrences; i++) { result.put(key, each); } } } }); return result; } public MapIterable groupByUniqueKey(Function function) { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".groupByUniqueKey() not implemented yet"); } } CollectUnsortedBagBatch.java000066400000000000000000000044711234315411400366430ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/bag/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.parallel.bag; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.impl.block.factory.Functions; import com.gs.collections.impl.lazy.parallel.AbstractBatch; @Beta public class CollectUnsortedBagBatch extends AbstractBatch implements UnsortedBagBatch { private final UnsortedBagBatch unsortedBagBatch; private final Function function; public CollectUnsortedBagBatch(UnsortedBagBatch unsortedBagBatch, Function function) { this.unsortedBagBatch = unsortedBagBatch; this.function = function; } public void forEach(Procedure procedure) { this.unsortedBagBatch.forEach(Functions.bind(procedure, this.function)); } public void forEachWithOccurrences(ObjectIntProcedure procedure) { this.unsortedBagBatch.forEachWithOccurrences(Functions.bind(procedure, this.function)); } /* public BagBatch collect(Function function) { return new CollectBagBatch(this.bagBatch, Functions.chain(this.function, function)); } */ public UnsortedBagBatch select(Predicate predicate) { return new SelectUnsortedBagBatch(this, predicate); } public UnsortedBagBatch collect(Function function) { return new CollectUnsortedBagBatch(this, function); } } ParallelCollectUnsortedBag.java000066400000000000000000000064261234315411400373600ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/bag/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.parallel.bag; import java.util.concurrent.ExecutorService; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.impl.block.factory.Functions; import com.gs.collections.impl.block.factory.Predicates; @Beta class ParallelCollectUnsortedBag extends AbstractParallelUnsortedBag> { private final AbstractParallelUnsortedBag> parallelIterable; private final Function function; ParallelCollectUnsortedBag(AbstractParallelUnsortedBag> parallelIterable, Function function) { this.parallelIterable = parallelIterable; this.function = function; } @Override public ExecutorService getExecutorService() { return this.parallelIterable.getExecutorService(); } @Override public LazyIterable> split() { return this.parallelIterable.split().collect(new Function, UnsortedBagBatch>() { public UnsortedBagBatch valueOf(UnsortedBagBatch eachBatch) { return eachBatch.collect(ParallelCollectUnsortedBag.this.function); } }); } public void forEach(Procedure procedure) { this.parallelIterable.forEach(Functions.bind(procedure, this.function)); } public void forEachWithOccurrences(final ObjectIntProcedure procedure) { this.parallelIterable.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int parameter) { procedure.value(ParallelCollectUnsortedBag.this.function.valueOf(each), parameter); } }); } public boolean anySatisfy(Predicate predicate) { return this.parallelIterable.anySatisfy(Predicates.attributePredicate(this.function, predicate)); } public boolean allSatisfy(Predicate predicate) { return this.parallelIterable.allSatisfy(Predicates.attributePredicate(this.function, predicate)); } public V detect(Predicate predicate) { T resultItem = this.parallelIterable.detect(Predicates.attributePredicate(this.function, predicate)); return resultItem == null ? null : this.function.valueOf(resultItem); } } ParallelSelectUnsortedBag.java000066400000000000000000000073771234315411400372200ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/bag/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.parallel.bag; import java.util.concurrent.ExecutorService; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.impl.block.factory.Predicates; import com.gs.collections.impl.block.procedure.IfProcedure; @Beta class ParallelSelectUnsortedBag extends AbstractParallelUnsortedBag> { private final AbstractParallelUnsortedBag> parallelIterable; private final Predicate predicate; ParallelSelectUnsortedBag(AbstractParallelUnsortedBag> parallelIterable, Predicate predicate) { this.parallelIterable = parallelIterable; this.predicate = predicate; } public void forEach(Procedure procedure) { this.parallelIterable.forEach(new IfProcedure(this.predicate, procedure)); } public void forEachWithOccurrences(final ObjectIntProcedure procedure) { this.parallelIterable.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int parameter) { if (ParallelSelectUnsortedBag.this.predicate.accept(each)) { procedure.value(each, parameter); } } }); } public boolean anySatisfy(Predicate predicate) { return this.parallelIterable.anySatisfy(Predicates.and(this.predicate, predicate)); } public boolean allSatisfy(Predicate predicate) { return this.parallelIterable.allSatisfy(new SelectAllSatisfyPredicate(this.predicate, predicate)); } @Override public ExecutorService getExecutorService() { return this.parallelIterable.getExecutorService(); } @Override public LazyIterable> split() { return this.parallelIterable.split().collect(new Function, UnsortedBagBatch>() { public UnsortedBagBatch valueOf(UnsortedBagBatch eachBatch) { return eachBatch.select(ParallelSelectUnsortedBag.this.predicate); } }); } public T detect(Predicate predicate) { return this.parallelIterable.detect(Predicates.and(this.predicate, predicate)); } private static final class SelectAllSatisfyPredicate implements Predicate { private final Predicate left; private final Predicate right; private SelectAllSatisfyPredicate(Predicate left, Predicate right) { this.left = left; this.right = right; } public boolean accept(T each) { boolean leftResult = this.left.accept(each); return !leftResult || this.right.accept(each); } } } ParallelUnsortedBagDistinctIterable.java000066400000000000000000000051761234315411400412250ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/bag/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.parallel.bag; import java.util.concurrent.ExecutorService; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.set.ParallelUnsortedSetIterable; import com.gs.collections.impl.lazy.parallel.set.AbstractParallelUnsortedSetIterable; import com.gs.collections.impl.lazy.parallel.set.UnsortedSetBatch; @Beta class ParallelUnsortedBagDistinctIterable extends AbstractParallelUnsortedSetIterable> { private final AbstractParallelUnsortedBag> parallelIterable; ParallelUnsortedBagDistinctIterable(AbstractParallelUnsortedBag> parallelIterable) { this.parallelIterable = parallelIterable; } @Override public ExecutorService getExecutorService() { return this.parallelIterable.getExecutorService(); } @Override public LazyIterable> split() { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".split() not implemented yet"); } public ParallelUnsortedSetIterable asUnique() { return this; } public void forEach(final Procedure procedure) { this.parallelIterable.forEachWithOccurrences(new ObjectIntProcedure() { public void value(T each, int occurrences) { procedure.value(each); } }); } public boolean anySatisfy(Predicate predicate) { return this.parallelIterable.anySatisfy(predicate); } public boolean allSatisfy(Predicate predicate) { return this.parallelIterable.allSatisfy(predicate); } public T detect(Predicate predicate) { return this.parallelIterable.detect(predicate); } } RootUnsortedBagBatch.java000066400000000000000000000015201234315411400361710ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/bag/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.parallel.bag; import com.gs.collections.api.annotation.Beta; import com.gs.collections.impl.lazy.parallel.RootBatch; @Beta public interface RootUnsortedBagBatch extends UnsortedBagBatch, RootBatch { } SelectUnsortedBagBatch.java000066400000000000000000000056411234315411400364750ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/bag/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.parallel.bag; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.impl.block.procedure.IfProcedure; import com.gs.collections.impl.lazy.parallel.AbstractBatch; @Beta public class SelectUnsortedBagBatch extends AbstractBatch implements UnsortedBagBatch { private final UnsortedBagBatch unsortedBagBatch; private final Predicate predicate; public SelectUnsortedBagBatch(UnsortedBagBatch unsortedBagBatch, Predicate predicate) { this.unsortedBagBatch = unsortedBagBatch; this.predicate = predicate; } public void forEach(Procedure procedure) { this.unsortedBagBatch.forEach(new IfProcedure(this.predicate, procedure)); } public void forEachWithOccurrences(ObjectIntProcedure procedure) { this.unsortedBagBatch.forEachWithOccurrences(new IfProcedureWithOccurrences(this.predicate, procedure)); } public UnsortedBagBatch select(Predicate predicate) { return new SelectUnsortedBagBatch(this, predicate); } public UnsortedBagBatch collect(Function function) { return new CollectUnsortedBagBatch(this, function); } /* public BagBatch select(Predicate predicate) { return new SelectBagBatch(this.bagBatch, Predicates.and(this.predicate, predicate)); } */ private static final class IfProcedureWithOccurrences implements ObjectIntProcedure { private final Predicate predicate; private final ObjectIntProcedure procedure; private IfProcedureWithOccurrences(Predicate predicate, ObjectIntProcedure procedure) { this.predicate = predicate; this.procedure = procedure; } public void value(T each, int parameter) { if (this.predicate.accept(each)) { this.procedure.value(each, parameter); } } } } UnsortedBagBatch.java000066400000000000000000000023071234315411400353310ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/bag/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.parallel.bag; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.impl.lazy.parallel.Batch; @Beta public interface UnsortedBagBatch extends Batch { void forEachWithOccurrences(ObjectIntProcedure procedure); UnsortedBagBatch select(Predicate predicate); UnsortedBagBatch collect(Function function); } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/list/000077500000000000000000000000001234315411400316065ustar00rootroot00000000000000AbstractParallelListIterable.java000066400000000000000000000076741234315411400401340ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/list/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.parallel.list; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.list.ParallelListIterable; import com.gs.collections.api.map.MapIterable; import com.gs.collections.api.multimap.list.ListMultimap; import com.gs.collections.api.set.ParallelUnsortedSetIterable; import com.gs.collections.impl.block.factory.Functions; import com.gs.collections.impl.block.factory.Predicates; import com.gs.collections.impl.lazy.parallel.AbstractParallelIterable; @Beta public abstract class AbstractParallelListIterable> extends AbstractParallelIterable implements ParallelListIterable { @Override protected boolean isOrdered() { return true; } public ParallelUnsortedSetIterable asUnique() { return new ParallelListDistinctIterable(this); } public ParallelListIterable select(Predicate predicate) { return new ParallelSelectListIterable(this, predicate); } public

ParallelListIterable selectWith(Predicate2 predicate, P parameter) { return this.select(Predicates.bind(predicate, parameter)); } public ParallelListIterable selectInstancesOf(Class clazz) { return (ParallelListIterable) this.select(Predicates.instanceOf(clazz)); } public ParallelListIterable reject(Predicate predicate) { return this.select(Predicates.not(predicate)); } public

ParallelListIterable rejectWith(Predicate2 predicate, P parameter) { return this.reject(Predicates.bind(predicate, parameter)); } public ParallelListIterable collect(Function function) { return new ParallelCollectListIterable(this, function); } public ParallelListIterable collectWith(Function2 function, P parameter) { return this.collect(Functions.bind(function, parameter)); } public ParallelListIterable collectIf(Predicate predicate, Function function) { return this.select(predicate).collect(function); } public ParallelListIterable flatCollect(Function> function) { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".flatCollect() not implemented yet"); } public ListMultimap groupBy(Function function) { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".groupBy() not implemented yet"); } public ListMultimap groupByEach(Function> function) { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".groupByEach() not implemented yet"); } public MapIterable groupByUniqueKey(Function function) { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".groupByUniqueKey() not implemented yet"); } } CollectListBatch.java000066400000000000000000000041731234315411400355620ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/list/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.parallel.list; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.impl.block.factory.Functions; import com.gs.collections.impl.lazy.parallel.AbstractBatch; import com.gs.collections.impl.lazy.parallel.set.UnsortedSetBatch; import com.gs.collections.impl.map.mutable.ConcurrentHashMap; @Beta public class CollectListBatch extends AbstractBatch implements ListBatch { private final ListBatch listBatch; private final Function function; public CollectListBatch(ListBatch listBatch, Function function) { this.listBatch = listBatch; this.function = function; } public void forEach(Procedure procedure) { this.listBatch.forEach(Functions.bind(procedure, this.function)); } public ListBatch select(Predicate predicate) { return new SelectListBatch(this, predicate); } public ListBatch collect(Function function) { // return new CollectListBatch(this.listBatch, Functions.chain(this.function, function)); return new CollectListBatch(this, function); } public UnsortedSetBatch distinct(ConcurrentHashMap distinct) { return new DistinctBatch(this, distinct); } } DistinctBatch.java000066400000000000000000000043411234315411400351170ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/list/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.parallel.list; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.impl.lazy.parallel.AbstractBatch; import com.gs.collections.impl.lazy.parallel.Batch; import com.gs.collections.impl.lazy.parallel.set.CollectUnsortedSetBatch; import com.gs.collections.impl.lazy.parallel.set.SelectUnsortedSetBatch; import com.gs.collections.impl.lazy.parallel.set.UnsortedSetBatch; import com.gs.collections.impl.map.mutable.ConcurrentHashMap; @Beta public class DistinctBatch extends AbstractBatch implements UnsortedSetBatch { private final Batch batch; private final ConcurrentHashMap distinct; public DistinctBatch(Batch batch, ConcurrentHashMap distinct) { this.batch = batch; this.distinct = distinct; } public void forEach(final Procedure procedure) { this.batch.forEach(new Procedure() { public void value(T each) { if (DistinctBatch.this.distinct.put(each, true) == null) { procedure.value(each); } } }); } public UnsortedSetBatch select(Predicate predicate) { return new SelectUnsortedSetBatch(this, predicate); } public UnsortedSetBatch collect(Function function) { return new CollectUnsortedSetBatch(this, function); } } ListBatch.java000066400000000000000000000023501234315411400342470ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/list/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.parallel.list; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.impl.lazy.parallel.Batch; import com.gs.collections.impl.lazy.parallel.set.UnsortedSetBatch; import com.gs.collections.impl.map.mutable.ConcurrentHashMap; @Beta public interface ListBatch extends Batch { ListBatch select(Predicate predicate); ListBatch collect(Function function); UnsortedSetBatch distinct(ConcurrentHashMap distinct); } ParallelCollectListIterable.java000066400000000000000000000054321234315411400377440ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/list/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.parallel.list; import java.util.concurrent.ExecutorService; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.impl.block.factory.Functions; import com.gs.collections.impl.block.factory.Predicates; @Beta class ParallelCollectListIterable extends AbstractParallelListIterable> { private final AbstractParallelListIterable> parallelIterable; private final Function function; ParallelCollectListIterable(AbstractParallelListIterable> parallelIterable, Function function) { this.parallelIterable = parallelIterable; this.function = function; } @Override public ExecutorService getExecutorService() { return this.parallelIterable.getExecutorService(); } @Override public LazyIterable> split() { return this.parallelIterable.split().collect(new Function, ListBatch>() { public ListBatch valueOf(ListBatch eachBatch) { return eachBatch.collect(ParallelCollectListIterable.this.function); } }); } public void forEach(Procedure procedure) { this.parallelIterable.forEach(Functions.bind(procedure, this.function)); } public boolean anySatisfy(Predicate predicate) { return this.parallelIterable.anySatisfy(Predicates.attributePredicate(this.function, predicate)); } public boolean allSatisfy(Predicate predicate) { return this.parallelIterable.allSatisfy(Predicates.attributePredicate(this.function, predicate)); } public V detect(Predicate predicate) { T resultItem = this.parallelIterable.detect(Predicates.attributePredicate(this.function, predicate)); return resultItem == null ? null : this.function.valueOf(resultItem); } } ParallelListDistinctIterable.java000066400000000000000000000107371234315411400401440ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/list/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.parallel.list; import java.util.concurrent.ExecutorService; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.set.ParallelUnsortedSetIterable; import com.gs.collections.impl.lazy.parallel.set.AbstractParallelUnsortedSetIterable; import com.gs.collections.impl.lazy.parallel.set.UnsortedSetBatch; import com.gs.collections.impl.map.mutable.ConcurrentHashMap; @Beta class ParallelListDistinctIterable extends AbstractParallelUnsortedSetIterable> { private final AbstractParallelListIterable> parallelIterable; ParallelListDistinctIterable(AbstractParallelListIterable> parallelIterable) { this.parallelIterable = parallelIterable; } @Override public ExecutorService getExecutorService() { return this.parallelIterable.getExecutorService(); } @Override public LazyIterable> split() { // TODO: Replace the map with a concurrent set once it's implemented final ConcurrentHashMap distinct = new ConcurrentHashMap(); return this.parallelIterable.split().collect(new Function, UnsortedSetBatch>() { public UnsortedSetBatch valueOf(ListBatch listBatch) { return listBatch.distinct(distinct); } }); } @Override public ParallelUnsortedSetIterable asUnique() { return this; } public void forEach(final Procedure procedure) { // TODO: Replace the map with a concurrent set once it's implemented final ConcurrentHashMap distinct = new ConcurrentHashMap(); this.parallelIterable.forEach(new Procedure() { public void value(T each) { if (distinct.put(each, true) == null) { procedure.value(each); } } }); } public boolean anySatisfy(Predicate predicate) { return this.parallelIterable.anySatisfy(new DistinctAndPredicate(predicate)); } public boolean allSatisfy(Predicate predicate) { return this.parallelIterable.allSatisfy(new DistinctOrPredicate(predicate)); } public T detect(Predicate predicate) { return this.parallelIterable.detect(new DistinctAndPredicate(predicate)); } private static final class DistinctAndPredicate implements Predicate { // TODO: Replace the map with a concurrent set once it's implemented private final ConcurrentHashMap distinct = new ConcurrentHashMap(); private final Predicate predicate; private DistinctAndPredicate(Predicate predicate) { this.predicate = predicate; } public boolean accept(T each) { return this.distinct.put(each, true) == null && this.predicate.accept(each); } } private static final class DistinctOrPredicate implements Predicate { // TODO: Replace the map with a concurrent set once it's implemented private final ConcurrentHashMap distinct = new ConcurrentHashMap(); private final Predicate predicate; private DistinctOrPredicate(Predicate predicate) { this.predicate = predicate; } public boolean accept(T each) { return this.distinct.put(each, true) == null || this.predicate.accept(each); } } } ParallelSelectListIterable.java000066400000000000000000000063021234315411400375730ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/list/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.parallel.list; import java.util.concurrent.ExecutorService; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.impl.block.factory.Predicates; import com.gs.collections.impl.block.procedure.IfProcedure; @Beta class ParallelSelectListIterable extends AbstractParallelListIterable> { private final AbstractParallelListIterable> parallelIterable; private final Predicate predicate; ParallelSelectListIterable(AbstractParallelListIterable> parallelIterable, Predicate predicate) { this.parallelIterable = parallelIterable; this.predicate = predicate; } @Override public ExecutorService getExecutorService() { return this.parallelIterable.getExecutorService(); } @Override public LazyIterable> split() { return this.parallelIterable.split().collect(new Function, ListBatch>() { public ListBatch valueOf(ListBatch eachBatch) { return eachBatch.select(ParallelSelectListIterable.this.predicate); } }); } public void forEach(Procedure procedure) { this.parallelIterable.forEach(new IfProcedure(this.predicate, procedure)); } public boolean anySatisfy(Predicate predicate) { return this.parallelIterable.anySatisfy(Predicates.and(this.predicate, predicate)); } public boolean allSatisfy(Predicate predicate) { return this.parallelIterable.allSatisfy(new SelectAllSatisfyPredicate(this.predicate, predicate)); } public T detect(Predicate predicate) { return this.parallelIterable.detect(Predicates.and(this.predicate, predicate)); } private static final class SelectAllSatisfyPredicate implements Predicate { private final Predicate left; private final Predicate right; private SelectAllSatisfyPredicate(Predicate left, Predicate right) { this.left = left; this.right = right; } public boolean accept(T each) { boolean leftResult = this.left.accept(each); return !leftResult || this.right.accept(each); } } } RootListBatch.java000066400000000000000000000015031234315411400351120ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/list/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.parallel.list; import com.gs.collections.api.annotation.Beta; import com.gs.collections.impl.lazy.parallel.RootBatch; @Beta public interface RootListBatch extends ListBatch, RootBatch { } SelectListBatch.java000066400000000000000000000042721234315411400354140ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/list/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.parallel.list; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.impl.block.procedure.IfProcedure; import com.gs.collections.impl.lazy.parallel.AbstractBatch; import com.gs.collections.impl.lazy.parallel.set.UnsortedSetBatch; import com.gs.collections.impl.map.mutable.ConcurrentHashMap; @Beta public class SelectListBatch extends AbstractBatch implements ListBatch { private final ListBatch listBatch; private final Predicate predicate; public SelectListBatch(ListBatch listBatch, Predicate predicate) { this.listBatch = listBatch; this.predicate = predicate; } public void forEach(Procedure procedure) { this.listBatch.forEach(new IfProcedure(this.predicate, procedure)); } /* public ListBatch select(Predicate predicate) { return new SelectListBatch(this.listBatch, Predicates.and(this.predicate, predicate)); } */ public ListBatch select(Predicate predicate) { return new SelectListBatch(this, predicate); } public ListBatch collect(Function function) { return new CollectListBatch(this, function); } public UnsortedSetBatch distinct(ConcurrentHashMap distinct) { return new DistinctBatch(this, distinct); } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/set/000077500000000000000000000000001234315411400314265ustar00rootroot00000000000000AbstractParallelUnsortedSetIterable.java000066400000000000000000000112551234315411400413060ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/set/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.parallel.set; import com.gs.collections.api.ParallelIterable; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.map.MapIterable; import com.gs.collections.api.multimap.set.MutableSetMultimap; import com.gs.collections.api.multimap.set.UnsortedSetMultimap; import com.gs.collections.api.set.ParallelUnsortedSetIterable; import com.gs.collections.impl.block.factory.Functions; import com.gs.collections.impl.block.factory.Predicates; import com.gs.collections.impl.lazy.parallel.AbstractParallelIterable; import com.gs.collections.impl.multimap.set.SynchronizedPutUnifiedSetMultimap; @Beta public abstract class AbstractParallelUnsortedSetIterable> extends AbstractParallelIterable implements ParallelUnsortedSetIterable { @Override protected boolean isOrdered() { return false; } public ParallelUnsortedSetIterable asUnique() { return this; } public ParallelUnsortedSetIterable select(Predicate predicate) { return new ParallelSelectUnsortedSetIterable(this, predicate); } public

ParallelUnsortedSetIterable selectWith(Predicate2 predicate, P parameter) { return this.select(Predicates.bind(predicate, parameter)); } public ParallelUnsortedSetIterable selectInstancesOf(Class clazz) { return (ParallelUnsortedSetIterable) this.select(Predicates.instanceOf(clazz)); } public ParallelUnsortedSetIterable reject(Predicate predicate) { return this.select(Predicates.not(predicate)); } public

ParallelUnsortedSetIterable rejectWith(Predicate2 predicate, P parameter) { return this.reject(Predicates.bind(predicate, parameter)); } public ParallelIterable collect(Function function) { return new ParallelCollectIterable(this, function); } public ParallelIterable collectWith(Function2 function, P parameter) { return this.collect(Functions.bind(function, parameter)); } public ParallelIterable collectIf(Predicate predicate, Function function) { return this.select(predicate).collect(function); } public ParallelIterable flatCollect(Function> function) { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".flatCollect() not implemented yet"); } public UnsortedSetMultimap groupBy(final Function function) { final MutableSetMultimap result = SynchronizedPutUnifiedSetMultimap.newMultimap(); this.forEach(new Procedure() { public void value(T each) { V key = function.valueOf(each); result.put(key, each); } }); return result; } public UnsortedSetMultimap groupByEach(final Function> function) { final MutableSetMultimap result = SynchronizedPutUnifiedSetMultimap.newMultimap(); this.forEach(new Procedure() { public void value(T each) { Iterable keys = function.valueOf(each); for (V key : keys) { result.put(key, each); } } }); return result; } public MapIterable groupByUniqueKey(Function function) { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".groupByUniqueKey() not implemented yet"); } } CollectUnsortedSetBatch.java000066400000000000000000000040601234315411400367410ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/set/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.parallel.set; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.impl.block.factory.Functions; import com.gs.collections.impl.lazy.parallel.AbstractBatch; @Beta public class CollectUnsortedSetBatch extends AbstractBatch implements UnsortedSetBatch { private final UnsortedSetBatch unsortedSetBatch; private final Function function; public CollectUnsortedSetBatch(UnsortedSetBatch unsortedSetBatch, Function function) { this.unsortedSetBatch = unsortedSetBatch; this.function = function; } public void forEach(Procedure procedure) { this.unsortedSetBatch.forEach(Functions.bind(procedure, this.function)); } /* public SetBatch collect(Function function) { return new CollectSetBatch(this.setBatch, Functions.chain(this.function, function)); } */ public UnsortedSetBatch select(Predicate predicate) { return new SelectUnsortedSetBatch(this, predicate); } public UnsortedSetBatch collect(Function function) { return new CollectUnsortedSetBatch(this, function); } } ParallelCollectIterable.java000066400000000000000000000056711234315411400367350ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/set/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.parallel.set; import java.util.concurrent.ExecutorService; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.impl.block.factory.Functions; import com.gs.collections.impl.block.factory.Predicates; import com.gs.collections.impl.lazy.parallel.AbstractParallelIterable; import com.gs.collections.impl.lazy.parallel.AbstractParallelIterableImpl; import com.gs.collections.impl.lazy.parallel.Batch; @Beta public class ParallelCollectIterable extends AbstractParallelIterableImpl> { private final AbstractParallelIterable> parallelIterable; private final Function function; public ParallelCollectIterable(AbstractParallelIterable> parallelIterable, Function function) { this.parallelIterable = parallelIterable; this.function = function; } @Override public ExecutorService getExecutorService() { return this.parallelIterable.getExecutorService(); } @Override public LazyIterable> split() { return this.parallelIterable.split().collect(new Function, Batch>() { public Batch valueOf(Batch eachBatch) { return eachBatch.collect(ParallelCollectIterable.this.function); } }); } public void forEach(Procedure procedure) { this.parallelIterable.forEach(Functions.bind(procedure, this.function)); } public boolean anySatisfy(Predicate predicate) { return this.parallelIterable.anySatisfy(Predicates.attributePredicate(this.function, predicate)); } public boolean allSatisfy(Predicate predicate) { return this.parallelIterable.allSatisfy(Predicates.attributePredicate(this.function, predicate)); } public V detect(Predicate predicate) { T resultItem = this.parallelIterable.detect(Predicates.attributePredicate(this.function, predicate)); return resultItem == null ? null : this.function.valueOf(resultItem); } } ParallelSelectUnsortedSetIterable.java000066400000000000000000000064431234315411400407650ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/set/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.parallel.set; import java.util.concurrent.ExecutorService; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.impl.block.factory.Predicates; import com.gs.collections.impl.block.procedure.IfProcedure; @Beta class ParallelSelectUnsortedSetIterable extends AbstractParallelUnsortedSetIterable> { private final AbstractParallelUnsortedSetIterable> parallelIterable; private final Predicate predicate; ParallelSelectUnsortedSetIterable(AbstractParallelUnsortedSetIterable> parallelIterable, Predicate predicate) { this.parallelIterable = parallelIterable; this.predicate = predicate; } @Override public ExecutorService getExecutorService() { return this.parallelIterable.getExecutorService(); } @Override public LazyIterable> split() { return this.parallelIterable.split().collect(new Function, UnsortedSetBatch>() { public UnsortedSetBatch valueOf(UnsortedSetBatch eachBatch) { return eachBatch.select(ParallelSelectUnsortedSetIterable.this.predicate); } }); } public void forEach(Procedure procedure) { this.parallelIterable.forEach(new IfProcedure(this.predicate, procedure)); } public boolean anySatisfy(Predicate predicate) { return this.parallelIterable.anySatisfy(Predicates.and(this.predicate, predicate)); } public boolean allSatisfy(Predicate predicate) { return this.parallelIterable.allSatisfy(new SelectAllSatisfyPredicate(this.predicate, predicate)); } public T detect(Predicate predicate) { return this.parallelIterable.detect(Predicates.and(this.predicate, predicate)); } private static final class SelectAllSatisfyPredicate implements Predicate { private final Predicate left; private final Predicate right; private SelectAllSatisfyPredicate(Predicate left, Predicate right) { this.left = left; this.right = right; } public boolean accept(T each) { boolean leftResult = this.left.accept(each); return !leftResult || this.right.accept(each); } } } RootUnsortedSetBatch.java000066400000000000000000000015201234315411400362750ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/set/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.parallel.set; import com.gs.collections.api.annotation.Beta; import com.gs.collections.impl.lazy.parallel.RootBatch; @Beta public interface RootUnsortedSetBatch extends UnsortedSetBatch, RootBatch { } SelectUnsortedSetBatch.java000066400000000000000000000040051234315411400365720ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/set/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.parallel.set; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.impl.block.procedure.IfProcedure; import com.gs.collections.impl.lazy.parallel.AbstractBatch; @Beta public class SelectUnsortedSetBatch extends AbstractBatch implements UnsortedSetBatch { private final UnsortedSetBatch unsortedSetBatch; private final Predicate predicate; public SelectUnsortedSetBatch(UnsortedSetBatch unsortedSetBatch, Predicate predicate) { this.unsortedSetBatch = unsortedSetBatch; this.predicate = predicate; } public void forEach(Procedure procedure) { this.unsortedSetBatch.forEach(new IfProcedure(this.predicate, procedure)); } /* public SetBatch select(Predicate predicate) { return new SelectSetBatch(this.setBatch, Predicates.and(this.predicate, predicate)); } */ public UnsortedSetBatch select(Predicate predicate) { return new SelectUnsortedSetBatch(this, predicate); } public UnsortedSetBatch collect(Function function) { return new CollectUnsortedSetBatch(this, function); } } UnsortedSetBatch.java000066400000000000000000000016501234315411400354350ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/parallel/set/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.parallel.set; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.impl.lazy.parallel.Batch; @Beta public interface UnsortedSetBatch extends Batch { UnsortedSetBatch select(Predicate predicate); } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/primitive/000077500000000000000000000000001234315411400310475ustar00rootroot00000000000000CollectBooleanIterable.java000066400000000000000000000140441234315411400361730ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/primitive/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.primitive; import java.util.Iterator; import com.gs.collections.api.BooleanIterable; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.bag.primitive.MutableBooleanBag; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.primitive.BooleanPredicate; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.BooleanProcedure; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.iterator.BooleanIterator; import com.gs.collections.api.list.primitive.MutableBooleanList; import com.gs.collections.api.set.primitive.MutableBooleanSet; import com.gs.collections.impl.bag.mutable.primitive.BooleanHashBag; import com.gs.collections.impl.list.mutable.primitive.BooleanArrayList; import com.gs.collections.impl.set.mutable.primitive.BooleanHashSet; import net.jcip.annotations.Immutable; /** * A CollectIntIterable is an iterable that transforms a source iterable using an IntFunction as it iterates. */ @Immutable public class CollectBooleanIterable extends AbstractLazyBooleanIterable { private final LazyIterable iterable; private final BooleanFunction function; private final BooleanFunctionToProcedure booleanFunctionToProcedure = new BooleanFunctionToProcedure(); public CollectBooleanIterable(LazyIterable adapted, BooleanFunction function) { this.iterable = adapted; this.function = function; } public BooleanIterator booleanIterator() { return new BooleanIterator() { private final Iterator iterator = CollectBooleanIterable.this.iterable.iterator(); public boolean next() { return CollectBooleanIterable.this.function.booleanValueOf(this.iterator.next()); } public boolean hasNext() { return this.iterator.hasNext(); } }; } public void forEach(BooleanProcedure procedure) { this.iterable.forEachWith(this.booleanFunctionToProcedure, procedure); } @Override public int size() { return this.iterable.size(); } @Override public boolean isEmpty() { return this.iterable.isEmpty(); } @Override public boolean notEmpty() { return this.iterable.notEmpty(); } @Override public int count(final BooleanPredicate predicate) { return this.iterable.count(new Predicate() { public boolean accept(T each) { return predicate.accept(CollectBooleanIterable.this.function.booleanValueOf(each)); } }); } @Override public boolean anySatisfy(final BooleanPredicate predicate) { return this.iterable.anySatisfy(new Predicate() { public boolean accept(T each) { return predicate.accept(CollectBooleanIterable.this.function.booleanValueOf(each)); } }); } @Override public boolean allSatisfy(final BooleanPredicate predicate) { return this.iterable.allSatisfy(new Predicate() { public boolean accept(T each) { return predicate.accept(CollectBooleanIterable.this.function.booleanValueOf(each)); } }); } @Override public boolean noneSatisfy(final BooleanPredicate predicate) { return this.iterable.allSatisfy(new Predicate() { public boolean accept(T each) { return !predicate.accept(CollectBooleanIterable.this.function.booleanValueOf(each)); } }); } @Override public boolean[] toArray() { final boolean[] array = new boolean[this.size()]; this.iterable.forEachWithIndex(new ObjectIntProcedure() { public void value(T each, int index) { array[index] = CollectBooleanIterable.this.function.booleanValueOf(each); } }); return array; } @Override public MutableBooleanList toList() { return BooleanArrayList.newList(this); } @Override public MutableBooleanSet toSet() { return BooleanHashSet.newSet(this); } @Override public MutableBooleanBag toBag() { return BooleanHashBag.newBag(this); } @Override public boolean containsAll(boolean... source) { for (boolean value : source) { if (!this.contains(value)) { return false; } } return true; } @Override public boolean containsAll(BooleanIterable source) { for (BooleanIterator iterator = source.booleanIterator(); iterator.hasNext(); ) { if (!this.contains(iterator.next())) { return false; } } return true; } private final class BooleanFunctionToProcedure implements Procedure2 { private static final long serialVersionUID = -4133872659735979655L; public void value(T each, BooleanProcedure parm) { parm.value(CollectBooleanIterable.this.function.booleanValueOf(each)); } } } CollectBooleanToObjectIterable.java000066400000000000000000000070151234315411400376250ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/primitive/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.primitive; import java.util.Iterator; import com.gs.collections.api.BooleanIterable; import com.gs.collections.api.block.function.primitive.BooleanToObjectFunction; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.BooleanProcedure; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.iterator.BooleanIterator; import com.gs.collections.impl.lazy.AbstractLazyIterable; public class CollectBooleanToObjectIterable extends AbstractLazyIterable { private final BooleanIterable iterable; private final BooleanToObjectFunction function; public CollectBooleanToObjectIterable(BooleanIterable iterable, BooleanToObjectFunction function) { this.iterable = iterable; this.function = function; } public void forEach(final Procedure procedure) { this.iterable.forEach(new BooleanProcedure() { public void value(boolean each) { procedure.value(CollectBooleanToObjectIterable.this.function.valueOf(each)); } }); } public void forEachWithIndex(final ObjectIntProcedure objectIntProcedure) { this.iterable.forEach(new BooleanProcedure() { private int index; public void value(boolean each) { objectIntProcedure.value(CollectBooleanToObjectIterable.this.function.valueOf(each), this.index++); } }); } public

void forEachWith(final Procedure2 procedure, final P parameter) { this.iterable.forEach(new BooleanProcedure() { public void value(boolean each) { procedure.value(CollectBooleanToObjectIterable.this.function.valueOf(each), parameter); } }); } public Iterator iterator() { return new Iterator() { private final BooleanIterator iterator = CollectBooleanToObjectIterable.this.iterable.booleanIterator(); public boolean hasNext() { return this.iterator.hasNext(); } public V next() { return CollectBooleanToObjectIterable.this.function.valueOf(this.iterator.next()); } public void remove() { throw new UnsupportedOperationException("Cannot call remove() on " + this.getClass().getSimpleName()); } }; } @Override public int size() { return this.iterable.size(); } @Override public boolean isEmpty() { return this.iterable.isEmpty(); } @Override public boolean notEmpty() { return this.iterable.notEmpty(); } } CollectByteIterable.java000066400000000000000000000142301234315411400355140ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/primitive/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.primitive; import java.util.Arrays; import java.util.Iterator; import com.gs.collections.api.ByteIterable; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.bag.primitive.MutableByteBag; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.primitive.BytePredicate; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ByteProcedure; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.iterator.ByteIterator; import com.gs.collections.api.list.primitive.MutableByteList; import com.gs.collections.api.set.primitive.MutableByteSet; import com.gs.collections.impl.bag.mutable.primitive.ByteHashBag; import com.gs.collections.impl.list.mutable.primitive.ByteArrayList; import com.gs.collections.impl.set.mutable.primitive.ByteHashSet; import net.jcip.annotations.Immutable; /** * A CollectIntIterable is an iterable that transforms a source iterable using an IntFunction as it iterates. */ @Immutable public class CollectByteIterable extends AbstractLazyByteIterable { private final LazyIterable iterable; private final ByteFunction function; private final ByteFunctionToProcedure byteFunctionToProcedure = new ByteFunctionToProcedure(); public CollectByteIterable(LazyIterable adapted, ByteFunction function) { this.iterable = adapted; this.function = function; } public ByteIterator byteIterator() { return new ByteIterator() { private final Iterator iterator = CollectByteIterable.this.iterable.iterator(); public byte next() { return CollectByteIterable.this.function.byteValueOf(this.iterator.next()); } public boolean hasNext() { return this.iterator.hasNext(); } }; } public void forEach(ByteProcedure procedure) { this.iterable.forEachWith(this.byteFunctionToProcedure, procedure); } @Override public int size() { return this.iterable.size(); } @Override public boolean isEmpty() { return this.iterable.isEmpty(); } @Override public boolean notEmpty() { return this.iterable.notEmpty(); } @Override public int count(final BytePredicate predicate) { return this.iterable.count(new Predicate() { public boolean accept(T each) { return predicate.accept(CollectByteIterable.this.function.byteValueOf(each)); } }); } @Override public boolean anySatisfy(final BytePredicate predicate) { return this.iterable.anySatisfy(new Predicate() { public boolean accept(T each) { return predicate.accept(CollectByteIterable.this.function.byteValueOf(each)); } }); } @Override public boolean allSatisfy(final BytePredicate predicate) { return this.iterable.allSatisfy(new Predicate() { public boolean accept(T each) { return predicate.accept(CollectByteIterable.this.function.byteValueOf(each)); } }); } @Override public boolean noneSatisfy(final BytePredicate predicate) { return this.iterable.allSatisfy(new Predicate() { public boolean accept(T each) { return !predicate.accept(CollectByteIterable.this.function.byteValueOf(each)); } }); } @Override public byte[] toArray() { final byte[] array = new byte[this.size()]; this.iterable.forEachWithIndex(new ObjectIntProcedure() { public void value(T each, int index) { array[index] = CollectByteIterable.this.function.byteValueOf(each); } }); return array; } @Override public byte[] toSortedArray() { byte[] array = this.toArray(); Arrays.sort(array); return array; } @Override public MutableByteList toList() { return ByteArrayList.newList(this); } @Override public MutableByteList toSortedList() { return ByteArrayList.newList(this).sortThis(); } @Override public MutableByteSet toSet() { return ByteHashSet.newSet(this); } @Override public MutableByteBag toBag() { return ByteHashBag.newBag(this); } @Override public boolean containsAll(byte... source) { for (byte value : source) { if (!this.contains(value)) { return false; } } return true; } @Override public boolean containsAll(ByteIterable source) { for (ByteIterator iterator = source.byteIterator(); iterator.hasNext(); ) { if (!this.contains(iterator.next())) { return false; } } return true; } private final class ByteFunctionToProcedure implements Procedure2 { private static final long serialVersionUID = -4133872659735979655L; public void value(T each, ByteProcedure parm) { parm.value(CollectByteIterable.this.function.byteValueOf(each)); } } } CollectByteToObjectIterable.java000066400000000000000000000067201234315411400371530ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/primitive/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.primitive; import java.util.Iterator; import com.gs.collections.api.ByteIterable; import com.gs.collections.api.block.function.primitive.ByteToObjectFunction; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ByteProcedure; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.iterator.ByteIterator; import com.gs.collections.impl.lazy.AbstractLazyIterable; public class CollectByteToObjectIterable extends AbstractLazyIterable { private final ByteIterable iterable; private final ByteToObjectFunction function; public CollectByteToObjectIterable(ByteIterable iterable, ByteToObjectFunction function) { this.iterable = iterable; this.function = function; } public void forEach(final Procedure procedure) { this.iterable.forEach(new ByteProcedure() { public void value(byte each) { procedure.value(CollectByteToObjectIterable.this.function.valueOf(each)); } }); } public void forEachWithIndex(final ObjectIntProcedure objectIntProcedure) { this.iterable.forEach(new ByteProcedure() { private int index; public void value(byte each) { objectIntProcedure.value(CollectByteToObjectIterable.this.function.valueOf(each), this.index++); } }); } public

void forEachWith(final Procedure2 procedure, final P parameter) { this.iterable.forEach(new ByteProcedure() { public void value(byte each) { procedure.value(CollectByteToObjectIterable.this.function.valueOf(each), parameter); } }); } public Iterator iterator() { return new Iterator() { private final ByteIterator iterator = CollectByteToObjectIterable.this.iterable.byteIterator(); public boolean hasNext() { return this.iterator.hasNext(); } public V next() { return CollectByteToObjectIterable.this.function.valueOf(this.iterator.next()); } public void remove() { throw new UnsupportedOperationException("Cannot call remove() on " + this.getClass().getSimpleName()); } }; } @Override public int size() { return this.iterable.size(); } @Override public boolean isEmpty() { return this.iterable.isEmpty(); } @Override public boolean notEmpty() { return this.iterable.notEmpty(); } } CollectCharIterable.java000066400000000000000000000144351234315411400354750ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/primitive/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.primitive; import java.util.Arrays; import java.util.Iterator; import com.gs.collections.api.CharIterable; import com.gs.collections.api.LazyCharIterable; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.bag.primitive.MutableCharBag; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.primitive.CharPredicate; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.CharProcedure; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.iterator.CharIterator; import com.gs.collections.api.list.primitive.MutableCharList; import com.gs.collections.api.set.primitive.MutableCharSet; import com.gs.collections.impl.bag.mutable.primitive.CharHashBag; import com.gs.collections.impl.list.mutable.primitive.CharArrayList; import com.gs.collections.impl.set.mutable.primitive.CharHashSet; import net.jcip.annotations.Immutable; /** * A CollectIntIterable is an iterable that transforms a source iterable using an IntFunction as it iterates. */ @Immutable public class CollectCharIterable extends AbstractLazyCharIterable { private final LazyIterable iterable; private final CharFunction function; private final CharFunctionToProcedure charFunctionToProcedure = new CharFunctionToProcedure(); public CollectCharIterable(LazyIterable adapted, CharFunction function) { this.iterable = adapted; this.function = function; } public CharIterator charIterator() { return new CharIterator() { private final Iterator iterator = CollectCharIterable.this.iterable.iterator(); public char next() { return CollectCharIterable.this.function.charValueOf(this.iterator.next()); } public boolean hasNext() { return this.iterator.hasNext(); } }; } public void forEach(CharProcedure procedure) { this.iterable.forEachWith(this.charFunctionToProcedure, procedure); } @Override public int size() { return this.iterable.size(); } @Override public boolean isEmpty() { return this.iterable.isEmpty(); } @Override public boolean notEmpty() { return this.iterable.notEmpty(); } @Override public int count(final CharPredicate predicate) { return this.iterable.count(new Predicate() { public boolean accept(T each) { return predicate.accept(CollectCharIterable.this.function.charValueOf(each)); } }); } @Override public boolean anySatisfy(final CharPredicate predicate) { return this.iterable.anySatisfy(new Predicate() { public boolean accept(T each) { return predicate.accept(CollectCharIterable.this.function.charValueOf(each)); } }); } @Override public boolean allSatisfy(final CharPredicate predicate) { return this.iterable.allSatisfy(new Predicate() { public boolean accept(T each) { return predicate.accept(CollectCharIterable.this.function.charValueOf(each)); } }); } @Override public boolean noneSatisfy(final CharPredicate predicate) { return this.iterable.allSatisfy(new Predicate() { public boolean accept(T each) { return !predicate.accept(CollectCharIterable.this.function.charValueOf(each)); } }); } @Override public char[] toArray() { final char[] array = new char[this.size()]; this.iterable.forEachWithIndex(new ObjectIntProcedure() { public void value(T each, int index) { array[index] = CollectCharIterable.this.function.charValueOf(each); } }); return array; } @Override public char[] toSortedArray() { char[] array = this.toArray(); Arrays.sort(array); return array; } @Override public MutableCharList toList() { return CharArrayList.newList(this); } @Override public MutableCharList toSortedList() { return CharArrayList.newList(this).sortThis(); } @Override public MutableCharSet toSet() { return CharHashSet.newSet(this); } @Override public MutableCharBag toBag() { return CharHashBag.newBag(this); } @Override public LazyCharIterable asLazy() { return this; } @Override public boolean containsAll(char... source) { for (char value : source) { if (!this.contains(value)) { return false; } } return true; } @Override public boolean containsAll(CharIterable source) { for (CharIterator iterator = source.charIterator(); iterator.hasNext(); ) { if (!this.contains(iterator.next())) { return false; } } return true; } private final class CharFunctionToProcedure implements Procedure2 { private static final long serialVersionUID = -4133872659735979655L; public void value(T each, CharProcedure parm) { parm.value(CollectCharIterable.this.function.charValueOf(each)); } } } CollectCharToObjectIterable.java000066400000000000000000000067201234315411400371250ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/primitive/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.primitive; import java.util.Iterator; import com.gs.collections.api.CharIterable; import com.gs.collections.api.block.function.primitive.CharToObjectFunction; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.CharProcedure; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.iterator.CharIterator; import com.gs.collections.impl.lazy.AbstractLazyIterable; public class CollectCharToObjectIterable extends AbstractLazyIterable { private final CharIterable iterable; private final CharToObjectFunction function; public CollectCharToObjectIterable(CharIterable iterable, CharToObjectFunction function) { this.iterable = iterable; this.function = function; } public void forEach(final Procedure procedure) { this.iterable.forEach(new CharProcedure() { public void value(char each) { procedure.value(CollectCharToObjectIterable.this.function.valueOf(each)); } }); } public void forEachWithIndex(final ObjectIntProcedure objectIntProcedure) { this.iterable.forEach(new CharProcedure() { private int index; public void value(char each) { objectIntProcedure.value(CollectCharToObjectIterable.this.function.valueOf(each), this.index++); } }); } public

void forEachWith(final Procedure2 procedure, final P parameter) { this.iterable.forEach(new CharProcedure() { public void value(char each) { procedure.value(CollectCharToObjectIterable.this.function.valueOf(each), parameter); } }); } public Iterator iterator() { return new Iterator() { private final CharIterator iterator = CollectCharToObjectIterable.this.iterable.charIterator(); public boolean hasNext() { return this.iterator.hasNext(); } public V next() { return CollectCharToObjectIterable.this.function.valueOf(this.iterator.next()); } public void remove() { throw new UnsupportedOperationException("Cannot call remove() on " + this.getClass().getSimpleName()); } }; } @Override public int size() { return this.iterable.size(); } @Override public boolean isEmpty() { return this.iterable.isEmpty(); } @Override public boolean notEmpty() { return this.iterable.notEmpty(); } } CollectDoubleIterable.java000066400000000000000000000144361234315411400360330ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/primitive/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.primitive; import java.util.Arrays; import java.util.Iterator; import com.gs.collections.api.DoubleIterable; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.bag.primitive.MutableDoubleBag; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.primitive.DoublePredicate; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.DoubleProcedure; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.iterator.DoubleIterator; import com.gs.collections.api.list.primitive.MutableDoubleList; import com.gs.collections.api.set.primitive.MutableDoubleSet; import com.gs.collections.impl.bag.mutable.primitive.DoubleHashBag; import com.gs.collections.impl.list.mutable.primitive.DoubleArrayList; import com.gs.collections.impl.set.mutable.primitive.DoubleHashSet; import net.jcip.annotations.Immutable; /** * A CollectDoubleIterable is an iterable that transforms a source iterable using a DoubleFunction as it iterates. */ @Immutable public class CollectDoubleIterable extends AbstractLazyDoubleIterable { private final LazyIterable iterable; private final DoubleFunction function; private final DoubleFunctionToProcedure doubleFunctionToProcedure = new DoubleFunctionToProcedure(); public CollectDoubleIterable(LazyIterable adapted, DoubleFunction function) { this.iterable = adapted; this.function = function; } public DoubleIterator doubleIterator() { return new DoubleIterator() { private final Iterator iterator = CollectDoubleIterable.this.iterable.iterator(); public double next() { return CollectDoubleIterable.this.function.doubleValueOf(this.iterator.next()); } public boolean hasNext() { return this.iterator.hasNext(); } }; } public void forEach(DoubleProcedure procedure) { this.iterable.forEachWith(this.doubleFunctionToProcedure, procedure); } @Override public int size() { return this.iterable.size(); } @Override public boolean isEmpty() { return this.iterable.isEmpty(); } @Override public boolean notEmpty() { return this.iterable.notEmpty(); } @Override public int count(final DoublePredicate predicate) { return this.iterable.count(new Predicate() { public boolean accept(T each) { return predicate.accept(CollectDoubleIterable.this.function.doubleValueOf(each)); } }); } @Override public boolean anySatisfy(final DoublePredicate predicate) { return this.iterable.anySatisfy(new Predicate() { public boolean accept(T each) { return predicate.accept(CollectDoubleIterable.this.function.doubleValueOf(each)); } }); } @Override public boolean allSatisfy(final DoublePredicate predicate) { return this.iterable.allSatisfy(new Predicate() { public boolean accept(T each) { return predicate.accept(CollectDoubleIterable.this.function.doubleValueOf(each)); } }); } @Override public boolean noneSatisfy(final DoublePredicate predicate) { return this.iterable.allSatisfy(new Predicate() { public boolean accept(T each) { return !predicate.accept(CollectDoubleIterable.this.function.doubleValueOf(each)); } }); } @Override public double[] toArray() { final double[] array = new double[this.size()]; this.iterable.forEachWithIndex(new ObjectIntProcedure() { public void value(T each, int index) { array[index] = CollectDoubleIterable.this.function.doubleValueOf(each); } }); return array; } @Override public double[] toSortedArray() { double[] array = this.toArray(); Arrays.sort(array); return array; } @Override public MutableDoubleList toList() { return DoubleArrayList.newList(this); } @Override public MutableDoubleList toSortedList() { return DoubleArrayList.newList(this).sortThis(); } @Override public MutableDoubleSet toSet() { return DoubleHashSet.newSet(this); } @Override public MutableDoubleBag toBag() { return DoubleHashBag.newBag(this); } @Override public boolean containsAll(double... source) { for (double value : source) { if (!this.contains(value)) { return false; } } return true; } @Override public boolean containsAll(DoubleIterable source) { for (DoubleIterator iterator = source.doubleIterator(); iterator.hasNext(); ) { if (!this.contains(iterator.next())) { return false; } } return true; } private final class DoubleFunctionToProcedure implements Procedure2 { private static final long serialVersionUID = 8449781737918512474L; public void value(T each, DoubleProcedure parm) { parm.value(CollectDoubleIterable.this.function.doubleValueOf(each)); } } } CollectDoubleToObjectIterable.java000066400000000000000000000067761234315411400374750ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/primitive/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.primitive; import java.util.Iterator; import com.gs.collections.api.DoubleIterable; import com.gs.collections.api.block.function.primitive.DoubleToObjectFunction; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.DoubleProcedure; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.iterator.DoubleIterator; import com.gs.collections.impl.lazy.AbstractLazyIterable; public class CollectDoubleToObjectIterable extends AbstractLazyIterable { private final DoubleIterable iterable; private final DoubleToObjectFunction function; public CollectDoubleToObjectIterable(DoubleIterable iterable, DoubleToObjectFunction function) { this.iterable = iterable; this.function = function; } public void forEach(final Procedure procedure) { this.iterable.forEach(new DoubleProcedure() { public void value(double each) { procedure.value(CollectDoubleToObjectIterable.this.function.valueOf(each)); } }); } public void forEachWithIndex(final ObjectIntProcedure objectIntProcedure) { this.iterable.forEach(new DoubleProcedure() { private int index; public void value(double each) { objectIntProcedure.value(CollectDoubleToObjectIterable.this.function.valueOf(each), this.index++); } }); } public

void forEachWith(final Procedure2 procedure, final P parameter) { this.iterable.forEach(new DoubleProcedure() { public void value(double each) { procedure.value(CollectDoubleToObjectIterable.this.function.valueOf(each), parameter); } }); } public Iterator iterator() { return new Iterator() { private final DoubleIterator iterator = CollectDoubleToObjectIterable.this.iterable.doubleIterator(); public boolean hasNext() { return this.iterator.hasNext(); } public V next() { return CollectDoubleToObjectIterable.this.function.valueOf(this.iterator.next()); } public void remove() { throw new UnsupportedOperationException("Cannot call remove() on " + this.getClass().getSimpleName()); } }; } @Override public int size() { return this.iterable.size(); } @Override public boolean isEmpty() { return this.iterable.isEmpty(); } @Override public boolean notEmpty() { return this.iterable.notEmpty(); } } CollectFloatIterable.java000066400000000000000000000143331234315411400356620ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/primitive/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.primitive; import java.util.Arrays; import java.util.Iterator; import com.gs.collections.api.FloatIterable; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.bag.primitive.MutableFloatBag; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.primitive.FloatPredicate; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.FloatProcedure; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.iterator.FloatIterator; import com.gs.collections.api.list.primitive.MutableFloatList; import com.gs.collections.api.set.primitive.MutableFloatSet; import com.gs.collections.impl.bag.mutable.primitive.FloatHashBag; import com.gs.collections.impl.list.mutable.primitive.FloatArrayList; import com.gs.collections.impl.set.mutable.primitive.FloatHashSet; import net.jcip.annotations.Immutable; /** * A CollectFloatIterable is an iterable that transforms a source iterable using a FloatFunction as it iterates. */ @Immutable public class CollectFloatIterable extends AbstractLazyFloatIterable { private final LazyIterable iterable; private final FloatFunction function; private final FloatFunctionToProcedure floatFunctionToProcedure = new FloatFunctionToProcedure(); public CollectFloatIterable(LazyIterable adapted, FloatFunction function) { this.iterable = adapted; this.function = function; } public FloatIterator floatIterator() { return new FloatIterator() { private final Iterator iterator = CollectFloatIterable.this.iterable.iterator(); public float next() { return CollectFloatIterable.this.function.floatValueOf(this.iterator.next()); } public boolean hasNext() { return this.iterator.hasNext(); } }; } public void forEach(FloatProcedure procedure) { this.iterable.forEachWith(this.floatFunctionToProcedure, procedure); } @Override public int size() { return this.iterable.size(); } @Override public boolean isEmpty() { return this.iterable.isEmpty(); } @Override public boolean notEmpty() { return this.iterable.notEmpty(); } @Override public int count(final FloatPredicate predicate) { return this.iterable.count(new Predicate() { public boolean accept(T each) { return predicate.accept(CollectFloatIterable.this.function.floatValueOf(each)); } }); } @Override public boolean anySatisfy(final FloatPredicate predicate) { return this.iterable.anySatisfy(new Predicate() { public boolean accept(T each) { return predicate.accept(CollectFloatIterable.this.function.floatValueOf(each)); } }); } @Override public boolean allSatisfy(final FloatPredicate predicate) { return this.iterable.allSatisfy(new Predicate() { public boolean accept(T each) { return predicate.accept(CollectFloatIterable.this.function.floatValueOf(each)); } }); } @Override public boolean noneSatisfy(final FloatPredicate predicate) { return this.iterable.allSatisfy(new Predicate() { public boolean accept(T each) { return !predicate.accept(CollectFloatIterable.this.function.floatValueOf(each)); } }); } @Override public float[] toArray() { final float[] array = new float[this.size()]; this.iterable.forEachWithIndex(new ObjectIntProcedure() { public void value(T each, int index) { array[index] = CollectFloatIterable.this.function.floatValueOf(each); } }); return array; } @Override public float[] toSortedArray() { float[] array = this.toArray(); Arrays.sort(array); return array; } @Override public MutableFloatList toList() { return FloatArrayList.newList(this); } @Override public MutableFloatList toSortedList() { return FloatArrayList.newList(this).sortThis(); } @Override public MutableFloatSet toSet() { return FloatHashSet.newSet(this); } @Override public MutableFloatBag toBag() { return FloatHashBag.newBag(this); } @Override public boolean containsAll(float... source) { for (float value : source) { if (!this.contains(value)) { return false; } } return true; } @Override public boolean containsAll(FloatIterable source) { for (FloatIterator iterator = source.floatIterator(); iterator.hasNext(); ) { if (!this.contains(iterator.next())) { return false; } } return true; } private final class FloatFunctionToProcedure implements Procedure2 { private static final long serialVersionUID = 5812943420002956844L; public void value(T each, FloatProcedure parm) { parm.value(CollectFloatIterable.this.function.floatValueOf(each)); } } } CollectFloatToObjectIterable.java000066400000000000000000000067471234315411400373260ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/primitive/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.primitive; import java.util.Iterator; import com.gs.collections.api.FloatIterable; import com.gs.collections.api.block.function.primitive.FloatToObjectFunction; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.FloatProcedure; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.iterator.FloatIterator; import com.gs.collections.impl.lazy.AbstractLazyIterable; public class CollectFloatToObjectIterable extends AbstractLazyIterable { private final FloatIterable iterable; private final FloatToObjectFunction function; public CollectFloatToObjectIterable(FloatIterable iterable, FloatToObjectFunction function) { this.iterable = iterable; this.function = function; } public void forEach(final Procedure procedure) { this.iterable.forEach(new FloatProcedure() { public void value(float each) { procedure.value(CollectFloatToObjectIterable.this.function.valueOf(each)); } }); } public void forEachWithIndex(final ObjectIntProcedure objectIntProcedure) { this.iterable.forEach(new FloatProcedure() { private int index; public void value(float each) { objectIntProcedure.value(CollectFloatToObjectIterable.this.function.valueOf(each), this.index++); } }); } public

void forEachWith(final Procedure2 procedure, final P parameter) { this.iterable.forEach(new FloatProcedure() { public void value(float each) { procedure.value(CollectFloatToObjectIterable.this.function.valueOf(each), parameter); } }); } public Iterator iterator() { return new Iterator() { private final FloatIterator iterator = CollectFloatToObjectIterable.this.iterable.floatIterator(); public boolean hasNext() { return this.iterator.hasNext(); } public V next() { return CollectFloatToObjectIterable.this.function.valueOf(this.iterator.next()); } public void remove() { throw new UnsupportedOperationException("Cannot call remove() on " + this.getClass().getSimpleName()); } }; } @Override public int size() { return this.iterable.size(); } @Override public boolean isEmpty() { return this.iterable.isEmpty(); } @Override public boolean notEmpty() { return this.iterable.notEmpty(); } } CollectIntIterable.java000066400000000000000000000141171234315411400353470ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/primitive/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.primitive; import java.util.Arrays; import java.util.Iterator; import com.gs.collections.api.IntIterable; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.bag.primitive.MutableIntBag; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.primitive.IntPredicate; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.IntProcedure; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.iterator.IntIterator; import com.gs.collections.api.list.primitive.MutableIntList; import com.gs.collections.api.set.primitive.MutableIntSet; import com.gs.collections.impl.bag.mutable.primitive.IntHashBag; import com.gs.collections.impl.list.mutable.primitive.IntArrayList; import com.gs.collections.impl.set.mutable.primitive.IntHashSet; import net.jcip.annotations.Immutable; /** * A CollectIntIterable is an iterable that transforms a source iterable using an IntFunction as it iterates. */ @Immutable public class CollectIntIterable extends AbstractLazyIntIterable { private final LazyIterable iterable; private final IntFunction function; private final IntFunctionToProcedure intFunctionToProcedure = new IntFunctionToProcedure(); public CollectIntIterable(LazyIterable adapted, IntFunction function) { this.iterable = adapted; this.function = function; } public IntIterator intIterator() { return new IntIterator() { private final Iterator iterator = CollectIntIterable.this.iterable.iterator(); public int next() { return CollectIntIterable.this.function.intValueOf(this.iterator.next()); } public boolean hasNext() { return this.iterator.hasNext(); } }; } public void forEach(IntProcedure procedure) { this.iterable.forEachWith(this.intFunctionToProcedure, procedure); } @Override public int size() { return this.iterable.size(); } @Override public boolean isEmpty() { return this.iterable.isEmpty(); } @Override public boolean notEmpty() { return this.iterable.notEmpty(); } @Override public int count(final IntPredicate predicate) { return this.iterable.count(new Predicate() { public boolean accept(T each) { return predicate.accept(CollectIntIterable.this.function.intValueOf(each)); } }); } @Override public boolean anySatisfy(final IntPredicate predicate) { return this.iterable.anySatisfy(new Predicate() { public boolean accept(T each) { return predicate.accept(CollectIntIterable.this.function.intValueOf(each)); } }); } @Override public boolean allSatisfy(final IntPredicate predicate) { return this.iterable.allSatisfy(new Predicate() { public boolean accept(T each) { return predicate.accept(CollectIntIterable.this.function.intValueOf(each)); } }); } @Override public boolean noneSatisfy(final IntPredicate predicate) { return this.iterable.allSatisfy(new Predicate() { public boolean accept(T each) { return !predicate.accept(CollectIntIterable.this.function.intValueOf(each)); } }); } @Override public int[] toArray() { final int[] array = new int[this.size()]; this.iterable.forEachWithIndex(new ObjectIntProcedure() { public void value(T each, int index) { array[index] = CollectIntIterable.this.function.intValueOf(each); } }); return array; } @Override public int[] toSortedArray() { int[] array = this.toArray(); Arrays.sort(array); return array; } @Override public MutableIntList toList() { return IntArrayList.newList(this); } @Override public MutableIntList toSortedList() { return IntArrayList.newList(this).sortThis(); } @Override public MutableIntSet toSet() { return IntHashSet.newSet(this); } @Override public MutableIntBag toBag() { return IntHashBag.newBag(this); } @Override public boolean containsAll(int... source) { for (int value : source) { if (!this.contains(value)) { return false; } } return true; } @Override public boolean containsAll(IntIterable source) { for (IntIterator iterator = source.intIterator(); iterator.hasNext(); ) { if (!this.contains(iterator.next())) { return false; } } return true; } private final class IntFunctionToProcedure implements Procedure2 { private static final long serialVersionUID = -4133872659735979655L; public void value(T each, IntProcedure parm) { parm.value(CollectIntIterable.this.function.intValueOf(each)); } } } CollectIntToObjectIterable.java000066400000000000000000000066711234315411400370070ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/primitive/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.primitive; import java.util.Iterator; import com.gs.collections.api.IntIterable; import com.gs.collections.api.block.function.primitive.IntToObjectFunction; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.IntProcedure; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.iterator.IntIterator; import com.gs.collections.impl.lazy.AbstractLazyIterable; public class CollectIntToObjectIterable extends AbstractLazyIterable { private final IntIterable iterable; private final IntToObjectFunction function; public CollectIntToObjectIterable(IntIterable iterable, IntToObjectFunction function) { this.iterable = iterable; this.function = function; } public void forEach(final Procedure procedure) { this.iterable.forEach(new IntProcedure() { public void value(int each) { procedure.value(CollectIntToObjectIterable.this.function.valueOf(each)); } }); } public void forEachWithIndex(final ObjectIntProcedure objectIntProcedure) { this.iterable.forEach(new IntProcedure() { private int index; public void value(int each) { objectIntProcedure.value(CollectIntToObjectIterable.this.function.valueOf(each), this.index++); } }); } public

void forEachWith(final Procedure2 procedure, final P parameter) { this.iterable.forEach(new IntProcedure() { public void value(int each) { procedure.value(CollectIntToObjectIterable.this.function.valueOf(each), parameter); } }); } public Iterator iterator() { return new Iterator() { private final IntIterator iterator = CollectIntToObjectIterable.this.iterable.intIterator(); public boolean hasNext() { return this.iterator.hasNext(); } public V next() { return CollectIntToObjectIterable.this.function.valueOf(this.iterator.next()); } public void remove() { throw new UnsupportedOperationException("Cannot call remove() on " + this.getClass().getSimpleName()); } }; } @Override public int size() { return this.iterable.size(); } @Override public boolean isEmpty() { return this.iterable.isEmpty(); } @Override public boolean notEmpty() { return this.iterable.notEmpty(); } } CollectLongIterable.java000066400000000000000000000142271234315411400355160ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/primitive/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.primitive; import java.util.Arrays; import java.util.Iterator; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.LongIterable; import com.gs.collections.api.bag.primitive.MutableLongBag; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.primitive.LongPredicate; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.LongProcedure; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.iterator.LongIterator; import com.gs.collections.api.list.primitive.MutableLongList; import com.gs.collections.api.set.primitive.MutableLongSet; import com.gs.collections.impl.bag.mutable.primitive.LongHashBag; import com.gs.collections.impl.list.mutable.primitive.LongArrayList; import com.gs.collections.impl.set.mutable.primitive.LongHashSet; import net.jcip.annotations.Immutable; /** * A CollectLongIterable is an iterable that transforms a source iterable using an LongFunction as it iterates. */ @Immutable public class CollectLongIterable extends AbstractLazyLongIterable { private final LazyIterable iterable; private final LongFunction function; private final LongFunctionToProcedure intFunctionToProcedure = new LongFunctionToProcedure(); public CollectLongIterable(LazyIterable adapted, LongFunction function) { this.iterable = adapted; this.function = function; } public LongIterator longIterator() { return new LongIterator() { private final Iterator iterator = CollectLongIterable.this.iterable.iterator(); public long next() { return CollectLongIterable.this.function.longValueOf(this.iterator.next()); } public boolean hasNext() { return this.iterator.hasNext(); } }; } public void forEach(LongProcedure procedure) { this.iterable.forEachWith(this.intFunctionToProcedure, procedure); } @Override public int size() { return this.iterable.size(); } @Override public boolean isEmpty() { return this.iterable.isEmpty(); } @Override public boolean notEmpty() { return this.iterable.notEmpty(); } @Override public int count(final LongPredicate predicate) { return this.iterable.count(new Predicate() { public boolean accept(T each) { return predicate.accept(CollectLongIterable.this.function.longValueOf(each)); } }); } @Override public boolean anySatisfy(final LongPredicate predicate) { return this.iterable.anySatisfy(new Predicate() { public boolean accept(T each) { return predicate.accept(CollectLongIterable.this.function.longValueOf(each)); } }); } @Override public boolean allSatisfy(final LongPredicate predicate) { return this.iterable.allSatisfy(new Predicate() { public boolean accept(T each) { return predicate.accept(CollectLongIterable.this.function.longValueOf(each)); } }); } @Override public boolean noneSatisfy(final LongPredicate predicate) { return this.iterable.allSatisfy(new Predicate() { public boolean accept(T each) { return !predicate.accept(CollectLongIterable.this.function.longValueOf(each)); } }); } @Override public long[] toArray() { final long[] array = new long[this.size()]; this.iterable.forEachWithIndex(new ObjectIntProcedure() { public void value(T each, int index) { array[index] = CollectLongIterable.this.function.longValueOf(each); } }); return array; } @Override public long[] toSortedArray() { long[] array = this.toArray(); Arrays.sort(array); return array; } @Override public MutableLongList toList() { return LongArrayList.newList(this); } @Override public MutableLongList toSortedList() { return LongArrayList.newList(this).sortThis(); } @Override public MutableLongSet toSet() { return LongHashSet.newSet(this); } @Override public MutableLongBag toBag() { return LongHashBag.newBag(this); } @Override public boolean containsAll(long... source) { for (long value : source) { if (!this.contains(value)) { return false; } } return true; } @Override public boolean containsAll(LongIterable source) { for (LongIterator iterator = source.longIterator(); iterator.hasNext(); ) { if (!this.contains(iterator.next())) { return false; } } return true; } private final class LongFunctionToProcedure implements Procedure2 { private static final long serialVersionUID = 3445125933721627554L; public void value(T each, LongProcedure parm) { parm.value(CollectLongIterable.this.function.longValueOf(each)); } } } CollectLongToObjectIterable.java000066400000000000000000000067201234315411400371470ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/primitive/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.primitive; import java.util.Iterator; import com.gs.collections.api.LongIterable; import com.gs.collections.api.block.function.primitive.LongToObjectFunction; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.LongProcedure; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.iterator.LongIterator; import com.gs.collections.impl.lazy.AbstractLazyIterable; public class CollectLongToObjectIterable extends AbstractLazyIterable { private final LongIterable iterable; private final LongToObjectFunction function; public CollectLongToObjectIterable(LongIterable iterable, LongToObjectFunction function) { this.iterable = iterable; this.function = function; } public void forEach(final Procedure procedure) { this.iterable.forEach(new LongProcedure() { public void value(long each) { procedure.value(CollectLongToObjectIterable.this.function.valueOf(each)); } }); } public void forEachWithIndex(final ObjectIntProcedure objectIntProcedure) { this.iterable.forEach(new LongProcedure() { private int index; public void value(long each) { objectIntProcedure.value(CollectLongToObjectIterable.this.function.valueOf(each), this.index++); } }); } public

void forEachWith(final Procedure2 procedure, final P parameter) { this.iterable.forEach(new LongProcedure() { public void value(long each) { procedure.value(CollectLongToObjectIterable.this.function.valueOf(each), parameter); } }); } public Iterator iterator() { return new Iterator() { private final LongIterator iterator = CollectLongToObjectIterable.this.iterable.longIterator(); public boolean hasNext() { return this.iterator.hasNext(); } public V next() { return CollectLongToObjectIterable.this.function.valueOf(this.iterator.next()); } public void remove() { throw new UnsupportedOperationException("Cannot call remove() on " + this.getClass().getSimpleName()); } }; } @Override public int size() { return this.iterable.size(); } @Override public boolean isEmpty() { return this.iterable.isEmpty(); } @Override public boolean notEmpty() { return this.iterable.notEmpty(); } } CollectShortIterable.java000066400000000000000000000145401234315411400357140ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/primitive/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.primitive; import java.util.Arrays; import java.util.Iterator; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.LazyShortIterable; import com.gs.collections.api.ShortIterable; import com.gs.collections.api.bag.primitive.MutableShortBag; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.primitive.ShortPredicate; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.block.procedure.primitive.ShortProcedure; import com.gs.collections.api.iterator.ShortIterator; import com.gs.collections.api.list.primitive.MutableShortList; import com.gs.collections.api.set.primitive.MutableShortSet; import com.gs.collections.impl.bag.mutable.primitive.ShortHashBag; import com.gs.collections.impl.list.mutable.primitive.ShortArrayList; import com.gs.collections.impl.set.mutable.primitive.ShortHashSet; import net.jcip.annotations.Immutable; /** * A CollectIntIterable is an iterable that transforms a source iterable using an IntFunction as it iterates. */ @Immutable public class CollectShortIterable extends AbstractLazyShortIterable { private final LazyIterable iterable; private final ShortFunction function; private final ShortFunctionToProcedure shortFunctionToProcedure = new ShortFunctionToProcedure(); public CollectShortIterable(LazyIterable adapted, ShortFunction function) { this.iterable = adapted; this.function = function; } public ShortIterator shortIterator() { return new ShortIterator() { private final Iterator iterator = CollectShortIterable.this.iterable.iterator(); public short next() { return CollectShortIterable.this.function.shortValueOf(this.iterator.next()); } public boolean hasNext() { return this.iterator.hasNext(); } }; } public void forEach(ShortProcedure procedure) { this.iterable.forEachWith(this.shortFunctionToProcedure, procedure); } @Override public int size() { return this.iterable.size(); } @Override public boolean isEmpty() { return this.iterable.isEmpty(); } @Override public boolean notEmpty() { return this.iterable.notEmpty(); } @Override public int count(final ShortPredicate predicate) { return this.iterable.count(new Predicate() { public boolean accept(T each) { return predicate.accept(CollectShortIterable.this.function.shortValueOf(each)); } }); } @Override public boolean anySatisfy(final ShortPredicate predicate) { return this.iterable.anySatisfy(new Predicate() { public boolean accept(T each) { return predicate.accept(CollectShortIterable.this.function.shortValueOf(each)); } }); } @Override public boolean allSatisfy(final ShortPredicate predicate) { return this.iterable.allSatisfy(new Predicate() { public boolean accept(T each) { return predicate.accept(CollectShortIterable.this.function.shortValueOf(each)); } }); } @Override public boolean noneSatisfy(final ShortPredicate predicate) { return this.iterable.allSatisfy(new Predicate() { public boolean accept(T each) { return !predicate.accept(CollectShortIterable.this.function.shortValueOf(each)); } }); } @Override public short[] toArray() { final short[] array = new short[this.size()]; this.iterable.forEachWithIndex(new ObjectIntProcedure() { public void value(T each, int index) { array[index] = CollectShortIterable.this.function.shortValueOf(each); } }); return array; } @Override public short[] toSortedArray() { short[] array = this.toArray(); Arrays.sort(array); return array; } @Override public MutableShortList toList() { return ShortArrayList.newList(this); } @Override public MutableShortList toSortedList() { return ShortArrayList.newList(this).sortThis(); } @Override public MutableShortSet toSet() { return ShortHashSet.newSet(this); } @Override public MutableShortBag toBag() { return ShortHashBag.newBag(this); } @Override public LazyShortIterable asLazy() { return this; } @Override public boolean containsAll(short... source) { for (short value : source) { if (!this.contains(value)) { return false; } } return true; } @Override public boolean containsAll(ShortIterable source) { for (ShortIterator iterator = source.shortIterator(); iterator.hasNext(); ) { if (!this.contains(iterator.next())) { return false; } } return true; } private final class ShortFunctionToProcedure implements Procedure2 { private static final long serialVersionUID = -4133872659735979655L; public void value(T each, ShortProcedure parm) { parm.value(CollectShortIterable.this.function.shortValueOf(each)); } } } CollectShortToObjectIterable.java000066400000000000000000000067471234315411400373600ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/primitive/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.lazy.primitive; import java.util.Iterator; import com.gs.collections.api.ShortIterable; import com.gs.collections.api.block.function.primitive.ShortToObjectFunction; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.block.procedure.primitive.ShortProcedure; import com.gs.collections.api.iterator.ShortIterator; import com.gs.collections.impl.lazy.AbstractLazyIterable; public class CollectShortToObjectIterable extends AbstractLazyIterable { private final ShortIterable iterable; private final ShortToObjectFunction function; public CollectShortToObjectIterable(ShortIterable iterable, ShortToObjectFunction function) { this.iterable = iterable; this.function = function; } public void forEach(final Procedure procedure) { this.iterable.forEach(new ShortProcedure() { public void value(short each) { procedure.value(CollectShortToObjectIterable.this.function.valueOf(each)); } }); } public void forEachWithIndex(final ObjectIntProcedure objectIntProcedure) { this.iterable.forEach(new ShortProcedure() { private int index; public void value(short each) { objectIntProcedure.value(CollectShortToObjectIterable.this.function.valueOf(each), this.index++); } }); } public

void forEachWith(final Procedure2 procedure, final P parameter) { this.iterable.forEach(new ShortProcedure() { public void value(short each) { procedure.value(CollectShortToObjectIterable.this.function.valueOf(each), parameter); } }); } public Iterator iterator() { return new Iterator() { private final ShortIterator iterator = CollectShortToObjectIterable.this.iterable.shortIterator(); public boolean hasNext() { return this.iterator.hasNext(); } public V next() { return CollectShortToObjectIterable.this.function.valueOf(this.iterator.next()); } public void remove() { throw new UnsupportedOperationException("Cannot call remove() on " + this.getClass().getSimpleName()); } }; } @Override public int size() { return this.iterable.size(); } @Override public boolean isEmpty() { return this.iterable.isEmpty(); } @Override public boolean notEmpty() { return this.iterable.notEmpty(); } } package-info.java000066400000000000000000000013431234315411400341600ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/lazy/primitive/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains implementations of the lazy primitive iterator interfaces. */ package com.gs.collections.impl.lazy.primitive; gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/000077500000000000000000000000001234315411400270335ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/Interval.java000066400000000000000000000741121234315411400314670ustar00rootroot00000000000000/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list; import java.io.Serializable; import java.math.BigInteger; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.NoSuchElementException; import java.util.RandomAccess; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Executor; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.bag.MutableBag; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.DoubleObjectToDoubleFunction; import com.gs.collections.api.block.function.primitive.IntObjectToIntFunction; import com.gs.collections.api.block.function.primitive.LongObjectToLongFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.IntIntProcedure; import com.gs.collections.api.block.procedure.primitive.IntObjectProcedure; import com.gs.collections.api.block.procedure.primitive.IntProcedure; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.set.MutableSet; import com.gs.collections.impl.bag.mutable.HashBag; import com.gs.collections.impl.block.procedure.CollectProcedure; import com.gs.collections.impl.block.procedure.CollectionAddProcedure; import com.gs.collections.impl.block.procedure.RejectProcedure; import com.gs.collections.impl.block.procedure.SelectProcedure; import com.gs.collections.impl.factory.Lists; import com.gs.collections.impl.lazy.AbstractLazyIterable; import com.gs.collections.impl.list.mutable.FastList; import com.gs.collections.impl.list.mutable.MutableListIterator; import com.gs.collections.impl.set.mutable.UnifiedSet; /** * An Interval is a range of integers that may be iterated over using a step value. Interval * is an OO implementation of a for-loop. */ public final class Interval extends AbstractLazyIterable implements List, Serializable, RandomAccess { private static final long serialVersionUID = 1L; private final int from; private final int to; private final int step; private Interval(int from, int to, int step) { this.from = from; this.to = to; this.step = step; } /** * This static {@code from} method allows Interval to act as a fluent builder for itself. * It works in conjunction with the instance methods {@link #to(int)} and {@link #by(int)}. *

* Usage Example: *

     * Interval interval1 = Interval.from(1).to(5);         // results in: 1, 2, 3, 4, 5.
     * Interval interval2 = Interval.from(1).to(10).by(2);  // results in: 1, 3, 5, 7, 9.
     * 
*/ public static Interval from(int newFrom) { return Interval.fromToBy(newFrom, newFrom, 1); } /** * This instance {@code to} method allows Interval to act as a fluent builder for itself. * It works in conjunction with the static method {@link #from(int)} and instance method {@link #by(int)}. *

* Usage Example: *

     * Interval interval1 = Interval.from(1).to(5);         // results in: 1, 2, 3, 4, 5.
     * Interval interval2 = Interval.from(1).to(10).by(2);  // results in: 1, 3, 5, 7, 9.
     * 
*/ public Interval to(int newTo) { return Interval.fromToBy(this.from, newTo, this.step); } /** * This instance {@code by} method allows Interval to act as a fluent builder for itself. * It works in conjunction with the static method {@link #from(int)} and instance method {@link #to(int)}. *

* Usage Example: *

     * Interval interval1 = Interval.from(1).to(5);         // results in: 1, 2, 3, 4, 5.
     * Interval interval2 = Interval.from(1).to(10).by(2);  // results in: 1, 3, 5, 7, 9.
     * 
*/ public Interval by(int newStep) { return Interval.fromToBy(this.from, this.to, newStep); } /** * Returns an Interval starting at zero. *

* Usage Example: *

     * Interval interval1 = Interval.zero().to(5);         // results in: 0, 1, 2, 3, 4, 5.
     * Interval interval2 = Interval.zero().to(10).by(2);  // results in: 0, 2, 4, 6, 8, 10.
     * 
*/ public static Interval zero() { return Interval.from(0); } /** * Returns an Interval starting from 1 to the specified count value with a step value of 1. */ public static Interval oneTo(int count) { return Interval.oneToBy(count, 1); } /** * Returns an Interval starting from 1 to the specified count value with a step value of step. */ public static Interval oneToBy(int count, int step) { if (count < 1) { throw new IllegalArgumentException("Only positive ranges allowed using oneToBy"); } return Interval.fromToBy(1, count, step); } /** * Returns an Interval starting from 0 to the specified count value with a step value of 1. */ public static Interval zeroTo(int count) { return Interval.zeroToBy(count, 1); } /** * Returns an Interval starting from 0 to the specified count value with a step value of step. */ public static Interval zeroToBy(int count, int step) { return Interval.fromToBy(0, count, step); } /** * Returns an Interval starting from the value from to the specified value to with a step value of 1. */ public static Interval fromTo(int from, int to) { if (from <= to) { return Interval.fromToBy(from, to, 1); } return Interval.fromToBy(from, to, -1); } /** * Returns an Interval representing the even values from the value from to the value to. */ public static Interval evensFromTo(int from, int to) { if (from % 2 != 0) { if (from < to) { from++; } else { from--; } } if (to % 2 != 0) { if (to > from) { to--; } else { to++; } } return Interval.fromToBy(from, to, to > from ? 2 : -2); } /** * Returns an Interval representing the odd values from the value from to the value to. */ public static Interval oddsFromTo(int from, int to) { if (from % 2 == 0) { if (from < to) { from++; } else { from--; } } if (to % 2 == 0) { if (to > from) { to--; } else { to++; } } return Interval.fromToBy(from, to, to > from ? 2 : -2); } /** * Returns an Set representing the Integer values from the value from to the value to. */ public static MutableSet toSet(int from, int to) { MutableSet targetCollection = UnifiedSet.newSet(); Interval.fromTo(from, to).forEach(CollectionAddProcedure.on(targetCollection)); return targetCollection; } /** * Returns a MutableList representing the Integer values from the value from to the value to in reverse. */ public static MutableList toReverseList(int from, int to) { return Interval.fromTo(from, to).reverseThis().toList(); } /** * Returns an Integer array with the values inclusively between from and to. */ public static Integer[] toArray(int from, int to) { return Interval.fromTo(from, to).toArray(); } public static Integer[] toReverseArray(int from, int to) { return Interval.fromTo(from, to).reverseThis().toArray(); } /** * Returns an Interval for the range of integers inclusively between from and to with the specified * stepBy value. */ public static Interval fromToBy(int from, int to, int stepBy) { if (stepBy == 0) { throw new IllegalArgumentException("Cannot use a step by of 0"); } if (from > to && stepBy > 0 || from < to && stepBy < 0) { throw new IllegalArgumentException("Step by is incorrect for the range"); } return new Interval(from, to, stepBy); } /** * Returns true if the Interval contains all of the specified int values. */ public boolean containsAll(int... values) { for (int value : values) { if (!this.contains(value)) { return false; } } return true; } /** * Returns true if the Interval contains none of the specified int values. */ public boolean containsNone(int... values) { for (int value : values) { if (this.contains(value)) { return false; } } return true; } @Override public boolean contains(Object object) { return object instanceof Integer && this.contains(((Integer) object).intValue()); } /** * Returns true if the Interval contains the specified int value. */ public boolean contains(int value) { return this.isWithinBoundaries(value) && (value - this.from) % this.step == 0; } private boolean isWithinBoundaries(int value) { return this.step > 0 && this.from <= value && value <= this.to || this.step < 0 && this.to <= value && value <= this.from; } /** * Returns the Number result of calculating factorial for the range. */ public Number factorial() { this.failIfOutOfFactorialRange(); return this.from == 0 ? Integer.valueOf(1) : this.product(); } /** * Returns the Number result of calculating product for the range. */ public Number product() { return this.bigIntegerProduct(); } /** * Returns the BigInteger result of calculating product for the range. */ private BigInteger bigIntegerProduct() { return this.injectInto(BigInteger.valueOf(1L), new Function2() { public BigInteger value(BigInteger result, Integer each) { return result.multiply(BigInteger.valueOf(each.longValue())); } }); } private void failIfOutOfFactorialRange() { if (this.from < 0 || this.step != 1) { throw new IllegalStateException("Cannot calculate factorial on negative ranges"); } } public void forEachWithIndex(IntIntProcedure procedure) { int index = 0; if (this.from <= this.to) { for (int i = this.from; i <= this.to; i += this.step) { procedure.value(i, index++); } } else { for (int i = this.from; i >= this.to; i += this.step) { procedure.value(i, index++); } } } public void forEachWithIndex(final ObjectIntProcedure objectIntProcedure) { this.forEachWithIndex(new IntIntProcedure() { public void value(int each, int index) { objectIntProcedure.value(each, index); } }); } public

void forEachWith(IntObjectProcedure procedure, P parameter) { if (this.from <= this.to) { for (int i = this.from; i <= this.to; i += this.step) { procedure.value(i, parameter); } } else { for (int i = this.from; i >= this.to; i += this.step) { procedure.value(i, parameter); } } } public

void forEachWith(final Procedure2 procedure, P parameter) { this.forEachWith(new IntObjectProcedure

() { public void value(int each, P parameter) { procedure.value(each, parameter); } }, parameter); } public void forEach(IntProcedure procedure) { if (this.from <= this.to) { for (int i = this.from; i <= this.to; i += this.step) { procedure.value(i); } } else { for (int i = this.from; i >= this.to; i += this.step) { procedure.value(i); } } } public void forEach(final Procedure procedure) { this.forEach(new IntProcedure() { public void value(int each) { procedure.value(each); } }); } /** * This method executes a void procedure against an executor, passing the current index of the * interval. */ public void forEach(Procedure procedure, Executor executor) { CountDownLatch latch = new CountDownLatch(this.size()); if (this.from <= this.to) { // Iterates in forward direction because step value is negative for (int i = this.from; i <= this.to; i += this.step) { this.executeAndCountdown(procedure, executor, latch, i); } } else { // Iterates in reverse because step value is negative for (int i = this.from; i >= this.to; i += this.step) { this.executeAndCountdown(procedure, executor, latch, i); } } try { latch.await(); } catch (InterruptedException e) { // do nothing here; } } private void executeAndCountdown( final Procedure procedure, Executor executor, final CountDownLatch latch, final Integer integer) { executor.execute(new Runnable() { public void run() { try { procedure.value(integer); } finally { latch.countDown(); } } }); } /** * This method runs a runnable a specified number of times against on the current thread. */ public void run(Runnable runnable) { if (this.from <= this.to) { for (int i = this.from; i <= this.to; i += this.step) { runnable.run(); } } else { for (int i = this.from; i >= this.to; i += this.step) { runnable.run(); } } } /** * This method runs a runnable a specified number of times against an executor. The method is effectively * asynchronous because it does not wait for all of the runnables to finish. */ public void run(Runnable runnable, Executor executor) { if (this.from <= this.to) { for (int i = this.from; i <= this.to; i += this.step) { executor.execute(runnable); } } else { for (int i = this.from; i >= this.to; i += this.step) { executor.execute(runnable); } } } @Override public R injectInto(R injectValue, Function2 function) { R result = injectValue; if (this.from <= this.to) { for (int i = this.from; i <= this.to; i += this.step) { result = function.value(result, i); } } else { for (int i = this.from; i >= this.to; i += this.step) { result = function.value(result, i); } } return result; } @Override public int injectInto(int injectedValue, IntObjectToIntFunction function) { int result = injectedValue; if (this.from <= this.to) { for (int i = this.from; i <= this.to; i += this.step) { result = function.intValueOf(result, i); } } else { for (int i = this.from; i >= this.to; i += this.step) { result = function.intValueOf(result, i); } } return result; } @Override public long injectInto(long injectedValue, LongObjectToLongFunction function) { long result = injectedValue; if (this.from <= this.to) { for (int i = this.from; i <= this.to; i += this.step) { result = function.longValueOf(result, i); } } else { for (int i = this.from; i >= this.to; i += this.step) { result = function.longValueOf(result, i); } } return result; } @Override public double injectInto(double injectedValue, DoubleObjectToDoubleFunction function) { double result = injectedValue; if (this.from <= this.to) { for (int i = this.from; i <= this.to; i += this.step) { result = function.doubleValueOf(result, i); } } else { for (int i = this.from; i >= this.to; i += this.step) { result = function.doubleValueOf(result, i); } } return result; } public void reverseForEach(Procedure procedure) { this.reverseThis().forEach(procedure); } public R reverseInjectInto(R injectValue, Function2 function) { return this.reverseThis().injectInto(injectValue, function); } public > R addAllTo(R targetCollection) { this.forEach(CollectionAddProcedure.on(targetCollection)); return targetCollection; } @Override public > R collect( Function function, R target) { CollectProcedure procedure = new CollectProcedure(function, target); this.forEach(procedure); return target; } @Override public > R select(Predicate predicate, R target) { SelectProcedure procedure = new SelectProcedure(predicate, target); this.forEach(procedure); return target; } @Override public > R reject(Predicate predicate, R target) { RejectProcedure procedure = new RejectProcedure(predicate, target); this.forEach(procedure); return target; } @Override public boolean equals(Object otherList) { if (otherList == this) { return true; } if (!(otherList instanceof List)) { return false; } List list = (List) otherList; if (otherList instanceof RandomAccess) { if (this.size() != list.size()) { return false; } } ListIterator listIterator = ((List) otherList).listIterator(); if (this.from <= this.to) { for (int i = this.from; i <= this.to && listIterator.hasNext(); i += this.step) { Object object = listIterator.next(); if (this.intObjectEqual(i, object)) { return false; } } } else { for (int i = this.from; i >= this.to && listIterator.hasNext(); i += this.step) { Object object = listIterator.next(); if (this.intObjectEqual(i, object)) { return false; } } } return !listIterator.hasNext(); } private boolean intObjectEqual(int i, Object object) { return object == null || !(object instanceof Integer) || ((Integer) object).intValue() != i; } @Override public int hashCode() { int hashCode = 1; if (this.from <= this.to) { for (int i = this.from; i <= this.to; i += this.step) { hashCode = 31 * hashCode + i; } } else { for (int i = this.from; i >= this.to; i += this.step) { hashCode = 31 * hashCode + i; } } return hashCode; } /** * Returns a new interval with the from and to values reversed and the step value negated. */ public Interval reverseThis() { return Interval.fromToBy(this.to, this.from, -this.step); } /** * Calculates and returns the size of the interval. */ @Override public int size() { return (this.to - this.from) / this.step + 1; } @Override public Integer[] toArray() { final Integer[] result = new Integer[this.size()]; this.forEachWithIndex(new ObjectIntProcedure() { public void value(Integer each, int index) { result[index] = each; } }); return result; } /** * Converts the interval to an Integer array */ public int[] toIntArray() { final int[] result = new int[this.size()]; this.forEachWithIndex(new IntIntProcedure() { public void value(int each, int index) { result[index] = each; } }); return result; } @Override public String toString() { return "Interval from: " + this.from + " to: " + this.to + " step: " + this.step + " size: " + this.size(); } public Iterator iterator() { return new IntegerIterator(); } private class IntegerIterator implements Iterator { private int current = Interval.this.from; public boolean hasNext() { if (Interval.this.from <= Interval.this.to) { return this.current <= Interval.this.to; } return this.current >= Interval.this.to; } public Integer next() { if (this.hasNext()) { Integer result = this.current; this.current += Interval.this.step; return result; } throw new NoSuchElementException(); } public void remove() { throw new UnsupportedOperationException("Cannot remove a value from an Interval"); } } @Override public Integer getFirst() { return this.from; } @Override public Integer getLast() { return this.locationAfterN(this.size() - 1); } public void forEach(Procedure procedure, int startIndex, int endIndex) { this.checkBounds("startIndex", startIndex); this.checkBounds("endIndex", endIndex); if (startIndex <= endIndex) { for (int i = startIndex; i <= endIndex; i++) { procedure.value(this.locationAfterN(i)); } } else { for (int i = startIndex; i >= endIndex; i--) { procedure.value(this.locationAfterN(i)); } } } public void forEachWithIndex(ObjectIntProcedure objectIntProcedure, int startIndex, int endIndex) { this.checkBounds("startIndex", startIndex); this.checkBounds("endIndex", endIndex); if (startIndex <= endIndex) { for (int i = startIndex; i <= endIndex; i++) { objectIntProcedure.value(this.locationAfterN(i), i); } } else { for (int i = startIndex; i >= endIndex; i--) { objectIntProcedure.value(this.locationAfterN(i), i); } } } public Integer get(int index) { this.checkBounds("index", index); return this.locationAfterN(index); } private void checkBounds(String name, int index) { if (index < 0 || index >= this.size()) { throw new IndexOutOfBoundsException(name + ": " + index + ' ' + this.toString()); } } private int locationAfterN(int index) { if (index <= 0) { return this.from; } if (this.step > 0) { return (int) Math.min((long) this.from + (long) this.step * (long) index, this.to); } return (int) Math.max((long) this.from + (long) this.step * (long) index, this.to); } public int indexOf(Object object) { if (!(object instanceof Integer)) { return -1; } Integer value = (Integer) object; if (!this.isWithinBoundaries(value)) { return -1; } int diff = value - this.from; if (diff % this.step == 0) { return diff / this.step; } return -1; } public int lastIndexOf(Object object) { return this.indexOf(object); } @Override public MutableList toList() { FastList list = FastList.newList(this.size()); this.forEach(CollectionAddProcedure.on(list)); return list; } @Override public MutableSet toSet() { MutableSet set = UnifiedSet.newSet(this.size()); this.forEach(CollectionAddProcedure.on(set)); return set; } @Override public MutableBag toBag() { MutableBag bag = HashBag.newBag(this.size()); this.forEach(CollectionAddProcedure.on(bag)); return bag; } public boolean add(Integer integer) { throw new UnsupportedOperationException("Cannot call add() on " + this.getClass().getSimpleName()); } public boolean remove(Object o) { throw new UnsupportedOperationException("Cannot call remove() on " + this.getClass().getSimpleName()); } @SuppressWarnings("TypeParameterExtendsFinalClass") public boolean addAll(Collection collection) { throw new UnsupportedOperationException("Cannot call addAll() on " + this.getClass().getSimpleName()); } @SuppressWarnings("TypeParameterExtendsFinalClass") public boolean addAll(int index, Collection collection) { throw new UnsupportedOperationException("Cannot call addAll() on " + this.getClass().getSimpleName()); } public boolean removeAll(Collection collection) { throw new UnsupportedOperationException("Cannot call removeAll() on " + this.getClass().getSimpleName()); } public boolean retainAll(Collection collection) { throw new UnsupportedOperationException("Cannot call retainAll() on " + this.getClass().getSimpleName()); } public void clear() { throw new UnsupportedOperationException("Cannot call clear() on " + this.getClass().getSimpleName()); } public Integer set(int index, Integer element) { throw new UnsupportedOperationException("Cannot call set() on " + this.getClass().getSimpleName()); } public void add(int index, Integer element) { throw new UnsupportedOperationException("Cannot call add() on " + this.getClass().getSimpleName()); } public Integer remove(int index) { throw new UnsupportedOperationException("Cannot call remove() on " + this.getClass().getSimpleName()); } public ListIterator listIterator() { return new MutableListIterator(this, 0); } public ListIterator listIterator(int index) { return new MutableListIterator(this, index); } public Interval subList(int fromIndex, int toIndex) { return Interval.fromToBy(this.get(fromIndex), this.get(toIndex - 1), this.step); } @Override public Interval take(int count) { if (count < 0) { throw new IllegalArgumentException("Count must be greater than zero, but was: " + count); } if (count > 0 && this.notEmpty()) { return Interval.fromToBy(this.from, this.locationAfterN(count - 1), this.step); } return Interval.fromToBy(this.from, this.from, this.step); } @Override public LazyIterable drop(int count) { if (count < 0) { throw new IllegalArgumentException("Count must be greater than zero, but was: " + count); } if (count >= this.size()) { return Lists.immutable.of().asLazy(); } return Interval.fromToBy(this.locationAfterN(count), this.to, this.step); } @Override public LazyIterable distinct() { return this; } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/fixed/000077500000000000000000000000001234315411400301325ustar00rootroot00000000000000AbstractArrayAdapter.java000066400000000000000000000416521234315411400347710ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/fixed/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.fixed; import java.io.IOException; import java.lang.reflect.Array; import java.util.Arrays; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.RandomAccess; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.Function3; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.tuple.Twin; import com.gs.collections.impl.block.factory.Comparators; import com.gs.collections.impl.block.factory.Predicates; import com.gs.collections.impl.list.mutable.AbstractMutableList; import com.gs.collections.impl.list.mutable.FastList; import com.gs.collections.impl.list.mutable.ListAdapter; import com.gs.collections.impl.utility.ArrayIterate; import com.gs.collections.impl.utility.Iterate; import com.gs.collections.impl.utility.internal.IterableIterate; public abstract class AbstractArrayAdapter extends AbstractMutableList implements RandomAccess { protected T[] items; /** * This method must be here so subclasses can be serializable. */ protected AbstractArrayAdapter() { } protected AbstractArrayAdapter(T[] newElements) { this.items = newElements; } @Override public boolean notEmpty() { return ArrayIterate.notEmpty(this.items); } @Override public T getFirst() { return ArrayIterate.getFirst(this.items); } @Override public T getLast() { return ArrayIterate.getLast(this.items); } @Override public void forEach(Procedure procedure) { int size = this.size(); for (int i = 0; i < size; i++) { procedure.value(this.items[i]); } } @Override public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { int size = this.items.length; for (int i = 0; i < size; i++) { objectIntProcedure.value(this.items[i], i); } } @Override public void forEachWithIndex(int fromIndex, int toIndex, ObjectIntProcedure objectIntProcedure) { ArrayIterate.forEachWithIndex(this.items, fromIndex, toIndex, objectIntProcedure); } @Override public void removeIf(Predicate predicate) { throw new UnsupportedOperationException("Cannot call removeIf() on " + this.getClass().getSimpleName()); } @Override public

void removeIfWith(Predicate2 predicate, P parameter) { throw new UnsupportedOperationException("Cannot call removeIfWith() on " + this.getClass().getSimpleName()); } @Override public T detect(Predicate predicate) { return ArrayIterate.detect(this.items, predicate); } @Override public T detectIfNone(Predicate predicate, Function0 function) { T result = this.detect(predicate); return result == null ? function.value() : result; } @Override public int count(Predicate predicate) { return ArrayIterate.count(this.items, predicate); } @Override public boolean anySatisfy(Predicate predicate) { return ArrayIterate.anySatisfy(this.items, predicate); } @Override public boolean allSatisfy(Predicate predicate) { return ArrayIterate.allSatisfy(this.items, predicate); } @Override public boolean noneSatisfy(Predicate predicate) { return ArrayIterate.noneSatisfy(this.items, predicate); } @Override public IV injectInto(IV injectedValue, Function2 function) { return ArrayIterate.injectInto(injectedValue, this.items, function); } @Override public MutableList select(Predicate predicate) { return this.select(predicate, FastList.newList()); } @Override public > R select(Predicate predicate, R target) { return ArrayIterate.select(this.items, predicate, target); } @Override public MutableList reject(Predicate predicate) { return this.reject(predicate, FastList.newList()); } @Override public > R reject(Predicate predicate, R target) { return ArrayIterate.reject(this.items, predicate, target); } @Override public MutableList collect(Function function) { return this.collect(function, FastList.newList(this.size())); } @Override public > R collect(Function function, R target) { return ArrayIterate.collect(this.items, function, target); } @Override public MutableList collectIf( Predicate predicate, Function function) { return this.collectIf(predicate, function, FastList.newList()); } @Override public > R collectIf( Predicate predicate, Function function, R target) { return ArrayIterate.collectIf(this.items, predicate, function, target); } @Override public MutableList flatCollect(Function> function) { return ArrayIterate.flatCollect(this.items, function); } @Override public > R flatCollect(Function> function, R target) { return ArrayIterate.flatCollect(this.items, function, target); } @Override public

Twin> selectAndRejectWith( Predicate2 predicate, P parameter) { return ArrayIterate.selectAndRejectWith(this.items, predicate, parameter); } public int size() { return this.items.length; } @Override public boolean isEmpty() { return ArrayIterate.isEmpty(this.items); } @Override public boolean contains(Object o) { return this.anySatisfy(Predicates.equal(o)); } @Override public Iterator iterator() { return Arrays.asList(this.items).iterator(); } @Override public Object[] toArray() { return this.items.clone(); } @Override public E[] toArray(E[] array) { int size = this.size(); E[] result = array.length < size ? (E[]) Array.newInstance(array.getClass().getComponentType(), size) : array; System.arraycopy(this.items, 0, result, 0, size); if (result.length > size) { result[size] = null; } return result; } @Override public boolean add(T item) { throw new UnsupportedOperationException("Cannot call add() on " + this.getClass().getSimpleName()); } @Override public boolean remove(Object o) { throw new UnsupportedOperationException("Cannot call remove() on " + this.getClass().getSimpleName()); } @Override public boolean containsAll(Collection collection) { return Iterate.allSatisfy(collection, Predicates.in(this.items)); } @Override public boolean addAll(Collection collection) { throw new UnsupportedOperationException("Cannot call addAll() on " + this.getClass().getSimpleName()); } @Override public boolean addAllIterable(Iterable iterable) { throw new UnsupportedOperationException("Cannot call addAllIterable() on " + this.getClass().getSimpleName()); } @Override public boolean removeAll(Collection collection) { throw new UnsupportedOperationException("Cannot call removeAll() on " + this.getClass().getSimpleName()); } @Override public boolean removeAllIterable(Iterable iterable) { throw new UnsupportedOperationException("Cannot call removeAllIterable() on " + this.getClass().getSimpleName()); } @Override public boolean retainAll(Collection collection) { throw new UnsupportedOperationException("Cannot call retainAll() on " + this.getClass().getSimpleName()); } @Override public boolean retainAllIterable(Iterable iterable) { throw new UnsupportedOperationException("Cannot call retainAllIterable() on " + this.getClass().getSimpleName()); } public void clear() { throw new UnsupportedOperationException("Cannot call clear() on " + this.getClass().getSimpleName()); } public boolean addAll(int index, Collection collection) { throw new UnsupportedOperationException("Cannot call addAll() on " + this.getClass().getSimpleName()); } public T get(int index) { if (index >= this.size()) { throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size()); } return this.items[index]; } public void add(int index, T element) { throw new UnsupportedOperationException("Cannot call add() on " + this.getClass().getSimpleName()); } public T remove(int index) { throw new UnsupportedOperationException("Cannot call remove() on " + this.getClass().getSimpleName()); } @Override public int indexOf(Object item) { return ArrayIterate.indexOf(this.items, item); } @Override public int lastIndexOf(Object item) { return Arrays.asList(this.items).lastIndexOf(item); } @Override public ListIterator listIterator(int index) { return Arrays.asList(this.items).listIterator(index); } @Override public MutableList subList(int fromIndex, int toIndex) { return ListAdapter.adapt(Arrays.asList(this.items).subList(fromIndex, toIndex)); } @Override public boolean equals(Object otherList) { if (otherList == this) { return true; } if (!(otherList instanceof List)) { return false; } List list = (List) otherList; if (otherList instanceof AbstractArrayAdapter) { return this.abstractArrayAdapterEquals((AbstractArrayAdapter) otherList); } if (otherList instanceof RandomAccess) { return this.randomAccessListEquals(list); } return this.regularListEquals(list); } public boolean abstractArrayAdapterEquals(AbstractArrayAdapter otherList) { return Arrays.equals(this.items, otherList.items); } private boolean regularListEquals(List otherList) { Iterator iterator = otherList.iterator(); for (int i = 0; i < this.size(); i++) { T one = this.items[i]; if (!iterator.hasNext()) { return false; } Object two = iterator.next(); if (!Comparators.nullSafeEquals(one, two)) { return false; } } return !iterator.hasNext(); } private boolean randomAccessListEquals(List otherList) { if (this.size() != otherList.size()) { return false; } int n = this.items.length; for (int i = 0; i < n; i++) { Object one = this.items[i]; Object two = otherList.get(i); if (!Comparators.nullSafeEquals(one, two)) { return false; } } return true; } @Override public int hashCode() { return Arrays.hashCode(this.items); } @Override public

void forEachWith(Procedure2 procedure, P parameter) { ArrayIterate.forEachWith(this.items, procedure, parameter); } @Override public

MutableList selectWith(Predicate2 predicate, P parameter) { return this.selectWith(predicate, parameter, FastList.newList()); } @Override public > R selectWith( Predicate2 predicate, P parameter, R targetCollection) { return ArrayIterate.selectWith(this.items, predicate, parameter, targetCollection); } @Override public

MutableList rejectWith(Predicate2 predicate, P parameter) { return this.rejectWith(predicate, parameter, FastList.newList()); } @Override public > R rejectWith( Predicate2 predicate, P parameter, R targetCollection) { return ArrayIterate.rejectWith(this.items, predicate, parameter, targetCollection); } @Override public MutableList collectWith(Function2 function, P parameter) { return this.collectWith(function, parameter, FastList.newList()); } @Override public > R collectWith( Function2 function, P parameter, R targetCollection) { return ArrayIterate.collectWith(this.items, function, parameter, targetCollection); } @Override public IV injectIntoWith( IV injectValue, Function3 function, P parameter) { return ArrayIterate.injectIntoWith(injectValue, this.items, function, parameter); } @Override public void forEach(int fromIndex, int toIndex, Procedure procedure) { ArrayIterate.forEach(this.items, fromIndex, toIndex, procedure); } @Override public

T detectWith(Predicate2 predicate, P parameter) { return ArrayIterate.detectWith(this.items, predicate, parameter); } @Override public

T detectWithIfNone( Predicate2 predicate, P parameter, Function0 function) { T result = this.detectWith(predicate, parameter); return result == null ? function.value() : result; } @Override public

int countWith(Predicate2 predicate, P parameter) { return ArrayIterate.countWith(this.items, predicate, parameter); } @Override public

boolean anySatisfyWith(Predicate2 predicate, P parameter) { return ArrayIterate.anySatisfyWith(this.items, predicate, parameter); } @Override public

boolean allSatisfyWith(Predicate2 predicate, P parameter) { return ArrayIterate.allSatisfyWith(this.items, predicate, parameter); } @Override public

boolean noneSatisfyWith(Predicate2 predicate, P parameter) { return ArrayIterate.noneSatisfyWith(this.items, predicate, parameter); } @Override public MutableList distinct() { return ArrayIterate.distinct(this.items, FastList.newList()); } @Override public void appendString(Appendable appendable, String start, String separator, String end) { try { appendable.append(start); if (this.notEmpty()) { appendable.append(IterableIterate.stringValueOfItem(this, this.items[0])); int size = this.size(); for (int i = 1; i < size; i++) { appendable.append(separator); appendable.append(IterableIterate.stringValueOfItem(this, this.items[i])); } } appendable.append(end); } catch (IOException e) { throw new RuntimeException(e); } } } AbstractMemoryEfficientMutableList.java000066400000000000000000000163531234315411400376450ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/fixed/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.fixed; import java.util.Collection; import java.util.ListIterator; import java.util.RandomAccess; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.list.FixedSizeList; import com.gs.collections.api.list.MutableList; import com.gs.collections.impl.factory.Lists; import com.gs.collections.impl.list.mutable.AbstractMutableList; import com.gs.collections.impl.utility.Iterate; public abstract class AbstractMemoryEfficientMutableList extends AbstractMutableList implements FixedSizeList, RandomAccess { @Override public FixedSizeList clone() { return (FixedSizeList) super.clone(); } @Override public boolean add(T o) { throw new UnsupportedOperationException("Cannot add to a fixed size list: " + this.getClass()); } public void add(int index, T element) { throw new UnsupportedOperationException("Cannot add to a fixed size list: " + this.getClass()); } @Override public boolean addAll(Collection collection) { throw new UnsupportedOperationException("Cannot add to a fixed size list: " + this.getClass()); } public boolean addAll(int index, Collection collection) { throw new UnsupportedOperationException("Cannot add to a fixed size list: " + this.getClass()); } @Override public boolean addAllIterable(Iterable iterable) { throw new UnsupportedOperationException("Cannot add to a fixed size list: " + this.getClass()); } @Override public boolean remove(Object o) { throw new UnsupportedOperationException("Cannot remove from a fixed size list: " + this.getClass()); } public T remove(int index) { throw new UnsupportedOperationException("Cannot remove from a fixed size list: " + this.getClass()); } @Override public boolean removeAll(Collection collection) { throw new UnsupportedOperationException("Cannot remove from a fixed size list: " + this.getClass()); } @Override public boolean removeAllIterable(Iterable iterable) { throw new UnsupportedOperationException("Cannot remove from a fixed size list: " + this.getClass()); } @Override public void removeIf(Predicate predicate) { throw new UnsupportedOperationException("Cannot remove from a fixed size list: " + this.getClass()); } @Override public

void removeIfWith(Predicate2 predicate, P parameter) { throw new UnsupportedOperationException("Cannot removeIfWith from a fixed size list: " + this.getClass()); } @Override public boolean retainAll(Collection collection) { throw new UnsupportedOperationException("Cannot remove from a fixed size list: " + this.getClass()); } @Override public boolean retainAllIterable(Iterable iterable) { throw new UnsupportedOperationException("Cannot remove from a fixed size list: " + this.getClass()); } public void clear() { throw new UnsupportedOperationException("Cannot clear a fixed size list: " + this.getClass()); } @Override public MutableList subList(int fromIndex, int toIndex) { return new SubList(this, fromIndex, toIndex); } @Override public MutableList without(T element) { if (this.contains(element)) { return Lists.fixedSize.ofAll(this.toList().without(element)); } return this; } @Override public MutableList withAll(Iterable elements) { if (Iterate.isEmpty(elements)) { return this; } return Lists.fixedSize.ofAll(this.toList().withAll(elements)); } @Override public MutableList withoutAll(Iterable elements) { if (Iterate.isEmpty(elements)) { return this; } return Lists.fixedSize.ofAll(this.toList().withoutAll(elements)); } private static class SubList extends AbstractMutableList.SubList { // Not important since it uses writeReplace() private static final long serialVersionUID = 1L; protected SubList(AbstractMutableList list, int fromIndex, int toIndex) { super(list, fromIndex, toIndex); } @Override public boolean remove(Object o) { throw new UnsupportedOperationException("Cannot remove from a fixed size list: " + this.getClass()); } @Override public boolean removeAll(Collection collection) { throw new UnsupportedOperationException("Cannot remove from a fixed size list: " + this.getClass()); } @Override public boolean removeAllIterable(Iterable iterable) { throw new UnsupportedOperationException("Cannot remove from a fixed size list: " + this.getClass()); } @Override public boolean retainAll(Collection collection) { throw new UnsupportedOperationException("Cannot remove from a fixed size list: " + this.getClass()); } @Override public boolean retainAllIterable(Iterable iterable) { throw new UnsupportedOperationException("Cannot remove from a fixed size list: " + this.getClass()); } @Override public void removeIf(Predicate predicate) { throw new UnsupportedOperationException("Cannot remove from a fixed size list: " + this.getClass()); } @Override public

void removeIfWith(Predicate2 predicate, P parameter) { throw new UnsupportedOperationException("Cannot removeIfWith from a fixed size list: " + this.getClass()); } @Override public boolean addAll(Collection collection) { throw new UnsupportedOperationException("Cannot add to a fixed size list: " + this.getClass()); } @Override public boolean addAllIterable(Iterable iterable) { throw new UnsupportedOperationException("Cannot add to a fixed size list: " + this.getClass()); } } @Override public ListIterator listIterator(int index) { return new FixedSizeListIteratorAdapter(super.listIterator(index)); } @Override public ListIterator listIterator() { return new FixedSizeListIteratorAdapter(super.listIterator()); } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/fixed/ArrayAdapter.java000066400000000000000000000162031234315411400333560ustar00rootroot00000000000000/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.fixed; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.Arrays; import java.util.Collection; import java.util.Comparator; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.list.FixedSizeList; import com.gs.collections.api.list.MutableList; import com.gs.collections.impl.block.factory.Predicates2; import com.gs.collections.impl.utility.Iterate; /** * This class provides a MutableList wrapper around an array. All of the internal iteration methods of the MutableList * interface as well as the JDK Collections List interface are provided. However, the pre-determined fixed-sized * semantics of an array are maintained and thus mutating List interface methods such as {@link #add(Object)}, {@link * #addAll(Collection)}, {@link #remove(Object)}, {@link #removeAll(Collection)}, etc. are not supported and will throw * an {@link UnsupportedOperationException}. In addition, the mutating iteration methods {@link * #removeIf(Predicate)} and {@link #removeIfWith(Predicate2, Object)} are not supported and will also * throw an {@link UnsupportedOperationException}. *

* The {@link #with(Object)} method is not an exception to the above restrictions, as it will create a new * instance of this class with the existing contents plus the new item. *

* To create a wrapper around an existing array, use the {@link #adapt(Object[])} factory method. To wrap the contents * of an existing Collection instance, use the {@link #newArray(Iterable)} or {@link #newArrayWithItem(Iterable, Object)} * factory methods. To wrap existing objects in a new array, use one of the {@link #newArrayWith(Object)} factory methods. */ public final class ArrayAdapter extends AbstractArrayAdapter implements Serializable, FixedSizeList { private static final long serialVersionUID = 1L; private static final Object[] EMPTY_ARRAY = {}; private ArrayAdapter(T[] newElements) { super(newElements); } public static ArrayAdapter adapt(E... array) { return new ArrayAdapter(array); } public static ArrayAdapter newArray() { return ArrayAdapter.newArrayWith((E[]) EMPTY_ARRAY); } public static ArrayAdapter newArray(Iterable source) { return new ArrayAdapter((E[]) Iterate.toArray(source)); } public static ArrayAdapter newArrayWithItem(Iterable iterable, E itemToAdd) { int oldSize = Iterate.sizeOf(iterable); E[] array = (E[]) new Object[oldSize + 1]; Iterate.toArray(iterable, array); array[oldSize] = itemToAdd; return new ArrayAdapter(array); } public static ArrayAdapter newArrayWith(E one) { return new ArrayAdapter((E[]) new Object[]{one}); } public static ArrayAdapter newArrayWith(E one, E two) { return new ArrayAdapter((E[]) new Object[]{one, two}); } public static ArrayAdapter newArrayWith(E one, E two, E three) { return new ArrayAdapter((E[]) new Object[]{one, two, three}); } public static ArrayAdapter newArrayWith(E one, E two, E three, E four) { return new ArrayAdapter((E[]) new Object[]{one, two, three, four}); } public static ArrayAdapter newArrayWith(E one, E two, E three, E four, E five) { return new ArrayAdapter((E[]) new Object[]{one, two, three, four, five}); } public static ArrayAdapter newArrayWith(E one, E two, E three, E four, E five, E six) { return new ArrayAdapter((E[]) new Object[]{one, two, three, four, five, six}); } public static ArrayAdapter newArrayWith(E one, E two, E three, E four, E five, E six, E seven) { return new ArrayAdapter((E[]) new Object[]{one, two, three, four, five, six, seven}); } public static ArrayAdapter newArrayWith(E... elements) { return new ArrayAdapter(elements.clone()); } public T set(int index, T element) { T oldValue = this.items[index]; this.items[index] = element; return oldValue; } @Override public ArrayAdapter with(T value) { return ArrayAdapter.newArrayWithItem(this, value); } @Override public ArrayAdapter without(T element) { if (this.contains(element)) { return ArrayAdapter.newArray(this.toList().without(element)); } return this; } @Override public ArrayAdapter withAll(Iterable elements) { if (Iterate.isEmpty(elements)) { return this; } return ArrayAdapter.newArray(this.toList().withAll(elements)); } @Override public ArrayAdapter withoutAll(Iterable elements) { if (Iterate.isEmpty(elements)) { return this; } if (Iterate.anySatisfyWith(elements, Predicates2.in(), this)) { return ArrayAdapter.newArray(this.toList().withoutAll(elements)); } return this; } @Override public ArrayAdapter clone() { return new ArrayAdapter(this.items.clone()); } @Override public ArrayAdapter sortThis(Comparator comparator) { if (this.size() > 1) { Arrays.sort(this.items, 0, this.size(), comparator); } return this; } @Override public MutableList toReversed() { return this.clone().reverseThis(); } private void writeObject(ObjectOutputStream objectOutputStream) throws IOException { T[] localItems = this.items; int size = localItems.length; objectOutputStream.writeInt(size); for (int i = 0; i < size; i++) { objectOutputStream.writeObject(localItems[i]); } } private void readObject(ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException { // Read in array length and allocate array int arrayLength = objectInputStream.readInt(); this.items = (T[]) new Object[arrayLength]; Object[] localItems = this.items; // Read in all elements in the proper order. for (int i = 0; i < arrayLength; i++) { localItems[i] = objectInputStream.readObject(); } } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/fixed/DoubletonList.java000066400000000000000000000103101234315411400335570ustar00rootroot00000000000000/* * Copyright 2012 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.fixed; import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.impl.block.factory.Comparators; import net.jcip.annotations.NotThreadSafe; /** * A DoubletonList is a two-element memory efficient List. It is created by calling Lists.fixedSize.of(one, two). */ @NotThreadSafe final class DoubletonList extends AbstractMemoryEfficientMutableList implements Externalizable { private static final long serialVersionUID = 1L; private T element1; private T element2; @SuppressWarnings("UnusedDeclaration") public DoubletonList() { // For Externalizable use only } DoubletonList(T obj1, T obj2) { this.element1 = obj1; this.element2 = obj2; } @Override public TripletonList with(T value) { return new TripletonList(this.element1, this.element2, value); } // Weird implementation of clone() is ok on final classes @Override public DoubletonList clone() { return new DoubletonList(this.element1, this.element2); } @Override public T getFirst() { return this.element1; } @Override public T getLast() { return this.element2; } public int size() { return 2; } public T get(int index) { switch (index) { case 0: return this.element1; case 1: return this.element2; default: throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size()); } } @Override public boolean contains(Object obj) { return Comparators.nullSafeEquals(obj, this.element1) || Comparators.nullSafeEquals(obj, this.element2); } /** * set is implemented purely to allow the List to be sorted, not because this List should be considered mutable. */ public T set(int index, T element) { switch (index) { case 0: T previousElement1 = this.element1; this.element1 = element; return previousElement1; case 1: T previousElement2 = this.element2; this.element2 = element; return previousElement2; default: throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size()); } } @Override public void forEach(Procedure procedure) { procedure.value(this.element1); procedure.value(this.element2); } @Override public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { objectIntProcedure.value(this.element1, 0); objectIntProcedure.value(this.element2, 1); } @Override public

void forEachWith(Procedure2 procedure, P parameter) { procedure.value(this.element1, parameter); procedure.value(this.element2, parameter); } public void writeExternal(ObjectOutput out) throws IOException { out.writeObject(this.element1); out.writeObject(this.element2); } public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { this.element1 = (T) in.readObject(); this.element2 = (T) in.readObject(); } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/fixed/EmptyList.java000066400000000000000000000107071234315411400327340ustar00rootroot00000000000000/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.fixed; import java.io.Serializable; import java.util.Comparator; import java.util.Iterator; import java.util.ListIterator; import java.util.NoSuchElementException; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.tuple.Pair; import com.gs.collections.impl.EmptyIterator; import com.gs.collections.impl.factory.Lists; import net.jcip.annotations.Immutable; /** * This class is a memory efficient list with no elements. It is created by calling Lists.fixedSize.of() which * actually returns a singleton instance. */ @Immutable final class EmptyList extends AbstractMemoryEfficientMutableList implements Serializable { private static final long serialVersionUID = 1L; private Object readResolve() { return Lists.fixedSize.of(); } @Override public SingletonList with(T value) { return new SingletonList(value); } // Weird implementation of clone() is ok on final classes @Override public EmptyList clone() { return this; } public int size() { return 0; } @Override public boolean contains(Object obj) { return false; } public T get(int index) { throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size()); } public T set(int index, T element) { throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size()); } @Override public EmptyList sortThis(Comparator comparator) { return this; } @Override public > MutableList sortThisBy(Function function) { return this; } @Override public T getFirst() { return null; } @Override public T getLast() { return null; } @Override public void forEach(Procedure procedure) { } @Override public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { } @Override public

void forEachWith(Procedure2 procedure, P parameter) { } @Override public Iterator iterator() { return EmptyIterator.getInstance(); } @Override public ListIterator listIterator() { return EmptyIterator.getInstance(); } @Override public ListIterator listIterator(int index) { if (index != 0) { throw new IndexOutOfBoundsException("Index: " + index); } return EmptyIterator.getInstance(); } @Override public T min(Comparator comparator) { throw new NoSuchElementException(); } @Override public T max(Comparator comparator) { throw new NoSuchElementException(); } @Override public T min() { throw new NoSuchElementException(); } @Override public T max() { throw new NoSuchElementException(); } @Override public > T minBy(Function function) { throw new NoSuchElementException(); } @Override public > T maxBy(Function function) { throw new NoSuchElementException(); } @Override public MutableList> zip(Iterable that) { return Lists.fixedSize.of(); } @Override public MutableList> zipWithIndex() { return Lists.fixedSize.of(); } } FixedSizeListFactoryImpl.java000066400000000000000000000074161234315411400356260ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/fixed/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.fixed; import com.gs.collections.api.factory.list.FixedSizeListFactory; import com.gs.collections.api.list.FixedSizeList; import com.gs.collections.impl.utility.Iterate; import net.jcip.annotations.Immutable; @Immutable public class FixedSizeListFactoryImpl implements FixedSizeListFactory { private static final FixedSizeList EMPTY_LIST = new EmptyList(); public FixedSizeList of() { return this.with(); } public FixedSizeList with() { return (FixedSizeList) FixedSizeListFactoryImpl.EMPTY_LIST; } public FixedSizeList of(T one) { return this.with(one); } public FixedSizeList with(T one) { return new SingletonList(one); } public FixedSizeList of(T one, T two) { return this.with(one, two); } public FixedSizeList with(T one, T two) { return new DoubletonList(one, two); } public FixedSizeList of(T one, T two, T three) { return this.with(one, two, three); } public FixedSizeList with(T one, T two, T three) { return new TripletonList(one, two, three); } public FixedSizeList of(T one, T two, T three, T four) { return this.with(one, two, three, four); } public FixedSizeList with(T one, T two, T three, T four) { return new QuadrupletonList(one, two, three, four); } public FixedSizeList of(T one, T two, T three, T four, T five) { return this.with(one, two, three, four, five); } public FixedSizeList with(T one, T two, T three, T four, T five) { return new QuintupletonList(one, two, three, four, five); } public FixedSizeList of(T one, T two, T three, T four, T five, T six) { return this.with(one, two, three, four, five, six); } public FixedSizeList with(T one, T two, T three, T four, T five, T six) { return new SextupletonList(one, two, three, four, five, six); } public FixedSizeList of(T... items) { return this.with(items); } public FixedSizeList with(T... items) { switch (items.length) { case 0: return this.of(); case 1: return this.of(items[0]); case 2: return this.of(items[0], items[1]); case 3: return this.of(items[0], items[1], items[2]); case 4: return this.of(items[0], items[1], items[2], items[3]); case 5: return this.of(items[0], items[1], items[2], items[3], items[4]); case 6: return this.of(items[0], items[1], items[2], items[3], items[4], items[5]); default: return ArrayAdapter.newArrayWith(items); } } public FixedSizeList ofAll(Iterable items) { return this.withAll(items); } public FixedSizeList withAll(Iterable items) { return this.of((T[]) Iterate.toArray(items)); } } FixedSizeListIteratorAdapter.java000066400000000000000000000033541234315411400364640ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/fixed/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.fixed; import java.util.ListIterator; public class FixedSizeListIteratorAdapter implements ListIterator { private final ListIterator iterator; public FixedSizeListIteratorAdapter(ListIterator iterator) { this.iterator = iterator; } public boolean hasNext() { return this.iterator.hasNext(); } public T next() { return this.iterator.next(); } public boolean hasPrevious() { return this.iterator.hasPrevious(); } public T previous() { return this.iterator.previous(); } public int nextIndex() { return this.iterator.nextIndex(); } public int previousIndex() { return this.iterator.previousIndex(); } public void remove() { throw new UnsupportedOperationException("Cannot call remove() on " + this.getClass().getSimpleName()); } public void set(T o) { this.iterator.set(o); } public void add(T o) { throw new UnsupportedOperationException("Cannot call add() on " + this.getClass().getSimpleName()); } } QuadrupletonList.java000066400000000000000000000126351234315411400342440ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/fixed/* * Copyright 2012 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.fixed; import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.impl.block.factory.Comparators; import net.jcip.annotations.NotThreadSafe; /** * This is a four element memory efficient List which is created by calling Lists.fixedSize.of(one, two, three, four). */ @NotThreadSafe final class QuadrupletonList extends AbstractMemoryEfficientMutableList implements Externalizable { private static final long serialVersionUID = 1L; private T element1; private T element2; private T element3; private T element4; @SuppressWarnings("UnusedDeclaration") public QuadrupletonList() { // For Externalizable use only } QuadrupletonList(T obj1, T obj2, T obj3, T obj4) { this.element1 = obj1; this.element2 = obj2; this.element3 = obj3; this.element4 = obj4; } @Override public QuintupletonList with(T value) { return new QuintupletonList(this.element1, this.element2, this.element3, this.element4, value); } // Weird implementation of clone() is ok on final classes @Override public QuadrupletonList clone() { return new QuadrupletonList(this.element1, this.element2, this.element3, this.element4); } public int size() { return 4; } public T get(int index) { switch (index) { case 0: return this.element1; case 1: return this.element2; case 2: return this.element3; case 3: return this.element4; default: throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size()); } } @Override public boolean contains(Object obj) { return Comparators.nullSafeEquals(obj, this.element1) || Comparators.nullSafeEquals(obj, this.element2) || Comparators.nullSafeEquals(obj, this.element3) || Comparators.nullSafeEquals(obj, this.element4); } /** * set is implemented purely to allow the List to be sorted, not because this List should be considered mutable. */ public T set(int index, T element) { switch (index) { case 0: T previousElement1 = this.element1; this.element1 = element; return previousElement1; case 1: T previousElement2 = this.element2; this.element2 = element; return previousElement2; case 2: T previousElement3 = this.element3; this.element3 = element; return previousElement3; case 3: T previousElement4 = this.element4; this.element4 = element; return previousElement4; default: throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size()); } } @Override public T getFirst() { return this.element1; } @Override public T getLast() { return this.element4; } @Override public void forEach(Procedure procedure) { procedure.value(this.element1); procedure.value(this.element2); procedure.value(this.element3); procedure.value(this.element4); } @Override public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { objectIntProcedure.value(this.element1, 0); objectIntProcedure.value(this.element2, 1); objectIntProcedure.value(this.element3, 2); objectIntProcedure.value(this.element4, 3); } @Override public

void forEachWith(Procedure2 procedure, P parameter) { procedure.value(this.element1, parameter); procedure.value(this.element2, parameter); procedure.value(this.element3, parameter); procedure.value(this.element4, parameter); } public void writeExternal(ObjectOutput out) throws IOException { out.writeObject(this.element1); out.writeObject(this.element2); out.writeObject(this.element3); out.writeObject(this.element4); } public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { this.element1 = (T) in.readObject(); this.element2 = (T) in.readObject(); this.element3 = (T) in.readObject(); this.element4 = (T) in.readObject(); } } QuintupletonList.java000066400000000000000000000137671234315411400342770ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/fixed/* * Copyright 2012 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.fixed; import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.impl.block.factory.Comparators; import net.jcip.annotations.NotThreadSafe; /** * This is a five element memory efficient List which is created by calling Lists.fixedSize.of(one, two, three, four, five). */ @NotThreadSafe final class QuintupletonList extends AbstractMemoryEfficientMutableList implements Externalizable { private static final long serialVersionUID = 1L; private T element1; private T element2; private T element3; private T element4; private T element5; @SuppressWarnings("UnusedDeclaration") public QuintupletonList() { // For Externalizable use only } QuintupletonList(T obj1, T obj2, T obj3, T obj4, T obj5) { this.element1 = obj1; this.element2 = obj2; this.element3 = obj3; this.element4 = obj4; this.element5 = obj5; } @Override public SextupletonList with(T value) { return new SextupletonList(this.element1, this.element2, this.element3, this.element4, this.element5, value); } // Weird implementation of clone() is ok on final classes @Override public QuintupletonList clone() { return new QuintupletonList(this.element1, this.element2, this.element3, this.element4, this.element5); } public int size() { return 5; } public T get(int index) { switch (index) { case 0: return this.element1; case 1: return this.element2; case 2: return this.element3; case 3: return this.element4; case 4: return this.element5; default: throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size()); } } @Override public boolean contains(Object obj) { return Comparators.nullSafeEquals(obj, this.element1) || Comparators.nullSafeEquals(obj, this.element2) || Comparators.nullSafeEquals(obj, this.element3) || Comparators.nullSafeEquals(obj, this.element4) || Comparators.nullSafeEquals(obj, this.element5); } /** * set is implemented purely to allow the List to be sorted, not because this List should be considered mutable. */ public T set(int index, T element) { switch (index) { case 0: T previousElement1 = this.element1; this.element1 = element; return previousElement1; case 1: T previousElement2 = this.element2; this.element2 = element; return previousElement2; case 2: T previousElement3 = this.element3; this.element3 = element; return previousElement3; case 3: T previousElement4 = this.element4; this.element4 = element; return previousElement4; case 4: T previousElement5 = this.element5; this.element5 = element; return previousElement5; default: throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size()); } } @Override public T getFirst() { return this.element1; } @Override public T getLast() { return this.element5; } @Override public void forEach(Procedure procedure) { procedure.value(this.element1); procedure.value(this.element2); procedure.value(this.element3); procedure.value(this.element4); procedure.value(this.element5); } @Override public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { objectIntProcedure.value(this.element1, 0); objectIntProcedure.value(this.element2, 1); objectIntProcedure.value(this.element3, 2); objectIntProcedure.value(this.element4, 3); objectIntProcedure.value(this.element5, 4); } @Override public

void forEachWith(Procedure2 procedure, P parameter) { procedure.value(this.element1, parameter); procedure.value(this.element2, parameter); procedure.value(this.element3, parameter); procedure.value(this.element4, parameter); procedure.value(this.element5, parameter); } public void writeExternal(ObjectOutput out) throws IOException { out.writeObject(this.element1); out.writeObject(this.element2); out.writeObject(this.element3); out.writeObject(this.element4); out.writeObject(this.element5); } public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { this.element1 = (T) in.readObject(); this.element2 = (T) in.readObject(); this.element3 = (T) in.readObject(); this.element4 = (T) in.readObject(); this.element5 = (T) in.readObject(); } } SextupletonList.java000066400000000000000000000154271234315411400341150ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/fixed/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.fixed; import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.impl.block.factory.Comparators; import net.jcip.annotations.NotThreadSafe; /** * This is a six element immutable List which is created by calling Lists.fixedSize.of(one, two, three, four, five, six). */ @NotThreadSafe final class SextupletonList extends AbstractMemoryEfficientMutableList implements Externalizable { private static final long serialVersionUID = 1L; private T element1; private T element2; private T element3; private T element4; private T element5; private T element6; @SuppressWarnings("UnusedDeclaration") public SextupletonList() { // For Externalizable use only } SextupletonList(T obj1, T obj2, T obj3, T obj4, T obj5, T obj6) { this.element1 = obj1; this.element2 = obj2; this.element3 = obj3; this.element4 = obj4; this.element5 = obj5; this.element6 = obj6; } @Override public ArrayAdapter with(T value) { return ArrayAdapter.newArrayWith( this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, value); } // Weird implementation of clone() is ok on final classes @Override public SextupletonList clone() { return new SextupletonList( this.element1, this.element2, this.element3, this.element4, this.element5, this.element6); } public int size() { return 6; } public T get(int index) { switch (index) { case 0: return this.element1; case 1: return this.element2; case 2: return this.element3; case 3: return this.element4; case 4: return this.element5; case 5: return this.element6; default: throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size()); } } @Override public boolean contains(Object obj) { return Comparators.nullSafeEquals(obj, this.element1) || Comparators.nullSafeEquals(obj, this.element2) || Comparators.nullSafeEquals(obj, this.element3) || Comparators.nullSafeEquals(obj, this.element4) || Comparators.nullSafeEquals(obj, this.element5) || Comparators.nullSafeEquals(obj, this.element6); } /** * set is implemented purely to allow the List to be sorted, not because this List should be considered mutable. */ public T set(int index, T element) { switch (index) { case 0: T previousElement1 = this.element1; this.element1 = element; return previousElement1; case 1: T previousElement2 = this.element2; this.element2 = element; return previousElement2; case 2: T previousElement3 = this.element3; this.element3 = element; return previousElement3; case 3: T previousElement4 = this.element4; this.element4 = element; return previousElement4; case 4: T previousElement5 = this.element5; this.element5 = element; return previousElement5; case 5: T previousElement6 = this.element6; this.element6 = element; return previousElement6; default: throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size()); } } @Override public T getFirst() { return this.element1; } @Override public T getLast() { return this.element6; } @Override public void forEach(Procedure procedure) { procedure.value(this.element1); procedure.value(this.element2); procedure.value(this.element3); procedure.value(this.element4); procedure.value(this.element5); procedure.value(this.element6); } @Override public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { objectIntProcedure.value(this.element1, 0); objectIntProcedure.value(this.element2, 1); objectIntProcedure.value(this.element3, 2); objectIntProcedure.value(this.element4, 3); objectIntProcedure.value(this.element5, 4); objectIntProcedure.value(this.element6, 5); } @Override public

void forEachWith(Procedure2 procedure, P parameter) { procedure.value(this.element1, parameter); procedure.value(this.element2, parameter); procedure.value(this.element3, parameter); procedure.value(this.element4, parameter); procedure.value(this.element5, parameter); procedure.value(this.element6, parameter); } public void writeExternal(ObjectOutput out) throws IOException { out.writeObject(this.element1); out.writeObject(this.element2); out.writeObject(this.element3); out.writeObject(this.element4); out.writeObject(this.element5); out.writeObject(this.element6); } public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { this.element1 = (T) in.readObject(); this.element2 = (T) in.readObject(); this.element3 = (T) in.readObject(); this.element4 = (T) in.readObject(); this.element5 = (T) in.readObject(); this.element6 = (T) in.readObject(); } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/fixed/SingletonList.java000066400000000000000000000077531234315411400336070ustar00rootroot00000000000000/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.fixed; import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; import java.util.Comparator; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.list.MutableList; import com.gs.collections.impl.block.factory.Comparators; import net.jcip.annotations.NotThreadSafe; /** * This class is a memory efficient list with one element. Unlike Collections.singletonList(), it can be sorted. It is * normally created by calling Lists.fixedSize.of(one). */ @NotThreadSafe final class SingletonList extends AbstractMemoryEfficientMutableList implements Externalizable { private static final long serialVersionUID = 1L; private T element1; @SuppressWarnings("UnusedDeclaration") public SingletonList() { // For Externalizable use only } SingletonList(T obj1) { this.element1 = obj1; } @Override public DoubletonList with(T value) { return new DoubletonList(this.element1, value); } // Weird implementation of clone() is ok on final classes @Override public SingletonList clone() { return new SingletonList(this.element1); } public int size() { return 1; } @Override public boolean contains(Object obj) { return Comparators.nullSafeEquals(obj, this.element1); } public T get(int index) { if (index == 0) { return this.element1; } throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size()); } /** * set is implemented purely to allow the List to be sorted, not because this List should be considered mutable. */ public T set(int index, T element) { if (index == 0) { T previousElement = this.element1; this.element1 = element; return previousElement; } throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size()); } @Override public SingletonList sortThis(Comparator comparator) { return this; } @Override public > MutableList sortThisBy(Function function) { return this; } @Override public T getFirst() { return this.element1; } @Override public T getLast() { return this.element1; } @Override public void forEach(Procedure procedure) { procedure.value(this.element1); } @Override public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { objectIntProcedure.value(this.element1, 0); } @Override public

void forEachWith(Procedure2 procedure, P parameter) { procedure.value(this.element1, parameter); } public void writeExternal(ObjectOutput out) throws IOException { out.writeObject(this.element1); } public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { this.element1 = (T) in.readObject(); } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/fixed/TripletonList.java000066400000000000000000000114631234315411400336160ustar00rootroot00000000000000/* * Copyright 2012 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.fixed; import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.impl.block.factory.Comparators; import net.jcip.annotations.NotThreadSafe; /** * This is a three element memory efficient List which is created by calling Lists.fixedSize.of(one, two, three). */ @NotThreadSafe final class TripletonList extends AbstractMemoryEfficientMutableList implements Externalizable { private static final long serialVersionUID = 1L; private T element1; private T element2; private T element3; @SuppressWarnings("UnusedDeclaration") public TripletonList() { // For Externalizable use only } TripletonList(T obj1, T obj2, T obj3) { this.element1 = obj1; this.element2 = obj2; this.element3 = obj3; } @Override public QuadrupletonList with(T value) { return new QuadrupletonList(this.element1, this.element2, this.element3, value); } // Weird implementation of clone() is ok on final classes @Override public TripletonList clone() { return new TripletonList(this.element1, this.element2, this.element3); } public int size() { return 3; } public T get(int index) { switch (index) { case 0: return this.element1; case 1: return this.element2; case 2: return this.element3; default: throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size()); } } @Override public boolean contains(Object obj) { return Comparators.nullSafeEquals(obj, this.element1) || Comparators.nullSafeEquals(obj, this.element2) || Comparators.nullSafeEquals(obj, this.element3); } /** * set is implemented purely to allow the List to be sorted, not because this List should be considered mutable. */ public T set(int index, T element) { switch (index) { case 0: T previousElement1 = this.element1; this.element1 = element; return previousElement1; case 1: T previousElement2 = this.element2; this.element2 = element; return previousElement2; case 2: T previousElement3 = this.element3; this.element3 = element; return previousElement3; default: throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size()); } } @Override public T getFirst() { return this.element1; } @Override public T getLast() { return this.element3; } @Override public void forEach(Procedure procedure) { procedure.value(this.element1); procedure.value(this.element2); procedure.value(this.element3); } @Override public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { objectIntProcedure.value(this.element1, 0); objectIntProcedure.value(this.element2, 1); objectIntProcedure.value(this.element3, 2); } @Override public

void forEachWith(Procedure2 procedure, P parameter) { procedure.value(this.element1, parameter); procedure.value(this.element2, parameter); procedure.value(this.element3, parameter); } public void writeExternal(ObjectOutput out) throws IOException { out.writeObject(this.element1); out.writeObject(this.element2); out.writeObject(this.element3); } public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { this.element1 = (T) in.readObject(); this.element2 = (T) in.readObject(); this.element3 = (T) in.readObject(); } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/fixed/package-info.java000066400000000000000000000016041234315411400333220ustar00rootroot00000000000000/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains implementations of the {@link com.gs.collections.api.list.FixedSizeList} interface. *

* A {@link com.gs.collections.api.list.FixedSizeList} is a list that may be mutated, but cannot grow or shrink in size. *

*/ package com.gs.collections.impl.list.fixed; gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/immutable/000077500000000000000000000000001234315411400310125ustar00rootroot00000000000000AbstractImmutableList.java000066400000000000000000000634621234315411400360500ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/immutable/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.immutable; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.RandomAccess; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.DoubleObjectToDoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.FloatObjectToFloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.IntObjectToIntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.LongObjectToLongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.collection.MutableCollection; import com.gs.collections.api.list.ImmutableList; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.list.primitive.ImmutableBooleanList; import com.gs.collections.api.list.primitive.ImmutableByteList; import com.gs.collections.api.list.primitive.ImmutableCharList; import com.gs.collections.api.list.primitive.ImmutableDoubleList; import com.gs.collections.api.list.primitive.ImmutableFloatList; import com.gs.collections.api.list.primitive.ImmutableIntList; import com.gs.collections.api.list.primitive.ImmutableLongList; import com.gs.collections.api.list.primitive.ImmutableShortList; import com.gs.collections.api.map.ImmutableMap; import com.gs.collections.api.multimap.MutableMultimap; import com.gs.collections.api.multimap.list.ImmutableListMultimap; import com.gs.collections.api.partition.list.PartitionImmutableList; import com.gs.collections.api.stack.MutableStack; import com.gs.collections.api.tuple.Pair; import com.gs.collections.impl.block.factory.Comparators; import com.gs.collections.impl.block.factory.Functions; import com.gs.collections.impl.block.procedure.CollectIfProcedure; import com.gs.collections.impl.block.procedure.CollectProcedure; import com.gs.collections.impl.block.procedure.FlatCollectProcedure; import com.gs.collections.impl.block.procedure.RejectProcedure; import com.gs.collections.impl.block.procedure.SelectInstancesOfProcedure; import com.gs.collections.impl.block.procedure.SelectProcedure; import com.gs.collections.impl.block.procedure.primitive.CollectBooleanProcedure; import com.gs.collections.impl.block.procedure.primitive.CollectByteProcedure; import com.gs.collections.impl.block.procedure.primitive.CollectCharProcedure; import com.gs.collections.impl.block.procedure.primitive.CollectDoubleProcedure; import com.gs.collections.impl.block.procedure.primitive.CollectFloatProcedure; import com.gs.collections.impl.block.procedure.primitive.CollectIntProcedure; import com.gs.collections.impl.block.procedure.primitive.CollectLongProcedure; import com.gs.collections.impl.block.procedure.primitive.CollectShortProcedure; import com.gs.collections.impl.collection.immutable.AbstractImmutableCollection; import com.gs.collections.impl.factory.Lists; import com.gs.collections.impl.lazy.ReverseIterable; import com.gs.collections.impl.list.mutable.FastList; import com.gs.collections.impl.list.mutable.primitive.BooleanArrayList; import com.gs.collections.impl.list.mutable.primitive.ByteArrayList; import com.gs.collections.impl.list.mutable.primitive.CharArrayList; import com.gs.collections.impl.list.mutable.primitive.DoubleArrayList; import com.gs.collections.impl.list.mutable.primitive.FloatArrayList; import com.gs.collections.impl.list.mutable.primitive.IntArrayList; import com.gs.collections.impl.list.mutable.primitive.LongArrayList; import com.gs.collections.impl.list.mutable.primitive.ShortArrayList; import com.gs.collections.impl.multimap.list.FastListMultimap; import com.gs.collections.impl.stack.mutable.ArrayStack; import com.gs.collections.impl.utility.Iterate; import com.gs.collections.impl.utility.ListIterate; import net.jcip.annotations.Immutable; /** * This class is the parent class for all ImmutableLists. All implementations of ImmutableList must implement the List * interface so anArrayList.equals(anImmutableList) can return true when the contents and order are the same. */ @Immutable abstract class AbstractImmutableList extends AbstractImmutableCollection implements ImmutableList, List { public List castToList() { return this; } @Override public boolean equals(Object otherList) { if (otherList == this) { return true; } if (!(otherList instanceof List)) { return false; } List list = (List) otherList; if (list instanceof RandomAccess) { return this.randomAccessListEquals(list); } return this.regularListEquals(list); } protected boolean randomAccessListEquals(List otherList) { if (this.size() != otherList.size()) { return false; } int localSize = this.size(); for (int i = 0; i < localSize; i++) { T one = this.get(i); Object two = otherList.get(i); if (!Comparators.nullSafeEquals(one, two)) { return false; } } return true; } protected boolean regularListEquals(List otherList) { Iterator iterator = otherList.iterator(); for (int i = 0; i < this.size(); i++) { T one = this.get(i); if (!iterator.hasNext()) { return false; } Object two = iterator.next(); if (!Comparators.nullSafeEquals(one, two)) { return false; } } return !iterator.hasNext(); } @Override public int hashCode() { int hashCode = 1; int localSize = this.size(); for (int i = 0; i < localSize; i++) { T item = this.get(i); hashCode = 31 * hashCode + (item == null ? 0 : item.hashCode()); } return hashCode; } public ImmutableList newWithout(T element) { int indexToRemove = this.indexOf(element); if (indexToRemove < 0) { return this; } T[] results = (T[]) new Object[this.size() - 1]; int currentIndex = 0; for (int i = 0; i < this.size(); i++) { T item = this.get(i); if (i != indexToRemove) { results[currentIndex++] = item; } } return Lists.immutable.of(results); } public ImmutableList newWithAll(Iterable elements) { final int oldSize = this.size(); int newSize = Iterate.sizeOf(elements); final T[] array = (T[]) new Object[oldSize + newSize]; this.toArray(array); Iterate.forEachWithIndex(elements, new ObjectIntProcedure() { public void value(T each, int index) { array[oldSize + index] = each; } }); return Lists.immutable.of(array); } public ImmutableList newWithoutAll(Iterable elements) { FastList result = FastList.newListWith((T[]) this.toArray()); this.removeAllFrom(elements, result); return result.toImmutable(); } public T getFirst() { return this.isEmpty() ? null : this.get(0); } public T getLast() { return this.isEmpty() ? null : this.get(this.size() - 1); } public ImmutableList select(Predicate predicate) { MutableList result = Lists.mutable.of(); this.forEach(new SelectProcedure(predicate, result)); return result.toImmutable(); } public

ImmutableList selectWith(Predicate2 predicate, P parameter) { return ListIterate.selectWith(this, predicate, parameter, FastList.newList()).toImmutable(); } @Override public > R selectWith( Predicate2 predicate, P parameter, R targetCollection) { return ListIterate.selectWith(this, predicate, parameter, targetCollection); } public ImmutableList reject(Predicate predicate) { MutableList result = Lists.mutable.of(); this.forEach(new RejectProcedure(predicate, result)); return result.toImmutable(); } public

ImmutableList rejectWith(Predicate2 predicate, P parameter) { return ListIterate.rejectWith(this, predicate, parameter, FastList.newList()).toImmutable(); } @Override public > R rejectWith( Predicate2 predicate, P parameter, R targetCollection) { return ListIterate.rejectWith(this, predicate, parameter, targetCollection); } public PartitionImmutableList partition(Predicate predicate) { return ListIterate.partition(this, predicate).toImmutable(); } public

PartitionImmutableList partitionWith(Predicate2 predicate, P parameter) { return ListIterate.partitionWith(this, predicate, parameter).toImmutable(); } public ImmutableList selectInstancesOf(Class clazz) { FastList result = FastList.newList(this.size()); this.forEach(new SelectInstancesOfProcedure(clazz, result)); return result.toImmutable(); } public ImmutableList collect(Function function) { MutableList result = Lists.mutable.of(); this.forEach(new CollectProcedure(function, result)); return result.toImmutable(); } public ImmutableBooleanList collectBoolean(BooleanFunction booleanFunction) { BooleanArrayList result = new BooleanArrayList(); this.forEach(new CollectBooleanProcedure(booleanFunction, result)); return result.toImmutable(); } public ImmutableByteList collectByte(ByteFunction byteFunction) { ByteArrayList result = new ByteArrayList(); this.forEach(new CollectByteProcedure(byteFunction, result)); return result.toImmutable(); } public ImmutableCharList collectChar(CharFunction charFunction) { CharArrayList result = new CharArrayList(); this.forEach(new CollectCharProcedure(charFunction, result)); return result.toImmutable(); } public ImmutableDoubleList collectDouble(DoubleFunction doubleFunction) { DoubleArrayList result = new DoubleArrayList(); this.forEach(new CollectDoubleProcedure(doubleFunction, result)); return result.toImmutable(); } public ImmutableFloatList collectFloat(FloatFunction floatFunction) { FloatArrayList result = new FloatArrayList(); this.forEach(new CollectFloatProcedure(floatFunction, result)); return result.toImmutable(); } public ImmutableIntList collectInt(IntFunction intFunction) { IntArrayList result = new IntArrayList(); this.forEach(new CollectIntProcedure(intFunction, result)); return result.toImmutable(); } public ImmutableLongList collectLong(LongFunction longFunction) { LongArrayList result = new LongArrayList(this.size()); this.forEach(new CollectLongProcedure(longFunction, result)); return result.toImmutable(); } public ImmutableShortList collectShort(ShortFunction shortFunction) { ShortArrayList result = new ShortArrayList(); this.forEach(new CollectShortProcedure(shortFunction, result)); return result.toImmutable(); } public ImmutableList collectWith(Function2 function, P parameter) { return this.collect(Functions.bind(function, parameter)); } public ImmutableList collectIf( Predicate predicate, Function function) { MutableList result = Lists.mutable.of(); this.forEach(new CollectIfProcedure(result, function, predicate)); return result.toImmutable(); } @Override public > R collectWith( Function2 function, P parameter, R targetCollection) { return ListIterate.collectWith(this, function, parameter, targetCollection); } public ImmutableList flatCollect(Function> function) { MutableList result = Lists.mutable.of(); this.forEach(new FlatCollectProcedure(function, result)); return result.toImmutable(); } @Override public > R flatCollect( Function> function, R target) { return ListIterate.flatCollect(this, function, target); } @Override public T detect(Predicate predicate) { int size = this.size(); for (int i = 0; i < size; i++) { T item = this.get(i); if (predicate.accept(item)) { return item; } } return null; } @Override public

T detectWith(Predicate2 predicate, P parameter) { return ListIterate.detectWith(this, predicate, parameter); } @Override public

T detectWithIfNone(Predicate2 predicate, P parameter, Function0 function) { T result = this.detectWith(predicate, parameter); return result == null ? function.value() : result; } @Override public int count(Predicate predicate) { int count = 0; int size = this.size(); for (int i = 0; i < size; i++) { if (predicate.accept(this.get(i))) { count++; } } return count; } @Override public boolean anySatisfy(Predicate predicate) { int size = this.size(); for (int i = 0; i < size; i++) { if (predicate.accept(this.get(i))) { return true; } } return false; } @Override public boolean allSatisfy(Predicate predicate) { int size = this.size(); for (int i = 0; i < size; i++) { if (!predicate.accept(this.get(i))) { return false; } } return true; } @Override public boolean noneSatisfy(Predicate predicate) { int size = this.size(); for (int i = 0; i < size; i++) { if (predicate.accept(this.get(i))) { return false; } } return true; } @Override public IV injectInto(IV injectedValue, Function2 function) { return ListIterate.injectInto(injectedValue, this, function); } @Override public int injectInto(int injectedValue, IntObjectToIntFunction function) { return ListIterate.injectInto(injectedValue, this, function); } @Override public long injectInto(long injectedValue, LongObjectToLongFunction function) { return ListIterate.injectInto(injectedValue, this, function); } @Override public double injectInto(double injectedValue, DoubleObjectToDoubleFunction function) { return ListIterate.injectInto(injectedValue, this, function); } @Override public float injectInto(float injectedValue, FloatObjectToFloatFunction function) { return ListIterate.injectInto(injectedValue, this, function); } @Override public long sumOfInt(IntFunction function) { return ListIterate.sumOfInt(this, function); } @Override public long sumOfLong(LongFunction function) { return ListIterate.sumOfLong(this, function); } @Override public double sumOfFloat(FloatFunction function) { return ListIterate.sumOfFloat(this, function); } @Override public double sumOfDouble(DoubleFunction function) { return ListIterate.sumOfDouble(this, function); } @Override public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { int localSize = this.size(); for (int i = 0; i < localSize; i++) { T each = this.get(i); objectIntProcedure.value(each, i); } } @Override public

void forEachWith(Procedure2 procedure, P parameter) { int localSize = this.size(); for (int i = 0; i < localSize; i++) { T each = this.get(i); procedure.value(each, parameter); } } public void forEach( int from, int to, Procedure procedure) { if (from < 0 || to < 0) { throw new IllegalArgumentException("Neither from nor to may be negative."); } if (from <= to) { for (int i = from; i <= to; i++) { procedure.value(this.get(i)); } } else { for (int i = from; i >= to; i--) { procedure.value(this.get(i)); } } } public void forEachWithIndex( int from, int to, ObjectIntProcedure objectIntProcedure) { if (from < 0 || to < 0) { throw new IllegalArgumentException("Neither from nor to may be negative."); } if (from <= to) { for (int i = from; i <= to; i++) { objectIntProcedure.value(this.get(i), i); } } else { for (int i = from; i >= to; i--) { objectIntProcedure.value(this.get(i), i); } } } public void reverseForEach(Procedure procedure) { if (this.notEmpty()) { this.forEach(this.size() - 1, 0, procedure); } } public int indexOf(Object object) { int n = this.size(); if (object == null) { for (int i = 0; i < n; i++) { if (this.get(i) == null) { return i; } } } else { for (int i = 0; i < n; i++) { if (object.equals(this.get(i))) { return i; } } } return -1; } public int lastIndexOf(Object object) { int n = this.size() - 1; if (object == null) { for (int i = n; i >= 0; i--) { if (this.get(i) == null) { return i; } } } else { for (int i = n; i >= 0; i--) { if (object.equals(this.get(i))) { return i; } } } return -1; } public Iterator iterator() { return this.listIterator(0); } public boolean addAll(int index, Collection collection) { throw new UnsupportedOperationException("Cannot call addAll() on " + this.getClass().getSimpleName()); } public T set(int index, T element) { throw new UnsupportedOperationException("Cannot call set() on " + this.getClass().getSimpleName()); } public void add(int index, T element) { throw new UnsupportedOperationException("Cannot call add() on " + this.getClass().getSimpleName()); } public T remove(int index) { throw new UnsupportedOperationException("Cannot call remove() on " + this.getClass().getSimpleName()); } public ListIterator listIterator() { return new ImmutableListIterator(this, 0); } public ListIterator listIterator(int index) { if (index < 0 || index > this.size()) { throw new IndexOutOfBoundsException("Index: " + index); } return new ImmutableListIterator(this, index); } public List subList(int fromIndex, int toIndex) { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".subList() not implemented yet"); } public ImmutableList distinct() { MutableList result = Lists.mutable.of(); ListIterate.distinct(this.castToList(), result); return result.toImmutable(); } @Override public void appendString(Appendable appendable, String start, String separator, String end) { ListIterate.appendString(this, appendable, start, separator, end); } public ImmutableListMultimap groupBy(Function function) { return this.groupBy(function, FastListMultimap.newMultimap()).toImmutable(); } @Override public > R groupBy( Function function, R target) { return ListIterate.groupBy(this, function, target); } public ImmutableListMultimap groupByEach(Function> function) { return this.groupByEach(function, FastListMultimap.newMultimap()).toImmutable(); } @Override public > R groupByEach( Function> function, R target) { return ListIterate.groupByEach(this, function, target); } public ImmutableMap groupByUniqueKey(Function function) { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".groupByUniqueKey() not implemented yet"); } @Override public T min(Comparator comparator) { return ListIterate.min(this, comparator); } @Override public T max(Comparator comparator) { return ListIterate.max(this, comparator); } @Override public T min() { return ListIterate.min(this); } @Override public T max() { return ListIterate.max(this); } @Override public > T minBy(Function function) { return ListIterate.minBy(this, function); } @Override public > T maxBy(Function function) { return ListIterate.maxBy(this, function); } public ImmutableList> zip(Iterable that) { return this.zip(that, FastList.>newList()).toImmutable(); } public ImmutableList> zipWithIndex() { return this.zipWithIndex(FastList.>newList()).toImmutable(); } public ImmutableList takeWhile(Predicate predicate) { return ListIterate.takeWhile(this, predicate).toImmutable(); } public ImmutableList dropWhile(Predicate predicate) { return ListIterate.dropWhile(this, predicate).toImmutable(); } public PartitionImmutableList partitionWhile(Predicate predicate) { return ListIterate.partitionWhile(this, predicate).toImmutable(); } @Override protected MutableCollection newMutable(int size) { return FastList.newList(size); } public MutableStack toStack() { return ArrayStack.newStack(this); } public ReverseIterable asReversed() { return ReverseIterable.adapt(this); } public int binarySearch(T key, Comparator comparator) { return Collections.binarySearch(this, key, comparator); } public int binarySearch(T key) { return Collections.binarySearch((List>) this, key); } public ImmutableList toImmutable() { return this; } } ImmutableArrayList.java000066400000000000000000000351311234315411400353530ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/immutable/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.immutable; import java.io.Serializable; import java.lang.reflect.Array; import java.util.Arrays; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.RandomAccess; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.list.ImmutableList; import com.gs.collections.api.partition.list.PartitionImmutableList; import com.gs.collections.impl.block.factory.Comparators; import com.gs.collections.impl.block.factory.Predicates; import com.gs.collections.impl.block.procedure.CountProcedure; import com.gs.collections.impl.block.procedure.FastListCollectIfProcedure; import com.gs.collections.impl.block.procedure.FastListCollectProcedure; import com.gs.collections.impl.block.procedure.FastListRejectProcedure; import com.gs.collections.impl.block.procedure.FastListSelectProcedure; import com.gs.collections.impl.block.procedure.MultimapPutProcedure; import com.gs.collections.impl.parallel.BatchIterable; import com.gs.collections.impl.partition.list.PartitionImmutableListImpl; import com.gs.collections.impl.utility.ArrayIterate; import com.gs.collections.impl.utility.Iterate; import net.jcip.annotations.Immutable; /** * An ImmutableArrayList wraps a Java array but it cannot be modified after creation. */ @Immutable final class ImmutableArrayList extends AbstractImmutableList implements Serializable, RandomAccess, BatchIterable { private static final long serialVersionUID = 1L; private final T[] items; private ImmutableArrayList(T[] newElements) { this.items = newElements; } public static ImmutableArrayList newList(Iterable iterable) { return new ImmutableArrayList((E[]) Iterate.toArray(iterable)); } public static ImmutableArrayList newListWith(E... elements) { return new ImmutableArrayList(elements.clone()); } @Override public int hashCode() { int hashCode = 1; int localSize = this.size(); for (int i = 0; i < localSize; i++) { T item = this.items[i]; hashCode = 31 * hashCode + (item == null ? 0 : item.hashCode()); } return hashCode; } @Override public boolean equals(Object otherList) { if (otherList == this) { return true; } if (!(otherList instanceof List)) { return false; } List list = (List) otherList; if (otherList instanceof ImmutableArrayList) { return this.immutableArrayListEquals((ImmutableArrayList) otherList); } if (list instanceof RandomAccess) { return this.randomAccessListEquals(list); } return this.regularListEquals(list); } public boolean immutableArrayListEquals(ImmutableArrayList otherList) { return Arrays.equals(this.items, otherList.items); } @Override protected boolean randomAccessListEquals(List otherList) { if (this.size() != otherList.size()) { return false; } for (int i = 0; i < this.size(); i++) { T one = this.items[i]; Object two = otherList.get(i); if (!Comparators.nullSafeEquals(one, two)) { return false; } } return true; } @Override protected boolean regularListEquals(List otherList) { Iterator iterator = otherList.iterator(); for (int i = 0; i < this.size(); i++) { T one = this.items[i]; if (!iterator.hasNext()) { return false; } Object two = iterator.next(); if (!Comparators.nullSafeEquals(one, two)) { return false; } } return !iterator.hasNext(); } @Override public boolean notEmpty() { return ArrayIterate.notEmpty(this.items); } @Override public T getFirst() { return ArrayIterate.getFirst(this.items); } @Override public T getLast() { return ArrayIterate.getLast(this.items); } public void forEach(Procedure procedure) { ArrayIterate.forEach(this.items, procedure); } @Override public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { ArrayIterate.forEachWithIndex(this.items, objectIntProcedure); } public void batchForEach(Procedure procedure, int sectionIndex, int sectionCount) { int sectionSize = this.size() / sectionCount; int start = sectionSize * sectionIndex; int end = sectionIndex == sectionCount - 1 ? this.size() : start + sectionSize; if (procedure instanceof FastListSelectProcedure) { this.batchFastListSelect(start, end, (FastListSelectProcedure) procedure); } else if (procedure instanceof FastListCollectProcedure) { this.batchFastListCollect(start, end, (FastListCollectProcedure) procedure); } else if (procedure instanceof FastListCollectIfProcedure) { this.batchFastListCollectIf(start, end, (FastListCollectIfProcedure) procedure); } else if (procedure instanceof CountProcedure) { this.batchCount(start, end, (CountProcedure) procedure); } else if (procedure instanceof FastListRejectProcedure) { this.batchReject(start, end, (FastListRejectProcedure) procedure); } else if (procedure instanceof MultimapPutProcedure) { this.batchGroupBy(start, end, (MultimapPutProcedure) procedure); } else { for (int i = start; i < end; i++) { procedure.value(this.items[i]); } } } /** * Implemented to avoid megamorphic call on castProcedure */ private void batchGroupBy(int start, int end, MultimapPutProcedure castProcedure) { for (int i = start; i < end; i++) { castProcedure.value(this.items[i]); } } /** * Implemented to avoid megamorphic call on castProcedure */ private void batchReject(int start, int end, FastListRejectProcedure castProcedure) { for (int i = start; i < end; i++) { castProcedure.value(this.items[i]); } } /** * Implemented to avoid megamorphic call on castProcedure */ private void batchCount(int start, int end, CountProcedure castProcedure) { for (int i = start; i < end; i++) { castProcedure.value(this.items[i]); } } /** * Implemented to avoid megamorphic call on castProcedure */ private void batchFastListCollectIf(int start, int end, FastListCollectIfProcedure castProcedure) { for (int i = start; i < end; i++) { castProcedure.value(this.items[i]); } } /** * Implemented to avoid megamorphic call on castProcedure */ private void batchFastListCollect(int start, int end, FastListCollectProcedure castProcedure) { for (int i = start; i < end; i++) { castProcedure.value(this.items[i]); } } /** * Implemented to avoid megamorphic call on castProcedure */ private void batchFastListSelect(int start, int end, FastListSelectProcedure castProcedure) { for (int i = start; i < end; i++) { castProcedure.value(this.items[i]); } } public int getBatchCount(int batchSize) { return Math.max(1, this.size() / batchSize); } @Override public void forEachWithIndex(int from, int to, ObjectIntProcedure objectIntProcedure) { if (from < 0 || to < 0) { throw new IllegalArgumentException("Neither from nor to may be negative."); } T[] localItems = this.items; if (from <= to) { for (int i = from; i <= to; i++) { objectIntProcedure.value(localItems[i], i); } } else { for (int i = from; i >= to; i--) { objectIntProcedure.value(localItems[i], i); } } } @Override public T detect(Predicate predicate) { return ArrayIterate.detect(this.items, predicate); } @Override public T detectIfNone(Predicate predicate, Function0 function) { T result = this.detect(predicate); return result == null ? function.value() : result; } @Override public int count(Predicate predicate) { return ArrayIterate.count(this.items, predicate); } @Override public boolean anySatisfy(Predicate predicate) { return ArrayIterate.anySatisfy(this.items, predicate); } @Override public boolean allSatisfy(Predicate predicate) { return ArrayIterate.allSatisfy(this.items, predicate); } @Override public boolean noneSatisfy(Predicate predicate) { return ArrayIterate.noneSatisfy(this.items, predicate); } @Override public IV injectInto(IV injectedValue, Function2 function) { return ArrayIterate.injectInto(injectedValue, this.items, function); } public int size() { return this.items.length; } @Override public boolean isEmpty() { return ArrayIterate.isEmpty(this.items); } @Override public boolean contains(Object o) { return this.anySatisfy(Predicates.equal(o)); } @Override public Iterator iterator() { return Arrays.asList(this.items).iterator(); } @Override public Object[] toArray() { return this.items.clone(); } @Override public E[] toArray(E[] a) { int size = this.size(); if (a.length < size) { a = (E[]) Array.newInstance(a.getClass().getComponentType(), size); } System.arraycopy(this.items, 0, a, 0, size); if (a.length > size) { a[size] = null; } return a; } @Override public String toString() { StringBuilder buf = new StringBuilder(); buf.append('['); int localSize = this.items.length; T[] localItems = this.items; for (int i = 0; i < localSize; i++) { T item = localItems[i]; if (i > 0) { buf.append(", "); } buf.append(item == this ? "(this ImmutableArrayList)" : String.valueOf(item)); } buf.append(']'); return buf.toString(); } @Override public boolean containsAll(Collection collection) { return Iterate.allSatisfy(collection, Predicates.in(this.items)); } public T get(int index) { return this.items[index]; } @Override public int indexOf(Object item) { return ArrayIterate.indexOf(this.items, item); } @Override public int lastIndexOf(Object item) { return Arrays.asList(this.items).lastIndexOf(item); } public ImmutableList newWith(T newItem) { int oldSize = this.size(); T[] array = (T[]) new Object[oldSize + 1]; this.toArray(array); array[oldSize] = newItem; return new ImmutableArrayList(array); } @Override public > T minBy(Function function) { return ArrayIterate.minBy(this.items, function); } @Override public > T maxBy(Function function) { return ArrayIterate.maxBy(this.items, function); } @Override public ImmutableList takeWhile(Predicate predicate) { int endIndex = this.detectNotIndex(predicate); T[] result = (T[]) new Object[endIndex]; System.arraycopy(this.items, 0, result, 0, endIndex); return new ImmutableArrayList(result); } @Override public ImmutableList dropWhile(Predicate predicate) { int startIndex = this.detectNotIndex(predicate); int resultSize = this.size() - startIndex; T[] result = (T[]) new Object[resultSize]; System.arraycopy(this.items, startIndex, result, 0, resultSize); return new ImmutableArrayList(result); } @Override public PartitionImmutableList partitionWhile(Predicate predicate) { int partitionIndex = this.detectNotIndex(predicate); int rejectedSize = this.size() - partitionIndex; T[] selectedArray = (T[]) new Object[partitionIndex]; T[] rejectedArray = (T[]) new Object[rejectedSize]; System.arraycopy(this.items, 0, selectedArray, 0, partitionIndex); System.arraycopy(this.items, partitionIndex, rejectedArray, 0, rejectedSize); ImmutableArrayList selected = new ImmutableArrayList(selectedArray); ImmutableArrayList rejected = new ImmutableArrayList(rejectedArray); return new PartitionImmutableListImpl(selected, rejected); } private int detectNotIndex(Predicate predicate) { for (int index = 0; index < this.size(); index++) { if (!predicate.accept(this.items[index])) { return index; } } return this.size(); } } ImmutableDecapletonList.java000066400000000000000000000071551234315411400363600ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/immutable/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.immutable; import java.io.Serializable; import java.util.RandomAccess; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.list.ImmutableList; import com.gs.collections.impl.factory.Lists; import net.jcip.annotations.Immutable; /** * This is a ten element immutable List which is created by calling * Immutable.newListWith(one, two, three, four, five, six, seven, eight, nine, ten) method. */ @Immutable final class ImmutableDecapletonList extends AbstractImmutableList implements Serializable, RandomAccess { private static final long serialVersionUID = 1L; private final T element1; private final T element2; private final T element3; private final T element4; private final T element5; private final T element6; private final T element7; private final T element8; private final T element9; private final T element10; ImmutableDecapletonList(T obj1, T obj2, T obj3, T obj4, T obj5, T obj6, T obj7, T obj8, T obj9, T obj10) { this.element1 = obj1; this.element2 = obj2; this.element3 = obj3; this.element4 = obj4; this.element5 = obj5; this.element6 = obj6; this.element7 = obj7; this.element8 = obj8; this.element9 = obj9; this.element10 = obj10; } public int size() { return 10; } public void forEach(Procedure procedure) { procedure.value(this.element1); procedure.value(this.element2); procedure.value(this.element3); procedure.value(this.element4); procedure.value(this.element5); procedure.value(this.element6); procedure.value(this.element7); procedure.value(this.element8); procedure.value(this.element9); procedure.value(this.element10); } public T get(int index) { switch (index) { case 0: return this.element1; case 1: return this.element2; case 2: return this.element3; case 3: return this.element4; case 4: return this.element5; case 5: return this.element6; case 6: return this.element7; case 7: return this.element8; case 8: return this.element9; case 9: return this.element10; default: throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size()); } } public ImmutableList newWith(T newItem) { return Lists.immutable.of(this.get(0), this.get(1), this.get(2), this.get(3), this.get(4), this.get(5), this.get(6), this.get(7), this.get(8), this.get(9), newItem); } } ImmutableDoubletonList.java000066400000000000000000000046131234315411400362310ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/immutable/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.immutable; import java.io.Serializable; import java.util.RandomAccess; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.list.ImmutableList; import com.gs.collections.impl.block.factory.Comparators; import com.gs.collections.impl.factory.Lists; import net.jcip.annotations.Immutable; /** * This is a two element immutable List which is created by calling * Immutable.newListWith(one, two) method. */ @Immutable final class ImmutableDoubletonList extends AbstractImmutableList implements Serializable, RandomAccess { private static final long serialVersionUID = 1L; private final T element1; private final T element2; ImmutableDoubletonList(T obj1, T obj2) { this.element1 = obj1; this.element2 = obj2; } @Override public T getFirst() { return this.element1; } @Override public T getLast() { return this.element2; } public int size() { return 2; } public void forEach(Procedure procedure) { procedure.value(this.element1); procedure.value(this.element2); } public T get(int index) { switch (index) { case 0: return this.element1; case 1: return this.element2; default: throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size()); } } @Override public boolean contains(Object obj) { return Comparators.nullSafeEquals(obj, this.element1) || Comparators.nullSafeEquals(obj, this.element2); } public ImmutableList newWith(T newItem) { return Lists.immutable.of(this.get(0), this.get(1), newItem); } } ImmutableEmptyList.java000066400000000000000000000255411234315411400353770ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/immutable/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.immutable; import java.io.IOException; import java.io.Serializable; import java.util.Collection; import java.util.Comparator; import java.util.List; import java.util.NoSuchElementException; import java.util.RandomAccess; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.DoubleObjectToDoubleFunction; import com.gs.collections.api.block.function.primitive.IntObjectToIntFunction; import com.gs.collections.api.block.function.primitive.LongObjectToLongFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.list.ImmutableList; import com.gs.collections.api.partition.list.PartitionImmutableList; import com.gs.collections.api.stack.MutableStack; import com.gs.collections.api.tuple.Pair; import com.gs.collections.impl.factory.Lists; import com.gs.collections.impl.factory.Stacks; import com.gs.collections.impl.partition.list.PartitionFastList; import net.jcip.annotations.Immutable; /** * This is a zero element {@link ImmutableList} which is created by calling the Lists.immutable.of() method. */ @Immutable final class ImmutableEmptyList extends AbstractImmutableList implements Serializable, RandomAccess { static final ImmutableList INSTANCE = new ImmutableEmptyList(); private static final PartitionImmutableList EMPTY = new PartitionFastList().toImmutable(); private static final long serialVersionUID = 1L; private Object readResolve() { return INSTANCE; } @Override public ImmutableList newWithout(T element) { return this; } @Override public ImmutableList newWithoutAll(Iterable elements) { return this; } public int size() { return 0; } @Override public boolean contains(Object obj) { return false; } public T get(int index) { throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size()); } public void forEach(Procedure procedure) { } @Override public void reverseForEach(Procedure procedure) { } @Override public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { } @Override public

void forEachWith(Procedure2 procedure, P parameter) { } public ImmutableList newWith(T newItem) { return Lists.immutable.of(newItem); } @Override public T min(Comparator comparator) { throw new NoSuchElementException(); } @Override public T max(Comparator comparator) { throw new NoSuchElementException(); } @Override public T min() { throw new NoSuchElementException(); } @Override public T max() { throw new NoSuchElementException(); } @Override public > T minBy(Function function) { throw new NoSuchElementException(); } @Override public > T maxBy(Function function) { throw new NoSuchElementException(); } @Override public ImmutableList> zip(Iterable that) { return Lists.immutable.of(); } @Override public >> R zip(Iterable that, R target) { return target; } @Override public ImmutableList> zipWithIndex() { return Lists.immutable.of(); } @Override public MutableStack toStack() { return Stacks.mutable.of(); } @Override public >> R zipWithIndex(R target) { return target; } @Override public ImmutableList select(Predicate predicate) { return this; } @Override public > R selectWith(Predicate2 predicate, P parameter, R targetCollection) { return targetCollection; } @Override public ImmutableList reject(Predicate predicate) { return this; } @Override public > R rejectWith(Predicate2 predicate, P parameter, R targetCollection) { return targetCollection; } @Override public PartitionImmutableList partition(Predicate predicate) { return (PartitionImmutableList) EMPTY; } @Override public ImmutableList collect(Function function) { return Lists.immutable.of(); } @Override public ImmutableList collectIf(Predicate predicate, Function function) { return Lists.immutable.of(); } @Override public > R collectWith(Function2 function, P parameter, R targetCollection) { return targetCollection; } @Override public ImmutableList flatCollect(Function> function) { return Lists.immutable.of(); } @Override public > R flatCollect(Function> function, R targetCollection) { return targetCollection; } @Override public T detect(Predicate predicate) { return null; } @Override public int count(Predicate predicate) { return 0; } @Override public

int countWith(Predicate2 predicate, P parameter) { return 0; } @Override public boolean anySatisfy(Predicate predicate) { return false; } @Override public boolean allSatisfy(Predicate predicate) { return true; } @Override public boolean noneSatisfy(Predicate predicate) { return true; } @Override public

boolean anySatisfyWith(Predicate2 predicate, P parameter) { return false; } @Override public

boolean allSatisfyWith(Predicate2 predicate, P parameter) { return true; } @Override public

boolean noneSatisfyWith(Predicate2 predicate, P parameter) { return true; } @Override public IV injectInto(IV injectedValue, Function2 function) { return injectedValue; } @Override public int injectInto(int injectedValue, IntObjectToIntFunction intObjectToIntFunction) { return injectedValue; } @Override public long injectInto(long injectedValue, LongObjectToLongFunction longObjectToLongFunction) { return injectedValue; } @Override public double injectInto(double injectedValue, DoubleObjectToDoubleFunction doubleObjectToDoubleFunction) { return injectedValue; } @Override public T getFirst() { return null; } @Override public T getLast() { return null; } @Override public int indexOf(Object object) { return -1; } @Override public boolean equals(Object otherList) { if (otherList == this) { return true; } if (!(otherList instanceof List)) { return false; } List list = (List) otherList; return list.isEmpty(); } @Override public int hashCode() { return 1; } @Override public boolean isEmpty() { return true; } @Override public boolean notEmpty() { return false; } @Override public > R select(Predicate predicate, R target) { return target; } @Override public > R reject(Predicate predicate, R target) { return target; } @Override public > R collect(Function function, R target) { return target; } @Override public > R collectIf(Predicate predicate, Function function, R target) { return target; } @Override public T detectIfNone(Predicate predicate, Function0 function) { return function.value(); } @Override public String toString() { return "[]"; } @Override public String makeString() { return ""; } @Override public String makeString(String separator) { return ""; } @Override public String makeString(String start, String separator, String end) { return start + end; } @Override public void appendString(Appendable appendable) { } @Override public void appendString(Appendable appendable, String separator) { } @Override public void appendString(Appendable appendable, String start, String separator, String end) { try { appendable.append(start); appendable.append(end); } catch (IOException e) { throw new RuntimeException(e); } } @Override public ImmutableList takeWhile(Predicate predicate) { return this; } @Override public ImmutableList dropWhile(Predicate predicate) { return this; } @Override public PartitionImmutableList partitionWhile(Predicate predicate) { return (PartitionImmutableList) EMPTY; } } ImmutableIterator.java000066400000000000000000000030521234315411400352270ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/immutable/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.immutable; import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; public class ImmutableIterator implements Iterator { /** * Index of element to be returned by subsequent call to next. */ protected int currentIndex; protected final List list; public ImmutableIterator(List list) { this.list = list; } public boolean hasNext() { return this.currentIndex != this.list.size(); } public T next() { try { T result = this.list.get(this.currentIndex); this.currentIndex++; return result; } catch (IndexOutOfBoundsException ignored) { throw new NoSuchElementException(); } } public void remove() { throw new UnsupportedOperationException("Cannot call remove() on " + this.getClass().getSimpleName()); } } ImmutableListFactoryImpl.java000066400000000000000000000140331234315411400365240ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/immutable/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.immutable; import com.gs.collections.api.factory.list.ImmutableListFactory; import com.gs.collections.api.list.ImmutableList; import com.gs.collections.impl.utility.Iterate; import net.jcip.annotations.Immutable; @Immutable public final class ImmutableListFactoryImpl implements ImmutableListFactory { public ImmutableList of() { return this.with(); } public ImmutableList with() { return (ImmutableList) ImmutableEmptyList.INSTANCE; } public ImmutableList of(T one) { return this.with(one); } public ImmutableList with(T one) { return new ImmutableSingletonList(one); } public ImmutableList of(T one, T two) { return this.with(one, two); } public ImmutableList with(T one, T two) { return new ImmutableDoubletonList(one, two); } public ImmutableList of(T one, T two, T three) { return this.with(one, two, three); } public ImmutableList with(T one, T two, T three) { return new ImmutableTripletonList(one, two, three); } public ImmutableList of(T one, T two, T three, T four) { return this.with(one, two, three, four); } public ImmutableList with(T one, T two, T three, T four) { return new ImmutableQuadrupletonList(one, two, three, four); } public ImmutableList of(T one, T two, T three, T four, T five) { return this.with(one, two, three, four, five); } public ImmutableList with(T one, T two, T three, T four, T five) { return new ImmutableQuintupletonList(one, two, three, four, five); } public ImmutableList of(T one, T two, T three, T four, T five, T six) { return this.with(one, two, three, four, five, six); } public ImmutableList with(T one, T two, T three, T four, T five, T six) { return new ImmutableSextupletonList(one, two, three, four, five, six); } public ImmutableList of(T one, T two, T three, T four, T five, T six, T seven) { return this.with(one, two, three, four, five, six, seven); } public ImmutableList with(T one, T two, T three, T four, T five, T six, T seven) { return new ImmutableSeptupletonList(one, two, three, four, five, six, seven); } public ImmutableList of(T one, T two, T three, T four, T five, T six, T seven, T eight) { return this.with(one, two, three, four, five, six, seven, eight); } public ImmutableList with(T one, T two, T three, T four, T five, T six, T seven, T eight) { return new ImmutableOctupletonList(one, two, three, four, five, six, seven, eight); } public ImmutableList of(T one, T two, T three, T four, T five, T six, T seven, T eight, T nine) { return this.with(one, two, three, four, five, six, seven, eight, nine); } public ImmutableList with(T one, T two, T three, T four, T five, T six, T seven, T eight, T nine) { return new ImmutableNonupletonList(one, two, three, four, five, six, seven, eight, nine); } public ImmutableList of(T one, T two, T three, T four, T five, T six, T seven, T eight, T nine, T ten) { return this.with(one, two, three, four, five, six, seven, eight, nine, ten); } public ImmutableList with(T one, T two, T three, T four, T five, T six, T seven, T eight, T nine, T ten) { return new ImmutableDecapletonList(one, two, three, four, five, six, seven, eight, nine, ten); } public ImmutableList of(T... items) { return this.with(items); } public ImmutableList with(T... items) { if (items == null || items.length == 0) { return this.of(); } switch (items.length) { case 1: return this.of(items[0]); case 2: return this.of(items[0], items[1]); case 3: return this.of(items[0], items[1], items[2]); case 4: return this.of(items[0], items[1], items[2], items[3]); case 5: return this.of(items[0], items[1], items[2], items[3], items[4]); case 6: return this.of(items[0], items[1], items[2], items[3], items[4], items[5]); case 7: return this.of(items[0], items[1], items[2], items[3], items[4], items[5], items[6]); case 8: return this.of(items[0], items[1], items[2], items[3], items[4], items[5], items[6], items[7]); case 9: return this.of(items[0], items[1], items[2], items[3], items[4], items[5], items[6], items[7], items[8]); case 10: return this.of(items[0], items[1], items[2], items[3], items[4], items[5], items[6], items[7], items[8], items[9]); default: return ImmutableArrayList.newListWith(items); } } public ImmutableList ofAll(Iterable items) { return this.withAll(items); } public ImmutableList withAll(Iterable items) { if (items instanceof ImmutableList) { return (ImmutableList) items; } return this.of((T[]) Iterate.toArray(items)); } } ImmutableListIterator.java000066400000000000000000000034641234315411400360720ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/immutable/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.immutable; import java.util.List; import java.util.ListIterator; import java.util.NoSuchElementException; public final class ImmutableListIterator extends ImmutableIterator implements ListIterator { public ImmutableListIterator(List list, int index) { super(list); this.currentIndex = index; } public boolean hasPrevious() { return this.currentIndex != 0; } public T previous() { try { int i = this.currentIndex - 1; T previous = this.list.get(i); this.currentIndex = i; return previous; } catch (IndexOutOfBoundsException ignored) { throw new NoSuchElementException(); } } public int nextIndex() { return this.currentIndex; } public int previousIndex() { return this.currentIndex - 1; } public void set(T o) { throw new UnsupportedOperationException("Cannot call set() on " + this.getClass().getSimpleName()); } public void add(T o) { throw new UnsupportedOperationException("Cannot call add() on " + this.getClass().getSimpleName()); } } ImmutableNonupletonList.java000066400000000000000000000066341234315411400364440ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/immutable/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.immutable; import java.io.Serializable; import java.util.RandomAccess; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.list.ImmutableList; import com.gs.collections.impl.factory.Lists; import net.jcip.annotations.Immutable; /** * This is a nine element immutable List which is created by calling * Lists.immutable.of(one, two, three, four, five, six, seven, eight, nine) method. */ @Immutable final class ImmutableNonupletonList extends AbstractImmutableList implements Serializable, RandomAccess { private static final long serialVersionUID = 1L; private final T element1; private final T element2; private final T element3; private final T element4; private final T element5; private final T element6; private final T element7; private final T element8; private final T element9; ImmutableNonupletonList(T obj1, T obj2, T obj3, T obj4, T obj5, T obj6, T obj7, T obj8, T obj9) { this.element1 = obj1; this.element2 = obj2; this.element3 = obj3; this.element4 = obj4; this.element5 = obj5; this.element6 = obj6; this.element7 = obj7; this.element8 = obj8; this.element9 = obj9; } public int size() { return 9; } public void forEach(Procedure procedure) { procedure.value(this.element1); procedure.value(this.element2); procedure.value(this.element3); procedure.value(this.element4); procedure.value(this.element5); procedure.value(this.element6); procedure.value(this.element7); procedure.value(this.element8); procedure.value(this.element9); } public T get(int index) { switch (index) { case 0: return this.element1; case 1: return this.element2; case 2: return this.element3; case 3: return this.element4; case 4: return this.element5; case 5: return this.element6; case 6: return this.element7; case 7: return this.element8; case 8: return this.element9; default: throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size()); } } public ImmutableList newWith(T newItem) { return Lists.immutable.of(this.get(0), this.get(1), this.get(2), this.get(3), this.get(4), this.get(5), this.get(6), this.get(7), this.get(8), newItem); } } ImmutableOctupletonList.java000066400000000000000000000063301234315411400364300ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/immutable/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.immutable; import java.io.Serializable; import java.util.RandomAccess; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.list.ImmutableList; import com.gs.collections.impl.factory.Lists; import net.jcip.annotations.Immutable; /** * This is an eight element immutable List which is created by calling * Immutable.newListWith(one, two, three, four, five, six, seven, eight) method. */ @Immutable final class ImmutableOctupletonList extends AbstractImmutableList implements Serializable, RandomAccess { private static final long serialVersionUID = 1L; private final T element1; private final T element2; private final T element3; private final T element4; private final T element5; private final T element6; private final T element7; private final T element8; ImmutableOctupletonList(T obj1, T obj2, T obj3, T obj4, T obj5, T obj6, T obj7, T obj8) { this.element1 = obj1; this.element2 = obj2; this.element3 = obj3; this.element4 = obj4; this.element5 = obj5; this.element6 = obj6; this.element7 = obj7; this.element8 = obj8; } public int size() { return 8; } public void forEach(Procedure procedure) { procedure.value(this.element1); procedure.value(this.element2); procedure.value(this.element3); procedure.value(this.element4); procedure.value(this.element5); procedure.value(this.element6); procedure.value(this.element7); procedure.value(this.element8); } public T get(int index) { switch (index) { case 0: return this.element1; case 1: return this.element2; case 2: return this.element3; case 3: return this.element4; case 4: return this.element5; case 5: return this.element6; case 6: return this.element7; case 7: return this.element8; default: throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size()); } } public ImmutableList newWith(T newItem) { return Lists.immutable.of(this.get(0), this.get(1), this.get(2), this.get(3), this.get(4), this.get(5), this.get(6), this.get(7), newItem); } } ImmutableQuadrupletonList.java000066400000000000000000000045651234315411400367670ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/immutable/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.immutable; import java.io.Serializable; import java.util.RandomAccess; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.list.ImmutableList; import com.gs.collections.impl.factory.Lists; import net.jcip.annotations.Immutable; /** * This is a four element immutable List which is created by calling * Immutable.newListWith(one, two, three, four) method. */ @Immutable final class ImmutableQuadrupletonList extends AbstractImmutableList implements Serializable, RandomAccess { private static final long serialVersionUID = 1L; private final T element1; private final T element2; private final T element3; private final T element4; ImmutableQuadrupletonList(T obj1, T obj2, T obj3, T obj4) { this.element1 = obj1; this.element2 = obj2; this.element3 = obj3; this.element4 = obj4; } public int size() { return 4; } public void forEach(Procedure procedure) { procedure.value(this.element1); procedure.value(this.element2); procedure.value(this.element3); procedure.value(this.element4); } public T get(int index) { switch (index) { case 0: return this.element1; case 1: return this.element2; case 2: return this.element3; case 3: return this.element4; default: throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size()); } } public ImmutableList newWith(T newItem) { return Lists.immutable.of(this.get(0), this.get(1), this.get(2), this.get(3), newItem); } } ImmutableQuintupletonList.java000066400000000000000000000050561234315411400370070ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/immutable/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.immutable; import java.io.Serializable; import java.util.RandomAccess; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.list.ImmutableList; import com.gs.collections.impl.factory.Lists; import net.jcip.annotations.Immutable; /** * This is a five element immutable List which is created by calling * Immutable.newListWith(one, two, three, four, five) method. */ @Immutable final class ImmutableQuintupletonList extends AbstractImmutableList implements Serializable, RandomAccess { private static final long serialVersionUID = 1L; private final T element1; private final T element2; private final T element3; private final T element4; private final T element5; ImmutableQuintupletonList(T obj1, T obj2, T obj3, T obj4, T obj5) { this.element1 = obj1; this.element2 = obj2; this.element3 = obj3; this.element4 = obj4; this.element5 = obj5; } public int size() { return 5; } public void forEach(Procedure procedure) { procedure.value(this.element1); procedure.value(this.element2); procedure.value(this.element3); procedure.value(this.element4); procedure.value(this.element5); } public T get(int index) { switch (index) { case 0: return this.element1; case 1: return this.element2; case 2: return this.element3; case 3: return this.element4; case 4: return this.element5; default: throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size()); } } public ImmutableList newWith(T newItem) { return Lists.immutable.of(this.get(0), this.get(1), this.get(2), this.get(3), this.get(4), newItem); } } ImmutableSeptupletonList.java000066400000000000000000000060401234315411400366140ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/immutable/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.immutable; import java.io.Serializable; import java.util.RandomAccess; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.list.ImmutableList; import com.gs.collections.impl.factory.Lists; import net.jcip.annotations.Immutable; /** * This is a seven element immutable List which is created by calling * Immutable.newListWith(one, two, three, four, five, six, seven) method. */ @Immutable final class ImmutableSeptupletonList extends AbstractImmutableList implements Serializable, RandomAccess { private static final long serialVersionUID = 1L; private final T element1; private final T element2; private final T element3; private final T element4; private final T element5; private final T element6; private final T element7; ImmutableSeptupletonList(T obj1, T obj2, T obj3, T obj4, T obj5, T obj6, T obj7) { this.element1 = obj1; this.element2 = obj2; this.element3 = obj3; this.element4 = obj4; this.element5 = obj5; this.element6 = obj6; this.element7 = obj7; } public int size() { return 7; } public void forEach(Procedure procedure) { procedure.value(this.element1); procedure.value(this.element2); procedure.value(this.element3); procedure.value(this.element4); procedure.value(this.element5); procedure.value(this.element6); procedure.value(this.element7); } public T get(int index) { switch (index) { case 0: return this.element1; case 1: return this.element2; case 2: return this.element3; case 3: return this.element4; case 4: return this.element5; case 5: return this.element6; case 6: return this.element7; default: throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size()); } } public ImmutableList newWith(T newItem) { return Lists.immutable.of( this.get(0), this.get(1), this.get(2), this.get(3), this.get(4), this.get(5), this.get(6), newItem); } } ImmutableSextupletonList.java000066400000000000000000000055031234315411400366270ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/immutable/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.immutable; import java.io.Serializable; import java.util.RandomAccess; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.list.ImmutableList; import com.gs.collections.impl.factory.Lists; import net.jcip.annotations.Immutable; /** * This is a six element immutable List which is created by calling * Immutable.newListWith(one, two, three, four, five, six) method. */ @Immutable final class ImmutableSextupletonList extends AbstractImmutableList implements Serializable, RandomAccess { private static final long serialVersionUID = 1L; private final T element1; private final T element2; private final T element3; private final T element4; private final T element5; private final T element6; ImmutableSextupletonList(T obj1, T obj2, T obj3, T obj4, T obj5, T obj6) { this.element1 = obj1; this.element2 = obj2; this.element3 = obj3; this.element4 = obj4; this.element5 = obj5; this.element6 = obj6; } public int size() { return 6; } public void forEach(Procedure procedure) { procedure.value(this.element1); procedure.value(this.element2); procedure.value(this.element3); procedure.value(this.element4); procedure.value(this.element5); procedure.value(this.element6); } public T get(int index) { switch (index) { case 0: return this.element1; case 1: return this.element2; case 2: return this.element3; case 3: return this.element4; case 4: return this.element5; case 5: return this.element6; default: throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size()); } } public ImmutableList newWith(T newItem) { return Lists.immutable.of(this.get(0), this.get(1), this.get(2), this.get(3), this.get(4), this.get(5), newItem); } } ImmutableSingletonList.java000066400000000000000000000041571234315411400362430ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/immutable/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.immutable; import java.io.Serializable; import java.util.RandomAccess; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.list.ImmutableList; import com.gs.collections.impl.block.factory.Comparators; import com.gs.collections.impl.factory.Lists; import net.jcip.annotations.Immutable; /** * This is a single element immutable List which is created by calling * Immutable.newListWith(one) method. */ @Immutable final class ImmutableSingletonList extends AbstractImmutableList implements Serializable, RandomAccess { private static final long serialVersionUID = 1L; private final T element1; ImmutableSingletonList(T obj1) { this.element1 = obj1; } public int size() { return 1; } @Override public boolean contains(Object obj) { return Comparators.nullSafeEquals(obj, this.element1); } public void forEach(Procedure procedure) { procedure.value(this.element1); } public T get(int index) { if (index == 0) { return this.element1; } throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size()); } @Override public T getFirst() { return this.element1; } @Override public T getLast() { return this.element1; } public ImmutableList newWith(T newItem) { return Lists.immutable.of(this.get(0), newItem); } } ImmutableTripletonList.java000066400000000000000000000042701234315411400362550ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/immutable/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.immutable; import java.io.Serializable; import java.util.RandomAccess; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.list.ImmutableList; import com.gs.collections.impl.factory.Lists; import net.jcip.annotations.Immutable; /** * This is a three element immutable List which is created by calling * Immutable.newListWith(one, two, three) method. */ @Immutable final class ImmutableTripletonList extends AbstractImmutableList implements Serializable, RandomAccess { private static final long serialVersionUID = 1L; private final T element1; private final T element2; private final T element3; ImmutableTripletonList(T obj1, T obj2, T obj3) { this.element1 = obj1; this.element2 = obj2; this.element3 = obj3; } public int size() { return 3; } public void forEach(Procedure procedure) { procedure.value(this.element1); procedure.value(this.element2); procedure.value(this.element3); } public T get(int index) { switch (index) { case 0: return this.element1; case 1: return this.element2; case 2: return this.element3; default: throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size()); } } public ImmutableList newWith(T newItem) { return Lists.immutable.of(this.get(0), this.get(1), this.get(2), newItem); } } package-info.java000066400000000000000000000016461234315411400341310ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/immutable/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains implementations of the {@link com.gs.collections.api.list.ImmutableList} interface. *

* An {@link com.gs.collections.api.list.ImmutableList} is the non-modifiable equivalent interface to {@link com.gs.collections.api.list.MutableList}. *

*/ package com.gs.collections.impl.list.immutable; gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/immutable/primitive/000077500000000000000000000000001234315411400330225ustar00rootroot00000000000000ImmutableBooleanArrayList.java000066400000000000000000000375501234315411400406720ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/immutable/primitive/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.immutable.primitive; import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; import java.io.Serializable; import java.util.BitSet; import java.util.NoSuchElementException; import com.gs.collections.api.BooleanIterable; import com.gs.collections.api.LazyBooleanIterable; import com.gs.collections.api.bag.primitive.MutableBooleanBag; import com.gs.collections.api.block.function.primitive.BooleanToObjectFunction; import com.gs.collections.api.block.function.primitive.ObjectBooleanIntToObjectFunction; import com.gs.collections.api.block.function.primitive.ObjectBooleanToObjectFunction; import com.gs.collections.api.block.predicate.primitive.BooleanPredicate; import com.gs.collections.api.block.procedure.primitive.BooleanIntProcedure; import com.gs.collections.api.block.procedure.primitive.BooleanProcedure; import com.gs.collections.api.iterator.BooleanIterator; import com.gs.collections.api.list.ImmutableList; import com.gs.collections.api.list.primitive.BooleanList; import com.gs.collections.api.list.primitive.ImmutableBooleanList; import com.gs.collections.api.list.primitive.MutableBooleanList; import com.gs.collections.api.set.primitive.MutableBooleanSet; import com.gs.collections.impl.bag.mutable.primitive.BooleanHashBag; import com.gs.collections.impl.factory.primitive.BooleanLists; import com.gs.collections.impl.lazy.primitive.LazyBooleanIterableAdapter; import com.gs.collections.impl.lazy.primitive.ReverseBooleanIterable; import com.gs.collections.impl.list.mutable.FastList; import com.gs.collections.impl.list.mutable.primitive.BooleanArrayList; import com.gs.collections.impl.set.mutable.primitive.BooleanHashSet; import net.jcip.annotations.Immutable; /** * ImmutableBooleanArrayList is the non-modifiable equivalent of {@link BooleanArrayList}. * It is backed by a {@link BitSet}. * * @since 3.2. */ @Immutable final class ImmutableBooleanArrayList implements ImmutableBooleanList, Serializable { private static final long serialVersionUID = 1L; private final int size; private final BitSet items; private ImmutableBooleanArrayList(boolean[] newElements) { if (newElements.length <= 1) { throw new IllegalArgumentException("Use BooleanLists.immutable.with() to instantiate an optimized collection"); } this.size = newElements.length; this.items = new BitSet(newElements.length); for (int i = 0; i < newElements.length; i++) { if (newElements[i]) { this.items.set(i); } } } private ImmutableBooleanArrayList(BitSet newItems, int size) { this.size = size; this.items = newItems; } public static ImmutableBooleanArrayList newList(BooleanIterable iterable) { return new ImmutableBooleanArrayList(iterable.toArray()); } public static ImmutableBooleanArrayList newListWith(boolean... elements) { return new ImmutableBooleanArrayList(elements); } private IndexOutOfBoundsException newIndexOutOfBoundsException(int index) { return new IndexOutOfBoundsException("Index: " + index + " Size: " + this.size); } public boolean get(int index) { if (index < this.size) { return this.items.get(index); } throw this.newIndexOutOfBoundsException(index); } public boolean getFirst() { return this.items.get(0); } public boolean getLast() { return this.items.get(this.size - 1); } public int indexOf(boolean value) { for (int i = 0; i < this.size; i++) { if (this.items.get(i) == value) { return i; } } return -1; } public int lastIndexOf(boolean value) { for (int i = this.size - 1; i >= 0; i--) { if (this.items.get(i) == value) { return i; } } return -1; } public BooleanIterator booleanIterator() { return new InternalBooleanIterator(); } public void forEach(BooleanProcedure procedure) { for (int i = 0; i < this.size; i++) { procedure.value(this.items.get(i)); } } public void forEachWithIndex(BooleanIntProcedure procedure) { for (int i = 0; i < this.size; i++) { procedure.value(this.items.get(i), i); } } public int count(BooleanPredicate predicate) { int count = 0; for (int i = 0; i < this.size; i++) { if (predicate.accept(this.items.get(i))) { count++; } } return count; } public boolean anySatisfy(BooleanPredicate predicate) { for (int i = 0; i < this.size; i++) { if (predicate.accept(this.items.get(i))) { return true; } } return false; } public boolean allSatisfy(BooleanPredicate predicate) { for (int i = 0; i < this.size; i++) { if (!predicate.accept(this.items.get(i))) { return false; } } return true; } public boolean noneSatisfy(BooleanPredicate predicate) { for (int i = 0; i < this.size; i++) { if (predicate.accept(this.items.get(i))) { return false; } } return true; } public ImmutableBooleanList select(BooleanPredicate predicate) { BooleanArrayList result = new BooleanArrayList(); for (int i = 0; i < this.size; i++) { boolean item = this.items.get(i); if (predicate.accept(item)) { result.add(item); } } return result.toImmutable(); } public ImmutableBooleanList reject(BooleanPredicate predicate) { BooleanArrayList result = new BooleanArrayList(); for (int i = 0; i < this.size; i++) { boolean item = this.items.get(i); if (!predicate.accept(item)) { result.add(item); } } return result.toImmutable(); } public boolean detectIfNone(BooleanPredicate predicate, boolean ifNone) { for (int i = 0; i < this.size; i++) { boolean item = this.items.get(i); if (predicate.accept(item)) { return item; } } return ifNone; } public ImmutableList collect(BooleanToObjectFunction function) { FastList target = FastList.newList(this.size); for (int i = 0; i < this.size; i++) { target.add(function.valueOf(this.items.get(i))); } return target.toImmutable(); } public boolean[] toArray() { boolean[] newItems = new boolean[this.size]; for (int i = 0; i < this.size; i++) { newItems[i] = this.items.get(i); } return newItems; } public boolean contains(boolean value) { for (int i = 0; i < this.size; i++) { if (this.items.get(i) == value) { return true; } } return false; } public boolean containsAll(boolean... source) { for (boolean value : source) { if (!this.contains(value)) { return false; } } return true; } public boolean containsAll(BooleanIterable source) { for (BooleanIterator iterator = source.booleanIterator(); iterator.hasNext(); ) { if (!this.contains(iterator.next())) { return false; } } return true; } public LazyBooleanIterable asReversed() { return ReverseBooleanIterable.adapt(this); } public MutableBooleanList toList() { return BooleanArrayList.newList(this); } public MutableBooleanSet toSet() { return BooleanHashSet.newSet(this); } public MutableBooleanBag toBag() { return BooleanHashBag.newBag(this); } public LazyBooleanIterable asLazy() { return new LazyBooleanIterableAdapter(this); } public ImmutableBooleanList toImmutable() { return this; } public ImmutableBooleanArrayList toReversed() { return ImmutableBooleanArrayList.newList(this.asReversed()); } public ImmutableBooleanList newWith(boolean element) { BitSet newItems = (BitSet) this.items.clone(); if (element) { newItems.set(this.size); } return new ImmutableBooleanArrayList(newItems, this.size + 1); } public ImmutableBooleanList newWithout(boolean element) { int index = this.indexOf(element); if (index != -1) { boolean[] newItems = new boolean[this.size - 1]; for (int i = 0; i < index; i++) { newItems[i] = this.items.get(i); } for (int i = index + 1; i < this.size; i++) { newItems[i - 1] = this.items.get(i); } return BooleanLists.immutable.with(newItems); } return this; } public ImmutableBooleanList newWithAll(BooleanIterable elements) { BitSet newItems = (BitSet) this.items.clone(); int index = 0; for (BooleanIterator booleanIterator = elements.booleanIterator(); booleanIterator.hasNext(); index++) { if (booleanIterator.next()) { newItems.set(this.size + index); } } return new ImmutableBooleanArrayList(newItems, this.size + elements.size()); } public ImmutableBooleanList newWithoutAll(BooleanIterable elements) { MutableBooleanList list = this.toList(); list.removeAll(elements); return list.toImmutable(); } public int size() { return this.size; } public boolean isEmpty() { return false; } public boolean notEmpty() { return true; } @Override public boolean equals(Object otherList) { if (otherList == this) { return true; } if (!(otherList instanceof BooleanList)) { return false; } BooleanList list = (BooleanList) otherList; if (this.size != list.size()) { return false; } for (int i = 0; i < this.size; i++) { if (this.items.get(i) != list.get(i)) { return false; } } return true; } @Override public int hashCode() { int hashCode = 1; for (int i = 0; i < this.size; i++) { boolean item = this.items.get(i); hashCode = 31 * hashCode + (item ? 1231 : 1237); } return hashCode; } public T injectInto(T injectedValue, ObjectBooleanToObjectFunction function) { T result = injectedValue; for (int i = 0; i < this.size; i++) { result = function.valueOf(result, this.items.get(i)); } return result; } public T injectIntoWithIndex(T injectedValue, ObjectBooleanIntToObjectFunction function) { T result = injectedValue; for (int i = 0; i < this.size; i++) { result = function.valueOf(result, this.items.get(i), i); } return result; } @Override public String toString() { return this.makeString("[", ", ", "]"); } public String makeString() { return this.makeString(", "); } public String makeString(String separator) { return this.makeString("", separator, ""); } public String makeString(String start, String separator, String end) { Appendable stringBuilder = new StringBuilder(); this.appendString(stringBuilder, start, separator, end); return stringBuilder.toString(); } public void appendString(Appendable appendable) { this.appendString(appendable, ", "); } public void appendString(Appendable appendable, String separator) { this.appendString(appendable, "", separator, ""); } public void appendString( Appendable appendable, String start, String separator, String end) { try { appendable.append(start); for (int i = 0; i < this.size; i++) { if (i > 0) { appendable.append(separator); } boolean value = this.items.get(i); appendable.append(String.valueOf(value)); } appendable.append(end); } catch (IOException e) { throw new RuntimeException(e); } } public ImmutableBooleanList subList(int fromIndex, int toIndex) { throw new UnsupportedOperationException("subList not yet implemented!"); } private Object writeReplace() { return new ImmutableBooleanListSerializationProxy(this); } private static class ImmutableBooleanListSerializationProxy implements Externalizable { private static final long serialVersionUID = 1L; private ImmutableBooleanList list; public ImmutableBooleanListSerializationProxy() { // Empty constructor for Externalizable class } private ImmutableBooleanListSerializationProxy(ImmutableBooleanList list) { this.list = list; } public void writeExternal(ObjectOutput out) throws IOException { out.writeInt(this.list.size()); for (int i = 0; i < this.list.size(); i++) { out.writeBoolean(this.list.get(i)); } } public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { int inputSize = in.readInt(); BitSet newItems = new BitSet(inputSize); for (int i = 0; i < inputSize; i++) { newItems.set(i, in.readBoolean()); } this.list = new ImmutableBooleanArrayList(newItems, inputSize); } protected Object readResolve() { return this.list; } } private class InternalBooleanIterator implements BooleanIterator { /** * Index of element to be returned by subsequent call to next. */ private int currentIndex; public boolean hasNext() { return this.currentIndex != ImmutableBooleanArrayList.this.size; } public boolean next() { if (!this.hasNext()) { throw new NoSuchElementException(); } boolean next = ImmutableBooleanArrayList.this.get(this.currentIndex); this.currentIndex++; return next; } } } package-info.java000066400000000000000000000017361234315411400361410ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/immutable/primitive/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains implementations of immutable primitive list interfaces and immutable primitive list factory interfaces. *

* An {@link com.gs.collections.api.list.primitive.ImmutableIntList} is the non-modifiable equivalent interface of {@link com.gs.collections.api.list.primitive.MutableIntList}. *

*/ package com.gs.collections.impl.list.immutable.primitive; gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/mutable/000077500000000000000000000000001234315411400304645ustar00rootroot00000000000000AbstractListAdapter.java000066400000000000000000000225531234315411400351570ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/mutable/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.mutable; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.ListIterator; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.list.primitive.MutableBooleanList; import com.gs.collections.api.list.primitive.MutableByteList; import com.gs.collections.api.list.primitive.MutableCharList; import com.gs.collections.api.list.primitive.MutableDoubleList; import com.gs.collections.api.list.primitive.MutableFloatList; import com.gs.collections.api.list.primitive.MutableIntList; import com.gs.collections.api.list.primitive.MutableLongList; import com.gs.collections.api.list.primitive.MutableShortList; import com.gs.collections.api.multimap.list.MutableListMultimap; import com.gs.collections.api.partition.list.PartitionMutableList; import com.gs.collections.api.stack.MutableStack; import com.gs.collections.api.tuple.Pair; import com.gs.collections.impl.collection.mutable.AbstractCollectionAdapter; import com.gs.collections.impl.lazy.ReverseIterable; import com.gs.collections.impl.stack.mutable.ArrayStack; import com.gs.collections.impl.utility.ListIterate; @SuppressWarnings("AbstractMethodOverridesConcreteMethod") public abstract class AbstractListAdapter extends AbstractCollectionAdapter implements MutableList { @Override public MutableList clone() { try { return (MutableList) super.clone(); } catch (CloneNotSupportedException e) { throw new AssertionError(e); } } @Override protected abstract List getDelegate(); public boolean addAll(int index, Collection collection) { return this.getDelegate().addAll(index, collection); } public MutableList toReversed() { return FastList.newList(this).reverseThis(); } public MutableList reverseThis() { int mid = this.size() >> 1; int j = this.size() - 1; for (int i = 0; i < mid; i++, j--) { this.swapElements(i, j); } return this; } protected void swapElements(int i, int j) { this.set(i, this.set(j, this.get(i))); } public T get(int index) { return this.getDelegate().get(index); } public T set(int index, T element) { return this.getDelegate().set(index, element); } public void add(int index, T element) { this.getDelegate().add(index, element); } public T remove(int index) { return this.getDelegate().remove(index); } public int indexOf(Object o) { return this.getDelegate().indexOf(o); } public int lastIndexOf(Object o) { return this.getDelegate().lastIndexOf(o); } public ListIterator listIterator() { return this.getDelegate().listIterator(); } public ListIterator listIterator(int index) { return this.getDelegate().listIterator(index); } public MutableList subList(int fromIndex, int toIndex) { return ListAdapter.adapt(this.getDelegate().subList(fromIndex, toIndex)); } @Override public boolean equals(Object o) { return this.getDelegate().equals(o); } @Override public int hashCode() { return this.getDelegate().hashCode(); } public MutableStack toStack() { return ArrayStack.newStack(this.getDelegate()); } public ReverseIterable asReversed() { return ReverseIterable.adapt(this); } public int binarySearch(T key, Comparator comparator) { return Collections.binarySearch(this, key, comparator); } public int binarySearch(T key) { return Collections.binarySearch((List>) this, key); } @Override public MutableListMultimap groupBy(Function function) { return ListIterate.groupBy(this.getDelegate(), function); } @Override public MutableListMultimap groupByEach(Function> function) { return ListIterate.groupByEach(this.getDelegate(), function); } @Override public MutableList select(Predicate predicate) { return ListIterate.select(this.getDelegate(), predicate); } @Override public MutableList reject(Predicate predicate) { return ListIterate.reject(this.getDelegate(), predicate); } @Override public MutableList selectInstancesOf(Class clazz) { return ListIterate.selectInstancesOf(this.getDelegate(), clazz); } @Override public MutableList collect(Function function) { return ListIterate.collect(this.getDelegate(), function); } @Override public MutableBooleanList collectBoolean(BooleanFunction booleanFunction) { return ListIterate.collectBoolean(this.getDelegate(), booleanFunction); } @Override public MutableByteList collectByte(ByteFunction byteFunction) { return ListIterate.collectByte(this.getDelegate(), byteFunction); } @Override public MutableCharList collectChar(CharFunction charFunction) { return ListIterate.collectChar(this.getDelegate(), charFunction); } @Override public MutableDoubleList collectDouble(DoubleFunction doubleFunction) { return ListIterate.collectDouble(this.getDelegate(), doubleFunction); } @Override public MutableFloatList collectFloat(FloatFunction floatFunction) { return ListIterate.collectFloat(this.getDelegate(), floatFunction); } @Override public MutableIntList collectInt(IntFunction intFunction) { return ListIterate.collectInt(this.getDelegate(), intFunction); } @Override public MutableLongList collectLong(LongFunction longFunction) { return ListIterate.collectLong(this.getDelegate(), longFunction); } @Override public MutableShortList collectShort(ShortFunction shortFunction) { return ListIterate.collectShort(this.getDelegate(), shortFunction); } @Override public MutableList flatCollect(Function> function) { return ListIterate.flatCollect(this.getDelegate(), function); } @Override public MutableList collectIf(Predicate predicate, Function function) { return ListIterate.collectIf(this.getDelegate(), predicate, function); } @Override public PartitionMutableList partition(Predicate predicate) { return ListIterate.partition(this.getDelegate(), predicate); } @Override public

PartitionMutableList partitionWith(Predicate2 predicate, P parameter) { return ListIterate.partitionWith(this.getDelegate(), predicate, parameter); } @Override public

MutableList selectWith(Predicate2 predicate, P parameter) { return ListIterate.selectWith(this.getDelegate(), predicate, parameter); } @Override public

MutableList rejectWith(Predicate2 predicate, P parameter) { return ListIterate.rejectWith(this.getDelegate(), predicate, parameter); } @Override public MutableList collectWith(Function2 function, P parameter) { return ListIterate.collectWith(this.getDelegate(), function, parameter); } @Override public MutableList> zip(Iterable that) { return ListIterate.zip(this.getDelegate(), that); } @Override public MutableList> zipWithIndex() { return ListIterate.zipWithIndex(this.getDelegate()); } } AbstractMutableList.java000066400000000000000000001006231234315411400351630ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/mutable/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.mutable; import java.io.Serializable; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.NoSuchElementException; import java.util.RandomAccess; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.Function3; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.FloatObjectToFloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.IntObjectToIntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.LongObjectToLongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.list.ImmutableList; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.list.primitive.MutableBooleanList; import com.gs.collections.api.list.primitive.MutableByteList; import com.gs.collections.api.list.primitive.MutableCharList; import com.gs.collections.api.list.primitive.MutableDoubleList; import com.gs.collections.api.list.primitive.MutableFloatList; import com.gs.collections.api.list.primitive.MutableIntList; import com.gs.collections.api.list.primitive.MutableLongList; import com.gs.collections.api.list.primitive.MutableShortList; import com.gs.collections.api.map.MutableMap; import com.gs.collections.api.partition.list.PartitionMutableList; import com.gs.collections.api.set.MutableSet; import com.gs.collections.api.stack.MutableStack; import com.gs.collections.api.tuple.Pair; import com.gs.collections.api.tuple.Twin; import com.gs.collections.impl.block.factory.Comparators; import com.gs.collections.impl.block.factory.Predicates2; import com.gs.collections.impl.block.procedure.primitive.CollectBooleanProcedure; import com.gs.collections.impl.block.procedure.primitive.CollectByteProcedure; import com.gs.collections.impl.block.procedure.primitive.CollectCharProcedure; import com.gs.collections.impl.block.procedure.primitive.CollectDoubleProcedure; import com.gs.collections.impl.block.procedure.primitive.CollectFloatProcedure; import com.gs.collections.impl.block.procedure.primitive.CollectIntProcedure; import com.gs.collections.impl.block.procedure.primitive.CollectLongProcedure; import com.gs.collections.impl.block.procedure.primitive.CollectShortProcedure; import com.gs.collections.impl.collection.mutable.AbstractMutableCollection; import com.gs.collections.impl.factory.Lists; import com.gs.collections.impl.factory.Stacks; import com.gs.collections.impl.lazy.ReverseIterable; import com.gs.collections.impl.list.mutable.primitive.BooleanArrayList; import com.gs.collections.impl.list.mutable.primitive.ByteArrayList; import com.gs.collections.impl.list.mutable.primitive.CharArrayList; import com.gs.collections.impl.list.mutable.primitive.DoubleArrayList; import com.gs.collections.impl.list.mutable.primitive.FloatArrayList; import com.gs.collections.impl.list.mutable.primitive.IntArrayList; import com.gs.collections.impl.list.mutable.primitive.LongArrayList; import com.gs.collections.impl.list.mutable.primitive.ShortArrayList; import com.gs.collections.impl.multimap.list.FastListMultimap; import com.gs.collections.impl.set.mutable.UnifiedSet; import com.gs.collections.impl.stack.mutable.ArrayStack; import com.gs.collections.impl.utility.Iterate; import com.gs.collections.impl.utility.ListIterate; public abstract class AbstractMutableList extends AbstractMutableCollection implements MutableList { @Override public MutableList clone() { try { return (MutableList) super.clone(); } catch (CloneNotSupportedException e) { throw new AssertionError(e); } } @Override public boolean equals(Object o) { if (o == this) { return true; } if (!(o instanceof List)) { return false; } List that = (List) o; return that instanceof RandomAccess ? this.randomAccessEquals(that) : this.nonRandomAccessEquals(that); } private boolean randomAccessEquals(List that) { if (this.size() != that.size()) { return false; } for (int i = 0; i < this.size(); i++) { if (!Comparators.nullSafeEquals(this.get(i), that.get(i))) { return false; } } return true; } private boolean nonRandomAccessEquals(List that) { Iterator iterator = that.iterator(); for (int i = 0; i < this.size(); i++) { if (!iterator.hasNext()) { return false; } if (!Comparators.nullSafeEquals(this.get(i), iterator.next())) { return false; } } return !iterator.hasNext(); } @Override public int hashCode() { int hashCode = 1; for (int i = 0; i < this.size(); i++) { T obj = this.get(i); hashCode = 31 * hashCode + (obj == null ? 0 : obj.hashCode()); } return hashCode; } public void forEach(Procedure procedure) { ListIterate.forEach(this, procedure); } public void reverseForEach(Procedure procedure) { if (this.notEmpty()) { this.forEach(this.size() - 1, 0, procedure); } } @Override public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { ListIterate.forEachWithIndex(this, objectIntProcedure); } @Override public

void forEachWith(Procedure2 procedure, P parameter) { ListIterate.forEachWith(this, procedure, parameter); } public void forEachWithIndex(int fromIndex, int toIndex, ObjectIntProcedure objectIntProcedure) { ListIterate.forEachWithIndex(this, fromIndex, toIndex, objectIntProcedure); } public MutableList select(Predicate predicate) { return this.select(predicate, this.newEmpty()); } @Override public > R select(Predicate predicate, R target) { return ListIterate.select(this, predicate, target); } public

MutableList selectWith(Predicate2 predicate, P parameter) { return this.selectWith(predicate, parameter, this.newEmpty()); } @Override public > R selectWith( Predicate2 predicate, P parameter, R targetCollection) { return ListIterate.selectWith(this, predicate, parameter, targetCollection); } public MutableList reject(Predicate predicate) { return this.reject(predicate, this.newEmpty()); } @Override public > R reject(Predicate predicate, R target) { return ListIterate.reject(this, predicate, target); } public

MutableList rejectWith(Predicate2 predicate, P parameter) { return this.rejectWith(predicate, parameter, this.newEmpty()); } @Override public > R rejectWith( Predicate2 predicate, P parameter, R targetCollection) { return ListIterate.rejectWith(this, predicate, parameter, targetCollection); } @Override public

Twin> selectAndRejectWith( Predicate2 predicate, P parameter) { return ListIterate.selectAndRejectWith(this, predicate, parameter); } public PartitionMutableList partition(Predicate predicate) { return ListIterate.partition(this, predicate); } public

PartitionMutableList partitionWith(Predicate2 predicate, P parameter) { return ListIterate.partitionWith(this, predicate, parameter); } public MutableList selectInstancesOf(Class clazz) { return ListIterate.selectInstancesOf(this, clazz); } @Override public void removeIf(Predicate predicate) { ListIterate.removeIf(this, predicate); } @Override public

void removeIfWith(Predicate2 predicate, P parameter) { ListIterate.removeIfWith(this, predicate, parameter); } public MutableList collect(Function function) { return this.collect(function, FastList.newList()); } public MutableBooleanList collectBoolean(BooleanFunction booleanFunction) { BooleanArrayList result = new BooleanArrayList(this.size()); this.forEach(new CollectBooleanProcedure(booleanFunction, result)); return result; } public MutableByteList collectByte(ByteFunction byteFunction) { ByteArrayList result = new ByteArrayList(this.size()); this.forEach(new CollectByteProcedure(byteFunction, result)); return result; } public MutableCharList collectChar(CharFunction charFunction) { CharArrayList result = new CharArrayList(this.size()); this.forEach(new CollectCharProcedure(charFunction, result)); return result; } public MutableDoubleList collectDouble(DoubleFunction doubleFunction) { DoubleArrayList result = new DoubleArrayList(this.size()); this.forEach(new CollectDoubleProcedure(doubleFunction, result)); return result; } public MutableFloatList collectFloat(FloatFunction floatFunction) { FloatArrayList result = new FloatArrayList(this.size()); this.forEach(new CollectFloatProcedure(floatFunction, result)); return result; } public MutableIntList collectInt(IntFunction intFunction) { IntArrayList result = new IntArrayList(this.size()); this.forEach(new CollectIntProcedure(intFunction, result)); return result; } public MutableLongList collectLong(LongFunction longFunction) { LongArrayList result = new LongArrayList(this.size()); this.forEach(new CollectLongProcedure(longFunction, result)); return result; } public MutableShortList collectShort(ShortFunction shortFunction) { ShortArrayList result = new ShortArrayList(this.size()); this.forEach(new CollectShortProcedure(shortFunction, result)); return result; } @Override public > R collect(Function function, R target) { return ListIterate.collect(this, function, target); } public MutableList flatCollect(Function> function) { return this.flatCollect(function, FastList.newList()); } @Override public > R flatCollect( Function> function, R target) { return ListIterate.flatCollect(this, function, target); } public MutableList collectWith(Function2 function, P parameter) { return this.collectWith(function, parameter, FastList.newList()); } @Override public > R collectWith( Function2 function, P parameter, R targetCollection) { return ListIterate.collectWith(this, function, parameter, targetCollection); } public MutableList collectIf( Predicate predicate, Function function) { return this.collectIf(predicate, function, FastList.newList()); } @Override public > R collectIf( Predicate predicate, Function function, R target) { return ListIterate.collectIf(this, predicate, function, target); } @Override public T detect(Predicate predicate) { return ListIterate.detect(this, predicate); } @Override public T detectIfNone(Predicate predicate, Function0 function) { T result = ListIterate.detect(this, predicate); return result == null ? function.value() : result; } @Override public T min(Comparator comparator) { return ListIterate.min(this, comparator); } @Override public T max(Comparator comparator) { return ListIterate.max(this, comparator); } @Override public T min() { return ListIterate.min(this); } @Override public T max() { return ListIterate.max(this); } @Override public > T minBy(Function function) { return ListIterate.minBy(this, function); } @Override public > T maxBy(Function function) { return ListIterate.maxBy(this, function); } @Override public

T detectWith(Predicate2 predicate, P parameter) { return ListIterate.detectWith(this, predicate, parameter); } @Override public

T detectWithIfNone( Predicate2 predicate, P parameter, Function0 function) { T result = ListIterate.detectWith(this, predicate, parameter); return result == null ? function.value() : result; } @Override public int count(Predicate predicate) { return ListIterate.count(this, predicate); } @Override public

int countWith(Predicate2 predicate, P parameter) { return ListIterate.countWith(this, predicate, parameter); } @Override public boolean anySatisfy(Predicate predicate) { return ListIterate.anySatisfy(this, predicate); } @Override public

boolean anySatisfyWith(Predicate2 predicate, P parameter) { return ListIterate.anySatisfyWith(this, predicate, parameter); } @Override public boolean allSatisfy(Predicate predicate) { return ListIterate.allSatisfy(this, predicate); } @Override public

boolean allSatisfyWith(Predicate2 predicate, P parameter) { return ListIterate.allSatisfyWith(this, predicate, parameter); } @Override public boolean noneSatisfy(Predicate predicate) { return ListIterate.noneSatisfy(this, predicate); } @Override public

boolean noneSatisfyWith(Predicate2 predicate, P parameter) { return ListIterate.noneSatisfyWith(this, predicate, parameter); } @Override public IV injectInto(IV injectedValue, Function2 function) { return ListIterate.injectInto(injectedValue, this, function); } @Override public int injectInto(int injectedValue, IntObjectToIntFunction function) { return ListIterate.injectInto(injectedValue, this, function); } @Override public float injectInto(float injectedValue, FloatObjectToFloatFunction function) { return ListIterate.injectInto(injectedValue, this, function); } public MutableList distinct() { return ListIterate.distinct(this, this.newEmpty()); } @Override public long sumOfInt(IntFunction function) { return ListIterate.sumOfInt(this, function); } @Override public long sumOfLong(LongFunction function) { return ListIterate.sumOfLong(this, function); } @Override public double sumOfFloat(FloatFunction function) { return ListIterate.sumOfFloat(this, function); } @Override public double sumOfDouble(DoubleFunction function) { return ListIterate.sumOfDouble(this, function); } @Override public long injectInto(long injectedValue, LongObjectToLongFunction function) { return ListIterate.injectInto(injectedValue, this, function); } @Override public IV injectIntoWith( IV injectValue, Function3 function, P parameter) { return ListIterate.injectIntoWith(injectValue, this, function, parameter); } @Override public MutableList toList() { return FastList.newList(this); } @Override public MutableList toSortedList() { return this.toSortedList(Comparators.naturalOrder()); } @Override public MutableList toSortedList(Comparator comparator) { return this.toList().sortThis(comparator); } @Override public MutableSet toSet() { return UnifiedSet.newSet(this); } public MutableStack toStack() { return Stacks.mutable.ofAll(this); } public MutableList asUnmodifiable() { return UnmodifiableMutableList.of(this); } public ImmutableList toImmutable() { return Lists.immutable.ofAll(this); } public MutableList asSynchronized() { return SynchronizedMutableList.of(this); } public MutableList sortThis(Comparator comparator) { if (this.size() < 10) { if (comparator == null) { this.insertionSort(); } else { this.insertionSort(comparator); } } else { this.defaultSort(comparator); } return this; } /** * Override in subclasses where it can be optimized. */ protected void defaultSort(Comparator comparator) { Collections.sort(this, comparator); } private void insertionSort(Comparator comparator) { for (int i = 0; i < this.size(); i++) { for (int j = i; j > 0 && comparator.compare(this.get(j - 1), this.get(j)) > 0; j--) { Collections.swap(this, j, j - 1); } } } private void insertionSort() { for (int i = 0; i < this.size(); i++) { for (int j = i; j > 0 && ((Comparable) this.get(j - 1)).compareTo(this.get(j)) > 0; j--) { Collections.swap(this, j, j - 1); } } } public MutableList sortThis() { return this.sortThis(Comparators.naturalOrder()); } public > MutableList sortThisBy(Function function) { return this.sortThis(Comparators.byFunction(function)); } public MutableList newEmpty() { return Lists.mutable.of(); } public void forEach(int from, int to, Procedure procedure) { ListIterate.forEach(this, from, to, procedure); } public int indexOf(Object o) { if (o == null) { for (int i = 0; i < this.size(); i++) { if (this.get(i) == null) { return i; } } } else { for (int i = 0; i < this.size(); i++) { if (o.equals(this.get(i))) { return i; } } } return -1; } public int lastIndexOf(Object o) { if (o == null) { for (int i = this.size(); i-- > 0; ) { if (this.get(i) == null) { return i; } } } else { for (int i = this.size(); i-- > 0; ) { if (o.equals(this.get(i))) { return i; } } } return -1; } public Iterator iterator() { return new MutableIterator(this); } public ListIterator listIterator() { return this.listIterator(0); } public ListIterator listIterator(int index) { if (index < 0 || index > this.size()) { throw new IndexOutOfBoundsException("Index: " + index); } return new MutableListIterator(this, index); } public MutableList toReversed() { return FastList.newList(this).reverseThis(); } public MutableList reverseThis() { Collections.reverse(this); return this; } public MutableList subList(int fromIndex, int toIndex) { return new SubList(this, fromIndex, toIndex); } protected static class SubList extends AbstractMutableList implements Serializable, RandomAccess { // Not important since it uses writeReplace() private static final long serialVersionUID = 1L; private final MutableList original; private final int offset; private int size; protected SubList(AbstractMutableList list, int fromIndex, int toIndex) { if (fromIndex < 0) { throw new IndexOutOfBoundsException("fromIndex = " + fromIndex); } if (toIndex > list.size()) { throw new IndexOutOfBoundsException("toIndex = " + toIndex); } if (fromIndex > toIndex) { throw new IllegalArgumentException("fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ')'); } this.original = list; this.offset = fromIndex; this.size = toIndex - fromIndex; } @Override public MutableList toReversed() { return FastList.newList(this).reverseThis(); } protected Object writeReplace() { return FastList.newList(this); } @Override public boolean add(T o) { this.original.add(this.offset + this.size, o); this.size++; return true; } public T set(int index, T element) { this.checkIfOutOfBounds(index); return this.original.set(index + this.offset, element); } public T get(int index) { this.checkIfOutOfBounds(index); return this.original.get(index + this.offset); } public int size() { return this.size; } public void add(int index, T element) { this.checkIfOutOfBounds(index); this.original.add(index + this.offset, element); this.size++; } public T remove(int index) { this.checkIfOutOfBounds(index); T result = this.original.remove(index + this.offset); this.size--; return result; } public void clear() { for (Iterator iterator = this.iterator(); iterator.hasNext(); ) { iterator.next(); iterator.remove(); } } @Override public boolean addAll(Collection collection) { return this.addAll(this.size, collection); } public boolean addAll(int index, Collection collection) { if (index < 0 || index > this.size) { throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size); } int cSize = collection.size(); if (cSize == 0) { return false; } this.original.addAll(this.offset + index, collection); this.size += cSize; return true; } @Override public Iterator iterator() { return this.listIterator(); } @Override public ListIterator listIterator(final int index) { if (index < 0 || index > this.size) { throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size); } return new ListIterator() { private final ListIterator listIterator = SubList.this.original.listIterator(index + SubList.this.offset); public boolean hasNext() { return this.nextIndex() < SubList.this.size; } public T next() { if (this.hasNext()) { return this.listIterator.next(); } throw new NoSuchElementException(); } public boolean hasPrevious() { return this.previousIndex() >= 0; } public T previous() { if (this.hasPrevious()) { return this.listIterator.previous(); } throw new NoSuchElementException(); } public int nextIndex() { return this.listIterator.nextIndex() - SubList.this.offset; } public int previousIndex() { return this.listIterator.previousIndex() - SubList.this.offset; } public void remove() { this.listIterator.remove(); SubList.this.size--; } public void set(T o) { this.listIterator.set(o); } public void add(T o) { this.listIterator.add(o); SubList.this.size++; } }; } @Override public MutableList subList(int fromIndex, int toIndex) { return new SubList(this, fromIndex, toIndex); } private void checkIfOutOfBounds(int index) { if (index >= this.size || index < 0) { throw new IndexOutOfBoundsException("Index: " + index + " Size: " + this.size); } } // Weird implementation of clone() is ok on final classes @Override public MutableList clone() { return new FastList(this); } @Override public T getFirst() { return this.isEmpty() ? null : this.original.get(this.offset); } @Override public T getLast() { return this.isEmpty() ? null : this.original.get(this.offset + this.size - 1); } @Override public MutableStack toStack() { return ArrayStack.newStack(this); } @Override public void forEach(Procedure procedure) { ListIterate.forEach(this, procedure); } @Override public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { ListIterate.forEachWithIndex(this, objectIntProcedure); } @Override public

void forEachWith(Procedure2 procedure, P parameter) { ListIterate.forEachWith(this, procedure, parameter); } } @Override public boolean contains(Object object) { return this.indexOf(object) > -1; } @Override public boolean containsAll(Collection source) { return Iterate.allSatisfyWith(source, Predicates2.in(), this); } @Override public boolean removeAll(Collection collection) { int currentSize = this.size(); this.removeIfWith(Predicates2.in(), collection); return currentSize != this.size(); } @Override public boolean retainAll(Collection collection) { int currentSize = this.size(); this.removeIfWith(Predicates2.notIn(), collection); return currentSize != this.size(); } public T getFirst() { return ListIterate.getFirst(this); } public T getLast() { return ListIterate.getLast(this); } @Override public void appendString(Appendable appendable, String start, String separator, String end) { ListIterate.appendString(this, appendable, start, separator, end); } public FastListMultimap groupBy(Function function) { return ListIterate.groupBy(this, function); } public FastListMultimap groupByEach(Function> function) { return ListIterate.groupByEach(this, function); } public MutableMap groupByUniqueKey(Function function) { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".groupByUniqueKey() not implemented yet"); } public MutableList> zip(Iterable that) { return ListIterate.zip(this, that); } public MutableList> zipWithIndex() { return ListIterate.zipWithIndex(this); } public MutableList with(T element) { this.add(element); return this; } public MutableList without(T element) { this.remove(element); return this; } public MutableList withAll(Iterable elements) { this.addAllIterable(elements); return this; } public MutableList withoutAll(Iterable elements) { this.removeAllIterable(elements); return this; } public ReverseIterable asReversed() { return ReverseIterable.adapt(this); } public int binarySearch(T key, Comparator comparator) { return Collections.binarySearch(this, key, comparator); } public int binarySearch(T key) { return Collections.binarySearch((List>) this, key); } public MutableList takeWhile(Predicate predicate) { return ListIterate.takeWhile(this, predicate); } public MutableList dropWhile(Predicate predicate) { return ListIterate.dropWhile(this, predicate); } public PartitionMutableList partitionWhile(Predicate predicate) { return ListIterate.partitionWhile(this, predicate); } } ArrayListAdapter.java000066400000000000000000000367531234315411400345010ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/mutable/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.mutable; import java.io.Serializable; import java.util.ArrayList; import java.util.Comparator; import java.util.RandomAccess; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.list.ImmutableList; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.list.primitive.MutableBooleanList; import com.gs.collections.api.list.primitive.MutableByteList; import com.gs.collections.api.list.primitive.MutableCharList; import com.gs.collections.api.list.primitive.MutableDoubleList; import com.gs.collections.api.list.primitive.MutableFloatList; import com.gs.collections.api.list.primitive.MutableIntList; import com.gs.collections.api.list.primitive.MutableLongList; import com.gs.collections.api.list.primitive.MutableShortList; import com.gs.collections.api.partition.list.PartitionMutableList; import com.gs.collections.api.tuple.Pair; import com.gs.collections.impl.block.factory.Comparators; import com.gs.collections.impl.block.procedure.CollectionAddProcedure; import com.gs.collections.impl.factory.Lists; import com.gs.collections.impl.lazy.ReverseIterable; import com.gs.collections.impl.list.mutable.primitive.BooleanArrayList; import com.gs.collections.impl.list.mutable.primitive.ByteArrayList; import com.gs.collections.impl.list.mutable.primitive.CharArrayList; import com.gs.collections.impl.list.mutable.primitive.DoubleArrayList; import com.gs.collections.impl.list.mutable.primitive.FloatArrayList; import com.gs.collections.impl.list.mutable.primitive.IntArrayList; import com.gs.collections.impl.list.mutable.primitive.LongArrayList; import com.gs.collections.impl.list.mutable.primitive.ShortArrayList; import com.gs.collections.impl.multimap.list.FastListMultimap; import com.gs.collections.impl.utility.ArrayIterate; import com.gs.collections.impl.utility.ArrayListIterate; import com.gs.collections.impl.utility.Iterate; /** * This class provides a MutableList wrapper around a JDK Collections ArrayList instance. All of the MutableList * interface methods are supported in addition to the JDK ArrayList methods. *

* To create a new wrapper around an existing ArrayList instance, use the {@link #adapt(ArrayList)} factory method. To * create a new empty wrapper, use the {@link #newList()} or {@link #newList(int)} factory methods. */ public final class ArrayListAdapter extends AbstractListAdapter implements RandomAccess, Serializable { private static final long serialVersionUID = 1L; private final ArrayList delegate; private ArrayListAdapter(ArrayList newDelegate) { if (newDelegate == null) { throw new NullPointerException("ArrayListAdapter may not wrap null"); } this.delegate = newDelegate; } @Override protected ArrayList getDelegate() { return this.delegate; } public static ArrayListAdapter newList() { return new ArrayListAdapter(new ArrayList()); } public static ArrayListAdapter newList(int size) { return new ArrayListAdapter(new ArrayList(size)); } public static ArrayListAdapter adapt(ArrayList newDelegate) { return new ArrayListAdapter(newDelegate); } public MutableList asUnmodifiable() { return UnmodifiableMutableList.of(this); } public MutableList asSynchronized() { return SynchronizedMutableList.of(this); } public ImmutableList toImmutable() { return Lists.immutable.ofAll(this); } @Override public ArrayListAdapter clone() { return new ArrayListAdapter((ArrayList) this.delegate.clone()); } public ArrayListAdapter newEmpty() { return ArrayListAdapter.newList(); } @Override public void forEach(Procedure procedure) { ArrayListIterate.forEach(this.delegate, procedure); } public void reverseForEach(Procedure procedure) { ArrayListIterate.reverseForEach(this.delegate, procedure); } @Override public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { ArrayListIterate.forEachWithIndex(this.delegate, objectIntProcedure); } public void forEachWithIndex(int fromIndex, int toIndex, ObjectIntProcedure objectIntProcedure) { ArrayListIterate.forEachWithIndex(this.delegate, fromIndex, toIndex, objectIntProcedure); } @Override public T detect(Predicate predicate) { return ArrayListIterate.detect(this.delegate, predicate); } @Override public T detectIfNone(Predicate predicate, Function0 function) { T result = this.detect(predicate); return result == null ? function.value() : result; } @Override public int count(Predicate predicate) { return ArrayListIterate.count(this.delegate, predicate); } @Override public boolean anySatisfy(Predicate predicate) { return ArrayListIterate.anySatisfy(this.delegate, predicate); } @Override public boolean allSatisfy(Predicate predicate) { return ArrayListIterate.allSatisfy(this.delegate, predicate); } @Override public boolean noneSatisfy(Predicate predicate) { return ArrayListIterate.noneSatisfy(this.delegate, predicate); } @Override public IV injectInto(IV injectedValue, Function2 function) { return ArrayListIterate.injectInto(injectedValue, this.delegate, function); } public void forEach(int fromIndex, int toIndex, Procedure procedure) { ArrayListIterate.forEach(this.delegate, fromIndex, toIndex, procedure); } public ArrayListAdapter sortThis(Comparator comparator) { Iterate.sortThis(this.delegate, comparator); return this; } public ArrayListAdapter sortThis() { return this.sortThis(Comparators.naturalOrder()); } public > MutableList sortThisBy(Function function) { return this.sortThis(Comparators.byFunction(function)); } public ArrayListAdapter with(T element) { this.add(element); return this; } public ArrayListAdapter with(T element1, T element2) { this.add(element1); this.add(element2); return this; } public ArrayListAdapter with(T element1, T element2, T element3) { this.add(element1); this.add(element2); this.add(element3); return this; } public ArrayListAdapter with(T... elements) { ArrayIterate.forEach(elements, CollectionAddProcedure.on(this.delegate)); return this; } public ArrayListAdapter without(T element) { this.remove(element); return this; } public ArrayListAdapter withAll(Iterable elements) { this.addAllIterable(elements); return this; } public ArrayListAdapter withoutAll(Iterable elements) { this.removeAllIterable(elements); return this; } private ArrayListAdapter wrap(ArrayList list) { return ArrayListAdapter.adapt(list); } @Override public ArrayListAdapter select(Predicate predicate) { return this.wrap(ArrayListIterate.select(this.delegate, predicate)); } @Override public ArrayListAdapter reject(Predicate predicate) { return this.wrap(ArrayListIterate.reject(this.delegate, predicate)); } @Override public PartitionMutableList partition(Predicate predicate) { return ArrayListIterate.partition(this.delegate, predicate); } @Override public

PartitionMutableList partitionWith(Predicate2 predicate, P parameter) { return ArrayListIterate.partitionWith(this.getDelegate(), predicate, parameter); } @Override public MutableList selectInstancesOf(Class clazz) { return ArrayListIterate.selectInstancesOf(this.delegate, clazz); } @Override public ArrayListAdapter collect(Function function) { return this.wrap(ArrayListIterate.collect(this.delegate, function)); } @Override public MutableBooleanList collectBoolean(final BooleanFunction booleanFunction) { final BooleanArrayList result = new BooleanArrayList(this.size()); this.forEach(new Procedure() { public void value(T each) { result.add(booleanFunction.booleanValueOf(each)); } }); return result; } @Override public MutableByteList collectByte(final ByteFunction byteFunction) { final ByteArrayList result = new ByteArrayList(this.size()); this.forEach(new Procedure() { public void value(T each) { result.add(byteFunction.byteValueOf(each)); } }); return result; } @Override public MutableCharList collectChar(final CharFunction charFunction) { final CharArrayList result = new CharArrayList(this.size()); this.forEach(new Procedure() { public void value(T each) { result.add(charFunction.charValueOf(each)); } }); return result; } @Override public MutableDoubleList collectDouble(final DoubleFunction doubleFunction) { final DoubleArrayList result = new DoubleArrayList(this.size()); this.forEach(new Procedure() { public void value(T each) { result.add(doubleFunction.doubleValueOf(each)); } }); return result; } @Override public MutableFloatList collectFloat(final FloatFunction floatFunction) { final FloatArrayList result = new FloatArrayList(this.size()); this.forEach(new Procedure() { public void value(T each) { result.add(floatFunction.floatValueOf(each)); } }); return result; } @Override public MutableIntList collectInt(final IntFunction intFunction) { final IntArrayList result = new IntArrayList(this.size()); this.forEach(new Procedure() { public void value(T each) { result.add(intFunction.intValueOf(each)); } }); return result; } @Override public MutableLongList collectLong(final LongFunction longFunction) { final LongArrayList result = new LongArrayList(this.size()); this.forEach(new Procedure() { public void value(T each) { result.add(longFunction.longValueOf(each)); } }); return result; } @Override public MutableShortList collectShort(final ShortFunction shortFunction) { final ShortArrayList result = new ShortArrayList(this.size()); this.forEach(new Procedure() { public void value(T each) { result.add(shortFunction.shortValueOf(each)); } }); return result; } @Override public ArrayListAdapter flatCollect(Function> function) { return this.wrap(ArrayListIterate.flatCollect(this.delegate, function)); } @Override public ArrayListAdapter collectIf(Predicate predicate, Function function) { return this.wrap(ArrayListIterate.collectIf(this.delegate, predicate, function)); } @Override public FastListMultimap groupBy(Function function) { return ArrayListIterate.groupBy(this.delegate, function); } @Override public FastListMultimap groupByEach(Function> function) { return ArrayListIterate.groupByEach(this.delegate, function); } @Override public

ArrayListAdapter selectWith(Predicate2 predicate, P parameter) { return this.wrap(ArrayListIterate.selectWith(this.delegate, predicate, parameter)); } @Override public

ArrayListAdapter rejectWith(Predicate2 predicate, P parameter) { return this.wrap(ArrayListIterate.rejectWith(this.delegate, predicate, parameter)); } @Override public ArrayListAdapter collectWith(Function2 function, P parameter) { return this.wrap(ArrayListIterate.collectWith(this.delegate, function, parameter)); } public ArrayListAdapter distinct() { return this.wrap(ArrayListIterate.distinct(this.delegate)); } @Override public MutableList> zip(Iterable that) { return ArrayListIterate.zip(this.delegate, that); } @Override public MutableList> zipWithIndex() { return ArrayListIterate.zipWithIndex(this.delegate); } public MutableList takeWhile(Predicate predicate) { return ArrayListIterate.takeWhile(this.delegate, predicate); } public MutableList dropWhile(Predicate predicate) { return ArrayListIterate.dropWhile(this.delegate, predicate); } public PartitionMutableList partitionWhile(Predicate predicate) { return ArrayListIterate.partitionWhile(this.delegate, predicate); } @Override public ReverseIterable asReversed() { return ReverseIterable.adapt(this); } } CompositeFastList.java000066400000000000000000000446431234315411400346770ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/mutable/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.mutable; import java.io.Serializable; import java.lang.reflect.Array; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.NoSuchElementException; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.list.MutableList; import com.gs.collections.impl.block.factory.Comparators; import com.gs.collections.impl.block.factory.Predicates; import com.gs.collections.impl.block.factory.Procedures; import com.gs.collections.impl.factory.Lists; import com.gs.collections.impl.parallel.ParallelIterate; import com.gs.collections.impl.utility.Iterate; import com.gs.collections.impl.utility.ListIterate; /** * CompositeFastList behaves like a list, but is composed of at least one list. * It is useful where you don't want the additional expense of appending several lists or allocating memory * for a super list to add multiple sublists to.

* Note: mutation operations (e.g. add and remove, sorting) will change the underlying * lists - so be sure to only use a composite list where it will be the only reference to the sublists * (for example, a composite list which contains multiple query results is OK as long * as it is the only thing that references the lists) */ public final class CompositeFastList extends AbstractMutableList implements Serializable { private static final Predicate2, Object> REMOVE_PREDICATE = new Predicate2, Object>() { public boolean accept(FastList list, Object toRemove) { return list.remove(toRemove); } }; private static final Procedure> REVERSE_LIST_PROCEDURE = new Procedure>() { public void value(FastList each) { each.reverseThis(); } }; private static final long serialVersionUID = 1L; private final FastList> lists = FastList.newList(); @Override public MutableList clone() { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".clone() not implemented yet"); } public int size() { int size = 0; for (int i = this.lists.size() - 1; i >= 0; i--) { size += this.lists.get(i).size(); } return size; } @Override public CompositeFastList reverseThis() { ParallelIterate.forEach(this.lists, REVERSE_LIST_PROCEDURE); this.lists.reverseThis(); return this; } @Override public void forEach(final Procedure procedure) { this.lists.forEach(new Procedure>() { public void value(FastList list) { list.forEach(procedure); } }); } @Override public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { this.lists.forEach(new ProcedureToInnerListObjectIntProcedure(objectIntProcedure)); } @Override public void reverseForEach(final Procedure procedure) { this.lists.reverseForEach(new Procedure>() { public void value(FastList each) { each.reverseForEach(procedure); } }); } @Override public void forEach(int fromIndex, int toIndex, Procedure procedure) { ListIterate.rangeCheck(fromIndex, toIndex, this.size()); if (fromIndex > toIndex) { super.forEach(fromIndex, toIndex, procedure); } else { this.optimizedForwardForEach(procedure, fromIndex, toIndex); } } private void optimizedForwardForEach(Procedure procedure, int fromIndex, int toIndex) { toIndex++; int outerIndex = 0; int size; // Find first list in the range FastList> fastList = this.lists; Object[] items = fastList.items; while ((size = ((FastList) items[outerIndex]).size()) <= fromIndex) { fromIndex -= size; toIndex -= size; outerIndex++; } while (true) { FastList list = (FastList) items[outerIndex++]; int end = list.size(); if (toIndex < end) { end = toIndex; } for (int j = fromIndex; j < end; j++) { procedure.value(list.items[j]); } toIndex -= end; if (toIndex == 0) { return; } fromIndex = 0; } } @Override public void forEachWithIndex(int fromIndex, int toIndex, ObjectIntProcedure objectIntProcedure) { ListIterate.rangeCheck(fromIndex, toIndex, this.size()); if (fromIndex > toIndex) { super.forEachWithIndex(fromIndex, toIndex, objectIntProcedure); } else { this.optimizedForwardForEach(Procedures.fromObjectIntProcedure(objectIntProcedure), fromIndex, toIndex); } } @Override public

void forEachWith( final Procedure2 procedure2, final P parameter) { this.lists.forEach(new Procedure>() { public void value(FastList list) { list.forEachWith(procedure2, parameter); } }); } @Override public boolean isEmpty() { return this.lists.allSatisfy(new Predicate>() { public boolean accept(FastList list) { return list.isEmpty(); } }); } @Override public boolean contains(final Object object) { return this.lists.anySatisfy(new Predicate>() { public boolean accept(FastList list) { return list.contains(object); } }); } @Override public Iterator iterator() { if (this.lists.isEmpty()) { return Collections.emptyList().iterator(); } return new CompositeIterator(this.lists); } @Override public Object[] toArray() { final Object[] result = new Object[this.size()]; this.forEachWithIndex(new ObjectIntProcedure() { public void value(E each, int index) { result[index] = each; } }); return result; } @Override public boolean add(E object) { if (this.lists.isEmpty()) { this.addComposited(FastList.newList()); } Collection list = this.lists.getLast(); return list.add(object); } @Override public boolean remove(Object object) { return this.lists.anySatisfyWith(REMOVE_PREDICATE, object); } @Override public boolean addAll(Collection collection) { Collection collectionToAdd = collection instanceof FastList ? collection : new FastList(collection); this.addComposited(collectionToAdd); return true; } @Override public boolean containsAll(Collection collection) { return Iterate.allSatisfy(collection, Predicates.in(this)); } @Override public Object[] toArray(Object[] array) { int size = this.size(); final Object[] result = array.length >= size ? array : (Object[]) Array.newInstance(array.getClass().getComponentType(), size); this.forEachWithIndex(new ObjectIntProcedure() { public void value(E each, int index) { result[index] = each; } }); if (result.length > size) { result[size] = null; } return result; } public void addComposited(Collection collection) { if (!(collection instanceof FastList)) { throw new IllegalArgumentException("CompositeFastList can only add FastLists"); } this.lists.add((FastList) collection); } public boolean addAll(int index, Collection collection) { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".addAll() not implemented yet"); } public void clear() { this.lists.forEach(new Procedure>() { public void value(FastList object) { object.clear(); } }); } @Override public boolean retainAll(Collection collection) { boolean changed = false; for (int i = this.lists.size() - 1; i >= 0; i--) { changed = this.lists.get(i).retainAll(collection) || changed; } return changed; } @Override public boolean removeAll(Collection collection) { if (collection.isEmpty()) { return false; } boolean changed = false; for (int i = this.lists.size() - 1; i >= 0; i--) { changed = this.lists.get(i).removeAll(collection) || changed; } return changed; } public E get(int index) { this.rangeCheck(index); int p = 0; int currentSize = this.lists.getFirst().size(); while (index >= currentSize) { index -= currentSize; currentSize = this.lists.get(++p).size(); } return this.lists.get(p).items[index]; } private void rangeCheck(int index) { if (index >= this.size()) { throw new IndexOutOfBoundsException("No such element " + index + " size: " + this.size()); } } public E set(int index, E element) { this.rangeCheck(index); int p = 0; int currentSize = this.lists.getFirst().size(); while (index >= currentSize) { index -= currentSize; currentSize = this.lists.get(++p).size(); } return this.lists.get(p).set(index, element); } public void add(int index, E element) { int localSize = this.size(); if (index > localSize || index < 0) { throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + localSize); } int max = 0; for (int i = 0; i < this.lists.size(); i++) { List list = this.lists.get(i); int previousMax = max; max += list.size(); if (index <= max) { list.add(index - previousMax, element); return; } } } public E remove(int index) { this.rangeCheck(index); int p = 0; int currentSize = this.lists.getFirst().size(); while (index >= currentSize) { index -= currentSize; currentSize = this.lists.get(++p).size(); } return this.lists.get(p).remove(index); } @Override public int indexOf(Object o) { int offset = 0; int listsSize = this.lists.size(); for (int i = 0; i < listsSize; i++) { MutableList list = this.lists.get(i); int index = list.indexOf(o); if (index > -1) { return index + offset; } offset += list.size(); } return -1; } @Override public int lastIndexOf(Object o) { int offset = this.size(); for (int i = this.lists.size() - 1; i >= 0; i--) { MutableList list = this.lists.get(i); offset -= list.size(); int index = list.lastIndexOf(o); if (index > -1) { return index + offset; } } return -1; } /** * a list iterator is a problem for a composite list as going back in the order of the list is an issue, * as are the other methods like set() and add() (and especially, remove). * Convert the internal lists to one list (if not already just one list) * and return that list's list iterator. *

* AFAIK list iterator is only commonly used in sorting. * * @return a ListIterator for this, with internal state convertedto one list if needed. */ @Override public ListIterator listIterator() { return this.listIterator(0); } /** * a llst iterator is a problem for a composite list as going back in the order of the list is an issue, * as are the other methods like set() and add() (and especially, remove). * Convert the internal lists to one list (if not already just one list) * and return that list's list iterator. *

* AFAIK list iterator is only commonly used in sorting. * * @return a ListIterator for this, with internal state convertedto one list if needed. */ @Override public ListIterator listIterator(int index) { if (this.lists.size() == 1) { return this.lists.getFirst().listIterator(index); } if (this.lists.isEmpty()) { return Lists.immutable.of().listIterator(index); } this.flattenLists(); return super.listIterator(index); } /** * convert multiple contained lists into one list and replace the contained lists with that list. * Synchronize to prevent changes to this list whilst this process is happening */ private void flattenLists() { FastList list = (FastList) this.toList(); this.lists.clear(); this.lists.add(list); } /** * Override in subclasses where it can be optimized. */ @Override protected void defaultSort(Comparator comparator) { FastList list = comparator == null ? (FastList) this.toSortedList() : (FastList) this.toSortedList(comparator); this.lists.clear(); this.lists.add(list); } private final class CompositeIterator implements Iterator { private final Iterator[] iterators; private Iterator currentIterator; private int currentIndex = 0; private CompositeIterator(FastList> newLists) { this.iterators = new Iterator[newLists.size()]; for (int i = 0; i < newLists.size(); ++i) { this.iterators[i] = newLists.get(i).iterator(); } this.currentIterator = this.iterators[0]; this.currentIndex = 0; } public boolean hasNext() { if (this.currentIterator.hasNext()) { return true; } if (this.currentIndex < this.iterators.length - 1) { this.currentIterator = this.iterators[++this.currentIndex]; return this.hasNext(); } return false; } public E next() { if (this.currentIterator.hasNext()) { return this.currentIterator.next(); } if (this.currentIndex < this.iterators.length - 1) { this.currentIterator = this.iterators[++this.currentIndex]; return this.next(); } throw new NoSuchElementException(); } public void remove() { this.currentIterator.remove(); } } @Override public boolean equals(Object other) { if (!(other instanceof List)) { return false; } List otherList = (List) other; if (this.size() != otherList.size()) { return false; } Iterator thisIterator = this.iterator(); Iterator otherIterator = otherList.iterator(); while (thisIterator.hasNext()) { E thisObject = thisIterator.next(); Object otherObject = otherIterator.next(); if (!Comparators.nullSafeEquals(thisObject, otherObject)) { return false; } } return true; } @Override public int hashCode() { int hashCode = 1; Iterator iterator = this.iterator(); while (iterator.hasNext()) { E item = iterator.next(); hashCode = 31 * hashCode + (item == null ? 0 : item.hashCode()); } return hashCode; } private static final class ProcedureToInnerListObjectIntProcedure implements Procedure> { private static final long serialVersionUID = 1L; private int index; private final ObjectIntProcedure objectIntProcedure; private ProcedureToInnerListObjectIntProcedure(ObjectIntProcedure objectIntProcedure) { this.objectIntProcedure = objectIntProcedure; } public void value(FastList list) { list.forEach(new Procedure() { public void value(E object) { ProcedureToInnerListObjectIntProcedure.this.objectIntProcedure.value( object, ProcedureToInnerListObjectIntProcedure.this.index); ProcedureToInnerListObjectIntProcedure.this.index++; } }); } } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/mutable/FastList.java000066400000000000000000001550421234315411400330670ustar00rootroot00000000000000/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.mutable; import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Comparator; import java.util.Iterator; import java.util.List; import java.util.RandomAccess; import java.util.concurrent.ExecutorService; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.annotation.Beta; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.Function3; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.DoubleObjectToDoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.FloatObjectToFloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.IntObjectToIntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.LongObjectToLongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.Procedure2; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.collection.primitive.MutableBooleanCollection; import com.gs.collections.api.collection.primitive.MutableByteCollection; import com.gs.collections.api.collection.primitive.MutableCharCollection; import com.gs.collections.api.collection.primitive.MutableDoubleCollection; import com.gs.collections.api.collection.primitive.MutableFloatCollection; import com.gs.collections.api.collection.primitive.MutableIntCollection; import com.gs.collections.api.collection.primitive.MutableLongCollection; import com.gs.collections.api.collection.primitive.MutableShortCollection; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.list.ParallelListIterable; import com.gs.collections.api.list.primitive.MutableBooleanList; import com.gs.collections.api.list.primitive.MutableByteList; import com.gs.collections.api.list.primitive.MutableCharList; import com.gs.collections.api.list.primitive.MutableDoubleList; import com.gs.collections.api.list.primitive.MutableFloatList; import com.gs.collections.api.list.primitive.MutableIntList; import com.gs.collections.api.list.primitive.MutableLongList; import com.gs.collections.api.list.primitive.MutableShortList; import com.gs.collections.api.multimap.MutableMultimap; import com.gs.collections.api.partition.list.PartitionMutableList; import com.gs.collections.api.set.MutableSet; import com.gs.collections.api.tuple.Twin; import com.gs.collections.impl.block.factory.Comparators; import com.gs.collections.impl.block.factory.Predicates2; import com.gs.collections.impl.block.factory.Procedures2; import com.gs.collections.impl.block.procedure.CountProcedure; import com.gs.collections.impl.block.procedure.FastListCollectIfProcedure; import com.gs.collections.impl.block.procedure.FastListCollectProcedure; import com.gs.collections.impl.block.procedure.FastListRejectProcedure; import com.gs.collections.impl.block.procedure.FastListSelectProcedure; import com.gs.collections.impl.block.procedure.MultimapPutProcedure; import com.gs.collections.impl.lazy.AbstractLazyIterable; import com.gs.collections.impl.lazy.parallel.AbstractBatch; import com.gs.collections.impl.lazy.parallel.list.AbstractParallelListIterable; import com.gs.collections.impl.lazy.parallel.list.CollectListBatch; import com.gs.collections.impl.lazy.parallel.list.DistinctBatch; import com.gs.collections.impl.lazy.parallel.list.ListBatch; import com.gs.collections.impl.lazy.parallel.list.RootListBatch; import com.gs.collections.impl.lazy.parallel.list.SelectListBatch; import com.gs.collections.impl.lazy.parallel.set.UnsortedSetBatch; import com.gs.collections.impl.list.mutable.primitive.BooleanArrayList; import com.gs.collections.impl.list.mutable.primitive.ByteArrayList; import com.gs.collections.impl.list.mutable.primitive.CharArrayList; import com.gs.collections.impl.list.mutable.primitive.DoubleArrayList; import com.gs.collections.impl.list.mutable.primitive.FloatArrayList; import com.gs.collections.impl.list.mutable.primitive.IntArrayList; import com.gs.collections.impl.list.mutable.primitive.LongArrayList; import com.gs.collections.impl.list.mutable.primitive.ShortArrayList; import com.gs.collections.impl.map.mutable.ConcurrentHashMap; import com.gs.collections.impl.multimap.list.FastListMultimap; import com.gs.collections.impl.parallel.BatchIterable; import com.gs.collections.impl.partition.list.PartitionFastList; import com.gs.collections.impl.set.mutable.UnifiedSet; import com.gs.collections.impl.tuple.Tuples; import com.gs.collections.impl.utility.ArrayIterate; import com.gs.collections.impl.utility.ArrayListIterate; import com.gs.collections.impl.utility.Iterate; import com.gs.collections.impl.utility.ListIterate; import com.gs.collections.impl.utility.internal.InternalArrayIterate; import net.jcip.annotations.NotThreadSafe; /** * FastList is an attempt to provide the same functionality as ArrayList without the support for concurrent * modification exceptions. It also attempts to correct the problem with subclassing ArrayList * in that the data elements are protected, not private. It is this issue that caused this class * to be created in the first place. The intent was to provide optimized internal iterators which use direct access * against the array of items, which is currently not possible by subclassing ArrayList. *

* An empty FastList created by calling the default constructor starts with a shared reference to a static * empty array (DEFAULT_SIZED_EMPTY_ARRAY). This makes empty FastLists very memory efficient. The * first call to add will lazily create an array of size 10. *

* An empty FastList created by calling the pre-size constructor with a value of 0 (new FastList(0)) starts * with a shared reference to a static empty array (ZERO_SIZED_ARRAY). This makes FastLists presized to 0 very * memory efficient as well. The first call to add will lazily create an array of size 1. */ @NotThreadSafe public class FastList extends AbstractMutableList implements Externalizable, RandomAccess, BatchIterable { private static final long serialVersionUID = 1L; private static final Object[] DEFAULT_SIZED_EMPTY_ARRAY = {}; private static final Object[] ZERO_SIZED_ARRAY = {}; private static final int MAXIMUM_ARRAY_SIZE = Integer.MAX_VALUE - 8; protected int size; protected transient T[] items = (T[]) DEFAULT_SIZED_EMPTY_ARRAY; public FastList() { } public FastList(int initialCapacity) { this.items = initialCapacity == 0 ? (T[]) ZERO_SIZED_ARRAY : (T[]) new Object[initialCapacity]; } protected FastList(T[] array) { this(array.length, array); } protected FastList(int size, T[] array) { this.size = size; this.items = array; } public FastList(Collection source) { this.items = (T[]) source.toArray(); this.size = this.items.length; } public static FastList newList() { return new FastList(); } public static FastList wrapCopy(E... array) { E[] newArray = (E[]) new Object[array.length]; System.arraycopy(array, 0, newArray, 0, array.length); return new FastList(newArray); } public static FastList newList(int initialCapacity) { return new FastList(initialCapacity); } public static FastList newList(Iterable source) { return FastList.newListWith((E[]) Iterate.toArray(source)); } /** * Creates a new list using the passed {@code elements} argument as the backing store. *

* !!! WARNING: This method uses the passed in array, so can be very unsafe if the original * array is held onto anywhere else. !!! */ public static FastList newListWith(E... elements) { return new FastList(elements); } /** * Creates a new FastList pre-sized to the specified size filled with default values generated by the specified function. * * @since 3.0 */ public static FastList newWithNValues(int size, Function0 factory) { FastList newFastList = FastList.newList(size); for (int i = 0; i < size; i++) { newFastList.add(factory.value()); } return newFastList; } @Override public FastList clone() { FastList result = (FastList) super.clone(); if (this.items.length > 0) { result.items = this.items.clone(); } return result; } public void clear() { Arrays.fill(this.items, null); this.size = 0; } @Override public void forEach(int from, int to, Procedure procedure) { ListIterate.rangeCheck(from, to, this.size); InternalArrayIterate.forEachWithoutChecks(this.items, from, to, procedure); } @Override public void forEachWithIndex(int from, int to, ObjectIntProcedure objectIntProcedure) { ListIterate.rangeCheck(from, to, this.size); InternalArrayIterate.forEachWithIndexWithoutChecks(this.items, from, to, objectIntProcedure); } public void batchForEach(Procedure procedure, int sectionIndex, int sectionCount) { int sectionSize = this.size() / sectionCount; int start = sectionSize * sectionIndex; int end = sectionIndex == sectionCount - 1 ? this.size() : start + sectionSize; if (procedure instanceof FastListSelectProcedure) { this.batchFastListSelect(start, end, (FastListSelectProcedure) procedure); } else if (procedure instanceof FastListCollectProcedure) { this.batchFastListCollect(start, end, (FastListCollectProcedure) procedure); } else if (procedure instanceof FastListCollectIfProcedure) { this.batchFastListCollectIf(start, end, (FastListCollectIfProcedure) procedure); } else if (procedure instanceof CountProcedure) { this.batchCount(start, end, (CountProcedure) procedure); } else if (procedure instanceof FastListRejectProcedure) { this.batchReject(start, end, (FastListRejectProcedure) procedure); } else if (procedure instanceof MultimapPutProcedure) { this.batchGroupBy(start, end, (MultimapPutProcedure) procedure); } else { for (int i = start; i < end; i++) { procedure.value(this.items[i]); } } } /** * Implemented to avoid megamorphic call on castProcedure. */ private void batchGroupBy(int start, int end, MultimapPutProcedure castProcedure) { for (int i = start; i < end; i++) { castProcedure.value(this.items[i]); } } /** * Implemented to avoid megamorphic call on castProcedure. */ private void batchReject(int start, int end, FastListRejectProcedure castProcedure) { for (int i = start; i < end; i++) { castProcedure.value(this.items[i]); } } /** * Implemented to avoid megamorphic call on castProcedure. */ private void batchCount(int start, int end, CountProcedure castProcedure) { for (int i = start; i < end; i++) { castProcedure.value(this.items[i]); } } /** * Implemented to avoid megamorphic call on castProcedure. */ private void batchFastListCollectIf(int start, int end, FastListCollectIfProcedure castProcedure) { for (int i = start; i < end; i++) { castProcedure.value(this.items[i]); } } /** * Implemented to avoid megamorphic call on castProcedure. */ private void batchFastListCollect(int start, int end, FastListCollectProcedure castProcedure) { for (int i = start; i < end; i++) { castProcedure.value(this.items[i]); } } /** * Implemented to avoid megamorphic call on castProcedure. */ private void batchFastListSelect(int start, int end, FastListSelectProcedure castProcedure) { for (int i = start; i < end; i++) { castProcedure.value(this.items[i]); } } public int getBatchCount(int batchSize) { return Math.max(1, this.size() / batchSize); } public E[] toArray(E[] array, int sourceFromIndex, int sourceToIndex, int destinationIndex) { System.arraycopy(this.items, sourceFromIndex, array, destinationIndex, sourceToIndex - sourceFromIndex + 1); return array; } public E[] toArray(int sourceFromIndex, int sourceToIndex) { return this.toArray((E[]) new Object[sourceToIndex - sourceFromIndex + 1], sourceFromIndex, sourceToIndex, 0); } @Override public FastList sortThis(Comparator comparator) { ArrayIterate.sort(this.items, this.size, comparator); return this; } @Override public FastList sortThis() { ArrayIterate.sort(this.items, this.size, null); return this; } @Override public FastList reverseThis() { ArrayIterate.reverse(this.items, this.size); return this; } @Override public boolean addAll(Collection source) { if (source.isEmpty()) { return false; } if (source.getClass() == FastList.class) { this.addAllFastList((FastList) source); } else if (source.getClass() == ArrayList.class) { this.addAllArrayList((ArrayList) source); } else { this.addAllCollection(source); } return true; } private void addAllFastList(FastList source) { int sourceSize = source.size(); int newSize = this.size + sourceSize; this.ensureCapacity(newSize); System.arraycopy(source.items, 0, this.items, this.size, sourceSize); this.size = newSize; } private void addAllArrayList(ArrayList source) { int sourceSize = source.size(); int newSize = this.size + sourceSize; this.ensureCapacity(newSize); ArrayListIterate.toArray(source, this.items, this.size, sourceSize); this.size = newSize; } private void addAllCollection(Collection source) { this.ensureCapacity(this.size + source.size()); Iterate.forEachWith(source, Procedures2.addToCollection(), this); } @Override public boolean containsAll(Collection source) { return Iterate.allSatisfyWith(source, Predicates2.in(), this); } @Override public boolean containsAllArguments(Object... source) { return ArrayIterate.allSatisfyWith(source, Predicates2.in(), this); } @Override public E[] toArray(E[] array) { if (array.length < this.size) { array = (E[]) Array.newInstance(array.getClass().getComponentType(), this.size); } System.arraycopy(this.items, 0, array, 0, this.size); if (array.length > this.size) { array[this.size] = null; } return array; } @Override public Object[] toArray() { return this.copyItemsWithNewCapacity(this.size); } public T[] toTypedArray(Class clazz) { T[] array = (T[]) Array.newInstance(clazz, this.size); System.arraycopy(this.items, 0, array, 0, this.size); return array; } private void throwOutOfBounds(int index) { throw this.newIndexOutOfBoundsException(index); } public T set(int index, T element) { T previous = this.get(index); this.items[index] = element; return previous; } @Override public int indexOf(Object object) { for (int i = 0; i < this.size; i++) { if (Comparators.nullSafeEquals(this.items[i], object)) { return i; } } return -1; } @Override public int lastIndexOf(Object object) { for (int i = this.size - 1; i >= 0; i--) { if (Comparators.nullSafeEquals(this.items[i], object)) { return i; } } return -1; } public void trimToSize() { if (this.size < this.items.length) { this.transferItemsToNewArrayWithCapacity(this.size); } } /** * Express load factor as 0.25 to trim a collection with more than 25% excess capacity */ public boolean trimToSizeIfGreaterThanPercent(double loadFactor) { double excessCapacity = 1.0 - (double) this.size / (double) this.items.length; if (excessCapacity > loadFactor) { this.trimToSize(); return true; } return false; } public void ensureCapacity(int minCapacity) { int oldCapacity = this.items.length; if (minCapacity > oldCapacity) { int newCapacity = Math.max(this.sizePlusFiftyPercent(oldCapacity), minCapacity); this.transferItemsToNewArrayWithCapacity(newCapacity); } } private void transferItemsToNewArrayWithCapacity(int newCapacity) { this.items = (T[]) this.copyItemsWithNewCapacity(newCapacity); } private Object[] copyItemsWithNewCapacity(int newCapacity) { Object[] newItems = new Object[newCapacity]; System.arraycopy(this.items, 0, newItems, 0, Math.min(this.size, newCapacity)); return newItems; } public FastList with(T element1, T element2) { this.add(element1); this.add(element2); return this; } public FastList with(T element1, T element2, T element3) { this.add(element1); this.add(element2); this.add(element3); return this; } public FastList with(T... elements) { return this.withArrayCopy(elements, 0, elements.length); } public FastList withArrayCopy(T[] elements, int begin, int length) { this.ensureCapacity(this.size + length); System.arraycopy(elements, begin, this.items, this.size, length); this.size += length; return this; } @Override public T getFirst() { return this.isEmpty() ? null : this.items[0]; } @Override public T getLast() { return this.isEmpty() ? null : this.items[this.size() - 1]; } @Override public FastListMultimap groupBy(Function function) { return this.groupBy(function, FastListMultimap.newMultimap()); } @Override public > R groupBy(Function function, R target) { for (int i = 0; i < this.size; i++) { T item = this.items[i]; target.put(function.valueOf(item), item); } return target; } @Override public void forEach(Procedure procedure) { for (int i = 0; i < this.size; i++) { procedure.value(this.items[i]); } } public void forEachIf(Predicate predicate, Procedure procedure) { for (int i = 0; i < this.size; i++) { T item = this.items[i]; if (predicate.accept(item)) { procedure.value(item); } } } @Override public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { for (int i = 0; i < this.size; i++) { objectIntProcedure.value(this.items[i], i); } } @Override public

void forEachWith(Procedure2 procedure, P parameter) { for (int i = 0; i < this.size; i++) { procedure.value(this.items[i], parameter); } } @Override public FastList select(Predicate predicate) { return this.select(predicate, FastList.newList()); } @Override public > R select(Predicate predicate, R target) { for (int i = 0; i < this.size; i++) { T item = this.items[i]; if (predicate.accept(item)) { target.add(item); } } return target; } @Override public

FastList selectWith(Predicate2 predicate, P parameter) { return this.selectWith(predicate, parameter, FastList.newList()); } @Override public > R selectWith( Predicate2 predicate, P parameter, R targetCollection) { for (int i = 0; i < this.size; i++) { T item = this.items[i]; if (predicate.accept(item, parameter)) { targetCollection.add(item); } } return targetCollection; } @Override public FastList reject(Predicate predicate) { return this.reject(predicate, FastList.newList()); } @Override public > R reject(Predicate predicate, R target) { for (int i = 0; i < this.size; i++) { T item = this.items[i]; if (!predicate.accept(item)) { target.add(item); } } return target; } @Override public

FastList rejectWith(Predicate2 predicate, P parameter) { return this.rejectWith(predicate, parameter, FastList.newList()); } @Override public > R rejectWith( Predicate2 predicate, P parameter, R target) { for (int i = 0; i < this.size; i++) { T item = this.items[i]; if (!predicate.accept(item, parameter)) { target.add(item); } } return target; } @Override public

Twin> selectAndRejectWith( Predicate2 predicate, P parameter) { MutableList positiveResult = FastList.newList(); MutableList negativeResult = FastList.newList(); for (int i = 0; i < this.size; i++) { T item = this.items[i]; (predicate.accept(item, parameter) ? positiveResult : negativeResult).add(item); } return Tuples.twin(positiveResult, negativeResult); } @Override public FastList selectInstancesOf(Class clazz) { FastList result = FastList.newList(this.size); for (int i = 0; i < this.size; i++) { T item = this.items[i]; if (clazz.isInstance(item)) { result.add((S) item); } } result.trimToSize(); return result; } @Override public void removeIf(Predicate predicate) { int currentFilledIndex = 0; for (int i = 0; i < this.size; i++) { T item = this.items[i]; if (!predicate.accept(item)) { // keep it if (currentFilledIndex != i) { this.items[currentFilledIndex] = item; } currentFilledIndex++; } } this.wipeAndResetTheEnd(currentFilledIndex); } private void wipeAndResetTheEnd(int newCurrentFilledIndex) { for (int i = newCurrentFilledIndex; i < this.size; i++) { this.items[i] = null; } this.size = newCurrentFilledIndex; } @Override public

void removeIfWith(Predicate2 predicate, P parameter) { int currentFilledIndex = 0; for (int i = 0; i < this.size; i++) { T item = this.items[i]; if (!predicate.accept(item, parameter)) { // keep it if (currentFilledIndex != i) { this.items[currentFilledIndex] = item; } currentFilledIndex++; } } this.wipeAndResetTheEnd(currentFilledIndex); } @Override public FastList collect(Function function) { return this.collect(function, FastList.newList(this.size())); } @Override public MutableBooleanList collectBoolean(BooleanFunction booleanFunction) { return this.collectBoolean(booleanFunction, new BooleanArrayList(this.size)); } @Override public R collectBoolean(BooleanFunction booleanFunction, R target) { for (int i = 0; i < this.size; i++) { target.add(booleanFunction.booleanValueOf(this.items[i])); } return target; } @Override public MutableByteList collectByte(ByteFunction byteFunction) { return this.collectByte(byteFunction, new ByteArrayList(this.size)); } @Override public R collectByte(ByteFunction byteFunction, R target) { for (int i = 0; i < this.size; i++) { target.add(byteFunction.byteValueOf(this.items[i])); } return target; } @Override public MutableCharList collectChar(CharFunction charFunction) { return this.collectChar(charFunction, new CharArrayList(this.size)); } @Override public R collectChar(CharFunction charFunction, R target) { for (int i = 0; i < this.size; i++) { target.add(charFunction.charValueOf(this.items[i])); } return target; } @Override public MutableDoubleList collectDouble(DoubleFunction doubleFunction) { return this.collectDouble(doubleFunction, new DoubleArrayList(this.size)); } @Override public R collectDouble(DoubleFunction doubleFunction, R target) { for (int i = 0; i < this.size; i++) { target.add(doubleFunction.doubleValueOf(this.items[i])); } return target; } @Override public MutableFloatList collectFloat(FloatFunction floatFunction) { return this.collectFloat(floatFunction, new FloatArrayList(this.size)); } @Override public R collectFloat(FloatFunction floatFunction, R target) { for (int i = 0; i < this.size; i++) { target.add(floatFunction.floatValueOf(this.items[i])); } return target; } @Override public MutableIntList collectInt(IntFunction intFunction) { return this.collectInt(intFunction, new IntArrayList(this.size)); } @Override public R collectInt(IntFunction intFunction, R target) { for (int i = 0; i < this.size; i++) { target.add(intFunction.intValueOf(this.items[i])); } return target; } @Override public MutableLongList collectLong(LongFunction longFunction) { return this.collectLong(longFunction, new LongArrayList(this.size)); } @Override public R collectLong(LongFunction longFunction, R target) { for (int i = 0; i < this.size; i++) { target.add(longFunction.longValueOf(this.items[i])); } return target; } @Override public MutableShortList collectShort(ShortFunction shortFunction) { return this.collectShort(shortFunction, new ShortArrayList(this.size)); } @Override public R collectShort(ShortFunction shortFunction, R target) { for (int i = 0; i < this.size; i++) { target.add(shortFunction.shortValueOf(this.items[i])); } return target; } @Override public > R collect(Function function, R target) { for (int i = 0; i < this.size; i++) { target.add(function.valueOf(this.items[i])); } return target; } @Override public FastList flatCollect(Function> function) { return this.flatCollect(function, FastList.newList(this.size())); } @Override public > R flatCollect( Function> function, R target) { for (int i = 0; i < this.size; i++) { Iterate.addAllTo(function.valueOf(this.items[i]), target); } return target; } @Override public FastList collectWith(Function2 function, P parameter) { return this.collectWith(function, parameter, FastList.newList(this.size())); } @Override public > R collectWith( Function2 function, P parameter, R targetCollection) { for (int i = 0; i < this.size; i++) { targetCollection.add(function.value(this.items[i], parameter)); } return targetCollection; } @Override public FastList collectIf( Predicate predicate, Function function) { return this.collectIf(predicate, function, FastList.newList()); } @Override public > R collectIf( Predicate predicate, Function function, R target) { for (int i = 0; i < this.size; i++) { T item = this.items[i]; if (predicate.accept(item)) { target.add(function.valueOf(item)); } } return target; } @Override public T detect(Predicate predicate) { for (int i = 0; i < this.size; i++) { T item = this.items[i]; if (predicate.accept(item)) { return item; } } return null; } @Override public T detectIfNone(Predicate predicate, Function0 defaultValueBlock) { T result = this.detect(predicate); return result == null ? defaultValueBlock.value() : result; } @Override public > T minBy(Function function) { return ArrayIterate.minBy(this.items, this.size, function); } @Override public > T maxBy(Function function) { return ArrayIterate.maxBy(this.items, this.size, function); } @Override public

T detectWith(Predicate2 predicate, P parameter) { for (int i = 0; i < this.size; i++) { T item = this.items[i]; if (predicate.accept(item, parameter)) { return item; } } return null; } @Override public

T detectWithIfNone( Predicate2 predicate, P parameter, Function0 defaultValueBlock) { T result = this.detectWith(predicate, parameter); return result == null ? defaultValueBlock.value() : result; } public T get(int index) { if (index < this.size) { return this.items[index]; } throw this.newIndexOutOfBoundsException(index); } private IndexOutOfBoundsException newIndexOutOfBoundsException(int index) { return new IndexOutOfBoundsException("Index: " + index + " Size: " + this.size); } @Override public boolean add(T newItem) { if (this.items.length == this.size) { this.ensureCapacityForAdd(); } this.items[this.size++] = newItem; return true; } private void ensureCapacityForAdd() { if (this.items == DEFAULT_SIZED_EMPTY_ARRAY) { this.items = (T[]) new Object[10]; } else { this.transferItemsToNewArrayWithCapacity(this.sizePlusFiftyPercent(this.size)); } } public void add(int index, T element) { if (index > -1 && index < this.size) { this.addAtIndex(index, element); } else if (index == this.size) { this.add(element); } else { this.throwOutOfBounds(index); } } private void addAtIndex(int index, T element) { int oldSize = this.size++; if (this.items.length == oldSize) { T[] newItems = (T[]) new Object[this.sizePlusFiftyPercent(oldSize)]; if (index > 0) { System.arraycopy(this.items, 0, newItems, 0, index); } System.arraycopy(this.items, index, newItems, index + 1, oldSize - index); this.items = newItems; } else { System.arraycopy(this.items, index, this.items, index + 1, oldSize - index); } this.items[index] = element; } private int sizePlusFiftyPercent(int oldSize) { int result = oldSize + (oldSize >> 1) + 1; return result < oldSize ? MAXIMUM_ARRAY_SIZE : result; } public T remove(int index) { T previous = this.get(index); int totalOffset = this.size - index - 1; if (totalOffset > 0) { System.arraycopy(this.items, index + 1, this.items, index, totalOffset); } this.items[--this.size] = null; return previous; } @Override public boolean remove(Object object) { int index = this.indexOf(object); if (index >= 0) { this.remove(index); return true; } return false; } public boolean addAll(int index, Collection source) { if (index > this.size || index < 0) { this.throwOutOfBounds(index); } if (source.isEmpty()) { return false; } if (source.getClass() == FastList.class) { this.addAllFastListAtIndex((FastList) source, index); } else if (source.getClass() == ArrayList.class) { this.addAllArrayListAtIndex((ArrayList) source, index); } else { this.addAllCollectionAtIndex(source, index); } return true; } private void addAllFastListAtIndex(FastList source, int index) { int sourceSize = source.size(); int newSize = this.size + sourceSize; this.ensureCapacity(newSize); this.shiftElementsAtIndex(index, sourceSize); System.arraycopy(source.items, 0, this.items, index, sourceSize); this.size = newSize; } private void addAllArrayListAtIndex(ArrayList source, int index) { int sourceSize = source.size(); int newSize = this.size + sourceSize; this.ensureCapacity(newSize); this.shiftElementsAtIndex(index, sourceSize); ArrayListIterate.toArray(source, this.items, index, sourceSize); this.size = newSize; } private void addAllCollectionAtIndex(Collection source, int index) { Object[] newItems = source.toArray(); int sourceSize = newItems.length; int newSize = this.size + sourceSize; this.ensureCapacity(newSize); this.shiftElementsAtIndex(index, sourceSize); this.size = newSize; System.arraycopy(newItems, 0, this.items, index, sourceSize); } private void shiftElementsAtIndex(int index, int sourceSize) { int numberToMove = this.size - index; if (numberToMove > 0) { System.arraycopy(this.items, index, this.items, index + sourceSize, numberToMove); } } public int size() { return this.size; } @Override public int count(Predicate predicate) { int count = 0; for (int i = 0; i < this.size; i++) { if (predicate.accept(this.items[i])) { count++; } } return count; } @Override public

int countWith(Predicate2 predicate, P parameter) { int count = 0; for (int i = 0; i < this.size; i++) { if (predicate.accept(this.items[i], parameter)) { count++; } } return count; } @Override public boolean anySatisfy(Predicate predicate) { for (int i = 0; i < this.size; i++) { if (predicate.accept(this.items[i])) { return true; } } return false; } @Override public

boolean anySatisfyWith(Predicate2 predicate, P parameter) { for (int i = 0; i < this.size; i++) { if (predicate.accept(this.items[i], parameter)) { return true; } } return false; } @Override public boolean allSatisfy(Predicate predicate) { for (int i = 0; i < this.size; i++) { if (!predicate.accept(this.items[i])) { return false; } } return true; } @Override public

boolean allSatisfyWith(Predicate2 predicate, P parameter) { for (int i = 0; i < this.size; i++) { if (!predicate.accept(this.items[i], parameter)) { return false; } } return true; } @Override public boolean noneSatisfy(Predicate predicate) { for (int i = 0; i < this.size; i++) { if (predicate.accept(this.items[i])) { return false; } } return true; } @Override public

boolean noneSatisfyWith(Predicate2 predicate, P parameter) { for (int i = 0; i < this.size; i++) { if (predicate.accept(this.items[i], parameter)) { return false; } } return true; } @Override public IV injectInto(IV injectedValue, Function2 function) { IV result = injectedValue; for (int i = 0; i < this.size; i++) { result = function.value(result, this.items[i]); } return result; } @Override public int injectInto(int injectedValue, IntObjectToIntFunction function) { int result = injectedValue; for (int i = 0; i < this.size; i++) { result = function.intValueOf(result, this.items[i]); } return result; } @Override public long injectInto(long injectedValue, LongObjectToLongFunction function) { long result = injectedValue; for (int i = 0; i < this.size; i++) { result = function.longValueOf(result, this.items[i]); } return result; } @Override public double injectInto(double injectedValue, DoubleObjectToDoubleFunction function) { double result = injectedValue; for (int i = 0; i < this.size; i++) { result = function.doubleValueOf(result, this.items[i]); } return result; } @Override public float injectInto(float injectedValue, FloatObjectToFloatFunction function) { float result = injectedValue; for (int i = 0; i < this.size; i++) { result = function.floatValueOf(result, this.items[i]); } return result; } @Override public FastList distinct() { MutableSet seenSoFar = UnifiedSet.newSet(); FastList targetCollection = FastList.newList(); for (int i = 0; i < this.size(); i++) { if (seenSoFar.add(this.items[i])) { targetCollection.add(this.items[i]); } } return targetCollection; } @Override public long sumOfInt(IntFunction function) { long result = 0L; for (int i = 0; i < this.size; i++) { result += (long) function.intValueOf(this.items[i]); } return result; } @Override public long sumOfLong(LongFunction function) { long result = 0L; for (int i = 0; i < this.size; i++) { result += function.longValueOf(this.items[i]); } return result; } @Override public double sumOfFloat(FloatFunction function) { double result = 0.0d; for (int i = 0; i < this.size; i++) { result += (double) function.floatValueOf(this.items[i]); } return result; } @Override public double sumOfDouble(DoubleFunction function) { double result = 0.0d; for (int i = 0; i < this.size; i++) { result += function.doubleValueOf(this.items[i]); } return result; } @Override public IV injectIntoWith( IV injectValue, Function3 function, P parameter) { IV result = injectValue; for (int i = 0; i < this.size; i++) { result = function.value(result, this.items[i], parameter); } return result; } @Override public FastList toList() { return FastList.newList(this); } @Override public FastList toSortedList() { return this.toSortedList(Comparators.naturalOrder()); } @Override public FastList toSortedList(Comparator comparator) { return FastList.newList(this).sortThis(comparator); } @Override public MutableList takeWhile(Predicate predicate) { int endIndex = this.detectNotIndex(predicate); T[] result = (T[]) new Object[endIndex]; System.arraycopy(this.items, 0, result, 0, endIndex); return FastList.newListWith(result); } @Override public MutableList dropWhile(Predicate predicate) { int startIndex = this.detectNotIndex(predicate); int resultSize = this.size() - startIndex; T[] result = (T[]) new Object[resultSize]; System.arraycopy(this.items, startIndex, result, 0, resultSize); return FastList.newListWith(result); } @Override public PartitionMutableList partitionWhile(Predicate predicate) { PartitionMutableList result = new PartitionFastList(); FastList selected = (FastList) result.getSelected(); FastList rejected = (FastList) result.getRejected(); int partitionIndex = this.detectNotIndex(predicate); int rejectedSize = this.size() - partitionIndex; selected.withArrayCopy(this.items, 0, partitionIndex); rejected.withArrayCopy(this.items, partitionIndex, rejectedSize); return result; } private int detectNotIndex(Predicate predicate) { for (int index = 0; index < this.size; index++) { if (!predicate.accept(this.items[index])) { return index; } } return this.size; } @Override public boolean equals(Object otherList) { if (otherList == this) { return true; } if (!(otherList instanceof List)) { return false; } List list = (List) otherList; if (otherList instanceof FastList) { return this.fastListEquals((FastList) otherList); } if (otherList instanceof RandomAccess) { return this.randomAccessListEquals(list); } return this.regularListEquals(list); } public boolean fastListEquals(FastList otherFastList) { if (this.size() != otherFastList.size()) { return false; } for (int i = 0; i < this.size; i++) { T one = this.items[i]; Object two = otherFastList.items[i]; if (!Comparators.nullSafeEquals(one, two)) { return false; } } return true; } /** * @deprecated in 1.3 */ @Deprecated public boolean equals(FastList otherList) { return this.fastListEquals(otherList); } private boolean regularListEquals(List otherList) { Iterator iterator = otherList.iterator(); for (int i = 0; i < this.size; i++) { T one = this.items[i]; if (!iterator.hasNext()) { return false; } Object two = iterator.next(); if (!Comparators.nullSafeEquals(one, two)) { return false; } } return !iterator.hasNext(); } private boolean randomAccessListEquals(List otherList) { if (this.size() != otherList.size()) { return false; } for (int i = 0; i < this.size; i++) { T one = this.items[i]; Object two = otherList.get(i); if (!Comparators.nullSafeEquals(one, two)) { return false; } } return true; } @Override public int hashCode() { int hashCode = 1; for (int i = 0; i < this.size; i++) { T item = this.items[i]; hashCode = 31 * hashCode + (item == null ? 0 : item.hashCode()); } return hashCode; } public void writeExternal(ObjectOutput out) throws IOException { out.writeInt(this.size()); for (int i = 0; i < this.size; i++) { out.writeObject(this.items[i]); } } public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { this.size = in.readInt(); this.items = (T[]) new Object[this.size]; for (int i = 0; i < this.size; i++) { this.items[i] = (T) in.readObject(); } } @Beta public ParallelListIterable asParallel(ExecutorService executorService, int batchSize) { if (executorService == null) { throw new NullPointerException(); } if (batchSize < 1) { throw new IllegalArgumentException(); } return new FastListParallelIterable(executorService, batchSize); } private final class FastListBatch extends AbstractBatch implements RootListBatch { private final int chunkStartIndex; private final int chunkEndIndex; private FastListBatch(int chunkStartIndex, int chunkEndIndex) { this.chunkStartIndex = chunkStartIndex; this.chunkEndIndex = chunkEndIndex; } public void forEach(Procedure procedure) { for (int i = this.chunkStartIndex; i < this.chunkEndIndex; i++) { procedure.value(FastList.this.items[i]); } } @Override public int count(Predicate predicate) { int count = 0; for (int i = this.chunkStartIndex; i < this.chunkEndIndex; i++) { if (predicate.accept(FastList.this.items[i])) { count++; } } return count; } public boolean anySatisfy(Predicate predicate) { for (int i = this.chunkStartIndex; i < this.chunkEndIndex; i++) { if (predicate.accept(FastList.this.items[i])) { return true; } } return false; } public boolean allSatisfy(Predicate predicate) { for (int i = this.chunkStartIndex; i < this.chunkEndIndex; i++) { if (!predicate.accept(FastList.this.items[i])) { return false; } } return true; } public T detect(Predicate predicate) { for (int i = this.chunkStartIndex; i < this.chunkEndIndex; i++) { if (predicate.accept(FastList.this.items[i])) { return FastList.this.items[i]; } } return null; } public ListBatch select(Predicate predicate) { return new SelectListBatch(this, predicate); } public ListBatch collect(Function function) { return new CollectListBatch(this, function); } public UnsortedSetBatch distinct(ConcurrentHashMap distinct) { return new DistinctBatch(this, distinct); } } private final class FastListParallelIterable extends AbstractParallelListIterable> { private final ExecutorService executorService; private final int batchSize; private FastListParallelIterable(ExecutorService executorService, int batchSize) { this.executorService = executorService; this.batchSize = batchSize; } @Override public ExecutorService getExecutorService() { return this.executorService; } @Override public LazyIterable> split() { return new FastListParallelBatchLazyIterable(); } public void forEach(Procedure procedure) { forEach(this, procedure); } public boolean anySatisfy(Predicate predicate) { return anySatisfy(this, predicate); } public boolean allSatisfy(Predicate predicate) { return allSatisfy(this, predicate); } public T detect(Predicate predicate) { return detect(this, predicate); } private class FastListParallelBatchIterator implements Iterator> { protected int chunkIndex; public boolean hasNext() { return this.chunkIndex * FastListParallelIterable.this.batchSize < FastList.this.size; } public RootListBatch next() { int chunkStartIndex = this.chunkIndex * FastListParallelIterable.this.batchSize; int chunkEndIndex = (this.chunkIndex + 1) * FastListParallelIterable.this.batchSize; int truncatedChunkEndIndex = Math.min(chunkEndIndex, FastList.this.size); this.chunkIndex++; return new FastListBatch(chunkStartIndex, truncatedChunkEndIndex); } public void remove() { throw new UnsupportedOperationException("Cannot call remove() on " + this.getClass().getSimpleName()); } } private class FastListParallelBatchLazyIterable extends AbstractLazyIterable> { public void forEach(Procedure> procedure) { for (RootListBatch chunk : this) { procedure.value(chunk); } } public

void forEachWith(Procedure2, ? super P> procedure, P parameter) { for (RootListBatch chunk : this) { procedure.value(chunk, parameter); } } public void forEachWithIndex(ObjectIntProcedure> objectIntProcedure) { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".forEachWithIndex() not implemented yet"); } public Iterator> iterator() { return new FastListParallelBatchIterator(); } } } } gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/mutable/ListAdapter.java000066400000000000000000000176721234315411400335600ustar00rootroot00000000000000/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.mutable; import java.io.Serializable; import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.RandomAccess; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.list.ImmutableList; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.partition.list.PartitionMutableList; import com.gs.collections.api.stack.MutableStack; import com.gs.collections.impl.block.factory.Comparators; import com.gs.collections.impl.block.procedure.CollectionAddProcedure; import com.gs.collections.impl.factory.Lists; import com.gs.collections.impl.stack.mutable.ArrayStack; import com.gs.collections.impl.utility.ArrayIterate; import com.gs.collections.impl.utility.Iterate; import com.gs.collections.impl.utility.ListIterate; /** * This class provides a MutableList wrapper around a JDK Collections List interface instance. All of the MutableList * interface methods are supported in addition to the JDK List interface methods. *

* To create a new wrapper around an existing List instance, use the {@link #adapt(List)} factory method. */ public final class ListAdapter extends AbstractListAdapter implements Serializable { private static final long serialVersionUID = 1L; private final List delegate; ListAdapter(List newDelegate) { if (newDelegate == null) { throw new NullPointerException("ListAdapter may not wrap null"); } if (newDelegate instanceof RandomAccess) { throw new IllegalArgumentException("Use RandomAccessListAdapter instead"); } this.delegate = newDelegate; } @Override protected List getDelegate() { return this.delegate; } public static MutableList adapt(List list) { if (list instanceof MutableList) { return (MutableList) list; } if (list instanceof ArrayList) { return ArrayListAdapter.adapt((ArrayList) list); } if (list instanceof RandomAccess) { return new RandomAccessListAdapter(list); } return new ListAdapter(list); } public ImmutableList toImmutable() { return Lists.immutable.ofAll(this.delegate); } public MutableList asUnmodifiable() { return UnmodifiableMutableList.of(this); } public MutableList asSynchronized() { return SynchronizedMutableList.of(this); } @Override public MutableList clone() { return FastList.newList(this.delegate); } /** * @deprecated use {@link FastList#newList()} instead (inlineable) */ @Deprecated public MutableList newEmpty() { return FastList.newList(); } @Override public void forEach(Procedure procedure) { ListIterate.forEach(this.delegate, procedure); } public void reverseForEach(Procedure procedure) { ListIterate.reverseForEach(this.delegate, procedure); } @Override public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { ListIterate.forEachWithIndex(this.delegate, objectIntProcedure); } public void forEachWithIndex(int fromIndex, int toIndex, ObjectIntProcedure objectIntProcedure) { ListIterate.forEachWithIndex(this.delegate, fromIndex, toIndex, objectIntProcedure); } @Override public T detect(Predicate predicate) { return ListIterate.detect(this.delegate, predicate); } @Override public T detectIfNone(Predicate predicate, Function0 function) { T result = this.detect(predicate); return result == null ? function.value() : result; } @Override public int count(Predicate predicate) { return ListIterate.count(this.delegate, predicate); } @Override public boolean anySatisfy(Predicate predicate) { return ListIterate.anySatisfy(this.delegate, predicate); } @Override public boolean allSatisfy(Predicate predicate) { return ListIterate.allSatisfy(this.delegate, predicate); } @Override public boolean noneSatisfy(Predicate predicate) { return ListIterate.noneSatisfy(this.delegate, predicate); } @Override public IV injectInto(IV injectedValue, Function2 function) { return ListIterate.injectInto(injectedValue, this.delegate, function); } public void forEach(int fromIndex, int toIndex, Procedure procedure) { ListIterate.forEach(this.delegate, fromIndex, toIndex, procedure); } public ListAdapter sortThis(Comparator comparator) { Iterate.sortThis(this.delegate, comparator); return this; } public ListAdapter sortThis() { return this.sortThis(Comparators.naturalOrder()); } public > MutableList sortThisBy(Function function) { return this.sortThis(Comparators.byFunction(function)); } public ListAdapter with(T element) { this.add(element); return this; } public ListAdapter with(T element1, T element2) { this.add(element1); this.add(element2); return this; } public ListAdapter with(T element1, T element2, T element3) { this.add(element1); this.add(element2); this.add(element3); return this; } public ListAdapter with(T... elements) { ArrayIterate.forEach(elements, CollectionAddProcedure.on(this.delegate)); return this; } public ListAdapter without(T element) { this.remove(element); return this; } public ListAdapter withAll(Iterable elements) { this.addAllIterable(elements); return this; } public ListAdapter withoutAll(Iterable elements) { this.removeAllIterable(elements); return this; } @Override public MutableList selectInstancesOf(Class clazz) { return ListIterate.selectInstancesOf(this.delegate, clazz); } public MutableList distinct() { return ListIterate.distinct(this.delegate, FastList.newList()); } public MutableList takeWhile(Predicate predicate) { return ListIterate.takeWhile(this.delegate, predicate); } public MutableList dropWhile(Predicate predicate) { return ListIterate.dropWhile(this.delegate, predicate); } public PartitionMutableList partitionWhile(Predicate predicate) { return ListIterate.partitionWhile(this.delegate, predicate); } @Override public MutableStack toStack() { return ArrayStack.newStack(this.delegate); } } MultiReaderFastList.java000066400000000000000000001151441234315411400351450ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/mutable/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.mutable; import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.RandomAccess; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.RichIterable; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.collection.primitive.MutableBooleanCollection; import com.gs.collections.api.collection.primitive.MutableByteCollection; import com.gs.collections.api.collection.primitive.MutableCharCollection; import com.gs.collections.api.collection.primitive.MutableDoubleCollection; import com.gs.collections.api.collection.primitive.MutableFloatCollection; import com.gs.collections.api.collection.primitive.MutableIntCollection; import com.gs.collections.api.collection.primitive.MutableLongCollection; import com.gs.collections.api.collection.primitive.MutableShortCollection; import com.gs.collections.api.list.ImmutableList; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.list.primitive.MutableBooleanList; import com.gs.collections.api.list.primitive.MutableByteList; import com.gs.collections.api.list.primitive.MutableCharList; import com.gs.collections.api.list.primitive.MutableDoubleList; import com.gs.collections.api.list.primitive.MutableFloatList; import com.gs.collections.api.list.primitive.MutableIntList; import com.gs.collections.api.list.primitive.MutableLongList; import com.gs.collections.api.list.primitive.MutableShortList; import com.gs.collections.api.map.MutableMap; import com.gs.collections.api.multimap.list.MutableListMultimap; import com.gs.collections.api.partition.list.PartitionMutableList; import com.gs.collections.api.stack.MutableStack; import com.gs.collections.api.tuple.Pair; import com.gs.collections.impl.collection.mutable.AbstractMultiReaderMutableCollection; import com.gs.collections.impl.factory.Lists; import com.gs.collections.impl.lazy.ReverseIterable; import com.gs.collections.impl.stack.mutable.ArrayStack; import com.gs.collections.impl.utility.LazyIterate; import static com.gs.collections.impl.factory.Iterables.*; /** * MultiReadFastList provides a thread-safe wrapper around a FastList, using a ReentrantReadWriteLock. In order to * provide true thread-safety, MultiReaderFastList does not implement iterator(), listIterator(), listIterator(int), or * get(int), as all of these methods require an external lock to be taken to provide thread-safe iteration. All of * these methods are available however, if you use the withReadLockAndDelegate() or withWriteLockAndDelegate() methods. * Both of these methods take a parameter of type Procedure, and a wrapped version of the underlying * FastList is returned. This wrapper guarantees that no external pointer can ever reference the underlying FastList * outside of a locked procedure. In the case of the read lock method, an Unmodifiable version of the collection is * offered, which will throw UnsupportedOperationExceptions on any write methods like add or remove. */ public final class MultiReaderFastList extends AbstractMultiReaderMutableCollection implements RandomAccess, Externalizable, MutableList { private static final long serialVersionUID = 1L; private transient ReadWriteLock lock; private MutableList delegate; @SuppressWarnings("UnusedDeclaration") public MultiReaderFastList() { // For Externalizable use only } private MultiReaderFastList(MutableList newDelegate) { this(newDelegate, new ReentrantReadWriteLock()); } private MultiReaderFastList(MutableList newDelegate, ReadWriteLock newLock) { this.lock = newLock; this.delegate = newDelegate; } public static MultiReaderFastList newList() { return new MultiReaderFastList(FastList.newList()); } public static MultiReaderFastList newList(int capacity) { return new MultiReaderFastList(FastList.newList(capacity)); } public static MultiReaderFastList newList(Iterable iterable) { return new MultiReaderFastList(FastList.newList(iterable)); } public static MultiReaderFastList newListWith(T... elements) { return new MultiReaderFastList(FastList.newListWith(elements)); } @Override protected MutableList getDelegate() { return this.delegate; } @Override protected ReadWriteLock getLock() { return this.lock; } UntouchableMutableList asReadUntouchable() { return new UntouchableMutableList(this.delegate.asUnmodifiable()); } UntouchableMutableList asWriteUntouchable() { return new UntouchableMutableList(this.delegate); } public void withReadLockAndDelegate(Procedure> procedure) { this.acquireReadLock(); try { UntouchableMutableList list = this.asReadUntouchable(); procedure.value(list); list.becomeUseless(); } finally { this.unlockReadLock(); } } public void withWriteLockAndDelegate(Procedure> procedure) { this.acquireWriteLock(); try { UntouchableMutableList list = this.asWriteUntouchable(); procedure.value(list); list.becomeUseless(); } finally { this.unlockWriteLock(); } } public MutableList asSynchronized() { this.acquireReadLock(); try { return SynchronizedMutableList.of(this); } finally { this.unlockReadLock(); } } public MutableList asUnmodifiable() { this.acquireReadLock(); try { return UnmodifiableMutableList.of(this); } finally { this.unlockReadLock(); } } public ImmutableList toImmutable() { this.acquireReadLock(); try { return Lists.immutable.ofAll(this.delegate); } finally { this.unlockReadLock(); } } @Override public MutableList clone() { this.acquireReadLock(); try { return new MultiReaderFastList(this.delegate.clone()); } finally { this.unlockReadLock(); } } public MutableList collect(Function function) { this.acquireReadLock(); try { return this.delegate.collect(function); } finally { this.unlockReadLock(); } } public MutableBooleanList collectBoolean(BooleanFunction booleanFunction) { this.acquireReadLock(); try { return this.delegate.collectBoolean(booleanFunction); } finally { this.unlockReadLock(); } } public MutableByteList collectByte(ByteFunction byteFunction) { this.acquireReadLock(); try { return this.delegate.collectByte(byteFunction); } finally { this.unlockReadLock(); } } public MutableCharList collectChar(CharFunction charFunction) { this.acquireReadLock(); try { return this.delegate.collectChar(charFunction); } finally { this.unlockReadLock(); } } public MutableDoubleList collectDouble(DoubleFunction doubleFunction) { this.acquireReadLock(); try { return this.delegate.collectDouble(doubleFunction); } finally { this.unlockReadLock(); } } public MutableFloatList collectFloat(FloatFunction floatFunction) { this.acquireReadLock(); try { return this.delegate.collectFloat(floatFunction); } finally { this.unlockReadLock(); } } public MutableIntList collectInt(IntFunction intFunction) { this.acquireReadLock(); try { return this.delegate.collectInt(intFunction); } finally { this.unlockReadLock(); } } public MutableLongList collectLong(LongFunction longFunction) { this.acquireReadLock(); try { return this.delegate.collectLong(longFunction); } finally { this.unlockReadLock(); } } public MutableShortList collectShort(ShortFunction shortFunction) { this.acquireReadLock(); try { return this.delegate.collectShort(shortFunction); } finally { this.unlockReadLock(); } } public MutableList flatCollect( Function> function) { this.acquireReadLock(); try { return this.delegate.flatCollect(function); } finally { this.unlockReadLock(); } } public MutableList collectIf( Predicate predicate, Function function) { this.acquireReadLock(); try { return this.delegate.collectIf(predicate, function); } finally { this.unlockReadLock(); } } public MutableList collectWith( Function2 function, P parameter) { this.acquireReadLock(); try { return this.delegate.collectWith(function, parameter); } finally { this.unlockReadLock(); } } public MutableList newEmpty() { return MultiReaderFastList.newList(); } public MutableList reject(Predicate predicate) { this.acquireReadLock(); try { return this.delegate.reject(predicate); } finally { this.unlockReadLock(); } } public

MutableList rejectWith( Predicate2 predicate, P parameter) { this.acquireReadLock(); try { return this.delegate.rejectWith(predicate, parameter); } finally { this.unlockReadLock(); } } public MutableList select(Predicate predicate) { this.acquireReadLock(); try { return this.delegate.select(predicate); } finally { this.unlockReadLock(); } } public

MutableList selectWith( Predicate2 predicate, P parameter) { this.acquireReadLock(); try { return this.delegate.selectWith(predicate, parameter); } finally { this.unlockReadLock(); } } public PartitionMutableList partition(Predicate predicate) { this.acquireReadLock(); try { return this.delegate.partition(predicate); } finally { this.unlockReadLock(); } } public

PartitionMutableList partitionWith(Predicate2 predicate, P parameter) { this.acquireReadLock(); try { return this.delegate.partitionWith(predicate, parameter); } finally { this.unlockReadLock(); } } public MutableList selectInstancesOf(Class clazz) { this.acquireReadLock(); try { return this.delegate.selectInstancesOf(clazz); } finally { this.unlockReadLock(); } } public MutableList distinct() { this.acquireReadLock(); try { return this.delegate.distinct(); } finally { this.unlockReadLock(); } } public MutableList sortThis() { this.acquireWriteLock(); try { this.delegate.sortThis(); return this; } finally { this.unlockWriteLock(); } } public MutableList sortThis(Comparator comparator) { this.acquireWriteLock(); try { this.delegate.sortThis(comparator); return this; } finally { this.unlockWriteLock(); } } public > MutableList sortThisBy( Function function) { this.acquireWriteLock(); try { this.delegate.sortThisBy(function); return this; } finally { this.unlockWriteLock(); } } public MutableList subList(int fromIndex, int toIndex) { this.acquireReadLock(); try { return new MultiReaderFastList(this.delegate.subList(fromIndex, toIndex), this.lock); } finally { this.unlockReadLock(); } } @Override public boolean equals(Object o) { this.acquireReadLock(); try { return this.delegate.equals(o); } finally { this.unlockReadLock(); } } @Override public int hashCode() { this.acquireReadLock(); try { return this.delegate.hashCode(); } finally { this.unlockReadLock(); } } public T get(int index) { this.acquireReadLock(); try { return this.delegate.get(index); } finally { this.unlockReadLock(); } } public int indexOf(Object o) { this.acquireReadLock(); try { return this.delegate.indexOf(o); } finally { this.unlockReadLock(); } } public int lastIndexOf(Object o) { this.acquireReadLock(); try { return this.delegate.lastIndexOf(o); } finally { this.unlockReadLock(); } } public MutableList with(T element) { this.add(element); return this; } public MutableList without(T element) { this.remove(element); return this; } public MutableList withAll(Iterable elements) { this.addAllIterable(elements); return this; } public MutableList withoutAll(Iterable elements) { this.removeAllIterable(elements); return this; } /** * This method is not supported directly on a MultiReaderFastList. If you would like to use a ListIterator with * MultiReaderFastList, then you must do the following: *

*

     * multiReaderList.withReadLockAndDelegate(new Procedure>()
     * {
     *     public void value(MutableList people)
     *     {
     *         Iterator it = people.listIterator();
     *         ....
     *     }
     * });
     * 
*/ public ListIterator listIterator() { throw new UnsupportedOperationException( "ListIterator is not supported for MultiReaderFastList. " + "If you would like to use a ListIterator, you must either use withReadLockAndDelegate() or withWriteLockAndDelegate()."); } /** * This method is not supported directly on a MultiReaderFastList. If you would like to use a ListIterator with * MultiReaderFastList, then you must do the following: *

*

     * multiReaderList.withReadLockAndDelegate(new Procedure>()
     * {
     *     public void value(MutableList people)
     *     {
     *         Iterator it = people.listIterator(0);
     *         ....
     *     }
     * });
     * 
*/ public ListIterator listIterator(int index) { throw new UnsupportedOperationException( "ListIterator is not supported for MultiReaderFastList. " + "If you would like to use a ListIterator, you must either use withReadLockAndDelegate() or withWriteLockAndDelegate()."); } public T remove(int index) { this.acquireWriteLock(); try { return this.delegate.remove(index); } finally { this.unlockWriteLock(); } } public T set(int index, T element) { this.acquireWriteLock(); try { return this.delegate.set(index, element); } finally { this.unlockWriteLock(); } } public boolean addAll(int index, Collection collection) { this.acquireWriteLock(); try { return this.delegate.addAll(index, collection); } finally { this.unlockWriteLock(); } } public void add(int index, T element) { this.acquireWriteLock(); try { this.delegate.add(index, element); } finally { this.unlockWriteLock(); } } public void forEach(int startIndex, int endIndex, Procedure procedure) { this.acquireReadLock(); try { this.delegate.forEach(startIndex, endIndex, procedure); } finally { this.unlockReadLock(); } } public int binarySearch(T key, Comparator comparator) { this.acquireReadLock(); try { return Collections.binarySearch(this, key, comparator); } finally { this.unlockReadLock(); } } public int binarySearch(T key) { this.acquireReadLock(); try { return Collections.binarySearch((List>) this, key); } finally { this.unlockReadLock(); } } public void reverseForEach(final Procedure procedure) { this.withReadLockRun(new Runnable() { public void run() { MultiReaderFastList.this.getDelegate().reverseForEach(procedure); } }); } public void forEachWithIndex(final int fromIndex, final int toIndex, final ObjectIntProcedure objectIntProcedure) { this.withReadLockRun(new Runnable() { public void run() { MultiReaderFastList.this.getDelegate().forEachWithIndex(fromIndex, toIndex, objectIntProcedure); } }); } public void writeExternal(ObjectOutput out) throws IOException { out.writeObject(this.delegate); } public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { this.delegate = (MutableList) in.readObject(); this.lock = new ReentrantReadWriteLock(); } // Exposed for testing static final class UntouchableMutableList extends UntouchableMutableCollection implements MutableList { private final MutableList> requestedIterators = mList(); private final MutableList> requestedSubLists = mList(); private UntouchableMutableList(MutableList delegate) { this.delegate = delegate; } public MutableList with(T element) { this.add(element); return this; } public MutableList without(T element) { this.remove(element); return this; } public MutableList withAll(Iterable elements) { this.addAllIterable(elements); return this; } public MutableList withoutAll(Iterable elements) { this.removeAllIterable(elements); return this; } public MutableList asSynchronized() { throw new UnsupportedOperationException("Cannot call asSynchronized() on " + this.getClass().getSimpleName()); } public MutableList asUnmodifiable() { throw new UnsupportedOperationException("Cannot call asUnmodifiable() on " + this.getClass().getSimpleName()); } public LazyIterable asLazy() { return LazyIterate.adapt(this); } public ImmutableList toImmutable() { return Lists.immutable.ofAll(this.getDelegate()); } @Override public MutableList clone() { return this.getDelegate().clone(); } public MutableList collect(Function function) { return this.getDelegate().collect(function); } public MutableBooleanList collectBoolean(BooleanFunction booleanFunction) { return this.getDelegate().collectBoolean(booleanFunction); } public R collectBoolean(BooleanFunction booleanFunction, R target) { return this.getDelegate().collectBoolean(booleanFunction, target); } public MutableByteList collectByte(ByteFunction byteFunction) { return this.getDelegate().collectByte(byteFunction); } public R collectByte(ByteFunction byteFunction, R target) { return this.getDelegate().collectByte(byteFunction, target); } public MutableCharList collectChar(CharFunction charFunction) { return this.getDelegate().collectChar(charFunction); } public R collectChar(CharFunction charFunction, R target) { return this.getDelegate().collectChar(charFunction, target); } public MutableDoubleList collectDouble(DoubleFunction doubleFunction) { return this.getDelegate().collectDouble(doubleFunction); } public R collectDouble(DoubleFunction doubleFunction, R target) { return this.getDelegate().collectDouble(doubleFunction, target); } public MutableFloatList collectFloat(FloatFunction floatFunction) { return this.getDelegate().collectFloat(floatFunction); } public R collectFloat(FloatFunction floatFunction, R target) { return this.getDelegate().collectFloat(floatFunction, target); } public MutableIntList collectInt(IntFunction intFunction) { return this.getDelegate().collectInt(intFunction); } public R collectInt(IntFunction intFunction, R target) { return this.getDelegate().collectInt(intFunction, target); } public MutableLongList collectLong(LongFunction longFunction) { return this.getDelegate().collectLong(longFunction); } public R collectLong(LongFunction longFunction, R target) { return this.getDelegate().collectLong(longFunction, target); } public MutableShortList collectShort(ShortFunction shortFunction) { return this.getDelegate().collectShort(shortFunction); } public R collectShort(ShortFunction shortFunction, R target) { return this.getDelegate().collectShort(shortFunction, target); } public MutableList flatCollect(Function> function) { return this.getDelegate().flatCollect(function); } public MutableList collectIf( Predicate predicate, Function function) { return this.getDelegate().collectIf(predicate, function); } public MutableList collectWith( Function2 function, P parameter) { return this.getDelegate().collectWith(function, parameter); } public MutableListMultimap groupBy(Function function) { return this.getDelegate().groupBy(function); } public MutableListMultimap groupByEach(Function> function) { return this.getDelegate().groupByEach(function); } public MutableMap groupByUniqueKey(Function function) { return this.getDelegate().groupByUniqueKey(function); } public void forEach(int fromIndex, int toIndex, Procedure procedure) { this.getDelegate().forEach(fromIndex, toIndex, procedure); } public void reverseForEach(Procedure procedure) { this.getDelegate().reverseForEach(procedure); } public void forEachWithIndex(int fromIndex, int toIndex, ObjectIntProcedure objectIntProcedure) { this.getDelegate().forEachWithIndex(fromIndex, toIndex, objectIntProcedure); } public MutableList newEmpty() { return this.getDelegate().newEmpty(); } public MutableList reject(Predicate predicate) { return this.getDelegate().reject(predicate); } public MutableList distinct() { return this.getDelegate().distinct(); } public

MutableList rejectWith( Predicate2 predicate, P parameter) { return this.getDelegate().rejectWith(predicate, parameter); } public MutableList select(Predicate predicate) { return this.getDelegate().select(predicate); } public

MutableList selectWith( Predicate2 predicate, P parameter) { return this.getDelegate().selectWith(predicate, parameter); } public PartitionMutableList partition(Predicate predicate) { return this.getDelegate().partition(predicate); } public

PartitionMutableList partitionWith(Predicate2 predicate, P parameter) { return this.getDelegate().partitionWith(predicate, parameter); } public MutableList selectInstancesOf(Class clazz) { return this.getDelegate().selectInstancesOf(clazz); } public MutableList sortThis() { this.getDelegate().sortThis(); return this; } public MutableList sortThis(Comparator comparator) { this.getDelegate().sortThis(comparator); return this; } public MutableList toReversed() { return this.getDelegate().toReversed(); } public MutableList reverseThis() { this.getDelegate().reverseThis(); return this; } public MutableStack toStack() { return ArrayStack.newStack(this.delegate); } public > MutableList sortThisBy(Function function) { this.getDelegate().sortThisBy(function); return this; } public MutableList takeWhile(Predicate predicate) { return this.getDelegate().takeWhile(predicate); } public MutableList dropWhile(Predicate predicate) { return this.getDelegate().dropWhile(predicate); } public PartitionMutableList partitionWhile(Predicate predicate) { return this.getDelegate().partitionWhile(predicate); } public MutableList subList(int fromIndex, int toIndex) { UntouchableMutableList subList = new UntouchableMutableList( this.getDelegate().subList(fromIndex, toIndex)); this.requestedSubLists.add(subList); return subList; } public Iterator iterator() { UntouchableListIterator iterator = new UntouchableListIterator(this.delegate.iterator()); this.requestedIterators.add(iterator); return iterator; } public void add(int index, T element) { this.getDelegate().add(index, element); } public boolean addAll(int index, Collection collection) { return this.getDelegate().addAll(index, collection); } public T get(int index) { return this.getDelegate().get(index); } public int indexOf(Object o) { return this.getDelegate().indexOf(o); } public int lastIndexOf(Object o) { return this.getDelegate().lastIndexOf(o); } public ListIterator listIterator() { UntouchableListIterator iterator = new UntouchableListIterator(this.getDelegate().listIterator()); this.requestedIterators.add(iterator); return iterator; } public ListIterator listIterator(int index) { UntouchableListIterator iterator = new UntouchableListIterator(this.getDelegate().listIterator(index)); this.requestedIterators.add(iterator); return iterator; } public T remove(int index) { return this.getDelegate().remove(index); } public T set(int index, T element) { return this.getDelegate().set(index, element); } public MutableList> zip(Iterable that) { return this.getDelegate().zip(that); } public MutableList> zipWithIndex() { return this.getDelegate().zipWithIndex(); } public LazyIterable asReversed() { return ReverseIterable.adapt(this); } public int binarySearch(T key, Comparator comparator) { return Collections.binarySearch(this, key, comparator); } public int binarySearch(T key) { return Collections.binarySearch((List>) this, key); } public void becomeUseless() { this.delegate = null; this.requestedSubLists.forEach(new Procedure>() { public void value(UntouchableMutableList each) { each.becomeUseless(); } }); this.requestedIterators.forEach(new Procedure>() { public void value(UntouchableListIterator each) { each.becomeUseless(); } }); } private MutableList getDelegate() { return (MutableList) this.delegate; } } private static final class UntouchableListIterator implements ListIterator { private Iterator delegate; private UntouchableListIterator(Iterator newDelegate) { this.delegate = newDelegate; } public void add(T o) { ((ListIterator) this.delegate).add(o); } public boolean hasNext() { return this.delegate.hasNext(); } public boolean hasPrevious() { return ((ListIterator) this.delegate).hasPrevious(); } public T next() { return this.delegate.next(); } public int nextIndex() { return ((ListIterator) this.delegate).nextIndex(); } public T previous() { return ((ListIterator) this.delegate).previous(); } public int previousIndex() { return ((ListIterator) this.delegate).previousIndex(); } public void remove() { this.delegate.remove(); } public void set(T o) { ((ListIterator) this.delegate).set(o); } public void becomeUseless() { this.delegate = null; } } public MutableListMultimap groupBy(Function function) { this.acquireReadLock(); try { return this.delegate.groupBy(function); } finally { this.unlockReadLock(); } } public MutableListMultimap groupByEach(Function> function) { this.acquireReadLock(); try { return this.delegate.groupByEach(function); } finally { this.unlockReadLock(); } } public MutableMap groupByUniqueKey(Function function) { this.acquireReadLock(); try { return this.delegate.groupByUniqueKey(function); } finally { this.unlockReadLock(); } } public MutableList> zip(Iterable that) { this.acquireReadLock(); try { return this.delegate.zip(that); } finally { this.unlockReadLock(); } } public MutableList> zipWithIndex() { this.acquireReadLock(); try { return this.delegate.zipWithIndex(); } finally { this.unlockReadLock(); } } public MutableList toReversed() { this.acquireReadLock(); try { return this.delegate.toReversed(); } finally { this.unlockReadLock(); } } public MutableList reverseThis() { this.acquireWriteLock(); try { this.delegate.reverseThis(); return this; } finally { this.unlockWriteLock(); } } public MutableStack toStack() { this.acquireReadLock(); try { return this.delegate.toStack(); } finally { this.unlockReadLock(); } } public RichIterable> chunk(int size) { this.acquireReadLock(); try { return this.delegate.chunk(size); } finally { this.unlockReadLock(); } } public MutableList takeWhile(Predicate predicate) { this.acquireReadLock(); try { return this.delegate.takeWhile(predicate); } finally { this.unlockReadLock(); } } public MutableList dropWhile(Predicate predicate) { this.acquireReadLock(); try { return this.delegate.dropWhile(predicate); } finally { this.unlockReadLock(); } } public PartitionMutableList partitionWhile(Predicate predicate) { this.acquireReadLock(); try { return this.delegate.partitionWhile(predicate); } finally { this.unlockReadLock(); } } public LazyIterable asReversed() { this.acquireReadLock(); try { return ReverseIterable.adapt(this); } finally { this.unlockReadLock(); } } } MutableIterator.java000066400000000000000000000036231234315411400343570ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/mutable/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.mutable; import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; public class MutableIterator implements Iterator { /** * Index of element to be returned by subsequent call to next. */ protected int currentIndex; /** * Index of element returned by most recent call to next or previous. Reset to -1 if this element is deleted by * a call to remove. */ protected int lastIndex = -1; protected final List list; public MutableIterator(List list) { this.list = list; } public boolean hasNext() { return this.currentIndex != this.list.size(); } public T next() { try { T next = this.list.get(this.currentIndex); this.lastIndex = this.currentIndex++; return next; } catch (IndexOutOfBoundsException ignored) { throw new NoSuchElementException(); } } public void remove() { if (this.lastIndex == -1) { throw new IllegalStateException(); } this.list.remove(this.lastIndex); if (this.lastIndex < this.currentIndex) { this.currentIndex--; } this.lastIndex = -1; } } MutableListFactoryImpl.java000066400000000000000000000032231234315411400356470ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/mutable/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.mutable; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.factory.list.MutableListFactory; import com.gs.collections.api.list.MutableList; import net.jcip.annotations.Immutable; @Immutable public final class MutableListFactoryImpl implements MutableListFactory { public MutableList of() { return this.with(); } public MutableList with() { return FastList.newList(); } public MutableList of(T... items) { return this.with(items); } public MutableList with(T... items) { return FastList.newListWith(items); } public MutableList ofAll(Iterable iterable) { return this.withAll(iterable); } public MutableList withAll(Iterable iterable) { return FastList.newList(iterable); } public MutableList withNValues(int size, Function0 factory) { return FastList.newWithNValues(size, factory); } } MutableListIterator.java000066400000000000000000000040451234315411400352120ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/mutable/* * Copyright 2011 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.mutable; import java.util.ConcurrentModificationException; import java.util.List; import java.util.ListIterator; import java.util.NoSuchElementException; public final class MutableListIterator extends MutableIterator implements ListIterator { public MutableListIterator(List list, int index) { super(list); this.currentIndex = index; } public boolean hasPrevious() { return this.currentIndex != 0; } public T previous() { try { int i = this.currentIndex - 1; T previous = this.list.get(i); this.currentIndex = i; this.lastIndex = i; return previous; } catch (IndexOutOfBoundsException ignored) { throw new NoSuchElementException(); } } public int nextIndex() { return this.currentIndex; } public int previousIndex() { return this.currentIndex - 1; } public void set(T o) { if (this.lastIndex == -1) { throw new IllegalStateException(); } try { this.list.set(this.lastIndex, o); } catch (IndexOutOfBoundsException ignored) { throw new ConcurrentModificationException(); } } public void add(T o) { this.list.add(this.currentIndex++, o); this.lastIndex = -1; } } RandomAccessListAdapter.java000066400000000000000000000371261234315411400357600ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/mutable/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.mutable; import java.io.Serializable; import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.RandomAccess; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function0; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.list.ImmutableList; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.list.primitive.MutableBooleanList; import com.gs.collections.api.list.primitive.MutableByteList; import com.gs.collections.api.list.primitive.MutableCharList; import com.gs.collections.api.list.primitive.MutableDoubleList; import com.gs.collections.api.list.primitive.MutableFloatList; import com.gs.collections.api.list.primitive.MutableIntList; import com.gs.collections.api.list.primitive.MutableLongList; import com.gs.collections.api.list.primitive.MutableShortList; import com.gs.collections.api.partition.list.PartitionMutableList; import com.gs.collections.api.tuple.Pair; import com.gs.collections.impl.block.factory.Comparators; import com.gs.collections.impl.block.procedure.CollectionAddProcedure; import com.gs.collections.impl.block.procedure.primitive.CollectBooleanProcedure; import com.gs.collections.impl.block.procedure.primitive.CollectByteProcedure; import com.gs.collections.impl.block.procedure.primitive.CollectCharProcedure; import com.gs.collections.impl.block.procedure.primitive.CollectDoubleProcedure; import com.gs.collections.impl.block.procedure.primitive.CollectFloatProcedure; import com.gs.collections.impl.block.procedure.primitive.CollectIntProcedure; import com.gs.collections.impl.block.procedure.primitive.CollectLongProcedure; import com.gs.collections.impl.block.procedure.primitive.CollectShortProcedure; import com.gs.collections.impl.factory.Lists; import com.gs.collections.impl.list.mutable.primitive.BooleanArrayList; import com.gs.collections.impl.list.mutable.primitive.ByteArrayList; import com.gs.collections.impl.list.mutable.primitive.CharArrayList; import com.gs.collections.impl.list.mutable.primitive.DoubleArrayList; import com.gs.collections.impl.list.mutable.primitive.FloatArrayList; import com.gs.collections.impl.list.mutable.primitive.IntArrayList; import com.gs.collections.impl.list.mutable.primitive.LongArrayList; import com.gs.collections.impl.list.mutable.primitive.ShortArrayList; import com.gs.collections.impl.multimap.list.FastListMultimap; import com.gs.collections.impl.utility.ArrayIterate; import com.gs.collections.impl.utility.Iterate; import com.gs.collections.impl.utility.ListIterate; import com.gs.collections.impl.utility.internal.RandomAccessListIterate; /** * This class provides a MutableList wrapper around a JDK Collections List interface instance. All of the MutableList * interface methods are supported in addition to the JDK List interface methods. *

* To create a new wrapper around an existing List instance, use the {@link #adapt(List)} factory method. */ public final class RandomAccessListAdapter extends AbstractListAdapter implements RandomAccess, Serializable { private static final long serialVersionUID = 1L; private final List delegate; RandomAccessListAdapter(List newDelegate) { if (newDelegate == null) { throw new NullPointerException("RandomAccessListAdapter may not wrap null"); } if (!(newDelegate instanceof RandomAccess)) { throw new IllegalArgumentException("RandomAccessListAdapter may not wrap a non RandomAccess list"); } this.delegate = newDelegate; } @Override protected List getDelegate() { return this.delegate; } public static MutableList adapt(List list) { if (list instanceof MutableList) { return (MutableList) list; } if (list instanceof ArrayList) { return ArrayListAdapter.adapt((ArrayList) list); } return new RandomAccessListAdapter(list); } public ImmutableList toImmutable() { return Lists.immutable.ofAll(this.delegate); } public MutableList asUnmodifiable() { return UnmodifiableMutableList.of(this); } public MutableList asSynchronized() { return SynchronizedMutableList.of(this); } @Override public MutableList clone() { return FastList.newList(this.delegate); } /** * @deprecated use {@link FastList#newList()} instead (inlineable) */ @Deprecated public MutableList newEmpty() { return Lists.mutable.of(); } @Override public void forEach(Procedure procedure) { RandomAccessListIterate.forEach(this.delegate, procedure); } public void reverseForEach(Procedure procedure) { ListIterate.reverseForEach(this.delegate, procedure); } @Override public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { RandomAccessListIterate.forEachWithIndex(this.delegate, objectIntProcedure); } public void forEachWithIndex(int fromIndex, int toIndex, ObjectIntProcedure objectIntProcedure) { RandomAccessListIterate.forEachWithIndex(this.delegate, fromIndex, toIndex, objectIntProcedure); } @Override public T detect(Predicate predicate) { return RandomAccessListIterate.detect(this.delegate, predicate); } @Override public T detectIfNone(Predicate predicate, Function0 function) { T result = this.detect(predicate); return result == null ? function.value() : result; } @Override public int count(Predicate predicate) { return RandomAccessListIterate.count(this.delegate, predicate); } @Override public boolean anySatisfy(Predicate predicate) { return RandomAccessListIterate.anySatisfy(this.delegate, predicate); } @Override public boolean allSatisfy(Predicate predicate) { return RandomAccessListIterate.allSatisfy(this.delegate, predicate); } @Override public boolean noneSatisfy(Predicate predicate) { return RandomAccessListIterate.noneSatisfy(this.delegate, predicate); } @Override public IV injectInto(IV injectedValue, Function2 function) { return RandomAccessListIterate.injectInto(injectedValue, this.delegate, function); } public void forEach(int fromIndex, int toIndex, Procedure procedure) { RandomAccessListIterate.forEach(this.delegate, fromIndex, toIndex, procedure); } public RandomAccessListAdapter sortThis(Comparator comparator) { Iterate.sortThis(this.delegate, comparator); return this; } public RandomAccessListAdapter sortThis() { return this.sortThis(Comparators.naturalOrder()); } public > MutableList sortThisBy(Function function) { return this.sortThis(Comparators.byFunction(function)); } public RandomAccessListAdapter with(T element) { this.add(element); return this; } public RandomAccessListAdapter with(T element1, T element2) { this.add(element1); this.add(element2); return this; } public RandomAccessListAdapter with(T element1, T element2, T element3) { this.add(element1); this.add(element2); this.add(element3); return this; } public RandomAccessListAdapter with(T... elements) { ArrayIterate.forEach(elements, CollectionAddProcedure.on(this.delegate)); return this; } public RandomAccessListAdapter without(T element) { this.remove(element); return this; } public RandomAccessListAdapter withAll(Iterable elements) { this.addAllIterable(elements); return this; } public RandomAccessListAdapter withoutAll(Iterable elements) { this.removeAllIterable(elements); return this; } @Override public MutableList select(Predicate predicate) { return RandomAccessListIterate.select(this.delegate, predicate, FastList.newList()); } @Override public MutableList reject(Predicate predicate) { return RandomAccessListIterate.reject(this.delegate, predicate, FastList.newList()); } @Override public PartitionMutableList partition(Predicate predicate) { return RandomAccessListIterate.partition(this.delegate, predicate); } @Override public

PartitionMutableList partitionWith(Predicate2 predicate, P parameter) { return RandomAccessListIterate.partitionWith(this.delegate, predicate, parameter); } @Override public MutableList selectInstancesOf(Class clazz) { return RandomAccessListIterate.selectInstancesOf(this.delegate, clazz); } @Override public MutableList collect(Function function) { return RandomAccessListIterate.collect(this.delegate, function, FastList.newList(this.delegate.size())); } @Override public MutableBooleanList collectBoolean(BooleanFunction booleanFunction) { BooleanArrayList result = new BooleanArrayList(this.size()); this.forEach(new CollectBooleanProcedure(booleanFunction, result)); return result; } @Override public MutableByteList collectByte(ByteFunction byteFunction) { ByteArrayList result = new ByteArrayList(this.size()); this.forEach(new CollectByteProcedure(byteFunction, result)); return result; } @Override public MutableCharList collectChar(CharFunction charFunction) { CharArrayList result = new CharArrayList(this.size()); this.forEach(new CollectCharProcedure(charFunction, result)); return result; } @Override public MutableDoubleList collectDouble(DoubleFunction doubleFunction) { DoubleArrayList result = new DoubleArrayList(this.size()); this.forEach(new CollectDoubleProcedure(doubleFunction, result)); return result; } @Override public MutableFloatList collectFloat(FloatFunction floatFunction) { FloatArrayList result = new FloatArrayList(this.size()); this.forEach(new CollectFloatProcedure(floatFunction, result)); return result; } @Override public MutableIntList collectInt(IntFunction intFunction) { IntArrayList result = new IntArrayList(this.size()); this.forEach(new CollectIntProcedure(intFunction, result)); return result; } @Override public MutableLongList collectLong(LongFunction longFunction) { LongArrayList result = new LongArrayList(this.size()); this.forEach(new CollectLongProcedure(longFunction, result)); return result; } @Override public MutableShortList collectShort(ShortFunction shortFunction) { ShortArrayList result = new ShortArrayList(this.size()); this.forEach(new CollectShortProcedure(shortFunction, result)); return result; } @Override public MutableList flatCollect(Function> function) { return RandomAccessListIterate.flatCollect(this.delegate, function, FastList.newList(this.delegate.size())); } @Override public MutableList collectIf( Predicate predicate, Function function) { return RandomAccessListIterate.collectIf(this.delegate, predicate, function, FastList.newList()); } @Override public FastListMultimap groupBy(Function function) { return RandomAccessListIterate.groupBy(this.delegate, function, FastListMultimap.newMultimap()); } @Override public FastListMultimap groupByEach(Function> function) { return RandomAccessListIterate.groupByEach(this.delegate, function, FastListMultimap.newMultimap()); } @Override public

MutableList selectWith(Predicate2 predicate, P parameter) { return RandomAccessListIterate.selectWith(this.delegate, predicate, parameter, FastList.newList()); } @Override public

MutableList rejectWith(Predicate2 predicate, P parameter) { return RandomAccessListIterate.rejectWith(this.delegate, predicate, parameter, FastList.newList()); } @Override public MutableList collectWith(Function2 function, P parameter) { return RandomAccessListIterate.collectWith(this.delegate, function, parameter, FastList.newList(this.delegate.size())); } public MutableList distinct() { return RandomAccessListIterate.distinct(this.delegate, FastList.newList()); } @Override public MutableList> zip(Iterable that) { return RandomAccessListIterate.zip(this.delegate, that, FastList.>newList(this.delegate.size())); } @Override public MutableList> zipWithIndex() { return RandomAccessListIterate.zipWithIndex(this.delegate, FastList.>newList(this.delegate.size())); } public MutableList takeWhile(Predicate predicate) { return RandomAccessListIterate.takeWhile(this.delegate, predicate); } public MutableList dropWhile(Predicate predicate) { return RandomAccessListIterate.dropWhile(this.delegate, predicate); } public PartitionMutableList partitionWhile(Predicate predicate) { return RandomAccessListIterate.partitionWhile(this.delegate, predicate); } } SynchronizedMutableList.java000066400000000000000000000422531234315411400361030ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/mutable/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.mutable; import java.io.Serializable; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.ListIterator; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.list.ImmutableList; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.list.primitive.MutableBooleanList; import com.gs.collections.api.list.primitive.MutableByteList; import com.gs.collections.api.list.primitive.MutableCharList; import com.gs.collections.api.list.primitive.MutableDoubleList; import com.gs.collections.api.list.primitive.MutableFloatList; import com.gs.collections.api.list.primitive.MutableIntList; import com.gs.collections.api.list.primitive.MutableLongList; import com.gs.collections.api.list.primitive.MutableShortList; import com.gs.collections.api.multimap.list.MutableListMultimap; import com.gs.collections.api.partition.list.PartitionMutableList; import com.gs.collections.api.stack.MutableStack; import com.gs.collections.api.tuple.Pair; import com.gs.collections.impl.collection.mutable.AbstractSynchronizedMutableCollection; import com.gs.collections.impl.collection.mutable.SynchronizedCollectionSerializationProxy; import com.gs.collections.impl.factory.Lists; import com.gs.collections.impl.lazy.ReverseIterable; import net.jcip.annotations.GuardedBy; /** * A synchronized view of a {@link MutableList}. It is imperative that the user manually synchronize on the collection when iterating over it using the * standard JDK iterator or JDK 5 for loop, as per {@link Collections#synchronizedCollection(Collection)}. * * @see MutableList#asSynchronized() */ public class SynchronizedMutableList extends AbstractSynchronizedMutableCollection implements MutableList, Serializable { SynchronizedMutableList(MutableList newCollection) { super(newCollection); } SynchronizedMutableList(MutableList newCollection, Object newLock) { super(newCollection, newLock); } /** * This method will take a MutableList and wrap it directly in a SynchronizedMutableList. It will * take any other non-GS-collection and first adapt it will a ListAdapter, and then return a * SynchronizedMutableList that wraps the adapter. */ public static > SynchronizedMutableList of(L list) { MutableList mutableList = list instanceof MutableList ? (MutableList) list : ListAdapter.adapt(list); return new SynchronizedMutableList(mutableList); } /** * This method will take a MutableList and wrap it directly in a SynchronizedMutableList. It will * take any other non-GS-collection and first adapt it will a ListAdapter, and then return a * SynchronizedMutableList that wraps the adapter. Additionally, a developer specifies which lock to use * with the collection. */ public static > SynchronizedMutableList of(L list, Object lock) { MutableList mutableList = list instanceof MutableList ? (MutableList) list : ListAdapter.adapt(list); return new SynchronizedMutableList(mutableList, lock); } @GuardedBy("getLock()") private MutableList getMutableList() { return (MutableList) this.getCollection(); } @Override public boolean equals(Object obj) { synchronized (this.getLock()) { return this.getMutableList().equals(obj); } } @Override public int hashCode() { synchronized (this.getLock()) { return this.getMutableList().hashCode(); } } @Override public MutableList asUnmodifiable() { synchronized (this.getLock()) { return UnmodifiableMutableList.of(this); } } @Override public ImmutableList toImmutable() { synchronized (this.getLock()) { return Lists.immutable.ofAll(this); } } @Override public MutableList asSynchronized() { return this; } @Override public MutableList clone() { synchronized (this.getLock()) { return of(this.getMutableList().clone()); } } @Override public MutableList collect(Function function) { synchronized (this.getLock()) { return this.getMutableList().collect(function); } } @Override public MutableBooleanList collectBoolean(BooleanFunction booleanFunction) { synchronized (this.getLock()) { return this.getMutableList().collectBoolean(booleanFunction); } } @Override public MutableByteList collectByte(ByteFunction byteFunction) { synchronized (this.getLock()) { return this.getMutableList().collectByte(byteFunction); } } @Override public MutableCharList collectChar(CharFunction charFunction) { synchronized (this.getLock()) { return this.getMutableList().collectChar(charFunction); } } @Override public MutableDoubleList collectDouble(DoubleFunction doubleFunction) { synchronized (this.getLock()) { return this.getMutableList().collectDouble(doubleFunction); } } @Override public MutableFloatList collectFloat(FloatFunction floatFunction) { synchronized (this.getLock()) { return this.getMutableList().collectFloat(floatFunction); } } @Override public MutableIntList collectInt(IntFunction intFunction) { synchronized (this.getLock()) { return this.getMutableList().collectInt(intFunction); } } @Override public MutableLongList collectLong(LongFunction longFunction) { synchronized (this.getLock()) { return this.getMutableList().collectLong(longFunction); } } @Override public MutableShortList collectShort(ShortFunction shortFunction) { synchronized (this.getLock()) { return this.getMutableList().collectShort(shortFunction); } } @Override public MutableList flatCollect(Function> function) { synchronized (this.getLock()) { return this.getMutableList().flatCollect(function); } } @Override public MutableList collectIf( Predicate predicate, Function function) { synchronized (this.getLock()) { return this.getMutableList().collectIf(predicate, function); } } @Override public MutableList collectWith(Function2 function, P parameter) { synchronized (this.getLock()) { return this.getMutableList().collectWith(function, parameter); } } @Override public MutableListMultimap groupBy(Function function) { synchronized (this.getLock()) { return this.getMutableList().groupBy(function); } } @Override public MutableListMultimap groupByEach(Function> function) { synchronized (this.getLock()) { return this.getMutableList().groupByEach(function); } } public void forEach(int fromIndex, int toIndex, Procedure procedure) { synchronized (this.getLock()) { this.getMutableList().forEach(fromIndex, toIndex, procedure); } } public void reverseForEach(Procedure procedure) { synchronized (this.getLock()) { this.getMutableList().reverseForEach(procedure); } } public void forEachWithIndex(int fromIndex, int toIndex, ObjectIntProcedure objectIntProcedure) { synchronized (this.getLock()) { this.getMutableList().forEachWithIndex(fromIndex, toIndex, objectIntProcedure); } } @Override public MutableList newEmpty() { synchronized (this.getLock()) { return this.getMutableList().newEmpty(); } } @Override public MutableList reject(Predicate predicate) { synchronized (this.getLock()) { return this.getMutableList().reject(predicate); } } @Override public

MutableList rejectWith(Predicate2 predicate, P parameter) { synchronized (this.getLock()) { return this.getMutableList().rejectWith(predicate, parameter); } } @Override public MutableList select(Predicate predicate) { synchronized (this.getLock()) { return this.getMutableList().select(predicate); } } @Override public

MutableList selectWith( Predicate2 predicate, P parameter) { synchronized (this.getLock()) { return this.getMutableList().selectWith(predicate, parameter); } } @Override public PartitionMutableList partition(Predicate predicate) { synchronized (this.getLock()) { return this.getMutableList().partition(predicate); } } @Override public

PartitionMutableList partitionWith(Predicate2 predicate, P parameter) { synchronized (this.getLock()) { return this.getMutableList().partitionWith(predicate, parameter); } } @Override public MutableList selectInstancesOf(Class clazz) { synchronized (this.getLock()) { return this.getMutableList().selectInstancesOf(clazz); } } public MutableList distinct() { synchronized (this.getLock()) { return this.getMutableList().distinct(); } } public MutableList sortThis() { synchronized (this.getLock()) { this.getMutableList().sortThis(); return this; } } public MutableList sortThis(Comparator comparator) { synchronized (this.getLock()) { this.getMutableList().sortThis(comparator); return this; } } public > MutableList sortThisBy(Function function) { synchronized (this.getLock()) { this.getMutableList().sortThisBy(function); return this; } } public MutableList subList(int fromIndex, int toIndex) { synchronized (this.getLock()) { return of(this.getMutableList().subList(fromIndex, toIndex), this.getLock()); } } public void add(int index, T element) { synchronized (this.getLock()) { this.getMutableList().add(index, element); } } public boolean addAll(int index, Collection collection) { synchronized (this.getLock()) { return this.getMutableList().addAll(index, collection); } } public T get(int index) { synchronized (this.getLock()) { return this.getMutableList().get(index); } } public int indexOf(Object o) { synchronized (this.getLock()) { return this.getMutableList().indexOf(o); } } public int lastIndexOf(Object o) { synchronized (this.getLock()) { return this.getMutableList().lastIndexOf(o); } } public ListIterator listIterator() { return this.getMutableList().listIterator(); } public ListIterator listIterator(int index) { return this.getMutableList().listIterator(index); } public T remove(int index) { synchronized (this.getLock()) { return this.getMutableList().remove(index); } } public T set(int index, T element) { synchronized (this.getLock()) { return this.getMutableList().set(index, element); } } @Override public MutableList> zip(Iterable that) { synchronized (this.getLock()) { return this.getMutableList().zip(that); } } @Override public >> R zip(Iterable that, R target) { synchronized (this.getLock()) { return this.getMutableList().zip(that, target); } } @Override public MutableList> zipWithIndex() { synchronized (this.getLock()) { return this.getMutableList().zipWithIndex(); } } public MutableList toReversed() { synchronized (this.getLock()) { return this.getMutableList().toReversed(); } } public MutableList reverseThis() { synchronized (this.getLock()) { this.getMutableList().reverseThis(); return this; } } public MutableStack toStack() { synchronized (this.getLock()) { return this.getMutableList().toStack(); } } @Override public >> R zipWithIndex(R target) { synchronized (this.getLock()) { return this.getMutableList().zipWithIndex(target); } } public MutableList takeWhile(Predicate predicate) { synchronized (this.getLock()) { return this.getMutableList().takeWhile(predicate); } } public MutableList dropWhile(Predicate predicate) { synchronized (this.getLock()) { return this.getMutableList().dropWhile(predicate); } } public PartitionMutableList partitionWhile(Predicate predicate) { synchronized (this.getLock()) { return this.getMutableList().partitionWhile(predicate); } } public LazyIterable asReversed() { synchronized (this.getLock()) { return ReverseIterable.adapt(this); } } public int binarySearch(T key, Comparator comparator) { synchronized (this.getLock()) { return Collections.binarySearch(this, key, comparator); } } public int binarySearch(T key) { synchronized (this.getLock()) { return Collections.binarySearch((List>) this, key); } } @Override public MutableList with(T element) { this.add(element); return this; } @Override public MutableList without(T element) { this.remove(element); return this; } @Override public MutableList withAll(Iterable elements) { this.addAllIterable(elements); return this; } @Override public MutableList withoutAll(Iterable elements) { this.removeAllIterable(elements); return this; } protected Object writeReplace() { return new SynchronizedCollectionSerializationProxy(this.getMutableList()); } } UnmodifiableListIteratorAdapter.java000066400000000000000000000035141234315411400375200ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/mutable/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.mutable; import java.util.ListIterator; public class UnmodifiableListIteratorAdapter implements ListIterator { private final ListIterator iterator; public UnmodifiableListIteratorAdapter(ListIterator iterator) { this.iterator = iterator; } public boolean hasNext() { return this.iterator.hasNext(); } public T next() { return this.iterator.next(); } public boolean hasPrevious() { return this.iterator.hasPrevious(); } public T previous() { return this.iterator.previous(); } public int nextIndex() { return this.iterator.nextIndex(); } public int previousIndex() { return this.iterator.previousIndex(); } public void remove() { throw new UnsupportedOperationException("Cannot call remove() on " + this.getClass().getSimpleName()); } public void set(T o) { throw new UnsupportedOperationException("Cannot call set() on " + this.getClass().getSimpleName()); } public void add(T o) { throw new UnsupportedOperationException("Cannot call add() on " + this.getClass().getSimpleName()); } } UnmodifiableMutableList.java000066400000000000000000000335531234315411400360250ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/mutable/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.mutable; import java.io.Serializable; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.ListIterator; import java.util.RandomAccess; import com.gs.collections.api.LazyIterable; import com.gs.collections.api.block.function.Function; import com.gs.collections.api.block.function.Function2; import com.gs.collections.api.block.function.primitive.BooleanFunction; import com.gs.collections.api.block.function.primitive.ByteFunction; import com.gs.collections.api.block.function.primitive.CharFunction; import com.gs.collections.api.block.function.primitive.DoubleFunction; import com.gs.collections.api.block.function.primitive.FloatFunction; import com.gs.collections.api.block.function.primitive.IntFunction; import com.gs.collections.api.block.function.primitive.LongFunction; import com.gs.collections.api.block.function.primitive.ShortFunction; import com.gs.collections.api.block.predicate.Predicate; import com.gs.collections.api.block.predicate.Predicate2; import com.gs.collections.api.block.procedure.Procedure; import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure; import com.gs.collections.api.list.ImmutableList; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.list.primitive.MutableBooleanList; import com.gs.collections.api.list.primitive.MutableByteList; import com.gs.collections.api.list.primitive.MutableCharList; import com.gs.collections.api.list.primitive.MutableDoubleList; import com.gs.collections.api.list.primitive.MutableFloatList; import com.gs.collections.api.list.primitive.MutableIntList; import com.gs.collections.api.list.primitive.MutableLongList; import com.gs.collections.api.list.primitive.MutableShortList; import com.gs.collections.api.multimap.list.MutableListMultimap; import com.gs.collections.api.partition.list.PartitionMutableList; import com.gs.collections.api.stack.MutableStack; import com.gs.collections.api.tuple.Pair; import com.gs.collections.impl.collection.mutable.AbstractUnmodifiableMutableCollection; import com.gs.collections.impl.collection.mutable.UnmodifiableCollectionSerializationProxy; import com.gs.collections.impl.factory.Lists; import com.gs.collections.impl.lazy.ReverseIterable; import com.gs.collections.impl.stack.mutable.ArrayStack; /** * An unmodifiable view of a list. * * @see MutableList#asUnmodifiable() */ public class UnmodifiableMutableList extends AbstractUnmodifiableMutableCollection implements MutableList, Serializable { UnmodifiableMutableList(MutableList mutableList) { super(mutableList); } /** * This method will take a MutableList and wrap it directly in a UnmodifiableMutableList. It will * take any other non-GS-list and first adapt it will a ListAdapter, and then return a * UnmodifiableMutableList that wraps the adapter. */ public static > UnmodifiableMutableList of(L list) { if (list == null) { throw new IllegalArgumentException("cannot create an UnmodifiableMutableList for null"); } if (list instanceof RandomAccess) { return new RandomAccessUnmodifiableMutableList(RandomAccessListAdapter.adapt(list)); } return new UnmodifiableMutableList(ListAdapter.adapt(list)); } private MutableList getMutableList() { return (MutableList) this.getMutableCollection(); } @Override public boolean equals(Object obj) { return this.getMutableList().equals(obj); } @Override public int hashCode() { return this.getMutableList().hashCode(); } @Override public MutableList asUnmodifiable() { return this; } @Override public ImmutableList toImmutable() { return Lists.immutable.ofAll(this.getMutableList()); } @Override public MutableList asSynchronized() { return SynchronizedMutableList.of(this); } @Override public UnmodifiableMutableList clone() { return this; } @Override public MutableList newEmpty() { return this.getMutableList().newEmpty(); } public void forEach(int fromIndex, int toIndex, Procedure procedure) { this.getMutableList().forEach(fromIndex, toIndex, procedure); } public void reverseForEach(Procedure procedure) { this.getMutableList().reverseForEach(procedure); } public void forEachWithIndex(int fromIndex, int toIndex, ObjectIntProcedure objectIntProcedure) { this.getMutableList().forEachWithIndex(fromIndex, toIndex, objectIntProcedure); } public UnmodifiableMutableList sortThis(Comparator comparator) { throw new UnsupportedOperationException("Cannot call sortThis() on " + this.getClass().getSimpleName()); } public UnmodifiableMutableList sortThis() { throw new UnsupportedOperationException("Cannot call sortThis() on " + this.getClass().getSimpleName()); } public MutableList toReversed() { return this.getMutableList().toReversed(); } public MutableList reverseThis() { throw new UnsupportedOperationException("Cannot call reverseThis() on " + this.getClass().getSimpleName()); } public MutableStack toStack() { return ArrayStack.newStack(this.getMutableList()); } public > MutableList sortThisBy(Function function) { throw new UnsupportedOperationException("Cannot call sortThisBy() on " + this.getClass().getSimpleName()); } public boolean addAll(int index, Collection collection) { throw new UnsupportedOperationException("Cannot call addAll() on " + this.getClass().getSimpleName()); } public T get(int index) { return this.getMutableList().get(index); } public T set(int index, T element) { throw new UnsupportedOperationException("Cannot call set() on " + this.getClass().getSimpleName()); } public void add(int index, T element) { throw new UnsupportedOperationException("Cannot call add() on " + this.getClass().getSimpleName()); } public T remove(int index) { throw new UnsupportedOperationException("Cannot call remove() on " + this.getClass().getSimpleName()); } public int indexOf(Object o) { return this.getMutableList().indexOf(o); } public int lastIndexOf(Object o) { return this.getMutableList().lastIndexOf(o); } public ListIterator listIterator() { return this.listIterator(0); } public ListIterator listIterator(int index) { return new UnmodifiableListIteratorAdapter(this.getMutableList().listIterator(index)); } public UnmodifiableMutableList subList(int fromIndex, int toIndex) { MutableList subList = this.getMutableList().subList(fromIndex, toIndex); return of(subList); } @Override public MutableList collectWith(Function2 function, P parameter) { return this.getMutableList().collectWith(function, parameter); } @Override public MutableList collect(Function function) { return this.getMutableList().collect(function); } @Override public MutableBooleanList collectBoolean(BooleanFunction booleanFunction) { return this.getMutableList().collectBoolean(booleanFunction); } @Override public MutableByteList collectByte(ByteFunction byteFunction) { return this.getMutableList().collectByte(byteFunction); } @Override public MutableCharList collectChar(CharFunction charFunction) { return this.getMutableList().collectChar(charFunction); } @Override public MutableDoubleList collectDouble(DoubleFunction doubleFunction) { return this.getMutableList().collectDouble(doubleFunction); } @Override public MutableFloatList collectFloat(FloatFunction floatFunction) { return this.getMutableList().collectFloat(floatFunction); } @Override public MutableIntList collectInt(IntFunction intFunction) { return this.getMutableList().collectInt(intFunction); } @Override public MutableLongList collectLong(LongFunction longFunction) { return this.getMutableList().collectLong(longFunction); } @Override public MutableShortList collectShort(ShortFunction shortFunction) { return this.getMutableList().collectShort(shortFunction); } @Override public MutableList flatCollect(Function> function) { return this.getMutableList().flatCollect(function); } @Override public MutableList collectIf( Predicate predicate, Function function) { return this.getMutableList().collectIf(predicate, function); } @Override public MutableListMultimap groupBy(Function function) { return this.getMutableList().groupBy(function); } @Override public MutableListMultimap groupByEach(Function> function) { return this.getMutableList().groupByEach(function); } @Override public MutableList reject(Predicate predicate) { return this.getMutableList().reject(predicate); } @Override public

MutableList rejectWith(Predicate2 predicate, P parameter) { return this.getMutableList().rejectWith(predicate, parameter); } @Override public MutableList select(Predicate predicate) { return this.getMutableList().select(predicate); } @Override public

MutableList selectWith(Predicate2 predicate, P parameter) { return this.getMutableList().selectWith(predicate, parameter); } @Override public PartitionMutableList partition(Predicate predicate) { return this.getMutableList().partition(predicate); } @Override public

PartitionMutableList partitionWith(Predicate2 predicate, P parameter) { return this.getMutableList().partitionWith(predicate, parameter); } @Override public MutableList selectInstancesOf(Class clazz) { return this.getMutableList().selectInstancesOf(clazz); } public MutableList distinct() { return this.getMutableList().distinct(); } @Override public MutableList> zip(Iterable that) { return this.getMutableList().zip(that); } @Override public MutableList> zipWithIndex() { return this.getMutableList().zipWithIndex(); } public MutableList takeWhile(Predicate predicate) { return this.getMutableList().takeWhile(predicate); } public MutableList dropWhile(Predicate predicate) { return this.getMutableList().dropWhile(predicate); } public PartitionMutableList partitionWhile(Predicate predicate) { return this.getMutableList().partitionWhile(predicate); } public LazyIterable asReversed() { return ReverseIterable.adapt(this); } public int binarySearch(T key, Comparator comparator) { return Collections.binarySearch(this, key, comparator); } public int binarySearch(T key) { return Collections.binarySearch((List>) this, key); } @Override public MutableList with(T element) { throw new UnsupportedOperationException("Cannot call with() on " + this.getClass().getSimpleName()); } @Override public MutableList without(T element) { throw new UnsupportedOperationException("Cannot call without() on " + this.getClass().getSimpleName()); } @Override public MutableList withAll(Iterable elements) { throw new UnsupportedOperationException("Cannot call withAll() on " + this.getClass().getSimpleName()); } @Override public MutableList withoutAll(Iterable elements) { throw new UnsupportedOperationException("Cannot call withoutAll() on " + this.getClass().getSimpleName()); } private static final class RandomAccessUnmodifiableMutableList extends UnmodifiableMutableList implements RandomAccess { private static final long serialVersionUID = 1L; RandomAccessUnmodifiableMutableList(MutableList mutableList) { super(mutableList); } @Override public RandomAccessUnmodifiableMutableList clone() { return this; } } protected Object writeReplace() { return new UnmodifiableCollectionSerializationProxy(this.getMutableList()); } } package-info.java000066400000000000000000000051111234315411400335720ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/mutable/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains implementations of the {@link com.gs.collections.api.list.MutableList} interface. *

* A MutableList is an implementation of a {@link java.util.List} which provides methods matching the Smalltalk Collection protocol. *

*

* This package contains the following implementations: *

    *
  • * {@link com.gs.collections.impl.list.mutable.FastList} - an array-backed list which provides optimized internal iterators. *
  • *
  • * {@link com.gs.collections.impl.list.mutable.ArrayListAdapter} - a MutableList wrapper around an {@link java.util.ArrayList} instance. *
  • *
  • * {@link com.gs.collections.impl.list.mutable.CompositeFastList} - behaves like a list, but is composed of one or more lists. *
  • *
  • * {@link com.gs.collections.impl.list.mutable.ListAdapter} - a MutableList wrapper around a {@link java.util.List} interface instance. *
  • *
  • * {@link com.gs.collections.impl.list.mutable.RandomAccessListAdapter} - a MutableList wrapper around a {@link java.util.List} interface instance. *
  • *
  • * {@link com.gs.collections.impl.list.mutable.MultiReaderFastList} - provides a thread-safe wrapper around a FastList, using a {@link java.util.concurrent.locks.ReentrantReadWriteLock}. *
  • *
  • * {@link com.gs.collections.impl.list.mutable.SynchronizedMutableList} - a synchronized view of a list. *
  • *
  • * {@link com.gs.collections.impl.list.mutable.UnmodifiableMutableList} - an unmodifiable view of a list. *
  • *
*

*

* This package contains one factory implementation: *

    *
  • * {@link com.gs.collections.impl.list.mutable.MutableListFactoryImpl} - a factory which creates instances of type {@link com.gs.collections.api.list.MutableList}. *
  • *
*

*/ package com.gs.collections.impl.list.mutable; gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/mutable/primitive/000077500000000000000000000000001234315411400324745ustar00rootroot00000000000000BooleanArrayList.java000066400000000000000000000507201234315411400364760ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/mutable/primitive/* * Copyright 2014 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gs.collections.impl.list.mutable.primitive; import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; import java.util.BitSet; import java.util.NoSuchElementException; import com.gs.collections.api.BooleanIterable; import com.gs.collections.api.LazyBooleanIterable; import com.gs.collections.api.bag.primitive.MutableBooleanBag; import com.gs.collections.api.block.function.primitive.BooleanToObjectFunction; import com.gs.collections.api.block.function.primitive.ObjectBooleanIntToObjectFunction; import com.gs.collections.api.block.function.primitive.ObjectBooleanToObjectFunction; import com.gs.collections.api.block.predicate.primitive.BooleanPredicate; import com.gs.collections.api.block.procedure.primitive.BooleanIntProcedure; import com.gs.collections.api.block.procedure.primitive.BooleanProcedure; import com.gs.collections.api.iterator.BooleanIterator; import com.gs.collections.api.list.MutableList; import com.gs.collections.api.list.primitive.BooleanList; import com.gs.collections.api.list.primitive.ImmutableBooleanList; import com.gs.collections.api.list.primitive.MutableBooleanList; import com.gs.collections.api.set.primitive.BooleanSet; import com.gs.collections.api.set.primitive.MutableBooleanSet; import com.gs.collections.impl.bag.mutable.primitive.BooleanHashBag; import com.gs.collections.impl.factory.primitive.BooleanLists; import com.gs.collections.impl.lazy.primitive.LazyBooleanIterableAdapter; import com.gs.collections.impl.lazy.primitive.ReverseBooleanIterable; import com.gs.collections.impl.list.mutable.FastList; import com.gs.collections.impl.set.mutable.primitive.BooleanHashSet; import net.jcip.annotations.NotThreadSafe; /** * BooleanArrayList is similar to {@link FastList}, and is memory-optimized for boolean primitives. * * @since 3.0. */ @NotThreadSafe public final class BooleanArrayList implements MutableBooleanList, Externalizable { private static final long serialVersionUID = 1L; private int size; private transient BitSet items; public BooleanArrayList() { } public BooleanArrayList(int initialCapacity) { if (initialCapacity != 0) { this.items = new BitSet(initialCapacity); } } public BooleanArrayList(boolean... array) { this.size = array.length; this.items = new BitSet(array.length); for (int i = 0; i < array.length; i++) { if (array[i]) { this.items.set(i); } } } private BooleanArrayList(BooleanIterable booleanIterable) { BooleanIterator booleanIterator = booleanIterable.booleanIterator(); while (booleanIterator.hasNext()) { this.add(booleanIterator.next()); } } public static BooleanArrayList newListWith(boolean... array) { return new BooleanArrayList(array); } public static BooleanArrayList newList(BooleanIterable source) { return new BooleanArrayList(source); } public int size() { return this.size; } public boolean isEmpty() { return this.size == 0; } public boolean notEmpty() { return this.size > 0; } public void clear() { if (this.items != null) { this.items.clear(); this.size = 0; } } public boolean contains(boolean value) { for (int i = 0; i < this.size; i++) { if (this.items.get(i) == value) { return true; } } return false; } public boolean containsAll(boolean... source) { for (boolean value : source) { if (!this.contains(value)) { return false; } } return true; } public boolean containsAll(BooleanIterable source) { for (BooleanIterator iterator = source.booleanIterator(); iterator.hasNext(); ) { if (!this.contains(iterator.next())) { return false; } } return true; } public boolean get(int index) { if (index < this.size) { return this.items.get(index); } throw this.newIndexOutOfBoundsException(index); } private IndexOutOfBoundsException newIndexOutOfBoundsException(int index) { return new IndexOutOfBoundsException("Index: " + index + " Size: " + this.size); } public boolean getFirst() { this.checkEmpty(); return this.items.get(0); } public boolean getLast() { this.checkEmpty(); return this.items.get(this.size() - 1); } private void checkEmpty() { if (this.isEmpty()) { throw this.newIndexOutOfBoundsException(0); } } public int indexOf(boolean object) { for (int i = 0; i < this.size; i++) { if (this.items.get(i) == object) { return i; } } return -1; } public int lastIndexOf(boolean object) { for (int i = this.size - 1; i >= 0; i--) { if (this.items.get(i) == object) { return i; } } return -1; } public boolean add(boolean newItem) { if (this.size == 0) { this.items = new BitSet(); } if (newItem) { this.items.set(this.size); } this.size++; return true; } public boolean addAll(boolean... source) { if (source.length < 1) { return false; } for (boolean sourceItem : source) { this.add(sourceItem); } return true; } public boolean addAll(BooleanIterable source) { return this.addAll(source.toArray()); } public void addAtIndex(int index, boolean element) { if (index > -1 && index < this.size) { this.addAtIndexLessThanSize(index, element); } else if (index == this.size) { this.add(element); } else { throw this.newIndexOutOfBoundsException(index); } } private void addAtIndexLessThanSize(int index, boolean element) { for (int i = this.size + 1; i > index; i--) { this.items.set(i, this.items.get(i - 1)); } this.items.set(index, element); this.size++; } public boolean addAllAtIndex(int index, boolean... source) { if (index > this.size || index < 0) { throw this.newIndexOutOfBoundsException(index); } if (source.length == 0) { return false; } int sourceSize = source.length; int newSize = this.size + sourceSize; for (int i = newSize; i > index; i--) { this.items.set(i, this.items.get(i - sourceSize)); } for (int i = 0; i < sourceSize; i++) { this.items.set(i + index, source[i]); } this.size = newSize; return true; } public boolean addAllAtIndex(int index, BooleanIterable source) { return this.addAllAtIndex(index, source.toArray()); } public boolean remove(boolean value) { int index = this.indexOf(value); if (index >= 0) { this.removeAtIndex(index); return true; } return false; } public boolean removeAll(BooleanIterable source) { boolean modified = false; for (int i = 0; i < this.size; i++) { if (source.contains(this.items.get(i))) { this.removeAtIndex(i); i--; modified = true; } } return modified; } public boolean removeAll(boolean... source) { if (this.isEmpty() || source.length == 0) { return false; } BooleanHashSet set = BooleanHashSet.newSetWith(source); if (set.size() == 2) { this.items = null; this.size = 0; return true; } int oldSize = this.size; int trueCount = this.getTrueCount(); if (set.contains(true)) { this.size -= trueCount; this.items.set(0, this.size, false); } else { this.size = trueCount; this.items.set(0, this.size, true); } return oldSize != this.size; } public boolean retainAll(BooleanIterable source) { int oldSize = this.size(); final BooleanSet sourceSet = source instanceof BooleanSet ? (BooleanSet) source : source.toSet(); BooleanArrayList retained = this.select(new BooleanPredicate() { public boolean accept(boolean value) { return sourceSet.contains(value); } }); this.size = retained.size; this.items = retained.items; return oldSize != this.size(); } public boolean retainAll(boolean... source) { return this.retainAll(BooleanHashSet.newSetWith(source)); } private int getTrueCount() { int count = 0; for (int i = 0; i < this.size; i++) { if (this.items.get(i)) { count++; } } return count; } public boolean removeAtIndex(int index) { boolean previous = this.get(index); if (this.size - index > 1) { for (int i = index; i < this.size; i++) { this.items.set(i, this.items.get(i + 1)); } } --this.size; this.items.clear(this.size); return previous; } public boolean set(int index, boolean element) { boolean previous = this.get(index); this.items.set(index, element); return previous; } public BooleanArrayList with(boolean element) { this.add(element); return this; } public BooleanArrayList without(boolean element) { this.remove(element); return this; } public BooleanArrayList withAll(BooleanIterable elements) { this.addAll(elements.toArray()); return this; } public BooleanArrayList withoutAll(BooleanIterable elements) { this.removeAll(elements); return this; } public BooleanArrayList with(boolean element1, boolean element2) { this.add(element1); this.add(element2); return this; } public BooleanArrayList with(boolean element1, boolean element2, boolean element3) { this.add(element1); this.add(element2); this.add(element3); return this; } public BooleanArrayList with(boolean element1, boolean element2, boolean element3, boolean... elements) { this.add(element1); this.add(element2); this.add(element3); this.addAll(elements); return this; } public BooleanIterator booleanIterator() { return new InternalBooleanIterator(); } public void forEach(BooleanProcedure procedure) { for (int i = 0; i < this.size; i++) { procedure.value(this.items.get(i)); } } public void forEachWithIndex(BooleanIntProcedure procedure) { for (int i = 0; i < this.size; i++) { procedure.value(this.items.get(i), i); } } public T injectInto(T injectedValue, ObjectBooleanToObjectFunction function) { T result = injectedValue; for (int i = 0; i < this.size; i++) { result = function.valueOf(result, this.items.get(i)); } return result; } public T injectIntoWithIndex(T injectedValue, ObjectBooleanIntToObjectFunction function) { T result = injectedValue; for (int i = 0; i < this.size; i++) { result = function.valueOf(result, this.items.get(i), i); } return result; } public int count(BooleanPredicate predicate) { int count = 0; for (int i = 0; i < this.size; i++) { if (predicate.accept(this.items.get(i))) { count++; } } return count; } public boolean anySatisfy(BooleanPredicate predicate) { for (int i = 0; i < this.size; i++) { if (predicate.accept(this.items.get(i))) { return true; } } return false; } public boolean allSatisfy(BooleanPredicate predicate) { for (int i = 0; i < this.size; i++) { if (!predicate.accept(this.items.get(i))) { return false; } } return true; } public boolean noneSatisfy(BooleanPredicate predicate) { for (int i = 0; i < this.size; i++) { if (predicate.accept(this.items.get(i))) { return false; } } return true; } public BooleanArrayList select(BooleanPredicate predicate) { BooleanArrayList result = new BooleanArrayList(); for (int i = 0; i < this.size; i++) { boolean item = this.items.get(i); if (predicate.accept(item)) { result.add(item); } } return result; } public BooleanArrayList reject(BooleanPredicate predicate) { BooleanArrayList result = new BooleanArrayList(); for (int i = 0; i < this.size; i++) { boolean item = this.items.get(i); if (!predicate.accept(item)) { result.add(item); } } return result; } public LazyBooleanIterable asReversed() { return new ReverseBooleanIterable(this); } public BooleanArrayList reverseThis() { int endIndex = this.size - 1; for (int i = 0; i < this.size / 2; i++) { boolean tempSwapValue = this.items.get(i); this.items.set(i, this.items.get(endIndex - i)); this.items.set(endIndex - i, tempSwapValue); } return this; } public MutableBooleanList asUnmodifiable() { return new UnmodifiableBooleanList(this); } public MutableBooleanList asSynchronized() { return new SynchronizedBooleanList(this); } public ImmutableBooleanList toImmutable() { if (this.size == 0) { return BooleanLists.immutable.with(); } if (this.size == 1) { return BooleanLists.immutable.with(this.items.get(0)); } return BooleanLists.immutable.with(this.toArray()); } public MutableBooleanList subList(int fromIndex, int toIndex) { throw new UnsupportedOperationException("subList not yet implemented!"); } public BooleanArrayList toReversed() { return new BooleanArrayList(this.asReversed()); } public boolean detectIfNone(BooleanPredicate predicate, boolean ifNone) { for (int i = 0; i < this.size; i++) { boolean item = this.items.get(i); if (predicate.accept(item)) { return item; } } return ifNone; } public MutableList collect(BooleanToObjectFunction function) { FastList target = FastList.newList(this.size); for (int i = 0; i < this.size; i++) { target.add(function.valueOf(this.items.get(i))); } return target; } public boolean[] toArray() { boolean[] newItems = new boolean[this.size]; for (int i = 0; i < this.size; i++) { newItems[i] = this.items.get(i); } return newItems; } @Override public boolean equals(Object otherList) { if (otherList == this) { return true; } if (!(otherList instanceof BooleanList)) { return false; } BooleanList list = (BooleanList) otherList; if (this.size != list.size()) { return false; } for (int i = 0; i < this.size; i++) { if (this.items.get(i) != list.get(i)) { return false; } } return true; } @Override public int hashCode() { int hashCode = 1; for (int i = 0; i < this.size; i++) { boolean item = this.items.get(i); hashCode = 31 * hashCode + (item ? 1231 : 1237); } return hashCode; } @Override public String toString() { return this.makeString("[", ", ", "]"); } public String makeString() { return this.makeString(", "); } public String makeString(String separator) { return this.makeString("", separator, ""); } public String makeString(String start, String separator, String end) { Appendable stringBuilder = new StringBuilder(); this.appendString(stringBuilder, start, separator, end); return stringBuilder.toString(); } public void appendString(Appendable appendable) { this.appendString(appendable, ", "); } public void appendString(Appendable appendable, String separator) { this.appendString(appendable, "", separator, ""); } public void appendString( Appendable appendable, String start, String separator, String end) { try { appendable.append(start); for (int i = 0; i < this.size; i++) { if (i > 0) { appendable.append(separator); } boolean value = this.items.get(i); appendable.append(String.valueOf(value)); } appendable.append(end); } catch (IOException e) { throw new RuntimeException(e); } } public MutableBooleanList toList() { return BooleanArrayList.newList(this); } public MutableBooleanSet toSet() { return BooleanHashSet.newSet(this); } public MutableBooleanBag toBag() { return BooleanHashBag.newBag(this); } public LazyBooleanIterable asLazy() { return new LazyBooleanIterableAdapter(this); } public void writeExternal(ObjectOutput out) throws IOException { out.writeInt(this.size()); for (int i = 0; i < this.size; i++) { out.writeBoolean(this.items.get(i)); } } public void readExternal(ObjectInput in) throws IOException { this.size = in.readInt(); if (this.size > 0) { this.items = new BitSet(); for (int i = 0; i < this.size; i++) { this.items.set(i, in.readBoolean()); } } } private class InternalBooleanIterator implements BooleanIterator { /** * Index of element to be returned by subsequent call to next. */ private int currentIndex; public boolean hasNext() { return this.currentIndex != BooleanArrayList.this.size(); } public boolean next() { if (!this.hasNext()) { throw new NoSuchElementException(); } boolean next = BooleanArrayList.this.get(this.currentIndex); this.currentIndex++; return next; } } } package-info.java000066400000000000000000000016021234315411400356030ustar00rootroot00000000000000gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/mutable/primitive/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains implementations of the mutable primitive list interfaces. *

* A mutable primitive list is similar to a {@link com.gs.collections.api.list.MutableList}, but is memory-optimized for primitives. *

*/ package com.gs.collections.impl.list.mutable.primitive; gs-collections-5.1.0/collections/src/main/java/com/gs/collections/impl/list/package-info.java000066400000000000000000000022041234315411400322200ustar00rootroot00000000000000/* * Copyright 2013 Goldman Sachs. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * This package contains implementations of the {@link com.gs.collections.api.list.ListIterable} interface. *

* A {@link com.gs.collections.api.list.ListIterable} is an {@link java.lang.Iterable} whose items are ordered and may be accessed directly by index. *

*

* This package contains the following implementations: *