KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > geinuke > block > BlockContainer


1
2  /*
3  -- GeiNuke --
4 Copyright (c) 2005 by Roberto Sidoti [geinuke@users.sourceforge.net]
5  http://www.hostingjava.it/-geinuke/
6
7 This file is part of GeiNuke.
8
9     GeiNuke is free software; you can redistribute it and/or modify
10     it under the terms of the GNU General Public License as published by
11     the Free Software Foundation; either version 2 of the License, or
12     (at your option) any later version.
13
14     GeiNuke is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17     GNU General Public License for more details.
18
19     You should have received a copy of the GNU General Public License
20     along with GeiNuke; if not, write to the Free Software
21     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */

23 package com.geinuke.block;
24
25 import java.util.ArrayList JavaDoc;
26 import java.util.HashMap JavaDoc;
27
28 import com.geinuke.common.NukeBlockI;
29
30
31 public class BlockContainer {
32     
33     protected HashMap JavaDoc map=null;
34     public BlockContainer(){
35         map=new HashMap JavaDoc();
36     }
37     protected void insertOrd(ArrayList JavaDoc list,NukeBlockI bl){
38         
39         NukeBlockI cb=null;
40         int cur=0;
41         boolean found=false;
42         //GeiServlet.intLog("BlockContainer.insertOrd(...), bl="+bl);
43
for(int i=0;i<list.size() && !found;i++){
44             cb=(NukeBlockI)list.get(i);
45             if(bl.getWeight()<cb.getWeight()){
46                 cur=i;
47                 found=true;
48             }
49         }
50         if(!found){
51             list.add(bl);
52         }else{
53             list.add(cur,bl);
54         }
55     }
56     public void addBlockInPosition(NukeBlockI block){
57         int pos=block.getPos();
58         //GeiServlet.intLog("BlockContainer.addBlockInPosition(...), pos="+pos);
59
ArrayList JavaDoc blocks=null;
60         blocks=(ArrayList JavaDoc)map.get(pos+"");
61         //GeiServlet.intLog("BlockContainer.addBlockInPosition(...), map="+map);
62
//GeiServlet.intLog("BlockContainer.addBlockInPosition(...), blocks="+blocks);
63
if(blocks!=null){
64             //GeiServlet.intLog("BlockContainer.addBlockInPosition(...), calling insertOrd");
65
this.insertOrd(blocks,block);
66         }else{
67             
68             blocks=new ArrayList JavaDoc();
69             blocks.add(block);
70             map.put(pos+"",blocks);
71         }
72     }
73     
74     public void addBlocks(ArrayList JavaDoc blocks){
75         NukeBlockI block=null;
76         //GeiServlet.intLog("BlockContainer.addBlocks(...), blocks="+blocks);
77
for(int i=0;i<blocks.size();i++){
78             block=(NukeBlockI)blocks.get(i);
79             this.addBlockInPosition(block);
80         }
81     }
82     
83     public ArrayList JavaDoc getBlocksAt(String JavaDoc pos){
84         return (ArrayList JavaDoc)map.get(pos);
85     }
86     
87     public void setBlocksAt(String JavaDoc pos,ArrayList JavaDoc blocks){
88         map.put(pos,blocks);
89     }
90     
91     public String JavaDoc STRING(){
92             return map.toString();
93     }
94     
95 }
96
Popular Tags