File Source: responsemanager.java

         /* 
    P/P   *  Method: net.sourceforge.pebble.domain.ResponseManager__static_init
          */
     1  /*
     2   * Copyright (c) 2003-2006, Simon Brown
     3   * All rights reserved.
     4   *
     5   * Redistribution and use in source and binary forms, with or without
     6   * modification, are permitted provided that the following conditions are met:
     7   *
     8   *   - Redistributions of source code must retain the above copyright
     9   *     notice, this list of conditions and the following disclaimer.
    10   *
    11   *   - Redistributions in binary form must reproduce the above copyright
    12   *     notice, this list of conditions and the following disclaimer in
    13   *     the documentation and/or other materials provided with the
    14   *     distribution.
    15   *
    16   *   - Neither the name of Pebble nor the names of its contributors may
    17   *     be used to endorse or promote products derived from this software
    18   *     without specific prior written permission.
    19   *
    20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    30   * POSSIBILITY OF SUCH DAMAGE.
    31   */
    32  package net.sourceforge.pebble.domain;
    33  
    34  import net.sourceforge.pebble.comparator.ResponseByDateComparator;
    35  import net.sourceforge.pebble.api.event.comment.CommentEvent;
    36  import net.sourceforge.pebble.api.event.comment.CommentListener;
    37  import net.sourceforge.pebble.api.event.trackback.TrackBackEvent;
    38  import net.sourceforge.pebble.api.event.trackback.TrackBackListener;
    39  
    40  import java.util.*;
    41  
    42  /**
    43   * Internal comment and TrackBack listener used to manage the list of
    44   * responses for the associated blog.
    45   *
    46   * @author    Simon Brown
    47   */
    48  public class ResponseManager implements CommentListener, TrackBackListener {
    49  
    50    /** the owning blog */
    51    private Blog blog;
    52  
    53    /** the set of recent comments */
    54    private SortedSet recentComments;
    55  
    56    /** the set of recent TrackBacks */
    57    private SortedSet recentTrackBacks;
    58  
    59    /** the set of recent responses (comments and TrackBacks) */
    60    private SortedSet approvedResponses;
    61  
    62    /** the set of pending responses (comments and TrackBacks) */
    63    private SortedSet pendingResponses;
    64  
    65    /** the set of rejected responses (comments and TrackBacks) */
    66    private SortedSet rejectedResponses;
    67  
    68    /**
    69     * Creates a new instance associated with the specified blog.
    70     *
    71     * @param blog    a Blog instance
    72     */
           /* 
    P/P     *  Method: void net.sourceforge.pebble.domain.ResponseManager(Blog)
            * 
            *  Postconditions:
            *    this.approvedResponses == &new TreeSet(ResponseManager#5)
            *    this.blog == blog
            *    init'ed(this.blog)
            *    this.pendingResponses == &new TreeSet(ResponseManager#7)
            *    this.recentComments == &new TreeSet(ResponseManager#1)
            *    this.recentTrackBacks == &new TreeSet(ResponseManager#3)
            *    this.rejectedResponses == &new TreeSet(ResponseManager#9)
            *    new TreeSet(ResponseManager#1) num objects == 1
            *    new TreeSet(ResponseManager#3) num objects == 1
            *    new TreeSet(ResponseManager#5) num objects == 1
            *    ...
            */
    73    public ResponseManager(Blog blog) {
    74      this.blog = blog;
    75  
    76      recentComments = new TreeSet(new ResponseByDateComparator());
    77      recentTrackBacks = new TreeSet(new ResponseByDateComparator());
    78      approvedResponses = new TreeSet(new ResponseByDateComparator());
    79      pendingResponses = new TreeSet(new ResponseByDateComparator());
    80      rejectedResponses = new TreeSet(new ResponseByDateComparator());
    81    }
    82  
    83    /**
    84     * Gets recent comments.
    85     *
    86     * @return  a collection containing comments that have been left most recently
    87     */
    88    public Collection getRecentComments() {
             /* 
    P/P       *  Method: Collection getRecentComments()
              * 
              *  Preconditions:
              *    init'ed(this.recentComments)
              * 
              *  Postconditions:
              *    return_value == this.recentComments
              *    init'ed(return_value)
              */
    89      return this.recentComments;
    90    }
    91  
    92    /**
    93     * Gets recent TrackBacks.
    94     *
    95     * @return  a collection containing TrackBacks that have been left most recently
    96     */
    97    public Collection getRecentTrackBacks() {
             /* 
    P/P       *  Method: Collection getRecentTrackBacks()
              * 
              *  Preconditions:
              *    init'ed(this.recentTrackBacks)
              * 
              *  Postconditions:
              *    return_value == this.recentTrackBacks
              *    init'ed(return_value)
              */
    98      return this.recentTrackBacks;
    99    }
   100  
   101    /**
   102     * Gets recent responses (combined comments and TrackBacks).
   103     *
   104     * @return  a collection containing comments and TrackBacks that have been left
   105     *          most recently
   106     */
   107    public Collection getRecentResponses() {
             /* 
    P/P       *  Method: Collection getRecentResponses()
              * 
              *  Preconditions:
              *    init'ed(this.approvedResponses)
              * 
              *  Postconditions:
              *    return_value == &new ArrayList(getRecentResponses#1)
              *    new ArrayList(getRecentResponses#1) num objects == 1
              */
   108      List list = new ArrayList();
   109      list.addAll(approvedResponses);
   110      return list;
   111    }
   112  
   113    /**
   114     * Gets the number of approved responses.
   115     *
   116     * @return  an int
   117     */
   118    public int getNumberOfApprovedResponses() {
             /* 
    P/P       *  Method: int getNumberOfApprovedResponses()
              * 
              *  Preconditions:
              *    this.approvedResponses != null
              * 
              *  Postconditions:
              *    init'ed(return_value)
              */
   119      return approvedResponses.size();
   120    }
   121  
   122    /**
   123     * Gets pending responses (combined comments and TrackBacks).
   124     *
   125     * @return  a collection containing comments and TrackBacks that are pending
   126     */
   127    public Collection getPendingResponses() {
             /* 
    P/P       *  Method: Collection getPendingResponses()
              * 
              *  Preconditions:
              *    init'ed(this.pendingResponses)
              * 
              *  Postconditions:
              *    return_value == &new ArrayList(getPendingResponses#1)
              *    new ArrayList(getPendingResponses#1) num objects == 1
              */
   128      List list = new ArrayList();
   129      list.addAll(pendingResponses);
   130      return list;
   131    }
   132  
   133    /**
   134     * Gets the number of pending responses.
   135     *
   136     * @return  an int
   137     */
   138    public int getNumberOfPendingResponses() {
             /* 
    P/P       *  Method: int getNumberOfPendingResponses()
              * 
              *  Preconditions:
              *    this.pendingResponses != null
              * 
              *  Postconditions:
              *    init'ed(return_value)
              */
   139      return pendingResponses.size();
   140    }
   141  
   142    /**
   143     * Gets rejected responses (combined comments and TrackBacks).
   144     *
   145     * @return  a collection containing comments and TrackBacks that are rejected
   146     */
   147    public Collection getRejectedResponses() {
             /* 
    P/P       *  Method: Collection getRejectedResponses()
              * 
              *  Preconditions:
              *    init'ed(this.rejectedResponses)
              * 
              *  Postconditions:
              *    return_value == &new ArrayList(getRejectedResponses#1)
              *    new ArrayList(getRejectedResponses#1) num objects == 1
              */
   148      List list = new ArrayList();
   149      list.addAll(rejectedResponses);
   150      return list;
   151    }
   152  
   153    /**
   154     * Gets the number of rejected responses.
   155     *
   156     * @return  an int
   157     */
   158    public int getNumberOfRejectedResponses() {
             /* 
    P/P       *  Method: int getNumberOfRejectedResponses()
              * 
              *  Preconditions:
              *    this.rejectedResponses != null
              * 
              *  Postconditions:
              *    init'ed(return_value)
              */
   159      return rejectedResponses.size();
   160    }
   161  
   162    /**
   163     * Called when a comment has been added.
   164     *
   165     * @param comment   a Comment instance
   166     */
   167    synchronized void addRecentComment(Comment comment) {
             /* 
    P/P       *  Method: void addRecentComment(Comment)
              * 
              *  Preconditions:
              *    comment != null
              *    comment.state != null
              *    (soft) init'ed(comment.state.name)
              *    (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#1).name != null
              *    (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#2).name != null
              *    (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#3).name != null
              *    (soft) this.approvedResponses != null
              *    (soft) this.pendingResponses != null
              *    (soft) this.recentComments != null
              *    (soft) this.rejectedResponses != null
              */
   168      if (comment.isApproved()) {
   169        recentComments.add(comment);
   170        approvedResponses.add(comment);
   171      } else if (comment.isPending()) {
   172        pendingResponses.add(comment);
   173      } else if (comment.isRejected()) {
   174        rejectedResponses.add(comment);
   175      }
   176    }
   177  
   178    /**
   179     * Called when a comment has been removed.
   180     *
   181     * @param comment   a Comment instance
   182     */
   183    synchronized void removeRecentComment(Comment comment) {
             /* 
    P/P       *  Method: void removeRecentComment(Comment)
              * 
              *  Preconditions:
              *    this.approvedResponses != null
              *    this.pendingResponses != null
              *    this.recentComments != null
              *    this.rejectedResponses != null
              */
   184      recentComments.remove(comment);
   185      approvedResponses.remove(comment);
   186      pendingResponses.remove(comment);
   187      rejectedResponses.remove(comment);
   188    }
   189  
   190    /**
   191     * Called when a TrackBack has been added.
   192     *
   193     * @param trackBack   a TrackBack instance
   194     */
   195    synchronized void addRecentTrackBack(TrackBack trackBack) {
             /* 
    P/P       *  Method: void addRecentTrackBack(TrackBack)
              * 
              *  Preconditions:
              *    trackBack != null
              *    trackBack.state != null
              *    (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#1).name != null
              *    (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#2).name != null
              *    (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#3).name != null
              *    (soft) this.approvedResponses != null
              *    (soft) this.pendingResponses != null
              *    (soft) this.recentTrackBacks != null
              *    (soft) this.rejectedResponses != null
              *    (soft) init'ed(trackBack.state.name)
              */
   196      if (trackBack.isApproved()) {
   197        recentTrackBacks.add(trackBack);
   198        approvedResponses.add(trackBack);
   199      } else if (trackBack.isPending()) {
   200        pendingResponses.add(trackBack);
   201      } else if (trackBack.isRejected()) {
   202        rejectedResponses.add(trackBack);
   203      }
   204    }
   205  
   206    /**
   207     * Called when a TrackBack has been removed.
   208     *
   209     * @param trackBack   a TrackBack instance
   210     */
   211    synchronized void removeRecentTrackBack(TrackBack trackBack) {
             /* 
    P/P       *  Method: void removeRecentTrackBack(TrackBack)
              * 
              *  Preconditions:
              *    this.approvedResponses != null
              *    this.pendingResponses != null
              *    this.recentTrackBacks != null
              *    this.rejectedResponses != null
              */
   212      recentTrackBacks.remove(trackBack);
   213      approvedResponses.remove(trackBack);
   214      pendingResponses.remove(trackBack);
   215      rejectedResponses.remove(trackBack);
   216    }
   217  
   218    /**
   219     * Called when a comment has been added.
   220     *
   221     * @param event a CommentEvent instance
   222     */
   223    public void commentAdded(CommentEvent event) {
             /* 
    P/P       *  Method: void commentAdded(CommentEvent)
              * 
              *  Preconditions:
              *    event != null
              *    (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#1).name != null
              *    (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#2).name != null
              *    (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#3).name != null
              *    (soft) this.approvedResponses != null
              *    (soft) this.pendingResponses != null
              *    (soft) this.recentComments != null
              *    (soft) this.rejectedResponses != null
              * 
              *  Presumptions:
              *    getComment(...).state@224 != null
              *    net.sourceforge.pebble.api.event.comment.CommentEvent:getSource(...)@72 != null
              */
   224      addRecentComment(event.getComment());
   225    }
   226  
   227    /**
   228     * Called when a comment has been removed.
   229     *
   230     * @param event a CommentEvent instance
   231     */
   232    public void commentRemoved(CommentEvent event) {
             /* 
    P/P       *  Method: void commentRemoved(CommentEvent)
              * 
              *  Preconditions:
              *    event != null
              *    this.approvedResponses != null
              *    this.pendingResponses != null
              *    this.recentComments != null
              *    this.rejectedResponses != null
              */
   233      removeRecentComment(event.getComment());
   234    }
   235  
   236    /**
   237     * Called when a comment has been approved.
   238     *
   239     * @param event a CommentEvent instance
   240     */
   241    public void commentApproved(CommentEvent event) {
             /* 
    P/P       *  Method: void commentApproved(CommentEvent)
              * 
              *  Preconditions:
              *    event != null
              *    this.approvedResponses != null
              *    this.pendingResponses != null
              *    this.recentComments != null
              *    this.rejectedResponses != null
              *    (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#1).name != null
              *    (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#2).name != null
              *    (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#3).name != null
              * 
              *  Presumptions:
              *    getComment(...).state@243 != null
              *    net.sourceforge.pebble.api.event.comment.CommentEvent:getSource(...)@72 != null
              */
   242      removeRecentComment(event.getComment());
   243      addRecentComment(event.getComment());
   244    }
   245  
   246    /**
   247     * Called when a comment has been rejected.
   248     *
   249     * @param event a CommentEvent instance
   250     */
   251    public void commentRejected(CommentEvent event) {
             /* 
    P/P       *  Method: void commentRejected(CommentEvent)
              * 
              *  Preconditions:
              *    event != null
              *    this.approvedResponses != null
              *    this.pendingResponses != null
              *    this.recentComments != null
              *    this.rejectedResponses != null
              *    (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#1).name != null
              *    (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#2).name != null
              *    (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#3).name != null
              * 
              *  Presumptions:
              *    getComment(...).state@253 != null
              *    net.sourceforge.pebble.api.event.comment.CommentEvent:getSource(...)@72 != null
              */
   252      removeRecentComment(event.getComment());
   253      addRecentComment(event.getComment());
   254    }
   255  
   256    /**
   257     * Called when a TrackBack has been added.
   258     *
   259     * @param event a TrackBackEvent instance
   260     */
   261    public void trackBackAdded(TrackBackEvent event) {
             /* 
    P/P       *  Method: void trackBackAdded(TrackBackEvent)
              * 
              *  Preconditions:
              *    event != null
              *    (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#1).name != null
              *    (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#2).name != null
              *    (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#3).name != null
              *    (soft) this.approvedResponses != null
              *    (soft) this.pendingResponses != null
              *    (soft) this.recentTrackBacks != null
              *    (soft) this.rejectedResponses != null
              * 
              *  Presumptions:
              *    getTrackBack(...).state@262 != null
              *    net.sourceforge.pebble.api.event.trackback.TrackBackEvent:getSource(...)@72 != null
              */
   262      addRecentTrackBack(event.getTrackBack());
   263    }
   264  
   265    /**
   266     * Called when a TrackBack has been removed.
   267     *
   268     * @param event a TrackBackEvent instance
   269     */
   270    public void trackBackRemoved(TrackBackEvent event) {
             /* 
    P/P       *  Method: void trackBackRemoved(TrackBackEvent)
              * 
              *  Preconditions:
              *    event != null
              *    this.approvedResponses != null
              *    this.pendingResponses != null
              *    this.recentTrackBacks != null
              *    this.rejectedResponses != null
              */
   271      removeRecentTrackBack(event.getTrackBack());
   272    }
   273  
   274    /**
   275     * Called when a TrackBack has been approved.
   276     *
   277     * @param event a TrackBackEvent instance
   278     */
   279    public void trackBackApproved(TrackBackEvent event) {
             /* 
    P/P       *  Method: void trackBackApproved(TrackBackEvent)
              * 
              *  Preconditions:
              *    event != null
              *    this.approvedResponses != null
              *    this.pendingResponses != null
              *    this.recentTrackBacks != null
              *    this.rejectedResponses != null
              *    (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#1).name != null
              *    (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#2).name != null
              *    (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#3).name != null
              * 
              *  Presumptions:
              *    getTrackBack(...).state@281 != null
              *    net.sourceforge.pebble.api.event.trackback.TrackBackEvent:getSource(...)@72 != null
              */
   280      removeRecentTrackBack(event.getTrackBack());
   281      addRecentTrackBack(event.getTrackBack());
   282    }
   283  
   284    /**
   285     * Called when a TrackBack has been rejected.
   286     *
   287     * @param event a TrackBackEvent instance
   288     */
   289    public void trackBackRejected(TrackBackEvent event) {
             /* 
    P/P       *  Method: void trackBackRejected(TrackBackEvent)
              * 
              *  Preconditions:
              *    event != null
              *    this.approvedResponses != null
              *    this.pendingResponses != null
              *    this.recentTrackBacks != null
              *    this.rejectedResponses != null
              *    (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#1).name != null
              *    (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#2).name != null
              *    (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#3).name != null
              * 
              *  Presumptions:
              *    getTrackBack(...).state@291 != null
              *    net.sourceforge.pebble.api.event.trackback.TrackBackEvent:getSource(...)@72 != null
              */
   290      removeRecentTrackBack(event.getTrackBack());
   291      addRecentTrackBack(event.getTrackBack());
   292    }
   293  
   294    /**
   295     * Gets the number of responses.
   296     */
   297    public int getNumberOfResponses() {
             /* 
    P/P       *  Method: int getNumberOfResponses()
              * 
              *  Preconditions:
              *    this.approvedResponses != null
              *    this.pendingResponses != null
              *    this.rejectedResponses != null
              * 
              *  Presumptions:
              *    java.util.SortedSet:size(...)@298 + java.util.SortedSet:size(...)@298 in -232..6_442_450_943
              *    java.util.SortedSet:size(...)@298 + java.util.SortedSet:size(...)@298 + java.util.SortedSet:size(...)@298 in -231..232-1
              * 
              *  Postconditions:
              *    (soft) init'ed(return_value)
              */
   298      return approvedResponses.size() + pendingResponses.size() + rejectedResponses.size();
   299    }
   300  
   301  }








SofCheck Inspector Build Version : 2.22510
responsemanager.java 2010-Jun-25 19:40:32
responsemanager.class 2010-Jul-19 20:23:40