下面列出了org.apache.commons.lang3.ArrayUtils#isEmpty ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void disruptorEventHandlerChain() {
for(int i=0;i<eventHandlerChain.length;i++){
EventHandlerChain<T> eventHandlersChain = eventHandlerChain[i];
EventHandlerGroup<T> eventHandlerGroup = null;
if(i == 0){
eventHandlerGroup = getDisruptor().handleEventsWith(eventHandlersChain.getCurrentEventHandlers());
}else{
eventHandlerGroup = getDisruptor().after(eventHandlersChain.getCurrentEventHandlers());
}
if(! ArrayUtils.isEmpty(eventHandlersChain.getNextEventHandlers())){
eventHandlerGroup.then(eventHandlersChain.getNextEventHandlers());
}
}
getEventProcessorGraph();
}
@Override
protected Transferable createTransferable(JComponent c)
{
if (c == equipmentSetTable)
{
int[] rows = equipmentSetTable.getSelectedRows();
if (ArrayUtils.isEmpty(rows))
{
return null;
}
EquipNode[] nodeArray = new EquipNode[rows.length];
for (int i = 0; i < nodeArray.length; i++)
{
nodeArray[i] = (EquipNode) equipmentSetTable.getModel().getValueAt(rows[i], 0);
}
return new EquipNodeSelection(nodeArray);
}
return super.createTransferable(c);
}
@Override
public List<String> getAvailableTargetIds() {
String[] availableTargetIds = SiteProperties.getAvailableTargetIds();
if (ArrayUtils.isEmpty(availableTargetIds)) {
List<Locale> availableLocales = LocaleUtils.availableLocaleList();
List<String> availableLocaleStrs = new ArrayList<>(availableLocales.size());
for (Locale locale : availableLocales) {
String localeStr = locale.toString();
// Ignore empty ROOT locale
if (StringUtils.isNotEmpty(localeStr)) {
availableLocaleStrs.add(StringUtils.lowerCase(localeStr));
}
}
return availableLocaleStrs;
} else {
return Arrays.asList(availableTargetIds);
}
}
@Override
public boolean hasPermission(final String roleIds, final String... codes) {
if (this.isAdministrator(roleIds)) {
return true;
}
if (StringUtils.isBlank(roleIds) || ArrayUtils.isEmpty(codes)) {
return false;
}
final String permissionIds = this.roleService.getPermissionIds(roleIds);
if (StringUtils.isBlank(permissionIds)) {
return false;
}
final String[] permissionIdSplit = StringUtils.split(permissionIds, ',');
final String codePermissionIds = this.permissionService.getPermissionIds(codes);
final String[] codePermissionIdSplit = StringUtils.split(codePermissionIds, ',');
return this.hasPermission(codePermissionIdSplit, permissionIdSplit);
}
@Override
@DeleteMapping
public ResponseEntity<Integer> deleteBatch(@RequestBody Integer[] id) {
if (ArrayUtils.isEmpty(id)) {
throw new BusinessException(ErrorCode.PARAM_IS_NULL);
}
int count = codeTemplateService.delete(id);
return ResponseEntity.ok(count);
}
private void createMessage(MessageLevel level, Throwable e, TextColor color, TextStyle style, String... messages) {
assertState(ContextType.TESTCASE, ContextType.ACTION, ContextType.ACTIONGROUP);
if (ArrayUtils.isEmpty(messages) && e == null) {
throw new ScriptRunException("Message array is empty");
}
getCurrentContextNode().addSubNodes(Arrays.stream(messages)
.map(m -> new CustomMessage(m, Objects.toString(color, null), Objects.toString(style, null), level, e))
.collect(Collectors.toSet()));
}
public static byte[] mix(byte[] bytes) {
try {
if (ArrayUtils.isEmpty(bytes)) {
return bytes;
}
int offset = offset((bytes.length));
int tailLength = bytes.length >> 1;
int headLength = tailLength + (bytes.length & 1);
int quarter = tailLength >> 2;
byte[] headBytes = new byte[headLength];
byte[] tailBytes = new byte[tailLength];
int ri = 0;
for (int i = 0; i < tailLength; i++) {
headBytes[left_relocation_index(i, headLength, quarter)] = mix(bytes[ri], offset + ri);
ri = ri | 1;
tailBytes[right_relocation_index(i, tailLength, quarter)] = mix(bytes[ri], offset + ri);
ri = ri + 1;
}
if ((bytes.length & 1) == 1) {
headBytes[left_relocation_index(tailLength, headLength, quarter)] = mix(bytes[ri], offset + ri);
}
return BytesUtils.concat(headBytes, tailBytes);
} catch (Exception e) {
throw new IllegalArgumentException("");
}
}
/**
* Returns true if all the given <code>searches</code> are contained in the given string,
* ignoring case.
*
* @param toSearch the string to search
* @param searches the strings to find
* @return true if all the given <code>searches</code> are contained in the given string.
*/
public static boolean containsAllIgnoreCase(CharSequence toSearch, CharSequence... searches) {
if (StringUtils.isEmpty(toSearch) || ArrayUtils.isEmpty(searches)) {
return false;
}
for (CharSequence search : searches) {
if (!StringUtils.containsIgnoreCase(toSearch, search)) {
return false;
}
}
return true;
}
/**
* 设置文件处理器
*
* @param handler 处理器
* @param suffixs 对应的文件后缀名集合
*/
public synchronized void setFileHandler(IFileHandler handler, String... suffixs) {
if (handler == null) return;
if (ArrayUtils.isEmpty(suffixs)) return;
if (fileHandlerMap == null) {
fileHandlerMap = new HashMap<>(16);
}
for (String suffix : suffixs) {
List<IFileHandler> handlers = fileHandlerMap.getOrDefault(suffix, new ArrayList<>());
handlers.add(handler);
fileHandlerMap.put(suffix, handlers);
}
}
@Override
public BytesWrapper get(byte[] key) {
byte[] value = revokingDB.getUnchecked(key);
if (ArrayUtils.isEmpty(value)) {
return null;
}
return new BytesWrapper(value);
}
@Override
public void groupBy(Object[] properties) {
if (isGrouping) {
return;
}
isGrouping = true;
try {
if (properties != null) {
groupProperties = properties;
if (!ArrayUtils.isEmpty(groupProperties)) {
doGroup();
} else {
roots = null;
parents = null;
children = null;
groupItems = null;
itemGroups = null;
}
}
} finally {
isGrouping = false;
if (sortProperties != null && sortProperties.length > 0 && !hasGroups()) {
super.sort(sortProperties, sortAscending);
}
}
}
@Override
public Map<String, String[]> getParameterMap() {
if (ArrayUtils.isEmpty(content) || this.parameterMap.isEmpty()) {
return super.getParameterMap();
}
return this.parameterMap;
}
/**
* 将一个byte数组转换成62进制的字符串。
*
* @param bytes 二进制数组
* @param noCase 区分大小写
*
* @return 62进制的字符串
*/
public static String bytesToString(byte[] bytes, boolean noCase) {
char[] digits = noCase ? DIGITS_NOCASE : DIGITS;
int digitsLength = digits.length;
if (ArrayUtils.isEmpty(bytes)) {
return String.valueOf(digits[0]);
}
StringBuilder strValue = new StringBuilder();
int value = 0;
int limit = Integer.MAX_VALUE >>> 8;
int i = 0;
do {
while (i < bytes.length && value < limit) {
value = (value << 8) + (0xFF & bytes[i++]);
}
while (value >= digitsLength) {
strValue.append(digits[value % digitsLength]);
value = value / digitsLength;
}
} while (i < bytes.length);
if (value != 0 || strValue.length() == 0) {
strValue.append(digits[value]);
}
return strValue.toString();
}
/**
* @return
*/
public WitnessWrapper getWitness() {
if (ArrayUtils.isEmpty(any)) {
return null;
}
return new WitnessWrapper(any);
}
@Override
@PutMapping(value = "/delete_batch")
public ResponseEntity<Integer> deleteBatch(@RequestBody Integer[] indexId) {
if (ArrayUtils.isEmpty(indexId)) {
throw new BusinessException(ErrorCode.PARAM_IS_NULL);
}
int count = metaIndexService.delete(indexId);
return ResponseEntity.ok(count);
}
public boolean isEmpty() {
return ArrayUtils.isEmpty((Object[])this.queueFolder.list());
}
private boolean isFilterActive(String[] filterTypes, MailingDependentType type) {
return ArrayUtils.isEmpty(filterTypes) || ArrayUtils.contains(filterTypes, type.name());
}
/**
* parse Event Data into map<String, Object> If parser failed, then return {"0",
* Hex.toHexString(data)} Only support basic solidity type, String, Bytes. Fixed Array or dynamic
* Array are not support yet (then return {"0": Hex.toHexString(data)}).
*/
public static Map<String, String> parseEventData(byte[] data,
List<byte[]> topicList, ABI.Entry entry) {
Map<String, String> map = new HashMap<>();
if (ArrayUtils.isEmpty(data)) {
return map;
}
// in case indexed topics doesn't match
if (!topicsMatched(topicList, entry)) {
map.put("" + (topicList.size() - 1), Hex.toHexString(data));
return map;
}
// the first is the signature.
List<ABI.Entry.Param> list = entry.getInputsList();
Integer startIndex = 0;
try {
// this one starts from the first position.
int index = 0;
for (Integer i = 0; i < list.size(); ++i) {
ABI.Entry.Param param = list.get(i);
if (param.getIndexed()) {
continue;
}
if (startIndex == 0) {
startIndex = i;
}
String str = parseDataBytes(data, param.getType(), index++);
if (StringUtils.isNotNullOrEmpty(param.getName())) {
map.put(param.getName(), str);
}
map.put("" + i, str);
}
if (list.size() == 0) {
map.put("0", Hex.toHexString(data));
}
} catch (UnsupportedOperationException e) {
logger.debug("Unsupported Operation Exception", e);
map.clear();
map.put(startIndex.toString(), Hex.toHexString(data));
}
return map;
}
public static void encryptContent( SecurityManager securityManager, String hostIdSource, String hostIdTarget,
Message message )
{
OutputStream os = message.getContent( OutputStream.class );
CachedStream cs = new CachedStream();
message.setContent( OutputStream.class, cs );
message.getInterceptorChain().doIntercept( message );
LOG.debug( String.format( "Encrypting IDs: %s -> %s", hostIdSource, hostIdTarget ) );
try
{
cs.flush();
CachedOutputStream csnew = ( CachedOutputStream ) message.getContent( OutputStream.class );
byte[] originalMessage = org.apache.commons.io.IOUtils.toByteArray( csnew.getInputStream() );
LOG.debug( String.format( "Original payload: \"%s\"", new String( originalMessage ) ) );
csnew.flush();
org.apache.commons.io.IOUtils.closeQuietly( cs );
org.apache.commons.io.IOUtils.closeQuietly( csnew );
//do something with original message to produce finalMessage
byte[] finalMessage =
originalMessage.length > 0 ? encryptData( securityManager, hostIdTarget, originalMessage ) : null;
if ( !ArrayUtils.isEmpty( finalMessage ) )
{
InputStream replaceInStream = new ByteArrayInputStream( finalMessage );
org.apache.commons.io.IOUtils.copy( replaceInStream, os );
replaceInStream.close();
org.apache.commons.io.IOUtils.closeQuietly( replaceInStream );
os.flush();
message.setContent( OutputStream.class, os );
}
org.apache.commons.io.IOUtils.closeQuietly( os );
}
catch ( Exception ioe )
{
throw new ActionFailedException( "Error encrypting content", ioe );
}
}
/**
* Checks if given content is available for public access.
*/
private static boolean isPublic(Content content) {
return content.isVisible() && ArrayUtils.isEmpty(content.getParents(Trash.class));
}