下面列出了org.apache.commons.lang3.ArrayUtils#remove ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Subscribe
private void onMenuEntryAdded(MenuEntryAdded event)
{
if ((event.getOption().equals("Floating <col=ff9040>World Map</col>") && config.shouldRightClickMap()) ||
(event.getTarget().equals("<col=ff9040>XP drops</col>") && config.shouldRightClickXp()) ||
(event.getOption().equals("Auto retaliate") && config.shouldRightClickRetaliate()))
{
forceRightClickFlag = true;
}
MenuEntry[] entries = client.getMenuEntries();
if (config.shouldBlockCompass())
{
for (int i = entries.length - 1; i >= 0; i--)
{
if (entries[i].getOption().equals("Look North"))
{
entries = ArrayUtils.remove(entries, i);
i--;
}
}
client.setMenuEntries(entries);
}
}
static String[] processExecuteArgs(String[] args) {
int index = -1;
for (int i = 0; i < args.length; i++) {
if (args[i].equals("-" + EXECUTE_ARGS)) {
index = i;
break;
}
}
if (index >= 0 && ((index + 1 >= args.length) || (index + 1 < args.length && keywordSet
.contains(args[index + 1])))) {
return ArrayUtils.remove(args, index);
} else if (index == -1) {
return args;
} else {
StringBuilder executeCommand = new StringBuilder();
for (int j = index + 1; j < args.length; j++) {
executeCommand.append(args[j]).append(" ");
}
executeCommand.deleteCharAt(executeCommand.length() - 1);
execute = executeCommand.toString();
hasExecuteSQL = true;
args = Arrays.copyOfRange(args, 0, index);
return args;
}
}
@Override
public Object resolveNode(String placeholderName) {
if (StringUtils.isEmpty(placeholderName)) {
return getValue();
}
String[] parts = placeholderName.split("\\.");
String field = parts[0];
Object value = getChild(field);
if (value instanceof NodePlaceholderResolver) {
String subPlaceholder = null;
if (parts.length > 1) {
parts = ArrayUtils.remove(parts, 0);
subPlaceholder = StringUtils.join(parts, ".");
}
return ((NodePlaceholderResolver) value).resolveNode(subPlaceholder);
}
return value;
}
@Override
public void moveCategory(String categoryCode, String newParentCode) {
Cache cache = this.getCache();
Category categoryNode1 = this.getCategory(categoryCode);
Category categoryNode2 = this.getCategory(newParentCode);
Category oldParent = this.getCategory(categoryNode1.getParentCode());
int index1 = Arrays.asList(oldParent.getChildrenCodes()).indexOf(categoryCode);
String[] newChildren = ArrayUtils.remove(oldParent.getChildrenCodes(), index1);
oldParent.setChildrenCodes(newChildren);
cache.put(CATEGORY_CACHE_NAME_PREFIX + oldParent.getCode(), oldParent);
String[] oldChildDest = categoryNode2.getChildrenCodes();
categoryNode1.setParentCode(categoryNode2.getCode());
cache.put(CATEGORY_CACHE_NAME_PREFIX + categoryNode1.getCode(), categoryNode1);
String[] newChildren2 = ArrayUtils.add(oldChildDest, categoryNode1.getCode());
categoryNode2.setChildrenCodes(newChildren2);
cache.put(CATEGORY_CACHE_NAME_PREFIX + categoryNode2.getCode(), categoryNode2);
}
public boolean removeResolution(Resolution res) {
synchronized (this) {
int index = -1;
for (int i = 0; i < resolutions.length; i++) {
if (Arrays.equals(
resolutions[i].getResolutionPerDimension(),
res.getResolutionPerDimension())) {
index = i;
break;
}
}
if (index >= 0) {
resolutions = ArrayUtils.remove(resolutions, index);
return true;
}
return false;
}
}
static String[] removePasswordArgs(String[] args) {
int index = -1;
for (int i = 0; i < args.length; i++) {
if (args[i].equals("-" + PASSWORD_ARGS)) {
index = i;
break;
}
}
if (index >= 0 && ((index + 1 >= args.length) || (index + 1 < args.length && keywordSet
.contains(args[index + 1])))) {
return ArrayUtils.remove(args, index);
}
return args;
}
private void removeMacro(MacroEntry macro) {
MACROS.remove(macro);
if (macro.name.isPresent()) {
MC.gameSettings.keyBindings =
ArrayUtils.remove(
MC.gameSettings.keyBindings,
ArrayUtils.indexOf(MC.gameSettings.keyBindings, macro.getBind()));
}
// remove the category if there are no named macros to prevent crash
// TODO: fix crash when a category is empty
if (MACROS.stream().noneMatch(entry -> !entry.isAnonymous())) {
KeyBinding.getKeybinds().remove("Macros");
}
}
public Object exec(String script, Map<String,Object> values) throws ScriptException {
// handle return statement
String[] lines = script.split("\\r?\\n");
String returnExpr = null;
for (int i = lines.length - 1; i >= 0; i--) {
String line = lines[i].trim();
if (!line.isEmpty() && !line.startsWith("#")) {
if (line.startsWith("return")) {
returnExpr = line.substring(6).trim();
lines = ArrayUtils.remove(lines, i);
script = String.join("\n", lines);
}
break;
}
}
Bindings bindings = new SimpleBindings(values);
scriptContext.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
ScriptEngine scriptEngine = getScriptEngine();
scriptEngine.eval(script, scriptContext);
if (returnExpr != null) {
return scriptEngine.eval(returnExpr, scriptContext);
}
else {
return null;
}
}
protected String[] splitLines(String content,boolean removeBlank)
{
String[] arr = UITools.stringLineSplit(content,removeBlank);
if(skipFirstLine())
arr = ArrayUtils.remove(arr,0);
return arr;
}
private static String[] clearLogFilenameParam(String[] args) {
System.clearProperty(LOG_FILE_PROPERTY);
int idx = Arrays.asList(args).indexOf(LOG_FILE_PARAM);
if (-1 != idx) {
if (args.length > idx + 1)
args = ArrayUtils.remove(args, idx + 1); // value
args = ArrayUtils.remove(args, idx); // name
}
return args;
}
public static ArrayAdapter<? extends CharSequence> createFromResource(@NonNull Context context, @ArrayRes int textArrayResId, @LayoutRes int layoutTypeResId) {
CharSequence[] strings = context.getResources().getTextArray(textArrayResId);
if (!Reddit.canUseNightModeAuto) {
strings = ArrayUtils.remove(strings, SettingValues.NightModeState.AUTOMATIC.ordinal());
}
return new ArrayAdapter<>(context, layoutTypeResId, Arrays.asList(strings));
}
private IPage updateOldParent(IPage pageToMove, boolean draft, Cache cache) {
IPage oldParent = (draft) ? this.getDraftPage(pageToMove.getParentCode()) : this.getOnlinePage(pageToMove.getParentCode());
if (null == oldParent) {
return null;
}
int index = Arrays.asList(oldParent.getChildrenCodes()).indexOf(pageToMove.getCode());
if (index > -1) {
//rimuovo l'elemento dal vecchio parent
String[] newChildren = ArrayUtils.remove(oldParent.getChildrenCodes(), index);
((Page) oldParent).setChildrenCodes(newChildren);
cache.put(((draft) ? DRAFT_PAGE_CACHE_NAME_PREFIX : ONLINE_PAGE_CACHE_NAME_PREFIX) + oldParent.getCode(), oldParent);
}
return oldParent;
}
/**
* This method removes an element from a list of strings.
*
* @param list The list to remove from.
* @param index The index of the element to remove from the list.
* @param delimiter The list delimiter.
* @return The new list.
*/
@Action(name = "List Remover",
outputs = {
@Output(RESPONSE),
@Output(RETURN_RESULT),
@Output(RETURN_CODE)
},
responses = {
@Response(text = SUCCESS, field = RETURN_CODE, value = RETURN_CODE_SUCCESS, matchType = MatchType.COMPARE_EQUAL),
@Response(text = FAILURE, field = RETURN_CODE, value = RETURN_CODE_FAILURE, matchType = MatchType.COMPARE_EQUAL, isOnFail = true, isDefault = true)
})
public Map<String, String> removeElement(@Param(value = LIST, required = true) String list,
@Param(value = ELEMENT, required = true) String index,
@Param(value = DELIMITER, required = true) String delimiter) {
Map<String, String> result = new HashMap<>();
try {
if (StringUtils.isEmpty(list) || StringUtils.isEmpty(index) || StringUtils.isEmpty(delimiter)) {
throw new RuntimeException(EMPTY_INPUT_EXCEPTION);
} else {
String[] elements = StringUtils.split(list, delimiter);
elements = ArrayUtils.remove(elements, Integer.parseInt(index));
result.put(RESPONSE, SUCCESS);
result.put(RETURN_RESULT, StringUtils.join(elements, delimiter));
result.put(RETURN_CODE, RETURN_CODE_SUCCESS);
}
} catch (Exception e) {
result.put(RESPONSE, FAILURE);
result.put(RETURN_RESULT, e.getMessage());
result.put(RETURN_CODE, RETURN_CODE_FAILURE);
}
return result;
}
@Override
protected void keyTyped(char par1, int par2){
if(par2 == 1) {
NetworkHandler.sendToServer(new PacketAphorismTileUpdate(tile));
} else if(par2 == 200) {
cursorY--;
if(cursorY < 0) cursorY = textLines.length - 1;
} else if(par2 == 208 || par2 == 156) {
cursorY++;
if(cursorY >= textLines.length) cursorY = 0;
} else if(par2 == 28) {
cursorY++;
textLines = ArrayUtils.add(textLines, cursorY, "");
} else if(par2 == 14) {
if(textLines[cursorY].length() > 0) {
textLines[cursorY] = textLines[cursorY].substring(0, textLines[cursorY].length() - 1);
} else if(textLines.length > 1) {
textLines = ArrayUtils.remove(textLines, cursorY);
cursorY--;
if(cursorY < 0) cursorY = 0;
}
} else if(ChatAllowedCharacters.isAllowedCharacter(par1)) {
textLines[cursorY] = textLines[cursorY] + par1;
}
tile.setTextLines(textLines);
super.keyTyped(par1, par2);
}
@Test
public void givenArray_whenRemovingElementAtSpecifiedPosition_thenCorrect() {
int[] oldArray = { 1, 2, 3, 4, 5 };
int[] newArray = ArrayUtils.remove(oldArray, 1);
int[] expectedArray = { 1, 3, 4, 5 };
assertArrayEquals(expectedArray, newArray);
}
public static String getPackage(IFieldStructure fieldStructure, String[] packageName, boolean underscoreAsPackageSeparator) {
String[] classPath = getClassPath(fieldStructure, packageName, true, underscoreAsPackageSeparator);
classPath = ArrayUtils.remove(classPath, classPath.length - 1);
return String.join(".", classPath);
}
public L2MarketDataHelper removeAsk(int pos) {
askPrices = ArrayUtils.remove(askPrices, pos);
askVolumes = ArrayUtils.remove(askVolumes, pos);
askOrders = ArrayUtils.remove(askOrders, pos);
return this;
}
public L2MarketDataHelper removeBid(int pos) {
bidPrices = ArrayUtils.remove(bidPrices, pos);
bidVolumes = ArrayUtils.remove(bidVolumes, pos);
bidOrders = ArrayUtils.remove(bidOrders, pos);
return this;
}
public int[] removeAnElementWithAGivenIndex(int[] array, int index) {
return ArrayUtils.remove(array, index);
}
public ConstraintContext withoutMessage(int index) {
return new ConstraintContext((String[]) ArrayUtils.remove(messageArgs,index));
}