Skip to content

Commit b46f828

Browse files
committed
add new books
1 parent b27f0e9 commit b46f828

File tree

671 files changed

+30224
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

671 files changed

+30224
-0
lines changed

Java/Effective_Java_2nd_Edition.pdf

2.03 MB
Binary file not shown.

Java/Java 并发编程实战.pdf

8.86 MB
Binary file not shown.

Java/Java编程思想.pdf

2.21 MB
Binary file not shown.

Java/Spring实战 第3版.pdf

30.2 MB
Binary file not shown.
File renamed without changes.
962 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
abstract class Unit {
4+
abstract function bombardStrength();
5+
}
6+
7+
class Archer extends Unit {
8+
function bombardStrength() {
9+
return 4;
10+
}
11+
}
12+
13+
class LaserCannonUnit extends Unit {
14+
function bombardStrength() {
15+
return 44;
16+
}
17+
}
18+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
abstract class Unit {
4+
abstract function bombardStrength();
5+
}
6+
7+
class Archer extends Unit {
8+
function bombardStrength() {
9+
return 4;
10+
}
11+
}
12+
13+
class LaserCannonUnit extends Unit {
14+
function bombardStrength() {
15+
return 44;
16+
}
17+
}
18+
19+
20+
class Army {
21+
private $units = array();
22+
23+
function addUnit( Unit $unit ) {
24+
array_push( $this->units, $unit );
25+
}
26+
27+
function bombardStrength() {
28+
$ret = 0;
29+
foreach( $this->units as $unit ) {
30+
$ret += $unit->bombardStrength();
31+
}
32+
return $ret;
33+
}
34+
}
35+
36+
$unit1 = new Archer();
37+
$unit2 = new LaserCannonUnit();
38+
$army = new Army();
39+
$army->addUnit( $unit1 );
40+
$army->addUnit( $unit2 );
41+
print $army->bombardStrength();
42+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
abstract class Unit {
4+
abstract function bombardStrength();
5+
}
6+
7+
class Archer extends Unit {
8+
function bombardStrength() {
9+
return 4;
10+
}
11+
}
12+
13+
class LaserCannonUnit extends Unit {
14+
function bombardStrength() {
15+
return 44;
16+
}
17+
}
18+
19+
20+
class Army {
21+
private $units = array();
22+
private $armies= array();
23+
24+
function addUnit( Unit $unit ) {
25+
array_push( $this->units, $unit );
26+
}
27+
28+
function addArmy( Army $army ) {
29+
array_push( $this->armies, $army );
30+
}
31+
32+
function bombardStrength() {
33+
$ret = 0;
34+
foreach( $this->units as $unit ) {
35+
$ret += $unit->bombardStrength();
36+
}
37+
38+
foreach( $this->armies as $army ) {
39+
$ret += $army->bombardStrength();
40+
}
41+
42+
return $ret;
43+
}
44+
}
45+
46+
$unit1 = new Archer();
47+
$unit2 = new LaserCannonUnit();
48+
$army = new Army();
49+
$army->addUnit( $unit1 );
50+
$army->addUnit( $unit2 );
51+
print $army->bombardStrength();
52+
print "\n";
53+
$army2 = clone $army;
54+
$army->addArmy( $army2 );
55+
print $army->bombardStrength();
56+
print "\n";
57+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
abstract class Unit {
3+
abstract function addUnit( Unit $unit );
4+
abstract function removeUnit( Unit $unit );
5+
abstract function bombardStrength();
6+
}
7+
class Army extends Unit {
8+
private $units = array();
9+
10+
function addUnit( Unit $unit ) {
11+
if ( in_array( $unit, $this->units, true ) ) {
12+
return;
13+
}
14+
15+
$this->units[] = $unit;
16+
}
17+
18+
function removeUnit( Unit $unit ) {
19+
// >= php 5.3
20+
//$this->units = array_udiff( $this->units, array( $unit ),
21+
// function( $a, $b ) { return ($a === $b)?0:1; } );
22+
23+
// < php 5.3
24+
$this->units = array_udiff( $this->units, array( $unit ),
25+
create_function( '$a,$b', 'return ($a === $b)?0:1;' ) );
26+
}
27+
28+
function bombardStrength() {
29+
$ret = 0;
30+
foreach( $this->units as $unit ) {
31+
$ret += $unit->bombardStrength();
32+
}
33+
return $ret;
34+
}
35+
}
36+
37+
// quick example classes
38+
class Tank extends Unit {
39+
function addUnit( Unit $unit ) {}
40+
function removeUnit( Unit $unit ) {}
41+
42+
function bombardStrength() {
43+
return 4;
44+
}
45+
}
46+
47+
class Soldier extends Unit {
48+
function addUnit( Unit $unit ) {}
49+
function removeUnit( Unit $unit ) {}
50+
51+
function bombardStrength() {
52+
return 8;
53+
}
54+
}
55+
56+
$tank = new Tank();
57+
$tank2 = new Tank();
58+
$soldier = new Soldier();
59+
60+
$army = new Army();
61+
$army->addUnit( $soldier );
62+
$army->addUnit( $tank );
63+
$army->addUnit( $tank2 );
64+
65+
print_r( $army );
66+
67+
$army->removeUnit( $tank2 );
68+
69+
print_r( $army );
70+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
abstract class Unit {
3+
abstract function addUnit( Unit $unit );
4+
abstract function removeUnit( Unit $unit );
5+
abstract function bombardStrength();
6+
}
7+
8+
class Army extends Unit {
9+
private $units = array();
10+
11+
function addUnit( Unit $unit ) {
12+
if ( in_array( $unit, $this->units, true ) ) {
13+
return;
14+
}
15+
16+
$this->units[] = $unit;
17+
}
18+
19+
function removeUnit( Unit $unit ) {
20+
// >= php 5.3
21+
//$this->units = array_udiff( $this->units, array( $unit ),
22+
// function( $a, $b ) { return ($a === $b)?0:1; } );
23+
24+
// < php 5.3
25+
$this->units = array_udiff( $this->units, array( $unit ),
26+
create_function( '$a,$b', 'return ($a === $b)?0:1;' ) );
27+
}
28+
29+
function bombardStrength() {
30+
$ret = 0;
31+
foreach( $this->units as $unit ) {
32+
$ret += $unit->bombardStrength();
33+
}
34+
return $ret;
35+
}
36+
}
37+
38+
class UnitException extends Exception {}
39+
40+
class Archer extends Unit {
41+
function addUnit( Unit $unit ) {
42+
throw new UnitException( get_class($this)." is a leaf" );
43+
}
44+
45+
function removeUnit( Unit $unit ) {
46+
throw new UnitException( get_class($this)." is a leaf" );
47+
}
48+
49+
function bombardStrength() {
50+
return 4;
51+
}
52+
}
53+
54+
$archer = new Archer();
55+
$archer2 = new Archer();
56+
$archer->addUnit( $archer2 );
57+
58+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
class UnitException extends Exception {}
4+
5+
abstract class Unit {
6+
abstract function bombardStrength();
7+
8+
function addUnit( Unit $unit ) {
9+
throw new UnitException( get_class($this)." is a leaf" );
10+
}
11+
12+
function removeUnit( Unit $unit ) {
13+
throw new UnitException( get_class($this)." is a leaf" );
14+
}
15+
}
16+
17+
class Archer extends Unit {
18+
function bombardStrength() {
19+
return 4;
20+
}
21+
}
22+
23+
class LaserCannonUnit extends Unit {
24+
function bombardStrength() {
25+
return 44;
26+
}
27+
}
28+
29+
class Army extends Unit {
30+
private $units = array();
31+
32+
function addUnit( Unit $unit ) {
33+
if ( in_array( $unit, $this->units, true ) ) {
34+
return;
35+
}
36+
37+
$this->units[] = $unit;
38+
}
39+
40+
function removeUnit( Unit $unit ) {
41+
// >= php 5.3
42+
//$this->units = array_udiff( $this->units, array( $unit ),
43+
// function( $a, $b ) { return ($a === $b)?0:1; } );
44+
45+
// < php 5.3
46+
$this->units = array_udiff( $this->units, array( $unit ),
47+
create_function( '$a,$b', 'return ($a === $b)?0:1;' ) );
48+
}
49+
50+
function bombardStrength() {
51+
$ret = 0;
52+
foreach( $this->units as $unit ) {
53+
$ret += $unit->bombardStrength();
54+
}
55+
return $ret;
56+
}
57+
}
58+
59+
// create an army
60+
$main_army = new Army();
61+
62+
// add some units
63+
$main_army->addUnit( new Archer() );
64+
$main_army->addUnit( new LaserCannonUnit() );
65+
66+
// create a new army
67+
$sub_army = new Army();
68+
69+
// add some units
70+
$sub_army->addUnit( new Archer() );
71+
$sub_army->addUnit( new Archer() );
72+
$sub_army->addUnit( new Archer() );
73+
74+
// add the second army to the first
75+
$main_army->addUnit( $sub_army );
76+
77+
// all the calculations handled behind the scenes
78+
print "attacking with strength: {$main_army->bombardStrength()}\n";
79+
?>

0 commit comments

Comments
 (0)