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:MainClass.java

public static void main(String args[]) throws Exception {
    SSLServerSocketFactory ssf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
    SSLServerSocket ss = (SSLServerSocket) ssf.createServerSocket(443);
    ss.setNeedClientAuth(true);/*from  w w  w.  j ava  2  s. co m*/
    while (true) {
        Socket s = ss.accept();

        SSLSession session = ((SSLSocket) s).getSession();
        Certificate[] cchain = session.getPeerCertificates();
        for (int j = 0; j < cchain.length; j++) {
            System.out.println(((X509Certificate) cchain[j]).getSubjectDN());
        }
        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\nMIME_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:animalclient.AnimalClient.java

/**
 * @param args the command line arguments
 *///from   ww w  .j a  v a 2s .c om
public static void main(String[] arg) throws IOException, MalformedURLException, ParseException {
    // TODO code application logic here
    InputStreamReader isr = new InputStreamReader(System.in);
    BufferedReader br = new BufferedReader(isr);

    String username;
    String password;

    System.out.println("Username:");
    username = br.readLine();
    System.out.println("Password:");
    password = br.readLine();

    AnimalJerseyClient client = new AnimalJerseyClient(username, password);

    System.out.println("");
    System.out.println(
            "Willkommen bei ihrer Tierhandlung fr exotische Tiere. Geben sie help ein fr weitere Informationen");

    String auswahl = br.readLine();

    if (auswahl.equals("help")) {
        System.out.println("Sie haben folgende Auswahlmglichkeiten:");
        System.out.println("1. Listen sie alle verfgbaren Tiere auf.");
        System.out.println("2. Kaufen sie ein Tier.");
        System.out.println("3. Suchen sie nach einem Tier.");
        System.out.println("4. Whrung ndern.");
        auswahl = br.readLine();
        makeDecision(client, auswahl);
    } else {
        makeDecision(client, auswahl);
    }

    System.out.print("End");
}

From source file:Main.java

public static void main(String[] args) {
    String query = "name==p==?header=hello?aname=?????lname=lastname";
    String[] params = query.split("\\?");
    Map<String, String> map = new HashMap<String, String>();
    for (String param : params) {
        String name = param.split("=")[0];
        String value = param.substring(name.length(), param.length());
        map.put(name, value);// w ww . j  a  v a2  s.c om
        System.out.println(name);
        if (name.equals("")) {
            value += "?";
        }
        System.out.println(value.replaceAll(" ", ""));
    }
}

From source file:org.jboss.capedwarf.tools.BulkLoader.java

public static void main(String[] args) {
    if (args.length < 1) {
        printUsage();/*from w ww. ja va  2s.  c om*/
    }

    Arguments arguments = new Arguments(args);
    String command = args[0];
    if (command.equals("upload")) {
        doUpload(arguments);
    } else if (command.equals("dump")) {
        doDump(arguments);
    } else {
        System.out.println("Unknown command " + command);
        printUsage();
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    URLName server = new URLName("protocol://username@host/foldername");

    Session session = Session.getDefaultInstance(new Properties(), new MailAuthenticator());

    Folder folder = session.getFolder(server);
    if (folder == null) {
        System.out.println("Folder " + server.getFile() + " not found.");
        System.exit(1);//from w  w  w  .j  a  v  a  2  s. co  m
    }
    folder.open(Folder.READ_ONLY);

    Message[] messages = folder.getMessages();
    for (int i = 0; i < messages.length; i++) {
        System.out.println(messages[i].getSize() + " bytes long.");
        System.out.println(messages[i].getLineCount() + " lines.");
        String disposition = messages[i].getDisposition();
        if (disposition == null) {
            ; // do nothing
        } else if (disposition.equals(Part.INLINE)) {
            System.out.println("This part should be displayed inline");
        } else if (disposition.equals(Part.ATTACHMENT)) {
            System.out.println("This part is an attachment");
            String fileName = messages[i].getFileName();
            System.out.println("The file name of this attachment is " + fileName);
        }
        String description = messages[i].getDescription();
        if (description != null) {
            System.out.println("The description of this message is " + description);
        }
    }
    folder.close(false);
}

From source file:com.kasabi.data.movies.freebase.FreebaseMovies2RDF.java

public static void main(String[] args) throws Exception {
    String filename = "/backups/tmp/freebase-datadump-quadruples.tsv.bz2";
    BufferedReader in = new BufferedReader(
            new InputStreamReader(new BZip2CompressorInputStream(new FileInputStream(filename))));
    String line;//from w  w  w . ja  v a  2s.  c o m
    int count = 0;

    Model model = MoviesCommon.createModel();
    String prev_subject = null;
    while ((line = in.readLine()) != null) {
        count++;
        String[] tokens = line.split("\\t");

        if (tokens.length > 0) {
            String subject = tokens[0].trim();
            if (!subject.equals(prev_subject)) {
                process(model);
                model = MoviesCommon.createModel();
            }
            prev_subject = subject;
            if ((tokens.length == 3) && (tokens[0].trim().length() > 0) && (tokens[1].trim().length() > 0)
                    && (tokens[2].trim().length() > 0)) {
                output_resource(model, tokens[0], tokens[1], tokens[2]);
            } else if ((tokens.length == 4) && (tokens[0].trim().length() > 0)
                    && (tokens[1].trim().length() > 0) && (tokens[3].trim().length() > 0)) {
                if (tokens[2].trim().length() == 0) {
                    output_literal(model, tokens[0], tokens[1], tokens[3]);
                } else {
                    if (tokens[2].startsWith(LANG)) {
                        output_literal_lang(model, tokens[0], tokens[1], tokens[3], tokens[2]);
                    } else {
                        if (tokens[1].equals("/type/object/key")) {
                            output_literal2(model, tokens[0], tokens[1], tokens[2], tokens[3]);
                        } else if ((tokens[1].equals("/type/object/name"))
                                && (tokens[2].startsWith("/guid/"))) {
                            output_literal2(model, tokens[0], tokens[1], tokens[2], tokens[3]);
                        } else {
                            log.warn("Unexpected data at {}, ignoring: {}", count, line);
                        }
                    }
                }
            } else {
                if (tokens.length < 3) {
                    log.warn("Line {} has only {} tokens: {}", new Object[] { count, tokens.length, line });
                } else {
                    log.warn("Line {} has one or more empty tokens: {}", new Object[] { count, line });
                }
            }

        }
        if (count % 1000000 == 0)
            log.info("Processed {} lines...", count);
    }
}

From source file:is.merkor.core.cli.Main.java

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

    List<String> results = new ArrayList<String>();
    PrintStream out = new PrintStream(System.out, true, "UTF-8");

    CommandLineParser parser = new GnuParser();
    try {//from   w  w  w  . jav a  2 s  .  c  o m

        MerkorCoreCommandLineOptions.createOptions();
        results = processCommandLine(parser.parse(MerkorCoreCommandLineOptions.options, args));
        out.print("\n");
        for (String str : results) {
            if (!str.equals("no message"))
                out.println(str);
        }
        out.print("\n");
        if (results.isEmpty()) {
            out.println("nothing found for parameters: ");
            for (int i = 0; i < args.length; i++)
                out.println("\t" + args[i]);
            out.println("for help type: -help or see README.markdown");
            out.print("\n");
        }
    } catch (ParseException e) {
        System.err.println("Parsing failed.  Reason: " + e.getMessage());
    }
}

From source file:JRadioButtonItemListener.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");

    ItemListener itemListener = new ItemListener() {
        String lastSelected;//from w w  w  .j a v a  2  s. c  o  m

        public void itemStateChanged(ItemEvent itemEvent) {
            AbstractButton aButton = (AbstractButton) itemEvent.getSource();
            int state = itemEvent.getStateChange();
            String label = aButton.getText();
            String msgStart;
            if (state == ItemEvent.SELECTED) {
                if (label.equals(lastSelected)) {
                    msgStart = "Reselected -> ";
                } else {
                    msgStart = "Selected -> ";
                }
                lastSelected = label;
            } else {
                msgStart = "Deselected -> ";
            }
            System.out.println(msgStart + label);
        }
    };

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

    aRadioButton.addItemListener(itemListener);
    bRadioButton.addItemListener(itemListener);

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

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();
    contentPane.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
    JTextField tfield1 = new JTextField(10);
    JTextField tfield2 = new JTextField(10);

    FocusListener tfieldListener = new FocusListener() {
        @Override/*from  w  w w .  ja  va 2 s.  co  m*/
        public void focusGained(FocusEvent fe) {
        }

        @Override
        public void focusLost(FocusEvent fe) {
            String num1 = tfield1.getText().trim();
            String num2 = tfield2.getText().trim();
            if (num1 == null || num1.equals(""))
                num1 = "0";
            if (num2 == null || num2.equals(""))
                num2 = "0";
            System.out.println(Integer.toString(Integer.parseInt(num1) + Integer.parseInt(num2)));
        }
    };

    tfield1.addFocusListener(tfieldListener);
    tfield2.addFocusListener(tfieldListener);

    ((AbstractDocument) tfield1.getDocument()).setDocumentFilter(new MyDocumentFilter());
    ((AbstractDocument) tfield2.getDocument()).setDocumentFilter(new MyDocumentFilter());

    contentPane.add(tfield1);
    contentPane.add(tfield2);

    frame.setContentPane(contentPane);
    frame.pack();
    frame.setLocationByPlatform(true);
    frame.setVisible(true);
}

From source file:BRReadLines.java

public static void main(String args[]) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String str;

    System.out.println("Enter lines of text.");
    System.out.println("Enter 'stop' to quit.");
    do {/* w  w  w.j  a  v  a 2  s .  c o  m*/
        str = br.readLine();
        System.out.println(str);
    } while (!str.equals("stop"));
}