use of java.util.InputMismatchException in project GDSC-SMLM by aherbert.
the class PeakResultsReader method createPeakResultV1.
private PeakResult createPeakResultV1(String line) {
try {
float[] params = new float[7];
if (isUseScanner()) {
// Code using a Scanner
Scanner scanner = new Scanner(line);
scanner.useDelimiter(tabPattern);
scanner.useLocale(Locale.US);
int id = 0, endPeak = 0;
if (readId)
id = scanner.nextInt();
int peak = scanner.nextInt();
if (readEndFrame)
endPeak = scanner.nextInt();
int origX = scanner.nextInt();
int origY = scanner.nextInt();
float origValue = scanner.nextFloat();
double chiSquared = scanner.nextDouble();
float noise = scanner.nextFloat();
// Ignored but must be read
float signal = scanner.nextFloat();
for (int i = 0; i < params.length; i++) {
params[i] = scanner.nextFloat();
}
scanner.close();
params[Gaussian2DFunction.SIGNAL] = signal;
if (readId || readEndFrame)
return new ExtendedPeakResult(peak, origX, origY, origValue, chiSquared, noise, params, null, endPeak, id);
else
return new PeakResult(peak, origX, origY, origValue, chiSquared, noise, params, null);
} else {
// Code using split and parse
String[] fields = tabPattern.split(line);
int j = 0;
int id = (readId) ? Integer.parseInt(fields[j++]) : 0;
int peak = Integer.parseInt(fields[j++]);
int endPeak = (readEndFrame) ? Integer.parseInt(fields[j++]) : 0;
int origX = Integer.parseInt(fields[j++]);
int origY = Integer.parseInt(fields[j++]);
float origValue = Float.parseFloat(fields[j++]);
double chiSquared = Double.parseDouble(fields[j++]);
float noise = Float.parseFloat(fields[j++]);
float signal = Float.parseFloat(fields[j++]);
for (int i = 0; i < params.length; i++) {
params[i] = Float.parseFloat(fields[j++]);
}
params[Gaussian2DFunction.SIGNAL] = signal;
if (readId || readEndFrame)
return new ExtendedPeakResult(peak, origX, origY, origValue, chiSquared, noise, params, null, endPeak, id);
else
return new PeakResult(peak, origX, origY, origValue, chiSquared, noise, params, null);
}
} catch (InputMismatchException e) {
} catch (NoSuchElementException e) {
} catch (IndexOutOfBoundsException e) {
} catch (NumberFormatException e) {
}
return null;
}
use of java.util.InputMismatchException in project GDSC-SMLM by aherbert.
the class SpotAnalysis method saveTraces.
private void saveTraces() {
if (!onFrames.isEmpty() && updated) {
GenericDialog gd = new GenericDialog(TITLE);
gd.enableYesNoCancel();
gd.hideCancelButton();
gd.addMessage("The list contains unsaved selected frames.\n \nDo you want to continue?");
gd.showDialog();
if (!gd.wasOKed())
return;
}
// For all spots in the results window, get the ID and then save the traces to memory
if (!resultsWindowShowing())
return;
// Create a results set in memory
MemoryPeakResults results = new MemoryPeakResults();
results.setName(TITLE);
results.begin();
MemoryPeakResults.addResults(results);
ArrayList<TraceResult> traceResults = new ArrayList<TraceResult>(resultsWindow.getTextPanel().getLineCount());
for (int i = 0; i < resultsWindow.getTextPanel().getLineCount(); i++) {
String line = resultsWindow.getTextPanel().getLine(i);
Scanner s = new Scanner(line);
s.useDelimiter("\t");
int id = -1;
double signal = -1;
// Be careful as the text panel may not contain what we expect, i.e. empty lines, etc
if (s.hasNextInt()) {
id = s.nextInt();
try {
// cx
s.nextDouble();
// cy
s.nextDouble();
signal = s.nextDouble();
} catch (InputMismatchException e) {
// Ignore
} catch (NoSuchElementException e) {
// Ignore
}
}
s.close();
if (id != -1 && signal != -1) {
Trace trace = traces.get(id);
if (trace != null) {
results.addAll(trace.getPoints());
traceResults.add(new TraceResult(new Spot(id, signal), trace));
}
}
}
results.end();
saveTracesToFile(traceResults);
IJ.showStatus("Saved traces");
}
use of java.util.InputMismatchException in project wildfly by wildfly.
the class VaultTool method main.
public static void main(String[] args) {
VaultTool tool = null;
if (args != null && args.length > 0) {
int returnVal = 0;
try {
tool = new VaultTool(args);
returnVal = tool.execute();
} catch (Exception e) {
System.err.println(SecurityLogger.ROOT_LOGGER.problemOcurred());
e.printStackTrace(System.err);
System.exit(1);
}
System.exit(returnVal);
} else {
tool = new VaultTool();
System.out.println("**********************************");
System.out.println("**** JBoss Vault ***************");
System.out.println("**********************************");
Console console = System.console();
if (console == null) {
System.err.println(SecurityLogger.ROOT_LOGGER.noConsole());
System.exit(1);
}
Scanner in = new Scanner(System.in);
while (true) {
System.out.println(SecurityLogger.ROOT_LOGGER.interactiveCommandString());
try {
int choice = in.nextInt();
switch(choice) {
case 0:
System.out.println(SecurityLogger.ROOT_LOGGER.startingInteractiveSession());
VaultInteractiveSession vsession = new VaultInteractiveSession();
tool.setSession(vsession);
vsession.start();
break;
case 1:
System.out.println(SecurityLogger.ROOT_LOGGER.removingInteractiveSession());
tool.setSession(null);
break;
default:
in.close();
System.exit(0);
}
} catch (InputMismatchException e) {
in.close();
System.exit(0);
}
}
}
}
use of java.util.InputMismatchException in project robovm by robovm.
the class ScannerTest method test_nextBoolean.
/**
* @throws IOException
* @tests java.util.Scanner#nextBoolean()
*/
public void test_nextBoolean() throws IOException {
// case insensitive
s = new Scanner("TRue");
assertTrue(s.nextBoolean());
s = new Scanner("tRue false");
assertTrue(s.nextBoolean());
assertFalse(s.nextBoolean());
try {
s.nextBoolean();
fail();
} catch (NoSuchElementException expected) {
}
s = new Scanner("true1");
try {
s.nextBoolean();
fail();
} catch (InputMismatchException expected) {
}
try {
s = new Scanner("");
s.nextBoolean();
fail();
} catch (NoSuchElementException expected) {
}
// test socket inputStream
os.write("true false".getBytes());
serverSocket.close();
s = new Scanner(client);
assertTrue(s.nextBoolean());
assertFalse(s.nextBoolean());
// ues '*' as delimiter
s = new Scanner("true**false").useDelimiter("\\*");
assertTrue(s.nextBoolean());
try {
s.nextBoolean();
fail();
} catch (NoSuchElementException expected) {
}
s = new Scanner("false( )").useDelimiter("\\( \\)");
assertFalse(s.nextBoolean());
}
use of java.util.InputMismatchException in project robovm by robovm.
the class ScannerTest method test_nextByteI.
/**
* @throws IOException
* @tests java.util.Scanner#nextByte(int)
*/
public void test_nextByteI() throws IOException {
s = new Scanner("123 126");
assertEquals(123, s.nextByte(10));
assertEquals(126, s.nextByte(10));
try {
s.nextByte(10);
fail();
} catch (NoSuchElementException expected) {
}
// If the radix is different from 10
s = new Scanner("123 126");
assertEquals(38, s.nextByte(5));
try {
s.nextByte(5);
fail();
} catch (InputMismatchException expected) {
}
// If the number is out of range
s = new Scanner("1234");
try {
s.nextByte(10);
fail();
} catch (InputMismatchException expected) {
}
/*
* The input string has Arabic-Indic digits.
*/
s = new Scanner("1٠2 12٦");
assertEquals(102, s.nextByte(10));
try {
s.nextByte(5);
fail();
} catch (InputMismatchException expected) {
}
assertEquals(126, s.nextByte(10));
s = new Scanner("012");
assertEquals(12, s.nextByte(10));
s = new Scanner("E");
assertEquals(14, s.nextByte(16));
/*
* There are 3 types of zero digit in all locales, '0' '०' '๐'
* respectively, but they are not differentiated.
*/
s = new Scanner("100");
s.useLocale(Locale.CHINESE);
assertEquals(100, s.nextByte(10));
s = new Scanner("1००");
s.useLocale(Locale.CHINESE);
assertEquals(100, s.nextByte(10));
s = new Scanner("1๐๐");
s.useLocale(Locale.CHINESE);
assertEquals(100, s.nextByte(10));
s = new Scanner("-123");
s.useLocale(new Locale("ar", "AE"));
assertEquals(-123, s.nextByte(10));
s = new Scanner("-123");
s.useLocale(new Locale("mk", "MK"));
assertEquals(-123, s.nextByte(10));
}
Aggregations