• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

iluwatar / java-design-patterns / #1676

07 Jun 2016 07:32PM UTC coverage: 89.415% (-0.2%) from 89.611%
#1676

push

iluwatar
Merge pull request #433 from qza/master

Abstract Document

48 of 48 new or added lines in 8 files covered. (100.0%)

18 existing lines in 4 files now uncovered.

5026 of 5621 relevant lines covered (89.41%)

0.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

38.1
/semaphore/src/main/java/com/iluwatar/semaphore/FruitBowl.java
1
/**
2
 * The MIT License
3
 * Copyright (c) 2014 Ilkka Seppälä
4
 *
5
 * Permission is hereby granted, free of charge, to any person obtaining a copy
6
 * of this software and associated documentation files (the "Software"), to deal
7
 * in the Software without restriction, including without limitation the rights
8
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the Software is
10
 * furnished to do so, subject to the following conditions:
11
 *
12
 * The above copyright notice and this permission notice shall be included in
13
 * all copies or substantial portions of the Software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
 * THE SOFTWARE.
22
 */
23
package com.iluwatar.semaphore;
24

25
import java.util.ArrayList;
26

27
/**
28
 * A FruitBowl contains Fruit. 
29
 */
30
public class FruitBowl {
1✔
31
    
32
  private ArrayList<Fruit> fruit = new ArrayList<>();
1✔
33

34
  /**
35
   * 
36
   * @return The amount of Fruit left in the bowl. 
37
   */
38
  public int countFruit() {
39
    return fruit.size();
1✔
40
  }
41

42
  /**
43
   * Put an item of Fruit into the bowl.
44
   * 
45
   * @param f fruit
46
   */
47
  public void put(Fruit f) {
48
    fruit.add(f);
1✔
49
  }
1✔
50
  
51
  /**
52
   * Take an item of Fruit out of the bowl.
53
   * @return The Fruit taken out of the bowl, or null if empty.
54
   */
55
  public Fruit take() {
56
    if (fruit.isEmpty()) {
1✔
57
      return null;
1✔
58
    } else {
59
      return fruit.remove(0);
1✔
60
    }
61
  }
62
  
63
  /**
64
   * toString method
65
   */   
66
  public String toString() {
UNCOV
67
    int apples = 0;
×
UNCOV
68
    int oranges = 0;
×
UNCOV
69
    int lemons = 0;
×
70
        
UNCOV
71
    for (Fruit f : fruit) {
×
UNCOV
72
      switch (f.getType()) {
×
73
        case APPLE:
UNCOV
74
          apples++;
×
UNCOV
75
          break;
×
76
        case ORANGE:
UNCOV
77
          oranges++;
×
UNCOV
78
          break;
×
79
        case LEMON:
UNCOV
80
          lemons++;
×
UNCOV
81
          break;
×
82
        default:
83
      }
UNCOV
84
    }
×
85
        
UNCOV
86
    return apples + " Apples, " + oranges + " Oranges, and " + lemons + " Lemons";
×
87
  }
88
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc