Example usage for java.lang RuntimeException RuntimeException

List of usage examples for java.lang RuntimeException RuntimeException

Introduction

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

Prototype

public RuntimeException() 

Source Link

Document

Constructs a new runtime exception with null as its detail message.

Usage

From source file:GetColor.java

static public void main(String[] args) {
    Rabbit rabbit = new Rabbit();
    //start extract snippet3
    setObjectColor(rabbit, Color.WHITE);
    //stop extract snippet3
    if (!rabbit.setColorCalled)
        throw new RuntimeException();
}

From source file:CatchAllThreadExceptionHandler.java

public static void main(String[] args) {
    CatchAllThreadExceptionHandler handler = new CatchAllThreadExceptionHandler();

    // Set an uncaught exception handler for main thread
    Thread.currentThread().setUncaughtExceptionHandler(handler);

    // Throw an exception
    throw new RuntimeException();
}

From source file:com.novadart.silencedetect.SilenceDetect.java

public static void main(String[] args) {

    // create the parser
    CommandLineParser parser = new BasicParser();
    try {/*from  w  w w. j av a  2  s  . co m*/
        // parse the command line arguments
        CommandLine line = parser.parse(OPTIONS, args);

        if (line.hasOption("h")) {

            printHelp();

        } else {

            String decibels = "-10";
            if (line.hasOption("b")) {
                decibels = "-" + line.getOptionValue("b");
            } else {
                throw new RuntimeException();
            }

            String videoFile = null;

            if (line.hasOption("i")) {

                videoFile = line.getOptionValue("i");

                Boolean debug = line.hasOption("d");

                if (line.hasOption("t")) {

                    System.out.println(printAudioTracksList(videoFile, debug));

                } else if (line.hasOption("s")) {

                    int trackNumber = Integer.parseInt(line.getOptionValue("s"));
                    System.out.println(printAudioTrackSilenceDuration(videoFile, trackNumber, decibels, debug));

                } else {

                    printHelp();

                }

            } else if (line.hasOption("-j")) {

                // choose file
                final JFileChooser fc = new JFileChooser();
                fc.setVisible(true);
                int returnVal = fc.showOpenDialog(null);
                if (returnVal == JFileChooser.APPROVE_OPTION) {

                    videoFile = fc.getSelectedFile().getAbsolutePath();

                } else {
                    return;
                }

                JTextArea tracks = new JTextArea();
                tracks.setText(printAudioTracksList(videoFile, true));
                JSpinner trackNumber = new JSpinner();
                trackNumber.setValue(1);
                final JComponent[] inputs = new JComponent[] { new JLabel("Audio Tracks"), tracks,
                        new JLabel("Track to analyze"), trackNumber };
                JOptionPane.showMessageDialog(null, inputs, "Select Audio Track", JOptionPane.PLAIN_MESSAGE);

                JTextArea results = new JTextArea();
                results.setText(printAudioTrackSilenceDuration(videoFile, (int) trackNumber.getValue(),
                        decibels, false));
                final JComponent[] resultsInputs = new JComponent[] { new JLabel("Results"), results };
                JOptionPane.showMessageDialog(null, resultsInputs, "RESULTS!", JOptionPane.PLAIN_MESSAGE);

            } else {
                printHelp();
                return;
            }

        }

    } catch (ParseException | IOException | InterruptedException exp) {
        // oops, something went wrong
        System.out.println("There was a problem :(\nReason: " + exp.getMessage());
    }
}

From source file:cc.redberry.core.performance.ProductBijectionPerformanceTest.java

public static void main(String[] args) {
    int badCounter = 0;
    //        CC.resetTensorNames(-3912578993076521674L);
    RandomTensor rp = new RandomTensor(4, 10, new int[] { 4, 0, 0, 0 }, new int[] { 10, 0, 0, 0 }, false);
    rp.reset(-3806751651286565680L);/*from w w  w. j av a  2 s.  co  m*/
    System.out.println("Random Seed = " + rp.getSeed());
    System.out.println("NM Seed = " + CC.getNameManager().getSeed());
    DescriptiveStatistics timeStats = new DescriptiveStatistics();
    DescriptiveStatistics trysStats = new DescriptiveStatistics();
    int count = 0;
    while (++count < 500) {
        //            CC.resetTensorNames();
        Tensor t = rp.nextProduct(15);
        if (!(t instanceof Product))
            continue;

        Product from = (Product) t;

        long start = System.nanoTime();
        ProductsBijectionsPort port = new ProductsBijectionsPort(from.getContent(), from.getContent());

        int[] bijection;
        boolean good = false;
        int trys = 0;
        OUTER: while (trys++ < 5000 && (bijection = port.take()) != null) {
            for (int i = 0; i < bijection.length; ++i)
                if (bijection[i] != i)
                    continue OUTER;
            good = true;
            break;
        }

        double millis = 1E-6 * (System.nanoTime() - start);
        timeStats.addValue(millis);
        trysStats.addValue(trys);

        if (!good)
            throw new RuntimeException();
    }
    System.out.println(timeStats);
    System.out.println(trysStats);
}

From source file:gedi.lfc.quick.ShiroguchiCounter.java

public static void main(String[] args) throws IOException {

    String path = "/home/users/erhard/biostor/seq/ngade/shiroguchi_randombarcodes/data/";

    MemoryIntervalTreeStorage<int[]> reads = new MemoryIntervalTreeStorage<int[]>(int[].class);

    String[] files = { "Shiroguchi_A_collapsed.bed", "Shiroguchi_B_collapsed.bed",
            "Shiroguchi_A_uncollapsed.bed", "Shiroguchi_B_uncollapsed.bed" };
    for (int i = 0; i < 4; i++) {
        Iterator<String> it = new LineOrientedFile(path + files[i]).lineIterator();
        while (it.hasNext()) {
            String[] f = StringUtils.split(it.next(), '\t');
            Chromosome chr = Chromosome.obtain(f[0]);
            ArrayGenomicRegion region = new ArrayGenomicRegion(Integer.parseInt(f[1]), Integer.parseInt(f[2]));
            int c = Integer.parseInt(StringUtils.splitField(f[3], '|', 0));

            int[] counts = reads.getData(chr, region);
            if (counts == null)
                reads.add(chr, region, counts = new int[4]);

            counts[i] += c;/*from ww  w.  ja va  2  s . c o  m*/
        }
    }

    HashMap<String, String> map = new HashMap<String, String>();
    new LineOrientedFile(path + "U00096.2.genes.csv").lineIterator().forEachRemaining(s -> {
        String[] f = StringUtils.split(s, '\t');
        map.put(f[0], f[7]);
    });

    LineOrientedFile fragments = new LineOrientedFile("fragments.csv");
    fragments.startWriting();
    fragments.writef("Gene\tonlyA\tonlyB\tBoth\tLength\n");

    LineOrientedFile bias = new LineOrientedFile("bias.csv");
    bias.startWriting();
    bias.writef("OriginalA\tBiasA\tOriginalB\tBiasB\n");

    IntArrayList biasFactors = new IntArrayList();
    ArrayList<GeneData> geneData = new ArrayList<GeneData>();

    MemoryIntervalTreeStorage<Transcript> genes = new BiomartExonFileReader(path + "U00096.2.exons.csv", false)
            .readIntoMemoryTakeFirst();
    for (ImmutableReferenceGenomicRegion<Transcript> g : genes.getReferenceGenomicRegions()) {
        ArrayList<ImmutableReferenceGenomicRegion<int[]>> frag = reads
                .getReferenceRegionsIntersecting(g.getReference().toStrandIndependent(), g.getRegion());

        GeneData gd = new GeneData();

        int l = g.getRegion().getTotalLength();
        for (ImmutableReferenceGenomicRegion<int[]> r : frag) {
            if (r.getData()[0] == 0)
                gd.onlyB++;
            if (r.getData()[1] == 0)
                gd.onlyA++;
            if (r.getData()[0] == 0 && r.getData()[1] == 0)
                throw new RuntimeException();

            bias.writef("%d\t%.0f\t%d\t%.0f\n", r.getData()[0], r.getData()[2] / (double) r.getData()[0],
                    r.getData()[1], r.getData()[3] / (double) r.getData()[1]);
            if (r.getData()[0] > 0) {
                biasFactors.add(r.getData()[2] / r.getData()[0]);
            }
            if (r.getData()[1] > 0) {
                biasFactors.add(r.getData()[3] / r.getData()[1]);
            }

        }
        gd.both = frag.size() - gd.onlyA - gd.onlyB;
        fragments.writef("%s\t%d\t%d\t%d\t%d\n", map.get(g.getData().getTranscriptId()), gd.onlyA, gd.onlyB,
                gd.both, l);

        if (gd.onlyA + gd.onlyB + gd.both > 0)
            geneData.add(gd);
    }

    fragments.finishWriting();
    bias.finishWriting();

    double fc = 1.4;
    int rep = 5;
    int nDiff = 1000;
    int n = 10000;
    int N = 6000;
    double noise = 0.05;

    LineOrientedFile countMatrix = new LineOrientedFile("countMatrix.csv");
    countMatrix.startWriting();

    LineOrientedFile downCountMatrix = new LineOrientedFile("countMatrix_downsampled.csv");
    downCountMatrix.startWriting();

    RandomNumbers rnd = new RandomNumbers();
    for (int i = 0; i < n; i++) {
        GeneData gd = geneData.get(rnd.getUnif(0, geneData.size()));

        //         int N = gd.both==0?Integer.MAX_VALUE/2:(int) (gd.onlyA+gd.onlyB+gd.both+gd.onlyA*gd.onlyB/gd.both);
        double p1 = (gd.onlyA + gd.both) / (double) N;
        double p2 = i < nDiff ? p1 / fc : p1;

        ArrayList<ReadData> list = new ArrayList<ReadData>();
        for (int r = 0; r < rep * 2; r++) {
            int k = rnd.getBinom(N, r < rep ? p1 : p2) + 1;
            int hit = N == -1 ? 0 : rnd.getBinom(k, list.size() / (double) N);
            rnd.shuffle(list);
            for (int x = 0; x < hit; x++)
                list.get(x).reads[r] = (int) rnd.getNormal(list.get(x).bias, list.get(x).bias * noise);
            for (int x = 0; x < k - hit; x++)
                list.add(new ReadData(biasFactors.getInt(rnd.getUnif(0, biasFactors.size())), rep * 2, r));
        }

        int[] c = new int[rep * 2];
        for (ReadData d : list) {
            for (int r = 0; r < c.length; r++) {
                c[r] += d.reads[r];
            }
        }

        double[] down = new double[rep * 2];
        for (ReadData d : list) {
            double max = ArrayUtils.max(d.reads);
            for (int r = 0; r < down.length; r++) {
                down[r] += d.reads[r] / max;
            }
        }

        countMatrix.writeLine(StringUtils.concat("\t", c));
        downCountMatrix.writeLine(StringUtils.concat("\t", down));

    }

    countMatrix.finishWriting();
    downCountMatrix.finishWriting();

}

From source file:com.otz.plugin.transport.funnel.FunnelService.java

public static void main(String[] args) {
    List<String> test = new ArrayList<>();
    test.add("1");
    test.add("2");
    test.add("3");

    String result = Observable.from(test).filter(s -> s.equals("4")).first()
            .onErrorResumeNext(Observable.error(new RuntimeException())).flatMap(s -> {
                System.out.println(s);
                return Observable.just(s);
            }).toBlocking().single();//from  w  w  w .  j a  v a  2 s . c  o  m

    System.out.println(result);
}

From source file:Main.java

public static void sleep(long millis) {
    try {/*w w w .  j a v  a2  s  . c o m*/
        Thread.sleep(millis);
    } catch (InterruptedException e) {
        throw new RuntimeException();
    }
}

From source file:Main.java

/**
 * Wrapper over newSingleThreadExecutor.
 * @param threadName (undocumented)/*  ww  w  . j  av  a 2s .c o m*/
 * @return (undocumented)
 */
static public java.util.concurrent.ExecutorService newDaemonSingleThreadExecutor(java.lang.String threadName) {
    throw new RuntimeException();
}

From source file:Main.java

/**
 * Create a thread factory that names threads with a prefix and also sets the threads to daemon.
 * @param prefix (undocumented)/*from   w ww.  j a  va 2s.c o m*/
 * @return (undocumented)
 */
static public java.util.concurrent.ThreadFactory namedThreadFactory(java.lang.String prefix) {
    throw new RuntimeException();
}

From source file:Main.java

/**
 * Wrapper over ScheduledThreadPoolExecutor.
 * @param threadName (undocumented)/*  w w w. jav  a 2 s .c om*/
 * @return (undocumented)
 */
static public java.util.concurrent.ScheduledExecutorService newDaemonSingleThreadScheduledExecutor(
        java.lang.String threadName) {
    throw new RuntimeException();
}