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:com.github.joshelser.dropwizard.metrics.hadoop.StandaloneExample.java

public static void main(String[] args) throws Exception {
    final MetricRegistry metrics = new MetricRegistry();

    final HadoopMetrics2Reporter metrics2Reporter = HadoopMetrics2Reporter.forRegistry(metrics).build(
            DefaultMetricsSystem.initialize("StandaloneTest"), // The application-level name
            "Test", // Component name
            "Test", // Component description
            "Test"); // Name for each metric record
    final ConsoleReporter consoleReporter = ConsoleReporter.forRegistry(metrics).build();

    MetricsSystem metrics2 = DefaultMetricsSystem.instance();
    // Writes to stdout without a filename configuration
    // Will be invoked every 10seconds by default
    FileSink sink = new FileSink();
    metrics2.register("filesink", "filesink", sink);
    sink.init(new SubsetConfiguration(null, null) {
        public String getString(String key) {
            if (key.equals("filename")) {
                return null;
            }//from w  w w .j  a v  a 2s.  c  o m
            return super.getString(key);
        }
    });

    // How often should the dropwizard reporter be invoked
    metrics2Reporter.start(500, TimeUnit.MILLISECONDS);
    // How often will the dropwziard metrics be logged to the console
    consoleReporter.start(2, TimeUnit.SECONDS);

    generateMetrics(metrics, 5000, 25, TimeUnit.MILLISECONDS, metrics2Reporter, 10);
}

From source file:example.Example.java

public static void main(String[] args) {
    if (args.length == 0) {
        System.err.println("Usage: Example username:password ... [-f twitter_id ...] [-t keyword]");
        System.exit(1);/*from  w  ww .  ja v a 2  s . c  o m*/
    }

    Collection<String> credentials = new ArrayList<String>();
    Collection<String> followIds = null;
    Collection<String> trackKeywords = null;

    Collection<String> list = credentials;

    for (int i = 0; i < args.length; i++) {
        String arg = args[i];
        if (arg.equals("-f")) {
            followIds = new ArrayList<String>();
            list = followIds;
        } else if (arg.equals("-t")) {
            trackKeywords = new ArrayList<String>();
            list = trackKeywords;
        } else {
            list.add(arg);
        }
    }

    final Collection<String> finalFollowIds = followIds;
    final Collection<String> finalTrackKeywords = trackKeywords;

    FilterParameterFetcher filterParameterFetcher = new FilterParameterFetcher() {
        public Collection<String> getFollowIds() {
            return finalFollowIds;
        }

        public Collection<String> getTrackKeywords() {
            return finalTrackKeywords;
        }
    };

    new TwitterClient(filterParameterFetcher, new ExampleTwitterStreamProcessor(),
            "http://stream.twitter.com/1/statuses/filter.json", 200, 10, credentials, 60 * 1000L).execute();
}

From source file:elaborate.editor.backend.AnnotationMarkerScrubber.java

@SuppressWarnings("boxing")
public static void main(String[] args) {
    StopWatch sw = new StopWatch();
    sw.start();/*from  w  w  w .j a v a2 s  .  c om*/
    EntityManager entityManager = HibernateUtil.beginTransaction();
    TranscriptionService ts = TranscriptionService.instance();
    ts.setEntityManager(entityManager);
    try {
        List<Transcription> resultList = entityManager// .
                .createQuery("select t from Transcription t", Transcription.class)//
                .getResultList();
        int size = resultList.size();
        int n = 1;
        for (Transcription t : resultList) {
            Log.info("indexing transcription {} ({}/{} = {}%)",
                    new Object[] { t.getId(), n, size, percentage(n, size) });
            String bodyBefore = t.getBody();
            ts.cleanupAnnotations(t);
            String bodyAfter = t.getBody();
            if (!bodyAfter.equals(bodyBefore)) {
                ProjectEntry projectEntry = t.getProjectEntry();
                String projectname = projectEntry.getProject().getName();
                long entryId = projectEntry.getId();
                Log.info("url: http://test.elaborate.huygens.knaw.nl/projects/{}/entries/{}/transcriptions/{}",
                        projectname, entryId, t.getTextLayer());
                Log.info("body changed:\nbefore: {}\nafter:{}", bodyBefore, bodyAfter);
            }
            n++;
        }
    } finally {
        HibernateUtil.commitTransaction(entityManager);
    }
    sw.stop();
    Log.info("done in {}", convert(sw.getTime()));
}

From source file:Main.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  w  ww.  ja  v a 2s.c o  m*/

        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);
}

From source file:net.sf.jodreports.cli.CreateDocument.java

public static void main(String[] args) throws Exception {
    if (args.length < 3) {
        System.err.println("USAGE: " + CreateDocument.class.getName()
                + " <template-document> <data-file> <output-document>");
        System.exit(0);/*from ww w.j a  v a 2 s .c om*/
    }
    File templateFile = new File(args[0]);
    File dataFile = new File(args[1]);
    File outputFile = new File(args[2]);

    DocumentTemplateFactory documentTemplateFactory = new DocumentTemplateFactory();
    DocumentTemplate template = documentTemplateFactory.getTemplate(templateFile);

    Object model = null;
    String dataFileExtension = FilenameUtils.getExtension(dataFile.getName());
    if (dataFileExtension.equals("xml")) {
        model = NodeModel.parse(dataFile);
    } else if (dataFileExtension.equals("properties")) {
        Properties properties = new Properties();
        properties.load(new FileInputStream(dataFile));
        model = properties;
    } else {
        throw new IllegalArgumentException(
                "data file must be 'xml' or 'properties'; unsupported type: " + dataFileExtension);
    }

    template.createDocument(model, new FileOutputStream(outputFile));
}

From source file:HTTPServer.java

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

    ServerSocket sSocket = new ServerSocket(1777);
    while (true) {
        System.out.println("Waiting for a client...");
        Socket newSocket = sSocket.accept();
        System.out.println("accepted the socket");

        OutputStream os = newSocket.getOutputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(newSocket.getInputStream()));

        String inLine = null;
        while (((inLine = br.readLine()) != null) && (!(inLine.equals("")))) {
            System.out.println(inLine);
        }/* w  w w.ja  va 2  s.c  o  m*/
        System.out.println("");

        StringBuffer sb = new StringBuffer();
        sb.append("<html>\n");
        sb.append("<head>\n");
        sb.append("<title>Java \n");
        sb.append("</title>\n");
        sb.append("</head>\n");
        sb.append("<body>\n");
        sb.append("<H1>HTTPServer Works!</H1>\n");
        sb.append("</body>\n");
        sb.append("</html>\n");

        String string = sb.toString();

        byte[] byteArray = string.getBytes();

        os.write("HTTP/1.0 200 OK\n".getBytes());
        os.write(new String("Content-Length: " + byteArray.length + "\n").getBytes());
        os.write("Content-Type: text/html\n\n".getBytes());

        os.write(byteArray);
        os.flush();

        os.close();
        br.close();
        newSocket.close();
    }

}

From source file:edu.cornell.med.icb.goby.util.RenameWeights.java

public static void main(final String[] args) throws IOException {
    final File directory = new File(".");

    final String[] list = directory.list(new FilenameFilter() {
        public boolean accept(final File directory, final String filename) {

            final String extension = FilenameUtils.getExtension(filename);
            return (extension.equals("entries"));
        }//from   w  ww. j a v  a2s .  c  o  m
    });
    for (final String filename : args) {
        final String extension = FilenameUtils.getExtension(filename);
        final String basename = FilenameUtils.removeExtension(filename);
        for (final String alignFilename : list) {
            final String alignBasename = FilenameUtils.removeExtension(alignFilename);
            if (alignBasename.endsWith(basename)) {
                System.out.println("move " + filename + " to " + alignBasename + "." + extension);

                final File destination = new File(alignBasename + "." + extension);
                FileUtils.deleteQuietly(destination);
                FileUtils.moveFile(new File(filename), destination);
            }
        }

    }
}

From source file:Main.java

public static void main(String[] args) {
    ArrayList<String> aList = new ArrayList<String>();

    aList.add("1");
    aList.add("2");
    aList.add("3");
    aList.add("4");
    aList.add("5");

    for (String str : aList) {
        System.out.println(str);//from  w w w .ja v  a2 s  .  c o  m
    }
    Iterator itr = aList.iterator();

    // remove 2 from ArrayList using Iterator's remove method.

    String strElement = "";

    while (itr.hasNext()) {
        strElement = (String) itr.next();
        if (strElement.equals("2")) {
            itr.remove();
            break;
        }
    }
    for (String str : aList) {
        System.out.println(str);
    }
}

From source file:ToolTipRectangle.java

public static void main(String[] args) {
    Display display = new Display();
    final Color[] colors = { display.getSystemColor(SWT.COLOR_RED), display.getSystemColor(SWT.COLOR_GREEN),
            display.getSystemColor(SWT.COLOR_BLUE), };
    final Rectangle[] rects = { new Rectangle(10, 10, 30, 30), new Rectangle(20, 45, 25, 35),
            new Rectangle(80, 80, 10, 10), };
    final Shell shell = new Shell(display);
    Listener mouseListener = new Listener() {
        public void handleEvent(Event event) {
            switch (event.type) {
            case SWT.MouseEnter:
            case SWT.MouseMove:
                for (int i = 0; i < rects.length; i++) {
                    if (rects[i].contains(event.x, event.y)) {
                        String text = "ToolTip " + i;
                        if (!(text.equals(shell.getToolTipText()))) {
                            shell.setToolTipText("ToolTip " + i);
                        }//from   w  ww. jav a  2 s.  c om
                        return;
                    }
                }
                shell.setToolTipText(null);
                break;
            }
        }
    };
    shell.addListener(SWT.MouseMove, mouseListener);
    shell.addListener(SWT.MouseEnter, mouseListener);
    shell.addListener(SWT.Paint, new Listener() {
        public void handleEvent(Event event) {
            GC gc = event.gc;
            for (int i = 0; i < rects.length; i++) {
                gc.setBackground(colors[i]);
                gc.fillRectangle(rects[i]);
                gc.drawRectangle(rects[i]);
            }
        }
    });
    shell.setSize(200, 200);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:org.eclipse.swt.snippets.Snippet304.java

public static void main(String[] args) {
    display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 304");

    shell.setLayout(new GridLayout());
    Text text = new Text(shell, SWT.MULTI | SWT.BORDER);
    text.setText("< cursor was there\na\nmulti\nline\ntext\nnow it's here >");

    text.addKeyListener(new KeyListener() {
        @Override/*from   w  w  w  .ja v  a2 s.c om*/
        public void keyPressed(KeyEvent e) {
            System.out.println("KeyDown " + e);
        }

        @Override
        public void keyReleased(KeyEvent e) {
            System.out.println("KeyUp   " + e);
        }
    });

    shell.pack();
    shell.open();

    /*
    * Simulate the (platform specific) key sequence
    * to move the I-beam to the end of a text control.
    */
    new Thread() {
        @Override
        public void run() {
            int key = SWT.END;
            String platform = SWT.getPlatform();
            if (platform.equals("cocoa")) {
                key = SWT.ARROW_DOWN;
            }
            postEvent(SWT.MOD1, SWT.KeyDown);
            postEvent(key, SWT.KeyDown);
            postEvent(key, SWT.KeyUp);
            postEvent(SWT.MOD1, SWT.KeyUp);
        }
    }.start();

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}