Skip to content

Commit 4236fbd

Browse files
committed
Finish 9.4.0
2 parents 6807501 + e647248 commit 4236fbd

16 files changed

Lines changed: 782 additions & 357 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ buildscript {
88
}
99
}
1010

11-
rootProject.version = '9.3.0'
11+
rootProject.version = '9.4.0'
1212
group = 'com.spaceshift'
1313

1414
allprojects {

rlib-common/src/main/java/com/ss/rlib/common/concurrent/GroupThreadFactory.java

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,13 @@ public interface ThreadConstructor {
2020
@NotNull Thread create(@NotNull ThreadGroup group, @NotNull Runnable runnable, @NotNull String name);
2121
}
2222

23-
/**
24-
* The order of the next thread.
25-
*/
2623
private final AtomicInteger ordinal;
27-
28-
/**
29-
* The name of this group.
30-
*/
3124
private final String name;
32-
33-
/**
34-
* The group of threads.
35-
*/
3625
private final ThreadGroup group;
37-
38-
/**
39-
* The thread's constructor.
40-
*/
4126
private final ThreadConstructor constructor;
4227

43-
/**
44-
* The priority of these threads.
45-
*/
4628
private final int priority;
29+
private final boolean daemon;
4730

4831
public GroupThreadFactory(@NotNull String name) {
4932
this(name, Thread::new, Thread.NORM_PRIORITY);
@@ -54,11 +37,21 @@ public GroupThreadFactory(@NotNull String name, int priority) {
5437
}
5538

5639
public GroupThreadFactory(@NotNull String name, @NotNull ThreadConstructor constructor, int priority) {
40+
this(name, constructor, priority, false);
41+
}
42+
43+
public GroupThreadFactory(
44+
@NotNull String name,
45+
@NotNull ThreadConstructor constructor,
46+
int priority,
47+
boolean daemon
48+
) {
5749
this.constructor = constructor;
5850
this.priority = priority;
5951
this.name = name;
6052
this.group = new ThreadGroup(name);
6153
this.ordinal = new AtomicInteger();
54+
this.daemon = daemon;
6255
}
6356

6457
@Deprecated
@@ -67,6 +60,7 @@ public GroupThreadFactory(@NotNull String name, @NotNull Class<? extends Thread>
6760
this.name = name;
6861
this.group = new ThreadGroup(name);
6962
this.ordinal = new AtomicInteger();
63+
this.daemon = false;
7064
this.constructor = new ThreadConstructor() {
7165

7266
Constructor<? extends Thread> constructor =
@@ -87,6 +81,7 @@ public GroupThreadFactory(@NotNull String name, @NotNull Class<? extends Thread>
8781
public @NotNull Thread newThread(@NotNull Runnable runnable) {
8882
var thread = constructor.create(group, runnable, name + "-" + ordinal.incrementAndGet());
8983
thread.setPriority(priority);
84+
thread.setDaemon(daemon);
9085
return thread;
9186
}
9287
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.ss.rlib.common.function;
2+
3+
/**
4+
* @author JavaSaBr
5+
*/
6+
@FunctionalInterface
7+
public interface ByteFunction<R> {
8+
9+
R apply(byte value);
10+
}

rlib-common/src/main/java/com/ss/rlib/common/util/NumberUtils.java

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,26 @@ public static boolean isLong(@Nullable String string) {
111111
}
112112
}
113113

114+
/**
115+
* Convert a string to int object or null if this string is null or not a number.
116+
*
117+
* @param string the string to convert.
118+
* @return the int object or null.
119+
* @since 9.4.0
120+
*/
121+
public static @Nullable Integer safeToInt(@Nullable String string) {
122+
123+
if (string == null) {
124+
return null;
125+
} else {
126+
try {
127+
return Integer.valueOf(string);
128+
} catch (NumberFormatException e) {
129+
return null;
130+
}
131+
}
132+
}
133+
114134
/**
115135
* Convert a string to long object or null if this string is null or not a number.
116136
*
@@ -151,6 +171,98 @@ public static boolean isLong(@Nullable String string) {
151171
}
152172
}
153173

174+
/**
175+
* Set a bit in a number by a pos to 1.
176+
*
177+
* @param value the byte.
178+
* @param pos the bit position.
179+
* @return the update number.
180+
*/
181+
public static int setBit(int value, int pos) {
182+
return value | (1 << pos);
183+
}
184+
185+
/**
186+
* Set a bit in a number by a pos to 0.
187+
*
188+
* @param value the byte.
189+
* @param pos the bit position.
190+
* @return the update number.
191+
*/
192+
public static int unsetBit(int value, int pos) {
193+
return value & ~(1 << pos);
194+
}
195+
196+
/**
197+
* Return true if bit by pos in a byte is 1.
198+
*
199+
* @param value the byte.
200+
* @return true if the bit is 1.
201+
*/
202+
public static boolean isSetBit(int value, int pos) {
203+
return (value & (1L << pos)) != 0;
204+
}
205+
206+
/**
207+
* Return true if bit by pos in a byte is 0.
208+
*
209+
* @param value the byte.
210+
* @return true if the bit is 0.
211+
*/
212+
public static boolean isNotSetBit(int value, int pos) {
213+
return (value & (1L << pos)) == 0;
214+
}
215+
216+
/**
217+
* Set last high 4 bits to a byte.
218+
*
219+
* @param value the byte value.
220+
* @return the result value with updating last high 4 bits.
221+
*/
222+
public static int setHighByteBits(int value, int highBits) {
223+
return value | highBits << 4;
224+
}
225+
226+
/**
227+
* Get last high 4 bits from a byte.
228+
*
229+
* @param value the byte value.
230+
* @return the value of last 4 high bits.
231+
*/
232+
public static byte getHighByteBits(int value) {
233+
return (byte) (value >> 4);
234+
}
235+
236+
/**
237+
* Set first low 4 bits to a byte.
238+
*
239+
* @param value the byte value.
240+
* @return the result value with updating first low 4 bits.
241+
*/
242+
public static int setLowByteBits(int value, int lowBits) {
243+
return value | lowBits & 0x0F;
244+
}
245+
246+
/**
247+
* Get first low 4 bits from a byte.
248+
*
249+
* @param value the byte value.
250+
* @return the value of last 4 low bits.
251+
*/
252+
public static byte getLowByteBits(int value) {
253+
return (byte) (value & 0x0F);
254+
}
255+
256+
/**
257+
* Covert a byte to unsigned byte.
258+
*
259+
* @param value the byte.
260+
* @return the unsigned byte.
261+
*/
262+
public static int toUnsignedByte(byte value) {
263+
return value & 0xFF;
264+
}
265+
154266
private NumberUtils() {
155267
throw new IllegalArgumentException();
156268
}

0 commit comments

Comments
 (0)