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
077f7ff2
Commit
077f7ff2
authored
May 19, 2022
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
将源码打包进jar包
parent
0f2649ca
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
24 deletions
+28
-24
StringHelper.java
...c/main/java/com/yanzuoguang/util/helper/StringHelper.java
+28
-24
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/StringHelper.java
View file @
077f7ff2
...
...
@@ -390,57 +390,61 @@ public class StringHelper {
/**
* 根据类型来获取值
*
* @param
cls
类型
* @param
fromCls
类型
* @param from 对象
* @return 返回获取的值
*/
public
static
<
T
>
T
to
(
Class
<
T
>
cls
,
Object
from
)
{
String
vName
=
cls
.
getName
();
public
static
<
T
>
T
to
(
Class
<
T
>
fromCls
,
Object
from
)
{
Object
to
=
null
;
if
(
isType
(
c
ls
,
String
.
class
))
{
if
(
isType
(
fromC
ls
,
String
.
class
))
{
to
=
toString
(
from
);
}
else
if
(
TYPE_BOOL
.
equals
(
vName
)
||
(
isType
(
cls
,
Boolean
.
class
)
&&
from
!=
null
))
{
}
else
if
(
isBaseType
(
TYPE_BOOL
,
Boolean
.
class
,
fromCls
,
from
))
{
String
strValue
=
toString
(
from
);
to
=
toBoolean
(
strValue
);
}
else
if
(
TYPE_INT
.
equals
(
vName
)
||
(
isType
(
cls
,
Integer
.
class
)
&&
from
!=
null
))
{
to
=
toInt
(
from
);
}
else
if
(
TYPE_LONG
.
equals
(
vName
)
||
(
isType
(
cls
,
Long
.
class
)
&&
from
!=
null
))
{
}
else
if
(
isBaseType
(
TYPE_INT
,
Integer
.
class
,
fromCls
,
from
))
{
to
=
toInt
(
from
);
}
else
if
(
TYPE_DOUBLE
.
equals
(
vName
)
||
(
isType
(
cls
,
Double
.
class
)
&&
from
!=
null
))
{
to
=
toDouble
(
from
);
}
else
if
(
TYPE_FLOAT
.
equals
(
vName
)
||
(
isType
(
cls
,
Float
.
class
)
&&
from
!=
null
))
{
}
else
if
(
isBaseType
(
TYPE_LONG
,
Long
.
class
,
fromCls
,
from
))
{
to
=
toLong
(
from
);
}
else
if
(
isBaseType
(
TYPE_DOUBLE
,
Double
.
class
,
fromCls
,
from
))
{
to
=
toDouble
(
from
);
}
else
if
(
isType
(
cls
,
Date
.
class
))
{
}
else
if
(
isBaseType
(
TYPE_FLOAT
,
Float
.
class
,
fromCls
,
from
))
{
to
=
toFloat
(
from
);
}
else
if
(
isType
(
fromCls
,
Date
.
class
))
{
to
=
DateHelper
.
getDateTime
(
from
);
}
else
if
(
c
ls
.
isEnum
())
{
}
else
if
(
fromC
ls
.
isEnum
())
{
String
strValue
=
toString
(
from
);
if
(
strValue
!=
null
)
{
to
=
EnumHelper
.
toEnum
(
c
ls
,
strValue
);
to
=
EnumHelper
.
toEnum
(
fromC
ls
,
strValue
);
}
}
if
(
to
==
null
&&
from
==
null
)
{
return
null
;
}
else
if
(
to
!=
null
)
{
return
(
T
)
to
;
}
else
if
(
c
ls
==
List
.
class
&&
from
instanceof
List
)
{
}
else
if
(
fromC
ls
==
List
.
class
&&
from
instanceof
List
)
{
return
(
T
)
from
;
}
else
if
(
c
ls
==
Map
.
class
&&
from
instanceof
Map
)
{
}
else
if
(
fromC
ls
==
Map
.
class
&&
from
instanceof
Map
)
{
return
(
T
)
from
;
}
else
if
(
c
ls
==
Object
.
class
)
{
}
else
if
(
fromC
ls
==
Object
.
class
)
{
return
(
T
)
from
;
}
else
{
if
(
ObjectHelper
.
isSub
(
c
ls
,
from
.
getClass
()))
{
if
(
ObjectHelper
.
isSub
(
fromC
ls
,
from
.
getClass
()))
{
return
(
T
)
from
;
}
return
(
T
)
to
;
}
}
private
static
boolean
isBaseType
(
String
clsName
,
Class
<?>
cls
,
Class
<?>
fromCls
,
Object
fromValue
)
{
if
(
clsName
.
equals
(
fromCls
.
getName
()))
{
return
true
;
}
if
(
fromValue
==
null
)
{
return
false
;
}
return
isType
(
fromCls
,
cls
);
}
/**
* 将 object 转换为String
*
...
...
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