001/* 002 * Trident - A Multithreaded Server Alternative 003 * Copyright 2014 The TridentSDK Team 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package net.tridentsdk.server.inventory; 019 020import com.google.common.collect.ForwardingCollection; 021import com.google.common.collect.ImmutableList; 022import net.tridentsdk.inventory.Inventories; 023import net.tridentsdk.inventory.Inventory; 024 025import javax.annotation.concurrent.ThreadSafe; 026import java.util.Collection; 027import java.util.Map; 028import java.util.concurrent.ConcurrentHashMap; 029 030/** 031 * Manages the inventory windows on the server, whether being viewed or not 032 * 033 * @author The TridentSDK Team 034 */ 035@ThreadSafe 036public class TridentInventories extends ForwardingCollection<Inventory> implements Inventories { 037 private static final Map<Integer, TridentInventory> windows = new ConcurrentHashMap<>(); 038 039 @Override 040 public Inventory fromId(int id) { 041 return windows.get(id); 042 } 043 044 @Override 045 public void register(Inventory window) { 046 windows.put(window.id(), (TridentInventory) window); 047 } 048 049 @Override 050 protected Collection<Inventory> delegate() { 051 return ImmutableList.copyOf(windows.values()); 052 } 053}