⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 schemacalendarbase.java

📁 java 3d game jme 工程开发源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**
 * SchemaCalendarBase.java
 *
 * This file was generated by XMLSpy 2007sp2 Enterprise Edition.
 *
 * YOU SHOULD NOT MODIFY THIS FILE, BECAUSE IT WILL BE
 * OVERWRITTEN WHEN YOU RE-RUN CODE GENERATION.
 *
 * Refer to the XMLSpy Documentation for further details.
 * http://www.altova.com/xmlspy
 */


package com.jmex.xml.types;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;


public abstract class SchemaCalendarBase implements SchemaTypeCalendar {
  public static final int TZ_MISSING = 0;
  public static final int TZ_UTC = 1;
  public static final int TZ_OFFSET = 2;

  protected int year;
  protected int month;
  protected int day;
  protected int hour;
  protected int minute;
  protected int second;
  protected double partsecond; // 0.0 <= partsecond < 1.0
  protected int hasTZ;
  protected int offsetTZ; // offset in minutes
  protected boolean isempty;
    
  protected final int DateTimePart_Year = 1 << 0;
  protected final int DateTimePart_Month = 1 << 1;
  protected final int DateTimePart_Day = 1 << 2;
  protected final int DateTimePart_Date = DateTimePart_Year | DateTimePart_Month | DateTimePart_Day;
  protected final int DateTimePart_Time = 1 << 3;
  
  // helper classes - int by reference
  class RefInt
  {
	  RefInt(int i) {value = i;}
	  public int value;
  }
  
  // helper classes - parse context
  class ParseContext
  {
    String source;
    int index;
    
    public ParseContext(String source) 
    {
    	this.source = source;
    	this.index = 0;
    }
    
    public boolean isValid()
    {
    	return index < source.length();
    }
    
    public boolean check(char expect)
    {
    	if (!isValid())
    		return false;
    	return source.charAt(index) == expect;
    }
    
    public boolean checkAndAdvance(char expect)
    {
    	if (!check(expect))
    		return false;
    	advance();
    	return true;
    }
    
    public void advance()
    {
    	++index;
    }
    
    public boolean readDigitAndAdvance(RefInt i, int scale, int maxdigit)
    {
    	if (!isValid()) return false;
    	char c = source.charAt(index);
    	if (c<'0' || c>'9')
    		return false;
    	int val = (int)c - (int)'0';
    	if (val > maxdigit)
    		return false;
    	i.value += (val * scale);
    	advance();
    	return true;
    }
  }
  
  public SchemaCalendarBase() {
    setEmpty();
  }

  public void setNull() {
    setEmpty();
  }

  public void setEmpty() {
    setInternalValues( 1,1,1, 0,0,0, 0.0, TZ_MISSING ,0 );
	  isempty = true;
  }

  public boolean equals(Object obj) {
    if (! (obj instanceof SchemaCalendarBase))
      return false;
    SchemaCalendarBase dt = (SchemaCalendarBase)obj;
    if( !(year == dt.year) )
      return false;
    if( !(month == dt.month) )
      return false;
    if( !(day == dt.day) )
      return false;
    if( !(hour == dt.hour) )
      return false;
    if( !(minute == dt.minute) )
      return false;
    if( !(second == dt.second) )
      return false;
    if( !(partsecond == dt.partsecond) )
      return false;
    if( !(hasTZ == dt.hasTZ) )
      return false;
    if( !(offsetTZ == dt.offsetTZ) )
      return false;
    return true;
  }

  public int hashCode() {
    return (int) Double.doubleToLongBits(getApproximatedTotal());
  }

  public String toDateString() {
    StringBuffer s = new StringBuffer();
    s.append( new DecimalFormat("0000").format( (long)year ) );
    s.append("-");
    s.append( new DecimalFormat("00").format( (long)month) );
    s.append("-");
    s.append( new DecimalFormat("00").format( (long)day) );
    return s.toString();
  }

  public String toTimeString() {
    StringBuffer s = new StringBuffer();
    s.append( new DecimalFormat("00").format( (long)hour) );
    s.append(":");
    s.append( new DecimalFormat("00").format( (long)minute) );
    s.append(":");
    s.append( new DecimalFormat("00").format( (long)second) );
    if( partsecond > 0 && partsecond < 1) {
      String sPartSecond = new DecimalFormat("0.0###############").format( partsecond );
      s.append( "." );
      s.append( sPartSecond.substring( 2, sPartSecond.length() ) );
    }
 	if( hasTZ == TZ_UTC ) {
      s.append("Z");
	}
    else if( hasTZ == TZ_OFFSET ) {
      int absOffsetTZ = offsetTZ;
      if (offsetTZ < 0) {
        s.append("-");
        absOffsetTZ = -offsetTZ;
      }
      else
        s.append("+");
      s.append(new DecimalFormat("00").format(absOffsetTZ / 60));
      s.append(":");
      s.append(new DecimalFormat("00").format(absOffsetTZ % 60));
    }
    return s.toString();
  }

  public int length() {
    return toString().length();
  }

  public boolean booleanValue() {
    return true;
  }

  public boolean isEmpty() {
    return isempty;
  }

  public boolean isNull() {
    return isEmpty();
  }

  public int compareTo(Object obj) {
    return compareTo( (SchemaCalendarBase) obj);
  }

  public int compareTo(SchemaCalendarBase obj) {
    return (int)(getApproximatedTotal()-obj.getApproximatedTotal());
  }

  protected void parseDate(String newvalue) throws StringParseException {
  	if (newvalue.length() == 0 )
  		isempty = true;
    else if (newvalue.length() < 10)
      throw new StringParseException("date-part of string is too short", 0);
    else {
	    try {
	      int nStart = 0;
	      if( newvalue.substring(0,1).equals("-") )
	        nStart = 1;
	      year = Integer.parseInt(newvalue.substring(0, nStart+4));
	      if( !newvalue.substring(nStart+4, nStart+5).equals("-"))
	        throw new StringParseException("invalid date format", 2);
	      month = Integer.parseInt(newvalue.substring(nStart+5, nStart+7));
	      if( !newvalue.substring(nStart+7, nStart+8).equals("-"))
	        throw new StringParseException("invalid date format", 2);
	      day = Integer.parseInt(newvalue.substring(nStart+8, newvalue.length()));
	    }
	    catch (NumberFormatException e) {
	      throw new StringParseException("invalid date format", 2);
	    }
	    isempty = false;
	}
  }

  protected void parseTime(String newvalue) throws StringParseException {
    if (newvalue.length() < 8)
      throw new StringParseException("time-part of string is too short", 0);
    try {
      int nStart = 0;
      hour = Integer.parseInt(newvalue.substring(nStart, nStart+2));
      if( !newvalue.substring(nStart+2, nStart+3).equals(":"))
        throw new StringParseException("invalid date format", 2);
      minute = Integer.parseInt(newvalue.substring(nStart+3, nStart+5));
      if( !newvalue.substring(nStart+5, nStart+6).equals(":"))
        throw new StringParseException("invalid date format", 2);
      second = Integer.parseInt(newvalue.substring(nStart+6, nStart+8));
      int nTZStartPosition = nStart+8;
	  partsecond = 0;
      if (newvalue.length()>(nStart+8) ) {
        nStart = nTZStartPosition;
        int nEnd = newvalue.length();
        int nMSecEnd = newvalue.indexOf("Z", nStart);
        if( nMSecEnd > -1  &&  nMSecEnd < nEnd )
          nEnd = nMSecEnd;
        nMSecEnd = newvalue.indexOf("+", nStart);
        if( nMSecEnd > -1  &&  nMSecEnd < nEnd )
          nEnd = nMSecEnd;
        nMSecEnd = newvalue.indexOf("-", nStart);
        if( nMSecEnd > -1  &&  nMSecEnd < nEnd )
          nEnd = nMSecEnd;
        nTZStartPosition = nEnd;
        partsecond = Double.parseDouble( "0" + newvalue.substring(nStart, nEnd));
      }
      hasTZ = TZ_MISSING;
	  offsetTZ = 0;
      if (newvalue.length()>nTZStartPosition && newvalue.substring(nTZStartPosition, nTZStartPosition + 1).equals("Z"))
        hasTZ = TZ_UTC;
      else if (newvalue.length() == nTZStartPosition + 6) {
        hasTZ = TZ_OFFSET;
        offsetTZ = Integer.parseInt(newvalue.substring(nTZStartPosition+1, nTZStartPosition + 3)) * 60 +
            Integer.parseInt(newvalue.substring(nTZStartPosition+4, nTZStartPosition + 6));
        if( newvalue.substring(nTZStartPosition, nTZStartPosition+1).equals("-"))
          offsetTZ = -offsetTZ;
      }
    }
    catch (NumberFormatException e) {
      throw new StringParseException("invalid number format", 2);
    }
    isempty = false;
  }

  protected boolean parseDateTime(String s, int part)
  {
	  ParseContext context = new ParseContext(s);
	  
	  boolean bDatePart = ( part & DateTimePart_Date ) != 0;
      boolean bTimePart = ( part & DateTimePart_Time ) != 0;
	
	  RefInt year = new RefInt(0);
	  RefInt month = new RefInt(0);
	  RefInt day = new RefInt(0);
	  RefInt hour = new RefInt(0); 
	  RefInt minute = new RefInt(0);
	  double second = 0;
	
	  hasTZ = TZ_MISSING;
	  offsetTZ = 0;
	
	  if (bDatePart)
	  {
		// parse date
		boolean bNegative = context.checkAndAdvance('-');
		
		if ((part & DateTimePart_Year) != 0)
		{
			int digits = 0;
			RefInt temp = new RefInt(0);;
			while (context.readDigitAndAdvance(temp, 1, 9))
			{
				year.value = year.value * 10 + temp.value;
				digits += 1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -