List of usage examples for org.apache.commons.lang3 ArrayUtils remove
private static Object remove(final Object array, final int index)
Removes the element at the specified position from the specified array.
From source file:com.cdd.bao.Main.java
public static void main(String[] argv) { //org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.OFF); org.apache.logging.log4j.status.StatusLogger.getLogger().setLevel(org.apache.logging.log4j.Level.OFF); if (argv.length > 0 && (argv[0].equals("-h") || argv[0].equals("--help"))) { printHelp();//w w w .jav a 2 s .co m return; } // look for additional options that affect overall state String[] extraOnto = null, exclOnto = null; for (int n = 0; n < argv.length;) { if (argv[n].startsWith("--onto")) { argv = ArrayUtils.remove(argv, n); while (n < argv.length) { if (argv[n].startsWith("-")) break; extraOnto = ArrayUtils.add(extraOnto, argv[n]); argv = ArrayUtils.remove(argv, n); } } else if (argv[n].startsWith("--excl")) { argv = ArrayUtils.remove(argv, n); while (n < argv.length) { if (argv[n].startsWith("-")) break; exclOnto = ArrayUtils.add(exclOnto, argv[n]); argv = ArrayUtils.remove(argv, n); } } else n++; } Vocabulary.setExtraOntology(extraOnto); Vocabulary.setExclOntology(exclOnto); // main command-induced functionality if (argv.length == 0) new MainApplication().exec(new String[0]); else if (argv[0].equals("edit")) { String[] subset = Arrays.copyOfRange(argv, 1, argv.length); new MainApplication().exec(subset); } else if (argv[0].equals("geneont")) { try { ImportGeneOntology impgo = new ImportGeneOntology(); impgo.load(argv[1]); impgo.save(argv[2]); } catch (Exception ex) { ex.printStackTrace(); } } else if (argv[0].equals("filter")) { try { OntologyFilter filt = new OntologyFilter(); filt.load(argv[1]); filt.save(argv[2]); } catch (Exception ex) { ex.printStackTrace(); } } else if (argv[0].equals("compare")) { try { diffVocab(ArrayUtils.remove(argv, 0)); } catch (Exception ex) { ex.printStackTrace(); } } else if (argv[0].equals("compile")) { try { compileSchema(ArrayUtils.remove(argv, 0)); } catch (Exception ex) { ex.printStackTrace(); } } else if (argv[0].equals("check")) { try { checkTemplate(ArrayUtils.remove(argv, 0)); } catch (Exception ex) { ex.printStackTrace(); } } else if (argv[0].equals("import")) { try { importKeywords(ArrayUtils.remove(argv, 0)); } catch (Exception ex) { ex.printStackTrace(); } } else if (argv[0].equals("scanaxioms")) { try { new ScanAxioms().exec(); } catch (Exception ex) { ex.printStackTrace(); } } else { Util.writeln("Unknown option '" + argv[0] + "'"); printHelp(); } }
From source file:com.netflix.hystrix.contrib.javanica.utils.CommonUtils.java
public static Object[] createArgsForFallback(Object[] args, MetaHolder metaHolder, Throwable exception) { if (metaHolder.isExtendedFallback()) { if (metaHolder.isExtendedParentFallback()) { args[args.length - 1] = exception; } else {//from w ww .jav a 2s.c o m args = Arrays.copyOf(args, args.length + 1); args[args.length - 1] = exception; } } else { if (metaHolder.isExtendedParentFallback()) { args = ArrayUtils.remove(args, args.length - 1); } } return args; }
From source file:com.joyent.manta.client.PruneEmpytParentDirectoryStrategy.java
/** * This will delete empty parent directories up to the root. * * @param client - A valid client./*from ww w . j a v a 2 s.co m*/ * @param path - THe complete path that you want to start with. * @param limit - The limit of directories to delete. * @throws IOException - this is thrown from */ static void pruneParentDirectories(final MantaClient client, final MantaHttpHeaders headers, final String path, final int limit) throws IOException { // First thing first, delete the child directory. client.delete(path, headers, null); // Generating all parent paths. String[] directories = MantaUtils.writeablePrefixPaths(path); ArrayUtils.reverse(directories); // Removing first element, because we have already deleted it. directories = ArrayUtils.remove(directories, 0); int actualLimit = limit; if (actualLimit > directories.length || actualLimit == PRUNE_ALL_PARENTS) { actualLimit = directories.length; } for (int i = 0; i < actualLimit; i++) { try { LOG.debug("************ Deleting Index : " + i + " name " + directories[i]); client.delete(directories[i], headers, null); } catch (MantaClientHttpResponseException responseException) { if (responseException.getServerCode().equals(MantaErrorCode.RESOURCE_NOT_FOUND_ERROR)) { continue; } else if (responseException.getServerCode() != MantaErrorCode.DIRECTORY_NOT_EMPTY_ERROR) { throw responseException; } } } }
From source file:com.techcavern.wavetact.ircCommands.fun.Roll.java
@Override public void onCommand(String command, User user, PircBotX network, String prefix, Channel channel, boolean isPrivate, int userPermLevel, String... args) throws Exception { int x = 1;//from w w w. j a v a2 s. co m try { x = Integer.parseInt(args[0]); args = ArrayUtils.remove(args, 0); } catch (NumberFormatException e) { } if (x > 50) { IRCUtils.sendError(user, network, channel, "You may not roll the dice more than 50 times", prefix); return; } else if (x <= 0) { IRCUtils.sendError(user, network, channel, "I cannot roll the dice that amount of times", prefix); IRCUtils.sendError(user, network, channel, "I cannot roll the dice that amount of times", prefix); return; } String[] dice = StringUtils.split(args[0], "d"); if (Integer.parseInt(dice[0]) > 100) { IRCUtils.sendError(user, network, channel, "You may not roll more than 100 dice at a time", prefix); } else if (Integer.parseInt(dice[1]) > 100) { IRCUtils.sendError(user, network, channel, "You may not roll more than 100 sided dice", prefix); } else if (Integer.parseInt(dice[0]) <= 0) { IRCUtils.sendError(user, network, channel, "I cannot find that amount of dice", prefix); } else if (Integer.parseInt(dice[1]) <= 0) { IRCUtils.sendError(user, network, channel, "I cannot find dice with that amount of sides", prefix); } else { List<Integer> list = new ArrayList<>(); for (int i = 0; i < x; i++) { int b = 0; for (int j = 0; j < Integer.parseInt(dice[0]); j++) { { b += Registry.randNum.nextInt(Integer.parseInt(dice[1]) + 1); } } list.add(b); } IRCUtils.sendMessage(user, network, channel, StringUtils.join(list, ", "), prefix); } }
From source file:com.techcavern.wavetact.ircCommands.fun.Say.java
@Override public void onCommand(String command, User user, PircBotX network, String prefix, Channel channel, boolean isPrivate, int userPermLevel, String... args) throws Exception { String channelname = null;/*w w w .jav a 2 s . c om*/ if (!isPrivate) { channelname = prefix + channel.getName(); } else { channelname = user.getNick(); } if (args.length > 1 && args[0].startsWith("#")) { channelname = args[0]; args = ArrayUtils.remove(args, 0); } if (command.equalsIgnoreCase("act") || command.equalsIgnoreCase("do") || command.equalsIgnoreCase("a")) { Registry.messageQueue.get(network) .add("PRIVMSG " + channelname + " :\u0001ACTION " + StringUtils.join(args, " ") + "\u0001"); } else if (command.equalsIgnoreCase("prism")) { Registry.messageQueue.get(network) .add("PRIVMSG " + channelname + " :" + GeneralUtils.prism(StringUtils.join(args, " "))); } else { if (args.length > 1 && !Character.isLetterOrDigit(args[0].charAt(0)) && args[0].charAt(1) == "#".charAt(0)) { channelname = args[0]; args = ArrayUtils.remove(args, 0); } Registry.messageQueue.get(network).add("PRIVMSG " + channelname + " :" + StringUtils.join(args, " ")); } }
From source file:com.techcavern.wavetact.ircCommands.anonymonity.Act.java
@Override public void onCommand(User user, PircBotX network, String prefix, Channel channel, boolean isPrivate, int userPermLevel, String... args) throws Exception { Channel chan;/*from ww w .j av a 2s . c om*/ if (args.length > 1) { prefix = IRCUtils.getPrefix(network, args[0]); if (!prefix.isEmpty()) chan = IRCUtils.getChannelbyName(network, args[0].replace(prefix, "")); else chan = IRCUtils.getChannelbyName(network, args[0]); if (chan != null) args = ArrayUtils.remove(args, 0); else chan = channel; } else { chan = channel; } if (PermUtils.getPermLevel(network, user.getNick(), chan) >= 5) { IRCUtils.sendAction(user, network, chan, StringUtils.join(args, " ").replace("\n", " "), prefix); } else { ErrorUtils.sendError(user, "Permission denied"); } }
From source file:com.techcavern.wavetact.ircCommands.anonymonity.Say.java
@Override public void onCommand(User user, PircBotX network, String prefix, Channel channel, boolean isPrivate, int userPermLevel, String... args) throws Exception { Channel chan;/*from w w w. ja v a 2 s . co m*/ if (args.length > 1) { prefix = IRCUtils.getPrefix(network, args[0]); if (!prefix.isEmpty()) chan = IRCUtils.getChannelbyName(network, args[0].replace(prefix, "")); else chan = IRCUtils.getChannelbyName(network, args[0]); if (chan != null) args = ArrayUtils.remove(args, 0); else chan = channel; } else { chan = channel; } if (PermUtils.getPermLevel(network, user.getNick(), chan) >= 5) { IRCUtils.sendMessage(user, network, chan, StringUtils.join(args, " ").replace("\n", " "), prefix); } else { ErrorUtils.sendError(user, "Permission denied"); } }
From source file:apexproject.ShoppingCart.java
public void removeTour(int tour) { index = ArrayUtils.indexOf(chosenTours, tour); if (index >= 0) { this.chosenTours = ArrayUtils.remove(chosenTours, index); this.nrOfAdults = ArrayUtils.remove(nrOfAdults, index); this.nrOfChildren = ArrayUtils.remove(nrOfChildren, index); this.hotelPickupRequested = ArrayUtils.remove(hotelPickupRequested, index); this.hotelLocation = ArrayUtils.remove(hotelLocation, index); }/*from w ww. ja v a 2 s . c o m*/ //LAGA ETTA else if (index < 0) { System.out.println("Listinn er tmur!"); } else { System.out.println("Enginn dayTour me etta ID"); } }
From source file:com.techcavern.wavetact.ircCommands.utils.CustomCMD.java
@Override public void onCommand(User user, PircBotX network, String prefix, Channel channel, boolean isPrivate, int userPermLevel, String... args) throws Exception { String chan = null;/*from w w w .java2 s. com*/ String net = null; boolean isAction = false; boolean modify = false; boolean remove = false; for (int i = 0; i < 1; i++) { if (args[i].equalsIgnoreCase(".") && !GeneralUtils.isInteger(args[i + 1])) { net = IRCUtils.getNetworkNameByNetwork(network); chan = channel.getName(); args = ArrayUtils.remove(args, i); i--; } else if (args[i].equalsIgnoreCase("a") && !GeneralUtils.isInteger(args[i + 1])) { isAction = true; args = ArrayUtils.remove(args, i); i--; } } String command; if (args[0].startsWith("+")) { command = args[0].replaceFirst("\\+", ""); modify = true; } else if (args[0].startsWith("-")) { command = args[0].replaceFirst("\\-", ""); remove = true; } else { command = args[0]; } Record customCommand = DatabaseUtils.getChannelCustomCommand(net, chan, command); if (modify && customCommand != null && userPermLevel >= customCommand.getValue(CUSTOMCOMMANDS.PERMLEVEL) && !customCommand.getValue(CUSTOMCOMMANDS.ISLOCKED)) { customCommand.setValue(CUSTOMCOMMANDS.PERMLEVEL, Integer.parseInt(args[1])); customCommand.setValue(CUSTOMCOMMANDS.VALUE, GeneralUtils.buildMessage(2, args.length, args).replace("\n", " ")); DatabaseUtils.updateCustomCommand(customCommand); IRCUtils.sendMessage(user, network, channel, "Custom Command modified", prefix); } else if (remove && customCommand != null && userPermLevel >= customCommand.getValue(CUSTOMCOMMANDS.PERMLEVEL) && !customCommand.getValue(CUSTOMCOMMANDS.ISLOCKED)) { DatabaseUtils.removeCustomCommand(net, chan, command); IRCUtils.sendMessage(user, network, channel, "Custom Command removed", prefix); } else if (customCommand == null && IRCUtils.getGenericCommand(command) == null) { DatabaseUtils.addCustomCommand(net, chan, command, Integer.parseInt(args[1]), GeneralUtils.buildMessage(2, args.length, args).replace("\n", " "), false, isAction); IRCUtils.sendMessage(user, network, channel, "Custom Command added", prefix); } else { ErrorUtils.sendError(user, "Command already exists (If you were adding) or Command does not exist, or The command is locked (Either could be the problem if you were modifing)"); } }
From source file:com.techcavern.wavetact.ircCommands.misc.CustomCMD.java
@Override public void onCommand(String command, User user, PircBotX network, String prefix, Channel channel, boolean isPrivate, int userPermLevel, String... args) throws Exception { String chan = null;/*from w w w. j ava 2 s . com*/ String net = null; boolean isAction = false; boolean isModify = false; boolean isDelete = false; if (args[0].equalsIgnoreCase(".")) { net = IRCUtils.getNetworkNameByNetwork(network); chan = channel.getName(); args = ArrayUtils.remove(args, 0); } if (command.equalsIgnoreCase("cact") || command.equalsIgnoreCase("customact")) { isAction = true; } String cCommand; if (args[0].startsWith("+")) { cCommand = args[0].replaceFirst("\\+", ""); isModify = true; } else if (args[0].startsWith("-")) { cCommand = args[0].replaceFirst("\\-", ""); isDelete = true; } else { cCommand = args[0]; } cCommand = cCommand.toLowerCase(); Record customCommand = DatabaseUtils.getChannelCustomCommand(net, chan, cCommand); if (isModify && customCommand != null && userPermLevel >= customCommand.getValue(CUSTOMCOMMANDS.PERMLEVEL) && !customCommand.getValue(CUSTOMCOMMANDS.ISLOCKED)) { customCommand.setValue(CUSTOMCOMMANDS.PERMLEVEL, Integer.parseInt(args[1])); customCommand.setValue(CUSTOMCOMMANDS.ISACTION, isAction); customCommand.setValue(CUSTOMCOMMANDS.VALUE, GeneralUtils.buildMessage(2, args.length, args).replace("\n", " ")); DatabaseUtils.updateCustomCommand(customCommand); IRCUtils.sendMessage(user, network, channel, "Custom Command modified", prefix); } else if (isDelete && customCommand != null && userPermLevel >= customCommand.getValue(CUSTOMCOMMANDS.PERMLEVEL) && !customCommand.getValue(CUSTOMCOMMANDS.ISLOCKED)) { DatabaseUtils.removeCustomCommand(net, chan, cCommand); IRCUtils.sendMessage(user, network, channel, "Custom Command removed", prefix); } else if (customCommand == null && Registry.ircCommands.get(cCommand) == null && !isDelete && !isModify) { DatabaseUtils.addCustomCommand(net, chan, cCommand, Integer.parseInt(args[1]), GeneralUtils.buildMessage(2, args.length, args).replace("\n", " "), false, isAction); IRCUtils.sendMessage(user, network, channel, "Custom Command added", prefix); } else { IRCUtils.sendError(user, network, channel, "Command already exists (If you were adding) or Command does not exist, or The command is locked (Either could be the problem if you were modifying)", prefix); } }