-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6bb422f
commit 7b7bfd9
Showing
61 changed files
with
1,081 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...unner-core/src/main/java/org/specrunner/converters/core/ConverterDateMidnightCurrent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
SpecRunner - Acceptance Test Driven Development Tool | ||
Copyright (C) 2011-2015 Thiago Santos | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/> | ||
*/ | ||
package org.specrunner.converters.core; | ||
|
||
import org.specrunner.source.resource.ResourceException; | ||
import org.specrunner.util.UtilIO; | ||
|
||
/** | ||
* Create current date. | ||
* | ||
* @author Thiago Santos | ||
* | ||
*/ | ||
@SuppressWarnings("serial") | ||
public class ConverterDateMidnightCurrent extends ConverterDateMidnightCurrentTemplate { | ||
|
||
/** | ||
* Basic data converter. | ||
* | ||
* @throws ResourceException | ||
* On load errors. | ||
*/ | ||
public ConverterDateMidnightCurrent() throws ResourceException { | ||
super(UtilIO.readLines("sr_converters_time.txt")); | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
...re/src/main/java/org/specrunner/converters/core/ConverterDateMidnightCurrentTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
SpecRunner - Acceptance Test Driven Development Tool | ||
Copyright (C) 2011-2015 Thiago Santos | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/> | ||
*/ | ||
package org.specrunner.converters.core; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.regex.Pattern; | ||
|
||
import org.joda.time.DateMidnight; | ||
import org.specrunner.converters.ConverterException; | ||
|
||
/** | ||
* Create current date. | ||
* | ||
* @author Thiago Santos | ||
* | ||
*/ | ||
@SuppressWarnings("serial") | ||
public class ConverterDateMidnightCurrentTemplate extends AbstractConverterTimeTemplate<DateMidnight> { | ||
|
||
protected Map<String, String> aliasToField = new HashMap<String, String>(); | ||
protected Map<String, String> fieldToMethod = new HashMap<String, String>(); | ||
protected Pattern pattern; | ||
|
||
/** | ||
* See superclass. | ||
* | ||
* @param values | ||
* Value. | ||
*/ | ||
public ConverterDateMidnightCurrentTemplate(List<String> values) { | ||
super(values); | ||
pattern = extractPattern(bindAliases(aliasToField).keySet()); | ||
bindPatterns(fieldToMethod); | ||
} | ||
|
||
protected Map<String, String> bindAliases(Map<String, String> map) { | ||
UtilDate.bindAliases(map); | ||
return map; | ||
} | ||
|
||
protected Map<String, String> bindPatterns(Map<String, String> map) { | ||
UtilJodatime.bindDatePatterns(map); | ||
UtilJodatime.bindTimePatterns(map); | ||
return map; | ||
} | ||
|
||
protected Pattern extractPattern(Set<String> set) { | ||
return UtilDate.extractPattern(set); | ||
} | ||
|
||
@Override | ||
protected boolean testValue(String str, String value) { | ||
return str.startsWith(value); | ||
} | ||
|
||
@Override | ||
protected DateMidnight instance() { | ||
return new DateMidnight(); | ||
} | ||
|
||
@Override | ||
public Object convert(Object value, Object[] args) throws ConverterException { | ||
if (value instanceof DateMidnight) { | ||
return value; | ||
} | ||
return super.convert(value, args); | ||
} | ||
|
||
@Override | ||
protected DateMidnight postProcess(Object value, Object[] args, DateMidnight result) { | ||
return UtilJodatime.postProcess(value, args, result, pattern, aliasToField, fieldToMethod); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...r-core/src/main/java/org/specrunner/converters/core/ConverterDateMidnightPatternArgs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
SpecRunner - Acceptance Test Driven Development Tool | ||
Copyright (C) 2011-2015 Thiago Santos | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/> | ||
*/ | ||
package org.specrunner.converters.core; | ||
|
||
import java.util.TimeZone; | ||
|
||
import org.joda.time.DateMidnight; | ||
import org.joda.time.DateTimeZone; | ||
import org.joda.time.format.DateTimeFormat; | ||
import org.joda.time.format.DateTimeFormatter; | ||
import org.specrunner.SRServices; | ||
import org.specrunner.converters.ConverterException; | ||
import org.specrunner.util.cache.ICache; | ||
import org.specrunner.util.cache.ICacheFactory; | ||
|
||
/** | ||
* Convert any date (DateMidnight form Jodatime), given a provided pattern in | ||
* arg[0]. | ||
* | ||
* @author Thiago Santos | ||
* | ||
*/ | ||
@SuppressWarnings("serial") | ||
public class ConverterDateMidnightPatternArgs extends AbstractConverterTimezone<DateMidnight> { | ||
/** | ||
* Cache of formatters. | ||
*/ | ||
protected static ICache<String, DateTimeFormatter> cache = SRServices.get(ICacheFactory.class).newCache(ConverterDateMidnightPatternArgs.class.getName()); | ||
|
||
@Override | ||
public Object convert(Object value, Object[] args) throws ConverterException { | ||
if (value == null) { | ||
return null; | ||
} | ||
if (value instanceof DateMidnight) { | ||
return value; | ||
} | ||
try { | ||
if (args.length < 1) { | ||
throw new ConverterException("Converter '" + getClass() + "' missing pattern argument information (i.e. arg0=\"dd/MM/yyyy\")."); | ||
} | ||
String pattern = String.valueOf(args[0]); | ||
synchronized (cache) { | ||
DateTimeFormatter formatter = cache.get(pattern); | ||
if (formatter == null) { | ||
formatter = DateTimeFormat.forPattern(pattern); | ||
cache.put(pattern, formatter); | ||
} | ||
TimeZone tz = getZone(); | ||
if (tz != null) { | ||
formatter = formatter.withZone(DateTimeZone.forTimeZone(tz)); | ||
} | ||
return formatter.parseDateTime(String.valueOf(value)).toDateMidnight(); | ||
} | ||
} catch (IllegalArgumentException e) { | ||
throw new ConverterException(e); | ||
} | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...re/src/main/java/org/specrunner/converters/core/ConverterDateMidnightPatternTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
SpecRunner - Acceptance Test Driven Development Tool | ||
Copyright (C) 2011-2015 Thiago Santos | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/> | ||
*/ | ||
package org.specrunner.converters.core; | ||
|
||
import org.joda.time.DateTime; | ||
import org.joda.time.format.DateTimeFormat; | ||
import org.joda.time.format.DateTimeFormatter; | ||
import org.specrunner.converters.ConverterException; | ||
|
||
/** | ||
* General date converter. | ||
* | ||
* @author Thiago Santos | ||
* | ||
*/ | ||
@SuppressWarnings("serial") | ||
public class ConverterDateMidnightPatternTemplate extends ConverterNotNullNotEmpty { | ||
|
||
/** | ||
* Parser instance. | ||
*/ | ||
protected DateTimeFormatter pattern; | ||
|
||
/** | ||
* Create a SimpleDateFormat using the given pattern. | ||
* | ||
* @param pattern | ||
* Pattern. | ||
*/ | ||
public ConverterDateMidnightPatternTemplate(String pattern) { | ||
this.pattern = DateTimeFormat.forPattern(pattern); | ||
} | ||
|
||
@Override | ||
public Object convert(Object value, Object[] args) throws ConverterException { | ||
if (value == null) { | ||
return null; | ||
} | ||
if (value instanceof DateTime) { | ||
return value; | ||
} | ||
try { | ||
return pattern.parseDateTime(String.valueOf(value)).toDateMidnight(); | ||
} catch (IllegalArgumentException e) { | ||
throw new ConverterException(e); | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...nner-core/src/main/java/org/specrunner/converters/core/ConverterLocalDateTimeCurrent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
SpecRunner - Acceptance Test Driven Development Tool | ||
Copyright (C) 2011-2015 Thiago Santos | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/> | ||
*/ | ||
package org.specrunner.converters.core; | ||
|
||
import org.specrunner.source.resource.ResourceException; | ||
import org.specrunner.util.UtilIO; | ||
|
||
/** | ||
* Create current date. | ||
* | ||
* @author Thiago Santos | ||
* | ||
*/ | ||
@SuppressWarnings("serial") | ||
public class ConverterLocalDateTimeCurrent extends ConverterLocalDateTimeCurrentTemplate { | ||
|
||
/** | ||
* Basic data converter. | ||
* | ||
* @throws ResourceException | ||
* On load errors. | ||
*/ | ||
public ConverterLocalDateTimeCurrent() throws ResourceException { | ||
super(UtilIO.readLines("sr_converters_date.txt")); | ||
} | ||
} |
Oops, something went wrong.