state

How to avoid long switch ..need help refactoring

ⅰ亾dé卋堺 提交于 2019-12-04 17:37:25
i needed help refactoring the following class, Following is a class Operation with variety of Operations in switch : i want to avoid the switch statement.I read few articles on using polymorphism and state pattern .but when i refactor the classes i dont get access to many variables,properties Im confused on whether to use operation as abstract class or to implement an interface. Just wanted to know which type of refactoring will help in this case polymorphism or state pattern? And when to use them? public class Operation { public enum OperationType { add, update, delete, retrieve } public enum

User state in Parsec

萝らか妹 提交于 2019-12-04 17:23:19
问题 I'm parsing an expression using Parsec and I want to keep track of variables in these expressions using the user state in Parsec. Unfortunately I don't really get how to do it. Given the following code: import Data.Set as Set inp = "$x = $y + $z" data Var = V String var = do char '$' n <- many1 letter let v = Var n -- I want to modify the set of variables here return v parseAssignment = ... -- parses the above assignment run = case runIdentity $ runParserT parseAssignment Set.empty "" inp of

Clojure states within states within states

房东的猫 提交于 2019-12-04 16:52:17
问题 I'd love to hear what advice the Clojure gurus here have about managing state in hierarchies. I find I'm often using {:structures {:like {:this {:with {:many 'levels}} } } } and if I want to track changes in state at multiple levels, by throwing atoms around values (atom {:like (atom 'this)} ) , I find myself thinking this must be wrong. Is it generally better to use just one atom at the top level, and have none as values in a map ? 回答1: Don't use nested atoms in a data structure if at all

state transition with different guard condition

寵の児 提交于 2019-12-04 16:50:43
In the state pattern how is this modeled ? state A to state B on trigger X and conditon C1 when current state is A state A to state C on trigger X and condition C2 when current state is A how is this usually accomplished ? I have a lot of guard conditions that I may need to implement. That's pretty standard see e.g. this example . [Edited on basis it's not homework!] Assuming I understand right: You have one event ( X ) which can trigger one of two possible transitions Selecting which transition to fire is made according to which condition holds true ( C1 or C2 ) If so that's a standard case

TransactionScope and rolling back object state

二次信任 提交于 2019-12-04 16:48:15
I'm looking for a solution to a design problem. This will take a bit of explaining. I would post code, but that woul make this even longer. I have a custom generic collection I use to hold Business Objects as needed. For easy of reference, call the business objects BO and the generic collection GC . Inside GC I have a private collection of those business objects that have been flagged for deletion. Call this private collection PDC . I can have an arbitrary number of GC's, each with their own PDC, at any one time, plus other BOs that aren't in any collection. When I save changes I loop over all

Stateful processing in Beam - is state shared across window panes?

老子叫甜甜 提交于 2019-12-04 16:36:41
Apache Beam has recently introduced state cells, through StateSpec and the @StateId annotation, with partial support in Apache Flink and Google Cloud Dataflow. My question is about state garbage collection, in the case where a stateful DoFn is used on a windowed stream. Typically, state is removed (garbage collected) by the runner when the window expires (i.e. the watermark passes the end of the window). However, consider the case where window panes are triggered early, and the fired panes are discarded: input.apply(Window.<MyElement>into(CalendarWindows.days(1)) .triggering(AfterWatermark

Storing entire process state on disk and restoring it later? (On Linux/Unix)

梦想与她 提交于 2019-12-04 16:26:22
问题 I would like to know: Is there a system call, library, kernel module or command line tool I can use to store the complete state of a running program on the disk? That is: I would like to completely dump the memory, page layout, stack, registers, threads and file descriptors a process is currently using to a file on the hard drive and be able to restore it later seamlessly, just like an emulator "savestate" or a Virtual Machine "snapshot". I would also like, if possible, to have multiple

Why cant react set initial state based on props

守給你的承諾、 提交于 2019-12-04 16:02:00
问题 I have a es6 react component that I want the initial value of the state to depend on that of the passed down prop, but its value is always false: AttachStateToProps component <AttachStateToProps VALUE=false /> AttachStateToProps component: class AttachStateToProps extends React.Component { state = { stateValue: this.props.VALUE, } render() { console.log('Value of Prop - ', this.props.VALUE) console.log('Value of State - ', this.state.stateValue) return null } } Every time the value of the

$locationChangeSuccess triggers four times

对着背影说爱祢 提交于 2019-12-04 15:55:19
I am new to angular Js. My application flow is as below: 1) I have a view controller wherein, each view controller sets the breadcrumb data with the help of Breadcrumbs factory. 2) Breadcrumbs factory takes data from view controller and attaches data to $location.$$state object.(reason for storing in state object is if back button is pressed, view controller doesn't instantiate so I can refer history data for breadcrumbs ) below is code to attach data to state object: var state = $location.state(); state.breadcrumb = breadcrumbData; $location.replace().state(state); 3) I have also created

Implementing communication protocol in Java using state pattern design

安稳与你 提交于 2019-12-04 14:22:37
问题 Apologies if this is answered elsewhere; couldn't find enough information to convince myself of the best way to do this. I also realize this is a lengthy explanation with no code, but let me know if I should whip up some sample code to help demonstrate what I'm doing. Basically: implementing a communication protocol in Java using System.in/out current approach is implementing a state pattern where a Scanner is instantiated on System.in in the context class concrete states invoke a context