A Java common utility library that simplifies the operation of other libraries by encapsulating its original functionality.
Dependency this library in Maven Project
-
Add the JitPack repository to your build file
<repositories> <repository> <id>jitpack.io</id> <url>https://jitpack.io</url> </repository> </repositories>
-
Add the dependency
Using release tag
<dependency> <groupId>com.github.taogen-lib.taogen-commons</groupId> <artifactId>commons-lang</artifactId> <version>Tag</version> </dependency>
Or using a short commit hash on JitPack
<dependency> <groupId>com.github.taogen-lib.taogen-commons</groupId> <artifactId>commons-lang</artifactId> <version>{short_commit_hash_on_jitpack}</version> </dependency>
Or using the latest version (After you push a new commit. Other projects need to force checking update
mvn clean install -Uand reload maven project)<dependency> <groupId>com.github.taogen-lib.taogen-commons</groupId> <artifactId>commons-lang</artifactId> <version>-SNAPSHOT</version> </dependency>
Or using the local Maven repository
<dependency>
<groupId>com.taogen</groupId>
<artifactId>commons-lang</artifactId>
<version>{some_version}</version>
</dependency># test all modules
mvn clean test
# test a specific module
mvn clean test -pl submodule# Install all modules to local repository. So other projects can refer to it and grab it from your local repository.
mvn clean install
# Install a specific module
mvn clean install -pl submoduleIf you are always expecting to find a value then throw the exception if it is missing. The exception would mean that there was a problem.
If the value can be missing or present and both are valid for the application logic then return a null.
More important: What do you do other places in the code? Consistency is important.
- Java util class basic
- Java lib
- StringUtils
- EncodingUtils
- NumberUtils
- RandomUtils
- DateUtils
- TimeUtils
- EncryptUtils
- Md5Utils
- File I/O
- LocationUtils (LngAndLatUtils)
- Javax lib
- Third lib
- Others
- Java lib
Defining methods of utility --> writing fake implement class --> writing test class --> writing real implement class and pass its test.
- Illegal parameters
- bound value + middle value
- Cover all DD-paths
assertAll(...)
assertEquals(...)
assertNotEquals(...)
assertArrayEquals(...)
assertTrue(...)
assertFalse(...)
assertNull(...)
assertNotNull(...)
assertSame(...)
assertNotSame(...)
assertIterableEquals(...)
assertLinesMatch(...)
assertThrows(...)
assertTimeout(...)
assertTimeoutPreemptively(...)
fail(...)Dependencies:
import java.lang.reflect.InvocationTargetException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Methods
Convert
int str2Int (String str, int default)
long str2Long(String str, long default)
double str2Double(String str, double default)
boolean Str2Boolean(String str, boolean default)Verify
boolean isEmpty(String str)
boolean isEmail(String email)
boolean isMobile(String mobile)
boolean isMatch(String str, String regex)Handle
String encodeMobile(String mobile)
String encodeEmail(String email)
String encodeBankCard(String bankcard)
String jointString (String... strs)
String toNotNull (String str)
String expandLength(String str, int len, char fillChar)Dependencies
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Methods
Verify
boolean isChinese(String str)
boolean isEmoji(String str)Convert
String iso2Utf8(String str)
String emojiConvert(String str)
String emojiRecovery(String str)Dependencies
Methods
Dependencies
import java.util.Random;
Methods
int getRandomNumber(int bound)
String getRandomNumberStr(int length)
String getMixedRandomStr(int length)Dependencies
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;Methods
Convert
//int <--> String <--> Date
String getDateFormatStr(Date date, DateFormat format)
Date getDateByStr (String dateStr, DateFormat format)
String convertDateStr(String dateStr, DateFormat fromFormat, DateFormat toFormat)Calculate
int getField(Date date, int calendarField)
Date add(Date date, int calendarField, int addtion)
long getDiffDays(Date firstDate, Date secondDate)
List<String> getBetweenDates(Date startDate, Date endDate, DateFormat formatter)
List<String> getBetweenMonths(Date startDate, Date endDate, DateFormat formatter)
Date getFirstDayOfWeek(Date date)
Date getFirstDayOfMonth(Date date)
Date getLastDayOfMonth(Date date)
Date getLastDayOfWeek(Date date)
int getWeekOfMonth(Date date)
int getWeekOfYear(Date date)Dependencies
Methods
Timestamp getCurrentTime()
int getHourDiff (long startTime, long endTime)
String getTimeZone()Dependencies
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
Methods
String encryptBASE64 (String source)
String decryptBASE64 (String str)
String generateSalt()Dependencies
Methods
Dependencies
import java.io.InputStream;
import java.util.Properties;
Methods
void load(String filePath)
String getString (String key)
int getInt (String key, int def)
long getLong (String key, long def)Dependencies
import javax.imageio.ImageIO;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
java.io.*;
Methods
boolean isImageFile(String fileExt)
byte[] resize(byte[] img, int width, int height)Dependencies
Methods
Dependencies
Methods
Dependencies
Methods
Dependencies
import javax.servlet.http.HttpServletRequest;
Methods
String getIpAddr (HttpServletRequest request)
String getRealIpAddr (HttpServletRequest request)Dependencies
import java.lang.reflect.Type;
import com.google.gson.Gson;
Methods
String toJson (Object obj)
T fromJson (String str, Type type)
T fromJson (String str, Class<T> type)Dependencies
Methods
Dependencies
import org.apache.log4j.Logger;
Methods
void debug (String message)
void info (String message)
void warn (String message)
void error (String message)Dependencies
import net.sourceforge.pinyin4j.PinyinHelper;
Methods
String getPinyin (String str)
String getPinyinHeadChar (String str)Dependencies
Methods
Dependencies
Methods
Dependencies
Methods
--END--