Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Z
ZHHT-IRN-BD-ANALYSIS
Project
Overview
Details
Activity
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
李凯旋
ZHHT-IRN-BD-ANALYSIS
Commits
7515cd31
Commit
7515cd31
authored
Oct 31, 2022
by
吴延飞
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加字符串工具类
parent
83f2e7cd
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
181 additions
and
24 deletions
+181
-24
DateUtils.java
...streaming/src/main/java/com/zhht/irn/utils/DateUtils.java
+1
-24
StringUtils.java
...reaming/src/main/java/com/zhht/irn/utils/StringUtils.java
+180
-0
No files found.
realtime/hologram-streaming/src/main/java/com/zhht/irn/utils/DateUtils.java
View file @
7515cd31
package
com
.
zhht
.
irn
.
utils
package
com
.
zhht
.
irn
.
utils
;
import
com.alibaba.fastjson.JSONObject
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.client.RestTemplate
;
import
java.sql.Timestamp
;
import
java.sql.Timestamp
;
import
java.text.ParseException
;
import
java.text.ParseException
;
...
@@ -26,23 +20,6 @@ public class DateUtils {
...
@@ -26,23 +20,6 @@ public class DateUtils {
public
static
final
SimpleDateFormat
DATEKEY_FORMAT
=
public
static
final
SimpleDateFormat
DATEKEY_FORMAT
=
new
SimpleDateFormat
(
"yyyyMMdd"
);
new
SimpleDateFormat
(
"yyyyMMdd"
);
public
static
void
main
(
String
[]
args
)
throws
ParseException
{
RestTemplate
restTemplate
=
new
RestTemplate
();
// restTemplate.setRequestFactory(new HttpComponentsClientRestfulHttpRequestFactory());
String
url
=
"http://bd3.bcht:8088/ws/v1/cluster/apps/application_1605682285641_9999"
;
try
{
ResponseEntity
<
String
>
responseEntity
=
restTemplate
.
exchange
(
url
,
HttpMethod
.
GET
,
null
,
String
.
class
);
String
body
=
responseEntity
.
getBody
();
JSONObject
js
=
JSONObject
.
parseObject
(
body
);
Object
app
=
js
.
get
(
"app"
);
System
.
out
.
println
(
body
);
}
catch
(
Exception
e
){
System
.
out
.
println
(
"==========="
);
}
}
public
static
Map
getKylinTime
(
String
h
,
int
n
){
public
static
Map
getKylinTime
(
String
h
,
int
n
){
String
currentDateTime
=
DateUtils
.
getCurrentDateTime
(
"yyyy-MM-dd"
);
String
currentDateTime
=
DateUtils
.
getCurrentDateTime
(
"yyyy-MM-dd"
);
Date
date
=
DateUtils
.
stringToDate
(
currentDateTime
,
"yyyy-MM-dd"
);
Date
date
=
DateUtils
.
stringToDate
(
currentDateTime
,
"yyyy-MM-dd"
);
...
...
realtime/hologram-streaming/src/main/java/com/zhht/irn/utils/StringUtils.java
0 → 100644
View file @
7515cd31
package
com
.
zhht
.
irn
.
utils
;
import
java.util.HashMap
;
import
java.util.Map
;
public
class
StringUtils
{
/**
* 判断字符串是否为空
* @param str 字符串
* @return 是否为空
*/
public
static
boolean
isEmpty
(
String
str
)
{
return
str
==
null
||
""
.
equals
(
str
);
}
/**
* 判断字符串是否不为空
* @param str 字符串
* @return 是否不为空
*/
public
static
boolean
isNotEmpty
(
String
str
)
{
return
str
!=
null
&&
!
""
.
equals
(
str
);
}
/**
* 截断字符串两侧的逗号
* @param str 字符串
* @return 字符串
*/
public
static
String
trimComma
(
String
str
)
{
if
(
str
.
startsWith
(
","
))
{
str
=
str
.
substring
(
1
);
}
if
(
str
.
endsWith
(
","
))
{
str
=
str
.
substring
(
0
,
str
.
length
()
-
1
);
}
return
str
;
}
/**
* 补全两位数字
* @param str
* @return
*/
public
static
String
fulfuill
(
String
str
)
{
if
(
str
.
length
()
==
1
)
return
"0"
+
str
;
return
str
;
}
/**
* 补全num位数字
* @param str
* @return
*/
public
static
String
fulfuill
(
int
num
,
String
str
)
{
if
(
str
.
length
()
==
num
)
{
return
str
;
}
else
{
int
fulNum
=
num
-
str
.
length
();
String
tmpStr
=
""
;
for
(
int
i
=
0
;
i
<
fulNum
;
i
++){
tmpStr
+=
"0"
;
}
return
tmpStr
+
str
;
}
}
/**
* 从拼接的字符串中提取字段
* @param str 字符串
* @param delimiter 分隔符
* @param field 字段
* @return 字段值
* name=zhangsan|age=18
*/
public
static
String
getFieldFromConcatString
(
String
str
,
String
delimiter
,
String
field
)
{
try
{
String
[]
fields
=
str
.
split
(
delimiter
);
for
(
String
concatField
:
fields
)
{
// searchKeywords=|clickCategoryIds=1,2,3
if
(
concatField
.
split
(
"="
).
length
==
2
)
{
String
fieldName
=
concatField
.
split
(
"="
)[
0
];
String
fieldValue
=
concatField
.
split
(
"="
)[
1
];
if
(
fieldName
.
equals
(
field
))
{
return
fieldValue
;
}
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
setFieldInConcatString
(
"name=xuruyun,age=55"
,
","
,
"name"
,
"bochen"
));
}
/**
* 从拼接的字符串中给字段设置值
* @param str 字符串
* @param delimiter 分隔符
* @param field 字段名
* @param newFieldValue 新的field值
* @return 字段值
* name=zhangsan123
* age=18
* name=zhangsan|age=18
*/
public
static
String
setFieldInConcatString
(
String
str
,
String
delimiter
,
String
field
,
String
newFieldValue
)
{
// searchKeywords=iphone7|clickCategoryIds=1,2,3
String
[]
fields
=
str
.
split
(
delimiter
);
for
(
int
i
=
0
;
i
<
fields
.
length
;
i
++)
{
String
fieldName
=
fields
[
i
].
split
(
"="
)[
0
];
if
(
fieldName
.
equals
(
field
))
{
String
concatField
=
fieldName
+
"="
+
newFieldValue
;
fields
[
i
]
=
concatField
;
break
;
}
}
StringBuffer
buffer
=
new
StringBuffer
(
""
);
for
(
int
i
=
0
;
i
<
fields
.
length
;
i
++)
{
buffer
.
append
(
fields
[
i
]);
if
(
i
<
fields
.
length
-
1
)
{
buffer
.
append
(
"|"
);
}
}
return
buffer
.
toString
();
}
/**
* age=19
* name=jack
* @param str
* @param delimiter
* name=zhangsan|age=18
* @return
*
*/
public
static
Map
<
String
,
String
>
getKeyValuesFromConcatString
(
String
str
,
String
delimiter
)
{
Map
<
String
,
String
>
map
=
new
HashMap
<>
();
try
{
String
[]
fields
=
str
.
split
(
delimiter
);
for
(
String
concatField
:
fields
)
{
// searchKeywords=|clickCategoryIds=1,2,3
if
(
concatField
.
split
(
"="
).
length
==
2
)
{
String
fieldName
=
concatField
.
split
(
"="
)[
0
];
String
fieldValue
=
concatField
.
split
(
"="
)[
1
];
map
.
put
(
fieldName
,
fieldValue
);
}
}
return
map
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
public
static
Integer
convertStringtoInt
(
String
str
)
{
try
{
return
Integer
.
parseInt
(
str
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
}
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