Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Friday, 3 November 2017

Solr Sample Code and Articles

https://lucene.apache.org/solr/4_0_0/tutorial.html
https://github.com/pkainulainen/spring-data-solr-examples
https://www.petrikainulainen.net/programming/solr/spring-data-solr-tutorial-configuration/
http://nerdcenter.de/solr-multicore-installation-configuration/
http://www.params.me/2012/11/sample-solr-14-application-code-in-java.html
https://github.com/paramsethi/solr-setup
http://cmusphinx.sourceforge.net/2012/06/building-a-java-application-with-apache-nutch-and-solr/
http://www.solrtutorial.com/solrj-tutorial.html
https://www.drupal.org/node/484800
https://www.codeenigma.com/host/faq/how-do-i-create-solr-core-my-server
Share:

Thursday, 2 March 2017

Traverse in all files in directory using Java

Using apache collection to traverse all files in directory with regex
Share:

Wednesday, 22 February 2017

Java Enumeration Good Example

Enums are lists of constants. When you need a predefined list of values which do represent some kind of numeric or textual data, you should use an enum. You could enter number or string to get the specific value
Share:

How to declare a new exception in Java

Sample java code to declare a new exception.


public class MyNewException extends Exception {
 private static final long serialVersionUID = -7994546786269588726L;

 public MyNewException() {
  super();
 }

 public MyNewException(String msg) {
  super(msg);
 }
}

Share:

Wednesday, 6 July 2016

Java Date Validations and Various Regex Validators

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class CheckDateFormat {
 public static void main(String... args) {
 
  Date date = checkDates("2016-01-01");
  System.out.println(date);
 
  date = checkDates("2016-13-01");
  System.out.println(date);   //returns null
 
  date = checkDates("03/22/1974");
  System.out.println(date);   //returns null
 
 
 
 }
 public static Date checkDates(String text) {
  // http://howtodoinjava.com/regex/java-regex-date-format-validation/
  // https://www.debuggex.com/r/7jAhBMayS28ezOAN/4
  SimpleDateFormat df = null;
  
 
  if (text != null) {
   if (text.matches("\\d{4}-[01]\\d-[0-3]\\d")) {
    //http://stackoverflow.com/questions/2149680/regex-date-format-validation-on-java
    df = new SimpleDateFormat("yyyy-MM-dd");
   
   } else if (text.matches("/^(0[1-9]|1[0-2])\\/(0[1-9]|1\\d|2\\d|3[01])\\/(19|20)\\d{2}$/")) {
    //http://stackoverflow.com/questions/15196451/regular-expression-to-validate-datetime-format-mm-dd-yyyy   
    df = new SimpleDateFormat("MM/DD/YYYY");
   
   } else if (text.matches("/^(\\d{1,2})-(\\d{1,2})-(\\d{4})$/")) {
    //http://stackoverflow.com/questions/8937408/regular-expression-for-date-format-dd-mm-yyyy-in-javascript
    df = new SimpleDateFormat("dd-mm-yyyy");
   
//   } else if (text.matches("0?[1-9]|[12][0-9]|3[01])/(0?[1-9]|1[012])/((19|20)\\d\\d")) {
//    //http://stackoverflow.com/questions/8937408/regular-expression-for-date-format-dd-mm-yyyy-in-javascript
//    df = new SimpleDateFormat("dd/mm/yyyy");
   }
 
   if (df == null) return null;   // didnt match any regex parser
  
   df.setLenient(false);
   try {
    return df.parse(text);
   } catch (ParseException ex) {
    return null;
   }
  }
  return null;
 }
}
Share:

Tuesday, 21 June 2016

Popular Posts

Recent Posts

Pages

Powered by Blogger.

About Me

My photo
For the past 10 years, I've been playing with codes using PHP, Java, Rails. I do this for a living and love new things to learn and the challenges that comes with it. Besides programming I love spending time with friends and family and can often be found together catching the latest movie or planning a trip to someplace I've never been before.