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

iluwatar / java-design-patterns / #1675

07 Jun 2016 07:32PM UTC coverage: 89.15% (-0.5%) from 89.611%
#1675

push

iluwatar
Merge pull request #433 from qza/master

Abstract Document

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

14 existing lines in 4 files now uncovered.

5053 of 5668 relevant lines covered (89.15%)

0.89 hits per line

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

85.71
/semaphore/src/main/java/com/iluwatar/semaphore/Customer.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
/**
26
 * A Customer attempts to repeatedly take Fruit from the FruitShop by
27
 * taking Fruit from FruitBowl instances.
28
 */
29
public class Customer extends Thread {
30

31
  /**
32
   * Name of the Customer.
33
   */
34
  private final String name;
35
  
36
  /**
37
   * The FruitShop he is using.
38
   */
39
  private final FruitShop fruitShop;
40
  
41
  /**
42
   * Their bowl of Fruit.
43
   */
44
  private final FruitBowl fruitBowl;
45
  
46
  /**
47
   * Customer constructor
48
   */
49
  public Customer(String name, FruitShop fruitShop) {
1✔
50
    this.name = name;
1✔
51
    this.fruitShop = fruitShop;
1✔
52
    this.fruitBowl = new FruitBowl();
1✔
53
  }
1✔
54
  
55
  /**
56
   * The Customer repeatedly takes Fruit from the FruitShop until no Fruit
57
   * remains.
58
   */   
59
  public void run() {
60
        
61
    while (fruitShop.countFruit() > 0) {
1✔
62
      FruitBowl bowl = fruitShop.takeBowl();
1✔
63
      Fruit fruit;
64
            
65
      if (bowl != null && (fruit = bowl.take()) != null) {
1✔
66
        System.out.println(name + " took an " + fruit);
1✔
67
        fruitBowl.put(fruit);
1✔
68
        fruitShop.returnBowl(bowl);
1✔
69
      }
70
    }
1✔
71
        
UNCOV
72
    System.out.println(name + " took " + fruitBowl);
×
73
        
UNCOV
74
  }
×
75
    
76
}
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