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:net.mmberg.nadia.processor.NadiaProcessor.java

/**
 * @param args/*from w w w .  j  av  a 2s . c  o m*/
 */
@SuppressWarnings("static-access")
public static void main(String[] args) {

    Class<? extends UserInterface> ui_class = ConsoleInterface.class; //default UI
    String dialog_file = default_dialog; //default dialogue

    //process command line args
    Options cli_options = new Options();
    cli_options.addOption("h", "help", false, "print this message");
    cli_options.addOption(OptionBuilder.withLongOpt("interface").withDescription("select user interface")
            .hasArg(true).withArgName("console, rest").create("i"));
    cli_options.addOption("f", "file", true, "specify dialogue path and file, e.g. -f /res/dialogue1.xml");
    cli_options.addOption("r", "resource", true, "load dialogue (by name) from resources, e.g. -r dialogue1");
    cli_options.addOption("s", "store", true, "load dialogue (by name) from internal store, e.g. -s dialogue1");

    CommandLineParser parser = new org.apache.commons.cli.BasicParser();
    try {
        CommandLine cmd = parser.parse(cli_options, args);

        //Help
        if (cmd.hasOption("h")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("nadia", cli_options, true);
            return;
        }

        //UI
        if (cmd.hasOption("i")) {
            String interf = cmd.getOptionValue("i");
            if (interf.equals("console"))
                ui_class = ConsoleInterface.class;
            else if (interf.equals("rest"))
                ui_class = RESTInterface.class;
        }

        //load dialogue from path file
        if (cmd.hasOption("f")) {
            dialog_file = "file:///" + cmd.getOptionValue("f");
        }
        //load dialogue from resources
        if (cmd.hasOption("r")) {
            dialog_file = config.getProperty(NadiaProcessorConfig.DIALOGUEDIR) + "/" + cmd.getOptionValue("r")
                    + ".xml";
        }
        //load dialogue from internal store
        if (cmd.hasOption("s")) {
            Dialog store_dialog = DialogStore.getInstance().getDialogFromStore((cmd.getOptionValue("s")));
            store_dialog.save();
            dialog_file = config.getProperty(NadiaProcessorConfig.DIALOGUEDIR) + "/" + cmd.getOptionValue("s")
                    + ".xml";
        }

    } catch (ParseException e1) {
        logger.severe("NADIA: loading by main-method failed. " + e1.getMessage());
        e1.printStackTrace();
    }

    //start Nadia with selected UI
    default_dialog = dialog_file;
    NadiaProcessor nadia = new NadiaProcessor();
    try {
        ui = ui_class.newInstance();
        ui.register(nadia);
        ui.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:JTextFieldSample.java

public static void main(String args[]) {
    String title = (args.length == 0 ? "TextField Listener Example" : args[0]);
    JFrame frame = new JFrame(title);
    Container content = frame.getContentPane();

    JPanel namePanel = new JPanel(new BorderLayout());
    JLabel nameLabel = new JLabel("Name: ");
    nameLabel.setDisplayedMnemonic(KeyEvent.VK_N);
    JTextField nameTextField = new JTextField();
    nameLabel.setLabelFor(nameTextField);
    namePanel.add(nameLabel, BorderLayout.WEST);
    namePanel.add(nameTextField, BorderLayout.CENTER);
    content.add(namePanel, BorderLayout.NORTH);

    JPanel cityPanel = new JPanel(new BorderLayout());
    JLabel cityLabel = new JLabel("City: ");
    cityLabel.setDisplayedMnemonic(KeyEvent.VK_C);
    JTextField cityTextField = new JTextField();
    cityLabel.setLabelFor(cityTextField);
    cityPanel.add(cityLabel, BorderLayout.WEST);
    cityPanel.add(cityTextField, BorderLayout.CENTER);
    content.add(cityPanel, BorderLayout.SOUTH);

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            System.out.println("Command: " + actionEvent.getActionCommand());
        }/*from  w  w w .  jav a 2 s  .co  m*/
    };
    nameTextField.setActionCommand("Yo");
    nameTextField.addActionListener(actionListener);
    cityTextField.addActionListener(actionListener);

    KeyListener keyListener = new KeyListener() {
        public void keyPressed(KeyEvent keyEvent) {
            printIt("Pressed", keyEvent);
        }

        public void keyReleased(KeyEvent keyEvent) {
            printIt("Released", keyEvent);
        }

        public void keyTyped(KeyEvent keyEvent) {
            printIt("Typed", keyEvent);
        }

        private void printIt(String title, KeyEvent keyEvent) {
            int keyCode = keyEvent.getKeyCode();
            String keyText = KeyEvent.getKeyText(keyCode);
            System.out.println(title + " : " + keyText + " / " + keyEvent.getKeyChar());
        }
    };
    nameTextField.addKeyListener(keyListener);
    cityTextField.addKeyListener(keyListener);

    InputVerifier verifier = new InputVerifier() {
        public boolean verify(JComponent input) {
            final JTextComponent source = (JTextComponent) input;
            String text = source.getText();
            if ((text.length() != 0) && !(text.equals("Exit"))) {
                Runnable runnable = new Runnable() {
                    public void run() {
                        JOptionPane.showMessageDialog(source, "Can't leave.", "Error Dialog",
                                JOptionPane.ERROR_MESSAGE);
                    }
                };
                SwingUtilities.invokeLater(runnable);
                return false;
            } else {
                return true;
            }
        }
    };
    nameTextField.setInputVerifier(verifier);
    cityTextField.setInputVerifier(verifier);

    DocumentListener documentListener = new DocumentListener() {
        public void changedUpdate(DocumentEvent documentEvent) {
            printIt(documentEvent);
        }

        public void insertUpdate(DocumentEvent documentEvent) {
            printIt(documentEvent);
        }

        public void removeUpdate(DocumentEvent documentEvent) {
            printIt(documentEvent);
        }

        private void printIt(DocumentEvent documentEvent) {
            DocumentEvent.EventType type = documentEvent.getType();
            String typeString = null;
            if (type.equals(DocumentEvent.EventType.CHANGE)) {
                typeString = "Change";
            } else if (type.equals(DocumentEvent.EventType.INSERT)) {
                typeString = "Insert";
            } else if (type.equals(DocumentEvent.EventType.REMOVE)) {
                typeString = "Remove";
            }
            System.out.print("Type  :   " + typeString + " / ");
            Document source = documentEvent.getDocument();
            int length = source.getLength();
            try {
                System.out.println("Contents: " + source.getText(0, length));
            } catch (BadLocationException badLocationException) {
                System.out.println("Contents: Unknown");
            }
        }
    };
    nameTextField.getDocument().addDocumentListener(documentListener);
    cityTextField.getDocument().addDocumentListener(documentListener);

    frame.setSize(250, 150);
    frame.setVisible(true);
}

From source file:Chat.java

/** Main program entry point. */
public static void main(String argv[]) {

    // Is there anything to do?
    if (argv.length == 0) {
        printUsage();/* w  w w .  j a  v a 2  s .  co m*/
        System.exit(1);
    }

    // Values to be read from parameters
    String broker = DEFAULT_BROKER_NAME;
    String username = null;
    String password = DEFAULT_PASSWORD;

    // Check parameters
    for (int i = 0; i < argv.length; i++) {
        String arg = argv[i];

        if (arg.equals("-b")) {
            if (i == argv.length - 1 || argv[i + 1].startsWith("-")) {
                System.err.println("error: missing broker name:port");
                System.exit(1);
            }
            broker = argv[++i];
            continue;
        }

        if (arg.equals("-u")) {
            if (i == argv.length - 1 || argv[i + 1].startsWith("-")) {
                System.err.println("error: missing user name");
                System.exit(1);
            }
            username = argv[++i];
            continue;
        }

        if (arg.equals("-p")) {
            if (i == argv.length - 1 || argv[i + 1].startsWith("-")) {
                System.err.println("error: missing password");
                System.exit(1);
            }
            password = argv[++i];
            continue;
        }

        if (arg.equals("-h")) {
            printUsage();
            System.exit(1);
        }

        // Invalid argument
        System.err.println("error: unexpected argument: " + arg);
        printUsage();
        System.exit(1);
    }

    // Check values read in.
    if (username == null) {
        System.err.println("error: user name must be supplied");
        printUsage();
        System.exit(1);
    }

    // Start the JMS client for the "chat".
    Chat chat = new Chat();
    chat.chatter(broker, username, password);

}

From source file:jena.RuleMap.java

/**
 * General command line utility to process one RDF file into another
 * by application of a set of forward chaining rules. 
 * <pre>//from w  w  w  . ja va 2  s .c o m
 * Usage:  RuleMap [-il inlang] [-ol outlang] -d infile rulefile
 * </pre>
 */
public static void main(String[] args) {
    try {

        // Parse the command line
        String usage = "Usage:  RuleMap [-il inlang] [-ol outlang] [-d] rulefile infile (- for stdin)";
        final CommandLineParser parser = new DefaultParser();
        Options options = new Options().addOption("il", "inputLang", true, "input language")
                .addOption("ol", "outputLang", true, "output language").addOption("d", "Deductions only?");
        CommandLine cl = parser.parse(options, args);
        final List<String> filenameArgs = cl.getArgList();
        if (filenameArgs.size() != 2) {
            System.err.println(usage);
            System.exit(1);
        }

        String inLang = cl.getOptionValue("inputLang");
        String fname = filenameArgs.get(1);
        Model inModel = null;
        if (fname.equals("-")) {
            inModel = ModelFactory.createDefaultModel();
            inModel.read(System.in, null, inLang);
        } else {
            inModel = FileManager.get().loadModel(fname, inLang);
        }

        String outLang = cl.hasOption("outputLang") ? cl.getOptionValue("outputLang") : "N3";

        boolean deductionsOnly = cl.hasOption('d');

        // Fetch the rule set and create the reasoner
        BuiltinRegistry.theRegistry.register(new Deduce());
        Map<String, String> prefixes = new HashMap<>();
        List<Rule> rules = loadRules(filenameArgs.get(0), prefixes);
        Reasoner reasoner = new GenericRuleReasoner(rules);

        // Process
        InfModel infModel = ModelFactory.createInfModel(reasoner, inModel);
        infModel.prepare();
        infModel.setNsPrefixes(prefixes);

        // Output
        try (PrintWriter writer = new PrintWriter(System.out)) {
            if (deductionsOnly) {
                Model deductions = infModel.getDeductionsModel();
                deductions.setNsPrefixes(prefixes);
                deductions.setNsPrefixes(inModel);
                deductions.write(writer, outLang);
            } else {
                infModel.write(writer, outLang);
            }
        }
    } catch (Throwable t) {
        System.err.println("An error occured: \n" + t);
        t.printStackTrace();
    }
}

From source file:Requestor.java

/** Main program entry point. */
public static void main(String argv[]) {

    // Values to be read from parameters
    String broker = DEFAULT_BROKER_NAME;
    String username = DEFAULT_USER_NAME;
    String password = DEFAULT_PASSWORD;
    String queue = DEFAULT_QUEUE;

    // Check parameters
    for (int i = 0; i < argv.length; i++) {
        String arg = argv[i];

        if (arg.equals("-b")) {
            if (i == argv.length - 1 || argv[i + 1].startsWith("-")) {
                System.err.println("error: missing broker name:port");
                System.exit(1);/* www  .  j  av  a 2 s  . c o  m*/
            }
            broker = argv[++i];
            continue;
        }

        if (arg.equals("-u")) {
            if (i == argv.length - 1 || argv[i + 1].startsWith("-")) {
                System.err.println("error: missing user name");
                System.exit(1);
            }
            username = argv[++i];
            continue;
        }

        if (arg.equals("-p")) {
            if (i == argv.length - 1 || argv[i + 1].startsWith("-")) {
                System.err.println("error: missing password");
                System.exit(1);
            }
            password = argv[++i];
            continue;
        }

        if (arg.equals("-qs")) {
            if (i == argv.length - 1 || argv[i + 1].startsWith("-")) {
                System.err.println("error: missing queue");
                System.exit(1);
            }
            queue = argv[++i];
            continue;
        }

        if (arg.equals("-h")) {
            printUsage();
            System.exit(1);
        }

        // Invalid argument
        System.err.println("error: unexpected argument: " + arg);
        printUsage();
        System.exit(1);
    }

    // Start the JMS client for sending requests.
    Requestor requestor = new Requestor();
    requestor.start(broker, username, password, queue);

}

From source file:Triana.java

/**
 * The main program for Triana/*from   w  w  w.  ja va  2  s. c o  m*/
 */
public static void main(String[] args) throws Exception {

    String os = Locations.os();
    String usage = "./triana.sh";
    if (os.equals("windows")) {
        usage = "triana.bat";
    }

    OptionsHandler parser = new OptionsHandler(usage, TrianaOptions.TRIANA_OPTIONS);
    OptionValues vals = null;
    try {
        vals = parser.parse(args);
    } catch (ArgumentParsingException e) {
        System.out.println(e.getMessage());
        System.out.println(parser.usage());
        System.exit(0);
    }
    boolean help = vals.hasOption(HELP);
    if (help) {
        System.out.println(parser.usage());
        System.exit(0);
    }
    String logLevel = vals.getOptionValue(LOG_LEVEL);

    String logger = vals.getOptionValue(ISOLATED_LOGGER);
    if (logger != null) {
        Loggers.isolateLogger(logger, logLevel == null ? "INFO" : logLevel);
    } else {
        if (logLevel != null) {
            Loggers.setLogLevel(logLevel);
        }
    }

    boolean runUnit = vals.hasOption(TrianaOptions.RUN_UNIT.getShortOpt());
    boolean runNoGui = vals.hasOption(NOGUI);
    boolean pid = vals.hasOptionValue(UUID);
    boolean exec = vals.hasOptionValue(EXECUTE);
    boolean server = vals.hasOption(SERVER);
    boolean workflow = vals.hasOptionValue(WORKFLOW);
    boolean plugin = vals.hasOption(TrianaOptions.PLUGIN.getShortOpt());
    boolean convert = vals.hasOption(TrianaOptions.CONVERT_WORKFLOW.getShortOpt());
    if (runNoGui || pid || runUnit) {
        System.out.println("Running headless, optional pid or unit.");
        if (runUnit) {
            new RunUnit(args);
            System.exit(0);
        }
        if (convert) {
            Convert.convert(args);
        } else if (!server) {
            if (pid || exec || workflow || plugin) {
                if (plugin) {
                    try {
                        System.exit(Plugins.exec(args));
                    } catch (ArgumentParsingException e) {
                        System.out.println(e.getMessage());
                        System.out.println(parser.usage());
                    }
                } else {
                    System.exit(Exec.exec(args));
                }
            } else {
                System.out.println(
                        "Non-gui mode combined with non-server mode requires either a uuid, a workflow, or a bundle");
                System.out.println(parser.usage());
                System.exit(0);
            }
        } else {
            new TrianaInstance(args).init();
        }
    } else {
        ApplicationFrame.initTriana(args);
    }

}

From source file:FormatStorage2ColumnStorageMR.java

@SuppressWarnings("deprecation")
public static void main(String[] args) throws Exception {

    if (args.length != 2) {
        System.out.println("FormatStorage2ColumnStorageMR <input> <output>");
        System.exit(-1);/*from   w  ww  . j ava 2  s  . co  m*/
    }

    JobConf conf = new JobConf(FormatStorageMR.class);

    conf.setJobName("FormatStorage2ColumnStorageMR");

    conf.setNumMapTasks(1);
    conf.setNumReduceTasks(4);

    conf.setOutputKeyClass(LongWritable.class);
    conf.setOutputValueClass(Unit.Record.class);

    conf.setMapperClass(FormatStorageMapper.class);
    conf.setReducerClass(ColumnStorageReducer.class);

    conf.setInputFormat(FormatStorageInputFormat.class);
    conf.set("mapred.output.compress", "flase");

    Head head = new Head();
    initHead(head);

    head.toJobConf(conf);

    FileInputFormat.setInputPaths(conf, args[0]);
    Path outputPath = new Path(args[1]);
    FileOutputFormat.setOutputPath(conf, outputPath);

    FileSystem fs = outputPath.getFileSystem(conf);
    fs.delete(outputPath, true);

    JobClient jc = new JobClient(conf);
    RunningJob rj = null;
    rj = jc.submitJob(conf);

    String lastReport = "";
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss,SSS");
    long reportTime = System.currentTimeMillis();
    long maxReportInterval = 3 * 1000;
    while (!rj.isComplete()) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        }

        int mapProgress = Math.round(rj.mapProgress() * 100);
        int reduceProgress = Math.round(rj.reduceProgress() * 100);

        String report = " map = " + mapProgress + "%,  reduce = " + reduceProgress + "%";

        if (!report.equals(lastReport) || System.currentTimeMillis() >= reportTime + maxReportInterval) {

            String output = dateFormat.format(Calendar.getInstance().getTime()) + report;
            System.out.println(output);
            lastReport = report;
            reportTime = System.currentTimeMillis();
        }
    }

    System.exit(0);

}

From source file:eu.scape_project.tb.lsdr.hocrparser.HocrParser.java

/**
 * The main entry point./*from  ww  w  .  ja v  a  2  s  .  c  o m*/
 */
public static void main(String[] args) throws ParseException {
    Configuration conf = new Configuration();

    //conf.setBoolean("mapreduce.client.genericoptionsparser.used", true);
    GenericOptionsParser gop = new GenericOptionsParser(conf, args);
    HocrParserCliConfig pc = new HocrParserCliConfig();
    CommandLineParser cmdParser = new PosixParser();
    CommandLine cmd = cmdParser.parse(HocrParserOptions.OPTIONS, gop.getRemainingArgs());
    if ((args.length == 0) || (cmd.hasOption(HocrParserOptions.HELP_OPT))) {
        HocrParserOptions.exit("Usage", 0);
    } else {
        HocrParserOptions.initOptions(cmd, pc);
    }
    String dir = pc.getDirStr();

    String name = pc.getHadoopJobName();
    if (name == null || name.equals("")) {
        name = "hocr_parser";
    }

    try {
        Job job = new Job(conf, name);
        job.setJarByClass(HocrParser.class);

        job.setMapperClass(HocrParserMapper.class);
        //job.setCombinerClass(HocrParserReducer.class);
        job.setReducerClass(HocrParserReducer.class);

        job.setInputFormatClass(SequenceFileInputFormat.class);

        job.setOutputFormatClass(TextOutputFormat.class);
        //SequenceFileOutputFormat.setOutputCompressionType(job, SequenceFile.CompressionType.NONE);

        //conf.setMapOutputKeyClass(Text.class);
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(Text.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(LongWritable.class);

        SequenceFileInputFormat.addInputPath(job, new Path(dir));
        String outpath = "output/" + System.currentTimeMillis() + "hop";
        FileOutputFormat.setOutputPath(job, new Path(outpath));
        job.waitForCompletion(true);
        System.out.print(outpath);
        System.exit(0);
    } catch (Exception e) {
        logger.error("IOException occurred", e);
    }
}

From source file:net.orpiske.dcd.main.Main.java

/**
 * @param args/*  www.j a v  a 2  s . co  m*/
 */
public static void main(String[] args) {
    int ret = 0;

    if (args.length == 0) {
        help(1);
    }

    String first = args[0];
    String[] newArgs = Arrays.copyOfRange(args, 1, args.length);

    initConfiguration();
    initDomainConfiguration();

    // TODO: add a fetching action
    if (first.equals("fetch")) {

    }

    if (first.equals("parse")) {
        ParseAction parseAction = new ParseAction(newArgs);

        ret = parseAction.run();
        System.exit(ret);
    }

    if (first.equals("dispatch")) {

    }

}

From source file:FileCompressor.java

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

    String file = "D:\\XJad.rar.txt";
    BufferedReader reader = new BufferedReader(new FileReader(file));
    BufferedWriter writer = new BufferedWriter(new FileWriter(file + "_out.txt"));
    StringBuilder content = new StringBuilder();
    String tmp;/*  w w w  .j  a v  a 2s .c  o m*/

    while ((tmp = reader.readLine()) != null) {
        content.append(tmp);
        content.append(System.getProperty("line.separator"));
    }

    FileCompressor f = new FileCompressor();
    writer.write(f.compress(content.toString()));

    writer.close();
    reader.close();

    reader = new BufferedReader(new FileReader(file + "_out.txt"));
    StringBuilder content2 = new StringBuilder();

    while ((tmp = reader.readLine()) != null) {
        content2.append(tmp);
        content2.append(System.getProperty("line.separator"));
    }

    String decompressed = f.decompress(content2.toString());
    String c = content.toString();
    System.out.println(decompressed.equals(c));
}