All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.tidalwave.bluebill.taxonomy.mobile.impl.SimpleTaxon Maven / Gradle / Ivy

The newest version!
/***********************************************************************************************************************
 *
 * blueBill Mobile - Android - open source birding
 * Copyright (C) 2009-2011 by Tidalwave s.a.s. (http://www.tidalwave.it)
 *
 ***********************************************************************************************************************
 *
 * 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.
 *
 ***********************************************************************************************************************
 *
 * WWW: http://bluebill.tidalwave.it/mobile
 * SCM: https://java.net/hg/bluebill-mobile~android-src
 *
 **********************************************************************************************************************/
package it.tidalwave.bluebill.taxonomy.mobile.impl;

import java.util.Map;
import java.util.SortedSet;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import it.tidalwave.util.Id;
import it.tidalwave.util.NotFoundException;
import it.tidalwave.util.Finder;
import it.tidalwave.util.spi.SimpleFinderSupport;
import it.tidalwave.role.spi.DefaultIdentifiable;
import it.tidalwave.netbeans.util.AsLookupSupport;
import it.tidalwave.bluebill.taxonomy.mobile.Taxon;
import it.tidalwave.bluebill.taxonomy.mobile.Taxon.Rank;
import it.tidalwave.role.LocalizedDisplayable;
import lombok.Getter;
import org.openide.util.Exceptions;

/***********************************************************************************************************************
 *
 * @author  Fabrizio Giudici
 * @version $Id$
 *
 **********************************************************************************************************************/
@Immutable
public class SimpleTaxon extends AsLookupSupport implements Taxon
  {
    private static final long serialVersionUID = 5234367475785934L;

    private final SimpleTaxonomy taxonomy;

    @Nonnull
    private final Id id;
    
    @Getter @Nonnull
    private final String scientificName;

    @Getter @Nonnull
    private final Rank rank;

    @CheckForNull
    private final SimpleTaxon parent;

    protected final List children = new ArrayList();
    
    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    public SimpleTaxon (final @Nonnull SimpleTaxonomy taxonomy,
                        final @Nonnull Id id,
                        final @Nonnull String scientificName,
                        final @Nonnull Rank rank,
                        final @Nullable SimpleTaxon parent)
      {
        super(new Object[]{ new DefaultIdentifiable(id) }); 
//        super(new Object[]{ new DefaultIdentifiable(id), new LocalizedDisplayable() 
//          {
//            @Nonnull
//            public String getDisplayName() 
//              {
//                return getDisplayName(Locale.getDefault());
//              }
//
//            @Nonnull
//            public String getDisplayName (final @Nonnull Locale locale) 
//              {
//                try // FIXME: we rely on throwing NotFoundException for missing names; must change LocalizedDisplayable!
//                  {
//                    return taxonomy.getDisplayName(SimpleTaxon.this, locale);
//                  }
//                catch (NotFoundException e) 
//                  {
//                    throw new RuntimeException(e);
//                  }
//              }
//
//            @Nonnull
//            public Map getDisplayNames() 
//              {
//                throw new UnsupportedOperationException("Not supported yet.");
//              }
//
//            @Nonnull
//            public SortedSet getLocales() 
//              {
//                throw new UnsupportedOperationException("Not supported yet.");
//              }
//          } });
        
        this.taxonomy = taxonomy;
        this.id = id;
        this.scientificName = scientificName;
        this.rank = rank;
        this.parent = parent;
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @Nonnull
    public Id getId()
      {
        return id;
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @Nonnull
    public String getDisplayName (final @Nonnull Locale locale)
      throws NotFoundException
      {
        return taxonomy.getDisplayName(this, locale);
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @Nonnull
    public Taxon getParent()
      throws NotFoundException
      {
        return NotFoundException.throwWhenNull(parent, "No parent for %s", this);
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @Nonnull
    public Finder findSubTaxa()
      {
        return new SimpleFinderSupport() 
          {
            @Override @Nonnull
            protected List computeResults() 
              {
                return Collections.unmodifiableList(children);
              }
          };
      }
    
    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @Override @Nonnull
    public String toString()
      {
        return String.format("Taxon[%s]", scientificName);
      }

    public Id getScientificNameId() 
      {
        throw new UnsupportedOperationException("Not supported yet.");
      }

    public String getSpecificEpithet() 
      {
        throw new UnsupportedOperationException("Not supported yet.");
      }

    public Taxon getAnonymousSynonym() throws NotFoundException 
      {
        throw new NotFoundException();
      }

    public Object getSynonyms() 
      {
        throw new UnsupportedOperationException("Not supported yet.");
      }
  }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy