
it.tidalwave.bluebill.factsheet.FactSheet Maven / Gradle / Ivy
/***********************************************************************************************************************
*
* blueBill Mobile - open source birdwatching
* ==========================================
*
* Copyright (C) 2009, 2010 by Tidalwave s.a.s. (http://www.tidalwave.it)
* http://bluebill.tidalwave.it/mobile/
*
***********************************************************************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
***********************************************************************************************************************
*
* $Id: FactSheet.java,v 22778a721655 2010/06/22 00:06:09 fabrizio $
*
**********************************************************************************************************************/
package it.tidalwave.bluebill.factsheet;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import it.tidalwave.util.Id;
import it.tidalwave.util.Key;
import it.tidalwave.util.TypeSafeMultiMap;
import it.tidalwave.util.TypeSafeHashMultiMap;
import it.tidalwave.mobile.media.Media;
import it.tidalwave.util.As;
/***********************************************************************************************************************
*
* @author Fabrizio Giudici
* @version $Id: $
*
**********************************************************************************************************************/
@Immutable
public class FactSheet implements As, TypeSafeMultiMap
{
public static final Key SOUNDS = new Key("urn:blueBill-mobile:sound");
private final TypeSafeMultiMap map;
@Nonnull
private final Id id;
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
public FactSheet (final @Nonnull Id id)
{
this(id, Collections., Collection extends Object>>emptyMap());
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
private FactSheet (final @Nonnull Id id, final @Nonnull Map, Collection extends Object>> map)
{
this.id = id;
this.map = new TypeSafeHashMultiMap(map);
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Nonnull
public Id getId()
{
return id;
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Nonnull
public Collection get (final @Nonnull Key key)
{
return map.get(key);
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
public boolean containsKey (final @Nonnull Key> item)
{
return map.containsKey(item);
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Nonnull
public Set> getKeys()
{
return map.getKeys();
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Nonnegative
public int getSize()
{
return map.getSize();
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Nonnull
public Iterator> iterator()
{
return map.iterator();
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Nonnull
public FactSheet with (final @Nonnull Key key, final @Nonnull T value)
{
return with(key, Collections.singletonList(value));
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Nonnull
public FactSheet with (final @Nonnull Key key, final @Nonnull Collection values)
{
final Map, Collection extends Object>> asMap = map.asMap();
Collection list = (Collection)asMap.get(key);
list = (list == null) ? new ArrayList() : new ArrayList(list);
list.addAll(values);
asMap.put(key, list);
return new FactSheet(id, asMap);
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Nonnull
public Map, Collection extends Object>> asMap()
{
throw new UnsupportedOperationException("Not supported yet.");
}
public T as(Class type)
{
throw new UnsupportedOperationException("Not supported yet.");
}
public T as(Class type, NotFoundBehaviour nfb)
{
throw new UnsupportedOperationException("Not supported yet.");
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy