本文整理汇总了Java中org.apache.commons.lang.ArrayUtils.isNotEmpty方法的典型用法代码示例。如果您正苦于以下问题:Java ArrayUtils.isNotEmpty方法的具体用法?Java ArrayUtils.isNotEmpty怎么用?Java ArrayUtils.isNotEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang.ArrayUtils
的用法示例。
在下文中一共展示了ArrayUtils.isNotEmpty方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configure
import org.apache.commons.lang.ArrayUtils; //导入方法依赖的package包/类
@Override
public void configure(Context context) {
String[] hosts = getHosts(context);
if(ArrayUtils.isNotEmpty(hosts)) {
TransportClient client = new ElasticsearchClientBuilder(
context.getString(PREFIX + ES_CLUSTER_NAME, DEFAULT_ES_CLUSTER_NAME), hosts)
.setTransportSniff(context.getBoolean(
PREFIX + ES_TRANSPORT_SNIFF, false))
.setIgnoreClusterName(context.getBoolean(
PREFIX + ES_IGNORE_CLUSTER_NAME, false))
.setTransportPingTimeout(Util.getTimeValue(context.getString(
PREFIX + ES_TRANSPORT_PING_TIMEOUT), DEFAULT_ES_TIME))
.setNodeSamplerInterval(Util.getTimeValue(context.getString(
PREFIX + ES_TRANSPORT_NODE_SAMPLER_INTERVAL), DEFAULT_ES_TIME))
.build();
buildIndexBuilder(context);
buildSerializer(context);
bulkProcessor = new BulkProcessorBuilder().buildBulkProcessor(context, client);
} else {
logger.error("Could not create transport client, No host exist");
}
}
示例2: getMetadataForContainersEntries
import org.apache.commons.lang.ArrayUtils; //导入方法依赖的package包/类
/**
* Lookup entry metadata for all given entries and all given containers and then build a map of data,
* the outer map will include an entry for every input container, however,
* the second map will ONLY contain the entries which actually have metadata entered for them
* (therefore it is unlikely to contain the same number of values as the entryIds input value)
*
* This differs from {@link #getMetadataForEntry(String, String...)} which always returns a map of the same size
* as the input set of entry ids.
*
* OPTIMIZATION method (fetch lots of metadata at once)
*
* @param containerIds the set of collection (or site) ids to fetch metadata for the input entries
* @param entryIds the id of the entry (can be 1 or many values)
* @return Map of the {containerId -> Map of {entryId -> Map of metadata {key -> value} } }
*/
protected Map<String, Map<String, Map<String, String>>> getMetadataForContainersEntries(Set<String> containerIds, String... entryIds) {
if (containerIds == null || containerIds.isEmpty()) {
throw new IllegalArgumentException("playlist ids must be set and not empty");
}
if (entryIds == null) {
throw new IllegalArgumentException("entry ids must be set");
}
if (log.isDebugEnabled()) log.debug("getMetadataForContainersEntries(containerIds="+containerIds+", entryIds="+ArrayUtils.toString(entryIds)+")");
Map<String, Map<String, Map<String, String>>> metadata = new LinkedHashMap<String, Map<String, Map<String, String>>>(containerIds.size());
// pre-populate the metadata map to ensure every passed in playlist id has an entry
for (String playlistId : containerIds) {
metadata.put(playlistId, new LinkedHashMap<String, Map<String, String>>());
}
if (ArrayUtils.isNotEmpty(entryIds)) {
Map<String, List<String>> metadataFieldsMap = getEntryMetadataFields(entryIds);
for (Map.Entry<String, List<String>> entry : metadataFieldsMap.entrySet()) {
String entryId = entry.getKey();
List<String> metadataList = entry.getValue();
for (String entryMetadata : metadataList) {
// search for the matching container Id in the decoded metadata and only use the results if it was found
Map<String, String> metadataMap = decodeMetadataPermissions(entryMetadata, false);
String containerId = metadataMap.get(METADATA_CONTAINER_ID);
if (containerIds.contains(containerId)) {
metadata.get(containerId).put(entryId, metadataMap);
}
}
}
}
return metadata;
}
示例3: postHandle
import org.apache.commons.lang.ArrayUtils; //导入方法依赖的package包/类
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
if (modelAndView!=null && ArrayUtils.isNotEmpty(request.getCookies())) {
HashMap<String, Cookie> cookieMap = new HashMap<String, Cookie>();
for (Cookie ck : request.getCookies()) {
cookieMap.put(ck.getName(), ck);
}
modelAndView.addObject("cookieMap", cookieMap);
}
super.postHandle(request, response, handler, modelAndView);
}
示例4: sendMailSpring
import org.apache.commons.lang.ArrayUtils; //导入方法依赖的package包/类
/**
* 发送邮件 (完整版)(结合Spring)
*
* //@param javaMailSender: 发送Bean
* //@param sendFrom : 发送人邮箱
* //@param sendNick : 发送人昵称
* @param toAddress : 收件人邮箱
* @param mailSubject : 邮件主题
* @param mailBody : 邮件正文
* @param mailBodyIsHtml: 邮件正文格式,true:HTML格式;false:文本格式
* @param attachments : 附件
*/
@SuppressWarnings("null")
public static boolean sendMailSpring(String toAddress, String mailSubject, String mailBody, boolean mailBodyIsHtml,File[] attachments) {
JavaMailSender javaMailSender = null;//ResourceBundle.getInstance().getJavaMailSender();
try {
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, ArrayUtils.isNotEmpty(attachments), "UTF-8"); // 设置utf-8或GBK编码,否则邮件会有乱码;multipart,true表示文件上传
helper.setFrom(username, sendNick);
helper.setTo(toAddress);
// 设置收件人抄送的名片和地址(相当于群发了)
//helper.setCc(InternetAddress.parse(MimeUtility.encodeText("邮箱001") + " <@163.com>," + MimeUtility.encodeText("邮箱002") + " <@foxmail.com>"));
helper.setSubject(mailSubject);
helper.setText(mailBody, mailBodyIsHtml);
// 添加附件
if (ArrayUtils.isNotEmpty(attachments)) {
for (File file : attachments) {
helper.addAttachment(MimeUtility.encodeText(file.getName()), file);
}
}
// 群发
//MimeMessage[] mailMessages = { mimeMessage };
javaMailSender.send(mimeMessage);
return true;
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
return false;
}
示例5: sendMailSpring
import org.apache.commons.lang.ArrayUtils; //导入方法依赖的package包/类
/**
* 发送邮件 (完整版)(结合Spring)
*
* //@param javaMailSender: 发送Bean
* //@param sendFrom : 发送人邮箱
* //@param sendNick : 发送人昵称
* @param toAddress : 收件人邮箱
* @param mailSubject : 邮件主题
* @param mailBody : 邮件正文
* @param mailBodyIsHtml: 邮件正文格式,true:HTML格式;false:文本格式
* @param attachments : 附件
*/
@SuppressWarnings("null")
public static boolean sendMailSpring(String toAddress, String mailSubject, String mailBody, boolean mailBodyIsHtml,File[] attachments) {
JavaMailSender javaMailSender = null;//ResourceBundle.getInstance().getJavaMailSender();
try {
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, ArrayUtils.isNotEmpty(attachments), "UTF-8"); // 设置utf-8或GBK编码,否则邮件会有乱码;multipart,true表示文件上传
helper.setFrom(sendFrom, sendNick);
helper.setTo(toAddress);
// 设置收件人抄送的名片和地址(相当于群发了)
//helper.setCc(InternetAddress.parse(MimeUtility.encodeText("邮箱001") + " <@163.com>," + MimeUtility.encodeText("邮箱002") + " <@foxmail.com>"));
helper.setSubject(mailSubject);
helper.setText(mailBody, mailBodyIsHtml);
// 添加附件
if (ArrayUtils.isNotEmpty(attachments)) {
for (File file : attachments) {
helper.addAttachment(MimeUtility.encodeText(file.getName()), file);
}
}
// 群发
//MimeMessage[] mailMessages = { mimeMessage };
javaMailSender.send(mimeMessage);
return true;
} catch (Exception e) {
logger.info("{}", e);
}
return false;
}
示例6: doFilter
import org.apache.commons.lang.ArrayUtils; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) throws IOException, ServletException {
if(AuthUtil.getAuthFlag()){
arg2.doFilter(arg0, arg1);
return ;
}
try{
HttpServletRequest request = (HttpServletRequest) arg0;
WrapperResponse wrapper = new WrapperResponse((HttpServletResponse)arg1);
boolean flag = doGet(request, wrapper);
log.info("HTTPAuthFilter uri {} doGet flag : {}",request.getRequestURI(),flag);
if(flag){
arg2.doFilter(arg0, wrapper);
byte[] content = wrapper.getContent();
content = filterGroups(request, content);
if(ArrayUtils.isNotEmpty(content)){
ServletOutputStream out = arg1.getOutputStream();
out.write(content);
out.flush();
out.close();
}
}
}catch(Exception e){
log.error(e.getMessage(),e);
}finally{
AuthUtil.THREAD_LOCAL_USER.remove();
}
}
示例7: getAPIResultsForQualityGates
import org.apache.commons.lang.ArrayUtils; //导入方法依赖的package包/类
public QualityGatesStatus getAPIResultsForQualityGates(JobConfigData jobConfigData, GlobalConfigDataForSonarInstance globalConfigDataForSonarInstance, BuildListener listener) throws JSONException, InterruptedException{
GlobalConfigDataForSonarInstance validatedData = sonarInstanceValidationService.validateData(globalConfigDataForSonarInstance);
boolean taskAnalysisRunning = true;
int attemptsToRepeat = jobConfigData.getAttemptsToRepeat();
int timeToWait = globalConfigDataForSonarInstance.getTimeToWait();
if (timeToWait == 0) {
timeToWait = MILLISECONDS_10_SECONDS;
}
if (attemptsToRepeat == 0) {
attemptsToRepeat = 1;
}
if (attemptsToRepeat * timeToWait > MILLISECONDS_10_MINUTES) {
attemptsToRepeat = MILLISECONDS_10_MINUTES / timeToWait;
}
int timesExecuted = 0;
do {
sonarHttpRequester.setLogged(false);
String statusResultJson = sonarHttpRequester.getAPITaskInfo(jobConfigData, validatedData);
Gson gson = new GsonBuilder().create();
QualityGateTaskCE taskCE = gson.fromJson(statusResultJson, QualityGateTaskCE.class);
if (ArrayUtils.isNotEmpty(taskCE.getQueue())) {
listener.getLogger().println("Has build " + taskCE.getQueue()[0].getStatus() + " with id: " + taskCE.getQueue()[0].getId() + " - waiting " + timeToWait + " to execute next check.");
Thread.sleep(timeToWait);
} else {
listener.getLogger().println("Status => " + taskCE.getCurrent().getStatus());
if ("SUCCESS".equals(taskCE.getCurrent().getStatus())) {
taskAnalysisRunning = false;
}
}
if (attemptsToRepeat < timesExecuted++) {
throw new MaxExecutionTimeException("Max time to wait sonar job!");
}
} while (taskAnalysisRunning);
String requesterResult = getRequesterResult(jobConfigData, validatedData);
return qualityGateResponseParser.getQualityGateResultFromJSON(requesterResult);
}
示例8: sendMail
import org.apache.commons.lang.ArrayUtils; //导入方法依赖的package包/类
/**
* 发送邮件 (完整版) (纯JavaMail)
*
* @param toAddress : 收件人邮箱
* @param mailSubject : 邮件主题
* @param mailBody : 邮件正文
* @param mailBodyIsHtml: 邮件正文格式,true:HTML格式;false:文本格式
* //@param inLineFile : 内嵌文件
* @param attachments : 附件
*/
public static boolean sendMail (String toAddress, String mailSubject, String mailBody,
boolean mailBodyIsHtml, File[] attachments){
try {
// 创建邮件发送类 JavaMailSender (用于发送多元化邮件,包括附件,图片,html 等)
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost(host); // 设置邮件服务主机
mailSender.setUsername(username); // 发送者邮箱的用户名
mailSender.setPassword(password); // 发送者邮箱的密码
// 配置文件,用于实例化java.mail.session
Properties pro = new Properties();
pro.put("mail.transport.protocol", "smtp");
pro.put("mail.smtp.auth", "true"); // 登录SMTP服务器,需要获得授权 (网易163邮箱新近注册的邮箱均不能授权,测试 sohu 的邮箱可以获得授权)
pro.put("mail.smtp.socketFactory.port", port);
pro.put("mail.smtp.socketFactory.fallback", "false");
mailSender.setJavaMailProperties(pro);
// 创建多元化邮件 (创建 mimeMessage 帮助类,用于封装信息至 mimeMessage)
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, ArrayUtils.isNotEmpty(attachments), "UTF-8");
helper.setFrom(username, sendNick);
helper.setTo(toAddress);
helper.setSubject(mailSubject);
helper.setText(mailBody, mailBodyIsHtml);
// 设置收件人抄送的名片和地址(相当于群发)
//helper.setCc(InternetAddress.parse(MimeUtility.encodeText("邮箱001") + " <@163.com>," + MimeUtility.encodeText("邮箱002") + " <@foxmail.com>"));
// 内嵌文件,第1个参数为cid标识这个文件,第2个参数为资源
//helper.addInline(MimeUtility.encodeText(inLineFile.getName()), inLineFile);
// 添加附件
/*if (ArrayUtils.isNotEmpty(attachments)) {
for (File file : attachments) {
helper.addAttachment(MimeUtility.encodeText(file.getName()), file);
}
}*/
// 群发
//MimeMessage[] mailMessages = { mimeMessage };
mailSender.send(mimeMessage);
return true;
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
return false;
}
示例9: sendMail
import org.apache.commons.lang.ArrayUtils; //导入方法依赖的package包/类
/**
* 发送邮件 (完整版) (纯JavaMail)
*
* @param toAddress : 收件人邮箱
* @param mailSubject : 邮件主题
* @param mailBody : 邮件正文
* @param mailBodyIsHtml: 邮件正文格式,true:HTML格式;false:文本格式
* //@param inLineFile : 内嵌文件
* @param attachments : 附件
*/
public static boolean sendMail (String toAddress, String mailSubject, String mailBody,
boolean mailBodyIsHtml, File[] attachments){
try {
// 创建邮件发送类 JavaMailSender (用于发送多元化邮件,包括附件,图片,html 等 )
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost(host); // 设置邮件服务主机
mailSender.setUsername(username); // 发送者邮箱的用户名
mailSender.setPassword(password); // 发送者邮箱的密码
//配置文件,用于实例化java.mail.session
Properties pro = new Properties();
pro.put("mail.smtp.auth", "true"); // 登录SMTP服务器,需要获得授权 (网易163邮箱新近注册的邮箱均不能授权,测试 sohu 的邮箱可以获得授权)
pro.put("mail.smtp.socketFactory.port", port);
pro.put("mail.smtp.socketFactory.fallback", "false");
mailSender.setJavaMailProperties(pro);
//创建多元化邮件 (创建 mimeMessage 帮助类,用于封装信息至 mimeMessage)
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, ArrayUtils.isNotEmpty(attachments), "UTF-8");
helper.setFrom(sendFrom, sendNick);
helper.setTo(toAddress);
helper.setSubject(mailSubject);
helper.setText(mailBody, mailBodyIsHtml);
// 添加内嵌文件,第1个参数为cid标识这个文件,第2个参数为资源
//helper.addInline(MimeUtility.encodeText(inLineFile.getName()), inLineFile);
// 添加附件
if (ArrayUtils.isNotEmpty(attachments)) {
for (File file : attachments) {
helper.addAttachment(MimeUtility.encodeText(file.getName()), file);
}
}
mailSender.send(mimeMessage);
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}