//# 0 errors, 301 messages
//#
/*
    //#authorindex.java:1:1: class: net.sourceforge.pebble.index.AuthorIndex
 * 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.comparator.ReverseBlogEntryIdComparator;
import net.sourceforge.pebble.domain.Blog;
import net.sourceforge.pebble.domain.BlogEntry;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.*;
import java.util.*;

/**
 * Keeps an index of all blog entries from a specific author, allowing efficient access at runtime.
 *
 * @author    Simon Brown
 */
public class AuthorIndex {

  private static final Log log = LogFactory.getLog(AuthorIndex.class);
    //#authorindex.java:50: method: net.sourceforge.pebble.index.AuthorIndex.net.sourceforge.pebble.index.AuthorIndex__static_init
    //#authorindex.java:50: Warning: method not available
    //#    -- call on Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.index.AuthorIndex
    //#    method: net.sourceforge.pebble.index.AuthorIndex__static_init
    //#    unanalyzed callee: Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#output(net.sourceforge.pebble.index.AuthorIndex__static_init): __Descendant_Table[net/sourceforge/pebble/index/AuthorIndex]
    //#output(net.sourceforge.pebble.index.AuthorIndex__static_init): __Dispatch_Table.clear()V
    //#output(net.sourceforge.pebble.index.AuthorIndex__static_init): __Dispatch_Table.getAuthors()Ljava/util/List;
    //#output(net.sourceforge.pebble.index.AuthorIndex__static_init): __Dispatch_Table.getBlogEntries(Ljava/lang/String;)Ljava/util/List;
    //#output(net.sourceforge.pebble.index.AuthorIndex__static_init): __Dispatch_Table.getRecentBlogEntries(Ljava/lang/String;)Ljava/util/List;
    //#output(net.sourceforge.pebble.index.AuthorIndex__static_init): __Dispatch_Table.index(Ljava/util/Collection;)V
    //#output(net.sourceforge.pebble.index.AuthorIndex__static_init): __Dispatch_Table.index(Lnet/sourceforge/pebble/domain/BlogEntry;)V
    //#output(net.sourceforge.pebble.index.AuthorIndex__static_init): __Dispatch_Table.readIndex()V
    //#output(net.sourceforge.pebble.index.AuthorIndex__static_init): __Dispatch_Table.unindex(Lnet/sourceforge/pebble/domain/BlogEntry;)V
    //#output(net.sourceforge.pebble.index.AuthorIndex__static_init): __Dispatch_Table.writeIndex()V
    //#output(net.sourceforge.pebble.index.AuthorIndex__static_init): log
    //#post(net.sourceforge.pebble.index.AuthorIndex__static_init): __Descendant_Table[net/sourceforge/pebble/index/AuthorIndex] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.index.AuthorIndex__static_init): __Dispatch_Table.clear()V == &clear
    //#post(net.sourceforge.pebble.index.AuthorIndex__static_init): __Dispatch_Table.getAuthors()Ljava/util/List; == &getAuthors
    //#post(net.sourceforge.pebble.index.AuthorIndex__static_init): __Dispatch_Table.getBlogEntries(Ljava/lang/String;)Ljava/util/List; == &getBlogEntries
    //#post(net.sourceforge.pebble.index.AuthorIndex__static_init): __Dispatch_Table.getRecentBlogEntries(Ljava/lang/String;)Ljava/util/List; == &getRecentBlogEntries
    //#post(net.sourceforge.pebble.index.AuthorIndex__static_init): __Dispatch_Table.index(Ljava/util/Collection;)V == &index
    //#post(net.sourceforge.pebble.index.AuthorIndex__static_init): __Dispatch_Table.index(Lnet/sourceforge/pebble/domain/BlogEntry;)V == &index
    //#post(net.sourceforge.pebble.index.AuthorIndex__static_init): __Dispatch_Table.readIndex()V == &readIndex
    //#post(net.sourceforge.pebble.index.AuthorIndex__static_init): __Dispatch_Table.unindex(Lnet/sourceforge/pebble/domain/BlogEntry;)V == &unindex
    //#post(net.sourceforge.pebble.index.AuthorIndex__static_init): __Dispatch_Table.writeIndex()V == &writeIndex
    //#post(net.sourceforge.pebble.index.AuthorIndex__static_init): init'ed(log)
    //#authorindex.java:50: end of method: net.sourceforge.pebble.index.AuthorIndex.net.sourceforge.pebble.index.AuthorIndex__static_init

  private Blog blog;

  /** the map containing the tags */
  private Map<String,List<String>> authors = new HashMap<String,List<String>>();

  public AuthorIndex(Blog blog) {
    //#authorindex.java:57: method: void net.sourceforge.pebble.index.AuthorIndex.net.sourceforge.pebble.index.AuthorIndex(Blog)
    //#input(void net.sourceforge.pebble.index.AuthorIndex(Blog)): blog
    //#input(void net.sourceforge.pebble.index.AuthorIndex(Blog)): log
    //#input(void net.sourceforge.pebble.index.AuthorIndex(Blog)): this
    //#output(void net.sourceforge.pebble.index.AuthorIndex(Blog)): new HashMap(AuthorIndex#1) num objects
    //#output(void net.sourceforge.pebble.index.AuthorIndex(Blog)): this.authors
    //#output(void net.sourceforge.pebble.index.AuthorIndex(Blog)): this.blog
    //#new obj(void net.sourceforge.pebble.index.AuthorIndex(Blog)): new HashMap(AuthorIndex#1)
    //#pre[1] (void net.sourceforge.pebble.index.AuthorIndex(Blog)): blog != null
    //#post(void net.sourceforge.pebble.index.AuthorIndex(Blog)): this.authors == &new HashMap(AuthorIndex#1)
    //#post(void net.sourceforge.pebble.index.AuthorIndex(Blog)): this.blog == blog
    //#post(void net.sourceforge.pebble.index.AuthorIndex(Blog)): this.blog != null
    //#post(void net.sourceforge.pebble.index.AuthorIndex(Blog)): new HashMap(AuthorIndex#1) num objects == 1
    //#unanalyzed(void net.sourceforge.pebble.index.AuthorIndex(Blog)): Effects-of-calling:java.util.Map:get
    //#unanalyzed(void net.sourceforge.pebble.index.AuthorIndex(Blog)): Effects-of-calling:java.util.LinkedList
    //#unanalyzed(void net.sourceforge.pebble.index.AuthorIndex(Blog)): Effects-of-calling:java.util.Map:put
    //#unanalyzed(void net.sourceforge.pebble.index.AuthorIndex(Blog)): Effects-of-calling:net.sourceforge.pebble.domain.Blog:getIndexesDirectory
    //#unanalyzed(void net.sourceforge.pebble.index.AuthorIndex(Blog)): Effects-of-calling:java.io.File
    //#unanalyzed(void net.sourceforge.pebble.index.AuthorIndex(Blog)): Effects-of-calling:java.io.File:exists
    //#unanalyzed(void net.sourceforge.pebble.index.AuthorIndex(Blog)): Effects-of-calling:java.io.FileReader
    //#unanalyzed(void net.sourceforge.pebble.index.AuthorIndex(Blog)): Effects-of-calling:java.io.BufferedReader
    //#unanalyzed(void net.sourceforge.pebble.index.AuthorIndex(Blog)): Effects-of-calling:java.io.BufferedReader:readLine
    //#unanalyzed(void net.sourceforge.pebble.index.AuthorIndex(Blog)): Effects-of-calling:java.lang.String:split
    //#unanalyzed(void net.sourceforge.pebble.index.AuthorIndex(Blog)): Effects-of-calling:java.util.List:add
    //#unanalyzed(void net.sourceforge.pebble.index.AuthorIndex(Blog)): Effects-of-calling:java.io.BufferedReader:close
    //#unanalyzed(void net.sourceforge.pebble.index.AuthorIndex(Blog)): Effects-of-calling:org.apache.commons.logging.Log:error
    this.blog = blog;

    readIndex();
  }
    //#authorindex.java:61: end of method: void net.sourceforge.pebble.index.AuthorIndex.net.sourceforge.pebble.index.AuthorIndex(Blog)

  /**
   * Clears the index.
   */
  public void clear() {
    authors = new HashMap<String,List<String>>();
    //#authorindex.java:67: method: void net.sourceforge.pebble.index.AuthorIndex.clear()
    //#input(void clear()): log
    //#input(void clear()): this
    //#input(void clear()): this.blog
    //#output(void clear()): new HashMap(clear#1) num objects
    //#output(void clear()): this.authors
    //#new obj(void clear()): new HashMap(clear#1)
    //#pre[2] (void clear()): (soft) this.blog != null
    //#post(void clear()): this.authors == &new HashMap(clear#1)
    //#post(void clear()): new HashMap(clear#1) num objects == 1
    //#unanalyzed(void clear()): Effects-of-calling:java.util.Map:get
    //#unanalyzed(void clear()): Effects-of-calling:net.sourceforge.pebble.domain.Blog:getIndexesDirectory
    //#unanalyzed(void clear()): Effects-of-calling:java.io.File
    //#unanalyzed(void clear()): Effects-of-calling:org.apache.commons.logging.Log:error
    //#unanalyzed(void clear()): Effects-of-calling:java.io.FileWriter
    //#unanalyzed(void clear()): Effects-of-calling:java.io.BufferedWriter
    //#unanalyzed(void clear()): Effects-of-calling:java.util.Map:keySet
    //#unanalyzed(void clear()): Effects-of-calling:java.util.Set:iterator
    //#unanalyzed(void clear()): Effects-of-calling:java.util.Iterator:hasNext
    //#unanalyzed(void clear()): Effects-of-calling:java.util.Iterator:next
    //#unanalyzed(void clear()): Effects-of-calling:java.io.BufferedWriter:write
    //#unanalyzed(void clear()): Effects-of-calling:java.util.List:iterator
    //#unanalyzed(void clear()): Effects-of-calling:java.io.BufferedWriter:newLine
    //#unanalyzed(void clear()): Effects-of-calling:java.io.BufferedWriter:flush
    //#unanalyzed(void clear()): Effects-of-calling:java.io.BufferedWriter:close
    writeIndex();
  }
    //#authorindex.java:69: end of method: void net.sourceforge.pebble.index.AuthorIndex.clear()

  /**
   * Indexes one or more blog entries.
   *
   * @param blogEntries   a List of BlogEntry instances
   */
  public synchronized void index(Collection<BlogEntry> blogEntries) {
    for (BlogEntry blogEntry : blogEntries) {
    //#authorindex.java:77: method: void net.sourceforge.pebble.index.AuthorIndex.index(Collection)
    //#input(void index(Collection)): blogEntries
    //#input(void index(Collection)): log
    //#input(void index(Collection)): net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#5).__Tag
    //#input(void index(Collection)): net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#5).name
    //#input(void index(Collection)): net/sourceforge/pebble/domain/BlogEntry.__Descendant_Table[net/sourceforge/pebble/domain/BlogEntry]
    //#input(void index(Collection)): net/sourceforge/pebble/domain/BlogEntry.__Descendant_Table[others]
    //#input(void index(Collection)): net/sourceforge/pebble/domain/BlogEntry.__Dispatch_Table.getAuthor()Ljava/lang/String;
    //#input(void index(Collection)): net/sourceforge/pebble/domain/BlogEntry.__Dispatch_Table.getId()Ljava/lang/String;
    //#input(void index(Collection)): net/sourceforge/pebble/domain/BlogEntry.__Dispatch_Table.getState()Lnet/sourceforge/pebble/domain/State;
    //#input(void index(Collection)): net/sourceforge/pebble/domain/BlogEntry.__Dispatch_Table.isPublished()Z
    //#input(void index(Collection)): net/sourceforge/pebble/domain/PageBasedContent.__Descendant_Table[net/sourceforge/pebble/domain/BlogEntry]
    //#input(void index(Collection)): net/sourceforge/pebble/domain/PageBasedContent.__Descendant_Table[net/sourceforge/pebble/domain/PageBasedContent]
    //#input(void index(Collection)): net/sourceforge/pebble/domain/PageBasedContent.__Descendant_Table[net/sourceforge/pebble/domain/StaticPage]
    //#input(void index(Collection)): net/sourceforge/pebble/domain/PageBasedContent.__Descendant_Table[others]
    //#input(void index(Collection)): net/sourceforge/pebble/domain/PageBasedContent.__Dispatch_Table.getState()Lnet/sourceforge/pebble/domain/State;
    //#input(void index(Collection)): net/sourceforge/pebble/domain/State.PUBLISHED
    //#input(void index(Collection)): net/sourceforge/pebble/domain/State.__Descendant_Table[net/sourceforge/pebble/domain/State]
    //#input(void index(Collection)): net/sourceforge/pebble/domain/State.__Descendant_Table[others]
    //#input(void index(Collection)): net/sourceforge/pebble/domain/State.__Dispatch_Table.equals(Ljava/lang/Object;)Z
    //#input(void index(Collection)): net/sourceforge/pebble/domain/State.__Dispatch_Table.getName()Ljava/lang/String;
    //#input(void index(Collection)): net/sourceforge/pebble/domain/StaticPage.__Dispatch_Table.getState()Lnet/sourceforge/pebble/domain/State;
    //#input(void index(Collection)): this
    //#input(void index(Collection)): this.authors
    //#input(void index(Collection)): this.blog
    //#pre[1] (void index(Collection)): blogEntries != null
    //#pre[2] (void index(Collection)): (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#5).name != null
    //#pre[4] (void index(Collection)): (soft) this.authors != null
    //#pre[5] (void index(Collection)): (soft) this.blog != null
    //#presumption(void index(Collection)): blogEntry.state.__Tag@77 == net/sourceforge/pebble/domain/State
    //#presumption(void index(Collection)): blogEntry.state@77 != null
    //#presumption(void index(Collection)): java.util.Iterator:next(...).__Tag@77 == net/sourceforge/pebble/domain/BlogEntry
    //#presumption(void index(Collection)): java.util.Iterator:next(...)@77 != null
    //#unanalyzed(void index(Collection)): Effects-of-calling:java.util.Map:get
    //#unanalyzed(void index(Collection)): Effects-of-calling:java.util.LinkedList
    //#unanalyzed(void index(Collection)): Effects-of-calling:java.util.Map:put
    //#unanalyzed(void index(Collection)): Effects-of-calling:net.sourceforge.pebble.domain.Blog:getIndexesDirectory
    //#unanalyzed(void index(Collection)): Effects-of-calling:java.io.File
    //#unanalyzed(void index(Collection)): Effects-of-calling:org.apache.commons.logging.Log:error
    //#unanalyzed(void index(Collection)): Effects-of-calling:java.io.FileWriter
    //#unanalyzed(void index(Collection)): Effects-of-calling:java.io.BufferedWriter
    //#unanalyzed(void index(Collection)): Effects-of-calling:java.util.Map:keySet
    //#unanalyzed(void index(Collection)): Effects-of-calling:java.util.Set:iterator
    //#unanalyzed(void index(Collection)): Effects-of-calling:java.util.Iterator:hasNext
    //#unanalyzed(void index(Collection)): Effects-of-calling:java.util.Iterator:next
    //#unanalyzed(void index(Collection)): Effects-of-calling:java.io.BufferedWriter:write
    //#unanalyzed(void index(Collection)): Effects-of-calling:java.util.List:iterator
    //#unanalyzed(void index(Collection)): Effects-of-calling:java.io.BufferedWriter:newLine
    //#unanalyzed(void index(Collection)): Effects-of-calling:java.io.BufferedWriter:flush
    //#unanalyzed(void index(Collection)): Effects-of-calling:java.io.BufferedWriter:close
    //#unanalyzed(void index(Collection)): Effects-of-calling:java.lang.String:equals
    //#test_vector(void index(Collection)): java.util.Iterator:hasNext(...)@77: {1}, {0}
      if (blogEntry.isPublished()) {
        List<String> blogEntryIds = getBlogEntries(blogEntry.getAuthor());
        blogEntryIds.add(blogEntry.getId());
        Collections.sort(blogEntryIds, new ReverseBlogEntryIdComparator());
      }
    }

    writeIndex();
  }
    //#authorindex.java:86: end of method: void net.sourceforge.pebble.index.AuthorIndex.index(Collection)

  /**
   * Indexes a single blog entry.
   *
   * @param blogEntry   a BlogEntry instance
   */
  public synchronized void index(BlogEntry blogEntry) {
    if (blogEntry.isPublished()) {
    //#authorindex.java:94: method: void net.sourceforge.pebble.index.AuthorIndex.index(BlogEntry)
    //#input(void index(BlogEntry)): blogEntry
    //#input(void index(BlogEntry)): blogEntry.__Tag
    //#input(void index(BlogEntry)): blogEntry.author
    //#input(void index(BlogEntry)): blogEntry.id
    //#input(void index(BlogEntry)): blogEntry.state
    //#input(void index(BlogEntry)): blogEntry.state.__Tag
    //#input(void index(BlogEntry)): blogEntry.state.name
    //#input(void index(BlogEntry)): log
    //#input(void index(BlogEntry)): net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#5).__Tag
    //#input(void index(BlogEntry)): net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#5).name
    //#input(void index(BlogEntry)): net/sourceforge/pebble/domain/BlogEntry.__Descendant_Table[net/sourceforge/pebble/domain/BlogEntry]
    //#input(void index(BlogEntry)): net/sourceforge/pebble/domain/BlogEntry.__Descendant_Table[others]
    //#input(void index(BlogEntry)): net/sourceforge/pebble/domain/BlogEntry.__Dispatch_Table.getAuthor()Ljava/lang/String;
    //#input(void index(BlogEntry)): net/sourceforge/pebble/domain/BlogEntry.__Dispatch_Table.getId()Ljava/lang/String;
    //#input(void index(BlogEntry)): net/sourceforge/pebble/domain/BlogEntry.__Dispatch_Table.getState()Lnet/sourceforge/pebble/domain/State;
    //#input(void index(BlogEntry)): net/sourceforge/pebble/domain/BlogEntry.__Dispatch_Table.isPublished()Z
    //#input(void index(BlogEntry)): net/sourceforge/pebble/domain/PageBasedContent.__Descendant_Table[net/sourceforge/pebble/domain/BlogEntry]
    //#input(void index(BlogEntry)): net/sourceforge/pebble/domain/PageBasedContent.__Descendant_Table[net/sourceforge/pebble/domain/PageBasedContent]
    //#input(void index(BlogEntry)): net/sourceforge/pebble/domain/PageBasedContent.__Descendant_Table[net/sourceforge/pebble/domain/StaticPage]
    //#input(void index(BlogEntry)): net/sourceforge/pebble/domain/PageBasedContent.__Descendant_Table[others]
    //#input(void index(BlogEntry)): net/sourceforge/pebble/domain/PageBasedContent.__Dispatch_Table.getState()Lnet/sourceforge/pebble/domain/State;
    //#input(void index(BlogEntry)): net/sourceforge/pebble/domain/State.PUBLISHED
    //#input(void index(BlogEntry)): net/sourceforge/pebble/domain/State.__Descendant_Table[net/sourceforge/pebble/domain/State]
    //#input(void index(BlogEntry)): net/sourceforge/pebble/domain/State.__Descendant_Table[others]
    //#input(void index(BlogEntry)): net/sourceforge/pebble/domain/State.__Dispatch_Table.equals(Ljava/lang/Object;)Z
    //#input(void index(BlogEntry)): net/sourceforge/pebble/domain/State.__Dispatch_Table.getName()Ljava/lang/String;
    //#input(void index(BlogEntry)): net/sourceforge/pebble/domain/StaticPage.__Dispatch_Table.getState()Lnet/sourceforge/pebble/domain/State;
    //#input(void index(BlogEntry)): this
    //#input(void index(BlogEntry)): this.authors
    //#input(void index(BlogEntry)): this.blog
    //#pre[1] (void index(BlogEntry)): blogEntry != null
    //#pre[2] (void index(BlogEntry)): blogEntry.__Tag == net/sourceforge/pebble/domain/BlogEntry
    //#pre[5] (void index(BlogEntry)): blogEntry.state != null
    //#pre[6] (void index(BlogEntry)): blogEntry.state.__Tag == net/sourceforge/pebble/domain/State
    //#pre[3] (void index(BlogEntry)): (soft) init'ed(blogEntry.author)
    //#pre[4] (void index(BlogEntry)): (soft) init'ed(blogEntry.id)
    //#pre[7] (void index(BlogEntry)): (soft) init'ed(blogEntry.state.name)
    //#pre[8] (void index(BlogEntry)): (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#5).name != null
    //#pre[10] (void index(BlogEntry)): (soft) this.authors != null
    //#pre[11] (void index(BlogEntry)): (soft) this.blog != null
    //#unanalyzed(void index(BlogEntry)): Effects-of-calling:java.util.Map:get
    //#unanalyzed(void index(BlogEntry)): Effects-of-calling:java.util.LinkedList
    //#unanalyzed(void index(BlogEntry)): Effects-of-calling:java.util.Map:put
    //#unanalyzed(void index(BlogEntry)): Effects-of-calling:net.sourceforge.pebble.domain.Blog:getIndexesDirectory
    //#unanalyzed(void index(BlogEntry)): Effects-of-calling:java.io.File
    //#unanalyzed(void index(BlogEntry)): Effects-of-calling:org.apache.commons.logging.Log:error
    //#unanalyzed(void index(BlogEntry)): Effects-of-calling:java.io.FileWriter
    //#unanalyzed(void index(BlogEntry)): Effects-of-calling:java.io.BufferedWriter
    //#unanalyzed(void index(BlogEntry)): Effects-of-calling:java.util.Map:keySet
    //#unanalyzed(void index(BlogEntry)): Effects-of-calling:java.util.Set:iterator
    //#unanalyzed(void index(BlogEntry)): Effects-of-calling:java.util.Iterator:hasNext
    //#unanalyzed(void index(BlogEntry)): Effects-of-calling:java.util.Iterator:next
    //#unanalyzed(void index(BlogEntry)): Effects-of-calling:java.io.BufferedWriter:write
    //#unanalyzed(void index(BlogEntry)): Effects-of-calling:java.util.List:iterator
    //#unanalyzed(void index(BlogEntry)): Effects-of-calling:java.io.BufferedWriter:newLine
    //#unanalyzed(void index(BlogEntry)): Effects-of-calling:java.io.BufferedWriter:flush
    //#unanalyzed(void index(BlogEntry)): Effects-of-calling:java.io.BufferedWriter:close
    //#unanalyzed(void index(BlogEntry)): Effects-of-calling:java.lang.String:equals
      List<String> blogEntryIds = getBlogEntries(blogEntry.getAuthor());
      blogEntryIds.add(blogEntry.getId());
      Collections.sort(blogEntryIds, new ReverseBlogEntryIdComparator());

      writeIndex();
    }
  }
    //#authorindex.java:101: end of method: void net.sourceforge.pebble.index.AuthorIndex.index(BlogEntry)

  /**
   * Unindexes a single blog entry.
   *
   * @param blogEntry   a BlogEntry instance
   */
  public synchronized void unindex(BlogEntry blogEntry) {
    List<String> blogEntries = authors.get(blogEntry.getAuthor());
    //#authorindex.java:109: method: void net.sourceforge.pebble.index.AuthorIndex.unindex(BlogEntry)
    //#input(void unindex(BlogEntry)): blogEntry
    //#input(void unindex(BlogEntry)): blogEntry.__Tag
    //#input(void unindex(BlogEntry)): blogEntry.author
    //#input(void unindex(BlogEntry)): blogEntry.id
    //#input(void unindex(BlogEntry)): log
    //#input(void unindex(BlogEntry)): net/sourceforge/pebble/domain/BlogEntry.__Descendant_Table[net/sourceforge/pebble/domain/BlogEntry]
    //#input(void unindex(BlogEntry)): net/sourceforge/pebble/domain/BlogEntry.__Descendant_Table[others]
    //#input(void unindex(BlogEntry)): net/sourceforge/pebble/domain/BlogEntry.__Dispatch_Table.getAuthor()Ljava/lang/String;
    //#input(void unindex(BlogEntry)): net/sourceforge/pebble/domain/BlogEntry.__Dispatch_Table.getId()Ljava/lang/String;
    //#input(void unindex(BlogEntry)): this
    //#input(void unindex(BlogEntry)): this.authors
    //#input(void unindex(BlogEntry)): this.blog
    //#pre[1] (void unindex(BlogEntry)): blogEntry != null
    //#pre[2] (void unindex(BlogEntry)): blogEntry.__Tag == net/sourceforge/pebble/domain/BlogEntry
    //#pre[3] (void unindex(BlogEntry)): init'ed(blogEntry.author)
    //#pre[6] (void unindex(BlogEntry)): this.authors != null
    //#pre[4] (void unindex(BlogEntry)): (soft) init'ed(blogEntry.id)
    //#pre[7] (void unindex(BlogEntry)): (soft) this.blog != null
    //#unanalyzed(void unindex(BlogEntry)): Effects-of-calling:java.util.Map:get
    //#unanalyzed(void unindex(BlogEntry)): Effects-of-calling:net.sourceforge.pebble.domain.Blog:getIndexesDirectory
    //#unanalyzed(void unindex(BlogEntry)): Effects-of-calling:java.io.File
    //#unanalyzed(void unindex(BlogEntry)): Effects-of-calling:org.apache.commons.logging.Log:error
    //#unanalyzed(void unindex(BlogEntry)): Effects-of-calling:java.io.FileWriter
    //#unanalyzed(void unindex(BlogEntry)): Effects-of-calling:java.io.BufferedWriter
    //#unanalyzed(void unindex(BlogEntry)): Effects-of-calling:java.util.Map:keySet
    //#unanalyzed(void unindex(BlogEntry)): Effects-of-calling:java.util.Set:iterator
    //#unanalyzed(void unindex(BlogEntry)): Effects-of-calling:java.util.Iterator:hasNext
    //#unanalyzed(void unindex(BlogEntry)): Effects-of-calling:java.util.Iterator:next
    //#unanalyzed(void unindex(BlogEntry)): Effects-of-calling:java.io.BufferedWriter:write
    //#unanalyzed(void unindex(BlogEntry)): Effects-of-calling:java.util.List:iterator
    //#unanalyzed(void unindex(BlogEntry)): Effects-of-calling:java.io.BufferedWriter:newLine
    //#unanalyzed(void unindex(BlogEntry)): Effects-of-calling:java.io.BufferedWriter:flush
    //#unanalyzed(void unindex(BlogEntry)): Effects-of-calling:java.io.BufferedWriter:close
    //#test_vector(void unindex(BlogEntry)): java.util.List:isEmpty(...)@113: {0}, {1}
    //#test_vector(void unindex(BlogEntry)): java.util.Map:get(...)@109: Addr_Set{null}, Inverse{null}
    if (blogEntries != null) {
      blogEntries.remove(blogEntry.getId());

      if (blogEntries.isEmpty()) {
        authors.remove(blogEntry.getAuthor());
      }
    }

    writeIndex();
  }
    //#authorindex.java:119: end of method: void net.sourceforge.pebble.index.AuthorIndex.unindex(BlogEntry)

  /**
   * Helper method to load the index.
   */
  private void readIndex() {
    File indexFile = new File(blog.getIndexesDirectory(), "authors.index");
    //#authorindex.java:125: method: void net.sourceforge.pebble.index.AuthorIndex.readIndex()
    //#authorindex.java:125: Warning: method not available
    //#    -- call on String net.sourceforge.pebble.domain.Blog:getIndexesDirectory()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.index.AuthorIndex
    //#    method: void readIndex()
    //#    unanalyzed callee: String net.sourceforge.pebble.domain.Blog:getIndexesDirectory()
    //#input(void readIndex()): log
    //#input(void readIndex()): this
    //#input(void readIndex()): this.authors
    //#input(void readIndex()): this.blog
    //#pre[3] (void readIndex()): this.blog != null
    //#pre[2] (void readIndex()): (soft) this.authors != null
    //#presumption(void readIndex()): blogEntryIds.length@136 <= 4_294_967_295
    //#presumption(void readIndex()): org.apache.commons.logging.LogFactory:getLog(...)@50 != null
    //#presumption(void readIndex()): tuple.length@131 >= 1
    //#unanalyzed(void readIndex()): Effects-of-calling:java.util.Map:get
    //#unanalyzed(void readIndex()): Effects-of-calling:java.util.LinkedList
    //#unanalyzed(void readIndex()): Effects-of-calling:java.util.Map:put
    //#test_vector(void readIndex()): java.io.File:exists(...)@126: {0}, {1}
    //#test_vector(void readIndex()): tuple.length@131: {1}, {2..+Inf}
    //#test_vector(void readIndex()): tuple[1]@131: Addr_Set{null}, Inverse{null}
    if (indexFile.exists()) {
      try {
        BufferedReader reader = new BufferedReader(new FileReader(indexFile));
        String indexEntry = reader.readLine();
        while (indexEntry != null) {
          String[] tuple = indexEntry.split("=");
          String author = tuple[0];
          List<String> blogEntries = getBlogEntries(author);

          if (tuple.length > 1 && tuple[1] != null) {
            String[] blogEntryIds = tuple[1].split(",");
            for (String blogEntry : blogEntryIds) {
              blogEntries.add(blogEntry);
            }
          }

          indexEntry = reader.readLine();
        }

        reader.close();
      } catch (Exception e) {
        log.error("Error while reading index", e);
    //#authorindex.java:147: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:error(Object, Throwable)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.index.AuthorIndex
    //#    method: void readIndex()
    //#    unanalyzed callee: void org.apache.commons.logging.Log:error(Object, Throwable)
      }
    }
  }
    //#authorindex.java:150: end of method: void net.sourceforge.pebble.index.AuthorIndex.readIndex()

  /**
   * Helper method to write out the index to disk.
   */
  private void writeIndex() {
    try {
      File indexFile = new File(blog.getIndexesDirectory(), "authors.index");
    //#authorindex.java:157: method: void net.sourceforge.pebble.index.AuthorIndex.writeIndex()
    //#authorindex.java:157: Warning: method not available
    //#    -- call on String net.sourceforge.pebble.domain.Blog:getIndexesDirectory()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.index.AuthorIndex
    //#    method: void writeIndex()
    //#    unanalyzed callee: String net.sourceforge.pebble.domain.Blog:getIndexesDirectory()
    //#input(void writeIndex()): log
    //#input(void writeIndex()): this
    //#input(void writeIndex()): this.authors
    //#input(void writeIndex()): this.blog
    //#pre[2] (void writeIndex()): (soft) this.authors != null
    //#pre[3] (void writeIndex()): (soft) this.blog != null
    //#presumption(void writeIndex()): java.util.Map:keySet(...)@160 != null
    //#presumption(void writeIndex()): org.apache.commons.logging.LogFactory:getLog(...)@50 != null
    //#test_vector(void writeIndex()): java.util.Iterator:hasNext(...)@160: {1}, {0}
    //#test_vector(void writeIndex()): java.util.Iterator:hasNext(...)@165: {1}, {0}
    //#test_vector(void writeIndex()): java.util.Map:get(...)@163: Addr_Set{null}, Inverse{null}
      BufferedWriter writer = new BufferedWriter(new FileWriter(indexFile));

      for (String author : authors.keySet()) {
        writer.write(author);
        writer.write("=");
        List<String> blogEntries = authors.get(author);
        if (blogEntries != null) {
          for (String blogEntry : blogEntries) {
            writer.write(blogEntry);
            writer.write(",");
          }
        }
        writer.newLine();
      }

      writer.flush();
      writer.close();
    } catch (Exception e) {
      log.error("Error while writing index", e);
    //#authorindex.java:176: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:error(Object, Throwable)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.index.AuthorIndex
    //#    method: void writeIndex()
    //#    unanalyzed callee: void org.apache.commons.logging.Log:error(Object, Throwable)
    }
  }
    //#authorindex.java:178: end of method: void net.sourceforge.pebble.index.AuthorIndex.writeIndex()

  private synchronized List<String> getBlogEntries(String author) {
    List<String> blogEntries = authors.get(author);
    //#authorindex.java:181: method: List net.sourceforge.pebble.index.AuthorIndex.getBlogEntries(String)
    //#input(List getBlogEntries(String)): author
    //#input(List getBlogEntries(String)): this
    //#input(List getBlogEntries(String)): this.authors
    //#output(List getBlogEntries(String)): new LinkedList(getBlogEntries#1) num objects
    //#output(List getBlogEntries(String)): return_value
    //#new obj(List getBlogEntries(String)): new LinkedList(getBlogEntries#1)
    //#pre[3] (List getBlogEntries(String)): this.authors != null
    //#post(List getBlogEntries(String)): return_value != null
    //#post(List getBlogEntries(String)): new LinkedList(getBlogEntries#1) num objects <= 1
    //#test_vector(List getBlogEntries(String)): java.util.Map:get(...)@181: Inverse{null}, Addr_Set{null}
    if (blogEntries == null) {
      blogEntries = new LinkedList<String>();
      authors.put(author, blogEntries);
    }

    return blogEntries;
    //#authorindex.java:187: end of method: List net.sourceforge.pebble.index.AuthorIndex.getBlogEntries(String)
  }

  /**
   * Gets the list of authors associated with this blog.
   */
  public List<String> getAuthors() {
    return new LinkedList<String>(authors.keySet());
    //#authorindex.java:194: method: List net.sourceforge.pebble.index.AuthorIndex.getAuthors()
    //#input(List getAuthors()): this
    //#input(List getAuthors()): this.authors
    //#output(List getAuthors()): new LinkedList(getAuthors#1) num objects
    //#output(List getAuthors()): return_value
    //#new obj(List getAuthors()): new LinkedList(getAuthors#1)
    //#pre[2] (List getAuthors()): this.authors != null
    //#post(List getAuthors()): return_value == &new LinkedList(getAuthors#1)
    //#post(List getAuthors()): new LinkedList(getAuthors#1) num objects == 1
    //#authorindex.java:194: end of method: List net.sourceforge.pebble.index.AuthorIndex.getAuthors()
  }

  /**
   * Gets the blog entries for a given author.
   *
   * @param username    a username (String)
   * @return  a List of blog entry IDs
   */
  public List<String> getRecentBlogEntries(String username) {
    List<String> blogEntries = authors.get(username);
    //#authorindex.java:204: method: List net.sourceforge.pebble.index.AuthorIndex.getRecentBlogEntries(String)
    //#input(List getRecentBlogEntries(String)): this
    //#input(List getRecentBlogEntries(String)): this.authors
    //#input(List getRecentBlogEntries(String)): username
    //#output(List getRecentBlogEntries(String)): new LinkedList(getRecentBlogEntries#1) num objects
    //#output(List getRecentBlogEntries(String)): new LinkedList(getRecentBlogEntries#2) num objects
    //#output(List getRecentBlogEntries(String)): return_value
    //#new obj(List getRecentBlogEntries(String)): new LinkedList(getRecentBlogEntries#1)
    //#new obj(List getRecentBlogEntries(String)): new LinkedList(getRecentBlogEntries#2)
    //#pre[2] (List getRecentBlogEntries(String)): this.authors != null
    //#post(List getRecentBlogEntries(String)): return_value in Addr_Set{&new LinkedList(getRecentBlogEntries#2),&new LinkedList(getRecentBlogEntries#1)}
    //#post(List getRecentBlogEntries(String)): new LinkedList(getRecentBlogEntries#1) num objects <= 1
    //#post(List getRecentBlogEntries(String)): new LinkedList(getRecentBlogEntries#2) num objects <= 1
    //#test_vector(List getRecentBlogEntries(String)): java.util.Map:get(...)@204: Inverse{null}, Addr_Set{null}
    if (blogEntries == null) {
      return new LinkedList<String>();
    } else {
      return new LinkedList<String>(blogEntries);
    //#authorindex.java:208: end of method: List net.sourceforge.pebble.index.AuthorIndex.getRecentBlogEntries(String)
    }
  }

}    //#authorindex.java:: end of class: net.sourceforge.pebble.index.AuthorIndex
