2 * ========================LICENSE_START=================================
5 * Copyright (C) 2024: OpenInfra Foundation Europe
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ========================LICENSE_END===================================
21 package com.demo.consumer.repository;
23 import java.util.Collection;
24 import java.util.HashMap;
26 import java.util.Vector;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30 import org.springframework.http.HttpStatus;
31 import org.springframework.stereotype.Component;
34 public class InfoTypes {
35 private static final Logger logger = LoggerFactory.getLogger(InfoTypes.class);
37 private Map<String, InfoType> allTypes = new HashMap<>();
39 public InfoTypes(Collection<InfoType> types) {
40 for (InfoType type : types) {
45 public synchronized InfoType get(String id) {
46 return allTypes.get(id);
49 public synchronized InfoType getType(String id) throws Exception {
50 InfoType type = allTypes.get(id);
52 throw new Exception("Could not find type: " + id + HttpStatus.NOT_FOUND.toString());
57 public static class ConfigFile {
58 Collection<InfoType> types;
61 public synchronized void put(InfoType type) {
62 logger.debug("Put type: {}", type.getId());
63 allTypes.put(type.getId(), type);
66 public synchronized Iterable<InfoType> getAll() {
67 return new Vector<>(allTypes.values());
70 public synchronized Collection<String> typeIds() {
71 return allTypes.keySet();
74 public synchronized int size() {
75 return allTypes.size();
78 public synchronized void clear() {