Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedGridFactory.java @ 0729bc41

1 0729bc41 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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
40
    Object o = mGrids.get(d);
41
42
    if( o!=null ) return (DistortedObjectGrid)o;
43
44
    DistortedCubesGrid grid = new DistortedCubesGrid(cols,desc,frontOnly);
45
46
    mGrids.put(d,grid);
47
48
    return grid;
49
    }
50
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52
// DistortedBitmapGrid
53
54
  static synchronized DistortedObjectGrid getGrid(int cols, int rows)
55
    {
56
    String d = cols+"+"+rows;
57
58
    Object o = mGrids.get(d);
59
60
    if( o!=null ) return (DistortedObjectGrid)o;
61
62
    DistortedBitmapGrid grid = new DistortedBitmapGrid(cols,rows);
63
64
    mGrids.put(d,grid);
65
66
    return grid;
67
    }
68
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70
71
  static synchronized void release()
72
    {
73
    mGrids.clear();
74
    }
75
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77
  }