SchemaSet and inherited classes

Source: Internet
Author: User

Public class schemaset
{
// @ Field
Private object elementdata [];
Private int elementcount;
Private int capacityincrement;

Public cerrors merrors; // error message

// @ Constructor
Public schemaset (INT initialcapacity, int capacityincrement)
{
If (initialcapacity <0)
{
// @ Handle errors
Cerror terror = new cerror ();
Terror. modulename = "schemaset ";
Terror. functionname = "schemaset ";
Terror. errormessage = "illegal capacity:" + initialcapacity;
This. merrors. addoneerror (terror );
}
This. elementData = new Object [initialCapacity];
This. capacityIncrement = capacityIncrement;
This. elementCount = 0;

MErrors = new CErrors ();
}

Public SchemaSet (int initialCapacity)
{
This (initialCapacity, 0 );
}

Public SchemaSet ()
{
This (10 );
}

// @ Method
Public boolean add (Schema aSchema)
{
If (aSchema = null) return false;
EnsureCapacityHelper (elementCount + 1 );
ElementData [elementCount] = aSchema;
ElementCount ++;
Return true;
}

Public boolean add (SchemaSet aSet)
{
If (aSet = null) return false;
Int n = aSet. size ();
EnsureCapacityHelper (elementCount + n );
For (int I = 0; I <n; I ++)
{
ElementData [elementCount + I] = aSet. getObj (I + 1 );
}
ElementCount + = n;
Return true;
}

Public boolean remove (Schema aSchema)
{
If (aSchema = null) return false;
For (int I = 0; I <elementCount; I ++)
{
If (aSchema. equals (elementData [I])
{
Int j = elementCount-I-1;
If (j> 0)
{
System. arraycopy (elementdata, I + 1, elementdata, I, j );
}
Elementcount --;
Elementdata [elementcount] = NULL;
Return true;
} // End of if
} // End of
Return false;
}

Public Boolean removerange (INT begin, int end)
{
If (begin <= 0 | End> elementcount | begin> end)
{
Return false;
}
Int n = elementcount-end;
If (n> 0)
{
System. arraycopy (elementdata, end, elementdata, begin-1, elementcount-end );
}
Int M = end-begin + 1;
For (INT I = 1; I <= m; I ++)
{
Int J = elementcount-I;
Elementdata [J] = NULL;
}
Elementcount-= m;
Return true;
}

Public void clear ()
{
For (INT I = 0; I <elementcount; I ++)
{
Elementdata [I] = NULL;
}
Elementcount = 0;
}

Public object getobj (INT index)
{
If (index> elementCount)
{
// @ Handle errors
CError tError = new CError ();
TError. moduleName = "SchemaSet ";
TError. functionName = "get ";
TError. errorMessage = "Index out of bounds! ";
This. mErrors. addOneError (tError );
}
Return elementData [index-1];
}

Public boolean set (int index, Schema aSchema)
{
If (index> elementCount)
{
// @ Handle errors
CError tError = new CError ();
TError. moduleName = "SchemaSet ";
TError. functionName = "set ";
TError. errorMessage = "Index out of bounds! ";
This. mErrors. addOneError (tError );

Return false;
}
ElementData [index-1] = aSchema;
Return true;
}

Public boolean set (SchemaSet aSet)
{
This. clear ();
Return this. add (aSet );
}

Public int size ()
{
Return elementCount;
}

Private void ensureCapacityHelper (int minCapacity)
{
Int oldCapacity = elementData. length;
If (mincapacity> oldcapacity)
{
Object olddata [] = elementdata;
Int newcapacity = (capacityincrement> 0 )? (Oldcapacity + capacityincrement): (oldcapacity * 2 );
If (newcapacity <mincapacity)
{
Newcapacity = mincapacity;
}
Elementdata = new object [newcapacity];
System. arraycopy (olddata, 0, elementdata, 0, elementcount );
}
}
}

/*
*
*/
Package com. vschema;

Import com. schema. laascriptionschema;
Import com. Utility. schemaset;
Import com. utility. SysConst;

Public class LAAscriptionSet extends SchemaSet
{
// @ Method
Public boolean add (LAAscriptionSchema aSchema)
{
Return super. add (aSchema );
}

Public boolean add (LAAscriptionSet aSet)
{
Return super. add (aSet );
}

Public boolean remove (LAAscriptionSchema aSchema)
{
Return super. remove (aSchema );
}

Public LAAscriptionSchema get (int index)
{
LAAscriptionSchema tSchema = (LAAscriptionSchema) super. getObj (index );
Return tSchema;
}

Public boolean set (int index, LAAscriptionSchema aSchema)
{
Return super. set (index, aSchema );
}

Public boolean set (LAAscriptionSet aSet)
{
Return super. set (aSet );
}

/**
* Data packaging: The data is packaged in XML format. For the sequence, see <A href = {@ docRoot}/dataStructure/tb.html # PrpLAAscription description/A> table fields.
* @ Param: None
* @ Return: returns the packaged string.
**/
Public String encode ()
{
String strreturn = "";
Int n = This. Size ();
For (INT I = 1; I <= N; I ++)
{
Laascriptionschema aschema = (laascriptionschema) this. Get (I );
Strreturn + = aschema. encode ();
If (I! = N)
{
StrReturn + = SysConst. RECORDSPLITER;
}
}

Return strReturn;
}

/**
* Data unpacking
* @ Param: string after Packaging
* @ Return: boolean
**/
Public boolean decode (String str)
{
Int nBeginPos = 0;
Int nEndPos = str. indexOf ('^ ');
This. clear ();

While (nEndPos! =-1)
{
LAAscriptionSchema aSchema = new LAAscriptionSchema ();
If (aSchema. decode (str. substring (nBeginPos, nEndPos) = false)
{
// @ Handle errors
This. mErrors. copyAllErrors (aSchema. mErrors );
Return false;
}
This. Add (aschema );
Nbeginpos = nendpos + 1;
Nendpos = Str. indexof ('^', nendpos + 1 );
}
Laascriptionschema tschema = new laascriptionschema ();
If (tschema. Decode (Str. substring (nbeginpos) = false)
{
// @ Handle errors
This. merrors. copyallerrors (tschema. merrors );
Return false;
}
This. Add (tschema );

Return true;
}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.