下面列出了org.apache.commons.lang3.StringUtils#containsIgnoreCase ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static List<String> getAllJSONFileVolumes(String collectionCode) {
String filesPath = PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.DEFAULT_PERSISTER_FILE_PATH) + collectionCode + "/";
List<String> fileNames = new ArrayList<String>();
File folder = new File(filesPath);
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
String currentFileName = listOfFiles[i].getName();
if (StringUtils.contains(currentFileName, collectionCode)) {
if (!StringUtils.contains(currentFileName, ".csv") && !StringUtils.contains(currentFileName, ".txt")
&& StringUtils.containsIgnoreCase(listOfFiles[i].getName(), "vol")) { //do not consider CSV files here, only consider JSON files
fileNames.add(currentFileName);
}
}
}
}
return fileNames;
}
private void setDisambiguation(Article.Builder a) {
for (final String disambiguation : locale.getDisambigutionIdentifiers()) {
if (StringUtils.containsIgnoreCase(a.getTitle(), disambiguation)) {
a.setType(ArticleType.DISAMBIGUATION);
return;
}
if (a.hasTemplates()) {
for (final Template t : a.getTemplates()) {
if (StringUtils.equalsIgnoreCase(t.getName(), disambiguation)) {
a.setType(ArticleType.DISAMBIGUATION);
return;
}
}
}
}
}
@Override
public void match(final ComponentNode component, final SearchQuery query, final List<String> matches) {
final String searchTerm = query.getTerm();
if (!propertiesAreFilteredOut(query)) {
for (final Map.Entry<PropertyDescriptor, String> entry : component.getRawPropertyValues().entrySet()) {
final PropertyDescriptor descriptor = entry.getKey();
addIfMatching(searchTerm, descriptor.getName(), LABEL_NAME, matches);
addIfMatching(searchTerm, descriptor.getDescription(), LABEL_DESCRIPTION, matches);
// never include sensitive properties values in search results
if (!descriptor.isSensitive()) {
final String value = Optional.ofNullable(entry.getValue()).orElse(descriptor.getDefaultValue());
// evaluate if the value matches the search criteria
if (StringUtils.containsIgnoreCase(value, searchTerm)) {
matches.add(LABEL_VALUE + SEPARATOR + descriptor.getName() + " - " + value);
}
}
}
}
}
/**
* Get the {@link Status} from the string equivalent
*
* @param status the string status
* @return the equivalent {@link Status}
*/
public static Status getStatus(@Nullable final String status) {
if (UtilsString.notNaked(status)) {
if (StringUtils.containsIgnoreCase(NOTSTARTED.name(), status)) {
return NOTSTARTED;
} else if (StringUtils.containsIgnoreCase(RUNNING.name(), status)) {
return RUNNING;
} else if (StringUtils.containsIgnoreCase(FAILED.name(), status)) {
return FAILED;
} else if (StringUtils.containsIgnoreCase(SUCCEEDED.name(), status)) {
return SUCCEEDED;
}
}
return UNDEFINED;
}
private boolean disabledSkill500(CloseableHttpResponse response) throws IOException {
if(response.getStatusLine().getStatusCode() != HttpStatus.SC_INTERNAL_SERVER_ERROR) {
return false;
}
HttpEntity entity = null;
try {
entity = response.getEntity();
Map<String, Object> body = JSON.fromJson(EntityUtils.toString(entity, StandardCharsets.UTF_8), ERR_TYPE);
String msg = (String) body.get("message");
boolean disabled = StringUtils.containsIgnoreCase(msg, "SkillIdentifier");
if(disabled) {
logger.warn("disabled skill due to 500 error with body {}", body);
}
return disabled;
} finally {
consumeQuietly(entity);
}
}
public static int getLatestFileVolumeNumber(String collectionCode) {
String filesPath = PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.DEFAULT_PERSISTER_FILE_PATH) + collectionCode + "/";
File folder = new File(filesPath);
File[] listOfFiles = folder.listFiles();
Integer volNum = 1;
if (!(listOfFiles == null)) {
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
String currentFileName = listOfFiles[i].getName();
if (StringUtils.contains(currentFileName, collectionCode)) {
if (!(StringUtils.contains(currentFileName, ".csv"))
&& StringUtils.containsIgnoreCase(listOfFiles[i].getName(), "vol")) { //do not consider CSV files here, only consider JSON files
Integer currentVolN = Integer.parseInt(StringUtils.substringBetween(currentFileName, "vol-", ".json"));
if (currentVolN > volNum) {
volNum = currentVolN;
}
}
}
}
}
}
return volNum;
}
private void removeRequiredStringGesetzFromFallExtInfo(){
String selection = ldConstants.getSelection();
if (selection != null && StringUtils.containsIgnoreCase(selection, "Gesetz")) {
String[] split = selection.split("=");
String message = MessageFormat
.format("Remove the selected field [{0}] from all Faelle?\nPlease validate that a law is set!", split[0]);
boolean performDelete =
MessageDialog.openQuestion(UiDesk.getTopShell(), "Remove from Faelle", message);
if (performDelete) {
BusyIndicator.showWhile(UiDesk.getDisplay(), () -> {
BillingSystem.removeExtInfoValueForAllFaelleOfBillingSystem(tName.getText(),
Collections.singletonList(split[0]));
ldConstants.remove(selection);
BillingSystem.removeBillingSystemConstant(result[0], selection);
});
}
}
}
private static long convertToBytes(String memory) {
String lower = memory.toLowerCase().trim();
Matcher m = Pattern.compile("([0-9]+)([a-z]+)?").matcher(lower);
long value;
String suffix;
if (m.matches()) {
value = Long.parseLong(m.group(1));
suffix = m.group(2);
} else {
throw new NumberFormatException("Failed to parse string: " + memory);
}
long memoryAmountBytes = value;
if (StringUtils.containsIgnoreCase(suffix, "k")) {
memoryAmountBytes = value * K;
} else if (StringUtils.containsIgnoreCase(suffix, "m")) {
memoryAmountBytes = value * M;
} else if (StringUtils.containsIgnoreCase(suffix, "g")) {
memoryAmountBytes = value * G;
} else if (StringUtils.containsIgnoreCase(suffix, "t")) {
memoryAmountBytes = value * T;
}
if (0 > memoryAmountBytes) {
throw new NumberFormatException("Conversion of " + memory + " exceeds Long.MAX_VALUE");
}
return memoryAmountBytes;
}
public String getPoster(String query) {
// log.debug("Get Poster: " + query);
CloseableHttpResponse response = null;
try {
URIBuilder builder = new URIBuilder(this.baseUrl);
builder.setParameter("id", "movie").setParameter("multiple", "0").setParameter("mod", "json")
.setParameter("code", "utf_in_out").setParameter("limit", String.valueOf(limit))
.setParameter("q", query);
HttpGet httpGet = new HttpGet(builder.build());
response = httpClient.execute(httpGet);
JSONObject json = new JSONObject(EntityUtils.toString(response.getEntity()));
// log.debug(json.toString());
if(json.has("items")) {
JSONArray jarr = json.getJSONArray("items");
for(int i = 0; i < jarr.length(); i++) {
String[] arr = StringUtils.split(jarr.getString(i), "|");
if(arr.length > 2) {
if(StringUtils.containsIgnoreCase(arr[0], query)) {
return arr[2];
}
}
}
}
} catch (URISyntaxException | IOException | ParseException | JSONException e) {
log.error(e.getMessage());
} finally {
HttpClientUtils.closeQuietly(response);
}
return null;
}
@Override
public void onException(final Exception e) {
Throwable root = ExceptionUtils.getRootCause(e);
String message = root.getMessage();
if (root instanceof SyncopeClientException) {
SyncopeClientException sce = (SyncopeClientException) root;
if (sce.getType() == ClientExceptionType.InvalidSecurityAnswer) {
message = getApplication().getResourceSettings().getLocalizer().
getString("invalid.security.answer", null);
} else if (!sce.isComposite()) {
message = sce.getElements().stream().collect(Collectors.joining(", "));
}
} else if (root instanceof AccessControlException || root instanceof ForbiddenException) {
Error error = StringUtils.containsIgnoreCase(message, "expired")
? Error.SESSION_EXPIRED
: Error.AUTHORIZATION;
message = getApplication().getResourceSettings().getLocalizer().
getString(error.key(), null, null, null, null, error.fallback());
} else if (root instanceof BadRequestException || root instanceof WebServiceException) {
message = getApplication().getResourceSettings().getLocalizer().
getString(Error.REST.key(), null, null, null, null, Error.REST.fallback());
}
message = getApplication().getResourceSettings().getLocalizer().
getString(message, null, null, null, null, message);
error(message);
}
public List<SailfishURI> completeDictURI(String query) {
if (StringUtils.isEmpty(query)) {
return new ArrayList<>(loadDictionaries());
}
List<SailfishURI> result = new ArrayList<>();
for (SailfishURI dictUri : loadDictionaries()) {
if (StringUtils.containsIgnoreCase(dictUri.toString(), query)) {
result.add(dictUri);
}
}
return result;
}
private static Boolean isMatch(Boolean exactMatch, String query, String string) {
if (string != null) {
if (exactMatch) {
if (StringUtils.containsIgnoreCase(string, query)) {
return true;
}
} else {
if (StringUtils.containsIgnoreCase(string, query)) {
return true;
}
}
}
return false;
}
/**
* Loads the prescribed settlement template
*/
private void loadSettlementTemplate() {
// logger.config("loadSettlementTemplate()");
String templateString = "";
SettlementConfig settlementConfig = SimulationConfig.instance().getSettlementConfiguration();
for (String s: argList) {
if (StringUtils.containsIgnoreCase(s, "-country:")) {
List<String> countries = UnitManager.getAllCountryList();
// System.out.println(countries);
logger.info("has " + s);
for (String c: countries) {
// logger.info(c);
if (s.contains(c) || s.contains(c.toLowerCase())) {
countryString = c;
logger.info("Found country string: " + countryString);
}
}
}
if (StringUtils.containsIgnoreCase(s, "-sponsor:")) {
List<String> sponsors = UnitManager.getAllShortSponsors();
// System.out.println(sponsors);
logger.info("has " + s);
for (String ss: sponsors) {
// logger.info(ss);
if (s.contains(ss) || s.contains(ss.toLowerCase())) {
sponsorString = ss;
logger.info("Found sponsor string: " + sponsorString);
}
}
}
if (StringUtils.containsIgnoreCase(s, "-template:")) {
settlementConfig.clearInitialSettlements();
Collection<String> templates = settlementConfig.getTemplateMap().values();//MarsProjectHeadlessStarter.getTemplates();
// System.out.println(templates);
logger.info("has " + s);
templatePhaseString = s.substring(s.indexOf(":") + 1, s.length());
logger.info("Found templatePhaseString: " + templatePhaseString);
for (String t: templates) {
if (StringUtils.containsIgnoreCase(t, templatePhaseString)) {
templateString = t;
}
}
}
}
SettlementTemplate settlementTemplate = settlementConfig.getSettlementTemplate(templateString);
String longSponsorName = ReportingAuthorityType.convertSponsorNameShort2Long(sponsorString);
List<String> settlementNames = settlementConfig.getSettlementNameList(longSponsorName);
if (settlementNames.isEmpty()) {
settlementNames = settlementConfig.getSettlementNameList("Mars Society (MS)");
}
int size = settlementNames.size();
String settlementName = "";
int rand = RandomUtil.getRandomInt(size-1);
settlementName = settlementNames.get(rand);
settlementConfig.addInitialSettlement(settlementName,
templateString,
settlementTemplate.getDefaultPopulation(),
settlementTemplate.getDefaultNumOfRobots(),
longSponsorName,
"0.0", //latitude,
"0.0" //longitude
);
}
@Override
public void append(LogEvent e) {
// return if console channel isn't available
if (DiscordSRV.getPlugin().getConsoleChannel() == null) return;
// return if this is not an okay level to send
boolean isAnOkayLevel = false;
for (String consoleLevel : DiscordSRV.config().getStringList("DiscordConsoleChannelLevels")) if (consoleLevel.toLowerCase().equals(e.getLevel().name().toLowerCase())) isAnOkayLevel = true;
if (!isAnOkayLevel) return;
String line = e.getMessage().getFormattedMessage();
// remove coloring
line = DiscordUtil.aggressiveStrip(line);
// do nothing if line is blank before parsing
if (StringUtils.isBlank(line)) return;
// apply regex to line
line = applyRegex(line);
// do nothing if line is blank after parsing
if (StringUtils.isBlank(line)) return;
// escape markdown
line = DiscordUtil.escapeMarkdown(line);
// apply formatting
line = LangUtil.Message.CONSOLE_CHANNEL_LINE.toString()
.replace("%date%", TimeUtil.timeStamp())
.replace("%level%", e.getLevel().name().toUpperCase())
.replace("%line%", line)
;
// if line contains a blocked phrase don't send it
boolean whitelist = DiscordSRV.config().getBoolean("DiscordConsoleChannelDoNotSendPhrasesActsAsWhitelist");
List<String> phrases = DiscordSRV.config().getStringList("DiscordConsoleChannelDoNotSendPhrases");
for (String phrase : phrases) {
boolean contained = StringUtils.containsIgnoreCase(line, phrase);
if (contained != whitelist) return;
}
// queue final message
DiscordSRV.getPlugin().getConsoleMessageQueue().add(line);
}
public static String getGeneMutationNameInVariantSummary(Gene gene, String queryAlteration) {
StringBuilder sb = new StringBuilder();
if (queryAlteration == null) {
return "";
} else {
queryAlteration = queryAlteration.trim();
}
Alteration alteration = AlterationUtils.findAlteration(gene, queryAlteration);
if (alteration == null) {
alteration = AlterationUtils.getAlteration(gene.getHugoSymbol(), queryAlteration, null, null, null, null);
AlterationUtils.annotateAlteration(alteration, queryAlteration);
}
if (AlterationUtils.isGeneralAlterations(queryAlteration, true)) {
sb.append(gene.getHugoSymbol() + " " + queryAlteration.toLowerCase());
} else if (StringUtils.equalsIgnoreCase(queryAlteration, "gain")) {
queryAlteration = "amplification (gain)";
sb.append(gene.getHugoSymbol() + " " + queryAlteration);
} else if (StringUtils.equalsIgnoreCase(queryAlteration, "loss")) {
queryAlteration = "deletion (loss)";
sb.append(gene.getHugoSymbol() + " " + queryAlteration);
} else if (StringUtils.containsIgnoreCase(queryAlteration, "fusion")) {
queryAlteration = queryAlteration.replace("Fusion", "fusion");
sb.append(queryAlteration);
} else if (AlterationUtils.isGeneralAlterations(queryAlteration, false)
|| (alteration.getConsequence() != null
&& (alteration.getConsequence().getTerm().equals("inframe_deletion")
|| alteration.getConsequence().getTerm().equals("inframe_insertion")))
|| StringUtils.containsIgnoreCase(queryAlteration, "indel")
|| StringUtils.containsIgnoreCase(queryAlteration, "dup")
|| StringUtils.containsIgnoreCase(queryAlteration, "del")
|| StringUtils.containsIgnoreCase(queryAlteration, "ins")
|| StringUtils.containsIgnoreCase(queryAlteration, "splice")
|| MainUtils.isEGFRTruncatingVariants(queryAlteration)
) {
if (NamingUtils.hasAbbreviation(queryAlteration)) {
sb.append(gene.getHugoSymbol() + " " + NamingUtils.getFullName(queryAlteration) + " (" + queryAlteration + ")");
} else {
sb.append(gene.getHugoSymbol() + " " + queryAlteration);
}
if (!queryAlteration.endsWith("alteration")) {
sb.append(" alteration");
}
} else {
if (queryAlteration.contains(gene.getHugoSymbol())) {
sb.append(queryAlteration);
} else if (NamingUtils.hasAbbreviation(queryAlteration)) {
sb.append(gene.getHugoSymbol() + " " + NamingUtils.getFullName(queryAlteration) + " (" + queryAlteration + ") alteration");
} else {
sb.append(gene.getHugoSymbol() + " " + queryAlteration);
}
String finalStr = sb.toString();
if (!finalStr.endsWith("mutation")
&& !finalStr.endsWith("mutations")
&& !finalStr.endsWith("alteration")
&& !finalStr.endsWith("fusion")
&& !finalStr.endsWith("deletion")
&& !finalStr.endsWith("amplification")
) {
sb.append(" mutation");
}
}
return sb.toString();
}
private boolean isMySql() throws StorageException {
return StringUtils.containsIgnoreCase(getDialect(), "mysql");
}
public ObservableList<Message> getFilteredMessages(Event event, String[] words, int operator){
ObservableList<Message> messages = FXCollections.observableArrayList();
String[] interval = event.getTemporalDescription().split(",");
int timeSliceA = convertDayToTimeSlice(Double.parseDouble(interval[0]));
int timeSliceB = convertDayToTimeSlice(Double.parseDouble(interval[1]));
String term = event.getTextualDescription().split(" ")[0];
NumberFormat formatter = new DecimalFormat("00000000");
for(int i = timeSliceA; i <= timeSliceB; i++){
try {
File textFile = new File(path+File.separator+preprocessing+File.separator+formatter.format(i)+".text");
File timeFile = new File(path+File.separator+preprocessing+File.separator+formatter.format(i)+".time");
File authorFile = new File(path+File.separator+preprocessing+File.separator+formatter.format(i)+".author");
LineIterator textIter = FileUtils.lineIterator(textFile);
LineIterator timeIter = FileUtils.lineIterator(timeFile);
LineIterator authorIter = FileUtils.lineIterator(authorFile);
while(textIter.hasNext()){
String text = textIter.nextLine();
short[] test = new short[words.length];
for(int j = 0; j < words.length; j++){
if(StringUtils.containsIgnoreCase(text,words[j])){
test[j] = 1;
}else{
test[j] = 0;
}
}
if(StringUtils.containsIgnoreCase(text,term)){
int testSum = ArrayUtils.sum(test, 0, test.length-1);
String author = authorIter.nextLine();
String time = timeIter.nextLine();
if(operator==0 && testSum == test.length){
messages.add(new Message(author,time,text));
}
if(operator==1 && testSum > 0){
messages.add(new Message(author,time,text));
}
}
}
} catch (IOException ex) {
Logger.getLogger(Corpus.class.getName()).log(Level.SEVERE, null, ex);
}
}
return messages;
}
@Override
protected boolean skipCond(final ServerHttpResponseDecorator decorator) {
return decorator.getHeaders().getContentType() == null
|| !StringUtils.containsIgnoreCase(decorator.getHeaders().getContentType().toString(), "html");
}
@SuppressWarnings("deprecation")
@Override
public void processEvent(EventRequest portletReq, EventResponse portletResp) throws PortletException, IOException {
portletResp.setRenderParameters(portletReq);
long tid = Thread.currentThread().getId();
portletReq.setAttribute(THREADID_ATTR, tid);
StringWriter writer = new StringWriter();
JSR286SpecTestCaseDetails tcd = new JSR286SpecTestCaseDetails();
// Create result objects for the tests
/* TestCase: V2AddlRequestTests_SPEC2_11_EventReq_contentType1 */
/* Details: "The getResponseContentType method returns a String */
/* representing the default content type the portlet container */
/* assumes for the output" */
TestResult tr0 = tcd.getTestResultFailed(V2ADDLREQUESTTESTS_SPEC2_11_EVENTREQ_CONTENTTYPE1);
if (portletReq.getResponseContentType() != null && !portletReq.getResponseContentType().isEmpty())
tr0.setTcSuccess(true);
tr0.writeTo(writer);
/* TestCase: V2AddlRequestTests_SPEC2_11_EventReq_contentType2 */
/* Details: "The getResponseContentTypes method returns an */
/* Enumeration of String elements representing the acceptable content */
/* types for the output in order of preference" */
TestResult tr1 = tcd.getTestResultFailed(V2ADDLREQUESTTESTS_SPEC2_11_EVENTREQ_CONTENTTYPE2);
Enumeration<String> contentTypesTr1 = portletReq.getResponseContentTypes();
if (contentTypesTr1 != null && contentTypesTr1.hasMoreElements() && !contentTypesTr1.nextElement().isEmpty())
tr1.setTcSuccess(true);
tr1.writeTo(writer);
/* TestCase: V2AddlRequestTests_SPEC2_11_EventReq_contentType3 */
/* Details: "The first element of the Enumeration returned by the */
/* getResponseContentTypes method must equal the value returned by */
/* the getResponseContentType method" */
TestResult tr2 = tcd.getTestResultFailed(V2ADDLREQUESTTESTS_SPEC2_11_EVENTREQ_CONTENTTYPE3);
if (portletReq.getResponseContentTypes().nextElement().equals(portletReq.getResponseContentType()))
tr2.setTcSuccess(true);
tr2.writeTo(writer);
/* TestCase: V2AddlRequestTests_SPEC2_11_EventReq_windowId4 */
/* Details: "The string returned by getWindowID method must be the */
/* same ID used for scoping portlet-scope session attributes" */
TestResult tr5 = tcd.getTestResultFailed(V2ADDLREQUESTTESTS_SPEC2_11_EVENTREQ_WINDOWID4);
portletReq.getPortletSession().setAttribute("tr5", portletReq.getWindowID(), PORTLET_SCOPE);
String tr5SessionAttribute = (String) portletReq.getPortletSession().getAttribute("javax.portlet.p." + portletReq.getWindowID() + "?tr5",
APPLICATION_SCOPE);
if (tr5SessionAttribute != null && tr5SessionAttribute.equals(portletReq.getWindowID())) {
tr5.setTcSuccess(true);
} else {
tr5.appendTcDetail("Couldn't find javax.portlet.p." + portletReq.getWindowID() + ".tr5 attribute");
}
tr5.writeTo(writer);
/* TestCase: V2AddlRequestTests_SPEC2_11_EventReq_contentType8 */
/* Details: "Within the processEvent method, the content type must */
/* include only the MIME type, not the character set" */
TestResult tr6 = tcd.getTestResultFailed(V2ADDLREQUESTTESTS_SPEC2_11_EVENTREQ_CONTENTTYPE8);
if (!StringUtils.containsIgnoreCase(portletReq.getResponseContentType(), "UTF-8"))
tr6.setTcSuccess(true);
tr6.writeTo(writer);
portletReq.getPortletSession().setAttribute(RESULT_ATTR_PREFIX + "AddlRequestTests_SPEC2_11_EventReq", writer.toString(), APPLICATION_SCOPE);
}
/**
* Returns whether the warning type is of the specified type.
*
* @param matcher
* the matcher
* @param type
* the type to match with
*
* @return {@code true} if the warning type is of the specified type
*/
private boolean isOfType(final Matcher matcher, final String type) {
return StringUtils.containsIgnoreCase(matcher.group(7), type);
}