本文整理汇总了Java中java.text.ParseException类的典型用法代码示例。如果您正苦于以下问题:Java ParseException类的具体用法?Java ParseException怎么用?Java ParseException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ParseException类属于java.text包,在下文中一共展示了ParseException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: next
import java.text.ParseException; //导入依赖的package包/类
public String next(String regexp) throws ParseException {
trim();
Pattern p = Pattern.compile(regexp);
Matcher m = p.matcher(s);
if(m.lookingAt()) {
String r = m.group();
s = s.substring(r.length());
trim();
return r;
} else
throw error();
}
示例2: ParseUTCDate
import java.text.ParseException; //导入依赖的package包/类
Date ParseUTCDate(String s) throws ParseException {
if (m_pISODate == null) {
m_pISODate = Pattern.compile("(\\d+)-(\\d+)-(\\d+)T? ?(\\d+):(\\d+):(\\d+\\.?\\d*)Z?", Pattern.CASE_INSENSITIVE);
}
Matcher m = m_pISODate.matcher(s);
if (m.matches()) {
int year = Integer.parseInt(m.group(1));
int month = Integer.parseInt(m.group(2));
int day = Integer.parseInt(m.group(3));
int hour = Integer.parseInt(m.group(4));
int minute = Integer.parseInt(m.group(5));
double second = Double.parseDouble(m.group(6));
GregorianCalendar gc = UTCDate.UTCCalendar();
gc.set(year, month - 1, day, hour, minute, (int) second);
return gc.getTime();
}
return new Date();
}
示例3: testOrderOfMainACIComponentsDoesNotMatterButMissingsMatter
import java.text.ParseException; //导入依赖的package包/类
@Test
public void testOrderOfMainACIComponentsDoesNotMatterButMissingsMatter() throws Exception
{
String spec = "{ itemOrUserFirst userFirst: { userClasses { allUsers , name { \"ou=people,cn=ersin\" }, "
+ "subtree {{ base \"ou=system\" }, { base \"ou=ORGANIZATIONUNIT\","
+ "minimum 1, maximum 2 } } } , "
+ "userPermissions { { protectedItems{ entry , attributeType { cn , ou } , attributeValue {x=y,m=n,k=l} , "
+ "rangeOfValues (cn=ErsinEr) } , grantsAndDenials { grantBrowse } } } }, "
+ " identificationTag \"id2\" , precedence 14 } ";
try
{
parser.parse( spec );
fail( "testOrderOfMainACIComponentsDoesNotMatterButMissingsMatter() should not have run this line." );
}
catch ( ParseException e )
{
assertNotNull( e );
}
}
示例4: createPartitionedRegion
import java.text.ParseException; //导入依赖的package包/类
private Region createPartitionedRegion(String regionName) throws ParseException {
Cache cache = CacheUtils.getCache();
PartitionAttributesFactory prAttFactory = new PartitionAttributesFactory();
AttributesFactory attributesFactory = new AttributesFactory();
attributesFactory.setPartitionAttributes(prAttFactory.create());
RegionAttributes regionAttributes = attributesFactory.create();
return cache.createRegion(regionName, regionAttributes);
}
示例5: testUnderThresholdFilterTest_GLUCOSE_125_00_CGM_CGM_AVAILABLE_CGM_TH
import java.text.ParseException; //导入依赖的package包/类
@Test
public void testUnderThresholdFilterTest_GLUCOSE_125_00_CGM_CGM_AVAILABLE_CGM_TH() throws ParseException {
UnderThresholdFilter instance = new UnderThresholdFilter(VaultEntryType.GLUCOSE_CGM, 125.00, FilterType.CGM_AVAILABLE, FilterType.CGM_TH);
FilterResult result = instance.filter(data);
List<VaultEntry> filteredData = new ArrayList<>();
filteredData.add(new VaultEntry(VaultEntryType.GLUCOSE_CGM, TestFunctions.creatNewDateToCheckFor("2016.04.18-09:59"), 118));
//
filteredData.add(new VaultEntry(VaultEntryType.GLUCOSE_CGM, TestFunctions.creatNewDateToCheckFor("2016.04.18-10:29"), 110));
filteredData.add(new VaultEntry(VaultEntryType.GLUCOSE_CGM, TestFunctions.creatNewDateToCheckFor("2016.04.18-10:43"), 105));
//
filteredData.add(new VaultEntry(VaultEntryType.GLUCOSE_CGM, TestFunctions.creatNewDateToCheckFor("2016.04.18-10:59"), 100));
//
filteredData.add(new VaultEntry(VaultEntryType.GLUCOSE_CGM, TestFunctions.creatNewDateToCheckFor("2016.04.18-11:14"), 120));
filteredData.add(new VaultEntry(VaultEntryType.GLUCOSE_CGM, TestFunctions.creatNewDateToCheckFor("2016.04.18-11:29"), 103));
List<Pair<Date, Date>> timeSeries = new ArrayList<>();
timeSeries.add(new Pair<>(TestFunctions.creatNewDateToCheckFor("2016.04.18-09:59"), TestFunctions.creatNewDateToCheckFor("2016.04.18-09:59")));
timeSeries.add(new Pair<>(TestFunctions.creatNewDateToCheckFor("2016.04.18-10:29"), TestFunctions.creatNewDateToCheckFor("2016.04.18-10:43")));
timeSeries.add(new Pair<>(TestFunctions.creatNewDateToCheckFor("2016.04.18-10:59"), TestFunctions.creatNewDateToCheckFor("2016.04.18-10:59")));
timeSeries.add(new Pair<>(TestFunctions.creatNewDateToCheckFor("2016.04.18-11:14"), TestFunctions.creatNewDateToCheckFor("2016.04.18-11:29")));
FilterResult checkForThisResult = new FilterResult(filteredData, timeSeries);
assertEquals(result.filteredData, checkForThisResult.filteredData);
assertEquals(result.timeSeries, checkForThisResult.timeSeries);
//assertEquals(result, checkForThisResult);
}
示例6: initialize
import java.text.ParseException; //导入依赖的package包/类
public void initialize(File workingDirectory, String[] arguments)
{
if(arguments.length != 1 && arguments.length != 2 ) {
throw new RuntimeException(usageString);
}
String inputFileName = arguments[0];
this.outputFileName = inputFileName;
if (arguments.length > 1) {
this.outputFileName = arguments[1];
}
this.workingDirectory = workingDirectory;
configTree = new ConfigTree(workingDirectory, inputFileName);
String startDateString = configTree.getAsString(CONFIG_TREE_ELEMENT_STARTDATE, "");
String startTimeString = configTree.getAsString(CONFIG_TREE_ELEMENT_STARTTIME, "");
String endDateString = configTree.getAsString(CONFIG_TREE_ELEMENT_ENDDATE, "");
String endTimeString = configTree.getAsString(CONFIG_TREE_ELEMENT_ENDTIME, "");
String startString = startDateString + " " + startTimeString;
String endString = endDateString + " " + endTimeString;
double mjdStartTime;
double mjdEndTime;
try {
mjdStartTime = TimeUtils.date2Mjd(startString);
mjdEndTime = TimeUtils.date2Mjd(endString);
} catch (ParseException e) {
throw new RuntimeException("Could not parse start/end date time in file " + new File(workingDirectory, inputFileName));
}
exchangeItems = new HashMap<>();
exchangeItems.put(PROPERTY_STARTTIME, new Flow1DTimeInfoExchangeItem(Flow1DTimeInfoExchangeItem.PropertyId.StartTime, mjdStartTime));
exchangeItems.put(PROPERTY_STOPTIME, new Flow1DTimeInfoExchangeItem(Flow1DTimeInfoExchangeItem.PropertyId.StopTime, mjdEndTime));
}
示例7: main
import java.text.ParseException; //导入依赖的package包/类
public static void main(String[] args) throws IOException, ParseException {
if (args.length < 4) {
StringBuilder sb = new StringBuilder();
sb.append("current parameters: ");
for (String one : args) {
sb.append(one).append(",");
}
usage();
return;
}
new PerfDataGenerator(args[0], Integer.valueOf(args[1]), Integer.valueOf(args[2]),
Integer.valueOf(args[3])).work();
}
示例8: testOffsetTime
import java.text.ParseException; //导入依赖的package包/类
@Test
public void testOffsetTime() throws ParseException {
DateTimeApiParameterMapper mapper = new DateTimeApiParameterMapper();
assertThat(mapper.toJdbc(OffsetTime.from(createDateTime("2000/01/01 10:10:10.010")), null, null),
instanceOf(java.sql.Time.class));
assertThat(mapper.toJdbc(OffsetTime.from(createDateTime("2000/01/01 10:10:10.010")), null, null),
is(createTime("10:10:10.010")));
}
示例9: extendsStarted
import java.text.ParseException; //导入依赖的package包/类
private void extendsStarted(Attributes attributes) throws ParseException {
String parentOrganisation = attributes.getValue("organisation");
String parentModule = attributes.getValue("module");
String parentRevision = attributes.getValue("revision");
String location = elvis(attributes.getValue("location"), "../ivy.xml");
String extendType = elvis(attributes.getValue("extendType"), "all").toLowerCase();
List<String> extendTypes = Arrays.asList(extendType.split(","));
ModuleDescriptor parent;
try {
LOGGER.debug("Trying to parse included ivy file :{}", location);
parent = parseOtherIvyFileOnFileSystem(location);
if (parent != null) {
//verify that the parsed descriptor is the correct parent module.
ModuleId expected = IvyUtil.createModuleId(parentOrganisation, parentModule);
ModuleId pid = parent.getModuleRevisionId().getModuleId();
if (!expected.equals(pid)) {
LOGGER.warn("Ignoring parent Ivy file {}; expected {} but found {}", location, expected, pid);
parent = null;
}
}
// if the included ivy file is not found on file system, tries to resolve using
// repositories
if (parent == null) {
LOGGER.debug("Trying to parse included ivy file by asking repository for module :{}#{};{}",
parentOrganisation, parentModule, parentRevision);
parent = parseOtherIvyFile(parentOrganisation, parentModule, parentRevision);
}
} catch(Exception e) {
throw (ParseException) new ParseException("Unable to parse included ivy file for " + parentOrganisation + "#" + parentModule + ";" + parentRevision, 0).initCause(e);
}
if (parent == null) {
throw new ParseException("Unable to parse included ivy file for " + parentOrganisation + "#" + parentModule + ";" + parentRevision, 0);
}
mergeWithOtherModuleDescriptor(extendTypes, parent);
}
示例10: getValue
import java.text.ParseException; //导入依赖的package包/类
public Object getValue(User user, Map context) {
if (type.equals(STRING)) {
return value;
} else if (type.equals(INTEGER)) {
return new Integer(value);
} else if (type.equals(FLOAT)) {
return new Float(value);
} else if (type.equals(BOOLEAN)) {
return new Boolean(value);
} else if (type.equals(DATETIME)) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
try {
return format.parse(value);
} catch (ParseException e) {
log.error( "", e );
throw new RalasafeException(e);
}
} else {
String msg="Not supported value type '" + type + "'.";
log.error( msg );
throw new RalasafeException(msg);
}
}
示例11: toDate2
import java.text.ParseException; //导入依赖的package包/类
/**
* 将字符串转位年月日
*
* @param sdate
* @return
*/
public static Date toDate2(String sdate) {
try {
return dateFormater2.get().parse(sdate);
} catch (ParseException e) {
return null;
}
}
示例12: str2date
import java.text.ParseException; //导入依赖的package包/类
public static Date str2date(String str, String format) {
Date date = null;
try {
if (str != null) {
SimpleDateFormat sdf = new SimpleDateFormat(format);
date = sdf.parse(str);
}
} catch (ParseException e) {
e.printStackTrace();
}
return date;
}
示例13: testSingle
import java.text.ParseException; //导入依赖的package包/类
@Test
public void testSingle() throws ParseException {
LinkFormat lf = new LinkFormat("/power");
lf.setObservable(Boolean.TRUE);
lf.setResourceType("rt-test", "rt-test2");
lf.setInterfaceDescription("if-test");
lf.setMaximumSize(123);
lf.setResourceInstance("ri-test");
lf.setExport(Boolean.TRUE);
lf.setMedia("text/plain");
lf.setTitle("my title");
lf.setType("example type");
lf.setAnchor("/test/anch");
lf.setContentType((short) 12);
lf.setOAutobservable(true);
LinkFormat lf2 = LinkFormatBuilder.parse(lf.toString());
assertEquals(lf, lf2);
assertEquals(lf.getUri(), lf2.getUri());
assertEquals(lf.getContentType(), lf2.getContentType());
assertEquals(lf.getResourceTypeArray(), lf2.getResourceTypeArray());
assertEquals(lf.getInterfaceDescriptionArray(), lf2.getInterfaceDescriptionArray());
assertEquals(lf.isObservable(), lf2.isObservable());
assertEquals(lf.getMaxSize(), lf2.getMaxSize());
assertEquals(lf.getResourceInstance(), lf2.getResourceInstance());
assertEquals(lf.getExport(), lf2.getExport());
assertEquals(lf.getMedia(), lf2.getMedia());
assertEquals(lf.getTitle(), lf2.getTitle());
assertEquals(lf.getType(), lf2.getType());
assertEquals(lf.getAnchor(), lf2.getAnchor());
assertEquals(lf.getParam("href"), lf.getUri());
}
示例14: DERUTCTime
import java.text.ParseException; //导入依赖的package包/类
/**
* The correct format for this is YYMMDDHHMMSSZ (it used to be that seconds were
* never encoded. When you're creating one of these objects from scratch, that's
* what you want to use, otherwise we'll try to deal with whatever gets read from
* the input stream... (this is why the input format is different from the getTime()
* method output).
* <p>
*
* @param time the time string.
*/
public DERUTCTime(
String time)
{
this.time = time;
try
{
this.getDate();
}
catch (ParseException e)
{
throw new IllegalArgumentException("invalid date string: " + e.getMessage());
}
}
示例15: formatDate
import java.text.ParseException; //导入依赖的package包/类
public static Date formatDate(String csDate, String csFormat, boolean strict)
{
Date date = null;
if (csDate != null && csFormat != null && csFormat.length() > 0)
{
try
{
SimpleDateFormat formatter = new SimpleDateFormat(csFormat);
formatter.setLenient(false);
date = formatter.parse(csDate);
if (strict)
{
if (csFormat.length() != csDate.length())
{
date = null;
}
}
}
catch (ParseException e)
{
}
}
return date;
}