001/* Copyright (C) 2013 TU Dortmund 002 * This file is part of AutomataLib, http://www.automatalib.net/. 003 * 004 * AutomataLib is free software; you can redistribute it and/or 005 * modify it under the terms of the GNU Lesser General Public 006 * License version 3.0 as published by the Free Software Foundation. 007 * 008 * AutomataLib is distributed in the hope that it will be useful, 009 * but WITHOUT ANY WARRANTY; without even the implied warranty of 010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 011 * Lesser General Public License for more details. 012 * 013 * You should have received a copy of the GNU Lesser General Public 014 * License along with AutomataLib; if not, see 015 * http://www.gnu.de/documents/lgpl.en.html. 016 */ 017package net.automatalib.automata.base; 018 019import net.automatalib.automata.concepts.StateIDs; 020import net.automatalib.commons.util.mappings.MutableMapping; 021 022public class StateIDStaticMapping<S, V> implements MutableMapping<S, V> { 023 024 private final StateIDs<S> stateIds; 025 private final Object[] storage; 026 027 public StateIDStaticMapping(StateIDs<S> stateIds, int size) { 028 this.stateIds = stateIds; 029 this.storage = new Object[size]; 030 } 031 032 @Override 033 @SuppressWarnings("unchecked") 034 public V get(S elem) { 035 return (V)storage[stateIds.getStateId(elem)]; 036 } 037 038 @Override 039 @SuppressWarnings("unchecked") 040 public V put(S key, V value) { 041 V old = (V)storage[stateIds.getStateId(key)]; 042 storage[stateIds.getStateId(key)] = value; 043 return old; 044 } 045 046}