Project

General

Profile

Download (3.43 KB) Statistics
| Branch: | Revision:

library / src / main / java / org / distorted / library / DistortedGridFactory.java @ 62f7a90a

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.library;
21

    
22
import java.util.HashMap;
23
/**
24
 * HashMap of all DistortedObjectGrids ever created. The point: we can share the Grids among
25
 * DistortedObjects that are of the same shape.
26
 */
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28

    
29
final class DistortedGridFactory
30
  {
31
  private static HashMap<String,DistortedObjectGrid> mGrids = new HashMap<>();
32

    
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34
// DistortedCubesGrid
35

    
36
  static synchronized DistortedObjectGrid getGrid(int cols, String desc, boolean frontOnly)
37
    {
38
    String d = desc+("_"+cols+"_"+(frontOnly?"1":"0"));
39
    Object o = mGrids.get(d);
40

    
41
    if( o!=null )
42
      {
43
      return (DistortedObjectGrid)o;
44
      }
45
    else
46
      {
47
      DistortedObjectGrid grid = new DistortedCubesGrid(cols,desc,frontOnly);
48
      mGrids.put(d,grid);
49
      return grid;
50
      }
51
    }
52

    
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54
// DistortedBitmapGrid
55

    
56
  static synchronized DistortedObjectGrid getGrid(int cols, int rows)
57
    {
58
    String d = cols+"+"+rows;
59
    Object o = mGrids.get(d);
60

    
61
    if( o!=null )
62
      {
63
      return (DistortedObjectGrid)o;
64
      }
65
    else
66
      {
67
      DistortedObjectGrid grid = new DistortedBitmapGrid(cols,rows);
68
      mGrids.put(d,grid);
69
      return grid;
70
      }
71
    }
72

    
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74

    
75
  static synchronized void release()
76
    {
77
    mGrids.clear();
78
    }
79

    
80
///////////////////////////////////////////////////////////////////////////////////////////////////
81
  }
(6-6/18)