コード例 #1
0
ファイル: DateTest.java プロジェクト: hishidama/asakusafw
 /** 単純な文字列解析。 */
 @Test
 public void parse() {
   Date date = Date.valueOf("12340102", Date.Format.SIMPLE);
   assertThat(date.getYear(), is(1234));
   assertThat(date.getMonth(), is(1));
   assertThat(date.getDay(), is(2));
 }
コード例 #2
0
ファイル: DateTest.java プロジェクト: hishidama/asakusafw
 /** parses standard date string. */
 @Test
 public void parse_standard() {
   Date date = Date.valueOf("1234-01-02", Date.Format.STANDARD);
   assertThat(date.getYear(), is(1234));
   assertThat(date.getMonth(), is(1));
   assertThat(date.getDay(), is(2));
 }
コード例 #3
0
ファイル: DateTest.java プロジェクト: hishidama/asakusafw
 /** 大きな日付の文字列解析。 */
 @Test
 public void parse_big() {
   Date date = Date.valueOf("29991231", Date.Format.SIMPLE);
   assertThat(date.getYear(), is(2999));
   assertThat(date.getMonth(), is(12));
   assertThat(date.getDay(), is(31));
 }
コード例 #4
0
ファイル: DateTest.java プロジェクト: hishidama/asakusafw
 /** 最初の日付の文字列解析。 */
 @Test
 public void parse_zero() {
   Date date = Date.valueOf("00010101", Date.Format.SIMPLE);
   assertThat(date.getYear(), is(1));
   assertThat(date.getMonth(), is(1));
   assertThat(date.getDay(), is(1));
 }
コード例 #5
0
ファイル: DateTest.java プロジェクト: hishidama/asakusafw
 /** optionの解析。 */
 @Test
 public void parse_option() {
   StringOption option = new StringOption("20100615");
   Date date = Date.valueOf(option, Date.Format.SIMPLE);
   assertThat(date.getYear(), is(2010));
   assertThat(date.getMonth(), is(6));
   assertThat(date.getDay(), is(15));
 }
コード例 #6
0
ファイル: Timestamp.java プロジェクト: hammoum/gwt
  public static Timestamp valueOf(String s) {
    String[] components = s.split(" ");
    if (components.length != 2) {
      throw new IllegalArgumentException("Invalid escape format: " + s);
    }

    String[] timeComponents = components[1].split("\\.");
    boolean hasNanos = true;
    int nanos = 0;

    if (timeComponents.length == 1) {
      // Allow timestamps without .fffffffff nanoseconds field
      hasNanos = false;
    } else if (timeComponents.length != 2) {
      throw new IllegalArgumentException("Invalid escape format: " + s);
    }

    Date d = Date.valueOf(components[0]);
    Time t = Time.valueOf(timeComponents[0]);
    if (hasNanos) {
      String nanosString = timeComponents[1];
      int len = nanosString.length();
      assert len > 0; // len must be > 0 if hasNanos is true
      if (len > 9) {
        throw new IllegalArgumentException("Invalid escape format: " + s);
      }

      // Pad zeros on the right up to a total of 9 digits
      if (len < 9) {
        nanosString += "00000000".substring(len - 1);
      }

      try {
        nanos = Integer.valueOf(nanosString);
      } catch (NumberFormatException e) {
        throw new IllegalArgumentException("Invalid escape format: " + s);
      }
    }

    return new Timestamp(
        d.getYear(),
        d.getMonth(),
        d.getDate(),
        t.getHours(),
        t.getMinutes(),
        t.getSeconds(),
        nanos);
  }
コード例 #7
0
ファイル: DateTest.java プロジェクト: hishidama/asakusafw
 /** nullの解析。 */
 @Test
 public void parse_null() {
   StringOption option = new StringOption(null);
   Date date = Date.valueOf(option, Date.Format.SIMPLE);
   assertThat(date, is(nullValue()));
 }
コード例 #8
0
  @Deprecated
  public static FundingForm valueOf(org.orcid.jaxb.model.message.Funding funding) {
    FundingForm result = new FundingForm();

    result.setDateSortString(
        PojoUtil.createDateSortString(funding.getStartDate(), funding.getEndDate()));

    if (funding.getPutCode() != null) result.setPutCode(Text.valueOf(funding.getPutCode()));

    if (funding.getAmount() != null) {
      if (StringUtils.isNotEmpty(funding.getAmount().getContent())) {
        String cleanNumber = funding.getAmount().getContent().trim();
        result.setAmount(Text.valueOf(cleanNumber));
      }
      if (funding.getAmount().getCurrencyCode() != null)
        result.setCurrencyCode(Text.valueOf(funding.getAmount().getCurrencyCode()));
      else result.setCurrencyCode(new Text());
    } else {
      result.setAmount(new Text());
      result.setCurrencyCode(new Text());
    }
    if (StringUtils.isNotEmpty(funding.getDescription()))
      result.setDescription(Text.valueOf(funding.getDescription()));
    else result.setDescription(new Text());

    if (funding.getStartDate() != null) result.setStartDate(Date.valueOf(funding.getStartDate()));

    if (funding.getEndDate() != null) result.setEndDate(Date.valueOf(funding.getEndDate()));

    if (funding.getType() != null) result.setFundingType(Text.valueOf(funding.getType().value()));
    else result.setFundingType(new Text());

    if (funding.getOrganizationDefinedFundingType() != null) {
      OrgDefinedFundingSubType OrgDefinedFundingSubType = new OrgDefinedFundingSubType();
      OrgDefinedFundingSubType.setSubtype(
          Text.valueOf(funding.getOrganizationDefinedFundingType().getContent()));
      OrgDefinedFundingSubType.setAlreadyIndexed(false);
      result.setOrganizationDefinedFundingSubType(OrgDefinedFundingSubType);
    }

    org.orcid.jaxb.model.message.Source source = funding.getSource();
    if (source != null) {
      result.setSource(source.retrieveSourcePath());
      if (source.getSourceName() != null) {
        result.setSourceName(source.getSourceName().getContent());
      }
    }

    if (funding.getTitle() != null) {
      FundingTitleForm fundingTitle = new FundingTitleForm();
      if (funding.getTitle().getTitle() != null)
        fundingTitle.setTitle(Text.valueOf(funding.getTitle().getTitle().getContent()));
      else fundingTitle.setTitle(new Text());
      if (funding.getTitle().getTranslatedTitle() != null) {
        TranslatedTitleForm translatedTitle = new TranslatedTitleForm();
        translatedTitle.setContent(funding.getTitle().getTranslatedTitle().getContent());
        translatedTitle.setLanguageCode(funding.getTitle().getTranslatedTitle().getLanguageCode());
        fundingTitle.setTranslatedTitle(translatedTitle);
      }
      result.setFundingTitle(fundingTitle);
    } else {
      FundingTitleForm fundingTitle = new FundingTitleForm();
      fundingTitle.setTitle(new Text());
      result.setFundingTitle(fundingTitle);
    }

    if (funding.getUrl() != null) result.setUrl(Text.valueOf(funding.getUrl().getValue()));
    else result.setUrl(new Text());

    if (funding.getVisibility() != null)
      result.setVisibility(Visibility.valueOf(funding.getVisibility()));

    // Set the disambiguated organization
    org.orcid.jaxb.model.message.Organization organization = funding.getOrganization();
    result.setFundingName(Text.valueOf(organization.getName()));
    org.orcid.jaxb.model.message.DisambiguatedOrganization disambiguatedOrganization =
        organization.getDisambiguatedOrganization();
    if (disambiguatedOrganization != null) {
      if (StringUtils.isNotEmpty(
          disambiguatedOrganization.getDisambiguatedOrganizationIdentifier())) {
        result.setDisambiguatedFundingSourceId(
            Text.valueOf(disambiguatedOrganization.getDisambiguatedOrganizationIdentifier()));
        result.setDisambiguationSource(
            Text.valueOf(disambiguatedOrganization.getDisambiguationSource()));
      }
    }
    org.orcid.jaxb.model.message.OrganizationAddress organizationAddress =
        organization.getAddress();
    if (organizationAddress != null) {
      if (!PojoUtil.isEmpty(organizationAddress.getCity()))
        result.setCity(Text.valueOf(organizationAddress.getCity()));
      else result.setCity(new Text());
      if (!PojoUtil.isEmpty(organizationAddress.getRegion()))
        result.setRegion(Text.valueOf(organizationAddress.getRegion()));
      else result.setRegion(new Text());
      if (organizationAddress.getCountry() != null)
        result.setCountry(Text.valueOf(organizationAddress.getCountry().value()));
      else result.setCountry(new Text());

    } else {
      result.setCountry(new Text());
      result.setCity(new Text());
      result.setRegion(new Text());
    }

    // Set contributors
    if (funding.getFundingContributors() != null) {
      List<Contributor> contributors = new ArrayList<Contributor>();
      for (org.orcid.jaxb.model.message.FundingContributor fContributor :
          funding.getFundingContributors().getContributor()) {
        Contributor contributor = Contributor.valueOf(fContributor);
        contributors.add(contributor);
      }
      result.setContributors(contributors);
    }

    List<FundingExternalIdentifierForm> externalIdentifiersList =
        new ArrayList<FundingExternalIdentifierForm>();
    // Set external identifiers
    if (funding.getFundingExternalIdentifiers() != null) {
      for (org.orcid.jaxb.model.message.FundingExternalIdentifier fExternalIdentifier :
          funding.getFundingExternalIdentifiers().getFundingExternalIdentifier()) {
        FundingExternalIdentifierForm fundingExternalIdentifierForm =
            FundingExternalIdentifierForm.valueOf(fExternalIdentifier);
        externalIdentifiersList.add(fundingExternalIdentifierForm);
      }
    }
    result.setExternalIdentifiers(externalIdentifiersList);

    result.setCreatedDate(Date.valueOf(funding.getCreatedDate()));
    result.setLastModified(Date.valueOf(funding.getLastModifiedDate()));

    return result;
  }