Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package com.presidentio.testdatagenerator;
 
 
 import java.util.List;
 import java.util.Map;
 
 public class InitTask extends RecursiveAction {
 
     private Schema schema;
     private SinkFactory sinkFactory = new SinkFactory();
 
     private boolean async = true;
 
     public InitTask(Schema schema) {
         this. = schema;
     }
 
     @Override
     protected void compute() {
         final Context context = buildContext();
         List<GenerateTasktasks = new ArrayList<>(.getRoot().size());
         for (String rootTemplateId : .getRoot()) {
             final Template rootTemplate = context.getTemplates().get(rootTemplateId);
             if (rootTemplate == null) {
                 throw new IllegalArgumentException("Template with id does not defined: " + rootTemplateId);
             }
             GenerateTask task = new GenerateTask(contextrootTemplate);
             task.setAsync();
             tasks.add(task);
         }
         if () {
             invokeAll(tasks);
         } else {
             for (GenerateTask forkJoinTask : tasks) {
                 forkJoinTask.compute();
             }
         }
         context.getSink().close();
 
     }
 
     private Context buildContext(Schema schema) {
         Map<StringObjectvariables = new HashMap<>();
         for (Variable variable : schema.getVariables()) {
             Object initValue;
             switch (variable.getType()) {
                 case .:
                     initValue = variable.getInitValue();
                     break;
                 case .:
                     initValue = Long.valueOf(variable.getInitValue());
                     break;
                 case .:
                     initValue = Integer.valueOf(variable.getInitValue());
                     break;
                 case .:
                     initValue = Boolean.valueOf(variable.getInitValue());
                     break;
                 default:
                     throw new IllegalArgumentException("Variable type not known: " + variable.getType());
             }
 
             variables.put(variable.getName(), initValue);
         }
 
         Sink sink = buildSink(schema.getOutput());
 
         Map<StringTemplatetemplates = new HashMap<>();
         for (Template template : schema.getTemplates()) {
             templates.put(template.getId(), template);
         }
 
        return new Context(templatesvariablessink);
    }
    private Sink buildSink(Output output) {
        return .getSink(output);
    }
    public boolean isAsync() {
        return ;
    }
    public void setAsync(boolean async) {
        this. = async;
    }
        return ;
    }
    public void setValueProviderFactory(ValueProviderFactory valueProviderFactory) {
        this. = valueProviderFactory;
    }
    public SinkFactory getSinkFactory() {
        return ;
    }
    public void setSinkFactory(SinkFactory sinkFactory) {
        this. = sinkFactory;
    }
New to GrepCode? Check out our FAQ X