http://www.refactoring.com/catalog/index.html
http://www.dcs.qmul.ac.uk/~mmh/jlinks.html
http://www.xtremevbtalk.com/showthread.php?t=122263
http://javaquestion.tripod.com/javalinks.html
Tuesday, August 11, 2009
Wednesday, July 29, 2009
String Util
Utilities for reading and writing CSV (comma separated value) text files.
http://ostermiller.org/utils/CSV.html
http://ostermiller.org/utils/CSV.html
Monday, July 27, 2009
How To Ask Questions The Smart Way
How to get help from people who actually know about the software or hardware you're dealing with.
This guide will teach you how to ask questions in a way more likely to get you a satisfactory answer.
http://www.catb.org/~esr/faqs/smart-questions.html
This guide will teach you how to ask questions in a way more likely to get you a satisfactory answer.
http://www.catb.org/~esr/faqs/smart-questions.html
Sunday, July 26, 2009
String Util
package com.ananth.util;
import java.text.CharacterIterator;
import java.text.StringCharacterIterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public final class StringUtil {
private StringUtil() {
// Utility class, hide the constructor.
}
// Validators ---------------------------------------------------------------------------------
/**
* Check if given string is a number. It should contain digits only.
* @param string The string to check on.
* @return True if string is a number.
*/
public static boolean isNumber(String string) {
return string.matches("^\\d+$");
}
/**
* Check if given string is numeric. Positive and negative prefix and dot separators are
* allowed.
* @param string The string to check on.
* @return True if string is numeric.
*/
public static boolean isNumeric(String string) {
return string.matches("^[-+]?\\d+(\\.\\d+)?$");
}
/**
* Check if given string is a value. The dot separator and two decimals are required.
* @param string The string to check on.
* @return True if string is value.
*/
public static boolean isValue(String string) {
return string.matches("^\\d+\\.\\d{2}$");
}
/**
* Check if given string contains numbers.
* @param string The string to check on.
* @return True if string contains numbers.
*/
public static boolean hasNumbers(String string) {
return string.matches("^.*\\d.*$");
}
/**
* Check if given string is a valid email address.
* @param string The string to check on.
* @return True if string is an valid email address.
*/
public static boolean isEmailAddress(String string) {
return string.matches("^[\\w-~#&]+(\\.[\\w-~#&]+)*@([\\w-]+\\.)+[a-z]{2,5}$");
}
// Converters ---------------------------------------------------------------------------------
/**
* Convert the given string to a string with unicode escape sequence for every character.
* @param string The string to be converted.
* @return The string with unicode escape sequence for every character.
*/
public static String toUnicode(String string) {
StringBuilder builder = new StringBuilder();
for (char c : string.toCharArray()) {
builder.append(String.format("\\u%04x", (int) c));
}
return builder.toString();
}
/**
* Unescape any unicode escape sequence in the given string.
* @param string The string to be unescaped.
* @return The string with unescaped unicode escape sequences.
*/
public static String unescapeUnicode(String string) {
Matcher matcher = Pattern.compile("\\\\u((?i)[0-9a-f]{4})").matcher(string);
while (matcher.find()) {
int codepoint = Integer.valueOf(matcher.group(1), 16);
string = string.replaceAll("\\" + matcher.group(0), String.valueOf((char) codepoint));
}
return string;
}
/**
* Escape characters for text appearing as XML data, between tags.
*/
public static String forXML(String aText){
final StringBuilder result = new StringBuilder();
final StringCharacterIterator iterator = new StringCharacterIterator(aText);
char character = iterator.current();
while (character != CharacterIterator.DONE ){
if (character == '<') {
result.append("<");
}
else if (character == '>') {
result.append(">");
}
else if (character == '\"') {
result.append(""");
}
else if (character == '\'') {
result.append("'");
}
else if (character == '&') {
result.append("&");
}
else {
//the char is not a special one
//add it to the result as is
result.append(character);
}
character = iterator.next();
}
return result.toString();
}
/**
* Remove any XSS (Cross Site Scripting) vulnerabilities from the given string.
* @param string The string to remove XSS from.
* @return The string with removed XSS, if any.
*/
public static String removeXss(String string) {
return string
.replaceAll("(?i).*? ", "") // Remove all
import java.text.CharacterIterator;
import java.text.StringCharacterIterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public final class StringUtil {
private StringUtil() {
// Utility class, hide the constructor.
}
// Validators ---------------------------------------------------------------------------------
/**
* Check if given string is a number. It should contain digits only.
* @param string The string to check on.
* @return True if string is a number.
*/
public static boolean isNumber(String string) {
return string.matches("^\\d+$");
}
/**
* Check if given string is numeric. Positive and negative prefix and dot separators are
* allowed.
* @param string The string to check on.
* @return True if string is numeric.
*/
public static boolean isNumeric(String string) {
return string.matches("^[-+]?\\d+(\\.\\d+)?$");
}
/**
* Check if given string is a value. The dot separator and two decimals are required.
* @param string The string to check on.
* @return True if string is value.
*/
public static boolean isValue(String string) {
return string.matches("^\\d+\\.\\d{2}$");
}
/**
* Check if given string contains numbers.
* @param string The string to check on.
* @return True if string contains numbers.
*/
public static boolean hasNumbers(String string) {
return string.matches("^.*\\d.*$");
}
/**
* Check if given string is a valid email address.
* @param string The string to check on.
* @return True if string is an valid email address.
*/
public static boolean isEmailAddress(String string) {
return string.matches("^[\\w-~#&]+(\\.[\\w-~#&]+)*@([\\w-]+\\.)+[a-z]{2,5}$");
}
// Converters ---------------------------------------------------------------------------------
/**
* Convert the given string to a string with unicode escape sequence for every character.
* @param string The string to be converted.
* @return The string with unicode escape sequence for every character.
*/
public static String toUnicode(String string) {
StringBuilder builder = new StringBuilder();
for (char c : string.toCharArray()) {
builder.append(String.format("\\u%04x", (int) c));
}
return builder.toString();
}
/**
* Unescape any unicode escape sequence in the given string.
* @param string The string to be unescaped.
* @return The string with unescaped unicode escape sequences.
*/
public static String unescapeUnicode(String string) {
Matcher matcher = Pattern.compile("\\\\u((?i)[0-9a-f]{4})").matcher(string);
while (matcher.find()) {
int codepoint = Integer.valueOf(matcher.group(1), 16);
string = string.replaceAll("\\" + matcher.group(0), String.valueOf((char) codepoint));
}
return string;
}
/**
* Escape characters for text appearing as XML data, between tags.
*/
public static String forXML(String aText){
final StringBuilder result = new StringBuilder();
final StringCharacterIterator iterator = new StringCharacterIterator(aText);
char character = iterator.current();
while (character != CharacterIterator.DONE ){
if (character == '<') {
result.append("<");
}
else if (character == '>') {
result.append(">");
}
else if (character == '\"') {
result.append(""");
}
else if (character == '\'') {
result.append("'");
}
else if (character == '&') {
result.append("&");
}
else {
//the char is not a special one
//add it to the result as is
result.append(character);
}
character = iterator.next();
}
return result.toString();
}
/**
* Remove any XSS (Cross Site Scripting) vulnerabilities from the given string.
* @param string The string to remove XSS from.
* @return The string with removed XSS, if any.
*/
public static String removeXss(String string) {
return string
.replaceAll("(?i)