H-DTO mode (2)

xiaoxiao2021-03-06  103

1. Overview The foregoing instructions have some basic concepts and design ideas. From the UML diagram, there can be a lot of content, such as class relationships, component relationships, which will be implemented using Java implementation.

2, realize TransformData

/ *

* Created on 2004-7-21 by jem.lee

*

* TransformData is a part of cn.bs.common.transdata

* All Rights Reserved.

* CopyRight (C) 2004. Jem.lee

* /

/ * Package path cn.bs.common.transdata * /

Package cn.bs.common.transdata;

/ * Import package content * /

Import java.util.hashmap;

Import java.util.iterator;

/ **

*

* History

* 2004-7-21

21:02:57

Created by Jem.lee

*

* Purpose

* The main object of data transfer is performed as a view and controller,

* It contains general elements objects and table objects

*

* /

Public Class TransformData IMPLEments Cloneable {

/ *

* Hash table stores a single element

* /

PRIVATE HASHMAP TRSELEMENTS = new hashmap ();

/ *

* Hash table stores the Table element

* /

Private hashmap trutables = new hashmap ();

/ **

*

* Get the value of the specified element name from Formdata

* @Param Name element name

* @Return element corresponding to the value

* @Throws Exception

*

* /

Public String getfieldValue (String name) throws exception {

Return (this.GetfieldFromName (Name) .GetValue ());

}

/ **

*

* Get the specified element domain name from FormData

* @Param Name element name

* @Return Element Corresponding domain

* @Throws Exception

*

* /

Public Transformfield getfieldfromname (String name) throws exception {

IF (name == null) {

Throw (New NullPointersRexception ("Then the Name Name is empty or null")));

}

TRANSFORMFIELD RET = (Transformfield) TRSELEments.GET (NAME);

IF (RET == NULL) {

Throw (New Exception ")))));" Domain "));

}

Return (RET);

}

/ **

*

* Specify an element to Formdata and set it, if the element is found, the element is overwritten.

* @Param Name element name

* @Param Value elements value

*

* /

Public void PutfieldValueo (String Name, String Value) {

TRANSFORMFIELD NEWELEMENT = New Transformfield (Name, Value); NewElement.SetParent (this);

THIS.PUTELEMENTSO (NEWELEMENT);

}

/ **

*

* Set the Elevent Domain of FormData.

* @Param newElement designated new domain

*

* /

Public void Putelementso (Transformfield NewElement) {

NEWELEMENT.SETPARENT (THIS);

This.Trselements.put (newElement.getname (), newElement;

}

/ * ------------------------------------------------------------------------------------------- - * /

/ **

*

* Increase Table to Formdata and return to the table, if the specified table already exists,

* Throws Exception exceptions

* @Param Name Table name

* @Return FormTable returned Table type

* @Throws Exception

*

* /

Public TransformTable AddTable (String Name) Throws Exception {

IF (TRSTables.Get (Name)! = null) {

Throw (New Exception ());

}

Return (AddTableo (Name);

}

/ **

*

* Increase Table to FormData and return to this table, if the specified table already exists,

* The new table is forcibly overwritten.

* @Param Name Table name

* @Return FormTable returned Table type

*

* /

Public TransformTable AddTableo (String TableName) {

TransformTable NewTable = New TransformTable (TABLENAME);

NEWTABLE.SETPARENT (THIS);

Trstables.put (TableName, NewTable);

Return (NewTable);

}

/ **

*

* Sort Table content

*

* /

Void SortTable () {

Iterator itables = this.trstables.keyset (). Iterator ();

While (itables.hasnext ()) {

TransformTable TBL = (TransformTable) this.trstables.get (itables.next ());

Tbl.sort ();

}

}

/ **

*

* Get instances of the specified table name

* @Param Name Table Name

* @Return Specify an instance of the table name

* @Throws BScomponEntexception, NullPointerexception, IllegaArgumentException

*

* /

Public TransformTable GetTable (String Name) throws Exception {

IF (name == null) {

Throw (New NullPointersRexception "));}

IF (Name.Equals (")) {

Throw (New ILLEGALARGUMENTEXCEPTION ("Enter the domain name is empty"))))))

}

TRANSFORMTABLE RET = (TransformTable) TRSTABLES.GET (NAME);

IF (RET == NULL) {

Throw (New Exception ());

}

Return (RET);

}

}

3, realize TRANSFORMFIELD

/ *

* Created on 2004-7-21 by jem.lee

*

* Transformfield is a part of cn.bs.common.transdata

* All Rights Reserved.

* CopyRight (C) 2004. Jem.lee

* /

/ * Package path cn.bs.common.transdata * /

Package cn.bs.common.transdata;

/ **

*

* History

* 2004-7-21

21:03:26

Created by Jem.lee

*

* Purpose

* The main object of data transfer is performed as a view and controller,

* It as a general element object

*

* /

Public class transformfield {

/ *

* Element name

* /

PRIVATE STRING NAME;

/ *

* Element value

* /

PRIVATE STRING VALUE;

/ *

* Store this element of the parent directory

* /

PRIVATE TRANSFORMDATA PARENT;

/ **

* Constructor

* @Param Initname element name

* @Param initValue element value

* /

Public Transformfield (String Initname, String Initvalue) {

/ * If the name of the element is supplied, the NullPointerexception exception is thrown. * /

IF (InitName == Null)

Throw ("" "" "" Initialization Formfield is initialized, for example, initname is null "));

/ * If the name of the element provided is empty, IllegaLaRGumentException exceptions * /

IF (InitName.equals ("))

Throw (New IllegaLargumentException ("The parameter error provided when Formfield is initialized, the initname is empty))));

/ * If the value provided is NULL, it throws the NullPointerexception exception * /

IF (initValue == null)

Throw (New NullpointerException ("Initializing the parameter error provided by Formfield, INITVALUE is null"));

THIS.NAME = INITNAME;

THIS.VALUE = INITVALUE;

}

/ **

*

* Get element name

* @Return element name

*

* /

Public string getname () {

Return (this.name);

}

/ **

*

* Value of the element

* @return elements value

*

* /

Public String getValue () {

Return (this.Value);

}

/ **

*

* Set the parent directory of the element

* @Param newParent parent directory

*

* /

Public void setparent (TransformData newParent) {

/ * If the parent directory is NULL, throw the NullPointerexception exception * /

IF (newParent == null)

Throw (New NullpointerException ("Setting the Formfield's Packer FormData Error, such as null");

THIS.PARENT = NewParent;

}

}

4, realize TransformRecord

/ *

* Created on 2004-7-21 by jem.lee

*

* TransformRecord is a part of cn.bs.common.transdata

* All Rights Reserved.

* CopyRight (C) 2004. Jem.lee

* /

/ * Package path cn.bs.common.transdata * /

Package cn.bs.common.transdata;

/ **

*

* History

* 2004-7-21

21:03:44

Created by Jem.lee

*

* Purpose

* The main object of data transfer is performed as a view and controller,

* It as an element object for Table objects

*

* /

Public Class TransformRecord Extends TransformData Implements Comprarable {

/ *

* Record ID

* /

PRIVATE INT REC_ID;

/ *

* Store this element of the parent directory

* /

Private TransformTable Parent;

Public int compareto (Object Target) {

Target InstanceOf TransformRecord

RETURN (REC_ID - ((TransformRecord) Target .getRecid ());

Return (0);

}

/ **

*

* Set the parent directory of the element

* @Param newParent parent directory

*

* /

Void setParent (TransformTable newParent) {

Parent = newparent;

}

/ **

*

* Get the parent directory of the element

* @Return FormTable Parent Directory

*

* /

TransformTable getParent () {

Return (PARENT);

}

/ **

*

*

* Set new record ID

* @Param NewID record ID

*

* /

Void setRecid (int new_id) {

REC_ID = New_ID;

}

/ **

*

*

* Obtained record ID

* @Return record ID

*

* /

Int getRecid () {

Return (REC_ID);

}

}

5. Implement TransformTable

/ *

* Created on 2004-7-21 by jem.lee

*

* Formtable.java is a part of cn.bs.common.transdata

* All Rights Reserved.

* Copyright (c) 2004. Jem.lee * // * Package path cn.bs.common.transdata * /

Package cn.bs.common.transdata;

/ * Import package content * /

Import java.util.arraylist;

Import java.util.collections;

Import java.util.iterator;

/ **

*

* History

* 2004-7-21

21:04:00

Created by Jem.lee

*

* Purpose

* The main object of data transfer is performed as a view and controller,

* It as an element object as a Formdata object

*

* /

Public class transformtable {

/ *

* TABLE Name

* /

PRIVATE STRING NAME;

/ *

* Record array

* /

Private arraylist records = new arraylist ();

/ *

* Store this element of the parent directory

* /

PRIVATE TRANSFORMDATA PARENT;

/ **

*

* Constructor Provides a table name

* @Param Initname Table Name

*

* /

Public TransformTable (String InitName) {

/ * If the name of the name is NULL, throw the NullPointerexception exception * /

IF (InitName == Null)

Throw (New NullPointerException ("Constructs the formTable error, such as N-Null"));

/ * If the design provided is empty, throw a NullPointeredException exception * /

IF (InitName.equals ("))

Throw (New IllegalargumentException ")))));

THIS.NAME = INITNAME;

}

/ **

*

* Set the parent directory of the element

* @Param newParent parent directory

*

* /

Void setParent (TransformData newParent) throws nullpointersReption {

/ * If the parent directory provided is NULL, throw the NullPointerexception exception * /

IF (newParent == null)

Throw ("Setting ForformTableMfield's Inclusive Formdata Error, such as null"));

THIS.PARENT = NewParent;

}

/ **

*

*

* Add a record to TABLE

* @return Returns the instance of the record to make assignment operations

*

* /

Public TransformData Add () {

TRANSFORMRECORD NewRec = New TransformRecord ();

Newrec.SetParent (this);

Records.add (newREC);

Reindex ();

sort ();

Return (newREC);

}

/ **

*

*

* Sort function, sort the record of the table

*

* /

Void sort () {

Collectes.Sort (Records); item IRECs = Records.Itemrator ();

While (IRECs.hasnext ()) {

TRANSFORMDATA REC = (TransformData) IRECS.NEXT ();

Rec.SortTable ();

}

}

/ **

*

*

* Record index

*

* /

Void reindex () {

INT INDEX = 0;

//Collections.sort (RECS);

Iterator i = Records.Itemrator ();

While (I.hasNext ()) {

TransformRecord REC = (TransformRecord) i.next ();

Rec.SetRecid (INDEX);

INDEX ;

}

}

/ **

*

*

* Get a record through the record number

* @Param Recno record number

* @Return a record

*

* /

Public TransformData Get (int reccno) {

RETURN (TransformData) Records.get (Recno));

}

/ **

*

*

* Get the length of the table

* @ReturN table length

*

* /

Public int size () {

Return (Records.Size ());

}

}

6, summarize here, I made a brief introduction to the H-DTO mode, I hope some help to your design. If you find the wrong, please criticize correctly, if you have any questions or unknown, welcome to discuss.

转载请注明原文地址:https://www.9cbs.com/read-103759.html

New Post(0)