List of usage examples for java.text ParsePosition ParsePosition
public ParsePosition(int index)
From source file:com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter.java
private Object doConvertToNumber(Map<String, Object> context, Object value, Class toType) { if (value instanceof String) { if (toType == BigDecimal.class) { return new BigDecimal((String) value); } else if (toType == BigInteger.class) { return new BigInteger((String) value); } else if (toType.isPrimitive()) { Object convertedValue = super.convertValue(context, value, toType); String stringValue = (String) value; if (!isInRange((Number) convertedValue, stringValue, toType)) throw new XWorkException("Overflow or underflow casting: \"" + stringValue + "\" into class " + convertedValue.getClass().getName()); return convertedValue; } else {//from w w w . j a v a2 s . c o m String stringValue = (String) value; if (!toType.isPrimitive() && (stringValue == null || stringValue.length() == 0)) { return null; } NumberFormat numFormat = NumberFormat.getInstance(getLocale(context)); ParsePosition parsePos = new ParsePosition(0); if (isIntegerType(toType)) { numFormat.setParseIntegerOnly(true); } numFormat.setGroupingUsed(true); Number number = numFormat.parse(stringValue, parsePos); if (parsePos.getIndex() != stringValue.length()) { throw new XWorkException( "Unparseable number: \"" + stringValue + "\" at position " + parsePos.getIndex()); } else { if (!isInRange(number, stringValue, toType)) throw new XWorkException("Overflow or underflow casting: \"" + stringValue + "\" into class " + number.getClass().getName()); value = super.convertValue(context, number, toType); } } } else if (value instanceof Object[]) { Object[] objArray = (Object[]) value; if (objArray.length == 1) { return doConvertToNumber(context, objArray[0], toType); } } // pass it through DefaultTypeConverter return super.convertValue(context, value, toType); }
From source file:gov.nih.nci.ncicb.cadsr.bulkloader.util.MainTestCase.java
protected Date createDate(String date) { return dateFormat.parse(date, new ParsePosition(0)); }
From source file:edu.usu.sdl.openstorefront.usecase.DataConvertUseCase.java
private List<ComponentAll> processData(List<OldAsset> assets, boolean generateData) { Set<String> metaTypeToSkip = new HashSet<>(); metaTypeToSkip.add("Government Point of Contact Email Address"); metaTypeToSkip.add("Government Point of Contact Name"); metaTypeToSkip.add("Government Point of Contact Phone"); metaTypeToSkip.add("Government Point of Contact Organization"); metaTypeToSkip.add("Code Location URL"); metaTypeToSkip.add("Product Homepage"); metaTypeToSkip.add("DI2E Framework Evaluation Report URL"); //Dummy data/* w w w . java 2 s .co m*/ List<String> peopleNames = Arrays.asList("Cathy TEST", "Jack TEST", "Colby TEST", "Abby TEST", "Dawson TEST"); List<String> userTypes = Arrays.asList("End User", "Developer", "Project Manager"); //questions Map<String, List<String>> questionMap = new HashMap<>(); questionMap.put("Which version supports y-docs 1.5+? (SAMPLE)", Arrays.asList("Version 3.1 added support.(SAMPLE)", "They depreciated support in version 4.0 since it was a rarely used feature.(SAMPLE)")); questionMap.put("Which os platforms does this support? (SAMPLE)", Arrays.asList( "CentOS 6.5 and MorphOS(SAMPLE)", "'I think they also have Windows and ReactOS support. (SAMPLE)")); questionMap.put("Does this support the 2.0 specs? (SAMPLE)", Arrays.asList("No, they planned to add support next Version(SAMPLE)", "Update: they backport support to version 1.6(SAMPLE)")); questionMap.put("Are samples included? (SAMPLE)", Arrays.asList("They are included in a separate download.(SAMPLE)")); questionMap.put("Are there alternate licenses? (SAMPLE)", Arrays.asList( "You can ask their support team for a custom commerical license that should cover you needs.(SAMPLE)", "We've try to get an alternate license and we've been waiting for over 6 months for thier legal department.(SAMPLE)")); List<Date> questionDates = Arrays.asList(TimeUtil.fromString("2014-1-03T10:15:30.00Z"), TimeUtil.fromString("2012-2-04T11:15:30.00Z"), TimeUtil.fromString("2013-10-13T12:15:30.00Z"), TimeUtil.fromString("2013-3-03T1:15:30.00Z"), TimeUtil.fromString("2013-4-30T2:15:30.00Z")); List<Date> answerDates = Arrays.asList(TimeUtil.fromString("2014-2-03T10:15:30.00Z"), TimeUtil.fromString("2014-2-04T11:15:30.00Z"), TimeUtil.fromString("2014-5-13T12:15:30.00Z"), TimeUtil.fromString("2014-3-03T1:15:30.00Z"), TimeUtil.fromString("2014-4-30T2:15:30.00Z")); Map<String, String> metadataMap = new HashMap<>(); metadataMap.put("Extra Metadata (SAMPLE)", "Unfiltered"); metadataMap.put("Support Common Interface 2.1 (SAMPLE)", "No"); metadataMap.put("Provides Web Hooks via RPC service(SAMPLE)", "Yes"); metadataMap.put("Common Uses (SAMPLE)", "UDOP, Information Sharing, Research"); metadataMap.put("Available to public (SAMPLE)", "YES"); // Map<String, String> attriubuteMap = new HashMap<>(); // attriubuteMap.put("License Restrictions (SAMPLE)", "Per CPU"); // attriubuteMap.put("Funded (SAMPLE)", "Yes"); // attriubuteMap.put("Network(s) Fielded (SAMPLE)", "NIPR, SIPR"); // attriubuteMap.put("Accreditation Status (SAMPLE)", "ATO"); // attriubuteMap.put("License Type (SAMPLE)", "FOSS"); // attriubuteMap.put("Protection/ Impact Level (SAMPLE)", "DoD MAC Level"); // attriubuteMap.put("Lifecycle Stage (SAMPLE)", "Development"); Map<String, String> reviewMap = new HashMap<>(); reviewMap.put("Good Product (SAMPLE)", "It's a good product. The features are nice and performed well. It quite configurable without a lot of setup and it worked out of the box."); reviewMap.put("Just what I was looking for (SAMPLE)", "This was perfect it solved our issues and provided tools for things we didn't even anticipate."); reviewMap.put("Great but missing features (SAMPLE)", "This is a great product however, it's missing what I think are critical features. Hopefully, they are working on it for future updates."); reviewMap.put("Confused (SAMPLE)", "This wasn't quite what I thought it was."); reviewMap.put("Hassle (SAMPLE)", "I had issues trying to obtain the component and once I got it is very to difficult to install."); List<String> pros = new ArrayList<>(); pros.add("Well tested"); pros.add("Active Development"); pros.add("Reliable"); pros.add("Open Source"); pros.add("Compact"); pros.add("Well Tested"); List<String> cons = new ArrayList<>(); cons.add("Poorly Tested"); cons.add("Security Concerns"); cons.add("Difficult Installation"); cons.add("Poor Documentation"); cons.add("Bulky"); cons.add("Legacy system"); List<String> organizations = new ArrayList<>(); organizations.add("NGA"); organizations.add("NSA"); organizations.add("DCGS Army"); organizations.add("DCGS Navy"); organizations.add("Private Company"); List<String> usedTimeCode = new ArrayList<>(); usedTimeCode.add("< 1 month'"); usedTimeCode.add("< 3 Months"); usedTimeCode.add("< 6 Months"); usedTimeCode.add("< 1 year"); usedTimeCode.add("< 3 years"); usedTimeCode.add("> 3 years"); Map<String, String> externalDependancyMap = new HashMap<>(); externalDependancyMap.put("Ruby", "Version 2.0+"); externalDependancyMap.put("Erlang", "Version 3.0"); externalDependancyMap.put("Linux", "Tested on CentOS 5 and Ubuntu Server 11.0"); externalDependancyMap.put("Windows", "Version 8.1"); externalDependancyMap.put("Tomcat", "Version 7 or 8"); List<String> evalSections = new ArrayList<>(); evalSections.add("Discoverable"); evalSections.add("Accessible"); evalSections.add("Documentation"); evalSections.add("Deployable"); evalSections.add("Usable"); evalSections.add("Error Handling"); evalSections.add("Integrable"); evalSections.add("I/O Validation"); evalSections.add("Testing"); evalSections.add("Monitoring"); evalSections.add("Performance"); evalSections.add("Scalability"); evalSections.add("Security"); evalSections.add("Maintainability"); evalSections.add("Community"); evalSections.add("Change Management"); evalSections.add("CA"); evalSections.add("Licensing"); evalSections.add("Roadmap"); evalSections.add("Willingness"); evalSections.add("Architecture Alignment"); List<String> evalLevelStatus = new ArrayList<>(); evalLevelStatus.add("P"); evalLevelStatus.add("H"); List<String> tags = new ArrayList<>(); tags.add("Mapping"); tags.add("Visualization"); tags.add("Reference"); tags.add("Data Exchange"); tags.add("Communication"); tags.add("UDOP"); tags.add("Charting"); tags.add("Testing"); tags.add("Access"); AttributeImport attributeImport = new AttributeImport(); Map<String, AttributeTypeView> attributeMap = attributeImport.loadAttributeMap(); ComponentAttribute idamAttribute = new ComponentAttribute(); ComponentAttributePk componentAttributePk = new ComponentAttributePk(); componentAttributePk.setAttributeType("DI2E-SVCV4-A"); componentAttributePk.setAttributeCode("1.2.1"); idamAttribute.setComponentAttributePk(componentAttributePk); Set<String> idamComponents = new HashSet<>(); idamComponents.add("Central Authentication Service (CAS)"); idamComponents.add("OpenAM"); idamComponents.add("DCGS-E Web Service Access Control Technical Profile"); SimpleDateFormat sdfDate = new SimpleDateFormat("MM/dd/yyyy"); List<ComponentAll> newAssets = new ArrayList<>(); String createUser; String updateUser; for (OldAsset oldAsset : assets) { ComponentAll componentAll = new ComponentAll(); componentAll.setComponent(new Component()); Component componentDetail = componentAll.getComponent(); //defaults componentDetail.setActiveStatus(StandardEntity.ACTIVE_STATUS); //map form old componentDetail.setComponentId("" + oldAsset.getId()); componentDetail.setGuid(oldAsset.getUuid()); componentDetail.setUpdateDts(oldAsset.getEditedDate()); if (componentDetail.getUpdateDts() == null) { componentDetail.setUpdateDts(TimeUtil.currentDate()); } String description = oldAsset.getDescription().replace("\n", " <br>"); description = StringProcessor.stripeExtendedChars(description); description = StringProcessor.createHrefUrls(description); componentDetail.setDescription(description); componentDetail.setApprovedDts(oldAsset.getApprovalDate()); componentDetail.setCreateDts(oldAsset.getCreateDate()); if (componentDetail.getCreateDts() == null) { componentDetail.setCreateDts(componentDetail.getUpdateDts()); } componentDetail.setVersion(oldAsset.getVersionName()); createUser = StringUtils.isNotBlank(oldAsset.getCreatedBy().getUsername()) ? oldAsset.getCreatedBy().getUsername() : OpenStorefrontConstant.SYSTEM_ADMIN_USER; updateUser = StringUtils.isNotBlank(oldAsset.getEditedBy().getUsername()) ? oldAsset.getEditedBy().getUsername() : OpenStorefrontConstant.SYSTEM_ADMIN_USER; if ("Approved".equalsIgnoreCase(oldAsset.getApprovalStatus())) { componentDetail.setApprovalState(ApprovalStatus.APPROVED); if (componentDetail.getApprovedDts() == null) { componentDetail.setApprovedDts(TimeUtil.currentDate()); componentDetail.setApprovedUser(createUser); } } else { componentDetail.setApprovalState(ApprovalStatus.PENDING); } componentDetail.setCreateUser(createUser); componentDetail.setUpdateUser(updateUser); componentDetail.setOrganization(oldAsset.getOrganization()); if (StringUtils.isBlank(oldAsset.getOrganization())) { componentDetail.setOrganization(OpenStorefrontConstant.NOT_AVAILABLE); } componentDetail.setName(oldAsset.getTitle()); if (idamComponents.contains(componentDetail.getName())) { idamAttribute.getComponentAttributePk().setComponentId(componentDetail.getComponentId()); idamAttribute.setComponentId(componentDetail.getComponentId()); componentAll.getAttributes().add(idamAttribute); } if (StringUtils.isNotBlank(oldAsset.getReleaseDate())) { componentDetail.setReleaseDate(sdfDate.parse(oldAsset.getReleaseDate(), new ParsePosition(0))); } componentDetail.setLastActivityDts(oldAsset.getLastActivity().getActivitiyDate()); if (componentDetail.getLastActivityDts() == null) { componentDetail.setLastActivityDts(TimeUtil.currentDate()); } oldAsset.getTechPocs().forEach(poc -> { ComponentContact contact = new ComponentContact(); contact.setActiveStatus(ComponentContact.ACTIVE_STATUS); contact.setComponentId(componentDetail.getComponentId()); contact.setContactType(ContactType.TECHINCAL); contact.setFirstName(poc); //contact.setEmail(); //contact.setPhone("555-555-5555"); contact.setOrganization(OpenStorefrontConstant.NOT_AVAILABLE); contact.setCreateUser(componentDetail.getCreateUser()); contact.setUpdateUser(componentDetail.getUpdateUser()); contact.setCreateDts(componentDetail.getCreateDts()); contact.setUpdateDts(componentDetail.getUpdateDts()); componentAll.getContacts().add(contact); }); //Government Contact oldAsset.getCustomFields().forEach(field -> { if ("Government Point of Contact Name".equalsIgnoreCase(field.getName())) { ComponentContact contact = new ComponentContact(); contact.setContactType(ContactType.GOVERNMENT); contact.setFirstName(field.getValue()); if (StringUtils.isBlank(contact.getFirstName())) { contact.setFirstName(OpenStorefrontConstant.NOT_AVAILABLE); } // contact.setEmail("sample_email@tt.com"); // contact.setPhone("555-555-5555"); // contact.setOrganization("sample organization"); contact.setOrganization(OpenStorefrontConstant.NOT_AVAILABLE); contact.setCreateUser(componentDetail.getCreateUser()); contact.setUpdateUser(componentDetail.getUpdateUser()); contact.setCreateDts(componentDetail.getCreateDts()); contact.setUpdateDts(componentDetail.getUpdateDts()); componentAll.getContacts().add(contact); } }); //media oldAsset.getScreenshots().forEach(screen -> { componentAll.getMedia().add(createMediaFromUrl(componentDetail, screen.getLargeImageUrl())); }); if (StringUtils.isNotBlank(oldAsset.getImageLargeUrl())) { componentAll.getMedia().add(createMediaFromUrl(componentDetail, oldAsset.getImageLargeUrl())); } //resources oldAsset.getDocUrls().forEach(doc -> { ComponentResource componentResource = new ComponentResource(); componentResource.setLink(StringProcessor.createHrefUrls(doc.getUrl(), true)); componentResource.setResourceType(ResourceType.DOCUMENT); componentResource.setComponentId(componentDetail.getComponentId()); componentResource.setActiveStatus(ComponentAttribute.ACTIVE_STATUS); componentResource.setCreateUser(componentDetail.getCreateUser()); componentResource.setUpdateUser(componentDetail.getUpdateUser()); componentResource.setCreateDts(componentDetail.getCreateDts()); componentResource.setUpdateDts(componentDetail.getUpdateDts()); componentAll.getResources().add(componentResource); }); // if (StringUtils.isNotBlank(oldAsset.getInstallUrl())) { // ComponentResourceView componentResource = new ComponentResourceView(); // componentResource.setName("Install Url"); // componentResource.setLink(StringProcessor.createHrefUrls(oldAsset.getInstallUrl(), true)); // componentResource.setResourceType("Document"); // componentAll.getResources().add(componentResource); // } oldAsset.getCustomFields().forEach(field -> { if (StringUtils.isNotBlank(field.getValue())) { String type = null; if ("Code Location URL".equals(field.getName())) { type = ResourceType.CODE; } else if ("Product Homepage".equals(field.getName())) { type = ResourceType.HOME_PAGE; } else if ("DI2E Framework Evaluation Report URL".equals(field.getName())) { type = ResourceType.DI2E_EVAL_REPORT; } if (type != null) { ComponentResource componentResource = new ComponentResource(); componentResource.setLink(StringProcessor.createHrefUrls(field.getValue(), true)); componentResource.setResourceType(type); componentResource.setComponentId(componentDetail.getComponentId()); componentResource.setActiveStatus(ComponentAttribute.ACTIVE_STATUS); componentResource.setCreateUser(componentDetail.getCreateUser()); componentResource.setUpdateUser(componentDetail.getUpdateUser()); componentResource.setCreateDts(componentDetail.getCreateDts()); componentResource.setUpdateDts(componentDetail.getUpdateDts()); componentAll.getResources().add(componentResource); } } }); Map<String, String> typeXRefMap = new HashMap<>(); typeXRefMap.put("Application", "APP"); typeXRefMap.put("Development Tools", "DEVTOOL"); typeXRefMap.put("Documentation", "DOC"); typeXRefMap.put("Environment", "ENV"); typeXRefMap.put("Widget", "WIDGET"); typeXRefMap.put("Other", "OTH"); typeXRefMap.put("OZONE App", "OZONE"); typeXRefMap.put("Service Endpoint", "SERVICE"); typeXRefMap.put("Software", "SOFTWARE"); typeXRefMap.put("Standards, Specifications, and APIs", "SPEC"); typeXRefMap.put("Web App", "WEBAPP"); //metadata/attributes ComponentAttribute attribute = mapAttribute(componentDetail, AttributeType.TYPE, typeXRefMap.get(oldAsset.getTypes().getTitle())); componentAll.getAttributes().add(attribute); String oldStateLabel = oldAsset.getState().getTitle(); String stateLabel = null; Set<String> stateCodeSet = new HashSet<>(); stateCodeSet.add(AttributeCode.DI2ELEVEL_NA); stateCodeSet.add(AttributeCode.DI2ELEVEL_LEVEL0); stateCodeSet.add(AttributeCode.DI2ELEVEL_LEVEL1); stateCodeSet.add(AttributeCode.DI2ELEVEL_LEVEL2); stateCodeSet.add(AttributeCode.DI2ELEVEL_LEVEL3); if ("NA - No Eval Planned".equals(oldStateLabel)) { stateLabel = AttributeCode.DI2ELEVEL_NA; stateCodeSet.remove(AttributeCode.DI2ELEVEL_NA); stateCodeSet.remove(AttributeCode.DI2ELEVEL_LEVEL0); stateCodeSet.remove(AttributeCode.DI2ELEVEL_LEVEL1); stateCodeSet.remove(AttributeCode.DI2ELEVEL_LEVEL2); stateCodeSet.remove(AttributeCode.DI2ELEVEL_LEVEL3); } else if ("Level 0 - Not assessed".equals(oldStateLabel)) { stateLabel = AttributeCode.DI2ELEVEL_LEVEL0; stateCodeSet.remove(AttributeCode.DI2ELEVEL_LEVEL0); stateCodeSet.remove(AttributeCode.DI2ELEVEL_NA); } else if ("Level 1 - Checklist Complete".equals(oldStateLabel)) { stateLabel = AttributeCode.DI2ELEVEL_LEVEL1; stateCodeSet.remove(AttributeCode.DI2ELEVEL_LEVEL1); stateCodeSet.remove(AttributeCode.DI2ELEVEL_NA); } attribute = mapAttribute(componentDetail, AttributeType.DI2ELEVEL, stateLabel); componentAll.getAttributes().add(attribute); for (OldAssetCategory category : oldAsset.getCategories()) { ComponentAttribute catAttribute = new ComponentAttribute(); ComponentAttributePk attributePk = new ComponentAttributePk(); attributePk.setAttributeType(AttributeType.DI2E_SVCV4); attributePk.setComponentId(componentDetail.getComponentId()); catAttribute.setComponentAttributePk(attributePk); catAttribute.setActiveStatus(ComponentAttribute.ACTIVE_STATUS); catAttribute.setCreateUser(componentDetail.getCreateUser()); catAttribute.setUpdateUser(componentDetail.getUpdateUser()); catAttribute.setCreateDts(componentDetail.getCreateDts()); catAttribute.setUpdateDts(componentDetail.getUpdateDts()); catAttribute.setComponentId(componentDetail.getComponentId()); AttributeTypeView attributeTypeView = attributeMap.get(AttributeType.DI2E_SVCV4); for (AttributeCodeView attributeCodeView : attributeTypeView.getCodes()) { String label = attributeCodeView.getLabel().substring( attributeCodeView.getLabel().indexOf(" ") + 1, attributeCodeView.getLabel().length()); if (label.equalsIgnoreCase(category.getTitle().trim())) { catAttribute.getComponentAttributePk().setAttributeCode(attributeCodeView.getCode()); break; } } if (StringUtils.isNotBlank(catAttribute.getComponentAttributePk().getAttributeCode())) { componentAll.getAttributes().add(catAttribute); } } oldAsset.getCustomFields().forEach(field -> { if (StringUtils.isNotBlank(field.getValue()) && !metaTypeToSkip.contains(field.getName())) { String originTypeDesc = field.getName(); String originCodeLabel = field.getValue(); String newType = null; String newCode = null; //Skip N/A if ("N/A".equals(originCodeLabel.trim()) == false) { if ("Commercial Export Approved via EAR".equals(originTypeDesc)) { newType = "CEEAR"; if ("Yes".equalsIgnoreCase(originCodeLabel)) { newCode = "Y"; } else { newCode = "N"; } } else if ("ITAR Export Approved".equals(originTypeDesc)) { newType = "ITAR"; if ("Yes".equalsIgnoreCase(originCodeLabel)) { newCode = "Y"; } else { newCode = "N"; } } else if ("Software License Method".equals(originTypeDesc)) { newType = "LICTYPE"; if ("Open Source".startsWith(originCodeLabel)) { newCode = "OPENSRC"; } else if ("Enterprise".equalsIgnoreCase(originCodeLabel)) { newCode = "ENT"; } else if ("Government Unlimited Rights".startsWith(originCodeLabel)) { newCode = "GOVUNL"; } } else if ("Software License Type".equals(originTypeDesc)) { newType = "LICCLASS"; if ("Open Source".startsWith(originCodeLabel)) { newCode = "FOSS"; } else if ("FOSS".equalsIgnoreCase(originCodeLabel)) { newCode = "FOSS"; } else if ("GOSS".startsWith(originCodeLabel)) { newCode = "GOSS"; } else if ("COTS".equalsIgnoreCase(originCodeLabel)) { newCode = "COTS"; } else if ("GOTS".equalsIgnoreCase(originCodeLabel)) { newCode = "GOTS"; } else if ("OpenSource".equalsIgnoreCase(originCodeLabel)) { newCode = "FOSS"; } } else if ("Life Cycle Stage".equals(originTypeDesc)) { newType = "LIFECYCSTG"; if ("Development".equalsIgnoreCase(originCodeLabel)) { newCode = "DEV"; } else if ("Pilot".equalsIgnoreCase(originCodeLabel)) { newCode = "PILOT"; } else if ("Operations".equalsIgnoreCase(originCodeLabel)) { newCode = "OPR"; } } else if ("OWF Compatible Widget (Y/N)".equals(originTypeDesc)) { newType = "OWFCOMP"; if ("Yes".equalsIgnoreCase(originCodeLabel)) { newCode = "Y"; } else { newCode = "N"; } } } if (newType != null && newCode != null) { ComponentAttribute metaAttribute = mapAttribute(componentDetail, newType, newCode); componentAll.getAttributes().add(metaAttribute); } } }); newAssets.add(componentAll); } return newAssets; }
From source file:com.sun.socialsite.util.DateUtil.java
/** * Parse data as either 6-char or 8-char format. *//*from w w w . j av a 2 s .co m*/ public static Date parseWeblogURLDateString(String dateString, TimeZone tz, Locale locale) { Date ret = new Date(); DateFormat char8DateFormat = DateUtil.get8charDateFormat(); DateFormat char6DateFormat = DateUtil.get6charDateFormat(); if (dateString != null && dateString.length() == 8 && StringUtils.isNumeric(dateString)) { ParsePosition pos = new ParsePosition(0); ret = char8DateFormat.parse(dateString, pos); // make sure the requested date is not in the future Date today = null; Calendar todayCal = Calendar.getInstance(); todayCal = Calendar.getInstance(tz, locale); todayCal.setTime(new Date()); today = todayCal.getTime(); if (ret.after(today)) { ret = today; } } else if (dateString != null && dateString.length() == 6 && StringUtils.isNumeric(dateString)) { ParsePosition pos = new ParsePosition(0); ret = char6DateFormat.parse(dateString, pos); // make sure the requested date is not in the future Calendar todayCal = Calendar.getInstance(); todayCal = Calendar.getInstance(tz, locale); todayCal.setTime(new Date()); Date today = todayCal.getTime(); if (ret.after(today)) { ret = today; } } return ret; }
From source file:com.unboundid.scim2.common.JsonUtilsTestCase.java
/** * Test the findMatchingPaths method./*from ww w. j a v a 2 s . c o m*/ * * @throws Exception If an error occurred. */ @Test public void testGet() throws Exception { GenericScimResource gso = new GenericScimResource(getTestResource()); List<JsonNode> stringResult = JsonUtils.findMatchingPaths(Path.fromString("String"), gso.getObjectNode()); assertEquals(stringResult.size(), 1); assertEquals(stringResult.get(0).textValue(), "string"); List<JsonNode> intResult = JsonUtils.findMatchingPaths(Path.fromString("integeR"), gso.getObjectNode()); assertEquals(intResult.size(), 1); assertEquals(intResult.get(0).intValue(), 1); List<JsonNode> decimalResult = JsonUtils.findMatchingPaths(Path.fromString("deCimal"), gso.getObjectNode()); assertEquals(decimalResult.size(), 1); assertEquals(decimalResult.get(0).doubleValue(), 1.582); List<JsonNode> booleanResult = JsonUtils.findMatchingPaths(Path.fromString("boolean"), gso.getObjectNode()); assertEquals(booleanResult.size(), 1); assertEquals(booleanResult.get(0).booleanValue(), true); List<JsonNode> dateResult = JsonUtils.findMatchingPaths(Path.fromString("date"), gso.getObjectNode()); assertEquals(dateResult.size(), 1); assertEquals(ISO8601Utils.parse(dateResult.get(0).textValue(), new ParsePosition(0)), ISO8601Utils.parse("2015-02-27T11:28:39Z", new ParsePosition(0))); List<JsonNode> binaryResult = JsonUtils.findMatchingPaths(Path.fromString("binary"), gso.getObjectNode()); assertEquals(binaryResult.size(), 1); assertEquals(binaryResult.get(0).binaryValue(), "binary".getBytes()); }
From source file:com.examples.with.different.packagename.testcarver.NumberConverter.java
/** * Convert a String into a <code>Number</code> object. * @param sourceType TODO//from w ww.j av a2 s .co m * @param targetType The type to convert the value to * @param value The String date value. * @param format The NumberFormat to parse the String value. * * @return The converted Number object. * @throws ConversionException if the String cannot be converted. */ private Number parse(Class sourceType, Class targetType, String value, NumberFormat format) { ParsePosition pos = new ParsePosition(0); Number parsedNumber = format.parse(value, pos); if (pos.getErrorIndex() >= 0 || pos.getIndex() != value.length() || parsedNumber == null) { String msg = "Error converting from '" + toString(sourceType) + "' to '" + toString(targetType) + "'"; if (format instanceof DecimalFormat) { msg += " using pattern '" + ((DecimalFormat) format).toPattern() + "'"; } if (locale != null) { msg += " for locale=[" + locale + "]"; } throw new ConversionException(msg); } return parsedNumber; }
From source file:py.una.pol.karaku.util.FormatProvider.java
/** * Formatea una fecha con el formato dado * //from ww w. j a v a 2s . co m * @param string * cadena a formatear * @param format * formato deseado * @return {@link Date} con los demas parmetros a cero. * @throws ParseException * si el formato no es adecuado. */ protected synchronized Date stringToDate(String string, String format) throws ParseException { if (string == null || EMPTY_STRING.equals(string)) { return null; } SimpleDateFormat sdf = this.getFormat(format); ParsePosition psp = new ParsePosition(0); if (string.length() != format.length()) { this.throwException(string, format); } Date toRet = sdf.parse(string, psp); if (psp.getIndex() != string.length()) { this.throwException(string, format); } return toRet; }
From source file:com.almalence.util.Util.java
public static boolean isNumeric(String str) { NumberFormat formatter = NumberFormat.getInstance(); ParsePosition pos = new ParsePosition(0); formatter.parse(str, pos);/*from w ww. j a va 2 s . co m*/ return str.length() == pos.getIndex(); }
From source file:org.noorganization.instalistsynch.controller.local.dba.impl.SqliteGroupAccessDbControllerTest.java
License:asdf
public void testUpdateToken() throws Exception { Date currentDate = new Date(); SQLiteDatabase db = mDbHelper.getWritableDatabase(); ContentValues cv = new ContentValues(); cv.put(GroupAccess.COLUMN.GROUP_ID, 1); cv.put(GroupAccess.COLUMN.INTERRUPTED, false); cv.put(GroupAccess.COLUMN.SYNCHRONIZE, true); cv.put(GroupAccess.COLUMN.LAST_UPDATE_FROM_SERVER, ISO8601Utils.format(currentDate)); cv.put(GroupAccess.COLUMN.LAST_TOKEN_REQUEST, ISO8601Utils.format(currentDate)); cv.put(GroupAccess.COLUMN.TOKEN, "fdskhbvvkddscddueFSNDFSAdnandk3229df-dFSJDKMds."); assertTrue(db.insert(GroupAccess.TABLE_NAME, null, cv) >= 0); assertTrue(mGroupAuthAccessDbController.updateToken(1, "fdskhbvvkddscddueasdfeSAdnandk3229df-dFSJDKMds.")); Cursor cursor = db.query(GroupAccess.TABLE_NAME, GroupAccess.COLUMN.ALL_COLUMNS, GroupAccess.COLUMN.GROUP_ID + " = ? ", new String[] { String.valueOf(1) }, null, null, null); int count = cursor.getCount(); if (count == 0) cursor.close();// w w w . ja va2 s . co m assertTrue(cursor.moveToFirst()); int groupId = cursor.getInt(cursor.getColumnIndex(GroupAccess.COLUMN.GROUP_ID)); boolean synchronize = cursor.getInt(cursor.getColumnIndex(GroupAccess.COLUMN.SYNCHRONIZE)) == 1; boolean interrupted = cursor.getInt(cursor.getColumnIndex(GroupAccess.COLUMN.INTERRUPTED)) == 1; Date lastTokenRequestDate = ISO8601Utils.parse( cursor.getString(cursor.getColumnIndex(GroupAccess.COLUMN.LAST_TOKEN_REQUEST)), new ParsePosition(0)); Date lastUpdateDate = ISO8601Utils.parse( cursor.getString(cursor.getColumnIndex(GroupAccess.COLUMN.LAST_UPDATE_FROM_SERVER)), new ParsePosition(0)); String token = cursor.getString(cursor.getColumnIndex(GroupAccess.COLUMN.TOKEN)); cursor.close(); assertEquals(1, groupId); assertEquals(true, synchronize); assertEquals(false, interrupted); assertEquals(ISO8601Utils.format(currentDate), ISO8601Utils.format(lastTokenRequestDate)); assertEquals(ISO8601Utils.format(currentDate), ISO8601Utils.format(lastUpdateDate)); assertEquals("fdskhbvvkddscddueasdfeSAdnandk3229df-dFSJDKMds.", token); }
From source file:com.stimulus.archiva.domain.Email.java
public Date getReceivedDate() { MailDateFormat mdf = new MailDateFormat(); try {/*from ww w. j a va2 s .c om*/ /* Enumeration e = getAllHeaders(); while (e.hasMoreElements()) { Header h = (Header)e.nextElement(); System.out.println(h.getName()+":"+h.getValue()); }*/ String[] header = getHeader("Received"); if (header == null || header.length < 1) { return null; } for (int i = 0; i < header.length; i++) { int received = header[i].lastIndexOf(';'); if (received >= 0) { String dateStr = header[i].substring(received + 1).trim(); Date date = mdf.parse(dateStr, new ParsePosition(0)); return date; } } } catch (Exception re) { logger.debug("getReceivedDate(). unable to parse received date", re); } return null; }