Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
10bb5ea5
Commit
10bb5ea5
authored
Apr 12, 2023
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
表结构修改
parent
73fde779
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
4 deletions
+56
-4
StringHelper.java
...c/main/java/com/yanzuoguang/util/helper/StringHelper.java
+24
-4
TestGetFirst.java
yzg-util-base/src/test/java/helper/TestGetFirst.java
+32
-0
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/StringHelper.java
View file @
10bb5ea5
...
...
@@ -147,6 +147,19 @@ public class StringHelper {
* @return 返回值
*/
public
static
<
T
>
T
getFirstRun
(
T
expandValue
,
T
defReturn
,
T
...
froms
)
{
return
getFirstRunList
(
Collections
.
singletonList
(
expandValue
),
defReturn
,
froms
);
}
/**
* 传入很多值,返回第一个不等于排除值、空值的值,当全部为排除值时,返回默认值
*
* @param expandValues 排除值
* @param defReturn 默认返回值
* @param froms 其他值
* @param <T> 数据类型
* @return 返回值
*/
public
static
<
T
>
T
getFirstRunList
(
List
<
T
>
expandValues
,
T
defReturn
,
T
...
froms
)
{
if
(
froms
==
null
)
{
return
defReturn
;
}
...
...
@@ -154,10 +167,17 @@ public class StringHelper {
if
(
from
==
null
||
isEmpty
(
from
))
{
continue
;
}
if
(
expandValue
==
null
)
{
if
(
expandValue
s
==
null
||
expandValues
.
isEmpty
()
)
{
return
from
;
}
if
(
expandValue
==
from
||
expandValue
.
equals
(
from
))
{
boolean
isExpand
=
false
;
for
(
T
expandValue
:
expandValues
)
{
if
(
expandValue
==
from
||
expandValue
.
equals
(
from
))
{
isExpand
=
true
;
break
;
}
}
if
(
isExpand
)
{
continue
;
}
return
from
;
...
...
@@ -202,7 +222,7 @@ public class StringHelper {
* @return 第一个非0值
*/
public
static
Double
getFirst
(
Double
...
froms
)
{
return
getFirstRun
(
0.0
,
0.0
,
froms
);
return
getFirstRun
List
(
Arrays
.
asList
(
0
D
,
-
0
D
),
0
D
,
froms
);
}
/**
...
...
@@ -212,7 +232,7 @@ public class StringHelper {
* @return 第一个非0值
*/
public
static
Float
getFirst
(
Float
...
froms
)
{
return
getFirstRun
(
0.0f
,
0.0f
,
froms
);
return
getFirstRun
List
(
Arrays
.
asList
(
0
F
,
-
0
F
),
0
F
,
froms
);
}
/**
...
...
yzg-util-base/src/test/java/helper/TestGetFirst.java
0 → 100644
View file @
10bb5ea5
package
helper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
org.junit.Test
;
public
class
TestGetFirst
{
@Test
public
void
testDouble
()
{
Double
statementMoney
=
-
0
D
;
Double
zero
=
0
D
;
Double
first
=
StringHelper
.
getFirst
(
statementMoney
);
Double
zeroTo
=
StringHelper
.
getFirst
(
zero
);
System
.
out
.
println
(
first
.
equals
(
zeroTo
));
}
@Test
public
void
testFloat
()
{
Float
statementMoney
=
-
0
f
;
Float
zero
=
0
f
;
Float
first
=
StringHelper
.
getFirst
(
statementMoney
);
Float
zeroTo
=
StringHelper
.
getFirst
(
zero
);
System
.
out
.
println
(
first
.
equals
(
zeroTo
));
}
@Test
public
void
testInt
()
{
Integer
statementMoney
=
-
0
;
Integer
zero
=
0
;
Integer
first
=
StringHelper
.
getFirst
(
statementMoney
);
Integer
zeroTo
=
StringHelper
.
getFirst
(
zero
);
System
.
out
.
println
(
first
.
equals
(
zeroTo
));
}
}
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