Example usage for java.lang System lineSeparator

List of usage examples for java.lang System lineSeparator

Introduction

In this page you can find the example usage for java.lang System lineSeparator.

Prototype

String lineSeparator

To view the source code for java.lang System lineSeparator.

Click Source Link

Usage

From source file:com.searchcode.app.service.route.AdminRouteService.java

public String getStat(String statname) {
    if (statname == null) {
        return Values.EMPTYSTRING;
    }//from www.java2  s  . c  o m

    switch (statname.toLowerCase()) {
    case "memoryusage":
        return this.statsService.getMemoryUsage("<br>");
    case "loadaverage":
        return this.statsService.getLoadAverage();
    case "uptime":
        return this.statsService.getUptime();
    case "searchcount":
        return Values.EMPTYSTRING + this.statsService.getSearchCount();
    case "runningjobs":
        StringBuilder stringBuffer = new StringBuilder();
        for (String key : Singleton.getRunningIndexRepoJobs().keySet()) {
            RunningIndexJob indexJob = Singleton.getRunningIndexRepoJobs().get(key);
            if (indexJob != null) {
                int runningTime = Singleton.getHelpers().getCurrentTimeSeconds() - indexJob.startTime;
                stringBuffer.append(key).append(" <small>(").append(runningTime).append(" seconds)</small>")
                        .append(" ");
            } else {
                stringBuffer.append(key).append(" ");
            }
        }
        return stringBuffer.toString();
    case "spellingcount":
        return Values.EMPTYSTRING + Singleton.getSpellingCorrector().getWordCount();
    case "repocount":
        return Values.EMPTYSTRING + Singleton.getRepo().getRepoCount();
    case "numdocs":
        CodeSearcher codeSearcher = new CodeSearcher();
        return Values.EMPTYSTRING + codeSearcher.getTotalNumberDocumentsIndexed();
    case "servertime":
        return new Date().toString();
    case "deletionqueue":
        return Values.EMPTYSTRING + Singleton.getDataService().getPersistentDelete().size();
    case "alllogs":
        return StringUtils.join(Singleton.getLogger().getAllLogs(), System.lineSeparator());
    case "infologs":
        return StringUtils.join(Singleton.getLogger().getInfoLogs(), System.lineSeparator());
    case "warninglogs":
        return StringUtils.join(Singleton.getLogger().getWarningLogs(), System.lineSeparator());
    case "severelogs":
        return StringUtils.join(Singleton.getLogger().getSevereLogs(), System.lineSeparator());
    case "searchlogs":
        return StringUtils.join(Singleton.getLogger().getSearchLogs(), System.lineSeparator());
    case "apilogs":
        return StringUtils.join(Singleton.getLogger().getApiLogs(), System.lineSeparator());
    case "threads":
        return "" + java.lang.Thread.activeCount();
    case "paused":
        return this.sharedService.getPauseBackgroundJobs() ? "paused" : "running";
    }

    return Values.EMPTYSTRING;
}

From source file:de.fosd.jdime.artifact.file.FileArtifact.java

@Override
public void merge(MergeOperation<FileArtifact> operation, MergeContext context) {
    Objects.requireNonNull(operation, "operation must not be null!");
    Objects.requireNonNull(context, "context must not be null!");

    if (!exists()) {
        String className = getClass().getSimpleName();
        String filePath = file.getAbsolutePath();
        String message = String.format("Trying to merge %s whose file %s does not exist.", className, filePath);

        throw new RuntimeException(message);
    }//from www . j a  va2  s . c o  m

    if (isDirectory()) {
        Merge<FileArtifact> merge = new Merge<>();

        if (context.hasStatistics()) {
            context.getStatistics().setCurrentFileMergeScenario(operation.getMergeScenario());
        }

        LOG.finest(() -> "Merging directories " + operation.getMergeScenario());
        merge.merge(operation, context);
    } else {
        MergeStrategy<FileArtifact> strategy = context.getMergeStrategy();
        MergeScenario<FileArtifact> scenario = operation.getMergeScenario();

        if (!isJavaFile()) {
            LOG.fine(() -> "Skipping non-java file " + this);
            return;
        }

        if (context.hasStatistics()) {
            context.getStatistics().setCurrentFileMergeScenario(scenario);
        }

        try {
            try {
                strategy.merge(operation, context);
            } catch (Throwable e) {

                if (context.hasStatistics()) {
                    context.getStatistics().getScenarioStatistics(scenario).setStatus(FAILED);
                }

                throw e;
            }
        } catch (AbortException e) {
            throw e; // AbortExceptions must always cause the merge to be aborted
        } catch (RuntimeException e) {
            context.addCrash(scenario, e);

            LOG.log(SEVERE, e, () -> {
                String ls = System.lineSeparator();
                String scStr = operation.getMergeScenario().toString(ls, true);
                return String.format("Exception while merging%n%s", scStr);
            });

            if (context.isExitOnError()) {
                throw new AbortException(e);
            } else {

                if (!context.isKeepGoing() && !(strategy instanceof LinebasedStrategy)) {
                    LOG.severe(() -> "Falling back to line based strategy.");

                    context.setMergeStrategy(MergeStrategy.parse(MergeStrategy.LINEBASED).get());
                    merge(operation, context);
                } else {
                    LOG.severe(() -> "Skipping " + scenario);
                }
            }
        }
    }
}

From source file:io.cloudslang.lang.cli.SlangCliTest.java

@Test(timeout = DEFAULT_TIMEOUT)
public void testListSystemProperties() throws Exception {
    when(compilerHelperMock.loadSystemProperties(Lists.newArrayList("system_properties.prop.sl"))).thenReturn(
            Sets.newLinkedHashSet(Lists.newArrayList(new SystemProperty("namespace1", "key1", "value1", ""),
                    new SystemProperty("namespace2", "key2", "value2", ""),
                    new SystemProperty("namespace3", "key3", "value3", ""))));

    final CommandResult cr = shell.executeCommand("list --f system_properties.prop.sl");

    assertEquals("Following system properties were loaded:" + System.lineSeparator()
            + "\tnamespace1.key1: value1" + System.lineSeparator() + "\tnamespace2.key2: value2"
            + System.lineSeparator() + "\tnamespace3.key3: value3", cr.getResult());
    assertEquals("method threw exception", null, cr.getException());
    assertEquals("success should be true", true, cr.isSuccess());
}

From source file:com.opendoorlogistics.core.utils.strings.Strings.java

public static String getExceptionMessagesAsSingleStr(Throwable e) {
    StringBuilder b = new StringBuilder();
    for (String s : getExceptionMessages(e)) {
        b.append(s);//ww w.  jav a  2 s  .  c  o  m
        b.append(System.lineSeparator());
    }
    return b.toString();
}

From source file:dotaSoundEditor.Controls.EditorPanel.java

protected void revertButtonActionPerformed(ActionEvent evt, Path vpkToRevert) {
    //TODO: See if we can abstract away some of this functionality
    if (currentTree.getSelectionRows().length != 0
            && ((TreeNode) currentTree.getSelectionPath().getLastPathComponent()).isLeaf()) {
        DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) currentTree.getSelectionPath()
                .getLastPathComponent();
        String selectedWaveString = ((DefaultMutableTreeNode) selectedNode).getUserObject().toString();
        String selectedWaveParentString = ((DefaultMutableTreeNode) ((DefaultMutableTreeNode) selectedNode)
                .getParent()).getUserObject().toString();
        selectedNode = (DefaultMutableTreeNode) this.getTreeNodeFromWavePath(selectedWaveString);
        //First go in and delete the sound in customSounds
        deleteSoundFileByWaveString(selectedWaveString);
        //Get the relevant wavestring from the internal scriptfile
        VPKArchive vpk = new VPKArchive();
        try {/*from  ww w.  j  a  v  a2s  . c  o m*/
            vpk.load(new File(vpkToRevert.toString()));
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        String scriptDir = getCurrentScriptString();
        scriptDir = scriptDir.replace(Paths.get(installDir, "/dota/").toString(), "");
        scriptDir = scriptDir.replace("\\", "/"); //Match internal forward slashes
        scriptDir = scriptDir.substring(1); //Cut off leading slash
        byte[] bytes = null;
        VPKEntry entry = vpk.getEntry(scriptDir);
        try {
            ByteBuffer scriptBuffer = entry.getData();
            bytes = new byte[scriptBuffer.remaining()];
            scriptBuffer.get(bytes);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        String scriptFileString = new String(bytes, Charset.forName("UTF-8"));
        ArrayList<String> wavePathList = this.getWavePathsAsList(selectedNode.getParent());
        int waveStringIndex = wavePathList.indexOf(selectedWaveString);
        //Cut off every part of the scriptFileString before we get to the entry describing the relevant hero action, so we don't accidentally get the wrong wavepaths
        StringBuilder scriptFileStringShortened = new StringBuilder();
        Scanner scan = new Scanner(scriptFileString);
        boolean found = false;
        while (scan.hasNextLine()) {
            String curLine = scan.nextLine();
            if (curLine.equals(selectedWaveParentString)) {
                found = true;
            }
            if (found == true) {
                scriptFileStringShortened.append(curLine).append(System.lineSeparator());
            }
        }
        scriptFileString = scriptFileStringShortened.toString();
        ArrayList<String> internalWavePathsList = getWavePathListFromString(scriptFileString);
        String replacementString = internalWavePathsList.get(waveStringIndex);
        selectedNode.setUserObject(replacementString);
        ScriptParser parser = new ScriptParser(this.currentTreeModel);
        parser.writeModelToFile(getCurrentScriptString());
        //Modify the UI treeNode in addition to the backing TreeNode
        ((DefaultMutableTreeNode) currentTree.getLastSelectedPathComponent()).setUserObject(replacementString);
        ((DefaultTreeModel) currentTree.getModel())
                .nodeChanged((DefaultMutableTreeNode) currentTree.getLastSelectedPathComponent());
    }
}

From source file:com.opendoorlogistics.studio.AppFrame.java

private void importFile(SupportedFileType option) {
    // to do.. excel import needs to show progress dialog (as its slow)

    final JFileChooser chooser = option.createFileChooser();
    IOUtils.setFile(PreferencesManager.getSingleton().getLastImportFile(option), chooser);
    final ExecutionReport report = new ExecutionReportImpl();
    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        try {/*from   www.  j a  v a2 s  . c  o m*/
            PreferencesManager.getSingleton().setLastImportFile(chooser.getSelectedFile(), option);

            ODLDatastoreAlterable<ODLTableAlterable> imported = TableIOUtils
                    .importFile(chooser.getSelectedFile(), option, report);
            if (imported == null) {
                throw new RuntimeException();
            }

            if (loaded == null) {
                openEmptyDatastore();
            }

            if (!TableUtils.addDatastores(loaded.getDs(), imported, true)) {
                throw new RuntimeException();
            }

            for (int i = 0; i < imported.getTableCount(); i++) {
                ODLTableReadOnly table = imported.getTableAt(i);
                report.log("Imported table \"" + table.getName() + "\" with " + table.getRowCount()
                        + " rows and " + table.getColumnCount() + " columns.");
            }
            report.log("Imported " + imported.getTableCount() + " tables.");

        } catch (Throwable e) {
            report.setFailed(e);
            report.log("Error importing " + Strings.convertEnumToDisplayFriendly(option));
            report.log("Could not import file: " + chooser.getSelectedFile().getAbsolutePath());
            String message = report.getReportString(true, false);
            if (message.length() > 0) {
                message += System.lineSeparator();
            }
        }

        ExecutionReportDialog.show(this, "Import result", report);

    }
}

From source file:io.cloudslang.lang.cli.SlangCliTest.java

@Test(timeout = DEFAULT_TIMEOUT)
public void testPrintCompileErrors() {
    when(compilerHelperMock/*from ww  w.j a va 2  s  .  co m*/
            .compileSource(System.getProperty("user.dir") + File.separator + "some_slang_file.sl", null))
                    .thenReturn(new CompilationModellingResult(null, Lists.newArrayList(
                            new RuntimeException("1"), new RuntimeException("2"), new RuntimeException("3"))));

    final CommandResult cr = shell.executeCommand("compile --f some_slang_file.sl");
    Assert.assertNotNull(cr.getException());
    assertEquals("exception mismatch",
            "Following exceptions were found:" + System.lineSeparator()
                    + "\tclass java.lang.RuntimeException: 1" + System.lineSeparator()
                    + "\tclass java.lang.RuntimeException: 2" + System.lineSeparator()
                    + "\tclass java.lang.RuntimeException: 3" + System.lineSeparator(),
            cr.getException().getMessage());
}

From source file:com.pearson.eidetic.driver.threads.MonitorSnapshotVolumeTime.java

public boolean snapshotDecision(AmazonEC2Client ec2Client, Volume vol, String period) {
    if ((ec2Client == null) || (vol == null) || (period == null)) {
        return false;
    }/*from  ww  w .  j  a v a  2  s.  co  m*/
    try {

        List<Snapshot> int_snapshots = getAllSnapshotsOfVolume(ec2Client, vol,
                ApplicationConfiguration.getAwsCallRetryAttempts(), awsAccount_.getMaxApiRequestsPerSecond(),
                awsAccount_.getUniqueAwsAccountIdentifier());

        List<Snapshot> comparelist = new ArrayList();

        for (Snapshot snapshot : int_snapshots) {
            String desc = snapshot.getDescription();
            if ("week".equalsIgnoreCase(period) && desc.startsWith("week_snapshot")) {
                comparelist.add(snapshot);
            } else if ("day".equalsIgnoreCase(period) && desc.startsWith("day_snapshot")) {
                if (!desc.contains("snapshot checker")) {
                    comparelist.add(snapshot);
                }
            } else if ("hour".equalsIgnoreCase(period) && desc.startsWith("hour_snapshot")) {
                comparelist.add(snapshot);
            } else if ("month".equalsIgnoreCase(period) && desc.startsWith("month_snapshot")) {
                comparelist.add(snapshot);
            }
        }

        List<Snapshot> sortedCompareList = new ArrayList<>(comparelist);
        sortSnapshotsByDate(sortedCompareList);

        int hours = getHoursBetweenNowAndNewestSnapshot(sortedCompareList);
        int days = getDaysBetweenNowAndNewestSnapshot(sortedCompareList);

        if (("week".equalsIgnoreCase(period) && days < 0) || ("week".equalsIgnoreCase(period) && days >= 7)) {
        } else if (("hour".equalsIgnoreCase(period) && hours < 0)
                || ("hour".equalsIgnoreCase(period) && hours >= 1)) {
        } else if (("day".equalsIgnoreCase(period) && days < 0)
                || ("day".equalsIgnoreCase(period) && days >= 1)) {
        } else if (("month".equalsIgnoreCase(period) && days < 0)
                || ("month".equalsIgnoreCase(period) && days >= 30)) {
        } else {
            return false;
        }

    } catch (Exception e) {
        logger.info("awsAccountNickname=\"" + awsAccount_.getUniqueAwsAccountIdentifier()
                + "\",Event=\"Error\", Error=\"error in snapshotDecision\", stacktrace=\"" + e.toString()
                + System.lineSeparator() + StackTrace.getStringFromStackTrace(e) + "\"");
        return false;
    }

    return true;
}

From source file:de.fosd.jdime.artifact.file.FileArtifact.java

@Override
public FileArtifact createConflictArtifact(FileArtifact left, FileArtifact right) {
    // This is not a conflict introduced by concurrent modification of content,
    // but by deleting and changing a file (insertion-deletion conflict on file/directory level)

    FileArtifact deleted = left != null ? left : right;
    assert deleted != null;

    if (deleted.isFile()) {
        FileArtifact conflict = new FileArtifact(deleted);

        StringBuilder content = new StringBuilder();
        content.append(Content.Conflict.CONFLICT_START);
        if (deleted == left) {
            content.append(" ").append(deleted.getRevision());
        }//from   w  ww . ja v  a  2s . co m
        if (deleted == left) {
            content.append(System.lineSeparator()).append(deleted.content);
        }
        content.append(System.lineSeparator()).append(Content.Conflict.CONFLICT_DELIM);
        if (deleted == right) {
            content.append(System.lineSeparator()).append(deleted.content);
        }
        content.append(System.lineSeparator()).append(Content.Conflict.CONFLICT_END);
        if (deleted == right) {
            content.append(" ").append(deleted.getRevision());
        }
        content.append(System.lineSeparator());

        conflict.setContent(content.toString());

        return conflict;
    } else if (deleted.isDirectory()) {
        FileArtifact conflict = new FileArtifact(deleted);

        for (FileArtifact child : deleted.getChildren()) {
            if (deleted == left) {
                conflict.addChild(createConflictArtifact(child, null));
            } else if (deleted == right) {
                conflict.addChild(createConflictArtifact(null, child));
            } else {
                throw new RuntimeException("Both sides of conflict are null");
            }
        }

        return conflict;
    } else {
        throw new RuntimeException("FileArtifact " + deleted + " is neither file nor directory.");
    }
}

From source file:net.certifi.audittablegen.GenericDMR.java

String getAlterTableSQL(List<DBChangeUnit> op) {

    StringBuilder builder = new StringBuilder();
    StringBuilder constraints = new StringBuilder();
    DataTypeDef dataTypeDef = null;/* w ww .  j a v a2 s  .c om*/
    boolean firstCol = true;
    String schema;

    if (verifiedSchema != null) {
        schema = verifiedSchema + ".";
    } else {
        schema = "";
    }

    for (DBChangeUnit unit : op) {
        switch (unit.changeType) {
        case begin:
            //nothinig
            break;
        case end:
            builder.append(constraints);
            break;
        case alterTable:
            builder.append("ALTER TABLE ").append(schema).append(unit.tableName).append(System.lineSeparator());
            break;
        case addColumn:
            if (!firstCol) {
                builder.append(", ");
            } else {
                firstCol = false;
            }
            builder.append("ADD COLUMN ");

            dataTypeDef = getDataType(unit.typeName);

            if (unit.identity) {
                builder.append(unit.columnName).append(" ").append("serial PRIMARY KEY")
                        .append(System.lineSeparator());
            } else {
                builder.append(unit.columnName).append(" ").append(unit.typeName);
                //                        if (dataTypeDef.create_params != null &&  unit.size > 0){
                if (dataTypeDef.createWithSize && unit.size > 0) {
                    builder.append(" (").append(unit.size);

                    if (unit.decimalSize > 0) {
                        builder.append(",").append(unit.decimalSize);
                    }
                    builder.append(") ");
                }
                if (!unit.foreignTable.isEmpty()) {
                    builder.append("REFERENCES ").append(unit.foreignTable).append(" (").append(unit.columnName)
                            .append(")");
                    //constraints.append("CONSTRAINT ").append(unit.columnName).append(" REFERENCES ").append(unit.foreignTable);
                }
                builder.append(System.lineSeparator());
            }
            break;
        case alterColumnSize:
        case alterColumnType:
            if (!firstCol) {
                builder.append(", ");
            } else {
                firstCol = false;
            }
            builder.append("ALTER COLUMN ").append(unit.columnName).append(" TYPE ").append(unit.typeName);
            if (unit.size > 0) {
                builder.append(" (").append(unit.size);

                if (unit.decimalSize > 0) {
                    builder.append(",").append(unit.decimalSize);
                }
                builder.append(") ");
            }
            builder.append(System.lineSeparator());
            break;
        case alterColumnName:
            if (!firstCol) {
                builder.append(", ");
            } else {
                firstCol = false;
            }
            builder.append("RENAME COLUMN ").append(unit.columnName).append(" TO ").append(unit.newColumnName);
            builder.append(System.lineSeparator());

            break;
        default:
            //should not get here if the list is valid, unless a new changetype
            //was added that this DMR does not know about.  If which case - fail.
            logger.error("unimplemented DBChangeUnit {} for alter table operation",
                    unit.getChangeType().toString());
            return null;
        }
    }

    return builder.toString();

}