001package org.unix4j.convert; 002 003import java.util.regex.Pattern; 004import java.util.regex.PatternSyntaxException; 005 006public class PatternConverters { 007 public static final ValueConverter<Pattern> STRING = new ValueConverter<Pattern>() { 008 @Override 009 public Pattern convert(Object value) throws IllegalArgumentException { 010 if (value != null) { 011 try { 012 return Pattern.compile(value.toString()); 013 } catch (PatternSyntaxException e) { 014 //ignore, we just can't convert this string 015 } 016 } 017 return null; 018 } 019 }; 020 public static final ValueConverter<Pattern> DEFAULT = STRING; 021}