Search in sources :

Example 61 with NoSuchElementException

use of java.util.NoSuchElementException in project GDSC-SMLM by aherbert.

the class PeakResultsReader method createTableResultV1.

private PeakResult createTableResultV1(String line) {
    // [Precision] 
    try {
        Scanner scanner = new Scanner(line);
        scanner.useDelimiter(tabPattern);
        scanner.useLocale(Locale.US);
        int id = 0, endPeak = 0;
        if (readId)
            id = scanner.nextInt();
        if (readSource)
            scanner.next();
        int peak = scanner.nextInt();
        if (readEndFrame)
            endPeak = scanner.nextInt();
        int origX = scanner.nextInt();
        int origY = scanner.nextInt();
        float origValue = scanner.nextFloat();
        double error = scanner.nextDouble();
        float noise = scanner.nextFloat();
        @SuppressWarnings("unused") float // Ignored but must be read
        signal = scanner.nextFloat();
        @SuppressWarnings("unused") float // Ignored but must be read
        snr = scanner.nextFloat();
        float[] params = new float[7];
        float[] paramsStdDev = (deviations) ? new float[7] : null;
        for (int i = 0; i < params.length; i++) {
            params[i] = scanner.nextFloat();
            if (deviations)
                paramsStdDev[i] = scanner.nextFloat();
        }
        scanner.close();
        // For the new format we store the signal (not the amplitude).
        // Convert the amplitude into a signal
        params[Gaussian2DFunction.SIGNAL] *= 2 * Math.PI * params[Gaussian2DFunction.X_SD] * params[Gaussian2DFunction.Y_SD];
        if (readId || readEndFrame)
            return new ExtendedPeakResult(peak, origX, origY, origValue, error, noise, params, paramsStdDev, endPeak, id);
        else
            return new PeakResult(peak, origX, origY, origValue, error, noise, params, paramsStdDev);
    } catch (InputMismatchException e) {
    } catch (NoSuchElementException e) {
    }
    return null;
}
Also used : Scanner(java.util.Scanner) InputMismatchException(java.util.InputMismatchException) NoSuchElementException(java.util.NoSuchElementException)

Example 62 with NoSuchElementException

use of java.util.NoSuchElementException 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;
}
Also used : Scanner(java.util.Scanner) InputMismatchException(java.util.InputMismatchException) NoSuchElementException(java.util.NoSuchElementException)

Example 63 with NoSuchElementException

use of java.util.NoSuchElementException in project wire-android by wireapp.

the class BackendPicker method getCustomBackend.

@Nullable
private BackendConfig getCustomBackend() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    String backend = prefs.getString(CUSTOM_BACKEND_PREFERENCE, null);
    if (backend != null) {
        try {
            return BackendConfig.byName().apply(backend);
        } catch (NoSuchElementException ex) {
            Timber.w("Could not find backend with name: %s", backend);
        }
    }
    return null;
}
Also used : SharedPreferences(android.content.SharedPreferences) NoSuchElementException(java.util.NoSuchElementException) Nullable(android.support.annotation.Nullable)

Example 64 with NoSuchElementException

use of java.util.NoSuchElementException 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");
}
Also used : Scanner(java.util.Scanner) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) InputMismatchException(java.util.InputMismatchException) Point(java.awt.Point) Trace(gdsc.smlm.results.Trace) GenericDialog(ij.gui.GenericDialog) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) NoSuchElementException(java.util.NoSuchElementException)

Example 65 with NoSuchElementException

use of java.util.NoSuchElementException in project aries by apache.

the class AbstractJPATransactionTest method getService.

protected <T> T getService(Class<T> clazz, String filter, long timeout) throws InvalidSyntaxException {
    Filter f = FrameworkUtil.createFilter(filter == null ? "(|(foo=bar)(!(foo=bar)))" : filter);
    ServiceTracker<T, T> tracker = new ServiceTracker<T, T>(context, clazz, null) {

        @Override
        public T addingService(ServiceReference<T> reference) {
            return f.match(reference) ? super.addingService(reference) : null;
        }
    };
    tracker.open();
    try {
        T t = tracker.waitForService(timeout);
        if (t == null) {
            throw new NoSuchElementException(clazz.getName());
        }
        return t;
    } catch (InterruptedException e) {
        throw new RuntimeException("Error waiting for service " + clazz.getName(), e);
    } finally {
        trackers.add(tracker);
    }
}
Also used : Filter(org.osgi.framework.Filter) ServiceTracker(org.osgi.util.tracker.ServiceTracker) NoSuchElementException(java.util.NoSuchElementException) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

NoSuchElementException (java.util.NoSuchElementException)1629 Iterator (java.util.Iterator)234 ArrayList (java.util.ArrayList)138 IOException (java.io.IOException)137 Test (org.junit.Test)95 StringTokenizer (java.util.StringTokenizer)88 Scanner (java.util.Scanner)86 Map (java.util.Map)56 List (java.util.List)54 File (java.io.File)51 HashMap (java.util.HashMap)47 InputMismatchException (java.util.InputMismatchException)47 LinkedList (java.util.LinkedList)32 HashSet (java.util.HashSet)31 Set (java.util.Set)29 CorruptDataException (com.ibm.j9ddr.CorruptDataException)28 Locale (java.util.Locale)27 Collection (java.util.Collection)26 BufferedReader (java.io.BufferedReader)24 Enumeration (java.util.Enumeration)24