From 52c9fc85efdd237b954a1497ead58358c02f5dc2 Mon Sep 17 00:00:00 2001 From: ChenX Date: Mon, 18 Dec 2017 09:14:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9ObjectId=E6=8F=90=E4=BE=9B=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E6=9E=84=E5=BB=BA=E6=96=B9=E6=B3=95=20=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=E5=87=BA=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __test__/FileSystem/FileSystem.test.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/__test__/FileSystem/FileSystem.test.ts b/__test__/FileSystem/FileSystem.test.ts index cb8a1d2f1..8f083e5c7 100644 --- a/__test__/FileSystem/FileSystem.test.ts +++ b/__test__/FileSystem/FileSystem.test.ts @@ -237,12 +237,15 @@ class ObjectId { this.id = -1; } + + //创建一个id, 如果db中已经存在id,那么自动获得该id,如果不存在,new一个新的id,并且加入到db中 static Create(db: Database, index: number): ObjectId { let id = db.GetObjectId(index); if (!id) { id = new ObjectId(); + db.SetObjectId(index, id); id.id = index; } return id; @@ -599,26 +602,35 @@ class Database } } - //在对象池中创建id. + //创建一个id,自动递增它的索引号,并且会自动加入到db的id列表中. AllocateId(obj: CADObject): ObjectId { if (obj.Db === this) { this.idCout++; let id = ObjectId.Create(this, this.idCout); - this.idMap.set(this.idCout, id); return id; } else { - console.warn("对象不属于该数据库!"); + console.warn("警告:对象不属于该数据库!"); } } - //获得指定索引的id + //获得指定索引的id,注意该id可能为空,如果需要创建,请使用 ObjectId.Create 如果需要自动分配 请使用 AllocateId GetObjectId(index: number): ObjectId { return this.idMap.get(index); } + + //在id池中加入新建的id. 该方法暴露给 Objectid.Cretes使用. + SetObjectId(index: number, id: ObjectId) + { + if (this.idMap.has(index)) + { + console.warn("警告:尝试加入已经存在的id!"); + } + this.idMap.set(index, id); + } } class BlockTableRecord extends ObjectCollection