<commit_before>/*
 * Copyright (c) 2012 Orderly Ltd. All rights reserved.
 *
 * This program is licensed to you under the Apache License Version 2.0,
 * and you may not use this file except in compliance with the Apache License Version 2.0.
 * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the Apache License Version 2.0 is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
 */
package co.orderly.narcolepsy.marshallers.jaxb.types

// Java
import java.text.SimpleDateFormat
import java.util.{Date => JDate}

// JAXB
import javax.xml.bind.annotation.adapters.XmlAdapter

/**
 * DateSpaceTimeAdapter is for handling datetimes in the format yyyy-MM-dd HH:mm:ss.
 *
 * This is useful because by default JAXB expects datetimes to be in the format
 * yyyy-MM-ddTHH:mm:ss (note the 'T' in the middle)
 */
class DateSpaceTimeAdapter extends XmlAdapter[String, JDate] {

  private val dateFormat: SimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")

  @throws(classOf[Exception])
  override def marshal(value: JDate): String = dateFormat.format(value)

  @throws(classOf[Exception])
  override def unmarshal(value: String): JDate = {

    if (value == "0000-00-00 00:00:00") { // Lazy APIs use this value where they should use null
      null
    } else {
      dateFormat.parse(value)
    }<commit_msg>Adding support for a null date (not previously implemented)<commit_after>/*
 * Copyright (c) 2012 Orderly Ltd. All rights reserved.
 *
 * This program is licensed to you under the Apache License Version 2.0,
 * and you may not use this file except in compliance with the Apache License Version 2.0.
 * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the Apache License Version 2.0 is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
 */
package co.orderly.narcolepsy.marshallers.jaxb.types

// Java
import java.text.SimpleDateFormat
import java.util.{Date => JDate}

// JAXB
import javax.xml.bind.annotation.adapters.XmlAdapter

/**
 * DateSpaceTimeAdapter is for handling datetimes in the format yyyy-MM-dd HH:mm:ss.
 *
 * This is useful because by default JAXB expects datetimes to be in the format
 * yyyy-MM-ddTHH:mm:ss (note the 'T' in the middle)
 */
class DateSpaceTimeAdapter extends XmlAdapter[String, JDate] {

  private val dateFormat: SimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")

  @throws(classOf[Exception])
  override def marshal(value: JDate): String = dateFormat.format(value)

  @throws(classOf[Exception])
  override def unmarshal(value: String): JDate = Option(value) match {
    case Some(date) if date != "0000-00-00 00:00:00" => dateFormat.parse(date)
    case _ => null
{'fraction_non_alphanumeric': 0.08996328029375765, 'fraction_numerical': 0.01835985312117503, 'mean_word_length': 4.139937106918239, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4944483', 'n_tokens_mistral': 990, 'n_tokens_neox': 928, 'n_words': 374}