Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
sz-test
java-demo
Commits
195dc221
Commit
195dc221
authored
Mar 05, 2024
by
sz-test
Browse files
Merge branch 'init' into 'main'
init See merge request
!1
parents
ac7cbb43
7f583445
Changes
27
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
161 additions
and
0 deletions
+161
-0
src/main/java/factory/static1/StaticFactory.java
src/main/java/factory/static1/StaticFactory.java
+24
-0
src/main/java/strategy/CustomAuthenticator.java
src/main/java/strategy/CustomAuthenticator.java
+28
-0
src/main/java/strategy/IStrategy.java
src/main/java/strategy/IStrategy.java
+12
-0
src/main/java/strategy/LocalStrategy.java
src/main/java/strategy/LocalStrategy.java
+17
-0
src/main/java/strategy/StrategyDesign.java
src/main/java/strategy/StrategyDesign.java
+20
-0
src/main/java/strategy/WechatStrategy.java
src/main/java/strategy/WechatStrategy.java
+17
-0
src/main/java/tool/StrUtils.java
src/main/java/tool/StrUtils.java
+43
-0
No files found.
src/main/java/factory/static1/StaticFactory.java
0 → 100644
View file @
195dc221
package
factory.static1
;
import
factory.BMW
;
/**
* Copyright (c) 2021, ustchcs and its affiliates. All rights reserved. More info see www.ustchcs.com
*
* @author cch
* @package Thymeleaf1 com.example.demo.design
* @node
*/
public
class
StaticFactory
{
public
static
void
main
(
String
[]
args
)
{
BMW
car730
=
BMWFactory
.
productBMW
(
"730"
);
BMW
car840
=
BMWFactory
.
productBMW
(
"840"
);
if
(
car730
!=
null
)
{
car730
.
run
();
}
if
(
car840
!=
null
)
{
car840
.
run
();
}
}
}
src/main/java/strategy/CustomAuthenticator.java
0 → 100644
View file @
195dc221
package
strategy
;
/**
* Copyright (c) 2023, ustchcs and its affiliates. All rights reserved. More info see www.ustchcs.com
*
* @author cch
* @package java-test strategy
* @node
*/
public
class
CustomAuthenticator
{
private
IStrategy
strategy
;
public
CustomAuthenticator
(
IStrategy
strategyInput
)
{
this
.
strategy
=
strategyInput
;
}
public
void
authenticate
(
String
name
,
String
password
)
{
if
(
this
.
strategy
==
null
)
{
System
.
out
.
println
(
"no strategy"
);
return
;
}
this
.
strategy
.
authenticate
(
name
,
password
);
}
public
void
setStrategy
(
IStrategy
strategy
)
{
this
.
strategy
=
strategy
;
}
}
src/main/java/strategy/IStrategy.java
0 → 100644
View file @
195dc221
package
strategy
;
/**
* Copyright (c) 2023, ustchcs and its affiliates. All rights reserved. More info see www.ustchcs.com
*
* @author cch
* @package java-test strategy
* @node
*/
public
interface
IStrategy
{
void
authenticate
(
String
name
,
String
password
);
}
src/main/java/strategy/LocalStrategy.java
0 → 100644
View file @
195dc221
package
strategy
;
import
tool.StrUtils
;
/**
* Copyright (c) 2023, ustchcs and its affiliates. All rights reserved. More info see www.ustchcs.com
*
* @author cch
* @package java-test strategy
* @node
*/
public
class
LocalStrategy
implements
IStrategy
{
@Override
public
void
authenticate
(
String
name
,
String
password
)
{
System
.
out
.
println
(
StrUtils
.
concatNullToEmpty
(
"local login:name="
,
name
));
}
}
src/main/java/strategy/StrategyDesign.java
0 → 100644
View file @
195dc221
package
strategy
;
/**
* Copyright (c) 2021, ustchcs and its affiliates. All rights reserved. More info see www.ustchcs.com
*
* @author cch
* @package Thymeleaf1 com.example.demo.design.strategy
* @node
*/
public
class
StrategyDesign
{
public
static
void
main
(
String
[]
args
)
{
WechatStrategy
wechatStrategy
=
new
WechatStrategy
();
CustomAuthenticator
customAuthenticator
=
new
CustomAuthenticator
(
wechatStrategy
);
customAuthenticator
.
authenticate
(
"cch"
,
"1234556"
);
customAuthenticator
.
setStrategy
(
new
LocalStrategy
());
customAuthenticator
.
authenticate
(
"cch2"
,
"12345567"
);
}
}
src/main/java/strategy/WechatStrategy.java
0 → 100644
View file @
195dc221
package
strategy
;
import
tool.StrUtils
;
/**
* Copyright (c) 2023, ustchcs and its affiliates. All rights reserved. More info see www.ustchcs.com
*
* @author cch
* @package java-test strategy
* @node
*/
public
class
WechatStrategy
implements
IStrategy
{
@Override
public
void
authenticate
(
String
name
,
String
password
)
{
System
.
out
.
println
(
StrUtils
.
concatNullToEmpty
(
"wechat login:name="
,
name
));
}
}
src/main/java/tool/StrUtils.java
0 → 100644
View file @
195dc221
package
tool
;
/**
* Copyright (c) 2023, ustchcs and its affiliates. All rights reserved. More
* info see www.ustchcs.com
*
* @author cch
* @package backend com.ustchcs.qualityhub.system.utils
* @node
*/
public
class
StrUtils
{
public
static
final
String
EMPTY
=
""
;
public
static
String
concatNullToEmpty
(
CharSequence
...
strs
)
{
return
concat
(
true
,
strs
);
}
public
static
String
concat
(
boolean
isNullToEmpty
,
CharSequence
...
strs
)
{
final
StringBuilder
sb
=
new
StringBuilder
();
for
(
CharSequence
str
:
strs
)
{
if
(
isNullToEmpty
)
{
sb
.
append
(
nullToEmpty
(
str
));
}
else
{
sb
.
append
(
str
);
}
}
return
sb
.
toString
();
}
public
static
String
nullToEmpty
(
CharSequence
str
)
{
return
nullToDefault
(
str
,
EMPTY
);
}
public
static
String
nullToDefault
(
CharSequence
str
,
String
defaultStr
)
{
if
(
str
==
null
)
{
return
defaultStr
;
}
return
str
.
toString
();
}
}
Prev
1
2
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment