mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-20 22:18:43 +00:00
add methods: maskAndTruncate; nCopies; nCopiesWithGlue
This commit is contained in:
@ -23,6 +23,7 @@ package com.kingsrook.qqq.backend.core.utils;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@ -475,4 +476,59 @@ public class StringUtils
|
||||
return (s);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public static String maskAndTruncate(String value)
|
||||
{
|
||||
return (maskAndTruncate(value, "** MASKED **", 6, 4));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public static String maskAndTruncate(String value, String mask, int minLengthToMask, int charsToShowOnEnds)
|
||||
{
|
||||
if(!hasContent(value))
|
||||
{
|
||||
return ("");
|
||||
}
|
||||
|
||||
if(value.length() < minLengthToMask || value.length() < 2 * charsToShowOnEnds)
|
||||
{
|
||||
return mask;
|
||||
}
|
||||
|
||||
if(value.length() < charsToShowOnEnds * 3)
|
||||
{
|
||||
return (value.substring(0, charsToShowOnEnds) + mask);
|
||||
}
|
||||
|
||||
return (value.substring(0, charsToShowOnEnds) + mask + value.substring(value.length() - charsToShowOnEnds));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
**
|
||||
***************************************************************************/
|
||||
public static String nCopies(int n, String s)
|
||||
{
|
||||
return (nCopiesWithGlue(n, s, ""));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
**
|
||||
***************************************************************************/
|
||||
public static String nCopiesWithGlue(int n, String s, String glue)
|
||||
{
|
||||
return (StringUtils.join(glue, Collections.nCopies(n, s)));
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user