| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| SfComments | 
 | 
 | 1.1428571428571428;1.143 | ||||
| SfComments$1 | 
 | 
 | 1.1428571428571428;1.143 | ||||
| SfComments$AjcClosure1 | 
 | 
 | 1.1428571428571428;1.143 | ||||
| SfComments$AjcClosure3 | 
 | 
 | 1.1428571428571428;1.143 | ||||
| SfComments$AjcClosure5 | 
 | 
 | 1.1428571428571428;1.143 | ||||
| SfComments$AjcClosure7 | 
 | 
 | 1.1428571428571428;1.143 | 
| 1 | 0 |  /** | 
| 2 |   * Copyright (c) 2013-2017, jcabi.com | |
| 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 | |
| 7 |   * are met: 1) Redistributions of source code must retain the above | |
| 8 |   * copyright notice, this list of conditions and the following | |
| 9 |   * disclaimer. 2) Redistributions in binary form must reproduce the above | |
| 10 |   * copyright notice, this list of conditions and the following | |
| 11 |   * disclaimer in the documentation and/or other materials provided | |
| 12 |   * with the distribution. 3) Neither the name of the jcabi.com nor | |
| 13 |   * the names of its contributors may be used to endorse or promote | |
| 14 |   * products derived from this software without specific prior written | |
| 15 |   * permission. | |
| 16 |   * | |
| 17 |   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 18 |   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT | |
| 19 |   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
| 20 |   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | |
| 21 |   * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |
| 22 |   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
| 23 |   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
| 24 |   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
| 25 |   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
| 26 |   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 27 |   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | |
| 28 |   * OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 |   */ | |
| 30 |  package com.jcabi.github.safe; | |
| 31 | ||
| 32 |  import com.google.common.base.Function; | |
| 33 |  import com.google.common.collect.Iterables; | |
| 34 |  import com.jcabi.aspects.Immutable; | |
| 35 |  import com.jcabi.aspects.Loggable; | |
| 36 |  import com.jcabi.github.Comment; | |
| 37 |  import com.jcabi.github.Comments; | |
| 38 |  import com.jcabi.github.Issue; | |
| 39 |  import com.jcabi.github.mock.MkGithub; | |
| 40 |  import com.jcabi.log.Logger; | |
| 41 |  import java.io.IOException; | |
| 42 |  import java.util.Date; | |
| 43 |  import lombok.EqualsAndHashCode; | |
| 44 | ||
| 45 |  /** | |
| 46 |   * Safe comments. | |
| 47 |   * | |
| 48 |   * @author Yegor Bugayenko (yegor@tpc2.com) | |
| 49 |   * @version $Id: 6d6ecc8ac964f166a215d8a3ea0d188e0d9222e4 $ | |
| 50 |   * @since 0.34 | |
| 51 |   */ | |
| 52 | @Immutable | |
| 53 | @Loggable(Loggable.DEBUG) | |
| 54 | 0 |  @EqualsAndHashCode(of = "origin") | 
| 55 | public final class SfComments implements Comments { | |
| 56 | ||
| 57 |      /** | |
| 58 |       * Original comments. | |
| 59 |       */ | |
| 60 | private final transient Comments origin; | |
| 61 | ||
| 62 |      /** | |
| 63 |       * Public ctor. | |
| 64 |       * @param cmt The original comment | |
| 65 |       */ | |
| 66 | 0 |      public SfComments(final Comments cmt) { | 
| 67 | 0 |          this.origin = cmt; | 
| 68 | 0 |      } | 
| 69 | ||
| 70 | @Override | |
| 71 |      public String toString() { | |
| 72 | 0 |          return this.origin.toString(); | 
| 73 | } | |
| 74 | ||
| 75 | @Override | |
| 76 |      public Issue issue() { | |
| 77 | 0 |          return this.origin.issue(); | 
| 78 | } | |
| 79 | ||
| 80 | @Override | |
| 81 | public Comment get(final int number) { | |
| 82 | 0 |          return new SfComment(this.origin.get(number)); | 
| 83 | } | |
| 84 | ||
| 85 | @Override | |
| 86 | public Iterable<Comment> iterate(final Date since) { | |
| 87 | 0 |          return Iterables.transform( | 
| 88 | 0 |              this.origin.iterate(since), | 
| 89 | 0 |              new Function<Comment, Comment>() { | 
| 90 | @Override | |
| 91 | public Comment apply(final Comment input) { | |
| 92 | 0 |                      return new SfComment(input); | 
| 93 | } | |
| 94 | } | |
| 95 | ); | |
| 96 | } | |
| 97 | ||
| 98 | @Override | |
| 99 | public Comment post(final String text) throws IOException { | |
| 100 | Comment cmt; | |
| 101 |          try { | |
| 102 | 0 |              cmt = this.origin.post(text); | 
| 103 | 0 |          } catch (final AssertionError ex) { | 
| 104 | 0 |              Logger.warn(this, "Failed to post to GitHub: %[exception]s", ex); | 
| 105 | 0 |              cmt = new MkGithub().randomRepo() | 
| 106 | 0 |                  .issues().create("", "") | 
| 107 | 0 |                  .comments().post(text); | 
| 108 | 0 |          } | 
| 109 | 0 |          return cmt; | 
| 110 | } | |
| 111 | } |