Programming a State Machine in Java | Wicked Source
Programming a State Machine in Java Some programming problems center around managing different states and the transitions between the states. These problems are ideally suited to be solved by using a finite state machine. This post shows a way of programming a finite state machine in Java to solve a text parsing problem and to keep the readability of the code at a maximum at the same time. The Problem: a Parser for Unified Diffs Recently, I needed to parse a unified diff. I looked for a Java library that does this for me without luck, so I decided to roll my own since it is not that big of a problem. A unified diff is a text fragment that contains the differences in lines between two text files (or between two versions of the same text file). It looks something like this: This text is to be parsed to create a Java object that contains all information. A State Machine to the Rescue Luckily, a unified diff follows a pattern that can be parsed.Read full article from Programming a State Machine in Java | Wicked Source
No comments:
Post a Comment