<commit_before>/******************************************************************
 * File:        XSDDateTime.java
 * Created by:  <NAME>
 * Created on:  17-Dec-2002
 * 
 * (c) Copyright 2002, Hewlett-Packard Development Company, LP
 * [See end of file]
 * $Id: XSDDateTime.java,v 1.11 2004-02-17 09:14:28 der Exp $
 *****************************************************************/
package com.hp.hpl.jena.datatypes.xsd;

import java.util.*;

/**
 * Represent an XSD date/time value. Rather than have a separate type for each
 * legal date/time value combination this is a combination type than does runtime
 * checks whether a given field is legal in the current circumstances.
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @version $Revision: 1.11 $ on $Date: 2004-02-17 09:14:28 $
 */
public class XSDDateTime extends AbstractDateTime {
    /** Mask to indicate whether year is present */
    public static final short YEAR_MASK = 0x1;
    
    /** Mask to indicate whether month is present */
    public static final short MONTH_MASK = 0x2;
    
    /** Mask to indicate whether day is present */
    public static final short DAY_MASK = 0x4;
    
    /** Mask to indicate whether time is present */
    public static final short TIME_MASK = 0x8;
    
    /** Mask to indicate all date/time are present */
    public static final short FULL_MASK = 0xf;
    
    /** table mapping xs type name to mask of legal values */
    public static final HashMap maskMap = new HashMap();
        
    /** Set of legal fields for the particular date/time instance */
    protected short mask;
    
    /**
     * Constructor - should only be used by the internals but public scope because
     * the internals spread across multiple packages.
     * 
     * @param value the date/time value returned by the parsing
     * @param mask bitmask defining which components are valid in this instance
     * (e.g. dates don't have valid time fields).
     */
    public XSDDateTime(Object value, int mask) {
        super(value);
        this.mask = (short)mask;
    }
    
    
    /**
     * Constructor - create a full DateTime object from a java calendar instance.
     * 
     * @param date java calendar instance
     */
    public XSDDateTime(Calendar date) {
        super(convertCalendar(date));
        this.mask = FULL_MASK;
    }
    
    /**
     * Convert a java calendar object to a new int[] in the format used by XSDAbstractDateTime
     */
    private static int[] convertCalendar(Calendar date) {
        int[] data = new int[TOTAL_SIZE];
        int offset = date.get(Calendar.ZONE_OFFSET);
        Calendar cal = date;
        if (offset != 0) {
            cal = (Calendar)date.clone();
            cal.add(Calendar.MILLISECOND, -offset);
        }
        data[AbstractDateTime.CY] = cal.get(Calendar.YEAR);
        data[AbstractDateTime.M] = cal.get(Calendar.MONTH);
        data[AbstractDateTime.D] = cal.get(Calendar.DAY_OF_MONTH);
        data[AbstractDateTime.h] = cal.get(Calendar.HOUR);
        data[AbstractDateTime.m] = cal.get(Calendar.MINUTE);
        data[AbstractDateTime.s] = cal.get(Calendar.SECOND);
        data[AbstractDateTime.ms] = cal.get(Calendar.MILLISECOND);
        data[AbstractDateTime.utc] = 'Z';
        return data;
    }

    /**
     * Return the date time as a java Calendar object. 
     * If the timezone has been specified then the object is normalized to GMT.
     * If the zone has not been specified then we use the default timezone.
     * 
     * @throws IllegalDateTimeFieldException if this is not a full date + time
     */
    public Calendar asCalendar () throws IllegalDateTimeFieldException {
        TimeZone tz = data[utc] == 'Z' ? TimeZone.getTimeZone("GMT") : TimeZone.getDefault();<commit_msg>Improve javadoc for asCalendar<commit_after>/******************************************************************
 * File:        XSDDateTime.java
 * Created by:  <NAME>
 * Created on:  17-Dec-2002
 * 
 * (c) Copyright 2002, Hewlett-Packard Development Company, LP
 * [See end of file]
 * $Id: XSDDateTime.java,v 1.12 2004-02-18 09:54:48 der Exp $
 *****************************************************************/
package com.hp.hpl.jena.datatypes.xsd;

import java.util.*;

/**
 * Represent an XSD date/time value. Rather than have a separate type for each
 * legal date/time value combination this is a combination type than does runtime
 * checks whether a given field is legal in the current circumstances.
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @version $Revision: 1.12 $ on $Date: 2004-02-18 09:54:48 $
 */
public class XSDDateTime extends AbstractDateTime {
    /** Mask to indicate whether year is present */
    public static final short YEAR_MASK = 0x1;
    
    /** Mask to indicate whether month is present */
    public static final short MONTH_MASK = 0x2;
    
    /** Mask to indicate whether day is present */
    public static final short DAY_MASK = 0x4;
    
    /** Mask to indicate whether time is present */
    public static final short TIME_MASK = 0x8;
    
    /** Mask to indicate all date/time are present */
    public static final short FULL_MASK = 0xf;
    
    /** table mapping xs type name to mask of legal values */
    public static final HashMap maskMap = new HashMap();
        
    /** Set of legal fields for the particular date/time instance */
    protected short mask;
    
    /**
     * Constructor - should only be used by the internals but public scope because
     * the internals spread across multiple packages.
     * 
     * @param value the date/time value returned by the parsing
     * @param mask bitmask defining which components are valid in this instance
     * (e.g. dates don't have valid time fields).
     */
    public XSDDateTime(Object value, int mask) {
        super(value);
        this.mask = (short)mask;
    }
    
    
    /**
     * Constructor - create a full DateTime object from a java calendar instance.
     * 
     * @param date java calendar instance
     */
    public XSDDateTime(Calendar date) {
        super(convertCalendar(date));
        this.mask = FULL_MASK;
    }
    
    /**
     * Convert a java calendar object to a new int[] in the format used by XSDAbstractDateTime
     */
    private static int[] convertCalendar(Calendar date) {
        int[] data = new int[TOTAL_SIZE];
        int offset = date.get(Calendar.ZONE_OFFSET);
        Calendar cal = date;
        if (offset != 0) {
            cal = (Calendar)date.clone();
            cal.add(Calendar.MILLISECOND, -offset);
        }
        data[AbstractDateTime.CY] = cal.get(Calendar.YEAR);
        data[AbstractDateTime.M] = cal.get(Calendar.MONTH);
        data[AbstractDateTime.D] = cal.get(Calendar.DAY_OF_MONTH);
        data[AbstractDateTime.h] = cal.get(Calendar.HOUR);
        data[AbstractDateTime.m] = cal.get(Calendar.MINUTE);
        data[AbstractDateTime.s] = cal.get(Calendar.SECOND);
        data[AbstractDateTime.ms] = cal.get(Calendar.MILLISECOND);
        data[AbstractDateTime.utc] = 'Z';
        return data;
    }

    /**
     * Return the date time as a java Calendar object. 
     * If the timezone has been specified then the object is normalized to GMT.
     * If the zone has not been specified then we use the default timezone.
     * <p>
     * N.B. The millisecond field will be discarded and the resulting Calendar
     * object will have 0 in the millisecond field. This is a workaround for an
     * apparent problem with some Linux JDK's Calendar implementations. If it
     * causes a problem contact us to ask us to revisit this.
     * </p>
     * 
     * @throws IllegalDateTimeFieldException if this is not a full date + time
     */
    public Calendar asCalendar () throws IllegalDateTimeFieldException {
        TimeZone tz = data[utc] == 'Z' ? TimeZone.getTimeZone("GMT") : TimeZone.getDefault();
{'fraction_non_alphanumeric': 0.1253970270613645, 'fraction_numerical': 0.01384830390039385, 'mean_word_length': 2.7308056872037914, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4620992', 'n_tokens_mistral': 2269, 'n_tokens_neox': 2134, 'n_words': 774}