Search in sources :

Example 31 with LinkedList

use of java.util.LinkedList in project zeppelin by apache.

the class NotebookServer method broadcastUpdateNoteJobInfo.

public void broadcastUpdateNoteJobInfo(long lastUpdateUnixTime) throws IOException {
    List<Map<String, Object>> noteJobs = new LinkedList<>();
    Notebook notebookObject = notebook();
    List<Map<String, Object>> jobNotes = null;
    if (notebookObject != null) {
        jobNotes = notebook().getJobListByUnixTime(false, lastUpdateUnixTime, null);
        noteJobs = jobNotes == null ? noteJobs : jobNotes;
    }
    Map<String, Object> response = new HashMap<>();
    response.put("lastResponseUnixTime", System.currentTimeMillis());
    response.put("jobs", noteJobs != null ? noteJobs : new LinkedList<>());
    broadcast(JOB_MANAGER_SERVICE.JOB_MANAGER_PAGE.getKey(), new Message(OP.LIST_UPDATE_NOTE_JOBS).put("noteRunningJobs", response));
}
Also used : Notebook(org.apache.zeppelin.notebook.Notebook) InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) Message(org.apache.zeppelin.notebook.socket.Message) WatcherMessage(org.apache.zeppelin.notebook.socket.WatcherMessage) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) AngularObject(org.apache.zeppelin.display.AngularObject) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList)

Example 32 with LinkedList

use of java.util.LinkedList in project zeppelin by apache.

the class Notebook method convertFromSingleResultToMultipleResultsFormat.

public void convertFromSingleResultToMultipleResultsFormat(Note note) {
    for (Paragraph p : note.paragraphs) {
        Object ret = p.getPreviousResultFormat();
        try {
            if (ret != null && ret instanceof Map) {
                Map r = ((Map) ret);
                if (r.containsKey("code") && r.containsKey("msg") && r.containsKey("type")) {
                    // all three fields exists in sinle result format
                    InterpreterResult.Code code = InterpreterResult.Code.valueOf((String) r.get("code"));
                    InterpreterResult.Type type = InterpreterResult.Type.valueOf((String) r.get("type"));
                    String msg = (String) r.get("msg");
                    InterpreterResult result = new InterpreterResult(code, msg);
                    if (result.message().size() == 1) {
                        result = new InterpreterResult(code);
                        result.add(type, msg);
                    }
                    p.setResult(result);
                    // convert config
                    Map<String, Object> config = p.getConfig();
                    Object graph = config.remove("graph");
                    Object apps = config.remove("apps");
                    Object helium = config.remove("helium");
                    List<Object> results = new LinkedList<>();
                    for (int i = 0; i < result.message().size(); i++) {
                        if (i == result.message().size() - 1) {
                            HashMap<Object, Object> res = new HashMap<>();
                            res.put("graph", graph);
                            res.put("apps", apps);
                            res.put("helium", helium);
                            results.add(res);
                        } else {
                            results.add(new HashMap<>());
                        }
                    }
                    config.put("results", results);
                }
            }
        } catch (Exception e) {
            logger.error("Conversion failure", e);
        }
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LinkedList(java.util.LinkedList) SchedulerException(org.quartz.SchedulerException) IOException(java.io.IOException) JobExecutionException(org.quartz.JobExecutionException) AngularObject(org.apache.zeppelin.display.AngularObject) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 33 with LinkedList

use of java.util.LinkedList in project cogtool by cogtool.

the class ProjectController method createImportHumanCSVFileAction.

// Action for ImportHumanCSVFile
protected IListenerAction createImportHumanCSVFileAction() {
    return new IListenerAction() {

        public Class<?> getParameterClass() {
            return ProjectSelectionState.class;
        }

        public boolean performAction(Object prms) {
            ProjectSelectionState seln = (ProjectSelectionState) prms;
            // Must have selected tasks and design
            Design design = seln.getSelectedDesign();
            AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
            if ((design == null) || (tasks == null) || (tasks.length == 0)) {
                return false;
            }
            List<String> outputLines = new LinkedList<String>();
            List<String> errorLines = new LinkedList<String>();
            // Get csv file
            File dataFile = interaction.selectCSVFile();
            if (dataFile == null) {
                interaction.setStatusMessage(IMPORT_FAIL_NOFILE_MSG);
                return false;
            }
            // Read lines out of file
            FileReader reader = null;
            try {
                reader = new FileReader(dataFile);
                FileUtil.readLines(reader, outputLines);
            } catch (FileNotFoundException e) {
                interaction.setStatusMessage(IMPORT_FAIL_NOFILE_MSG);
                throw new RcvrIOTempException("Error in parsing csv", e);
            } catch (IOException e) {
                interaction.setStatusMessage(IMPORT_FAIL_NOREAD_MSG);
                throw new RcvrParsingException("Error in parsing csv", e);
            } finally {
                if (reader != null) {
                    try {
                        reader.close();
                    } catch (IOException e) {
                    // ignore
                    }
                    reader = null;
                }
            }
            // parse ResultSteps out of trace lines
            TraceParser<ResultStep> parser = new HumanCSVParser();
            List<ResultStep> steps;
            try {
                steps = parser.parseTrace(outputLines);
            } catch (TraceParser.ParseException e) {
                interaction.setStatusMessage(IMPORT_FAIL_PARSE_IMPL_MSG);
                throw new RcvrParsingException("Error in parsing implementation", e);
            }
            System.out.println(steps);
            if (steps.size() < 1) {
                interaction.setStatusMessage(IMPORT_FAIL_PARSE_MSG);
                return false;
            }
            double taskTime = -1.0;
            Iterator<ResultStep> stepIt = steps.iterator();
            while (stepIt.hasNext()) {
                ResultStep step = stepIt.next();
                taskTime = Math.max(taskTime, step.startTime + step.duration);
            }
            // Scale time to seconds.
            taskTime /= 1000.0;
            // -------------- Done parsing
            DemoStateManager demoMgr = DemoStateManager.getStateManager(project, design);
            final TaskApplication[] taskApps = new TaskApplication[tasks.length];
            final APredictionResult[] oldResults = new APredictionResult[tasks.length];
            final APredictionResult[] results = new APredictionResult[tasks.length];
            final IPredictionAlgo[] oldActiveAlgos = new IPredictionAlgo[tasks.length];
            for (int i = 0; i < tasks.length; i++) {
                taskApps[i] = ensureTaskApplication(tasks[i], design, MODELGEN_ALG, demoMgr);
                // If for some reason there are no result steps,
                // create a TimePredictionResult that
                // reflects COMPUTATION_FAILED.
                // Otherwise, create a normal one.
                Script script = taskApps[i].getScript(MODELGEN_ALG);
                if (taskTime < 0.0) {
                    results[i] = new TimePredictionResult(dataFile.getName(), script, HumanDataAlgo.ONLY, outputLines, errorLines, steps);
                } else {
                    results[i] = new TimePredictionResult(dataFile.getName(), script, HumanDataAlgo.ONLY, outputLines, errorLines, steps, taskTime);
                }
                oldResults[i] = taskApps[i].getResult(MODELGEN_ALG, HumanDataAlgo.ONLY);
                taskApps[i].setResult(MODELGEN_ALG, HumanDataAlgo.ONLY, results[i]);
                oldActiveAlgos[i] = taskApps[i].getActiveAlgorithm();
                taskApps[i].setActiveAlgorithm(HumanDataAlgo.ONLY);
            }
            IUndoableEdit edit = new AUndoableEdit(ProjectLID.RecomputeScript) {

                @Override
                public String getPresentationName() {
                    return IMPORT_HUMAN_CSV;
                }

                @Override
                public void redo() {
                    super.redo();
                    for (int i = 0; i < taskApps.length; i++) {
                        taskApps[i].setResult(MODELGEN_ALG, HumanDataAlgo.ONLY, results[i]);
                        taskApps[i].setActiveAlgorithm(HumanDataAlgo.ONLY);
                    }
                }

                @Override
                public void undo() {
                    super.undo();
                    for (int i = 0; i < taskApps.length; i++) {
                        taskApps[i].setResult(MODELGEN_ALG, HumanDataAlgo.ONLY, oldResults[i]);
                        taskApps[i].setActiveAlgorithm(oldActiveAlgos[i]);
                    }
                }
            };
            undoMgr.addEdit(edit);
            interaction.setStatusMessage(IMPORT_SUCCESS_MSG);
            return true;
        }
    };
}
Also used : TraceParser(edu.cmu.cs.hcii.cogtool.model.TraceParser) FileNotFoundException(java.io.FileNotFoundException) RcvrParsingException(edu.cmu.cs.hcii.cogtool.util.RcvrParsingException) Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) ResultStep(edu.cmu.cs.hcii.cogtool.model.ResultStep) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) HumanCSVParser(edu.cmu.cs.hcii.cogtool.model.HumanCSVParser) TimePredictionResult(edu.cmu.cs.hcii.cogtool.model.TimePredictionResult) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) FileReader(java.io.FileReader) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) Script(edu.cmu.cs.hcii.cogtool.model.Script) IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) APredictionResult(edu.cmu.cs.hcii.cogtool.model.APredictionResult) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) LinkedList(java.util.LinkedList) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) RcvrIOTempException(edu.cmu.cs.hcii.cogtool.util.RcvrIOTempException) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) File(java.io.File)

Example 34 with LinkedList

use of java.util.LinkedList in project cas by apereo.

the class CouchbaseServiceRegistryDao method load.

@Override
public List<RegisteredService> load() {
    try {
        LOGGER.debug("Loading services");
        final ViewResult allKeys = executeViewQueryForAllServices();
        final List<RegisteredService> services = new LinkedList<>();
        for (final ViewRow row : allKeys) {
            final RawJsonDocument document = row.document(RawJsonDocument.class);
            if (document != null) {
                final String json = document.content();
                LOGGER.debug("Found service: [{}]", json);
                final StringReader stringReader = new StringReader(json);
                services.add(this.registeredServiceJsonSerializer.from(stringReader));
            }
        }
        return services;
    } catch (final RuntimeException e) {
        LOGGER.error(e.getMessage(), e);
        return new LinkedList<>();
    }
}
Also used : StringReader(java.io.StringReader) RawJsonDocument(com.couchbase.client.java.document.RawJsonDocument) ViewResult(com.couchbase.client.java.view.ViewResult) LinkedList(java.util.LinkedList) ViewRow(com.couchbase.client.java.view.ViewRow)

Example 35 with LinkedList

use of java.util.LinkedList in project checkstyle by checkstyle.

the class FinalClassCheck method extractQualifiedName.

/**
     * Get name of class(with qualified package if specified) in extend clause.
     * @param classExtend extend clause to extract class name
     * @return super class name
     */
private static String extractQualifiedName(DetailAST classExtend) {
    final String className;
    if (classExtend.findFirstToken(TokenTypes.IDENT) == null) {
        // Name specified with packages, have to traverse DOT
        final DetailAST firstChild = classExtend.findFirstToken(TokenTypes.DOT);
        final List<String> qualifiedNameParts = new LinkedList<>();
        qualifiedNameParts.add(0, firstChild.findFirstToken(TokenTypes.IDENT).getText());
        DetailAST traverse = firstChild.findFirstToken(TokenTypes.DOT);
        while (traverse != null) {
            qualifiedNameParts.add(0, traverse.findFirstToken(TokenTypes.IDENT).getText());
            traverse = traverse.findFirstToken(TokenTypes.DOT);
        }
        className = String.join(PACKAGE_SEPARATOR, qualifiedNameParts);
    } else {
        className = classExtend.findFirstToken(TokenTypes.IDENT).getText();
    }
    return className;
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) LinkedList(java.util.LinkedList)

Aggregations

LinkedList (java.util.LinkedList)10856 Test (org.junit.Test)1545 List (java.util.List)1517 HashMap (java.util.HashMap)1413 ArrayList (java.util.ArrayList)1368 Map (java.util.Map)915 IOException (java.io.IOException)826 File (java.io.File)721 HashSet (java.util.HashSet)632 LinkedHashMap (java.util.LinkedHashMap)390 GenericValue (org.apache.ofbiz.entity.GenericValue)296 Iterator (java.util.Iterator)281 Set (java.util.Set)274 Date (java.util.Date)249 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)232 Collection (java.util.Collection)208 Collectors (java.util.stream.Collectors)162 Delegator (org.apache.ofbiz.entity.Delegator)162 URL (java.net.URL)159 Locale (java.util.Locale)159