• 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

80.0
/mutex/src/main/java/com/iluwatar/mutex/Thief.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.mutex;
24

25
/**
26
 * Thief is a class which continually tries to acquire a jar and take a bean
27
 * from it. When the jar is empty the thief stops.
28
 */
29
public class Thief extends Thread {
30

31
  /**
32
   * The name of the thief. 
33
   */
34
  private final String name;
35
  
36
  /**
37
   * The jar
38
   */
39
  private final Jar jar;
40

41
  public Thief(String name, Jar jar) {
1✔
42
    this.name = name;
1✔
43
    this.jar = jar;
1✔
44
  }
1✔
45

46
  /**
47
   * In the run method the thief repeatedly tries to take a bean until none
48
   * are left.
49
   */
50
  @Override
51
  public void run() {
52
    int beans = 0;
1✔
53

54
    while (jar.takeBean()) {
1✔
55
      beans = beans + 1;
1✔
56
      System.out.println(name + " took a bean.");
1✔
57
    }
58

UNCOV
59
    System.out.println(name + " took " + beans + " beans.");
×
UNCOV
60
  }
×
61

62
}
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