Example usage for java.lang String equals

List of usage examples for java.lang String equals

Introduction

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

Prototype

public boolean equals(Object anObject) 

Source Link

Document

Compares this string to the specified object.

Usage

From source file:edu.msu.cme.rdp.readseq.ToFasta.java

public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption("m", "mask", true, "Mask sequence name indicating columns to drop");
    String maskSeqid = null;/*from www.j av  a 2 s . c  om*/

    try {
        CommandLine line = new PosixParser().parse(options, args);

        if (line.hasOption("mask")) {
            maskSeqid = line.getOptionValue("mask");
        }

        args = line.getArgs();
        if (args.length == 0) {
            throw new Exception("");
        }

    } catch (Exception e) {
        new HelpFormatter().printHelp("USAGE: to-fasta <input-file>", options);
        System.err.println("ERROR: " + e.getMessage());
        System.exit(1);
        return;
    }

    SeqReader reader = null;

    FastaWriter out = new FastaWriter(System.out);
    Sequence seq;
    int totalSeqs = 0;
    long totalTime = System.currentTimeMillis();

    for (String fname : args) {
        if (fname.equals("-")) {
            reader = new SequenceReader(System.in);
        } else {
            File seqFile = new File(fname);

            if (maskSeqid == null) {
                reader = new SequenceReader(seqFile);
            } else {
                reader = new IndexedSeqReader(seqFile, maskSeqid);
            }
        }

        long startTime = System.currentTimeMillis();
        int thisFileTotalSeqs = 0;
        while ((seq = reader.readNextSequence()) != null) {
            out.writeSeq(seq.getSeqName().replace(" ", "_"), seq.getDesc(), seq.getSeqString());
            thisFileTotalSeqs++;
        }
        totalSeqs += thisFileTotalSeqs;
        System.err.println("Converted " + thisFileTotalSeqs + " (total sequences: " + totalSeqs
                + ") sequences from " + fname + " (" + reader.getFormat() + ") to fasta in "
                + (System.currentTimeMillis() - startTime) / 1000 + " s");
    }
    System.err.println("Converted " + totalSeqs + " to fasta in "
            + (System.currentTimeMillis() - totalTime) / 1000 + " s");

    out.close();
}

From source file:net.padlocksoftware.padlock.keymaker.Main.java

/**
 * @param args the command line arguments
 *///from w  w w  . j a v  a2 s .c  om
public static void main(String[] args) {

    int keySize = 1024;
    File file = null;

    if (args.length < 1 || args.length > 3) {
        showUsageAndExit();
    }

    for (int x = 0; x < args.length; x++) {
        String arg = args[x];

        if (arg.equals("-s")) {
            try {
                x++;
            } catch (Exception e) {
                showUsageAndExit();
            }
        } else {
            file = new File(arg);
        }
    }

    KeyPair pair = KeyManager.createKeyPair();
    try {
        KeyManager.exportKeyPair(pair, file);
        String[] lines = formatOutput(new String(Hex.encodeHex(pair.getPublic().getEncoded())));
        System.out.println("Your public key code: \n");
        for (int x = 0; x < lines.length; x++) {
            String line = lines[x];
            if (x == 0) {
                // First line
                System.out.println("\t private static final String publicKey = \n\t\t\"" + line + "\" + ");
            } else if (x == lines.length - 1) {
                // Last line
                System.out.println("\t\t\"" + line + "\";\n");
            } else {
                System.out.println("\t\t\"" + line + "\" + ");
            }
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) {
    String inputValue = JOptionPane.showInputDialog("Please input a value");

    if (inputValue == null) {
        System.out.println("CANCEL");
    } else if (inputValue.equals("")) {
        System.out.println("OK");
    } else {/*from  ww w  . ja v a2  s  .c om*/
        JOptionPane.showMessageDialog(null, inputValue);
    }
}

From source file:com.doctor.base64.CommonsCodecBase64.java

public static void main(String[] args) {
    String plainText = "Base64??"
            + "??ASCII???"
            + "????Base64";

    // ??//from  w w  w  .j a v a  2s .com
    String base64String = Base64.encodeBase64String(plainText.getBytes(StandardCharsets.UTF_8));
    System.out.println(base64String);

    String plainTxt = new String(Base64.decodeBase64(base64String), StandardCharsets.UTF_8);
    Preconditions.checkArgument(plainTxt.equals(plainText));

    // ??
    base64String = new String(Base64.encodeBase64Chunked(plainText.getBytes(StandardCharsets.UTF_8)),
            StandardCharsets.UTF_8);
    plainTxt = new String(Base64.decodeBase64(base64String), StandardCharsets.UTF_8);
    Preconditions.checkArgument(plainTxt.equals(plainText));

}

From source file:MainClass.java

public static void main(String args[]) {
    String s1 = "Hello";
    String s2 = "Hello";
    String s3 = "Goodbye";
    String s4 = "HELLO";
    System.out.println(s1 + " equals " + s2 + " -> " + s1.equals(s2));
    System.out.println(s1 + " equals " + s3 + " -> " + s1.equals(s3));
    System.out.println(s1 + " equals " + s4 + " -> " + s1.equals(s4));
}

From source file:MainClass.java

public static void main(String[] a) {
    final Display d = new Display();
    final Shell s = new Shell(d);

    s.setSize(250, 200);/*from  w  ww  .j av  a 2  s .c om*/
    s.setText("A Tree Shell Example");
    s.setLayout(new FillLayout(SWT.HORIZONTAL));
    final Tree t = new Tree(s, SWT.SINGLE | SWT.BORDER);
    final TreeItem child1 = new TreeItem(t, SWT.NONE, 0);
    child1.setText("1");
    //    child1.setImage(new Image(d, "c:\\icons\\folder.gif"));
    final TreeItem child2 = new TreeItem(t, SWT.NONE, 1);
    child2.setText("2");
    final TreeItem child2a = new TreeItem(child2, SWT.NONE, 0);
    child2a.setText("2A");
    final TreeItem child2b = new TreeItem(child2, SWT.NONE, 1);
    child2b.setText("2B");
    final TreeItem child3 = new TreeItem(t, SWT.NONE, 2);
    child3.setText("3");

    final List l = new List(s, SWT.BORDER | SWT.SINGLE);

    t.addTreeListener(new TreeListener() {
        public void treeExpanded(TreeEvent e) {
            TreeItem ti = (TreeItem) e.item;
            //      ti.setImage(new Image(d, "c:\\icons\\open.gif"));
        }

        public void treeCollapsed(TreeEvent e) {
            TreeItem ti = (TreeItem) e.item;
            //        ti.setImage(new Image(d, "c:\\icons\\folder.gif"));
        }
    });

    t.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            TreeItem ti = (TreeItem) e.item;
            populateList(ti.getText());
        }

        private void populateList(String type) {
            if (type.equals("1")) {
                l.removeAll();
                l.add("1");
                l.add("2");
            }
            if (type.equals("2")) {
                l.removeAll();
            }
            if (type.equals("2A")) {
                l.removeAll();
                l.add("3");
                l.add("4");
            }
            if (type.equals("2B")) {
                l.removeAll();
                l.add("5");
                l.add("6");
            }
            if (type.equals("3")) {
                l.removeAll();
                l.add("7");
                l.add("8");
            }
        }
    });

    s.open();
    while (!s.isDisposed()) {
        if (!d.readAndDispatch())
            d.sleep();
    }
    d.dispose();
}

From source file:JRadioButtonSelectedElements.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Grouping Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel panel = new JPanel(new GridLayout(0, 1));

    ButtonGroup group = new ButtonGroup();
    JRadioButton aRadioButton = new JRadioButton("A");
    JRadioButton bRadioButton = new JRadioButton("B");

    ActionListener crustActionListener = new ActionListener() {
        String lastSelected;//from ww  w. j  a va  2s .c om

        public void actionPerformed(ActionEvent actionEvent) {
            AbstractButton aButton = (AbstractButton) actionEvent.getSource();
            String label = aButton.getText();
            String msgStart;
            if (label.equals(lastSelected)) {
                msgStart = "Reselected: ";
            } else {
                msgStart = "Selected: ";
            }
            lastSelected = label;
            System.out.println(msgStart + label);
        }
    };

    panel.add(aRadioButton);
    group.add(aRadioButton);
    panel.add(bRadioButton);
    group.add(bRadioButton);

    aRadioButton.addActionListener(crustActionListener);
    bRadioButton.addActionListener(crustActionListener);

    frame.add(panel);
    frame.setSize(300, 200);
    frame.setVisible(true);

    System.out.println(getSelectedElements(panel).hasMoreElements());
}

From source file:Main.java

public static void main(String... args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel contentPane = new JPanel();

    JFormattedTextField ftf = new JFormattedTextField(NumberFormat.getNumberInstance());
    ftf.setColumns(10);/*from  ww  w.ja  va2 s.  com*/
    ftf.setFocusLostBehavior(JFormattedTextField.PERSIST);
    ftf.setValue(100);
    lastValidValue = "100";
    ftf.addCaretListener(e -> {
        System.out.println("Last Valid Value : " + lastValidValue);
        if (ftf.isEditValid()) {
            String latestValue = ftf.getText();
            System.out.println("Latest Value : " + latestValue);
            if (!(latestValue.equals(lastValidValue)))
                ftf.setBackground(Color.YELLOW.darker());
            else {
                lastValidValue = ftf.getText();
                ftf.setBackground(Color.WHITE);
            }
        } else {
            System.out.println("Invalid Edit Entered.");
        }
    });
    contentPane.add(ftf);
    frame.setContentPane(contentPane);
    frame.pack();
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    ServerSocket ss = new ServerSocket(80);
    while (true) {
        Socket s = ss.accept();/*w  w  w  .java2s. co  m*/
        PrintStream out = new PrintStream(s.getOutputStream());
        BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
        String info = null;
        while ((info = in.readLine()) != null) {
            System.out.println("now got " + info);
            if (info.equals(""))
                break;
        }
        out.println("HTTP/1.0 200 OK");
        out.println("MIME_version:1.0");
        out.println("Content_Type:text/html");
        String c = "<html> <head></head><body> <h1> hi</h1></Body></html>";
        out.println("Content_Length:" + c.length());
        out.println("");
        out.println(c);
        out.close();
        s.close();
        in.close();
    }
}

From source file:UdpEchoClient.java

public static void main(String[] args) {
    InetAddress address;/*from  w ww  .  j  a v a2 s . c o m*/
    try {
        address = InetAddress.getByName(args[0]);
    } catch (UnknownHostException host) {
        System.out.println(host);
        return;
    }
    DatagramPacket pack = new DatagramPacket(testString.getBytes(), testString.length(), address, 7);
    DatagramPacket incoming = new DatagramPacket(new byte[256], 256);
    DatagramSocket sock = null;
    try {
        Calendar start, end;
        sock = new DatagramSocket();
        start = Calendar.getInstance();
        sock.send(pack);
        sock.setSoTimeout(5000);
        sock.receive(incoming);
        end = Calendar.getInstance();
        String reply = new String(incoming.getData());
        reply = reply.substring(0, testString.length());
        if (reply.equals(testString)) {
            System.out.println("Success");
            System.out.println("Time = " + (end.getTime().getTime() - start.getTime().getTime()) + "mS");
        } else
            System.out.println("Reply data did not match");
    } catch (SocketException socke) {
        System.out.println(socke);
    } catch (IOException ioe) {
        System.out.println(ioe);
    } finally {
        sock.close();
    }
}