[windup-dev] TopLayerSingletonFramesSelector logic?

Ondrej Zizka ozizka at redhat.com
Wed Oct 7 08:54:45 EDT 2015


Just a minor thing, for potential refactoring:

TopLayerSingletonFramesSelector:

     public Iterable<? extends WindupVertexFrame> getFrames(GraphRewrite 
event, EvaluationContext context)
     {
         Variables variables = Variables.instance(event);
         this.varName = Iteration.getPayloadVariableName(event, context);
         return variables.findVariable(varName);
     }

     public static String getPayloadVariableName(GraphRewrite event, 
EvaluationContext ctx) throws IllegalStateException
     {
         Variables variables = Variables.instance(event);
         Map<String, Iterable<? extends WindupVertexFrame>> topLayer = 
variables.peek();
         if (topLayer.keySet().size() != 1)
             throw new IllegalStateException("Cannot determine Iteration 
payload variable name because the top "
                 + "layer of " + Variables.class.getSimpleName() + " 
stack contains no or multiple variables: " + topLayer.keySet());
         String name = topLayer.keySet().iterator().next();
         return name;
     }

So it verifies that the Variables stack has only one name, then returns 
it to let the calling code return the content of that single variable.
I think the logic should be reversed - the check for a single variable 
should be in the calling code.

Ondra


More information about the windup-dev mailing list