//# 0 errors, 124 messages
//#
/*
    //#indexedtag.java:1:1: class: net.sourceforge.pebble.index.IndexedTag
    //#indexedtag.java:1:1: method: net.sourceforge.pebble.index.IndexedTag.net.sourceforge.pebble.index.IndexedTag__static_init
 * Copyright (c) 2003-2006, Simon Brown
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *   - Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *
 *   - Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in
 *     the documentation and/or other materials provided with the
 *     distribution.
 *
 *   - Neither the name of Pebble nor the names of its contributors may
 *     be used to endorse or promote products derived from this software
 *     without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
package net.sourceforge.pebble.index;

import net.sourceforge.pebble.domain.Blog;
import net.sourceforge.pebble.domain.Tag;
import net.sourceforge.pebble.comparator.ReverseBlogEntryIdComparator;

import java.util.ArrayList;
import java.util.List;
import java.util.Collections;

/**
 * Represents a tag.
 *
 * @author    Simon Brown
 */
public class IndexedTag extends Tag {

  /** the blog entries associated with this tag */
  private List<String> blogEntries = new ArrayList<String>();

  /**
   * Creates a new tag with the specified properties.
   *
   * @param name    the name
   * @param blog    a Blog instance
   */
  public IndexedTag(String name, Blog blog) {
    super(name, blog);
    //#indexedtag.java:59: method: void net.sourceforge.pebble.index.IndexedTag.net.sourceforge.pebble.index.IndexedTag(String, Blog)
    //#indexedtag.java:59: Warning: suspicious precondition
    //#    the precondition for this.__Tag is not a contiguous range of values
    //#    severity: SUPPRESSED
    //#    class: net.sourceforge.pebble.index.IndexedTag
    //#    method: void net.sourceforge.pebble.index.IndexedTag(String, Blog)
    //#    suspicious precondition index: [3]
    //#input(void net.sourceforge.pebble.index.IndexedTag(String, Blog)): __Dispatch_Table.setName(Ljava/lang/String;)V
    //#input(void net.sourceforge.pebble.index.IndexedTag(String, Blog)): blog
    //#input(void net.sourceforge.pebble.index.IndexedTag(String, Blog)): name
    //#input(void net.sourceforge.pebble.index.IndexedTag(String, Blog)): net/sourceforge/pebble/domain/Tag.__Descendant_Table[net/sourceforge/pebble/domain/Tag]
    //#input(void net.sourceforge.pebble.index.IndexedTag(String, Blog)): net/sourceforge/pebble/domain/Tag.__Descendant_Table[net/sourceforge/pebble/index/IndexedTag]
    //#input(void net.sourceforge.pebble.index.IndexedTag(String, Blog)): net/sourceforge/pebble/domain/Tag.__Descendant_Table[others]
    //#input(void net.sourceforge.pebble.index.IndexedTag(String, Blog)): net/sourceforge/pebble/domain/Tag.__Dispatch_Table.setName(Ljava/lang/String;)V
    //#input(void net.sourceforge.pebble.index.IndexedTag(String, Blog)): this
    //#input(void net.sourceforge.pebble.index.IndexedTag(String, Blog)): this.__Tag
    //#output(void net.sourceforge.pebble.index.IndexedTag(String, Blog)): new ArrayList(IndexedTag#1) num objects
    //#output(void net.sourceforge.pebble.index.IndexedTag(String, Blog)): this.__Tag
    //#output(void net.sourceforge.pebble.index.IndexedTag(String, Blog)): this.blog
    //#output(void net.sourceforge.pebble.index.IndexedTag(String, Blog)): this.blogEntries
    //#output(void net.sourceforge.pebble.index.IndexedTag(String, Blog)): this.name
    //#new obj(void net.sourceforge.pebble.index.IndexedTag(String, Blog)): new ArrayList(IndexedTag#1)
    //#pre[3] (void net.sourceforge.pebble.index.IndexedTag(String, Blog)): this.__Tag in {net/sourceforge/pebble/domain/Tag, net/sourceforge/pebble/index/IndexedTag}
    //#post(void net.sourceforge.pebble.index.IndexedTag(String, Blog)): this.__Tag == old this.__Tag
    //#post(void net.sourceforge.pebble.index.IndexedTag(String, Blog)): this.__Tag in {net/sourceforge/pebble/domain/Tag, net/sourceforge/pebble/index/IndexedTag}
    //#post(void net.sourceforge.pebble.index.IndexedTag(String, Blog)): this.blog == blog
    //#post(void net.sourceforge.pebble.index.IndexedTag(String, Blog)): init'ed(this.blog)
    //#post(void net.sourceforge.pebble.index.IndexedTag(String, Blog)): this.blogEntries == &new ArrayList(IndexedTag#1)
    //#post(void net.sourceforge.pebble.index.IndexedTag(String, Blog)): this.name != null
    //#post(void net.sourceforge.pebble.index.IndexedTag(String, Blog)): new ArrayList(IndexedTag#1) num objects == 1
    //#unanalyzed(void net.sourceforge.pebble.index.IndexedTag(String, Blog)): Effects-of-calling:java.lang.String:trim
    //#unanalyzed(void net.sourceforge.pebble.index.IndexedTag(String, Blog)): Effects-of-calling:java.lang.String:toLowerCase
    //#unanalyzed(void net.sourceforge.pebble.index.IndexedTag(String, Blog)): Effects-of-calling:java.lang.String:replaceAll
  }
    //#indexedtag.java:60: end of method: void net.sourceforge.pebble.index.IndexedTag.net.sourceforge.pebble.index.IndexedTag(String, Blog)

  /**
   * Gets the blog entries associated with this tag.
   *
   * @return  a Collection of BlogEntry instances
   */
  public List<String> getBlogEntries() {
    return new ArrayList<String>(blogEntries);
    //#indexedtag.java:68: method: List net.sourceforge.pebble.index.IndexedTag.getBlogEntries()
    //#input(List getBlogEntries()): this
    //#input(List getBlogEntries()): this.blogEntries
    //#output(List getBlogEntries()): new ArrayList(getBlogEntries#1) num objects
    //#output(List getBlogEntries()): return_value
    //#new obj(List getBlogEntries()): new ArrayList(getBlogEntries#1)
    //#pre[2] (List getBlogEntries()): init'ed(this.blogEntries)
    //#post(List getBlogEntries()): return_value == &new ArrayList(getBlogEntries#1)
    //#post(List getBlogEntries()): new ArrayList(getBlogEntries#1) num objects == 1
    //#indexedtag.java:68: end of method: List net.sourceforge.pebble.index.IndexedTag.getBlogEntries()
  }

  /**
   * Adds a blog entry to this tag.
   *
   * @param blogEntryId   a blog entry ID
   */
  public synchronized void addBlogEntry(String blogEntryId) {
    if (blogEntryId != null && !blogEntries.contains(blogEntryId)) {
    //#indexedtag.java:77: method: void net.sourceforge.pebble.index.IndexedTag.addBlogEntry(String)
    //#input(void addBlogEntry(String)): blogEntryId
    //#input(void addBlogEntry(String)): this
    //#input(void addBlogEntry(String)): this.blogEntries
    //#pre[3] (void addBlogEntry(String)): (soft) this.blogEntries != null
    //#test_vector(void addBlogEntry(String)): blogEntryId: Addr_Set{null}, Inverse{null}
    //#test_vector(void addBlogEntry(String)): java.util.List:contains(...)@77: {1}, {0}
      blogEntries.add(blogEntryId);
      Collections.sort(blogEntries, new ReverseBlogEntryIdComparator());
    }
  }
    //#indexedtag.java:81: end of method: void net.sourceforge.pebble.index.IndexedTag.addBlogEntry(String)

  /**
   * Removes a blog entry to this tag.
   *
   * @param blogEntryId   a blog entry ID
   */
  public synchronized void removeBlogEntry(String blogEntryId) {
    if (blogEntryId != null) {
    //#indexedtag.java:89: method: void net.sourceforge.pebble.index.IndexedTag.removeBlogEntry(String)
    //#input(void removeBlogEntry(String)): blogEntryId
    //#input(void removeBlogEntry(String)): this
    //#input(void removeBlogEntry(String)): this.blogEntries
    //#pre[3] (void removeBlogEntry(String)): (soft) this.blogEntries != null
    //#test_vector(void removeBlogEntry(String)): blogEntryId: Addr_Set{null}, Inverse{null}
      blogEntries.remove(blogEntryId);
    }
  }
    //#indexedtag.java:92: end of method: void net.sourceforge.pebble.index.IndexedTag.removeBlogEntry(String)

  /**
   * Gets the number of blog entries associated with this tag.
   *
   * @return  an int
   */
  public int getNumberOfBlogEntries() {
    return blogEntries.size();
    //#indexedtag.java:100: method: int net.sourceforge.pebble.index.IndexedTag.getNumberOfBlogEntries()
    //#input(int getNumberOfBlogEntries()): this
    //#input(int getNumberOfBlogEntries()): this.blogEntries
    //#output(int getNumberOfBlogEntries()): return_value
    //#pre[2] (int getNumberOfBlogEntries()): this.blogEntries != null
    //#post(int getNumberOfBlogEntries()): init'ed(return_value)
    //#indexedtag.java:100: end of method: int net.sourceforge.pebble.index.IndexedTag.getNumberOfBlogEntries()
  }

  /**
   * Gets the rank for this tag.
   *
   * @return  an int between 1 and 10;
   */
  public int getRank() {
    return this.rank;
    //#indexedtag.java:109: method: int net.sourceforge.pebble.index.IndexedTag.getRank()
    //#input(int getRank()): this
    //#input(int getRank()): this.rank
    //#output(int getRank()): return_value
    //#pre[2] (int getRank()): init'ed(this.rank)
    //#post(int getRank()): return_value == this.rank
    //#post(int getRank()): init'ed(return_value)
    //#indexedtag.java:109: end of method: int net.sourceforge.pebble.index.IndexedTag.getRank()
  }

  /**
   * Sets the rank for this tag.
   *
   */
  void calculateRank(int[] thresholds) {
    for (int i = 0; i < thresholds.length; i++) {
    //#indexedtag.java:117: method: void net.sourceforge.pebble.index.IndexedTag.calculateRank(int[])
    //#input(void calculateRank(int[])): __Descendant_Table[net/sourceforge/pebble/index/IndexedTag]
    //#input(void calculateRank(int[])): __Descendant_Table[others]
    //#input(void calculateRank(int[])): __Dispatch_Table.getNumberOfBlogEntries()I
    //#input(void calculateRank(int[])): this
    //#input(void calculateRank(int[])): this.__Tag
    //#input(void calculateRank(int[])): this.blogEntries
    //#input(void calculateRank(int[])): thresholds
    //#input(void calculateRank(int[])): thresholds.length
    //#input(void calculateRank(int[])): thresholds[0..4_294_967_294]
    //#output(void calculateRank(int[])): this.rank
    //#pre[5] (void calculateRank(int[])): thresholds != null
    //#pre[3] (void calculateRank(int[])): (soft) this.__Tag == net/sourceforge/pebble/index/IndexedTag
    //#pre[4] (void calculateRank(int[])): (soft) this.blogEntries != null
    //#pre[6] (void calculateRank(int[])): (soft) thresholds.length <= 4_294_967_295
    //#pre[7] (void calculateRank(int[])): (soft) init'ed(thresholds[0..4_294_967_294])
    //#post(void calculateRank(int[])): possibly_updated(this.rank)
    //#unanalyzed(void calculateRank(int[])): Effects-of-calling:java.util.List:size
      int numberOfBlogEntries = getNumberOfBlogEntries();
      if (numberOfBlogEntries <= thresholds[i]) {
        this.rank = i+1;
        return;
      }
    }
  }
    //#indexedtag.java:124: end of method: void net.sourceforge.pebble.index.IndexedTag.calculateRank(int[])

}
    //#output(net.sourceforge.pebble.index.IndexedTag__static_init): __Descendant_Table[net/sourceforge/pebble/index/IndexedTag]
    //#output(net.sourceforge.pebble.index.IndexedTag__static_init): __Dispatch_Table.addBlogEntry(Ljava/lang/String;)V
    //#output(net.sourceforge.pebble.index.IndexedTag__static_init): __Dispatch_Table.calculateRank([I)V
    //#output(net.sourceforge.pebble.index.IndexedTag__static_init): __Dispatch_Table.compareTo(Ljava/lang/Object;)I
    //#output(net.sourceforge.pebble.index.IndexedTag__static_init): __Dispatch_Table.equals(Ljava/lang/Object;)Z
    //#output(net.sourceforge.pebble.index.IndexedTag__static_init): __Dispatch_Table.getBlogEntries()Ljava/util/List;
    //#output(net.sourceforge.pebble.index.IndexedTag__static_init): __Dispatch_Table.getName()Ljava/lang/String;
    //#output(net.sourceforge.pebble.index.IndexedTag__static_init): __Dispatch_Table.getNumberOfBlogEntries()I
    //#output(net.sourceforge.pebble.index.IndexedTag__static_init): __Dispatch_Table.getPermalink()Ljava/lang/String;
    //#output(net.sourceforge.pebble.index.IndexedTag__static_init): __Dispatch_Table.getRank()I
    //#output(net.sourceforge.pebble.index.IndexedTag__static_init): __Dispatch_Table.hashCode()I
    //#output(net.sourceforge.pebble.index.IndexedTag__static_init): __Dispatch_Table.removeBlogEntry(Ljava/lang/String;)V
    //#output(net.sourceforge.pebble.index.IndexedTag__static_init): __Dispatch_Table.setName(Ljava/lang/String;)V
    //#output(net.sourceforge.pebble.index.IndexedTag__static_init): __Dispatch_Table.toString()Ljava/lang/String;
    //#output(net.sourceforge.pebble.index.IndexedTag__static_init): net/sourceforge/pebble/domain/Permalinkable.__Descendant_Table[net/sourceforge/pebble/index/IndexedTag]
    //#output(net.sourceforge.pebble.index.IndexedTag__static_init): net/sourceforge/pebble/domain/Tag.__Descendant_Table[net/sourceforge/pebble/index/IndexedTag]
    //#post(net.sourceforge.pebble.index.IndexedTag__static_init): __Descendant_Table[net/sourceforge/pebble/index/IndexedTag] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.index.IndexedTag__static_init): net/sourceforge/pebble/domain/Permalinkable.__Descendant_Table[net/sourceforge/pebble/index/IndexedTag] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.index.IndexedTag__static_init): net/sourceforge/pebble/domain/Tag.__Descendant_Table[net/sourceforge/pebble/index/IndexedTag] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.index.IndexedTag__static_init): __Dispatch_Table.addBlogEntry(Ljava/lang/String;)V == &addBlogEntry
    //#post(net.sourceforge.pebble.index.IndexedTag__static_init): __Dispatch_Table.calculateRank([I)V == &calculateRank
    //#post(net.sourceforge.pebble.index.IndexedTag__static_init): __Dispatch_Table.compareTo(Ljava/lang/Object;)I == &net/sourceforge/pebble/domain/Tag.compareTo
    //#post(net.sourceforge.pebble.index.IndexedTag__static_init): __Dispatch_Table.equals(Ljava/lang/Object;)Z == &net/sourceforge/pebble/domain/Tag.equals
    //#post(net.sourceforge.pebble.index.IndexedTag__static_init): __Dispatch_Table.getBlogEntries()Ljava/util/List; == &getBlogEntries
    //#post(net.sourceforge.pebble.index.IndexedTag__static_init): __Dispatch_Table.getName()Ljava/lang/String; == &net/sourceforge/pebble/domain/Tag.getName
    //#post(net.sourceforge.pebble.index.IndexedTag__static_init): __Dispatch_Table.getNumberOfBlogEntries()I == &getNumberOfBlogEntries
    //#post(net.sourceforge.pebble.index.IndexedTag__static_init): __Dispatch_Table.getPermalink()Ljava/lang/String; == &net/sourceforge/pebble/domain/Tag.getPermalink
    //#post(net.sourceforge.pebble.index.IndexedTag__static_init): __Dispatch_Table.getRank()I == &getRank
    //#post(net.sourceforge.pebble.index.IndexedTag__static_init): __Dispatch_Table.hashCode()I == &net/sourceforge/pebble/domain/Tag.hashCode
    //#post(net.sourceforge.pebble.index.IndexedTag__static_init): __Dispatch_Table.removeBlogEntry(Ljava/lang/String;)V == &removeBlogEntry
    //#post(net.sourceforge.pebble.index.IndexedTag__static_init): __Dispatch_Table.setName(Ljava/lang/String;)V == &net/sourceforge/pebble/domain/Tag.setName
    //#post(net.sourceforge.pebble.index.IndexedTag__static_init): __Dispatch_Table.toString()Ljava/lang/String; == &net/sourceforge/pebble/domain/Tag.toString
    //#indexedtag.java:: end of method: net.sourceforge.pebble.index.IndexedTag.net.sourceforge.pebble.index.IndexedTag__static_init
    //#indexedtag.java:: end of class: net.sourceforge.pebble.index.IndexedTag
