├── showcases └── .gitkeep ├── design-patterns ├── .gitkeep ├── .gitignore ├── README.md ├── abstract_factory │ └── example │ │ ├── OutputDemo.txt │ │ ├── checkboxes │ │ ├── Checkbox.java │ │ ├── MacOSCheckbox.java │ │ └── WindowsCheckbox.java │ │ ├── factories │ │ ├── GUIFactory.java │ │ ├── MacOSFactory.java │ │ └── WindowsFactory.java │ │ └── buttons │ │ ├── MacOSButton.java │ │ ├── WindowsButton.java │ │ └── Button.java ├── factory_method │ └── example │ │ ├── OutputDemo.txt │ │ ├── OutputDemo.png │ │ ├── buttons │ │ ├── Button.java │ │ └── HtmlButton.java │ │ └── factory │ │ ├── HtmlDialog.java │ │ └── WindowsDialog.java ├── state │ └── example │ │ ├── OutputDemo.png │ │ ├── Demo.java │ │ └── states │ │ ├── PlayingState.java │ │ ├── State.java │ │ └── ReadyState.java ├── command │ └── example │ │ ├── OutputDemo.png │ │ ├── Demo.java │ │ └── commands │ │ ├── CommandHistory.java │ │ ├── CopyCommand.java │ │ ├── Command.java │ │ ├── PasteCommand.java │ │ └── CutCommand.java ├── mediator │ └── example │ │ ├── OutputDemo.png │ │ ├── components │ │ ├── Component.java │ │ └── Title.java │ │ └── mediator │ │ ├── Mediator.java │ │ └── Note.java ├── memento │ └── example │ │ ├── OutputDemo.png │ │ ├── commands │ │ ├── Command.java │ │ └── ColorCommand.java │ │ ├── history │ │ └── Memento.java │ │ └── shapes │ │ ├── Shape.java │ │ ├── Dot.java │ │ ├── Circle.java │ │ └── Rectangle.java ├── composite │ └── example │ │ ├── OutputDemo.png │ │ └── shapes │ │ ├── Shape.java │ │ ├── Dot.java │ │ ├── Circle.java │ │ └── Rectangle.java ├── flyweight │ └── example │ │ ├── OutputDemo.png │ │ ├── OutputDemo.txt │ │ ├── trees │ │ ├── Tree.java │ │ ├── TreeFactory.java │ │ └── TreeType.java │ │ └── forest │ │ └── Forest.java ├── adapter │ └── example │ │ ├── OutputDemo.txt │ │ ├── round │ │ ├── RoundPeg.java │ │ └── RoundHole.java │ │ ├── square │ │ └── SquarePeg.java │ │ └── adapters │ │ └── SquarePegAdapter.java ├── builder │ └── example │ │ ├── cars │ │ └── Type.java │ │ ├── OutputDemo.txt │ │ ├── components │ │ ├── Transmission.java │ │ ├── GPSNavigator.java │ │ └── TripComputer.java │ │ └── builders │ │ └── Builder.java ├── facade │ └── example │ │ ├── some_complex_media_library │ │ ├── Codec.java │ │ ├── OggCompressionCodec.java │ │ ├── MPEG4CompressionCodec.java │ │ ├── AudioMixer.java │ │ ├── BitrateReader.java │ │ ├── VideoFile.java │ │ └── CodecFactory.java │ │ ├── OutputDemo.txt │ │ └── Demo.java ├── prototype │ ├── caching │ │ └── OutputDemo.txt │ └── example │ │ ├── OutputDemo.txt │ │ └── shapes │ │ ├── Circle.java │ │ ├── Shape.java │ │ └── Rectangle.java ├── decorator │ └── example │ │ ├── decorators │ │ ├── DataSource.java │ │ └── DataSourceDecorator.java │ │ ├── OutputDemo.txt │ │ └── Demo.java ├── singleton │ └── example │ │ ├── thread_safe │ │ └── OutputDemoMultiThread.txt │ │ └── non_thread_safe │ │ ├── OutputDemoMultiThread.txt │ │ ├── OutputDemoSingleThread.txt │ │ ├── DemoSingleThread.java │ │ └── Singleton.java ├── observer │ └── example │ │ ├── listeners │ │ ├── EventListener.java │ │ ├── LogOpenListener.java │ │ └── EmailNotificationListener.java │ │ ├── OutputDemo.txt │ │ ├── editor │ │ └── Editor.java │ │ └── Demo.java ├── rm-misc.sh ├── bridge │ └── example │ │ ├── remotes │ │ ├── Remote.java │ │ └── AdvancedRemote.java │ │ ├── devices │ │ └── Device.java │ │ └── OutputDemo.txt ├── visitor │ └── example │ │ ├── shapes │ │ ├── Shape.java │ │ ├── Circle.java │ │ ├── CompoundShape.java │ │ └── Dot.java │ │ ├── visitor │ │ └── Visitor.java │ │ ├── OutputDemo.txt │ │ └── Demo.java ├── chain_of_responsibility │ └── example │ │ ├── OutputDemo.txt │ │ └── middleware │ │ └── RoleCheckMiddleware.java ├── iterator │ └── example │ │ ├── iterators │ │ └── ProfileIterator.java │ │ ├── social_networks │ │ └── SocialNetwork.java │ │ └── OutputDemo.txt ├── proxy │ └── example │ │ └── some_cool_media_library │ │ ├── ThirdPartyYoutubeLib.java │ │ └── Video.java ├── strategy │ └── example │ │ ├── strategies │ │ ├── PayStrategy.java │ │ └── CreditCard.java │ │ └── OutputDemo.txt └── template_method │ └── example │ └── OutputDemo.txt ├── snippets ├── io │ ├── c100k │ │ └── .gitkeep │ ├── FileIO-MOM │ │ ├── code_xy7620 │ │ │ ├── .gitignore │ │ │ ├── src │ │ │ │ ├── main │ │ │ │ │ ├── .gitignore │ │ │ │ │ └── java │ │ │ │ │ │ └── io │ │ │ │ │ │ └── openmessaging │ │ │ │ │ │ ├── exception │ │ │ │ │ │ └── OMSReadFinshedException.java │ │ │ │ │ │ ├── v1 │ │ │ │ │ │ └── V1ExcuteTester.java │ │ │ │ │ │ ├── v3 │ │ │ │ │ │ └── V3ExecuteTester.java │ │ │ │ │ │ ├── demo │ │ │ │ │ │ ├── ClientOMSException.java │ │ │ │ │ │ └── ExcuteTester.java │ │ │ │ │ │ ├── v5 │ │ │ │ │ │ └── V5ExcuteTester.java │ │ │ │ │ │ ├── v6 │ │ │ │ │ │ └── V6ExcuteTester.java │ │ │ │ │ │ ├── v7 │ │ │ │ │ │ └── V7ExcuteTester.java │ │ │ │ │ │ ├── v4 │ │ │ │ │ │ └── V4ExcuteTester.java │ │ │ │ │ │ └── tester │ │ │ │ │ │ └── ExcuteTester.java │ │ │ │ └── test │ │ │ │ │ └── .gitignore │ │ │ ├── .settings │ │ │ │ ├── org.eclipse.wst.jsdt.ui.superType.name │ │ │ │ ├── org.eclipse.wst.validation.prefs │ │ │ │ ├── org.eclipse.wst.jsdt.ui.superType.container │ │ │ │ ├── org.eclipse.m2e.core.prefs │ │ │ │ ├── org.eclipse.core.resources.prefs │ │ │ │ ├── org.eclipse.wst.common.project.facet.core.xml │ │ │ │ ├── org.eclipse.jdt.core.prefs │ │ │ │ ├── .jsdtscope │ │ │ │ └── org.eclipse.wst.common.component │ │ │ ├── java │ │ │ │ └── open-messaging │ │ │ │ │ └── target │ │ │ │ │ └── m2e-jee │ │ │ │ │ └── web-resources │ │ │ │ │ └── .gitignore │ │ │ ├── README.md │ │ │ └── pom.xml │ │ └── code_klosefu │ │ │ ├── .gitignore │ │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── io │ │ │ │ └── openmessaging │ │ │ │ ├── official │ │ │ │ └── tester │ │ │ │ │ └── ProducerTester.java │ │ │ │ ├── demo │ │ │ │ ├── serializer │ │ │ │ │ ├── MessageSerializer.java │ │ │ │ │ └── MessageDeserializer.java │ │ │ │ ├── Constants.java │ │ │ │ ├── ClientOMSException.java │ │ │ │ └── DefaultMessageFactory.java │ │ │ │ └── tester │ │ │ │ └── Constants.java │ │ │ └── resources │ │ │ └── package.xml │ ├── IncrementalSyncSequential │ │ ├── doc │ │ │ ├── Fig.1.1.png │ │ │ ├── Fig.1.2.png │ │ │ ├── Fig.1.3.png │ │ │ ├── Fig.1.4.png │ │ │ ├── Fig.2.1.png │ │ │ └── Fig.2.2.png │ │ └── code │ │ │ ├── .gitignore │ │ │ └── src │ │ │ ├── main │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── alibaba │ │ │ │ └── middleware │ │ │ │ └── race │ │ │ │ └── sync │ │ │ │ ├── server │ │ │ │ ├── Promise.java │ │ │ │ ├── Task.java │ │ │ │ └── Result.java │ │ │ │ └── utils │ │ │ │ ├── ReadUtils.java │ │ │ │ ├── LongObjectHashMap.java │ │ │ │ └── LongIntHashMap.java │ │ │ └── resources │ │ │ └── assembly.xml │ └── TopKN │ │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── assembly.xml │ │ │ └── java │ │ │ └── com │ │ │ └── alibaba │ │ │ └── middleware │ │ │ └── topkn │ │ │ └── worker │ │ │ └── FileSegment.java │ │ └── .gitignore ├── junit │ └── assumptions │ │ ├── README.md │ │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ │ ├── src │ │ ├── test │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── demo │ │ │ │ └── connectionchecking │ │ │ │ ├── ConnectionChecker.java │ │ │ │ ├── junit5 │ │ │ │ ├── AssumeConnection.java │ │ │ │ └── ConnectionCheckingJunit5Test.java │ │ │ │ └── junit4 │ │ │ │ └── ConnectionCheckingJunit4Test.java │ │ └── main │ │ │ └── resources │ │ │ └── application.yml │ │ ├── .gitignore │ │ └── build.gradle └── datastructure │ └── string │ └── StringReverse.java ├── algorithms └── snippets │ ├── set │ └── .gitkeep │ ├── sort │ ├── .gitkeep │ └── external │ │ ├── src │ │ └── .gitkeep │ │ ├── test │ │ └── .gitkeep │ │ └── ExternalSort.java │ ├── tree │ └── .gitkeep │ ├── graph │ └── .gitkeep │ ├── search │ └── .gitkeep │ ├── stack │ └── .gitkeep │ ├── table │ └── .gitkeep │ ├── number_theory │ └── .gitkeep │ ├── optimization │ └── .gitkeep │ ├── .gitignore │ ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.jdt.apt.core.prefs │ ├── org.eclipse.m2e.core.prefs │ └── org.eclipse.jdt.core.prefs │ ├── README.md │ ├── string │ └── match_droid │ │ ├── src │ │ └── nju │ │ │ └── iip │ │ │ └── kevin │ │ │ └── ac │ │ │ ├── AcDroid.java │ │ │ ├── State.java │ │ │ ├── AhoCorasick.java │ │ │ ├── DenseEdgeList.java │ │ │ ├── EdgeList.java │ │ │ ├── Queue.java │ │ │ └── Searcher.java │ │ └── .classpath │ └── scheduler │ └── hashed_wheel_timer │ └── BooleanSupplier.java ├── boilerplates ├── maven-app │ ├── .idea │ │ ├── .name │ │ ├── .gitignore │ │ ├── codeStyles │ │ │ └── codeStyleConfig.xml │ │ ├── vcs.xml │ │ ├── modules.xml │ │ ├── encodings.xml │ │ ├── misc.xml │ │ ├── libraries │ │ │ ├── Maven__junit_junit_4_12.xml │ │ │ ├── Maven__org_slf4j_slf4j_api_1_7_7.xml │ │ │ ├── Maven__org_slf4j_slf4j_jdk14_1_7_12.xml │ │ │ └── Maven__org_hamcrest_hamcrest_core_1_3.xml │ │ └── compiler.xml │ ├── .gitignore │ └── src │ │ └── main │ │ ├── resources │ │ └── logging.properties │ │ └── java │ │ └── com │ │ └── example │ │ ├── app │ │ ├── package-info.java │ │ └── AppDriver.java │ │ ├── lib │ │ ├── package-info.java │ │ └── MyClass.java │ │ └── package-info.java └── gradle │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── settings.gradle │ └── .gitignore ├── concurrency ├── akka │ ├── akka-agent │ │ ├── src │ │ │ └── main │ │ │ │ └── resources │ │ │ │ └── application.conf │ │ ├── project │ │ │ ├── build.properties │ │ │ └── plugins.sbt │ │ ├── .gitignore │ │ └── .mvn │ │ │ ├── extensions.xml │ │ │ └── jgitver.config.xml │ ├── akka-fsm │ │ ├── project │ │ │ ├── build.properties │ │ │ └── plugins.sbt │ │ ├── .mvn │ │ │ ├── extensions.xml │ │ │ └── jgitver.config.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── sample │ │ │ └── fsm │ │ │ └── Messages.java │ ├── akka-cluster │ │ ├── project │ │ │ ├── build.properties │ │ │ └── plugins.sbt │ │ ├── src │ │ │ ├── test │ │ │ │ └── resources │ │ │ │ │ └── reference.conf │ │ │ └── main │ │ │ │ ├── resources │ │ │ │ ├── stats1.conf │ │ │ │ ├── stats2.conf │ │ │ │ └── factorial.conf │ │ │ │ └── java │ │ │ │ └── sample │ │ │ │ └── cluster │ │ │ │ ├── factorial │ │ │ │ ├── FactorialApp.java │ │ │ │ ├── FactorialResult.java │ │ │ │ └── FactorialBackend.java │ │ │ │ ├── transformation │ │ │ │ ├── TransformationApp.java │ │ │ │ └── TransformationBackendMain.java │ │ │ │ └── stats │ │ │ │ ├── StatsSampleClientMain.java │ │ │ │ ├── StatsSampleOneMasterClientMain.java │ │ │ │ └── StatsWorker.java │ │ └── .gitignore │ ├── akka-router │ │ ├── project │ │ │ ├── build.properties │ │ │ └── plugins.sbt │ │ ├── src │ │ │ └── main │ │ │ │ └── resources │ │ │ │ └── application.conf │ │ ├── target │ │ │ └── classes │ │ │ │ ├── application.conf │ │ │ │ └── akka │ │ │ │ └── router │ │ │ │ ├── RouterTest.class │ │ │ │ ├── TestActor.class │ │ │ │ └── TestActor$Msg.class │ │ └── .mvn │ │ │ ├── extensions.xml │ │ │ └── jgitver.config.xml │ ├── akka-sharding │ │ ├── project │ │ │ ├── build.properties │ │ │ └── plugins.sbt │ │ ├── .gitignore │ │ └── src │ │ │ └── main │ │ │ ├── resources │ │ │ └── application.conf │ │ │ └── java │ │ │ └── sample │ │ │ └── sharding │ │ │ └── ShardingApp.java │ ├── akka-start │ │ ├── project │ │ │ ├── build.properties │ │ │ └── plugins.sbt │ │ ├── target │ │ │ └── classes │ │ │ │ ├── application.conf │ │ │ │ └── sample │ │ │ │ └── hello │ │ │ │ ├── Main.class │ │ │ │ ├── Main2.class │ │ │ │ ├── Greeter.class │ │ │ │ ├── HelloWorld.class │ │ │ │ ├── Greeter$Msg.class │ │ │ │ └── Main2$Terminator.class │ │ ├── src │ │ │ └── main │ │ │ │ ├── resources │ │ │ │ └── application.conf │ │ │ │ └── java │ │ │ │ └── sample │ │ │ │ └── hello │ │ │ │ ├── Main.java │ │ │ │ ├── Greeter.java │ │ │ │ ├── HelloWorld.java │ │ │ │ └── Main2.java │ │ └── .mvn │ │ │ ├── extensions.xml │ │ │ └── jgitver.config.xml │ ├── akka-websocket │ │ ├── project │ │ │ ├── build.properties │ │ │ └── plugins.sbt │ │ ├── target │ │ │ └── classes │ │ │ │ ├── application.conf │ │ │ │ ├── WebSocketCoreApp.class │ │ │ │ └── WebSocketCoreApp$1.class │ │ ├── src │ │ │ └── main │ │ │ │ └── resources │ │ │ │ └── application.conf │ │ └── .mvn │ │ │ ├── extensions.xml │ │ │ └── jgitver.config.xml │ ├── akka-persistence-dc │ │ ├── project │ │ │ ├── build.properties │ │ │ └── plugins.sbt │ │ └── src │ │ │ └── main │ │ │ ├── protobuf │ │ │ └── ThumbsUpMessages.proto │ │ │ └── resources │ │ │ └── logback.xml │ ├── akka-persistence │ │ ├── project │ │ │ ├── build.properties │ │ │ └── plugins.sbt │ │ ├── .gitignore │ │ ├── .mvn │ │ │ ├── extensions.xml │ │ │ └── jgitver.config.xml │ │ └── src │ │ │ └── main │ │ │ └── resources │ │ │ └── application.conf │ ├── akka-supervision │ │ ├── project │ │ │ ├── build.properties │ │ │ └── plugins.sbt │ │ └── .mvn │ │ │ ├── extensions.xml │ │ │ └── jgitver.config.xml │ ├── akka-distributed-data │ │ ├── project │ │ │ ├── build.properties │ │ │ └── plugins.sbt │ │ ├── .gitignore │ │ └── src │ │ │ ├── test │ │ │ └── resources │ │ │ │ └── reference.conf │ │ │ ├── main │ │ │ └── resources │ │ │ │ └── application.conf │ │ │ └── multi-jvm │ │ │ └── scala │ │ │ └── sample │ │ │ └── distributeddata │ │ │ └── STMultiNodeSpec.scala │ ├── akka-future │ │ ├── src │ │ │ └── main │ │ │ │ ├── resources │ │ │ │ └── application.conf │ │ │ │ └── java │ │ │ │ └── wx │ │ │ │ └── akka │ │ │ │ └── future │ │ │ │ ├── PrintActor.java │ │ │ │ └── WorkerActor.java │ │ ├── target │ │ │ └── classes │ │ │ │ ├── application.conf │ │ │ │ └── wx │ │ │ │ └── akka │ │ │ │ └── future │ │ │ │ ├── PrintActor.class │ │ │ │ ├── WorkerActor.class │ │ │ │ └── AkkaFutureApp.class │ │ └── .mvn │ │ │ ├── extensions.xml │ │ │ └── jgitver.config.xml │ ├── akka-spring │ │ ├── README.md │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── org │ │ │ │ └── baeldung │ │ │ │ └── akka │ │ │ │ ├── GreetingService.java │ │ │ │ ├── AppConfiguration.java │ │ │ │ └── SpringActorProducer.java │ │ │ └── resources │ │ │ └── logback.xml │ ├── akka-spring-boot │ │ ├── src │ │ │ └── main │ │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── chriniko │ │ │ │ │ └── example │ │ │ │ │ └── akkaspringexample │ │ │ │ │ ├── message │ │ │ │ │ ├── CheckAllAcks.java │ │ │ │ │ ├── GreetResult.java │ │ │ │ │ ├── CrimeRecordsProcessedAck.java │ │ │ │ │ ├── CrimeRecordsToProcess.java │ │ │ │ │ ├── CrimeRecordsToProcessBatch.java │ │ │ │ │ └── Greet.java │ │ │ │ │ ├── service │ │ │ │ │ └── GreetingService.java │ │ │ │ │ ├── domain │ │ │ │ │ └── CrimeRecord.java │ │ │ │ │ ├── file │ │ │ │ │ └── FileLinesCounter.java │ │ │ │ │ ├── integration │ │ │ │ │ └── akka │ │ │ │ │ │ ├── SpringAkkaExtension.java │ │ │ │ │ │ └── SpringActorProducer.java │ │ │ │ │ └── configuration │ │ │ │ │ └── SchedulingConfiguration.java │ │ │ │ └── resources │ │ │ │ ├── application.conf │ │ │ │ ├── application.properties │ │ │ │ └── db │ │ │ │ └── liquibase-changelog.xml │ │ ├── .mvn │ │ │ └── wrapper │ │ │ │ ├── maven-wrapper.properties │ │ │ │ └── maven-wrapper.jar │ │ └── .gitignore │ ├── akka-http │ │ ├── README.md │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── baeldung │ │ │ └── akkahttp │ │ │ ├── User.java │ │ │ └── UserService.java │ ├── akka-streams │ │ ├── README.md │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── baeldung │ │ │ │ └── akkastreams │ │ │ │ └── AverageRepository.java │ │ │ └── resources │ │ │ └── logback.xml │ └── akka-mqtt │ │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ ├── worker.conf │ │ │ └── iotmanager.conf │ │ │ └── scala │ │ │ └── akkaiot │ │ │ ├── Work.scala │ │ │ └── MasterWorkerProtocol.scala │ │ └── build.sbt ├── basic │ ├── src │ │ └── main │ │ │ └── java │ │ │ ├── safety │ │ │ ├── lock │ │ │ │ ├── dist-lock │ │ │ │ │ └── README.md │ │ │ │ └── counter │ │ │ │ │ ├── AtomicVariableCounter.java │ │ │ │ │ ├── SynchronizedMethodsCounter.java │ │ │ │ │ ├── SynchronizedBlocksCounter.java │ │ │ │ │ ├── ReentrantLockCounter.java │ │ │ │ │ └── ReadWriteLockCounter.java │ │ │ └── collection │ │ │ │ ├── concurrent_bag │ │ │ │ └── ConcurrentBag.java │ │ │ │ ├── boundedBlockingQueue │ │ │ │ ├── ClassicQueue.java │ │ │ │ ├── SyncMethodQueue.java │ │ │ │ └── SyncBlockQueue.java │ │ │ │ └── singleton │ │ │ │ ├── SynchronizedMethodSingleton.java │ │ │ │ ├── ClassicSingleton.java │ │ │ │ └── SynchronizedBlockSingleton.java │ │ │ ├── Main.java │ │ │ └── primitive │ │ │ ├── thread │ │ │ ├── ThreadAnonymous.java │ │ │ ├── ThreadExtends.java │ │ │ └── ThreadRunnable.java │ │ │ └── atomic │ │ │ └── AtomicTest.java │ └── build.gradle ├── lombok.config ├── config │ ├── settings.zip │ ├── env.tpl │ ├── flyway-local.conf │ └── spotbugs-exclude-filter.xml ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── settings.gradle ├── .gitattributes ├── sync.sh └── rm-misc.sh └── deployment └── docker ├── maven ├── README.md └── Dockerfile └── jar ├── Dockerfile └── run.sh /showcases/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /design-patterns/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /snippets/io/c100k/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /algorithms/snippets/set/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /algorithms/snippets/sort/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /algorithms/snippets/tree/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /algorithms/snippets/graph/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /algorithms/snippets/search/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /algorithms/snippets/stack/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /algorithms/snippets/table/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /algorithms/snippets/number_theory/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /algorithms/snippets/optimization/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /boilerplates/maven-app/.idea/.name: -------------------------------------------------------------------------------- 1 | MyApp -------------------------------------------------------------------------------- /algorithms/snippets/sort/external/src/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /algorithms/snippets/sort/external/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /snippets/io/FileIO-MOM/code_xy7620/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /concurrency/akka/akka-agent/src/main/resources/application.conf: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /concurrency/basic/src/main/java/safety/lock/dist-lock/README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /concurrency/akka/akka-fsm/project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=1.2.1 2 | -------------------------------------------------------------------------------- /snippets/io/FileIO-MOM/code_xy7620/src/main/.gitignore: -------------------------------------------------------------------------------- 1 | /resources/ 2 | -------------------------------------------------------------------------------- /algorithms/snippets/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | .idea 3 | *.iml 4 | bin 5 | *.project -------------------------------------------------------------------------------- /concurrency/akka/akka-agent/project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=1.2.1 2 | -------------------------------------------------------------------------------- /concurrency/akka/akka-cluster/project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=1.2.1 2 | -------------------------------------------------------------------------------- /concurrency/akka/akka-router/project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=1.2.1 2 | -------------------------------------------------------------------------------- /concurrency/akka/akka-sharding/project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=1.2.1 2 | -------------------------------------------------------------------------------- /concurrency/akka/akka-start/project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=1.2.1 2 | -------------------------------------------------------------------------------- /concurrency/akka/akka-websocket/project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=1.2.1 2 | -------------------------------------------------------------------------------- /design-patterns/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | .idea 3 | *.iml 4 | bin 5 | *.project -------------------------------------------------------------------------------- /boilerplates/maven-app/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /workspace.xml -------------------------------------------------------------------------------- /concurrency/akka/akka-persistence-dc/project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=1.2.1 2 | -------------------------------------------------------------------------------- /concurrency/akka/akka-persistence/project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=1.2.1 2 | -------------------------------------------------------------------------------- /concurrency/akka/akka-supervision/project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=1.2.1 2 | -------------------------------------------------------------------------------- /snippets/io/FileIO-MOM/code_xy7620/src/test/.gitignore: -------------------------------------------------------------------------------- 1 | /java/ 2 | /resources/ 3 | -------------------------------------------------------------------------------- /concurrency/akka/akka-distributed-data/project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=1.2.1 2 | -------------------------------------------------------------------------------- /design-patterns/README.md: -------------------------------------------------------------------------------- 1 | # Java Concurrency Snippets 2 | 3 | 参考 []() 获取完整的并发编程与代码说明。 -------------------------------------------------------------------------------- /snippets/io/FileIO-MOM/code_klosefu/.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | target 3 | *.iml 4 | 5 | tmp/ -------------------------------------------------------------------------------- /algorithms/snippets/sort/external/ExternalSort.java: -------------------------------------------------------------------------------- 1 | // https://github.com/htyleo/external-sort -------------------------------------------------------------------------------- /snippets/io/FileIO-MOM/code_xy7620/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /concurrency/akka/akka-start/target/classes/application.conf: -------------------------------------------------------------------------------- 1 | akka { 2 | loglevel = INFO 3 | } 4 | -------------------------------------------------------------------------------- /boilerplates/maven-app/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | .classpath 3 | .project 4 | .settings 5 | /target 6 | -------------------------------------------------------------------------------- /concurrency/akka/akka-fsm/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("com.dwijnand" % "sbt-dynver" % "3.0.0") 2 | -------------------------------------------------------------------------------- /concurrency/akka/akka-future/src/main/resources/application.conf: -------------------------------------------------------------------------------- 1 | akka { 2 | loglevel = INFO 3 | } 4 | -------------------------------------------------------------------------------- /concurrency/akka/akka-future/target/classes/application.conf: -------------------------------------------------------------------------------- 1 | akka { 2 | loglevel = INFO 3 | } 4 | -------------------------------------------------------------------------------- /concurrency/akka/akka-router/src/main/resources/application.conf: -------------------------------------------------------------------------------- 1 | akka { 2 | loglevel = INFO 3 | } 4 | -------------------------------------------------------------------------------- /concurrency/akka/akka-router/target/classes/application.conf: -------------------------------------------------------------------------------- 1 | akka { 2 | loglevel = INFO 3 | } 4 | -------------------------------------------------------------------------------- /concurrency/akka/akka-start/src/main/resources/application.conf: -------------------------------------------------------------------------------- 1 | akka { 2 | loglevel = INFO 3 | } 4 | -------------------------------------------------------------------------------- /concurrency/akka/akka-websocket/target/classes/application.conf: -------------------------------------------------------------------------------- 1 | akka { 2 | loglevel = INFO 3 | } 4 | -------------------------------------------------------------------------------- /concurrency/akka/akka-agent/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("com.dwijnand" % "sbt-dynver" % "3.0.0") 2 | -------------------------------------------------------------------------------- /concurrency/akka/akka-router/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("com.dwijnand" % "sbt-dynver" % "3.0.0") 2 | -------------------------------------------------------------------------------- /concurrency/akka/akka-sharding/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("com.dwijnand" % "sbt-dynver" % "3.0.0") 2 | -------------------------------------------------------------------------------- /concurrency/akka/akka-start/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("com.dwijnand" % "sbt-dynver" % "3.0.0") 2 | -------------------------------------------------------------------------------- /concurrency/akka/akka-websocket/src/main/resources/application.conf: -------------------------------------------------------------------------------- 1 | akka { 2 | loglevel = INFO 3 | } 4 | -------------------------------------------------------------------------------- /concurrency/lombok.config: -------------------------------------------------------------------------------- 1 | lombok.accessors.chain=true 2 | lombok.extern.findbugs.addSuppressFBWarnings = true -------------------------------------------------------------------------------- /concurrency/akka/akka-persistence/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("com.dwijnand" % "sbt-dynver" % "3.0.0") 2 | -------------------------------------------------------------------------------- /concurrency/akka/akka-supervision/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("com.dwijnand" % "sbt-dynver" % "3.0.0") 2 | -------------------------------------------------------------------------------- /concurrency/akka/akka-websocket/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("com.dwijnand" % "sbt-dynver" % "3.0.0") 2 | -------------------------------------------------------------------------------- /design-patterns/abstract_factory/example/OutputDemo.txt: -------------------------------------------------------------------------------- 1 | You create WindowsButton. 2 | You created WindowsCheckbox. -------------------------------------------------------------------------------- /snippets/io/FileIO-MOM/code_xy7620/java/open-messaging/target/m2e-jee/web-resources/.gitignore: -------------------------------------------------------------------------------- 1 | /META-INF/ 2 | -------------------------------------------------------------------------------- /design-patterns/factory_method/example/OutputDemo.txt: -------------------------------------------------------------------------------- 1 | 2 | Click! Button says - 'Hello World!' -------------------------------------------------------------------------------- /algorithms/snippets/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /concurrency/config/settings.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/concurrency/config/settings.zip -------------------------------------------------------------------------------- /snippets/io/FileIO-MOM/code_xy7620/.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | disabled=06target 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /algorithms/snippets/.settings/org.eclipse.jdt.apt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.apt.aptEnabled=false 3 | -------------------------------------------------------------------------------- /concurrency/basic/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | public class Main { 2 | 3 | public static void main(String[] args) { 4 | 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /snippets/io/FileIO-MOM/code_xy7620/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /snippets/junit/assumptions/README.md: -------------------------------------------------------------------------------- 1 | # Examples with JUnit 4 and JUnit 5 2 | 3 | Have a look at [the code](/src/test/java/com/example/demo/) -------------------------------------------------------------------------------- /boilerplates/maven-app/src/main/resources/logging.properties: -------------------------------------------------------------------------------- 1 | handlers=java.util.logging.ConsoleHandler 2 | .level=INFO 3 | com.example.level=FINEST 4 | -------------------------------------------------------------------------------- /design-patterns/state/example/OutputDemo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/design-patterns/state/example/OutputDemo.png -------------------------------------------------------------------------------- /algorithms/snippets/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /concurrency/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/concurrency/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /design-patterns/command/example/OutputDemo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/design-patterns/command/example/OutputDemo.png -------------------------------------------------------------------------------- /design-patterns/mediator/example/OutputDemo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/design-patterns/mediator/example/OutputDemo.png -------------------------------------------------------------------------------- /design-patterns/memento/example/OutputDemo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/design-patterns/memento/example/OutputDemo.png -------------------------------------------------------------------------------- /concurrency/akka/akka-spring/README.md: -------------------------------------------------------------------------------- 1 | # akka-spring 2 | 3 | # About 4 | 5 | - [Introduction to Spring with Akka](http://www.baeldung.com/akka-with-spring) 6 | -------------------------------------------------------------------------------- /design-patterns/composite/example/OutputDemo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/design-patterns/composite/example/OutputDemo.png -------------------------------------------------------------------------------- /design-patterns/flyweight/example/OutputDemo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/design-patterns/flyweight/example/OutputDemo.png -------------------------------------------------------------------------------- /design-patterns/adapter/example/OutputDemo.txt: -------------------------------------------------------------------------------- 1 | Round peg r5 fits round hole r5. 2 | Square peg w2 fits round hole r5. 3 | Square peg w20 does not fit into round hole r5. -------------------------------------------------------------------------------- /design-patterns/builder/example/cars/Type.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.builder.example.cars; 2 | 3 | public enum Type { 4 | CITY_CAR, SPORTS_CAR, SUV 5 | } 6 | -------------------------------------------------------------------------------- /boilerplates/gradle/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/boilerplates/gradle/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /concurrency/akka/akka-cluster/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("com.typesafe.sbt" % "sbt-multi-jvm" % "0.4.0") 2 | addSbtPlugin("com.dwijnand" % "sbt-dynver" % "3.0.0") 3 | -------------------------------------------------------------------------------- /concurrency/akka/akka-spring-boot/src/main/java/com/chriniko/example/akkaspringexample/message/CheckAllAcks.java: -------------------------------------------------------------------------------- 1 | public class CheckAllAcks { 2 | // Nothing. 3 | } 4 | -------------------------------------------------------------------------------- /design-patterns/factory_method/example/OutputDemo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/design-patterns/factory_method/example/OutputDemo.png -------------------------------------------------------------------------------- /snippets/io/FileIO-MOM/code_xy7620/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /snippets/io/IncrementalSyncSequential/doc/Fig.1.1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/snippets/io/IncrementalSyncSequential/doc/Fig.1.1.png -------------------------------------------------------------------------------- /snippets/io/IncrementalSyncSequential/doc/Fig.1.2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/snippets/io/IncrementalSyncSequential/doc/Fig.1.2.png -------------------------------------------------------------------------------- /snippets/io/IncrementalSyncSequential/doc/Fig.1.3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/snippets/io/IncrementalSyncSequential/doc/Fig.1.3.png -------------------------------------------------------------------------------- /snippets/io/IncrementalSyncSequential/doc/Fig.1.4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/snippets/io/IncrementalSyncSequential/doc/Fig.1.4.png -------------------------------------------------------------------------------- /snippets/io/IncrementalSyncSequential/doc/Fig.2.1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/snippets/io/IncrementalSyncSequential/doc/Fig.2.1.png -------------------------------------------------------------------------------- /snippets/io/IncrementalSyncSequential/doc/Fig.2.2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/snippets/io/IncrementalSyncSequential/doc/Fig.2.2.png -------------------------------------------------------------------------------- /concurrency/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'java-concurrency-examples' 2 | 3 | // 代码模块 4 | include ':basic' 5 | project(':basic').projectDir = new File("$rootDir/basic") 6 | -------------------------------------------------------------------------------- /concurrency/akka/akka-distributed-data/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("com.typesafe.sbt" % "sbt-multi-jvm" % "0.4.0") 2 | addSbtPlugin("com.dwijnand" % "sbt-dynver" % "3.0.0") 3 | -------------------------------------------------------------------------------- /concurrency/akka/akka-persistence-dc/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("com.dwijnand" % "sbt-dynver" % "3.0.0") 2 | addSbtPlugin("com.github.gseitz" % "sbt-protobuf" % "0.6.3") 3 | -------------------------------------------------------------------------------- /design-patterns/facade/example/some_complex_media_library/Codec.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.facade.example.some_complex_media_library; 2 | 3 | public interface Codec { 4 | } 5 | -------------------------------------------------------------------------------- /concurrency/akka/akka-spring-boot/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip 2 | -------------------------------------------------------------------------------- /snippets/junit/assumptions/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/snippets/junit/assumptions/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /algorithms/snippets/README.md: -------------------------------------------------------------------------------- 1 | # Java DataStructures & Algorithms Implementation 2 | 3 | 该项目是 [数据结构与算法 https://url.wx-coder.cn/S84SI](https://url.wx-coder.cn/S84SI) 系列中相关数据结构与算法的 Java 版本实现。 4 | -------------------------------------------------------------------------------- /concurrency/akka/akka-spring-boot/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/concurrency/akka/akka-spring-boot/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /design-patterns/prototype/caching/OutputDemo.txt: -------------------------------------------------------------------------------- 1 | Big green circle != Medium blue rectangle (yay!) 2 | Medium blue rectangles are two different objects (yay!) 3 | And they are identical (yay!) -------------------------------------------------------------------------------- /concurrency/akka/akka-start/target/classes/sample/hello/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/concurrency/akka/akka-start/target/classes/sample/hello/Main.class -------------------------------------------------------------------------------- /concurrency/akka/akka-start/target/classes/sample/hello/Main2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/concurrency/akka/akka-start/target/classes/sample/hello/Main2.class -------------------------------------------------------------------------------- /concurrency/akka/akka-start/target/classes/sample/hello/Greeter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/concurrency/akka/akka-start/target/classes/sample/hello/Greeter.class -------------------------------------------------------------------------------- /concurrency/akka/akka-websocket/target/classes/WebSocketCoreApp.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/concurrency/akka/akka-websocket/target/classes/WebSocketCoreApp.class -------------------------------------------------------------------------------- /design-patterns/memento/example/commands/Command.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.memento.example.commands; 2 | 3 | public interface Command { 4 | String getName(); 5 | void execute(); 6 | } 7 | -------------------------------------------------------------------------------- /algorithms/snippets/string/match_droid/src/nju/iip/kevin/ac/AcDroid.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/algorithms/snippets/string/match_droid/src/nju/iip/kevin/ac/AcDroid.java -------------------------------------------------------------------------------- /algorithms/snippets/string/match_droid/src/nju/iip/kevin/ac/State.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/algorithms/snippets/string/match_droid/src/nju/iip/kevin/ac/State.java -------------------------------------------------------------------------------- /concurrency/.gitattributes: -------------------------------------------------------------------------------- 1 | # 2 | # https://help.github.com/articles/dealing-with-line-endings/ 3 | # 4 | # These are explicitly windows files and should use crlf 5 | *.bat text eol=crlf 6 | 7 | -------------------------------------------------------------------------------- /concurrency/akka/akka-router/target/classes/akka/router/RouterTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/concurrency/akka/akka-router/target/classes/akka/router/RouterTest.class -------------------------------------------------------------------------------- /concurrency/akka/akka-router/target/classes/akka/router/TestActor.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/concurrency/akka/akka-router/target/classes/akka/router/TestActor.class -------------------------------------------------------------------------------- /concurrency/akka/akka-start/target/classes/sample/hello/HelloWorld.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/concurrency/akka/akka-start/target/classes/sample/hello/HelloWorld.class -------------------------------------------------------------------------------- /concurrency/akka/akka-websocket/target/classes/WebSocketCoreApp$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/concurrency/akka/akka-websocket/target/classes/WebSocketCoreApp$1.class -------------------------------------------------------------------------------- /concurrency/akka/akka-start/target/classes/sample/hello/Greeter$Msg.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/concurrency/akka/akka-start/target/classes/sample/hello/Greeter$Msg.class -------------------------------------------------------------------------------- /concurrency/config/env.tpl: -------------------------------------------------------------------------------- 1 | # build-locally.sh 2 | export DISABLE_TEST= 3 | export DISABLE_SPOTBUGS= 4 | export TAG= 5 | 6 | # deploy-locally.sh 7 | export RELEASE= 8 | export VALUES_FILE= 9 | export NAMESPACE= -------------------------------------------------------------------------------- /algorithms/snippets/string/match_droid/src/nju/iip/kevin/ac/AhoCorasick.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/algorithms/snippets/string/match_droid/src/nju/iip/kevin/ac/AhoCorasick.java -------------------------------------------------------------------------------- /concurrency/akka/akka-future/target/classes/wx/akka/future/PrintActor.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/concurrency/akka/akka-future/target/classes/wx/akka/future/PrintActor.class -------------------------------------------------------------------------------- /concurrency/akka/akka-future/target/classes/wx/akka/future/WorkerActor.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/concurrency/akka/akka-future/target/classes/wx/akka/future/WorkerActor.class -------------------------------------------------------------------------------- /concurrency/akka/akka-http/README.md: -------------------------------------------------------------------------------- 1 | ## Akka HTTP 2 | 3 | This module contains articles about Akka HTTP. 4 | 5 | ### Relevant articles: 6 | 7 | - [Introduction to Akka HTTP](https://www.baeldung.com/akka-http) 8 | -------------------------------------------------------------------------------- /concurrency/akka/akka-router/target/classes/akka/router/TestActor$Msg.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/concurrency/akka/akka-router/target/classes/akka/router/TestActor$Msg.class -------------------------------------------------------------------------------- /algorithms/snippets/string/match_droid/src/nju/iip/kevin/ac/DenseEdgeList.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/algorithms/snippets/string/match_droid/src/nju/iip/kevin/ac/DenseEdgeList.java -------------------------------------------------------------------------------- /boilerplates/maven-app/src/main/java/com/example/app/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * A package that does stuff. 3 | * 4 | * @author Myself 5 | * @version 0.0.1 6 | * @since 0.0.1 7 | */ 8 | package com.example.app; 9 | -------------------------------------------------------------------------------- /boilerplates/maven-app/src/main/java/com/example/lib/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * A package that does stuff. 3 | * 4 | * @author Myself 5 | * @version 0.0.1 6 | * @since 0.0.1 7 | */ 8 | package com.example.lib; 9 | -------------------------------------------------------------------------------- /concurrency/akka/akka-future/target/classes/wx/akka/future/AkkaFutureApp.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/concurrency/akka/akka-future/target/classes/wx/akka/future/AkkaFutureApp.class -------------------------------------------------------------------------------- /concurrency/akka/akka-start/src/main/java/sample/hello/Main.java: -------------------------------------------------------------------------------- 1 | public class Main { 2 | 3 | public static void main(String[] args) { 4 | akka.Main.main(new String[] { HelloWorld.class.getName() }); 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /concurrency/akka/akka-start/target/classes/sample/hello/Main2$Terminator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx-chevalier/java-examples/master/concurrency/akka/akka-start/target/classes/sample/hello/Main2$Terminator.class -------------------------------------------------------------------------------- /boilerplates/maven-app/.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /concurrency/akka/akka-streams/README.md: -------------------------------------------------------------------------------- 1 | ## Akka Streams 2 | 3 | This module contains articles about Akka Streams. 4 | 5 | ### Relevant articles 6 | 7 | - [Guide to Akka Streams](https://www.baeldung.com/akka-streams) 8 | -------------------------------------------------------------------------------- /concurrency/config/flyway-local.conf: -------------------------------------------------------------------------------- 1 | flyway.url=jdbc:mysql://127.0.0.1:3306/test-db 2 | flyway.user=root 3 | flyway.defaultSchema =test-db 4 | flyway.schemas=test-db 5 | flyway.password=roottoor 6 | flyway.cleanDisabled=true 7 | -------------------------------------------------------------------------------- /concurrency/sync.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | # 切入项目根目录 6 | cd "$(dirname "$0")/.." 7 | 8 | cp -r ./build.gradle ./.boilerplate 9 | cp -r ./gradle.properties ./.boilerplate 10 | cp -r ./scripts ./.boilerplate -------------------------------------------------------------------------------- /boilerplates/maven-app/src/main/java/com/example/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This is the main package for the application. 3 | * 4 | * @author Myself 5 | * @version 0.0.1 6 | * @since 0.0.1 7 | */ 8 | package com.example; 9 | -------------------------------------------------------------------------------- /design-patterns/decorator/example/decorators/DataSource.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.decorator.example.decorators; 2 | 3 | public interface DataSource { 4 | void writeData(String data); 5 | 6 | String readData(); 7 | } 8 | -------------------------------------------------------------------------------- /snippets/io/IncrementalSyncSequential/code/.gitignore: -------------------------------------------------------------------------------- 1 | .classpath 2 | .project 3 | .settings/ 4 | target/ 5 | tester.log 6 | .idea/ 7 | *.iml 8 | logs/ 9 | *.log 10 | 11 | user_result/ 12 | middle/ 13 | test_logs/ 14 | *.local -------------------------------------------------------------------------------- /boilerplates/maven-app/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /design-patterns/flyweight/example/OutputDemo.txt: -------------------------------------------------------------------------------- 1 | 1000000 trees drawn 2 | --------------------- 3 | Memory usage: 4 | Tree size (8 bytes) * 1000000 5 | + TreeTypes size (~30 bytes) * 2 6 | --------------------- 7 | Total: 7MB (instead of 36MB) -------------------------------------------------------------------------------- /design-patterns/singleton/example/thread_safe/OutputDemoMultiThread.txt: -------------------------------------------------------------------------------- 1 | If you see the same value, then singleton was reused (yay!) 2 | If you see different values, then 2 singletons were created (booo!!) 3 | 4 | RESULT: 5 | 6 | BAR 7 | BAR -------------------------------------------------------------------------------- /design-patterns/observer/example/listeners/EventListener.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.observer.example.listeners; 2 | 3 | import java.io.File; 4 | 5 | public interface EventListener { 6 | void update(String eventType, File file); 7 | } 8 | -------------------------------------------------------------------------------- /design-patterns/singleton/example/non_thread_safe/OutputDemoMultiThread.txt: -------------------------------------------------------------------------------- 1 | If you see the same value, then singleton was reused (yay!) 2 | If you see different values, then 2 singletons were created (booo!!) 3 | 4 | RESULT: 5 | 6 | FOO 7 | BAR -------------------------------------------------------------------------------- /design-patterns/singleton/example/non_thread_safe/OutputDemoSingleThread.txt: -------------------------------------------------------------------------------- 1 | If you see the same value, then singleton was reused (yay!) 2 | If you see different values, then 2 singletons were created (booo!!) 3 | 4 | RESULT: 5 | 6 | FOO 7 | FOO -------------------------------------------------------------------------------- /snippets/io/FileIO-MOM/code_xy7620/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java/io/openmessaging/demo/DemoTester.java=UTF-8 3 | encoding//src/main/java/io/openmessaging/v1/V1Tester.java=UTF-8 4 | -------------------------------------------------------------------------------- /design-patterns/facade/example/some_complex_media_library/OggCompressionCodec.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.facade.example.some_complex_media_library; 2 | 3 | public class OggCompressionCodec implements Codec { 4 | public String type = "ogg"; 5 | } 6 | -------------------------------------------------------------------------------- /design-patterns/observer/example/OutputDemo.txt: -------------------------------------------------------------------------------- 1 | Save to log \path\to\log\file.txt: Someone has performed open operation with the following file: test.txt 2 | Email to admin@example.com: Someone has performed save operation with the following file: test.txt 3 | -------------------------------------------------------------------------------- /concurrency/basic/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | testImplementation "org.mockito:mockito-core:${mockitoVersion}" 3 | } 4 | 5 | test { 6 | useJUnitPlatform() 7 | testLogging { 8 | events "passed", "skipped", "failed" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /concurrency/rm-misc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | find . -name '*.project' -exec rm -rf {} \; 4 | find . -name '*.idea' -exec rm -rf {} \; 5 | find . -name '*.iml' -exec rm -rf {} \; 6 | find . -name 'bin' -exec rm -rf {} \; 7 | find . -name 'target' -exec rm -rf {} \; 8 | -------------------------------------------------------------------------------- /design-patterns/facade/example/some_complex_media_library/MPEG4CompressionCodec.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.facade.example.some_complex_media_library; 2 | 3 | public class MPEG4CompressionCodec implements Codec { 4 | public String type = "mp4"; 5 | 6 | } 7 | -------------------------------------------------------------------------------- /concurrency/akka/akka-agent/.gitignore: -------------------------------------------------------------------------------- 1 | *# 2 | *.iml 3 | *.ipr 4 | *.iws 5 | *.pyc 6 | *.tm.epoch 7 | *.vim 8 | *-shim.sbt 9 | .idea/ 10 | /project/plugins/project 11 | project/boot 12 | target/ 13 | /logs 14 | .cache 15 | .classpath 16 | .project 17 | .settings -------------------------------------------------------------------------------- /design-patterns/rm-misc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | find . -name '*.project' -exec rm -rf {} \; 4 | find . -name '*.idea' -exec rm -rf {} \; 5 | find . -name '*.iml' -exec rm -rf {} \; 6 | find . -name 'bin' -exec rm -rf {} \; 7 | find . -name 'target' -exec rm -rf {} \; 8 | -------------------------------------------------------------------------------- /concurrency/akka/akka-persistence/.gitignore: -------------------------------------------------------------------------------- 1 | *# 2 | *.iml 3 | *.ipr 4 | *.iws 5 | *.pyc 6 | *.tm.epoch 7 | *.vim 8 | *-shim.sbt 9 | .idea/ 10 | /project/plugins/project 11 | project/boot 12 | target/ 13 | /logs 14 | .cache 15 | .classpath 16 | .project 17 | .settings -------------------------------------------------------------------------------- /concurrency/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /boilerplates/gradle/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-bin.zip 6 | -------------------------------------------------------------------------------- /concurrency/akka/akka-distributed-data/.gitignore: -------------------------------------------------------------------------------- 1 | *# 2 | *.iml 3 | *.ipr 4 | *.iws 5 | *.pyc 6 | *.tm.epoch 7 | *.vim 8 | *-shim.sbt 9 | .idea/ 10 | /project/plugins/project 11 | project/boot 12 | target/ 13 | /logs 14 | .cache 15 | .classpath 16 | .project 17 | .settings -------------------------------------------------------------------------------- /design-patterns/facade/example/OutputDemo.txt: -------------------------------------------------------------------------------- 1 | VideoConversionFacade: conversion started. 2 | CodecFactory: extracting ogg audio... 3 | BitrateReader: reading file... 4 | BitrateReader: writing file... 5 | AudioMixer: fixing audio... 6 | VideoConversionFacade: conversion completed. -------------------------------------------------------------------------------- /design-patterns/prototype/example/OutputDemo.txt: -------------------------------------------------------------------------------- 1 | 0: Shapes are different objects (yay!) 2 | 0: And they are identical (yay!) 3 | 1: Shapes are different objects (yay!) 4 | 1: And they are identical (yay!) 5 | 2: Shapes are different objects (yay!) 6 | 2: And they are identical (yay!) -------------------------------------------------------------------------------- /concurrency/akka/akka-cluster/src/test/resources/reference.conf: -------------------------------------------------------------------------------- 1 | # Don't terminate ActorSystem in tests 2 | akka.coordinated-shutdown.run-by-jvm-shutdown-hook = off 3 | akka.coordinated-shutdown.terminate-actor-system = off 4 | akka.cluster.run-coordinated-shutdown-when-down = off 5 | -------------------------------------------------------------------------------- /concurrency/akka/akka-cluster/.gitignore: -------------------------------------------------------------------------------- 1 | *# 2 | *.iml 3 | *.ipr 4 | *.iws 5 | *.pyc 6 | *.tm.epoch 7 | *.vim 8 | *-shim.sbt 9 | .idea/ 10 | /project/plugins/project 11 | project/boot 12 | target/ 13 | /logs 14 | .cache 15 | .classpath 16 | .project 17 | .settings 18 | native/ 19 | -------------------------------------------------------------------------------- /concurrency/akka/akka-distributed-data/src/test/resources/reference.conf: -------------------------------------------------------------------------------- 1 | # Don't terminate ActorSystem in tests 2 | akka.coordinated-shutdown.run-by-jvm-shutdown-hook = off 3 | akka.coordinated-shutdown.terminate-actor-system = off 4 | akka.cluster.run-coordinated-shutdown-when-down = off 5 | -------------------------------------------------------------------------------- /concurrency/akka/akka-sharding/.gitignore: -------------------------------------------------------------------------------- 1 | *# 2 | *.iml 3 | *.ipr 4 | *.iws 5 | *.pyc 6 | *.tm.epoch 7 | *.vim 8 | *-shim.sbt 9 | .idea/ 10 | /project/plugins/project 11 | project/boot 12 | target/ 13 | /logs 14 | .cache 15 | .classpath 16 | .project 17 | .settings 18 | native/ 19 | -------------------------------------------------------------------------------- /deployment/docker/maven/README.md: -------------------------------------------------------------------------------- 1 | docker build --build-arg url=https://github.com/spring-projects/spring-petclinic.git\ 2 | --build-arg project=spring-petclinic\ 3 | --build-arg artifactid=spring-petclinic\ 4 | --build-arg version=1.5.1\ 5 | -t nfrankel/spring-petclinic - < Dockerfile -------------------------------------------------------------------------------- /design-patterns/builder/example/OutputDemo.txt: -------------------------------------------------------------------------------- 1 | Car built: 2 | SPORTS_CAR 3 | 4 | Car manual built: 5 | Type of car: SPORTS_CAR 6 | Count of seats: 2 7 | Engine: volume - 3.0; mileage - 0.0 8 | Transmission: SEMI_AUTOMATIC 9 | Trip Computer: Functional 10 | GPS Navigator: Functional -------------------------------------------------------------------------------- /snippets/junit/assumptions/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip 6 | -------------------------------------------------------------------------------- /algorithms/snippets/string/match_droid/src/nju/iip/kevin/ac/EdgeList.java: -------------------------------------------------------------------------------- 1 | package nju.iip.kevin.ac; 2 | 3 | /** 4 | * Simple interface for mapping bytes to States. 5 | */ 6 | interface EdgeList { 7 | State get(byte ch); 8 | void put(byte ch, State state); 9 | byte[] keys(); 10 | } 11 | -------------------------------------------------------------------------------- /snippets/io/FileIO-MOM/code_xy7620/README.md: -------------------------------------------------------------------------------- 1 | # open-messaging 2 | 第三届阿里中间件性能挑战赛 初赛记录及源码分享 3 | 4 | 5 | 阅读Open-Messaging规范,了解Message,Topic,Queue,Producer,Consumer等概念,并基于相关语言的接口实现进程内消息引擎。(看demo像是消息中间件RocketMQ的一个简单版本) 6 | 7 | 比赛思路总结等见blog http://blog.csdn.net/u011299745/article/details/72864948 8 | -------------------------------------------------------------------------------- /concurrency/akka/akka-spring/src/main/java/org/baeldung/akka/GreetingService.java: -------------------------------------------------------------------------------- 1 | import org.springframework.stereotype.Component; 2 | 3 | @Component 4 | public class GreetingService { 5 | 6 | public String greet(String name) { 7 | return "Hello, " + name; 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /design-patterns/bridge/example/remotes/Remote.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.bridge.example.remotes; 2 | 3 | public interface Remote { 4 | void power(); 5 | 6 | void volumeDown(); 7 | 8 | void volumeUp(); 9 | 10 | void channelDown(); 11 | 12 | void channelUp(); 13 | } 14 | -------------------------------------------------------------------------------- /concurrency/akka/akka-spring-boot/src/main/resources/application.conf: -------------------------------------------------------------------------------- 1 | akka { 2 | 3 | blocking-io-dispatcher { 4 | type = Dispatcher 5 | executor = "thread-pool-executor" 6 | thread-pool-executor { 7 | fixed-pool-size = 32 8 | } 9 | throughput = 1 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /concurrency/basic/src/main/java/safety/collection/concurrent_bag/ConcurrentBag.java: -------------------------------------------------------------------------------- 1 | package safety.collection.concurrent_bag; 2 | 3 | /** 4 | * @see https://github.com/brettwooldridge/HikariCP/blob/dev/src/main/java/com/zaxxer/hikari/util/ConcurrentBag.java 5 | */ 6 | public class ConcurrentBag { 7 | } 8 | -------------------------------------------------------------------------------- /design-patterns/visitor/example/shapes/Shape.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.visitor.example.shapes; 2 | 3 | import refactoring_guru.visitor.example.visitor.Visitor; 4 | 5 | public interface Shape { 6 | void move(int x, int y); 7 | void draw(); 8 | String accept(Visitor visitor); 9 | } 10 | -------------------------------------------------------------------------------- /boilerplates/maven-app/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /concurrency/akka/akka-spring-boot/src/main/java/com/chriniko/example/akkaspringexample/service/GreetingService.java: -------------------------------------------------------------------------------- 1 | import org.springframework.stereotype.Component; 2 | 3 | @Component 4 | public class GreetingService { 5 | 6 | public String greet(String name) { 7 | return "Hello, " + name; 8 | } 9 | } -------------------------------------------------------------------------------- /design-patterns/chain_of_responsibility/example/OutputDemo.txt: -------------------------------------------------------------------------------- 1 | Enter email: admin@example.com 2 | Input password: admin_pass 3 | Hello, admin! 4 | Authorization have been successful! 5 | 6 | 7 | Enter email: user@example.com 8 | Input password: user_pass 9 | Hello, user! 10 | Authorization have been successful! -------------------------------------------------------------------------------- /boilerplates/maven-app/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /design-patterns/builder/example/components/Transmission.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.builder.example.components; 2 | 3 | /** 4 | * EN: Just another feature of a car. 5 | * 6 | * RU: Одна из фишек автомобиля. 7 | */ 8 | public enum Transmission { 9 | SINGLE_SPEED, MANUAL, AUTOMATIC, SEMI_AUTOMATIC 10 | } 11 | -------------------------------------------------------------------------------- /design-patterns/command/example/Demo.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.command.example; 2 | 3 | import refactoring_guru.command.example.editor.Editor; 4 | 5 | public class Demo { 6 | public static void main(String[] args) { 7 | Editor editor = new Editor(); 8 | editor.init(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /snippets/io/FileIO-MOM/code_xy7620/src/main/java/io/openmessaging/exception/OMSReadFinshedException.java: -------------------------------------------------------------------------------- 1 | package io.openmessaging.exception; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * @author XF 7 | * 自定义异常 读文件完毕 8 | */ 9 | public class OMSReadFinshedException extends IOException{ 10 | 11 | } 12 | -------------------------------------------------------------------------------- /design-patterns/iterator/example/iterators/ProfileIterator.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.iterator.example.iterators; 2 | 3 | import refactoring_guru.iterator.example.profile.Profile; 4 | 5 | public interface ProfileIterator { 6 | boolean hasNext(); 7 | 8 | Profile getNext(); 9 | 10 | void reset(); 11 | } -------------------------------------------------------------------------------- /design-patterns/factory_method/example/buttons/Button.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.factory_method.example.buttons; 2 | 3 | /** 4 | * EN: Common interface for all buttons. 5 | * 6 | * RU: Общий интерфейс для всех продуктов. 7 | */ 8 | public interface Button { 9 | void render(); 10 | void onClick(); 11 | } 12 | -------------------------------------------------------------------------------- /design-patterns/proxy/example/some_cool_media_library/ThirdPartyYoutubeLib.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.proxy.example.some_cool_media_library; 2 | 3 | import java.util.HashMap; 4 | 5 | public interface ThirdPartyYoutubeLib { 6 | HashMap popularVideos(); 7 | 8 | Video getVideo(String videoId); 9 | } 10 | -------------------------------------------------------------------------------- /snippets/io/FileIO-MOM/code_klosefu/src/main/java/io/openmessaging/official/tester/ProducerTester.java: -------------------------------------------------------------------------------- 1 | package io.openmessaging.official.tester; 2 | 3 | public class ProducerTester { 4 | 5 | 6 | public static void main(String[] args) { 7 | System.out.println("This is demo tester just for check"); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /concurrency/akka/akka-mqtt/src/main/resources/worker.conf: -------------------------------------------------------------------------------- 1 | akka { 2 | 3 | actor.provider = "akka.remote.RemoteActorRefProvider" 4 | 5 | remote.netty.tcp.port=0 6 | remote.netty.tcp.hostname=127.0.0.1 7 | 8 | } 9 | 10 | contact-points = [ 11 | "akka.tcp://ClusterSystem@127.0.0.1:2551", 12 | "akka.tcp://ClusterSystem@127.0.0.1:2552"] -------------------------------------------------------------------------------- /snippets/io/IncrementalSyncSequential/code/src/main/java/com/alibaba/middleware/race/sync/server/Promise.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.middleware.race.sync.server; 2 | 3 | /** 4 | * Promise 5 | * 6 | * Created by yfu on 6/28/17. 7 | */ 8 | public final class Promise { 9 | volatile int data = -1; 10 | 11 | byte sender = -1; 12 | } 13 | -------------------------------------------------------------------------------- /concurrency/akka/akka-mqtt/src/main/resources/iotmanager.conf: -------------------------------------------------------------------------------- 1 | akka { 2 | 3 | actor.provider = "akka.remote.RemoteActorRefProvider" 4 | 5 | remote.netty.tcp.port=0 6 | remote.netty.tcp.hostname=127.0.0.1 7 | 8 | } 9 | 10 | contact-points = [ 11 | "akka.tcp://ClusterSystem@127.0.0.1:2551", 12 | "akka.tcp://ClusterSystem@127.0.0.1:2552"] -------------------------------------------------------------------------------- /design-patterns/decorator/example/OutputDemo.txt: -------------------------------------------------------------------------------- 1 | - Input ---------------- 2 | Name,Salary 3 | John Smith,100000 4 | Steven Jobs,912000 5 | - Encoded -------------- 6 | Zkt7e1Q5eU8yUm1Qe0ZsdHJ2VXp6dDBKVnhrUHtUe0sxRUYxQkJIdjVLTVZ0dVI5Q2IwOXFISmVUMU5rcENCQmdxRlByaD4+ 7 | - Decoded -------------- 8 | Name,Salary 9 | John Smith,100000 10 | Steven Jobs,912000 -------------------------------------------------------------------------------- /algorithms/snippets/string/match_droid/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /concurrency/akka/akka-spring-boot/src/main/java/com/chriniko/example/akkaspringexample/message/GreetResult.java: -------------------------------------------------------------------------------- 1 | public class GreetResult { 2 | 3 | private final String result; 4 | 5 | public GreetResult(String result) { 6 | this.result = result; 7 | } 8 | 9 | public String getResult() { 10 | return result; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /concurrency/akka/akka-spring-boot/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | ######################################### 2 | #### APPLICATION SPECIFIC PROPERTIES #### 3 | ######################################### 4 | liquibase.change-log=classpath:db/liquibase-changelog.xml 5 | 6 | 7 | crime.records.fetcher.batch.size=10000 8 | 9 | crime.records.processor.supervisor.children=7 -------------------------------------------------------------------------------- /design-patterns/strategy/example/strategies/PayStrategy.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.strategy.example.strategies; 2 | 3 | /** 4 | * EN: Common interface for all strategies. 5 | * 6 | * RU: Общий интерфейс всех стратегий. 7 | */ 8 | public interface PayStrategy { 9 | boolean pay(int paymentAmount); 10 | void collectPaymentDetails(); 11 | } 12 | 13 | -------------------------------------------------------------------------------- /design-patterns/facade/example/some_complex_media_library/AudioMixer.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.facade.example.some_complex_media_library; 2 | 3 | import java.io.File; 4 | 5 | public class AudioMixer { 6 | public File fix(VideoFile result){ 7 | System.out.println("AudioMixer: fixing audio..."); 8 | return new File("tmp"); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /concurrency/akka/akka-cluster/src/main/resources/stats1.conf: -------------------------------------------------------------------------------- 1 | include "application" 2 | 3 | akka.actor.deployment { 4 | /statsService/workerRouter { 5 | router = consistent-hashing-group 6 | routees.paths = ["/user/statsWorker"] 7 | cluster { 8 | enabled = on 9 | allow-local-routees = on 10 | use-role = compute 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /concurrency/akka/akka-cluster/src/main/resources/stats2.conf: -------------------------------------------------------------------------------- 1 | include "application" 2 | 3 | akka.actor.deployment { 4 | /statsService/singleton/workerRouter { 5 | router = consistent-hashing-pool 6 | cluster { 7 | enabled = on 8 | max-nr-of-instances-per-node = 3 9 | allow-local-routees = on 10 | use-role = compute 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /concurrency/akka/akka-mqtt/src/main/scala/akkaiot/Work.scala: -------------------------------------------------------------------------------- 1 | package akkaiot 2 | 3 | import java.io.Serializable 4 | 5 | case class Work(workId: String, deviceType: String, deviceId: String, currState: Int, currSetting: Int) extends Serializable 6 | 7 | case class WorkResult(workId: String, deviceType: String, deviceId: String, nextState: Int, nextSetting: Int) extends Serializable 8 | -------------------------------------------------------------------------------- /snippets/junit/assumptions/src/test/java/com/example/demo/connectionchecking/ConnectionChecker.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.connectionchecking; 2 | 3 | public class ConnectionChecker { 4 | 5 | private String uri; 6 | 7 | public ConnectionChecker(String uri) { 8 | this.uri = uri; 9 | } 10 | 11 | public boolean connect() { 12 | return false; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /design-patterns/iterator/example/social_networks/SocialNetwork.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.iterator.example.social_networks; 2 | 3 | import refactoring_guru.iterator.example.iterators.ProfileIterator; 4 | 5 | public interface SocialNetwork { 6 | ProfileIterator createFriendsIterator(String profileEmail); 7 | 8 | ProfileIterator createCoworkersIterator(String profileEmail); 9 | } 10 | -------------------------------------------------------------------------------- /concurrency/akka/akka-spring-boot/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /snippets/io/FileIO-MOM/code_xy7620/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /design-patterns/mediator/example/components/Component.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.mediator.example.components; 2 | 3 | import refactoring_guru.mediator.example.mediator.Mediator; 4 | 5 | /** 6 | * EN: Common component interface. 7 | * 8 | * RU: Общий интерфейс компонентов. 9 | */ 10 | public interface Component { 11 | void setMediator(Mediator mediator); 12 | String getName(); 13 | } 14 | -------------------------------------------------------------------------------- /snippets/junit/assumptions/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /build/ 3 | !gradle/wrapper/gradle-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | nbproject/private/ 21 | build/ 22 | nbbuild/ 23 | dist/ 24 | nbdist/ 25 | .nb-gradle/ -------------------------------------------------------------------------------- /design-patterns/proxy/example/some_cool_media_library/Video.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.proxy.example.some_cool_media_library; 2 | 3 | public class Video { 4 | public String id; 5 | public String title; 6 | public String data; 7 | 8 | Video(String id, String title) { 9 | this.id = id; 10 | this.title = title; 11 | this.data = "Random video."; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /design-patterns/abstract_factory/example/checkboxes/Checkbox.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.abstract_factory.example.checkboxes; 2 | 3 | /** 4 | * EN: Checkboxes is the second product family. It has the same variants as 5 | * buttons. 6 | * 7 | * RU: Чекбоксы — это второе семейство продуктов. Оно имеет те же вариации, что 8 | * и кнопки. 9 | */ 10 | public interface Checkbox { 11 | void paint(); 12 | } 13 | -------------------------------------------------------------------------------- /design-patterns/bridge/example/devices/Device.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.bridge.example.devices; 2 | 3 | public interface Device { 4 | boolean isEnabled(); 5 | 6 | void enable(); 7 | 8 | void disable(); 9 | 10 | int getVolume(); 11 | 12 | void setVolume(int percent); 13 | 14 | int getChannel(); 15 | 16 | void setChannel(int channel); 17 | 18 | void printStatus(); 19 | } 20 | -------------------------------------------------------------------------------- /concurrency/basic/src/main/java/safety/lock/counter/AtomicVariableCounter.java: -------------------------------------------------------------------------------- 1 | package safety.lock.counter; 2 | 3 | import java.util.concurrent.atomic.AtomicInteger; 4 | 5 | public class AtomicVariableCounter 6 | { 7 | private AtomicInteger c = new AtomicInteger(0); 8 | 9 | public void increment() 10 | { 11 | c.incrementAndGet(); 12 | } 13 | 14 | public int getCount() 15 | { 16 | return c.get(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /concurrency/basic/src/main/java/safety/lock/counter/SynchronizedMethodsCounter.java: -------------------------------------------------------------------------------- 1 | package safety.lock.counter; 2 | 3 | /* 4 | * only one thread can enter get()/increment() 5 | * */ 6 | 7 | public class SynchronizedMethodsCounter 8 | { 9 | private int value; 10 | 11 | public synchronized int get() 12 | { 13 | return value; 14 | } 15 | 16 | public synchronized void increment() 17 | { 18 | value++; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /concurrency/akka/akka-spring-boot/src/main/java/com/chriniko/example/akkaspringexample/message/CrimeRecordsProcessedAck.java: -------------------------------------------------------------------------------- 1 | public class CrimeRecordsProcessedAck { 2 | 3 | private final long processedCount; 4 | 5 | public CrimeRecordsProcessedAck(long processedCount) { 6 | this.processedCount = processedCount; 7 | } 8 | 9 | public long getProcessedCount() { 10 | return processedCount; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /boilerplates/maven-app/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /design-patterns/template_method/example/OutputDemo.txt: -------------------------------------------------------------------------------- 1 | Input user name: Jhonatan 2 | Input password: qswe 3 | Input message: Hello, World! 4 | 5 | Choose social network for posting message. 6 | 1 - Facebook 7 | 2 - Twitter 8 | 2 9 | 10 | Checking user's parameters 11 | Name: Jhonatan 12 | Password: **** 13 | .......... 14 | 15 | LogIn success on Twitter 16 | Message: 'Hello, World!' was posted on Twitter 17 | User: 'Jhonatan' was logged out from Twitter -------------------------------------------------------------------------------- /concurrency/akka/akka-cluster/src/main/java/sample/cluster/factorial/FactorialApp.java: -------------------------------------------------------------------------------- 1 | public class FactorialApp { 2 | 3 | public static void main(String[] args) { 4 | // starting 3 backend nodes and 1 frontend node 5 | FactorialBackendMain.main(new String[] { "2551" }); 6 | FactorialBackendMain.main(new String[] { "2552" }); 7 | FactorialBackendMain.main(new String[0]); 8 | FactorialFrontendMain.main(new String[0]); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /concurrency/akka/akka-agent/.mvn/extensions.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | fr.brouillard.oss 5 | jgitver-maven-plugin 6 | 0.4.0 7 | 8 | 9 | -------------------------------------------------------------------------------- /concurrency/akka/akka-cluster/src/main/java/sample/cluster/factorial/FactorialResult.java: -------------------------------------------------------------------------------- 1 | import java.math.BigInteger; 2 | import java.io.Serializable; 3 | 4 | public class FactorialResult implements Serializable { 5 | private static final long serialVersionUID = 1L; 6 | public final int n; 7 | public final BigInteger factorial; 8 | 9 | FactorialResult(int n, BigInteger factorial) { 10 | this.n = n; 11 | this.factorial = factorial; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /concurrency/akka/akka-fsm/.mvn/extensions.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | fr.brouillard.oss 5 | jgitver-maven-plugin 6 | 0.4.0 7 | 8 | 9 | -------------------------------------------------------------------------------- /concurrency/akka/akka-future/.mvn/extensions.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | fr.brouillard.oss 5 | jgitver-maven-plugin 6 | 0.4.0 7 | 8 | 9 | -------------------------------------------------------------------------------- /concurrency/akka/akka-router/.mvn/extensions.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | fr.brouillard.oss 5 | jgitver-maven-plugin 6 | 0.4.0 7 | 8 | 9 | -------------------------------------------------------------------------------- /concurrency/akka/akka-start/.mvn/extensions.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | fr.brouillard.oss 5 | jgitver-maven-plugin 6 | 0.4.0 7 | 8 | 9 | -------------------------------------------------------------------------------- /design-patterns/bridge/example/remotes/AdvancedRemote.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.bridge.example.remotes; 2 | 3 | import refactoring_guru.bridge.example.devices.Device; 4 | 5 | public class AdvancedRemote extends BasicRemote { 6 | 7 | public AdvancedRemote(Device device) { 8 | super.device = device; 9 | } 10 | 11 | public void mute() { 12 | System.out.println("Remote: mute"); 13 | device.setVolume(0); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /design-patterns/composite/example/shapes/Shape.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.composite.example.shapes; 2 | 3 | import java.awt.*; 4 | 5 | public interface Shape { 6 | int getX(); 7 | int getY(); 8 | int getWidth(); 9 | int getHeight(); 10 | void move(int x, int y); 11 | boolean isInsideBounds(int x, int y); 12 | void select(); 13 | void unSelect(); 14 | boolean isSelected(); 15 | void paint(Graphics graphics); 16 | } 17 | -------------------------------------------------------------------------------- /design-patterns/facade/example/Demo.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.facade.example; 2 | 3 | import refactoring_guru.facade.example.facade.VideoConversionFacade; 4 | 5 | import java.io.File; 6 | 7 | public class Demo { 8 | public static void main(String[] args) { 9 | VideoConversionFacade converter = new VideoConversionFacade(); 10 | File mp4Video = converter.convertVideo("youtubevideo.ogg", "mp4"); 11 | // ... 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /concurrency/akka/akka-persistence/.mvn/extensions.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | fr.brouillard.oss 5 | jgitver-maven-plugin 6 | 0.4.0 7 | 8 | 9 | -------------------------------------------------------------------------------- /concurrency/akka/akka-supervision/.mvn/extensions.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | fr.brouillard.oss 5 | jgitver-maven-plugin 6 | 0.4.0 7 | 8 | 9 | -------------------------------------------------------------------------------- /concurrency/akka/akka-websocket/.mvn/extensions.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | fr.brouillard.oss 5 | jgitver-maven-plugin 6 | 0.4.0 7 | 8 | 9 | -------------------------------------------------------------------------------- /deployment/docker/jar/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-jre-alpine 2 | LABEL maintainer "Dragon <384924552@qq.com>" 3 | 4 | # 暴露必须的接口 5 | EXPOSE 80 1399 8000-12000 6 | 7 | RUN apk add --update curl tar && \ 8 | rm -rf /var/cache/apk/* 9 | 10 | # 创建并且设置运行目录 11 | RUN mkdir /opt/ 12 | RUN mkdir /opt/workspace 13 | WORKDIR /opt/workspace 14 | 15 | # 添加运行脚本 16 | ADD run.sh /opt/workspace 17 | RUN chmod +x /opt/workspace/run.sh 18 | 19 | ENTRYPOINT ["/opt/workspace/run.sh"] -------------------------------------------------------------------------------- /snippets/junit/assumptions/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server.port: 8081 2 | 3 | logging.level.com.example.demo.CustomerClient: DEBUG 4 | logging.level.com.example.demo.AddressClient: DEBUG 5 | logging.level.org.hibernate.SQL: DEBUG 6 | 7 | customers: 8 | ribbon: 9 | eureka: 10 | enabled: false 11 | listOfServers: localhost:8080 12 | 13 | addresses: 14 | ribbon: 15 | eureka: 16 | enabled: false 17 | listOfServers: localhost:8080 -------------------------------------------------------------------------------- /concurrency/akka/akka-streams/src/main/java/com/baeldung/akkastreams/AverageRepository.java: -------------------------------------------------------------------------------- 1 | import java.util.concurrent.CompletableFuture; 2 | import java.util.concurrent.CompletionStage; 3 | 4 | public class AverageRepository { 5 | CompletionStage save(Double average) { 6 | return CompletableFuture.supplyAsync(() -> { 7 | System.out.println("saving average: " + average); 8 | return average; 9 | }); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /concurrency/akka/akka-spring/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /design-patterns/flyweight/example/trees/Tree.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.flyweight.example.trees; 2 | 3 | import java.awt.*; 4 | 5 | public class Tree { 6 | private int x; 7 | private int y; 8 | private TreeType type; 9 | 10 | public Tree(int x, int y, TreeType type) { 11 | this.x = x; 12 | this.y = y; 13 | this.type = type; 14 | } 15 | 16 | public void draw(Graphics g) { 17 | type.draw(g, x, y); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /concurrency/akka/akka-streams/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /design-patterns/command/example/commands/CommandHistory.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.command.example.commands; 2 | 3 | import java.util.Stack; 4 | 5 | public class CommandHistory { 6 | private Stack history = new Stack<>(); 7 | 8 | public void push(Command c) { 9 | history.push(c); 10 | } 11 | 12 | public Command pop() { 13 | return history.pop(); 14 | } 15 | 16 | public boolean isEmpty() { return history.isEmpty(); } 17 | } 18 | -------------------------------------------------------------------------------- /design-patterns/command/example/commands/CopyCommand.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.command.example.commands; 2 | 3 | import refactoring_guru.command.example.editor.Editor; 4 | 5 | public class CopyCommand extends Command { 6 | 7 | public CopyCommand(Editor editor) { 8 | super(editor); 9 | } 10 | 11 | @Override 12 | public boolean execute() { 13 | editor.clipboard = editor.textField.getSelectedText(); 14 | return false; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /design-patterns/memento/example/history/Memento.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.memento.example.history; 2 | 3 | import refactoring_guru.memento.example.editor.Editor; 4 | 5 | public class Memento { 6 | private String backup; 7 | private Editor editor; 8 | 9 | public Memento(Editor editor) { 10 | this.editor = editor; 11 | this.backup = editor.backup(); 12 | } 13 | 14 | public void restore() { 15 | editor.restore(backup); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /boilerplates/maven-app/src/main/java/com/example/lib/MyClass.java: -------------------------------------------------------------------------------- 1 | package com.example.lib; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | /** 7 | * My class. 8 | * 9 | * @author Myself 10 | */ 11 | public class MyClass { 12 | 13 | /** The logger for this class. */ 14 | private static final Logger logger = LoggerFactory.getLogger(MyClass.class); 15 | 16 | /** 17 | * Constructor. 18 | */ 19 | public MyClass() { 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /concurrency/akka/akka-cluster/src/main/java/sample/cluster/transformation/TransformationApp.java: -------------------------------------------------------------------------------- 1 | public class TransformationApp { 2 | 3 | public static void main(String[] args) { 4 | // starting 2 frontend nodes and 3 backend nodes 5 | TransformationBackendMain.main(new String[] { "2551" }); 6 | TransformationBackendMain.main(new String[] { "2552" }); 7 | TransformationBackendMain.main(new String[0]); 8 | TransformationFrontendMain.main(new String[0]); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /snippets/junit/assumptions/src/test/java/com/example/demo/connectionchecking/junit5/AssumeConnection.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.connectionchecking.junit5; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.RetentionPolicy; 5 | 6 | import org.junit.jupiter.api.extension.ExtendWith; 7 | 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @ExtendWith(AssumeConnectionCondition.class) 10 | public @interface AssumeConnection { 11 | 12 | String uri(); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /snippets/junit/assumptions/src/test/java/com/example/demo/connectionchecking/junit5/ConnectionCheckingJunit5Test.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.connectionchecking.junit5; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import static org.junit.jupiter.api.Assertions.fail; 5 | 6 | @AssumeConnection(uri = "http://my.integration.system") 7 | public class ConnectionCheckingJunit5Test { 8 | 9 | @Test 10 | public void testOnlyWhenConnected() { 11 | fail("Booh!"); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /snippets/io/TopKN/src/main/resources/assembly.xml: -------------------------------------------------------------------------------- 1 | 2 | src 3 | false 4 | 5 | dir 6 | 7 | 8 | 9 | 10 | 11 | 12 | lib 13 | true 14 | 15 | 16 | -------------------------------------------------------------------------------- /concurrency/akka/akka-start/src/main/java/sample/hello/Greeter.java: -------------------------------------------------------------------------------- 1 | import akka.actor.AbstractActor; 2 | 3 | public class Greeter extends AbstractActor { 4 | 5 | public static enum Msg { 6 | GREET, DONE; 7 | } 8 | 9 | @Override 10 | public Receive createReceive() { 11 | return receiveBuilder() 12 | .matchEquals(Msg.GREET, m -> { 13 | System.out.println("Hello World!"); 14 | sender().tell(Msg.DONE, self()); 15 | }) 16 | .build(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /concurrency/akka/akka-distributed-data/src/main/resources/application.conf: -------------------------------------------------------------------------------- 1 | akka { 2 | actor { 3 | provider = "cluster" 4 | } 5 | remote { 6 | log-remote-lifecycle-events = off 7 | netty.tcp { 8 | hostname = "127.0.0.1" 9 | port = 0 10 | } 11 | } 12 | 13 | cluster { 14 | seed-nodes = [ 15 | "akka.tcp://ClusterSystem@127.0.0.1:2551", 16 | "akka.tcp://ClusterSystem@127.0.0.1:2552"] 17 | 18 | auto-down-unreachable-after = 10s 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /concurrency/akka/akka-spring-boot/src/main/resources/db/liquibase-changelog.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /snippets/io/IncrementalSyncSequential/code/src/main/java/com/alibaba/middleware/race/sync/utils/ReadUtils.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.middleware.race.sync.utils; 2 | 3 | /** 4 | * Created by yfu on 6/17/17. 5 | */ 6 | public class ReadUtils { 7 | 8 | public static int skipNext(byte[] buffer, int pos, char b) { 9 | while (buffer[pos++] != b) ; 10 | return pos; 11 | } 12 | 13 | public static byte peek(byte[] buffer, int pos) { 14 | return buffer[pos]; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /concurrency/akka/akka-mqtt/src/main/scala/akkaiot/MasterWorkerProtocol.scala: -------------------------------------------------------------------------------- 1 | package akkaiot 2 | 3 | object MasterWorkerProtocol { 4 | // Messages from Workers 5 | case class RegisterWorker(workerId: String) 6 | case class WorkerRequestsWork(workerId: String) 7 | case class WorkIsDone(workerId: String, workId: String, result: WorkResult) 8 | case class WorkFailed(workerId: String, workId: String) 9 | 10 | // Messages to Workers 11 | case object WorkIsReady 12 | case class Ack(id: String) 13 | } -------------------------------------------------------------------------------- /snippets/io/FileIO-MOM/code_xy7620/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 8 | org.eclipse.jdt.core.compiler.source=1.8 9 | -------------------------------------------------------------------------------- /design-patterns/adapter/example/round/RoundPeg.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.adapter.example.round; 2 | 3 | /** 4 | * EN: RoundPegs are compatible with RoundHoles. 5 | * 6 | * RU: КруглыеКолышки совместимы с КруглымиОтверстиями. 7 | */ 8 | public class RoundPeg { 9 | private double radius; 10 | 11 | public RoundPeg() {} 12 | 13 | public RoundPeg(double radius) { 14 | this.radius = radius; 15 | } 16 | 17 | public double getRadius() { 18 | return radius; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /design-patterns/state/example/Demo.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.state.example; 2 | 3 | import refactoring_guru.state.example.ui.Player; 4 | import refactoring_guru.state.example.ui.UI; 5 | 6 | /** 7 | * EN: Demo class. Everything comes together here. 8 | * 9 | * RU: Демо-класс. Здесь всё сводится воедино. 10 | */ 11 | public class Demo { 12 | public static void main(String[] args) { 13 | Player player = new Player(); 14 | UI ui = new UI(player); 15 | ui.init(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /deployment/docker/maven/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine/git as clone 2 | ARG url 3 | WORKDIR /app 4 | RUN git clone ${url} 5 | 6 | FROM maven:3.5-jdk-8-alpine as build 7 | ARG project 8 | WORKDIR /app 9 | COPY --from=clone /app/${project} /app 10 | RUN mvn install 11 | 12 | FROM openjdk:8-jre-alpine 13 | ARG artifactid 14 | ARG version 15 | ENV artifact ${artifactid}-${version}.jar 16 | WORKDIR /app 17 | COPY --from=build /app/target/${artifact} /app 18 | EXPOSE 8080 19 | ENTRYPOINT ["sh", "-c"] 20 | CMD ["java -jar ${artifact}"] -------------------------------------------------------------------------------- /snippets/io/IncrementalSyncSequential/code/src/resources/assembly.xml: -------------------------------------------------------------------------------- 1 | 2 | src 3 | false 4 | 5 | dir 6 | 7 | 8 | 9 | 10 | 11 | 12 | lib 13 | true 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /snippets/junit/assumptions/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenCentral() 4 | } 5 | } 6 | 7 | apply plugin: 'java' 8 | 9 | version = '0.0.1-SNAPSHOT' 10 | sourceCompatibility = 11 11 | 12 | repositories { 13 | mavenLocal() 14 | mavenCentral() 15 | } 16 | 17 | ext { 18 | springCloudVersion = 'Dalston.SR2' 19 | } 20 | 21 | dependencies { 22 | testCompile 'org.junit.jupiter:junit-jupiter-engine:5.0.1' 23 | testCompile 'junit:junit:4.12' 24 | } 25 | 26 | test { 27 | useJUnitPlatform() 28 | } -------------------------------------------------------------------------------- /concurrency/basic/src/main/java/safety/lock/counter/SynchronizedBlocksCounter.java: -------------------------------------------------------------------------------- 1 | package safety.lock.counter; 2 | 3 | /* 4 | * only one thread can enter get()/increment() 5 | * */ 6 | 7 | public class SynchronizedBlocksCounter 8 | { 9 | private int value; 10 | 11 | public synchronized int get() 12 | { 13 | synchronized ( this ) 14 | { 15 | return value; 16 | } 17 | } 18 | 19 | public synchronized void increment() 20 | { 21 | synchronized ( this ) 22 | { 23 | value++; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /design-patterns/factory_method/example/factory/HtmlDialog.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.factory_method.example.factory; 2 | 3 | import refactoring_guru.factory_method.example.buttons.Button; 4 | import refactoring_guru.factory_method.example.buttons.HtmlButton; 5 | 6 | /** 7 | * EN: HTML Dialog will produce HTML buttons. 8 | * 9 | * RU: HTML-диалог. 10 | */ 11 | public class HtmlDialog extends Dialog { 12 | 13 | @Override 14 | public Button createButton() { 15 | return new HtmlButton(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /concurrency/akka/akka-http/src/main/java/com/baeldung/akkahttp/User.java: -------------------------------------------------------------------------------- 1 | public class User { 2 | 3 | private final Long id; 4 | 5 | private final String name; 6 | 7 | public User() { 8 | this.name = ""; 9 | this.id = null; 10 | } 11 | 12 | public User(Long id, String name) { 13 | this.name = name; 14 | this.id = id; 15 | } 16 | 17 | public String getName() { 18 | return name; 19 | } 20 | 21 | public Long getId() { 22 | return id; 23 | } 24 | } -------------------------------------------------------------------------------- /concurrency/akka/akka-persistence/src/main/resources/application.conf: -------------------------------------------------------------------------------- 1 | akka.persistence.journal.plugin = "akka.persistence.journal.leveldb" 2 | akka.persistence.snapshot-store.plugin = "akka.persistence.snapshot-store.local" 3 | 4 | akka.persistence.journal.leveldb.dir = "target/example/journal" 5 | akka.persistence.snapshot-store.local.dir = "target/example/snapshots" 6 | 7 | # DO NOT USE THIS IN PRODUCTION !!! 8 | # See also https://github.com/typesafehub/activator/issues/287 9 | akka.persistence.journal.leveldb.native = false 10 | -------------------------------------------------------------------------------- /design-patterns/factory_method/example/buttons/HtmlButton.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.factory_method.example.buttons; 2 | 3 | /** 4 | * EN: HTML button implementation. 5 | * 6 | * RU: Реализация HTML кнопок. 7 | */ 8 | public class HtmlButton implements Button { 9 | 10 | public void render() { 11 | System.out.println(""); 12 | onClick(); 13 | } 14 | 15 | public void onClick() { 16 | System.out.println("Click! Button says - 'Hello World!'"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /design-patterns/facade/example/some_complex_media_library/BitrateReader.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.facade.example.some_complex_media_library; 2 | 3 | public class BitrateReader { 4 | public static VideoFile read(VideoFile file, Codec codec) { 5 | System.out.println("BitrateReader: reading file..."); 6 | return file; 7 | } 8 | 9 | public static VideoFile convert(VideoFile buffer, Codec codec) { 10 | System.out.println("BitrateReader: writing file..."); 11 | return buffer; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /snippets/io/FileIO-MOM/code_xy7620/src/main/java/io/openmessaging/v1/V1ExcuteTester.java: -------------------------------------------------------------------------------- 1 | package io.openmessaging.v1; 2 | 3 | /** 4 | * @author XF 5 | * 调用官方的两个测试例修改版,直接执行用控制台日志查看结果 6 | */ 7 | public class V1ExcuteTester { 8 | 9 | public static void main(String[] args) throws Exception { 10 | //不能循环执行,没有清空内存 11 | // for(int i=0; i<1; i++){ 12 | // V1ProducerTester.main(args); 13 | // Thread.sleep(5000); 14 | // V1ConsumerTester.main(args); 15 | // Thread.sleep(1000); 16 | // } 17 | System.out.println((byte)'1'); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /boilerplates/maven-app/.idea/libraries/Maven__junit_junit_4_12.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /design-patterns/abstract_factory/example/factories/GUIFactory.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.abstract_factory.example.factories; 2 | 3 | import refactoring_guru.abstract_factory.example.buttons.Button; 4 | import refactoring_guru.abstract_factory.example.checkboxes.Checkbox; 5 | 6 | /** 7 | * EN: Abstract factory knows about all (abstract) product types. 8 | * 9 | * RU: Абстрактная фабрика знает обо всех (абстрактных) типах продуктов. 10 | */ 11 | public interface GUIFactory { 12 | Button createButton(); 13 | Checkbox createCheckbox(); 14 | } 15 | -------------------------------------------------------------------------------- /design-patterns/decorator/example/decorators/DataSourceDecorator.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.decorator.example.decorators; 2 | 3 | public class DataSourceDecorator implements DataSource { 4 | private DataSource wrappee; 5 | 6 | DataSourceDecorator(DataSource source) { 7 | this.wrappee = source; 8 | } 9 | 10 | @Override 11 | public void writeData(String data) { 12 | wrappee.writeData(data); 13 | } 14 | 15 | @Override 16 | public String readData() { 17 | return wrappee.readData(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /design-patterns/facade/example/some_complex_media_library/VideoFile.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.facade.example.some_complex_media_library; 2 | 3 | public class VideoFile { 4 | private String name; 5 | private String codecType; 6 | 7 | public VideoFile(String name) { 8 | this.name = name; 9 | this.codecType = name.substring(name.indexOf(".") + 1); 10 | } 11 | 12 | public String getCodecType() { 13 | return codecType; 14 | } 15 | 16 | public String getName() { 17 | return name; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /algorithms/snippets/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 3 | org.eclipse.jdt.core.compiler.compliance=1.8 4 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled 5 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 6 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore 7 | org.eclipse.jdt.core.compiler.processAnnotations=disabled 8 | org.eclipse.jdt.core.compiler.release=disabled 9 | org.eclipse.jdt.core.compiler.source=1.8 10 | -------------------------------------------------------------------------------- /design-patterns/factory_method/example/factory/WindowsDialog.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.factory_method.example.factory; 2 | 3 | import refactoring_guru.factory_method.example.buttons.Button; 4 | import refactoring_guru.factory_method.example.buttons.WindowsButton; 5 | 6 | /** 7 | * EN: Windows Dialog will produce Windows buttons. 8 | * 9 | * RU: Диалог на элементах операционной системы. 10 | */ 11 | public class WindowsDialog extends Dialog { 12 | 13 | @Override 14 | public Button createButton() { 15 | return new WindowsButton(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /concurrency/akka/akka-spring-boot/src/main/java/com/chriniko/example/akkaspringexample/message/CrimeRecordsToProcess.java: -------------------------------------------------------------------------------- 1 | import CrimeRecord; 2 | 3 | import java.util.Collections; 4 | import java.util.List; 5 | 6 | public class CrimeRecordsToProcess { 7 | 8 | private final List crimeRecords; 9 | 10 | public CrimeRecordsToProcess(List crimeRecords) { 11 | this.crimeRecords = Collections.unmodifiableList(crimeRecords); 12 | } 13 | 14 | public List getCrimeRecords() { 15 | return crimeRecords; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /design-patterns/abstract_factory/example/buttons/MacOSButton.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.abstract_factory.example.buttons; 2 | 3 | /** 4 | * EN: All products families have the same varieties (MacOS/Windows). 5 | * 6 | * This is a MacOS variant of a button. 7 | * 8 | * RU: Все семейства продуктов имеют одни и те же вариации (MacOS/Windows). 9 | * 10 | * Это вариант кнопки под MacOS. 11 | */ 12 | public class MacOSButton implements Button { 13 | 14 | @Override 15 | public void paint() { 16 | System.out.println("You have created MacOSButton."); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /design-patterns/visitor/example/shapes/Circle.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.visitor.example.shapes; 2 | 3 | import refactoring_guru.visitor.example.visitor.Visitor; 4 | 5 | public class Circle extends Dot { 6 | private int radius; 7 | 8 | public Circle(int id, int x, int y, int radius) { 9 | super(id, x, y); 10 | this.radius = radius; 11 | } 12 | 13 | @Override 14 | public String accept(Visitor visitor) { 15 | return visitor.visitCircle(this); 16 | } 17 | 18 | public int getRadius() { 19 | return radius; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /design-patterns/command/example/commands/Command.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.command.example.commands; 2 | 3 | import refactoring_guru.command.example.editor.Editor; 4 | 5 | public abstract class Command { 6 | public Editor editor; 7 | private String backup; 8 | 9 | Command(Editor editor) { 10 | this.editor = editor; 11 | } 12 | 13 | void backup() { 14 | backup = editor.textField.getText(); 15 | } 16 | 17 | public void undo() { 18 | editor.textField.setText(backup); 19 | } 20 | 21 | public abstract boolean execute(); 22 | } 23 | -------------------------------------------------------------------------------- /design-patterns/visitor/example/visitor/Visitor.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.visitor.example.visitor; 2 | 3 | import refactoring_guru.visitor.example.shapes.Circle; 4 | import refactoring_guru.visitor.example.shapes.CompoundShape; 5 | import refactoring_guru.visitor.example.shapes.Dot; 6 | import refactoring_guru.visitor.example.shapes.Rectangle; 7 | 8 | public interface Visitor { 9 | String visitDot(Dot dot); 10 | 11 | String visitCircle(Circle circle); 12 | 13 | String visitRectangle(Rectangle rectangle); 14 | 15 | String visitCompoundGraphic(CompoundShape cg); 16 | } 17 | -------------------------------------------------------------------------------- /concurrency/akka/akka-cluster/src/main/java/sample/cluster/stats/StatsSampleClientMain.java: -------------------------------------------------------------------------------- 1 | import akka.actor.ActorSystem; 2 | import akka.actor.Props; 3 | 4 | import com.typesafe.config.ConfigFactory; 5 | 6 | public class StatsSampleClientMain { 7 | 8 | public static void main(String[] args) { 9 | // note that client is not a compute node, role not defined 10 | ActorSystem system = ActorSystem.create("ClusterSystem", 11 | ConfigFactory.load("stats1")); 12 | system.actorOf(Props.create(StatsSampleClient.class, "/user/statsService"), 13 | "client"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /concurrency/akka/akka-spring-boot/src/main/java/com/chriniko/example/akkaspringexample/message/CrimeRecordsToProcessBatch.java: -------------------------------------------------------------------------------- 1 | import CrimeRecord; 2 | 3 | import java.util.Collections; 4 | import java.util.List; 5 | 6 | public class CrimeRecordsToProcessBatch { 7 | 8 | private final List crimeRecords; 9 | 10 | public CrimeRecordsToProcessBatch(List crimeRecords) { 11 | this.crimeRecords = Collections.unmodifiableList(crimeRecords); 12 | } 13 | 14 | public List getCrimeRecords() { 15 | return crimeRecords; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /design-patterns/abstract_factory/example/buttons/WindowsButton.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.abstract_factory.example.buttons; 2 | 3 | /** 4 | * EN: All products families have the same varieties (MacOS/Windows). 5 | * 6 | * This is another variant of a button. 7 | * 8 | * RU: Все семейства продуктов имеют одни и те же вариации (MacOS/Windows). 9 | * 10 | * Это вариант кнопки под Windows. 11 | */ 12 | public class WindowsButton implements Button { 13 | 14 | @Override 15 | public void paint() { 16 | System.out.println("You have created WindowsButton."); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /design-patterns/abstract_factory/example/checkboxes/MacOSCheckbox.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.abstract_factory.example.checkboxes; 2 | 3 | /** 4 | * EN: All products families have the same varieties (MacOS/Windows). 5 | * 6 | * This is a variant of a checkbox. 7 | * 8 | * RU: Все семейства продуктов имеют одинаковые вариации (MacOS/Windows). 9 | * 10 | * Вариация чекбокса под MacOS. 11 | */ 12 | public class MacOSCheckbox implements Checkbox { 13 | 14 | @Override 15 | public void paint() { 16 | System.out.println("You have created MacOSCheckbox."); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /design-patterns/observer/example/listeners/LogOpenListener.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.observer.example.listeners; 2 | 3 | import java.io.File; 4 | 5 | public class LogOpenListener implements EventListener { 6 | private File log; 7 | 8 | public LogOpenListener(String fileName) { 9 | this.log = new File(fileName); 10 | } 11 | 12 | @Override 13 | public void update(String eventType, File file) { 14 | System.out.println("Save to log " + log + ": Someone has performed " + eventType + " operation with the following file: " + file.getName()); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /concurrency/basic/src/main/java/safety/collection/boundedBlockingQueue/ClassicQueue.java: -------------------------------------------------------------------------------- 1 | package safety.collection.boundedBlockingQueue; 2 | 3 | /** 4 | * 5 | * not thread safe 6 | */ 7 | 8 | public class ClassicQueue 9 | { 10 | public static final int QSIZE = 10; 11 | 12 | // next slot to deque, empty slot position 13 | int head = 0, tail = 0; 14 | 15 | // array of T items 16 | int[] items = new int[QSIZE]; 17 | 18 | public void enq( int x ) 19 | { 20 | items[(tail++) % QSIZE] = x; 21 | } 22 | 23 | public int deq() 24 | { 25 | return items[(head++) % QSIZE]; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /design-patterns/abstract_factory/example/checkboxes/WindowsCheckbox.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.abstract_factory.example.checkboxes; 2 | 3 | /** 4 | * EN: All products families have the same varieties (MacOS/Windows). 5 | * 6 | * This is another variant of a checkbox. 7 | * 8 | * RU: Все семейства продуктов имеют одинаковые вариации (MacOS/Windows). 9 | * 10 | * Вариация чекбокса под Windows. 11 | */ 12 | public class WindowsCheckbox implements Checkbox { 13 | 14 | @Override 15 | public void paint() { 16 | System.out.println("You have created WindowsCheckbox."); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /boilerplates/maven-app/.idea/libraries/Maven__org_slf4j_slf4j_api_1_7_7.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /concurrency/akka/akka-distributed-data/src/multi-jvm/scala/sample/distributeddata/STMultiNodeSpec.scala: -------------------------------------------------------------------------------- 1 | package sample.distributeddata 2 | 3 | import akka.remote.testkit.MultiNodeSpecCallbacks 4 | 5 | import org.scalatest.{ BeforeAndAfterAll, WordSpecLike } 6 | import org.scalatest.Matchers 7 | 8 | /** 9 | * Hooks up MultiNodeSpec with ScalaTest 10 | */ 11 | trait STMultiNodeSpec extends MultiNodeSpecCallbacks 12 | with WordSpecLike with Matchers with BeforeAndAfterAll { 13 | 14 | override def beforeAll() = multiNodeSpecBeforeAll() 15 | 16 | override def afterAll() = multiNodeSpecAfterAll() 17 | } 18 | -------------------------------------------------------------------------------- /snippets/io/FileIO-MOM/code_klosefu/src/main/java/io/openmessaging/demo/serializer/MessageSerializer.java: -------------------------------------------------------------------------------- 1 | package io.openmessaging.demo.serializer; 2 | 3 | import io.openmessaging.Message; 4 | 5 | import java.nio.BufferOverflowException; 6 | import java.nio.ByteBuffer; 7 | import java.util.List; 8 | 9 | /** 10 | * Created by yfu on 4/29/17. 11 | */ 12 | public interface MessageSerializer { 13 | // write a list of payloads into buffer 14 | // throws BufferOverflowException if buffer is overflowed 15 | void write(ByteBuffer buffer, List messages) throws BufferOverflowException; 16 | } 17 | -------------------------------------------------------------------------------- /concurrency/basic/src/main/java/safety/collection/singleton/SynchronizedMethodSingleton.java: -------------------------------------------------------------------------------- 1 | package safety.collection.singleton; 2 | 3 | /** 4 | * 5 | * threadsafe 6 | */ 7 | 8 | public class SynchronizedMethodSingleton 9 | { 10 | private static SynchronizedMethodSingleton instance; 11 | private SynchronizedMethodSingleton(){} 12 | 13 | // use mutex to protect object creation 14 | public synchronized static SynchronizedMethodSingleton getInstance() 15 | { 16 | if ( instance == null ) 17 | { 18 | instance = new SynchronizedMethodSingleton(); 19 | } 20 | return instance; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /design-patterns/builder/example/components/GPSNavigator.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.builder.example.components; 2 | 3 | /** 4 | * EN: Just another feature of a car. 5 | * 6 | * RU: Одна из фишек автомобиля. 7 | */ 8 | public class GPSNavigator { 9 | private String route; 10 | 11 | public GPSNavigator() { 12 | this.route = "221b, Baker Street, London to Scotland Yard, 8-10 Broadway, London"; 13 | } 14 | 15 | public GPSNavigator(String manualRoute) { 16 | this.route = manualRoute; 17 | } 18 | 19 | public String getRoute() { 20 | return route; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /design-patterns/observer/example/listeners/EmailNotificationListener.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.observer.example.listeners; 2 | 3 | import java.io.File; 4 | 5 | public class EmailNotificationListener implements EventListener { 6 | private String email; 7 | 8 | public EmailNotificationListener(String email) { 9 | this.email = email; 10 | } 11 | 12 | @Override 13 | public void update(String eventType, File file) { 14 | System.out.println("Email to " + email + ": Someone has performed " + eventType + " operation with the following file: " + file.getName()); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /snippets/io/FileIO-MOM/code_klosefu/src/main/java/io/openmessaging/demo/serializer/MessageDeserializer.java: -------------------------------------------------------------------------------- 1 | package io.openmessaging.demo.serializer; 2 | 3 | import io.openmessaging.Message; 4 | 5 | import java.nio.BufferUnderflowException; 6 | import java.nio.ByteBuffer; 7 | import java.util.List; 8 | 9 | /** 10 | * Created by yfu on 4/29/17. 11 | */ 12 | public interface MessageDeserializer { 13 | // read a list of payloads from buffer 14 | // throws BufferUnderflowException if excepting data but got EOF 15 | List read(ByteBuffer buffer, int count) throws BufferUnderflowException; 16 | } 17 | -------------------------------------------------------------------------------- /concurrency/akka/akka-agent/.mvn/jgitver.config.xml: -------------------------------------------------------------------------------- 1 | 4 | false 5 | true 6 | true 7 | true 8 | false 9 | -------------------------------------------------------------------------------- /concurrency/akka/akka-fsm/.mvn/jgitver.config.xml: -------------------------------------------------------------------------------- 1 | 4 | false 5 | true 6 | true 7 | true 8 | false 9 | -------------------------------------------------------------------------------- /concurrency/akka/akka-start/.mvn/jgitver.config.xml: -------------------------------------------------------------------------------- 1 | 4 | false 5 | true 6 | true 7 | true 8 | false 9 | -------------------------------------------------------------------------------- /design-patterns/command/example/commands/PasteCommand.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.command.example.commands; 2 | 3 | import refactoring_guru.command.example.editor.Editor; 4 | 5 | public class PasteCommand extends Command { 6 | 7 | public PasteCommand(Editor editor) { 8 | super(editor); 9 | } 10 | 11 | @Override 12 | public boolean execute() { 13 | if (editor.clipboard == null || editor.clipboard.isEmpty()) return false; 14 | 15 | backup(); 16 | editor.textField.insert(editor.clipboard, editor.textField.getCaretPosition()); 17 | return true; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /snippets/io/TopKN/.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Java template 3 | # Compiled class file 4 | *.class 5 | 6 | # Log file 7 | *.log 8 | 9 | # BlueJ files 10 | *.ctxt 11 | 12 | # Mobile Tools for Java (J2ME) 13 | .mtj.tmp/ 14 | 15 | # Package Files # 16 | *.jar 17 | *.war 18 | *.ear 19 | *.zip 20 | *.tar.gz 21 | *.rar 22 | 23 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 24 | hs_err_pid* 25 | 26 | .classpath 27 | .project 28 | .settings/ 29 | target/ 30 | tester.log 31 | .idea/ 32 | *.iml 33 | logs/ 34 | 35 | middle/ 36 | result/ 37 | test_logs/ -------------------------------------------------------------------------------- /concurrency/akka/akka-future/.mvn/jgitver.config.xml: -------------------------------------------------------------------------------- 1 | 4 | false 5 | true 6 | true 7 | true 8 | false 9 | -------------------------------------------------------------------------------- /concurrency/akka/akka-router/.mvn/jgitver.config.xml: -------------------------------------------------------------------------------- 1 | 4 | false 5 | true 6 | true 7 | true 8 | false 9 | -------------------------------------------------------------------------------- /concurrency/akka/akka-websocket/.mvn/jgitver.config.xml: -------------------------------------------------------------------------------- 1 | 4 | false 5 | true 6 | true 7 | true 8 | false 9 | -------------------------------------------------------------------------------- /concurrency/akka/akka-cluster/src/main/java/sample/cluster/stats/StatsSampleOneMasterClientMain.java: -------------------------------------------------------------------------------- 1 | import com.typesafe.config.ConfigFactory; 2 | 3 | import akka.actor.ActorSystem; 4 | import akka.actor.Props; 5 | 6 | public class StatsSampleOneMasterClientMain { 7 | 8 | public static void main(String[] args) { 9 | // note that client is not a compute node, role not defined 10 | ActorSystem system = ActorSystem.create("ClusterSystem", 11 | ConfigFactory.load("stats2")); 12 | system.actorOf(Props.create(StatsSampleClient.class, "/user/statsServiceProxy"), 13 | "client"); 14 | 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /concurrency/akka/akka-persistence/.mvn/jgitver.config.xml: -------------------------------------------------------------------------------- 1 | 4 | false 5 | true 6 | true 7 | true 8 | false 9 | -------------------------------------------------------------------------------- /concurrency/akka/akka-supervision/.mvn/jgitver.config.xml: -------------------------------------------------------------------------------- 1 | 4 | false 5 | true 6 | true 7 | true 8 | false 9 | -------------------------------------------------------------------------------- /boilerplates/maven-app/.idea/libraries/Maven__org_slf4j_slf4j_jdk14_1_7_12.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /boilerplates/maven-app/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /concurrency/akka/akka-sharding/src/main/resources/application.conf: -------------------------------------------------------------------------------- 1 | akka { 2 | actor { 3 | provider = "cluster" 4 | } 5 | remote { 6 | log-remote-lifecycle-events = off 7 | netty.tcp { 8 | hostname = "127.0.0.1" 9 | port = 0 10 | } 11 | } 12 | 13 | cluster { 14 | seed-nodes = [ 15 | "akka.tcp://ShardingSystem@127.0.0.1:2551", 16 | "akka.tcp://ShardingSystem@127.0.0.1:2552"] 17 | 18 | # auto downing is NOT safe for production deployments. 19 | # you may want to use it during development, read more about it in the docs. 20 | auto-down-unreachable-after = 10s 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /design-patterns/facade/example/some_complex_media_library/CodecFactory.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.facade.example.some_complex_media_library; 2 | 3 | public class CodecFactory { 4 | public static Codec extract(VideoFile file) { 5 | String type = file.getCodecType(); 6 | if (type.equals("mp4")) { 7 | System.out.println("CodecFactory: extracting mpeg audio..."); 8 | return new MPEG4CompressionCodec(); 9 | } 10 | else { 11 | System.out.println("CodecFactory: extracting ogg audio..."); 12 | return new OggCompressionCodec(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /concurrency/basic/src/main/java/safety/collection/singleton/ClassicSingleton.java: -------------------------------------------------------------------------------- 1 | package safety.collection.singleton; 2 | 3 | /** 4 | * 5 | * Not threadsafe 6 | */ 7 | 8 | public class ClassicSingleton 9 | { 10 | // define an instance field 11 | private static ClassicSingleton instance; 12 | 13 | // make constructure private 14 | private ClassicSingleton(){} 15 | 16 | // use static method to return instance 17 | public static ClassicSingleton getInstance() 18 | { 19 | // lazy initialization 20 | if ( instance == null ) 21 | { 22 | instance = new ClassicSingleton(); 23 | } 24 | return instance; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /design-patterns/flyweight/example/trees/TreeFactory.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.flyweight.example.trees; 2 | 3 | import java.awt.*; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | public class TreeFactory { 8 | static Map treeTypes = new HashMap<>(); 9 | 10 | public static TreeType getTreeType(String name, Color color, String otherTreeData) { 11 | TreeType result = treeTypes.get(name); 12 | if (result == null) { 13 | result = new TreeType(name, color, otherTreeData); 14 | treeTypes.put(name, result); 15 | } 16 | return result; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /concurrency/basic/src/main/java/primitive/thread/ThreadAnonymous.java: -------------------------------------------------------------------------------- 1 | package primitive.thread; 2 | 3 | public class ThreadAnonymous 4 | { 5 | public static void main(String[] args) 6 | { 7 | Thread thread1 = new Thread(new Runnable() { 8 | @Override 9 | public void run() 10 | { 11 | for ( int i = 0; i < 5; i++ ) 12 | { 13 | System.out.println("Hello: " + i + " Thread: " + Thread.currentThread().getName()); 14 | 15 | try 16 | { 17 | Thread.sleep(100); 18 | } 19 | catch (InterruptedException ignored) 20 | { 21 | } 22 | } 23 | } 24 | }); 25 | 26 | thread1.start(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /design-patterns/adapter/example/round/RoundHole.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.adapter.example.round; 2 | 3 | /** 4 | * EN: RoundHoles are compatible with RoundPegs. 5 | * 6 | * RU: КруглоеОтверстие совместимо с КруглымиКолышками. 7 | */ 8 | public class RoundHole { 9 | private double radius; 10 | 11 | public RoundHole(double radius) { 12 | this.radius = radius; 13 | } 14 | 15 | public double getRadius() { 16 | return radius; 17 | } 18 | 19 | public boolean fits(RoundPeg peg) { 20 | boolean result; 21 | result = (this.getRadius() >= peg.getRadius()); 22 | return result; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /design-patterns/memento/example/shapes/Shape.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.memento.example.shapes; 2 | 3 | import java.awt.*; 4 | import java.io.Serializable; 5 | 6 | public interface Shape extends Serializable { 7 | int getX(); 8 | int getY(); 9 | int getWidth(); 10 | int getHeight(); 11 | void drag(); 12 | void drop(); 13 | void moveTo(int x, int y); 14 | void moveBy(int x, int y); 15 | boolean isInsideBounds(int x, int y); 16 | Color getColor(); 17 | void setColor(Color color); 18 | void select(); 19 | void unSelect(); 20 | boolean isSelected(); 21 | void paint(Graphics graphics); 22 | } 23 | 24 | -------------------------------------------------------------------------------- /snippets/io/FileIO-MOM/code_klosefu/src/main/java/io/openmessaging/demo/Constants.java: -------------------------------------------------------------------------------- 1 | package io.openmessaging.demo; 2 | 3 | /** 4 | * Created by yfu on 5/21/17. 5 | */ 6 | public class Constants { 7 | 8 | public static final int MAX_BATCH_SIZE = 1024; // num of messages 9 | 10 | public static final int FILE_ALLOCATE_SIZE = 16 * 1024 * 1024; // Must be an integral multiple of 4K (page size) 11 | public static final int FILE_ALLOCATE_MARGIN = 512 * 1024; // Same as above 12 | 13 | public static final int CONSUMING_QUEUE_CAPACITY = MAX_BATCH_SIZE * 8; 14 | 15 | public static final int PRODUCER_WRITE_THREADS = 4; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /snippets/io/FileIO-MOM/code_xy7620/src/main/java/io/openmessaging/v3/V3ExecuteTester.java: -------------------------------------------------------------------------------- 1 | package io.openmessaging.v3; 2 | /** 3 | * Created by 瑞 on 2017/5/18. 4 | */ 5 | public class V3ExecuteTester { 6 | public static void main(String[] args) throws Exception { 7 | long start = System.currentTimeMillis(); 8 | V3ProducerTester.main(args); 9 | System.out.println(System.currentTimeMillis()-start); 10 | Thread.sleep(5000); 11 | start=System.currentTimeMillis(); 12 | V3ConsumerTester.main(args); 13 | System.out.println(System.currentTimeMillis()-start); 14 | Thread.sleep(1000); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /snippets/junit/assumptions/src/test/java/com/example/demo/connectionchecking/junit4/ConnectionCheckingJunit4Test.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.connectionchecking.junit4; 2 | 3 | 4 | import com.example.demo.connectionchecking.ConnectionChecker; 5 | import org.junit.ClassRule; 6 | import org.junit.Test; 7 | import static org.junit.Assert.fail; 8 | 9 | public class ConnectionCheckingJunit4Test { 10 | 11 | @ClassRule 12 | public static AssumingConnection assumingConnection = new AssumingConnection(new ConnectionChecker("http://my.integration.system")); 13 | 14 | @Test 15 | public void testOnlyWhenConnected() { 16 | fail("Booh!"); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /deployment/docker/jar/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [[ -z "$APP" ]]; then 4 | echo "APP variable is not specified, you should set it to be the address of the app, quitting." 5 | exit 1 6 | fi 7 | 8 | # 删除并且下载应用 9 | rm -rf app.tar.gz 10 | curl --user UserName:CustomPassword $APP -o app.tar.gz 11 | 12 | # 解压 13 | tar -xvzf app.tar.gz 14 | 15 | # 启动应用 16 | if [ -f "app/launcher.sh" ]; then 17 | echo "Starting app using user specified launcher script..." 18 | sh app/launcher.sh 19 | else 20 | if [[ -z "$ENTRY" ]]; then 21 | echo "Try starting app using entry, but ENTRY is not specified, quittting." 22 | exit 1 23 | fi 24 | /usr/bin/java -jar $ENTRY 25 | fi -------------------------------------------------------------------------------- /concurrency/basic/src/main/java/safety/collection/singleton/SynchronizedBlockSingleton.java: -------------------------------------------------------------------------------- 1 | package safety.collection.singleton; 2 | 3 | /** 4 | * 5 | * threadsafe 6 | */ 7 | 8 | public class SynchronizedBlockSingleton 9 | { 10 | private static SynchronizedBlockSingleton instance; 11 | private SynchronizedBlockSingleton(){} 12 | 13 | public static SynchronizedBlockSingleton getInstance() 14 | { 15 | // use mutex to protect object creation 16 | synchronized ( SynchronizedBlockSingleton.class ) 17 | { 18 | if ( instance == null ) 19 | { 20 | instance = new SynchronizedBlockSingleton(); 21 | } 22 | return instance; 23 | } 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /design-patterns/chain_of_responsibility/example/middleware/RoleCheckMiddleware.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.chain_of_responsibility.example.middleware; 2 | 3 | /** 4 | * EN: ConcreteHandler. Checks a user's role. 5 | * 6 | * RU: Конкретный элемент цепи обрабатывает запрос по-своему. 7 | */ 8 | public class RoleCheckMiddleware extends Middleware { 9 | public boolean check(String email, String password) { 10 | if (email.equals("admin@example.com")) { 11 | System.out.println("Hello, admin!"); 12 | return true; 13 | } 14 | System.out.println("Hello, user!"); 15 | return checkNext(email, password); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /concurrency/config/spotbugs-exclude-filter.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /boilerplates/gradle/settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This settings file was generated by the Gradle 'init' task. 3 | * 4 | * The settings file is used to specify which projects to include in your build. 5 | * In a single project build this file can be empty or even removed. 6 | * 7 | * Detailed information about configuring a multi-project build in Gradle can be found 8 | * in the user guide at https://docs.gradle.org/4.4.1/userguide/multi_project_builds.html 9 | */ 10 | 11 | /* 12 | // To declare projects as part of a multi-project build use the 'include' method 13 | include 'shared' 14 | include 'api' 15 | include 'services:webservice' 16 | */ 17 | 18 | rootProject.name = 'java-snippets' 19 | -------------------------------------------------------------------------------- /concurrency/basic/src/main/java/safety/lock/counter/ReentrantLockCounter.java: -------------------------------------------------------------------------------- 1 | package safety.lock.counter; 2 | 3 | import java.util.concurrent.locks.Lock; 4 | import java.util.concurrent.locks.ReentrantLock; 5 | 6 | public class ReentrantLockCounter 7 | { 8 | private final Lock lock = new ReentrantLock(); 9 | private int value; 10 | 11 | public int get() 12 | { 13 | try 14 | { 15 | lock.lock(); 16 | return value; 17 | } 18 | finally 19 | { 20 | lock.unlock(); 21 | } 22 | } 23 | 24 | public synchronized void increment() 25 | { 26 | try 27 | { 28 | lock.lock(); 29 | value++; 30 | } 31 | finally 32 | { 33 | lock.unlock(); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /design-patterns/flyweight/example/trees/TreeType.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.flyweight.example.trees; 2 | 3 | import java.awt.*; 4 | 5 | public class TreeType { 6 | private String name; 7 | private Color color; 8 | private String otherTreeData; 9 | 10 | public TreeType(String name, Color color, String otherTreeData) { 11 | this.name = name; 12 | this.color = color; 13 | this.otherTreeData = otherTreeData; 14 | } 15 | 16 | public void draw(Graphics g, int x, int y) { 17 | g.setColor(Color.BLACK); 18 | g.fillRect(x - 1, y, 3, 5); 19 | g.setColor(color); 20 | g.fillOval(x - 5, y - 10, 10, 10); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /design-patterns/memento/example/shapes/Dot.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.memento.example.shapes; 2 | 3 | import java.awt.*; 4 | 5 | public class Dot extends BaseShape { 6 | private final int DOT_SIZE = 3; 7 | 8 | public Dot(int x, int y, Color color) { 9 | super(x, y, color); 10 | } 11 | 12 | @Override 13 | public int getWidth() { 14 | return DOT_SIZE; 15 | } 16 | 17 | @Override 18 | public int getHeight() { 19 | return DOT_SIZE; 20 | } 21 | 22 | @Override 23 | public void paint(Graphics graphics) { 24 | super.paint(graphics); 25 | graphics.fillRect(x - 1, y - 1, getWidth(), getHeight()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /snippets/io/IncrementalSyncSequential/code/src/main/java/com/alibaba/middleware/race/sync/utils/LongObjectHashMap.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.middleware.race.sync.utils; 2 | 3 | import com.koloboke.compile.KolobokeMap; 4 | 5 | import java.util.Map; 6 | 7 | /** 8 | * Created by yfu on 6/23/17. 9 | */ 10 | public abstract class LongObjectHashMap implements Map { 11 | public static LongObjectHashMap withExpectedSize(int expectedSize) { 12 | return new KolobokeLongObjectHashMap<>(expectedSize); 13 | } 14 | 15 | public abstract V get(long key); 16 | 17 | public abstract V put(long key, V value); 18 | 19 | public abstract V remove(long key); 20 | } 21 | -------------------------------------------------------------------------------- /concurrency/akka/akka-persistence-dc/src/main/protobuf/ThumbsUpMessages.proto: -------------------------------------------------------------------------------- 1 | package sample.persistence.multidc.protobuf; 2 | 3 | option java_package = "sample.persistence.multidc.protobuf"; 4 | option optimize_for = SPEED; 5 | 6 | // state 7 | 8 | message State { 9 | repeated string users = 1; 10 | } 11 | 12 | // commands 13 | 14 | message GiveThumbsUp { 15 | required string resourceId = 1; 16 | required string userId = 2; 17 | } 18 | 19 | message GetCount { 20 | required string resourceId = 1; 21 | } 22 | 23 | message GetUsers { 24 | required string resourceId = 1; 25 | } 26 | 27 | // events 28 | 29 | message GaveThumbsUp { 30 | required string userId = 1; 31 | } 32 | 33 | 34 | -------------------------------------------------------------------------------- /concurrency/akka/akka-spring-boot/src/main/java/com/chriniko/example/akkaspringexample/domain/CrimeRecord.java: -------------------------------------------------------------------------------- 1 | import lombok.AllArgsConstructor; 2 | import lombok.Builder; 3 | import lombok.Getter; 4 | import lombok.ToString; 5 | 6 | @Getter 7 | @AllArgsConstructor 8 | @Builder 9 | @ToString 10 | public class CrimeRecord { 11 | 12 | private final String cDateTime; 13 | private final String address; 14 | private final String district; 15 | private final String beat; 16 | private final String grid; 17 | private final String crimeDescr; 18 | private final String ucrNcicCode; 19 | private final String latitude; 20 | private final String longtitude; 21 | 22 | 23 | } 24 | -------------------------------------------------------------------------------- /design-patterns/composite/example/shapes/Dot.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.composite.example.shapes; 2 | 3 | import java.awt.*; 4 | 5 | public class Dot extends BaseShape { 6 | private final int DOT_SIZE = 3; 7 | 8 | public Dot(int x, int y, Color color) { 9 | super(x, y, color); 10 | } 11 | 12 | @Override 13 | public int getWidth() { 14 | return DOT_SIZE; 15 | } 16 | 17 | @Override 18 | public int getHeight() { 19 | return DOT_SIZE; 20 | } 21 | 22 | @Override 23 | public void paint(Graphics graphics) { 24 | super.paint(graphics); 25 | graphics.fillRect(x - 1, y - 1, getWidth(), getHeight()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /concurrency/akka/akka-cluster/src/main/java/sample/cluster/stats/StatsWorker.java: -------------------------------------------------------------------------------- 1 | import java.util.HashMap; 2 | import java.util.Map; 3 | 4 | import akka.actor.AbstractActor; 5 | 6 | public class StatsWorker extends AbstractActor { 7 | 8 | Map cache = new HashMap(); 9 | 10 | @Override 11 | public Receive createReceive() { 12 | return receiveBuilder() 13 | .match(String.class, word -> { 14 | Integer length = cache.get(word); 15 | if (length == null) { 16 | length = word.length(); 17 | cache.put(word, length); 18 | } 19 | sender().tell(length, self()); 20 | }) 21 | .build(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /concurrency/akka/akka-future/src/main/java/wx/akka/future/PrintActor.java: -------------------------------------------------------------------------------- 1 | import akka.actor.UntypedActor; 2 | import akka.event.Logging; 3 | import akka.event.LoggingAdapter; 4 | 5 | /** 6 | * Created by liubenlong on 2017/1/12. 7 | */ 8 | public class PrintActor extends UntypedActor { 9 | 10 | private final LoggingAdapter log = Logging.getLogger(getContext().system(), this); 11 | 12 | @Override 13 | public void onReceive(Object o) throws Throwable { 14 | log.info("akka.future.wx.akka.future.PrintActor.onReceive:" + o); 15 | if (o instanceof Integer) { 16 | log.info("print:" + o); 17 | } else { 18 | unhandled(o); 19 | } 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /design-patterns/singleton/example/non_thread_safe/DemoSingleThread.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.singleton.example.non_thread_safe; 2 | 3 | public class DemoSingleThread { 4 | public static void main(String[] args) { 5 | System.out.println("If you see the same value, then singleton was reused (yay!)" + "\n" + 6 | "If you see different values, then 2 singletons were created (booo!!)" + "\n\n" + 7 | "RESULT:" + "\n"); 8 | Singleton singleton = Singleton.getInstance("FOO"); 9 | Singleton anotherSingleton = Singleton.getInstance("BAR"); 10 | System.out.println(singleton.value); 11 | System.out.println(anotherSingleton.value); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /snippets/io/FileIO-MOM/code_xy7620/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /concurrency/basic/src/main/java/primitive/thread/ThreadExtends.java: -------------------------------------------------------------------------------- 1 | package primitive.thread; 2 | 3 | class Runner extends Thread 4 | { 5 | 6 | @Override 7 | public void run() 8 | { 9 | for ( int i = 0; i < 5; i++ ) 10 | { 11 | System.out.println("Hello: " + i + " Thread: " + Thread.currentThread().getName()); 12 | try 13 | { 14 | Thread.sleep(100); 15 | } 16 | catch (InterruptedException e) 17 | { 18 | e.printStackTrace(); 19 | } 20 | } 21 | } 22 | } 23 | 24 | public class ThreadExtends 25 | { 26 | public static void main(String[] args) 27 | { 28 | Runner runner1 = new Runner(); 29 | runner1.start(); 30 | 31 | Runner runner2 = new Runner(); 32 | runner2.start(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /concurrency/basic/src/main/java/safety/collection/boundedBlockingQueue/SyncMethodQueue.java: -------------------------------------------------------------------------------- 1 | package safety.collection.boundedBlockingQueue; 2 | 3 | /** 4 | * 5 | * thread safe 6 | * 7 | * not handle enqueue finds a full array 8 | * not handle dequeue finds an empty array 9 | */ 10 | 11 | public class SyncMethodQueue 12 | { 13 | public static final int QSIZE = 10; 14 | 15 | // next slot to deque, empty slot position 16 | int head = 0, tail = 0; 17 | 18 | // array of T items 19 | int[] items = new int[QSIZE]; 20 | 21 | public synchronized void enq( int x ) 22 | { 23 | items[(tail++) % QSIZE] = x; 24 | } 25 | 26 | public synchronized int deq() 27 | { 28 | return items[(head++) % QSIZE]; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /design-patterns/composite/example/shapes/Circle.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.composite.example.shapes; 2 | 3 | import java.awt.*; 4 | 5 | public class Circle extends BaseShape { 6 | public int radius; 7 | 8 | public Circle(int x, int y, int radius, Color color) { 9 | super(x, y, color); 10 | this.radius = radius; 11 | } 12 | 13 | @Override 14 | public int getWidth() { 15 | return radius * 2; 16 | } 17 | 18 | @Override 19 | public int getHeight() { 20 | return radius * 2; 21 | } 22 | 23 | public void paint(Graphics graphics) { 24 | super.paint(graphics); 25 | graphics.drawOval(x, y, getWidth() - 1, getHeight() - 1); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /concurrency/akka/akka-future/src/main/java/wx/akka/future/WorkerActor.java: -------------------------------------------------------------------------------- 1 | import akka.actor.*; 2 | import akka.event.Logging; 3 | import akka.event.LoggingAdapter; 4 | 5 | public class WorkerActor extends UntypedActor { 6 | 7 | private final LoggingAdapter log = Logging.getLogger(getContext().system(), this); 8 | 9 | @Override 10 | public void onReceive(Object o) throws Throwable { 11 | log.info("akka.future.wx.akka.future.WorkerActor.onReceive:" + o); 12 | 13 | if (o instanceof Integer) { 14 | Thread.sleep(1000); 15 | int i = Integer.parseInt(o.toString()); 16 | getSender().tell(i * i, getSelf()); 17 | } else { 18 | unhandled(o); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /design-patterns/memento/example/shapes/Circle.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.memento.example.shapes; 2 | 3 | import java.awt.*; 4 | 5 | public class Circle extends BaseShape { 6 | private int radius; 7 | 8 | public Circle(int x, int y, int radius, Color color) { 9 | super(x, y, color); 10 | this.radius = radius; 11 | } 12 | 13 | @Override 14 | public int getWidth() { 15 | return radius * 2; 16 | } 17 | 18 | @Override 19 | public int getHeight() { 20 | return radius * 2; 21 | } 22 | 23 | @Override 24 | public void paint(Graphics graphics) { 25 | super.paint(graphics); 26 | graphics.drawOval(x, y, getWidth() - 1, getHeight() - 1); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /design-patterns/mediator/example/mediator/Mediator.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.mediator.example.mediator; 2 | 3 | import refactoring_guru.mediator.example.components.Component; 4 | 5 | import javax.swing.*; 6 | 7 | /** 8 | * EN: Common mediator interface. 9 | * 10 | * RU: Общий интерфейс посредников. 11 | */ 12 | public interface Mediator { 13 | void addNewNote(Note note); 14 | void deleteNote(); 15 | void getInfoFromList(Note note); 16 | void saveChanges(); 17 | void markNote(); 18 | void clear(); 19 | void sendToFilter(ListModel listModel); 20 | void setElementsList(ListModel list); 21 | void registerComponent(Component component); 22 | void hideElements(boolean flag); 23 | void createGUI(); 24 | } 25 | -------------------------------------------------------------------------------- /design-patterns/abstract_factory/example/buttons/Button.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.abstract_factory.example.buttons; 2 | 3 | /** 4 | * EN: Abstract Factory assumes that you have several families of products, 5 | * structured into separate class hierarchies (Button/Checkbox). All products of 6 | * the same family have the common interface. 7 | * 8 | * This is the common interface for buttons family. 9 | * 10 | * RU: Паттерн предполагает, что у вас есть несколько семейств продуктов, 11 | * находящихся в отдельных иерархиях классов (Button/Checkbox). Продукты одного 12 | * семейства должны иметь общий интерфейс. 13 | * 14 | * Это — общий интерфейс для семейства продуктов кнопок. 15 | */ 16 | public interface Button { 17 | void paint(); 18 | } 19 | -------------------------------------------------------------------------------- /design-patterns/prototype/example/shapes/Circle.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.prototype.example.shapes; 2 | 3 | public class Circle extends Shape { 4 | public int radius; 5 | 6 | public Circle() { 7 | } 8 | 9 | public Circle(Circle target) { 10 | super(target); 11 | if (target != null) { 12 | this.radius = target.radius; 13 | } 14 | } 15 | 16 | @Override 17 | public Shape clone() { 18 | return new Circle(this); 19 | } 20 | 21 | @Override 22 | public boolean equals(Object object2) { 23 | if (!(object2 instanceof Circle) || !super.equals(object2)) return false; 24 | Circle shape2 = (Circle) object2; 25 | return shape2.radius == radius; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /concurrency/akka/akka-spring-boot/src/main/java/com/chriniko/example/akkaspringexample/message/Greet.java: -------------------------------------------------------------------------------- 1 | import akka.actor.ActorRef; 2 | 3 | public class Greet { 4 | 5 | private final String name; 6 | private final ActorRef sendTo; 7 | 8 | public Greet(String name, ActorRef sendTo) { 9 | this.name = name; 10 | this.sendTo = sendTo; 11 | } 12 | 13 | public String getName() { 14 | return name; 15 | } 16 | 17 | public ActorRef getSendTo() { 18 | return sendTo; 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return "Greet{" + 24 | "name='" + name + '\'' + 25 | ", sendTo=" + sendTo.path().name() + 26 | '}'; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /concurrency/basic/src/main/java/safety/lock/counter/ReadWriteLockCounter.java: -------------------------------------------------------------------------------- 1 | package safety.lock.counter; 2 | 3 | import java.util.concurrent.locks.ReadWriteLock; 4 | import java.util.concurrent.locks.ReentrantReadWriteLock; 5 | 6 | public class ReadWriteLockCounter 7 | { 8 | private int count; 9 | private final ReadWriteLock lock = new ReentrantReadWriteLock(); 10 | 11 | public void increment() 12 | { 13 | try 14 | { 15 | lock.writeLock().lock(); 16 | count++; 17 | } 18 | finally 19 | { 20 | lock.writeLock().unlock(); 21 | } 22 | } 23 | 24 | public int getCount() 25 | { 26 | try 27 | { 28 | lock.readLock().lock(); 29 | return count; 30 | } 31 | finally 32 | { 33 | lock.readLock().unlock(); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /design-patterns/strategy/example/strategies/CreditCard.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.strategy.example.strategies; 2 | 3 | /** 4 | * EN: Dummy credit card class. 5 | * 6 | * RU: Очень наивная реализация кредитной карты. 7 | */ 8 | public class CreditCard { 9 | private int amount; 10 | private String number; 11 | private String date; 12 | private String cvv; 13 | 14 | CreditCard(String number, String date, String cvv) { 15 | this.amount = 100_000; 16 | this.number = number; 17 | this.date = date; 18 | this.cvv = cvv; 19 | } 20 | 21 | public void setAmount(int amount) { 22 | this.amount = amount; 23 | } 24 | 25 | public int getAmount() { 26 | return amount; 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /design-patterns/mediator/example/mediator/Note.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.mediator.example.mediator; 2 | 3 | /** 4 | * EN: Note class. 5 | * 6 | * RU: Класс заметок. 7 | */ 8 | public class Note { 9 | private String name; 10 | private String text; 11 | 12 | public Note() { 13 | name = "New note"; 14 | } 15 | 16 | public void setName(String name) { 17 | this.name = name; 18 | } 19 | 20 | public void setText(String text) { 21 | this.text = text; 22 | } 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public String getText() { 29 | return text; 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return name; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /snippets/datastructure/string/StringReverse.java: -------------------------------------------------------------------------------- 1 | public class Main { 2 | 3 | public static void main(String[] args) { 4 | 5 |     String str1 = "reverse this string"; 6 | 7 |     Stack stack = new Stack<>(); 8 | 9 |     StringTokenizer strTok = new StringTokenizer(str1); 10 | 11 |     while(strTok.hasMoreTokens()){ 12 | 13 |         stack.push(strTok.nextElement()); 14 |     } 15 | 16 |     StringBuffer str1rev = new StringBuffer(); 17 | 18 |     while(!stack.empty()){ 19 | 20 |         str1rev.append(stack.pop()); 21 |         str1rev.append(" "); 22 | 23 | 24 |     } 25 | 26 |     System.out.println(str1rev); 27 | 28 | 29 | 30 | } 31 | } -------------------------------------------------------------------------------- /concurrency/basic/src/main/java/primitive/thread/ThreadRunnable.java: -------------------------------------------------------------------------------- 1 | package primitive.thread; 2 | 3 | class RunnerRunnable implements Runnable 4 | { 5 | 6 | @Override 7 | public void run() 8 | { 9 | for ( int i = 0; i < 5; i++ ) 10 | { 11 | System.out.println("Hello: " + i + " Thread: " + Thread.currentThread().getName()); 12 | 13 | try 14 | { 15 | Thread.sleep(100); 16 | } 17 | catch (InterruptedException e) 18 | { 19 | e.printStackTrace(); 20 | } 21 | } 22 | } 23 | } 24 | 25 | public class ThreadRunnable 26 | { 27 | public static void main(String[] args) 28 | { 29 | Thread thread1 = new Thread(new RunnerRunnable()); 30 | Thread thread2 = new Thread(new RunnerRunnable()); 31 | thread1.start(); 32 | thread2.start(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /concurrency/basic/src/main/java/safety/collection/boundedBlockingQueue/SyncBlockQueue.java: -------------------------------------------------------------------------------- 1 | package safety.collection.boundedBlockingQueue; 2 | 3 | /** 4 | * 5 | * thread safe 6 | * not handle enqueue finds a full array 7 | * not handle dequeue finds an empty array 8 | */ 9 | 10 | public class SyncBlockQueue 11 | { 12 | public static final int QSIZE = 10; 13 | 14 | // next slot to deque, empty slot position 15 | int head = 0, tail = 0; 16 | 17 | // array of T items 18 | int[] items = new int[QSIZE]; 19 | 20 | public void enq( int x ) 21 | { 22 | synchronized( this ) 23 | { 24 | items[(tail++) % QSIZE] = x; 25 | } 26 | } 27 | 28 | public int deq() 29 | { 30 | synchronized( this ) 31 | { 32 | return items[(head++) % QSIZE]; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /design-patterns/strategy/example/OutputDemo.txt: -------------------------------------------------------------------------------- 1 | Please, select a product: 2 | 1 - Mother board 3 | 2 - CPU 4 | 3 - HDD 5 | 4 - Memory 6 | 1 7 | Count: 2 8 | Do you wish to continue selecting products? Y/N: y 9 | Please, select a product: 10 | 1 - Mother board 11 | 2 - CPU 12 | 3 - HDD 13 | 4 - Memory 14 | 2 15 | Count: 1 16 | Do you wish to continue selecting products? Y/N: n 17 | Please, select a payment method: 18 | 1 - PalPay 19 | 2 - Credit Card 20 | 1 21 | Enter the user's email: user@example.com 22 | Enter the password: qwerty 23 | Wrong email or password! 24 | Enter user email: amanda@ya.com 25 | Enter password: amanda1985 26 | Data verification has been successful. 27 | Pay 6250 units or Continue shopping? P/C: p 28 | Paying 6250 using PayPal. 29 | Payment has been successful. 30 | -------------------------------------------------------------------------------- /snippets/io/IncrementalSyncSequential/code/src/main/java/com/alibaba/middleware/race/sync/utils/LongIntHashMap.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.middleware.race.sync.utils; 2 | 3 | import com.koloboke.collect.map.LongIntMap; 4 | import com.koloboke.compile.KolobokeMap; 5 | 6 | /** 7 | * Created by yfu on 6/23/17. 8 | */ 9 | public abstract class LongIntHashMap implements LongIntMap { 10 | public static LongIntHashMap withExpectedSize(int expectedSize) { 11 | return new KolobokeLongIntHashMap(expectedSize); 12 | } 13 | 14 | public abstract int get(long key); 15 | 16 | public abstract int put(long key, int value); 17 | 18 | public abstract int remove(long key); 19 | 20 | @Override 21 | public final int defaultValue() { 22 | return -1; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /snippets/io/FileIO-MOM/code_klosefu/src/main/java/io/openmessaging/demo/ClientOMSException.java: -------------------------------------------------------------------------------- 1 | package io.openmessaging.demo; 2 | 3 | import io.openmessaging.exception.OMSException; 4 | import io.openmessaging.exception.OMSResourceNotExistException; 5 | import io.openmessaging.exception.OMSRuntimeException; 6 | 7 | public class ClientOMSException extends OMSRuntimeException { 8 | 9 | public String message; 10 | public ClientOMSException(String message) { 11 | this.message = message; 12 | } 13 | public ClientOMSException(String message, Throwable throwable) { 14 | this.initCause(throwable); 15 | this.message = message; 16 | } 17 | 18 | @Override 19 | public String getMessage() { 20 | return message; 21 | } 22 | 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /snippets/io/FileIO-MOM/code_xy7620/src/main/java/io/openmessaging/demo/ClientOMSException.java: -------------------------------------------------------------------------------- 1 | package io.openmessaging.demo; 2 | 3 | import io.openmessaging.exception.OMSException; 4 | import io.openmessaging.exception.OMSResourceNotExistException; 5 | import io.openmessaging.exception.OMSRuntimeException; 6 | 7 | public class ClientOMSException extends OMSRuntimeException { 8 | 9 | public String message; 10 | public ClientOMSException(String message) { 11 | this.message = message; 12 | } 13 | public ClientOMSException(String message, Throwable throwable) { 14 | this.initCause(throwable); 15 | this.message = message; 16 | } 17 | 18 | @Override 19 | public String getMessage() { 20 | return message; 21 | } 22 | 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /design-patterns/builder/example/components/TripComputer.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.builder.example.components; 2 | 3 | import refactoring_guru.builder.example.cars.Car; 4 | 5 | /** 6 | * EN: Just another feature of a car. 7 | * 8 | * RU: Одна из фишек автомобиля. 9 | */ 10 | public class TripComputer { 11 | 12 | private Car car; 13 | 14 | public void setCar(Car car) { 15 | this.car = car; 16 | } 17 | 18 | public void showFuelLevel() { 19 | System.out.println("Fuel level: " + car.getFuel()); 20 | } 21 | 22 | public void showStatus() { 23 | if (this.car.getEngine().isStarted()) { 24 | System.out.println("Car is started"); 25 | } else { 26 | System.out.println("Car isn't started"); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /boilerplates/gradle/.gitignore: -------------------------------------------------------------------------------- 1 | # Java 2 | 3 | # Compiled class file 4 | *.class 5 | 6 | # Log file 7 | *.log 8 | 9 | # BlueJ files 10 | *.ctxt 11 | 12 | # Mobile Tools for Java (J2ME) 13 | .mtj.tmp/ 14 | 15 | # Package Files # 16 | *.jar 17 | *.war 18 | *.ear 19 | *.zip 20 | *.tar.gz 21 | *.rar 22 | 23 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 24 | hs_err_pid* 25 | 26 | # Gradle 27 | 28 | .gradle 29 | /build/ 30 | 31 | # Ignore Gradle GUI config 32 | gradle-app.setting 33 | 34 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 35 | !gradle-wrapper.jar 36 | 37 | # Cache of project 38 | .gradletasknamecache 39 | 40 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 41 | # gradle/wrapper/gradle-wrapper.properties -------------------------------------------------------------------------------- /concurrency/akka/akka-cluster/src/main/resources/factorial.conf: -------------------------------------------------------------------------------- 1 | include "application" 2 | 3 | akka.cluster.min-nr-of-members = 3 4 | 5 | akka.cluster.role { 6 | frontend.min-nr-of-members = 1 7 | backend.min-nr-of-members = 2 8 | } 9 | 10 | akka.actor.deployment { 11 | /factorialFrontend/factorialBackendRouter = { 12 | # Router type provided by metrics extension. 13 | router = cluster-metrics-adaptive-group 14 | # Router parameter specific for metrics extension. 15 | # metrics-selector = heap 16 | # metrics-selector = load 17 | # metrics-selector = cpu 18 | metrics-selector = mix 19 | # 20 | routees.paths = ["/user/factorialBackend"] 21 | cluster { 22 | enabled = on 23 | use-role = backend 24 | allow-local-routees = off 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /design-patterns/memento/example/shapes/Rectangle.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.memento.example.shapes; 2 | 3 | import java.awt.*; 4 | 5 | public class Rectangle extends BaseShape { 6 | private int width; 7 | private int height; 8 | 9 | public Rectangle(int x, int y, int width, int height, Color color) { 10 | super(x, y, color); 11 | this.width = width; 12 | this.height = height; 13 | } 14 | 15 | @Override 16 | public int getWidth() { 17 | return width; 18 | } 19 | 20 | @Override 21 | public int getHeight() { 22 | return height; 23 | } 24 | 25 | @Override 26 | public void paint(Graphics graphics) { 27 | super.paint(graphics); 28 | graphics.drawRect(x, y, getWidth() - 1, getHeight() - 1); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /design-patterns/observer/example/editor/Editor.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.observer.example.editor; 2 | 3 | import refactoring_guru.observer.example.publisher.EventManager; 4 | 5 | import java.io.File; 6 | 7 | public class Editor { 8 | public EventManager events; 9 | private File file; 10 | 11 | public Editor() { 12 | this.events = new EventManager("open", "save"); 13 | } 14 | 15 | public void openFile(String filePath) { 16 | this.file = new File(filePath); 17 | events.notify("open", file); 18 | } 19 | 20 | public void saveFile() throws Exception { 21 | if (this.file != null) { 22 | events.notify("save", file); 23 | } else { 24 | throw new Exception("Please open a file first."); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /design-patterns/composite/example/shapes/Rectangle.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.composite.example.shapes; 2 | 3 | import java.awt.*; 4 | 5 | public class Rectangle extends BaseShape { 6 | public int width; 7 | public int height; 8 | 9 | public Rectangle(int x, int y, int width, int height, Color color) { 10 | super(x, y, color); 11 | this.width = width; 12 | this.height = height; 13 | } 14 | 15 | @Override 16 | public int getWidth() { 17 | return width; 18 | } 19 | 20 | @Override 21 | public int getHeight() { 22 | return height; 23 | } 24 | 25 | @Override 26 | public void paint(Graphics graphics) { 27 | super.paint(graphics); 28 | graphics.drawRect(x, y, getWidth() - 1, getHeight() - 1); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /design-patterns/observer/example/Demo.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.observer.example; 2 | 3 | import refactoring_guru.observer.example.editor.Editor; 4 | import refactoring_guru.observer.example.listeners.EmailNotificationListener; 5 | import refactoring_guru.observer.example.listeners.LogOpenListener; 6 | 7 | public class Demo { 8 | public static void main(String[] args) { 9 | Editor editor = new Editor(); 10 | editor.events.subscribe("open", new LogOpenListener("/path/to/log/file.txt")); 11 | editor.events.subscribe("save", new EmailNotificationListener("admin@example.com")); 12 | 13 | try { 14 | editor.openFile("test.txt"); 15 | editor.saveFile(); 16 | } catch (Exception e) { 17 | e.printStackTrace(); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /snippets/io/FileIO-MOM/code_xy7620/src/main/java/io/openmessaging/demo/ExcuteTester.java: -------------------------------------------------------------------------------- 1 | package io.openmessaging.demo; 2 | 3 | /** 4 | * @author XF 5 | * 调用官方的两个测试例修改版,直接执行用控制台日志查看结果 6 | */ 7 | public class ExcuteTester { 8 | 9 | public static void main(String[] args) throws Exception { 10 | //不能循环执行,没有清空内存 11 | // for(int i=0; i<10; i++){ 12 | ProducerTester.main(args); 13 | // Thread.sleep(5000); 14 | ConsumerTester.main(args); 15 | // Thread.sleep(1000); 16 | // } 17 | // byte[] bs = "asdfsa_SDFSF".getBytes(); 18 | // System.out.println(new String(bs,0,9)); 19 | // System.out.println("ab".getBytes()[0]); 20 | // System.out.println(Arrays.toString("a;b".getBytes())); 21 | // System.out.println((int)'a'); 22 | // int i=0; 23 | // i++; 24 | // System.out.println(++i==1); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /snippets/io/FileIO-MOM/code_xy7620/src/main/java/io/openmessaging/v5/V5ExcuteTester.java: -------------------------------------------------------------------------------- 1 | package io.openmessaging.v5; 2 | 3 | /** 4 | * @author XF 5 | * 调用官方的两个测试例修改版,直接执行用控制台日志查看结果 6 | */ 7 | public class V5ExcuteTester { 8 | 9 | public static void main(String[] args) throws Exception { 10 | //不能循环执行,没有清空内存 11 | // for(int i=0; i<10; i++){ 12 | V5ProducerTester.main(args); 13 | // Thread.sleep(5000); 14 | V5ConsumerTester.main(args); 15 | // Thread.sleep(1000); 16 | // } 17 | // byte[] bs = "asdfsa_SDFSF".getBytes(); 18 | // System.out.println(new String(bs,0,9)); 19 | // System.out.println("ab".getBytes()[0]); 20 | // System.out.println(Arrays.toString("a;b".getBytes())); 21 | // System.out.println((int)'a'); 22 | // int i=0; 23 | // i++; 24 | // System.out.println(++i==1); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /snippets/io/FileIO-MOM/code_xy7620/src/main/java/io/openmessaging/v6/V6ExcuteTester.java: -------------------------------------------------------------------------------- 1 | package io.openmessaging.v6; 2 | 3 | /** 4 | * @author XF 5 | * 调用官方的两个测试例修改版,直接执行用控制台日志查看结果 6 | */ 7 | public class V6ExcuteTester { 8 | 9 | public static void main(String[] args) throws Exception { 10 | //不能循环执行,没有清空内存 11 | // for(int i=0; i<10; i++){ 12 | V6ProducerTester.main(args); 13 | // Thread.sleep(5000); 14 | V6ConsumerTester.main(args); 15 | // Thread.sleep(1000); 16 | // } 17 | // byte[] bs = "asdfsa_SDFSF".getBytes(); 18 | // System.out.println(new String(bs,0,9)); 19 | // System.out.println("ab".getBytes()[0]); 20 | // System.out.println(Arrays.toString("a;b".getBytes())); 21 | // System.out.println((int)'a'); 22 | // int i=0; 23 | // i++; 24 | // System.out.println(++i==1); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /snippets/io/FileIO-MOM/code_xy7620/src/main/java/io/openmessaging/v7/V7ExcuteTester.java: -------------------------------------------------------------------------------- 1 | package io.openmessaging.v7; 2 | 3 | /** 4 | * @author XF 5 | * 调用官方的两个测试例修改版,直接执行用控制台日志查看结果 6 | */ 7 | public class V7ExcuteTester { 8 | 9 | public static void main(String[] args) throws Exception { 10 | //不能循环执行,没有清空内存 11 | // for(int i=0; i<10; i++){ 12 | V7ProducerTester.main(args); 13 | // Thread.sleep(5000); 14 | V7ConsumerTester.main(args); 15 | // Thread.sleep(1000); 16 | // } 17 | // byte[] bs = "asdfsa_SDFSF".getBytes(); 18 | // System.out.println(new String(bs,0,9)); 19 | // System.out.println("ab".getBytes()[0]); 20 | // System.out.println(Arrays.toString("a;b".getBytes())); 21 | // System.out.println((int)'a'); 22 | // int i=0; 23 | // i++; 24 | // System.out.println(++i==1); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /snippets/io/IncrementalSyncSequential/code/src/main/java/com/alibaba/middleware/race/sync/server/Task.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.middleware.race.sync.server; 2 | 3 | /** 4 | * Task 5 | * 6 | * Created by yfu on 6/28/17. 7 | */ 8 | final class Task { 9 | static final byte TASK_INSERT = 0; 10 | static final byte TASK_UPDATE = 1; 11 | static final byte TASK_UPDATE_PK_SRC = 2; 12 | static final byte TASK_UPDATE_PK_DST = 3; 13 | static final byte TASK_DELETE = 4; 14 | 15 | final byte opcode; 16 | final long key; 17 | final int promise; 18 | 19 | final int data; 20 | 21 | public Task(byte opcode, long key, int promise, int data) { 22 | this.opcode = opcode; 23 | this.key = key; 24 | this.promise = promise; 25 | this.data = data; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /snippets/io/TopKN/src/main/java/com/alibaba/middleware/topkn/worker/FileSegment.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.middleware.topkn.worker; 2 | 3 | import java.io.File; 4 | 5 | /** 6 | * 7 | * 8 | * Created by yfu on 7/15/17. 9 | */ 10 | public class FileSegment { 11 | 12 | private final File file; 13 | private final long offset; 14 | private final long nextOffset; 15 | 16 | public FileSegment(File file, long offset, long nextOffset) { 17 | this.file = file; 18 | this.offset = offset; 19 | this.nextOffset = nextOffset; 20 | } 21 | 22 | public File getFile() { 23 | return file; 24 | } 25 | 26 | public long getOffset() { 27 | return offset; 28 | } 29 | 30 | public long getNextOffset() { 31 | return nextOffset; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /boilerplates/maven-app/src/main/java/com/example/app/AppDriver.java: -------------------------------------------------------------------------------- 1 | package com.example.app; 2 | 3 | import com.example.lib.MyClass; 4 | 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | /** 9 | * App driver. 10 | * 11 | * @author Myself 12 | */ 13 | public final class AppDriver { 14 | 15 | /** The logger for this class. */ 16 | private static final Logger logger = LoggerFactory.getLogger(AppDriver.class); 17 | 18 | /** 19 | * Private Constructor. 20 | */ 21 | private AppDriver() { 22 | } 23 | 24 | /** 25 | * Main method. 26 | * 27 | * @param args Command line arguments 28 | */ 29 | public static void main(final String[] args) { 30 | logger.info("hello info"); 31 | 32 | MyClass klass = new MyClass(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /concurrency/akka/akka-mqtt/build.sbt: -------------------------------------------------------------------------------- 1 | name := "akka-iot-mqtt" 2 | 3 | version := "0.1" 4 | 5 | scalaVersion := "2.11.11" 6 | lazy val akkaVersion = "2.4.19" 7 | 8 | fork in Test := true 9 | 10 | resolvers += Resolver.jcenterRepo 11 | 12 | libraryDependencies ++= Seq( 13 | "org.eclipse.paho" % "org.eclipse.paho.client.mqttv3" % "1.0.2", 14 | "com.sandinh" % "paho-akka_2.11" % "1.2.0", 15 | "org.slf4j" % "slf4j-api" % "1.7.21", 16 | "ch.qos.logback" % "logback-classic" % "1.1.3", 17 | "com.typesafe.akka" %% "akka-cluster" % akkaVersion, 18 | "com.typesafe.akka" %% "akka-cluster-tools" % akkaVersion, 19 | "com.typesafe.akka" %% "akka-persistence" % akkaVersion, 20 | "com.github.etaty" %% "rediscala" % "1.6.0", 21 | "com.hootsuite" %% "akka-persistence-redis" % "0.6.0") 22 | 23 | 24 | fork in run := true 25 | -------------------------------------------------------------------------------- /design-patterns/memento/example/commands/ColorCommand.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.memento.example.commands; 2 | 3 | import refactoring_guru.memento.example.editor.Editor; 4 | import refactoring_guru.memento.example.shapes.Shape; 5 | 6 | import java.awt.*; 7 | 8 | public class ColorCommand implements Command { 9 | private Editor editor; 10 | private Color color; 11 | 12 | public ColorCommand(Editor editor, Color color) { 13 | this.editor = editor; 14 | this.color = color; 15 | } 16 | 17 | @Override 18 | public String getName() { 19 | return "Colorize: " + color.toString(); 20 | } 21 | 22 | @Override 23 | public void execute() { 24 | for (Shape child : editor.getShapes().getSelected()) { 25 | child.setColor(color); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /design-patterns/prototype/example/shapes/Shape.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.prototype.example.shapes; 2 | 3 | import java.util.Objects; 4 | 5 | public abstract class Shape { 6 | public int x; 7 | public int y; 8 | public String color; 9 | 10 | public Shape() { 11 | } 12 | 13 | public Shape(Shape target) { 14 | if (target != null) { 15 | this.x = target.x; 16 | this.y = target.y; 17 | this.color = target.color; 18 | } 19 | } 20 | 21 | public abstract Shape clone(); 22 | 23 | @Override 24 | public boolean equals(Object object2) { 25 | if (!(object2 instanceof Shape)) return false; 26 | Shape shape2 = (Shape) object2; 27 | return shape2.x == x && shape2.y == y && Objects.equals(shape2.color, color); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /design-patterns/singleton/example/non_thread_safe/Singleton.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.singleton.example.non_thread_safe; 2 | 3 | public final class Singleton { 4 | private static Singleton instance; 5 | public String value; 6 | 7 | private Singleton(String value) { 8 | // EN: Following code emulates slow initialization. 9 | // 10 | // RU: Этот код эмулирует медленную инициализацию. 11 | try { 12 | Thread.sleep(1000); 13 | } catch (InterruptedException ex) { 14 | ex.printStackTrace(); 15 | } 16 | this.value = value; 17 | } 18 | 19 | public static Singleton getInstance(String value) { 20 | if (instance == null) { 21 | instance = new Singleton(value); 22 | } 23 | return instance; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /concurrency/akka/akka-start/src/main/java/sample/hello/HelloWorld.java: -------------------------------------------------------------------------------- 1 | import akka.actor.AbstractActor; 2 | import akka.actor.ActorRef; 3 | import akka.actor.Props; 4 | 5 | import static Greeter.Msg; 6 | 7 | public class HelloWorld extends AbstractActor { 8 | 9 | @Override 10 | public Receive createReceive() { 11 | return receiveBuilder() 12 | .matchEquals(Msg.DONE, m -> { 13 | // when the greeter is done, stop this actor and with it the application 14 | getContext().stop(self()); 15 | }) 16 | .build(); 17 | } 18 | 19 | @Override 20 | public void preStart() { 21 | // create the greeter actor 22 | final ActorRef greeter = getContext().actorOf(Props.create(Greeter.class), "greeter"); 23 | // tell it to perform the greeting 24 | greeter.tell(Msg.GREET, self()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /concurrency/akka/akka-persistence-dc/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %d{HH:mm:ss.SSS} %-5level [%logger{36}] [%X{sourceThread}] - %msg%n 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /snippets/io/FileIO-MOM/code_xy7620/src/main/java/io/openmessaging/v4/V4ExcuteTester.java: -------------------------------------------------------------------------------- 1 | package io.openmessaging.v4; 2 | 3 | import java.util.Arrays; 4 | 5 | /** 6 | * @author XF 7 | * 调用官方的两个测试例修改版,直接执行用控制台日志查看结果 8 | */ 9 | public class V4ExcuteTester { 10 | 11 | public static void main(String[] args) throws Exception { 12 | //不能循环执行,没有清空内存 13 | // for(int i=0; i<1; i++){ 14 | V4ProducerTester.main(args); 15 | // Thread.sleep(5000); 16 | V4ConsumerTester.main(args); 17 | // Thread.sleep(1000); 18 | // } 19 | // byte[] bs = "asdfsa_SDFSF".getBytes(); 20 | // System.out.println(new String(bs,0,9)); 21 | // System.out.println("ab".getBytes()[0]); 22 | // System.out.println(Arrays.toString("a;b".getBytes())); 23 | // System.out.println((int)'a'); 24 | // int i=0; 25 | // i++; 26 | // System.out.println(++i==1); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /algorithms/snippets/scheduler/hashed_wheel_timer/BooleanSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Dmitry Spikhalskiy. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package scheduler.hashed_wheel_timer; 17 | 18 | interface BooleanSupplier { 19 | boolean getAsBoolean(); 20 | } -------------------------------------------------------------------------------- /design-patterns/adapter/example/square/SquarePeg.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.adapter.example.square; 2 | 3 | /** 4 | * EN: SquarePegs are not compatible with RoundHoles (they were implemented by 5 | * previous development team). But we have to integrate them into our program. 6 | * 7 | * RU: КвадратныеКолышки несовместимы с КруглымиОтверстиями (они остались в 8 | * проекте после бывших разработчиков). Но мы должны как-то интегрировать их в 9 | * нашу систему. 10 | */ 11 | public class SquarePeg { 12 | private double width; 13 | 14 | public SquarePeg(double width) { 15 | this.width = width; 16 | } 17 | 18 | public double getWidth() { 19 | return width; 20 | } 21 | 22 | public double getSquare() { 23 | double result; 24 | result = Math.pow(this.width, 2); 25 | return result; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /snippets/io/FileIO-MOM/code_xy7620/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /snippets/io/FileIO-MOM/code_xy7620/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | io.openmessaging 5 | open-messaging-demo 6 | war 7 | 0.0.1-SNAPSHOT 8 | open-messaging-demo Maven Webapp 9 | http://maven.apache.org 10 | 11 | 12 | junit 13 | junit 14 | 3.8.1 15 | test 16 | 17 | 18 | 19 | open-messaging-demo 20 | 21 | 22 | -------------------------------------------------------------------------------- /design-patterns/prototype/example/shapes/Rectangle.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.prototype.example.shapes; 2 | 3 | public class Rectangle extends Shape { 4 | public int width; 5 | public int height; 6 | 7 | public Rectangle() { 8 | } 9 | 10 | public Rectangle(Rectangle target) { 11 | super(target); 12 | if (target != null) { 13 | this.width = target.width; 14 | this.height = target.height; 15 | } 16 | } 17 | 18 | @Override 19 | public Shape clone() { 20 | return new Rectangle(this); 21 | } 22 | 23 | @Override 24 | public boolean equals(Object object2) { 25 | if (!(object2 instanceof Rectangle) || !super.equals(object2)) return false; 26 | Rectangle shape2 = (Rectangle) object2; 27 | return shape2.width == width && shape2.height == height; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /design-patterns/state/example/states/PlayingState.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.state.example.states; 2 | 3 | import refactoring_guru.state.example.ui.Player; 4 | 5 | public class PlayingState extends State { 6 | 7 | PlayingState(Player player) { 8 | super(player); 9 | } 10 | 11 | @Override 12 | public String onLock() { 13 | player.changeState(new LockedState(player)); 14 | player.setCurrentTrackAfterStop(); 15 | return "Stop playing"; 16 | } 17 | 18 | @Override 19 | public String onPlay() { 20 | player.changeState(new ReadyState(player)); 21 | return "Paused..."; 22 | } 23 | 24 | @Override 25 | public String onNext() { 26 | return player.nextTrack(); 27 | } 28 | 29 | @Override 30 | public String onPrevious() { 31 | return player.previousTrack(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /algorithms/snippets/string/match_droid/src/nju/iip/kevin/ac/Queue.java: -------------------------------------------------------------------------------- 1 | package nju.iip.kevin.ac; 2 | 3 | import java.util.ArrayList; 4 | 5 | /** 6 | * Quick-and-dirty queue class. Essentially uses two lists to represent a queue. 7 | * first come in, first come out 8 | */ 9 | class Queue { 10 | ArrayList l1; 11 | ArrayList l2; 12 | 13 | public Queue() { 14 | l1 = new ArrayList(); 15 | l2 = new ArrayList(); 16 | } 17 | 18 | public void add(State s) { 19 | l2.add(s); 20 | } 21 | 22 | public boolean isEmpty() { 23 | return l1.isEmpty() && l2.isEmpty(); 24 | } 25 | 26 | public State pop() { 27 | if (isEmpty()) 28 | throw new IllegalStateException(); 29 | if (l1.isEmpty()) { 30 | for (int i = l2.size() - 1; i >= 0; i--) 31 | l1.add(l2.remove(i)); 32 | assert l2.isEmpty(); 33 | assert !l1.isEmpty(); 34 | } 35 | return (State) l1.remove(l1.size() - 1); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /algorithms/snippets/string/match_droid/src/nju/iip/kevin/ac/Searcher.java: -------------------------------------------------------------------------------- 1 | package nju.iip.kevin.ac; 2 | 3 | import java.util.Iterator; 4 | import java.util.NoSuchElementException; 5 | 6 | /** 7 | * Iterator returns a list of Search matches. 8 | */ 9 | class Searcher implements Iterator { 10 | private SearchResult currentResult; 11 | private AhoCorasick tree; 12 | 13 | public Searcher(AhoCorasick tree, SearchResult result) { 14 | this.tree = tree; 15 | this.currentResult = result; 16 | } 17 | 18 | public boolean hasNext() { 19 | return (this.currentResult != null); 20 | } 21 | 22 | public Object next() { 23 | if (!hasNext()) 24 | throw new NoSuchElementException(); 25 | Object result = currentResult; 26 | currentResult = tree.continueSearch(currentResult); 27 | return result; 28 | } 29 | 30 | public void remove() { 31 | throw new UnsupportedOperationException(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /design-patterns/visitor/example/OutputDemo.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 2 4 | 23 5 | 15 6 | 10 7 | 8 | 9 | 10 | 11 | 4 12 | 13 | 1 14 | 10 15 | 55 16 | 17 | 18 | 2 19 | 23 20 | 15 21 | 10 22 | 23 | 24 | 3 25 | 10 26 | 17 27 | 20 28 | 30 29 | 30 | 31 | 5 32 | 33 | 1 34 | 10 35 | 55 36 | 37 | 38 | -------------------------------------------------------------------------------- /snippets/io/FileIO-MOM/code_klosefu/src/main/java/io/openmessaging/tester/Constants.java: -------------------------------------------------------------------------------- 1 | package io.openmessaging.tester; 2 | 3 | public class Constants { 4 | 5 | public final static String STORE_PATH = System.getProperty("store.path", "./tmp"); 6 | public final static int PRO_NUM = Integer.valueOf(System.getProperty("pro.num", "10")); 7 | public final static int CON_NUM = Integer.valueOf(System.getProperty("con.num", "10")); 8 | public final static String PRO_PRE = System.getProperty("pro.pre","PRODUCER_"); 9 | public final static int PRO_MAX = Integer.valueOf(System.getProperty("pro.max","10000000")); 10 | public final static String CON_PRE = System.getProperty("con.pre", "CONSUMER_"); 11 | public final static String TOPIC_PRE = System.getProperty("topic.pre", "TOPIC_"); 12 | public final static String QUEUE_PRE = System.getProperty("topic.pre", "QUEUE_"); 13 | 14 | 15 | } 16 | -------------------------------------------------------------------------------- /snippets/io/FileIO-MOM/code_klosefu/src/main/resources/package.xml: -------------------------------------------------------------------------------- 1 | 5 | package 6 | 7 | dir 8 | 9 | true 10 | 11 | 12 | src/main/resources 13 | conf 14 | false 15 | 16 | 17 | 18 | 19 | lib 20 | runtime 21 | 22 | 23 | -------------------------------------------------------------------------------- /snippets/io/FileIO-MOM/code_xy7620/src/main/java/io/openmessaging/tester/ExcuteTester.java: -------------------------------------------------------------------------------- 1 | package io.openmessaging.tester; 2 | 3 | import java.util.Arrays; 4 | 5 | import io.openmessaging.v5.V5ProducerTester; 6 | 7 | /** 8 | * @author XF 9 | * 调用官方的两个测试例修改版,直接执行用控制台日志查看结果 10 | */ 11 | public class ExcuteTester { 12 | 13 | public static void main(String[] args) throws Exception { 14 | //不能循环执行,没有清空内存 15 | // for(int i=0; i<10; i++){ 16 | V5ProducerTester.main(args); 17 | // Thread.sleep(5000); 18 | ConsumerTester.main(args); 19 | // Thread.sleep(1000); 20 | // } 21 | // byte[] bs = "asdfsa_SDFSF".getBytes(); 22 | // System.out.println(new String(bs,0,9)); 23 | // System.out.println("ab".getBytes()[0]); 24 | // System.out.println(Arrays.toString("a;b".getBytes())); 25 | // System.out.println((int)'a'); 26 | // int i=0; 27 | // i++; 28 | // System.out.println(++i==1); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /boilerplates/maven-app/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 20 | 21 | -------------------------------------------------------------------------------- /concurrency/akka/akka-spring/src/main/java/org/baeldung/akka/AppConfiguration.java: -------------------------------------------------------------------------------- 1 | import akka.actor.ActorSystem; 2 | import org.springframework.beans.factory.annotation.Autowired; 3 | import org.springframework.context.ApplicationContext; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.ComponentScan; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | import static SpringExtension.SPRING_EXTENSION_PROVIDER; 9 | 10 | @Configuration 11 | @ComponentScan 12 | public class AppConfiguration { 13 | 14 | @Autowired 15 | private ApplicationContext applicationContext; 16 | 17 | @Bean 18 | public ActorSystem actorSystem() { 19 | ActorSystem system = ActorSystem.create("akka-spring-demo"); 20 | SPRING_EXTENSION_PROVIDER.get(system).initialize(applicationContext); 21 | return system; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /concurrency/akka/akka-http/src/main/java/com/baeldung/akkahttp/UserService.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.List; 3 | import java.util.Optional; 4 | 5 | public class UserService { 6 | 7 | private final static List users = new ArrayList<>(); 8 | 9 | static { 10 | users.add(new User(1l, "Alice")); 11 | users.add(new User(2l, "Bob")); 12 | users.add(new User(3l, "Chris")); 13 | users.add(new User(4l, "Dick")); 14 | users.add(new User(5l, "Eve")); 15 | users.add(new User(6l, "Finn")); 16 | } 17 | 18 | public Optional getUser(Long id) { 19 | return users.stream() 20 | .filter(user -> user.getId() 21 | .equals(id)) 22 | .findFirst(); 23 | } 24 | 25 | public void createUser(User user) { 26 | users.add(user); 27 | } 28 | 29 | public List getUsers(){ 30 | return users; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /snippets/io/IncrementalSyncSequential/code/src/main/java/com/alibaba/middleware/race/sync/server/Result.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.middleware.race.sync.server; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Queue; 5 | 6 | /** 7 | * One result in queried range 8 | *

9 | * Created by yfu on 6/17/17. 10 | */ 11 | final class Result implements Comparable { 12 | 13 | static final Result DONE = new Result(-1, null, -1, -1); 14 | 15 | private final long key; 16 | 17 | final byte[] buffer; 18 | final int offset; 19 | final int length; 20 | 21 | public Result(long key, byte[] buffer, int offset, int length) { 22 | this.key = key; 23 | this.buffer = buffer; 24 | this.offset = offset; 25 | this.length = length; 26 | } 27 | 28 | @Override 29 | public int compareTo(Result o) { 30 | return Long.signum(key - o.key); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /design-patterns/state/example/states/State.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.state.example.states; 2 | 3 | import refactoring_guru.state.example.ui.Player; 4 | 5 | /** 6 | * EN: Common interface for all states. 7 | * 8 | * RU: Общий интерфейс всех состояний. 9 | */ 10 | public abstract class State { 11 | Player player; 12 | 13 | /** 14 | * EN: Context passes itself through the state constructor. This may help a 15 | * state to fetch some useful context data if needed. 16 | * 17 | * RU: Контекст передаёт себя в конструктор состояния, чтобы состояние могло 18 | * обращаться к его данным и методам в будущем, если потребуется. 19 | */ 20 | State(Player player) { 21 | this.player = player; 22 | } 23 | 24 | public abstract String onLock(); 25 | public abstract String onPlay(); 26 | public abstract String onNext(); 27 | public abstract String onPrevious(); 28 | } 29 | -------------------------------------------------------------------------------- /concurrency/akka/akka-spring/src/main/java/org/baeldung/akka/SpringActorProducer.java: -------------------------------------------------------------------------------- 1 | import akka.actor.Actor; 2 | import akka.actor.IndirectActorProducer; 3 | import org.springframework.context.ApplicationContext; 4 | 5 | public class SpringActorProducer implements IndirectActorProducer { 6 | 7 | private ApplicationContext applicationContext; 8 | 9 | private String beanActorName; 10 | 11 | public SpringActorProducer(ApplicationContext applicationContext, String beanActorName) { 12 | this.applicationContext = applicationContext; 13 | this.beanActorName = beanActorName; 14 | } 15 | 16 | @Override 17 | public Actor produce() { 18 | return (Actor) applicationContext.getBean(beanActorName); 19 | } 20 | 21 | @Override 22 | public Class actorClass() { 23 | return (Class) applicationContext.getType(beanActorName); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /design-patterns/flyweight/example/forest/Forest.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.flyweight.example.forest; 2 | 3 | import refactoring_guru.flyweight.example.trees.Tree; 4 | import refactoring_guru.flyweight.example.trees.TreeFactory; 5 | import refactoring_guru.flyweight.example.trees.TreeType; 6 | 7 | import javax.swing.*; 8 | import java.awt.*; 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | public class Forest extends JFrame { 13 | private List trees = new ArrayList<>(); 14 | 15 | public void plantTree(int x, int y, String name, Color color, String otherTreeData) { 16 | TreeType type = TreeFactory.getTreeType(name, color, otherTreeData); 17 | Tree tree = new Tree(x, y, type); 18 | trees.add(tree); 19 | } 20 | 21 | @Override 22 | public void paint(Graphics graphics) { 23 | for (Tree tree : trees) { 24 | tree.draw(graphics); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /design-patterns/visitor/example/shapes/CompoundShape.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.visitor.example.shapes; 2 | 3 | import refactoring_guru.visitor.example.visitor.Visitor; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | public class CompoundShape implements Shape { 9 | public int id; 10 | public List children = new ArrayList<>(); 11 | 12 | public CompoundShape(int id) { 13 | this.id = id; 14 | } 15 | 16 | @Override 17 | public void move(int x, int y) { 18 | // move shape 19 | } 20 | 21 | @Override 22 | public void draw() { 23 | // draw shape 24 | } 25 | 26 | public int getId() { 27 | return id; 28 | } 29 | 30 | @Override 31 | public String accept(Visitor visitor) { 32 | return visitor.visitCompoundGraphic(this); 33 | } 34 | 35 | public void add(Shape shape) { 36 | children.add(shape); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /snippets/io/FileIO-MOM/code_klosefu/src/main/java/io/openmessaging/demo/DefaultMessageFactory.java: -------------------------------------------------------------------------------- 1 | package io.openmessaging.demo; 2 | 3 | import io.openmessaging.BytesMessage; 4 | import io.openmessaging.MessageFactory; 5 | import io.openmessaging.MessageHeader; 6 | 7 | public class DefaultMessageFactory implements MessageFactory { 8 | 9 | @Override public BytesMessage createBytesMessageToTopic(String topic, byte[] body) { 10 | DefaultBytesMessage defaultBytesMessage = new DefaultBytesMessage(body); 11 | defaultBytesMessage.putHeaders(MessageHeader.TOPIC, topic); 12 | return defaultBytesMessage; 13 | } 14 | 15 | @Override public BytesMessage createBytesMessageToQueue(String queue, byte[] body) { 16 | DefaultBytesMessage defaultBytesMessage = new DefaultBytesMessage(body); 17 | defaultBytesMessage.putHeaders(MessageHeader.QUEUE, queue); 18 | return defaultBytesMessage; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /design-patterns/abstract_factory/example/factories/MacOSFactory.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.abstract_factory.example.factories; 2 | 3 | import refactoring_guru.abstract_factory.example.buttons.Button; 4 | import refactoring_guru.abstract_factory.example.buttons.MacOSButton; 5 | import refactoring_guru.abstract_factory.example.checkboxes.Checkbox; 6 | import refactoring_guru.abstract_factory.example.checkboxes.MacOSCheckbox; 7 | 8 | /** 9 | * EN: Each concrete factory extends basic factory and responsible for creating 10 | * products of a single variety. 11 | * 12 | * RU: Каждая конкретная фабрика знает и создаёт только продукты своей вариации. 13 | */ 14 | public class MacOSFactory implements GUIFactory { 15 | 16 | @Override 17 | public Button createButton() { 18 | return new MacOSButton(); 19 | } 20 | 21 | @Override 22 | public Checkbox createCheckbox() { 23 | return new MacOSCheckbox(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /design-patterns/builder/example/builders/Builder.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.builder.example.builders; 2 | 3 | import refactoring_guru.builder.example.cars.Type; 4 | import refactoring_guru.builder.example.components.Engine; 5 | import refactoring_guru.builder.example.components.GPSNavigator; 6 | import refactoring_guru.builder.example.components.Transmission; 7 | import refactoring_guru.builder.example.components.TripComputer; 8 | 9 | /** 10 | * EN: Builder interface defines all possible ways to configure a product. 11 | * 12 | * RU: Интерфейс Строителя объявляет все возможные этапы и шаги конфигурации 13 | * продукта. 14 | */ 15 | public interface Builder { 16 | void setType(Type type); 17 | void setSeats(int seats); 18 | void setEngine(Engine engine); 19 | void setTransmission(Transmission transmission); 20 | void setTripComputer(TripComputer tripComputer); 21 | void setGPSNavigator(GPSNavigator gpsNavigator); 22 | } 23 | -------------------------------------------------------------------------------- /design-patterns/command/example/commands/CutCommand.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.command.example.commands; 2 | 3 | import refactoring_guru.command.example.editor.Editor; 4 | 5 | public class CutCommand extends Command { 6 | 7 | public CutCommand(Editor editor) { 8 | super(editor); 9 | } 10 | 11 | @Override 12 | public boolean execute() { 13 | if (editor.textField.getSelectedText().isEmpty()) return false; 14 | 15 | backup(); 16 | String source = editor.textField.getText(); 17 | editor.clipboard = editor.textField.getSelectedText(); 18 | editor.textField.setText(cutString(source)); 19 | return true; 20 | } 21 | 22 | private String cutString(String source) { 23 | String start = source.substring(0, editor.textField.getSelectionStart()); 24 | String end = source.substring(editor.textField.getSelectionEnd()); 25 | return start + end; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /concurrency/akka/akka-start/src/main/java/sample/hello/Main2.java: -------------------------------------------------------------------------------- 1 | import akka.actor.*; 2 | 3 | public class Main2 { 4 | 5 | public static void main(String[] args) { 6 | ActorSystem system = ActorSystem.create("Hello"); 7 | ActorRef a = system.actorOf(Props.create(HelloWorld.class), "helloWorld"); 8 | system.actorOf(Props.create(Terminator.class, a), "terminator"); 9 | } 10 | 11 | public static class Terminator extends AbstractLoggingActor { 12 | 13 | private final ActorRef ref; 14 | 15 | public Terminator(ActorRef ref) { 16 | this.ref = ref; 17 | getContext().watch(ref); 18 | } 19 | 20 | @Override 21 | public Receive createReceive() { 22 | return receiveBuilder() 23 | .match(Terminated.class, t -> { 24 | log().info("{} has terminated, shutting down system", ref.path()); 25 | getContext().system().terminate(); 26 | }) 27 | .build(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /design-patterns/abstract_factory/example/factories/WindowsFactory.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.abstract_factory.example.factories; 2 | 3 | import refactoring_guru.abstract_factory.example.buttons.Button; 4 | import refactoring_guru.abstract_factory.example.buttons.WindowsButton; 5 | import refactoring_guru.abstract_factory.example.checkboxes.Checkbox; 6 | import refactoring_guru.abstract_factory.example.checkboxes.WindowsCheckbox; 7 | 8 | /** 9 | * EN: Each concrete factory extends basic factory and responsible for creating 10 | * products of a single variety. 11 | * 12 | * RU: Каждая конкретная фабрика знает и создаёт только продукты своей вариации. 13 | */ 14 | public class WindowsFactory implements GUIFactory { 15 | 16 | @Override 17 | public Button createButton() { 18 | return new WindowsButton(); 19 | } 20 | 21 | @Override 22 | public Checkbox createCheckbox() { 23 | return new WindowsCheckbox(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /design-patterns/visitor/example/shapes/Dot.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.visitor.example.shapes; 2 | 3 | import refactoring_guru.visitor.example.visitor.Visitor; 4 | 5 | public class Dot implements Shape { 6 | private int id; 7 | private int x; 8 | private int y; 9 | 10 | public Dot() { 11 | } 12 | 13 | public Dot(int id, int x, int y) { 14 | this.id = id; 15 | this.x = x; 16 | this.y = y; 17 | } 18 | 19 | @Override 20 | public void move(int x, int y) { 21 | // move shape 22 | } 23 | 24 | @Override 25 | public void draw() { 26 | // draw shape 27 | } 28 | 29 | public String accept(Visitor visitor) { 30 | return visitor.visitDot(this); 31 | } 32 | 33 | public int getX() { 34 | return x; 35 | } 36 | 37 | public int getY() { 38 | return y; 39 | } 40 | 41 | public int getId() { 42 | return id; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /concurrency/basic/src/main/java/primitive/atomic/AtomicTest.java: -------------------------------------------------------------------------------- 1 | package primitive.atomic; 2 | 3 | import java.util.concurrent.atomic.AtomicInteger; 4 | 5 | /** 6 | * Atomic 测试 7 | */ 8 | 9 | public class AtomicTest { 10 | 11 | private static final int THREADS_COUNT = 20; 12 | private static final AtomicInteger race = new AtomicInteger(); 13 | 14 | private static void increase() { 15 | race.incrementAndGet(); 16 | } 17 | 18 | public static void main(String[] args) { 19 | Thread[] threads = new Thread[THREADS_COUNT]; 20 | 21 | for (int i = 0; i < THREADS_COUNT; ++i) { 22 | threads[i] = new Thread(() -> { 23 | for (int j = 0; j < 10000; j++) { 24 | increase(); 25 | } 26 | }); 27 | threads[i].start(); 28 | } 29 | 30 | while (Thread.activeCount() > 1) { 31 | Thread.yield(); 32 | } 33 | 34 | System.out.println(race.get()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /concurrency/akka/akka-spring-boot/src/main/java/com/chriniko/example/akkaspringexample/file/FileLinesCounter.java: -------------------------------------------------------------------------------- 1 | import org.springframework.stereotype.Component; 2 | 3 | import java.io.IOException; 4 | import java.nio.file.Files; 5 | import java.nio.file.Paths; 6 | 7 | @Component 8 | public class FileLinesCounter { 9 | 10 | public long count(String filename, boolean hasHeaders) { 11 | 12 | try { 13 | long count = Files.lines(Paths.get(filename)).count(); 14 | return hasHeaders ? count - 1 : count; 15 | } catch (IOException e) { 16 | e.printStackTrace(System.err); 17 | throw new RuntimeException(e); 18 | } 19 | 20 | } 21 | 22 | public String getFile(String resourcePath) { 23 | return this.getClass() 24 | .getClassLoader() 25 | .getResource(resourcePath) 26 | .toString() 27 | .replace("file:", ""); 28 | } 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /concurrency/akka/akka-spring-boot/src/main/java/com/chriniko/example/akkaspringexample/integration/akka/SpringAkkaExtension.java: -------------------------------------------------------------------------------- 1 | import akka.actor.Extension; 2 | import akka.actor.Props; 3 | import org.springframework.context.ApplicationContext; 4 | import org.springframework.stereotype.Component; 5 | 6 | @Component 7 | public class SpringAkkaExtension implements Extension { 8 | 9 | private ApplicationContext applicationContext; 10 | 11 | public void initialize(ApplicationContext applicationContext) { 12 | this.applicationContext = applicationContext; 13 | } 14 | 15 | public Props props(String actorBeanName) { 16 | return Props.create(SpringActorProducer.class, applicationContext, actorBeanName); 17 | } 18 | 19 | public static String classNameToSpringName(Class clazz) { 20 | 21 | String simpleName = clazz.getSimpleName(); 22 | 23 | return simpleName.substring(0, 1).toLowerCase() + simpleName.substring(1); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /design-patterns/adapter/example/adapters/SquarePegAdapter.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.adapter.example.adapters; 2 | 3 | import refactoring_guru.adapter.example.round.RoundPeg; 4 | import refactoring_guru.adapter.example.square.SquarePeg; 5 | 6 | /** 7 | * EN: Adapter allows fitting square pegs into round holes. 8 | * 9 | * RU: Адаптер позволяет использовать КвадратныеКолышки и КруглыеОтверстия 10 | * вместе. 11 | */ 12 | public class SquarePegAdapter extends RoundPeg { 13 | private SquarePeg peg; 14 | 15 | public SquarePegAdapter(SquarePeg peg) { 16 | this.peg = peg; 17 | } 18 | 19 | @Override 20 | public double getRadius() { 21 | double result; 22 | // EN: Calculate a minimum circle radius, which can fit this peg. 23 | // 24 | // RU: Рассчитываем минимальный радиус, в который пролезет этот колышек. 25 | result = (Math.sqrt(Math.pow((peg.getWidth() / 2), 2) * 2)); 26 | return result; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /concurrency/akka/akka-cluster/src/main/java/sample/cluster/factorial/FactorialBackend.java: -------------------------------------------------------------------------------- 1 | import java.math.BigInteger; 2 | import java.util.concurrent.CompletableFuture; 3 | 4 | import akka.actor.AbstractActor; 5 | import static akka.pattern.PatternsCS.pipe; 6 | 7 | public class FactorialBackend extends AbstractActor { 8 | 9 | @Override 10 | public Receive createReceive() { 11 | return receiveBuilder() 12 | .match(Integer.class, n -> { 13 | 14 | CompletableFuture result = 15 | CompletableFuture.supplyAsync(() -> factorial(n)) 16 | .thenApply((factorial) -> new FactorialResult(n, factorial)); 17 | 18 | pipe(result, getContext().dispatcher()).to(sender()); 19 | 20 | }) 21 | .build(); 22 | } 23 | 24 | BigInteger factorial(int n) { 25 | BigInteger acc = BigInteger.ONE; 26 | for (int i = 1; i <= n; ++i) { 27 | acc = acc.multiply(BigInteger.valueOf(i)); 28 | } 29 | return acc; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /concurrency/akka/akka-fsm/src/main/java/sample/fsm/Messages.java: -------------------------------------------------------------------------------- 1 | import akka.actor.ActorRef; 2 | 3 | public class Messages { 4 | 5 | public static final class Busy { 6 | public final ActorRef chopstick; 7 | public Busy(ActorRef chopstick){ 8 | this.chopstick = chopstick; 9 | } 10 | } 11 | 12 | private static interface PutMessage {}; 13 | public static final Object Put = new PutMessage() { 14 | @Override 15 | public String toString() { return "Put"; } 16 | }; 17 | 18 | private static interface TakeMessage {}; 19 | public static final Object Take = new TakeMessage() { 20 | @Override 21 | public String toString() { return "Take"; } 22 | }; 23 | 24 | public static final class Taken { 25 | public final ActorRef chopstick; 26 | public Taken(ActorRef chopstick){ 27 | this.chopstick = chopstick; 28 | } 29 | } 30 | 31 | private static interface ThinkMessage {}; 32 | public static final Object Think = new ThinkMessage() {}; 33 | } 34 | -------------------------------------------------------------------------------- /concurrency/akka/akka-cluster/src/main/java/sample/cluster/transformation/TransformationBackendMain.java: -------------------------------------------------------------------------------- 1 | import com.typesafe.config.Config; 2 | import com.typesafe.config.ConfigFactory; 3 | 4 | import akka.actor.ActorSystem; 5 | import akka.actor.Props; 6 | 7 | public class TransformationBackendMain { 8 | 9 | public static void main(String[] args) { 10 | // Override the configuration of the port when specified as program argument 11 | final String port = args.length > 0 ? args[0] : "0"; 12 | final Config config = 13 | ConfigFactory.parseString( 14 | "akka.remote.netty.tcp.port=" + port + "\n" + 15 | "akka.remote.artery.canonical.port=" + port) 16 | .withFallback(ConfigFactory.parseString("akka.cluster.roles = [backend]")) 17 | .withFallback(ConfigFactory.load()); 18 | 19 | ActorSystem system = ActorSystem.create("ClusterSystem", config); 20 | 21 | system.actorOf(Props.create(TransformationBackend.class), "backend"); 22 | 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /design-patterns/bridge/example/OutputDemo.txt: -------------------------------------------------------------------------------- 1 | Tests with basic remote. 2 | Remote: power toggle 3 | ------------------------------------ 4 | | I'm TV set. 5 | | I'm enabled 6 | | Current volume is 30% 7 | | Current channel is 1 8 | ------------------------------------ 9 | 10 | Tests with advanced remote. 11 | Remote: power toggle 12 | Remote: mute 13 | ------------------------------------ 14 | | I'm TV set. 15 | | I'm disabled 16 | | Current volume is 0% 17 | | Current channel is 1 18 | ------------------------------------ 19 | 20 | Tests with basic remote. 21 | Remote: power toggle 22 | ------------------------------------ 23 | | I'm radio. 24 | | I'm enabled 25 | | Current volume is 30% 26 | | Current channel is 1 27 | ------------------------------------ 28 | 29 | Tests with advanced remote. 30 | Remote: power toggle 31 | Remote: mute 32 | ------------------------------------ 33 | | I'm radio. 34 | | I'm disabled 35 | | Current volume is 0% 36 | | Current channel is 1 37 | ------------------------------------ -------------------------------------------------------------------------------- /concurrency/akka/akka-spring-boot/src/main/java/com/chriniko/example/akkaspringexample/integration/akka/SpringActorProducer.java: -------------------------------------------------------------------------------- 1 | import akka.actor.Actor; 2 | import akka.actor.IndirectActorProducer; 3 | import org.springframework.context.ApplicationContext; 4 | 5 | public class SpringActorProducer implements IndirectActorProducer { 6 | 7 | private final ApplicationContext applicationContext; 8 | private final String actorBeanName; 9 | 10 | public SpringActorProducer(ApplicationContext applicationContext, String actorBeanName) { 11 | this.applicationContext = applicationContext; 12 | this.actorBeanName = actorBeanName; 13 | } 14 | 15 | @Override 16 | public Actor produce() { 17 | return (Actor) applicationContext.getBean(actorBeanName); 18 | } 19 | 20 | @SuppressWarnings("unchecked") 21 | @Override 22 | public Class actorClass() { 23 | return (Class) applicationContext.getType(actorBeanName); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /design-patterns/decorator/example/Demo.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.decorator.example; 2 | 3 | import refactoring_guru.decorator.example.decorators.*; 4 | 5 | public class Demo { 6 | public static void main(String[] args) { 7 | String salaryRecords = "Name,Salary\nJohn Smith,100000\nSteven Jobs,912000"; 8 | DataSourceDecorator encoded = new CompressionDecorator( 9 | new EncryptionDecorator( 10 | new FileDataSource("out/OutputDemo.txt"))); 11 | encoded.writeData(salaryRecords); 12 | DataSource plain = new FileDataSource("out/OutputDemo.txt"); 13 | 14 | System.out.println("- Input ----------------"); 15 | System.out.println(salaryRecords); 16 | System.out.println("- Encoded --------------"); 17 | System.out.println(plain.readData()); 18 | System.out.println("- Decoded --------------"); 19 | System.out.println(encoded.readData()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /design-patterns/iterator/example/OutputDemo.txt: -------------------------------------------------------------------------------- 1 | Please specify social network to target spam tool (default:Facebook): 2 | 1. Facebook 3 | 2. LinkedIn 4 | > 1 5 | 6 | Iterating over friends... 7 | 8 | Facebook: Loading 'friends' list of 'anna.smith@bing.com' over the network... 9 | Facebook: Loading profile 'mad_max@ya.com' over the network... 10 | Sent message to: 'mad_max@ya.com'. Message body: 'Hey! This is Anna's friend Josh. Can you do me a favor and like this post [link]?' 11 | Facebook: Loading profile 'catwoman@yahoo.com' over the network... 12 | Sent message to: 'catwoman@yahoo.com'. Message body: 'Hey! This is Anna's friend Josh. Can you do me a favor and like this post [link]?' 13 | 14 | Iterating over coworkers... 15 | 16 | Facebook: Loading 'coworkers' list of 'anna.smith@bing.com' over the network... 17 | Facebook: Loading profile 'sam@amazon.com' over the network... 18 | Sent message to: 'sam@amazon.com'. Message body: 'Hey! This is Anna's boss Jason. Anna told me you would be interested in [link].' 19 | -------------------------------------------------------------------------------- /concurrency/akka/akka-spring-boot/src/main/java/com/chriniko/example/akkaspringexample/configuration/SchedulingConfiguration.java: -------------------------------------------------------------------------------- 1 | import org.springframework.context.annotation.Bean; 2 | import org.springframework.context.annotation.Configuration; 3 | import org.springframework.scheduling.annotation.EnableScheduling; 4 | import org.springframework.scheduling.annotation.SchedulingConfigurer; 5 | import org.springframework.scheduling.config.ScheduledTaskRegistrar; 6 | 7 | import java.util.concurrent.ExecutorService; 8 | import java.util.concurrent.Executors; 9 | 10 | @Configuration 11 | @EnableScheduling 12 | public class SchedulingConfiguration implements SchedulingConfigurer { 13 | 14 | @Override 15 | public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { 16 | taskRegistrar.setScheduler(taskScheduler()); 17 | } 18 | 19 | @Bean(destroyMethod = "shutdown") 20 | public ExecutorService taskScheduler() { 21 | return Executors.newScheduledThreadPool(1); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /design-patterns/visitor/example/Demo.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.visitor.example; 2 | 3 | import refactoring_guru.visitor.example.shapes.*; 4 | import refactoring_guru.visitor.example.visitor.XMLExportVisitor; 5 | 6 | public class Demo { 7 | public static void main(String[] args) { 8 | Dot dot = new Dot(1, 10, 55); 9 | Circle circle = new Circle(2, 23, 15, 10); 10 | Rectangle rectangle = new Rectangle(3, 10, 17, 20, 30); 11 | 12 | CompoundShape compoundShape = new CompoundShape(4); 13 | compoundShape.add(dot); 14 | compoundShape.add(circle); 15 | compoundShape.add(rectangle); 16 | 17 | CompoundShape c = new CompoundShape(5); 18 | c.add(dot); 19 | compoundShape.add(c); 20 | 21 | export(circle, compoundShape); 22 | } 23 | 24 | private static void export(Shape... shapes) { 25 | XMLExportVisitor exportVisitor = new XMLExportVisitor(); 26 | System.out.println(exportVisitor.export(shapes)); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /concurrency/akka/akka-sharding/src/main/java/sample/sharding/ShardingApp.java: -------------------------------------------------------------------------------- 1 | import akka.actor.ActorSystem; 2 | import akka.actor.Props; 3 | 4 | import com.typesafe.config.Config; 5 | import com.typesafe.config.ConfigFactory; 6 | 7 | public class ShardingApp { 8 | 9 | public static void main(String[] args) { 10 | if (args.length == 0) 11 | startup(new String[] { "2551", "2552", "0" }); 12 | else 13 | startup(args); 14 | } 15 | 16 | public static void startup(String[] ports) { 17 | for (String port : ports) { 18 | // Override the configuration of the port 19 | Config config = ConfigFactory.parseString( 20 | "akka.remote.netty.tcp.port=" + port).withFallback( 21 | ConfigFactory.load()); 22 | 23 | // Create an Akka system 24 | ActorSystem system = ActorSystem.create("ShardingSystem", config); 25 | 26 | // Create an actor that starts the sharding and sends random messages 27 | system.actorOf(Props.create(Devices.class)); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /design-patterns/mediator/example/components/Title.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.mediator.example.components; 2 | 3 | import refactoring_guru.mediator.example.mediator.Mediator; 4 | 5 | import javax.swing.*; 6 | import java.awt.event.KeyEvent; 7 | 8 | /** 9 | * EN: Concrete components don't talk with each other. They have only one 10 | * communication channel–sending requests to the mediator. 11 | * 12 | * RU: Конкретные компоненты никак не связаны между собой. У них есть только 13 | * один канал общения – через отправку уведомлений посреднику. 14 | */ 15 | public class Title extends JTextField implements Component { 16 | private Mediator mediator; 17 | 18 | @Override 19 | public void setMediator(Mediator mediator) { 20 | this.mediator = mediator; 21 | } 22 | 23 | @Override 24 | protected void processComponentKeyEvent(KeyEvent keyEvent) { 25 | mediator.markNote(); 26 | } 27 | 28 | @Override 29 | public String getName() { 30 | return "Title"; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /design-patterns/state/example/states/ReadyState.java: -------------------------------------------------------------------------------- 1 | package refactoring_guru.state.example.states; 2 | 3 | import refactoring_guru.state.example.ui.Player; 4 | 5 | /** 6 | * EN: They can also trigger state transitions in the context. 7 | * 8 | * RU: Они также могут переводить контекст в другие состояния. 9 | */ 10 | public class ReadyState extends State { 11 | 12 | public ReadyState(Player player) { 13 | super(player); 14 | } 15 | 16 | @Override 17 | public String onLock() { 18 | player.changeState(new LockedState(player)); 19 | return "Locked..."; 20 | } 21 | 22 | @Override 23 | public String onPlay() { 24 | String action = player.startPlayback(); 25 | player.changeState(new PlayingState(player)); 26 | return action; 27 | } 28 | 29 | @Override 30 | public String onNext() { 31 | return "Locked..."; 32 | } 33 | 34 | @Override 35 | public String onPrevious() { 36 | return "Locked..."; 37 | } 38 | } 39 | --------------------------------------------------------------------------------