Wednesday, February 18, 2015

Check to see the string is Palindrome

import java.util.Scanner;
/**
* @author nuwan.n.bandara
* @since 2/18/15
* @version 1.0
*/
public class PalindromeCheck {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the String for check:");
String str = scanner.nextLine();
System.out.println(str + " is" + ((isPalindrome(str) ? " palindrome." : " not palindrome.")));
}
private static boolean isPalindrome(String str) {
if (str == null || str.length() == 0) {
return false;
}
else {
int maxIdx = str.length() - 1;
int mid = str.length() / 2;
char[] strChar = str.toCharArray();
for (int i = 0; i < mid; i++) {
if (strChar[i] != strChar[maxIdx - i]) {
return false;
}
}
}
return true;
}
}

Monday, December 15, 2014


List<Job> jobList = sourceDataManager.getCurrentJobs(sourceDataList);
        Collections.sort(jobList, new Comparator<Job>() {
            public int compare(Job j1, Job j2) {
                int result = j1.getJobType().getShortDescription().compareTo(j2.getJobType().getShortDescription());
                if (result == 0) {
                    result = j1.getJobNumber().compareTo(j2.getJobNumber());
                }
                if (result == 0) {
                    result = j2.getJobRevNumber().compareTo(j1.getJobRevNumber());
                }
                return result;
            }
        });


public static void main(String args[]) {
System.out.println("Hello World!!");
}
<script src="https://gist.github.com/anonymous/f51054324df5e67acea8.js"></script>

Tuesday, November 11, 2014

JDK8 - Lambda Expressions

One issue with anonymous classes is that if the implementation of your anonymous class is very simple, such as an interface that contains only one method, then the syntax of anonymous classes may seem unwieldy and unclear. In these cases, you're usually trying to pass functionality as an argument to another method, such as what action should be taken when someone clicks a button. Lambda expressions enable you to do this, to treat functionality as method argument, or code as data.

The previous section, Anonymous Classes, shows you how to implement a base class without giving it a name. Although this is often more concise than a named class, for classes with only one method, even an anonymous class seems a bit excessive and cumbersome. Lambda expressions let you express instances of single-method classes more compactly.

This section covers the following topics:

Friday, February 21, 2014

Access dialogArguments property (window) in all browsers

Access dialogArguments property (window) in all browsers

function GetDialogArguments() {
var arguments;
if (window.dialogArguments) { // For IE
arguments = window.dialogArguments;
}
else { //For FF and Chrome
arguments = window.opener;
}
return arguments;
}

Friday, September 27, 2013

Configuration With Apache Commons

http://www.code-thrill.com/2012/05/configuration-that-rocks-with-apache.html

http://commons.apache.org/proper/commons-configuration/userguide/howto_configurationbuilder.html#Using_DefaultConfigurationBuilder

@Test
    public void getDbUrl() throws ConfigurationException {
        final String appPropertiesFile = System.getProperty("jboss.server.config.url")
                + "external-connector-config/config.xml";
        try {
            DefaultConfigurationBuilder builder =
                    new DefaultConfigurationBuilder(appPropertiesFile);
            boolean load = true;
            CombinedConfiguration config = builder.getConfiguration(load);
            config.setExpressionEngine(new XPathExpressionEngine());
            String xpath1 = "application/name";
            String xpath2 = "web-services/web-service[vender-id = 'solid-tumor']/url";
            String xpath3 = "databases/database[name = 'dev']/url";
                     

           
            List<AbstractConfiguration> abstractConfigurations =  config.getConfigurations();
            for (AbstractConfiguration abstractConfiguration : abstractConfigurations) {
                if (abstractConfiguration instanceof EnvironmentConfiguration) {
                    for (ConfigurationListener configurationListener : abstractConfiguration
                            .getConfigurationListeners()) {
                        Set<String> configurationNames = ((CombinedConfiguration)
                                configurationListener).getConfigurationNames();
                        if (configurationNames.equals(ApplicationProperties.CONFIG_NAME_APPLICATION)) {
                            System.out.println();
                        }
                        System.out.println(((CombinedConfiguration) configurationListener).getConfigurationNames());
                    }
                }
                else if (abstractConfiguration instanceof XMLConfiguration) {
                    int lastIndex = ((XMLConfiguration) abstractConfiguration).getDocument().getBaseURI()
                            .split("/").length - 1;
                    String fileName = ((XMLConfiguration) abstractConfiguration).getDocument().getBaseURI()
                            .split("/")[lastIndex];
                    if (fileName.startsWith(ApplicationProperties.CONFIG_NAME_APPLICATION)) {
                        System.out.println((((XMLConfiguration) abstractConfiguration).getDocument().getDocumentURI()));
                    }
                }

            }
           
            //System.out.println(config.getString(xpath));

        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }