package org.wahlzeit.model;
/*
 * Copyright (c) 2006-2009 by Dirk Riehle, http://dirkriehle.com
 *
 * This file is part of the Wahlzeit photo rating application.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this program. If not, see
 * <http://www.gnu.org/licenses/>.
 */

import java.util.HashMap;
import java.util.Map;

public class MotorcycleManager {

    private static final MotorcycleManager instance = new MotorcycleManager();

    private Map<String, Motorcycle> motorcycles = new HashMap<>();
    private Map<MotorcycleType.Type, MotorcycleType> motorcycleTypes = new HashMap<>();


    public static MotorcycleManager getInstance() {
        return instance;
    }

    public Motorcycle createMotorcycle(MotorcycleType.Type typeName, String brand, String model, int buildYear) {
        MotorcycleType ft = getMotorcycleType(typeName);
        Motorcycle result = ft.createInstance( brand, model, buildYear);
        motorcycles.put(result.getName(), result);
        return result;
    }


    private MotorcycleType getMotorcycleType(MotorcycleType.Type typeName) {
        if(!motorcycleTypes.containsKey(typeName)) {
            MotorcycleType tmp = new MotorcycleType(typeName);
            motorcycleTypes.put(typeName, tmp);
        }

        return motorcycleTypes.get(typeName);
    }

    private Motorcycle getMotorcycle(String name){
        if(motorcycles.containsKey(name)) {
            return motorcycles.get(name);
        }

        return null;
    }


}

@@ -1350,32 +1350,35 @@
 Year) %7B%0A        
+add
 MotorcycleType f
@@ -1375,18 +1375,53 @@
 ycleType
- f
+(typeName);%0A%0A        MotorcycleType m
 t = getM
@@ -1473,17 +1473,17 @@
 esult = 
-f
+m
 t.create
@@ -1603,39 +1603,27 @@
  %7D%0A%0A
-%0A
     p
-rivate MotorcycleType get
+ublic void add
 Moto
@@ -1661,24 +1661,62 @@
 type
-Name) %7B%0A
+)%7B%0A        synchronized (motorcycleTypes)%7B%0A   
         
 if(!
@@ -1711,16 +1711,17 @@
         
+ 
 if(!moto
@@ -1752,17 +1752,17 @@
 type
-Name
 )) %7B%0A
+    
     
@@ -1805,36 +1805,32 @@
 orcycleType(type
-Name
 );%0A            m
@@ -1820,32 +1820,36 @@
 e);%0A            
+  
+  
 motorcycleTypes.
@@ -1856,20 +1856,16 @@
 put(type
-Name
 , tmp);%0A
@@ -1864,34 +1864,130 @@
 , tmp);%0A        
+  
-%7D%0A
+  %7D%0A        %7D%0A    %7D%0A%0A    public MotorcycleType getMotorcycleType(MotorcycleType.Type typeName) %7B
 %0A        return 
@@ -2029,22 +2029,21 @@
 %7D%0A%0A    p
-rivate
+ublic
  Motorcy

split getMotorcycleType in addMotorcycleType and getMotocycleType