Java Code Examples for org.apache.commons.lang3.ArrayUtils.remove()

The following are Jave code examples for showing how to use remove() of the org.apache.commons.lang3.ArrayUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: EARLGREY   File: Router.java   View Source Code Vote up 6 votes
public RouteDef route(String path){
	
	String[] ruta = path.split("/");
	if(ruta.length > 0){
		if(this.RouteMap.containsKey(ruta[0])){
			RouteDef rt = this.RouteMap.get(ruta[0]);
			ruta = ArrayUtils.remove(ruta,0);
			RouteDef enrutado = rt.route(ruta);
			return enrutado;
		}
		else
		{
			return null;
		}
	}
	else
	{
		return null;
	}
}
 
Example 2
Project: liteBatch   File: DBRowBatchHandler.java   View Source Code Vote up 6 votes
public DBRowBatchHandler(HandlerContext<T> context, JdbcTemplate jdbcTemplate) {
	super(context);
	this.jdbcTemplate = jdbcTemplate;

	Class<T> clazz = context.getClazz();
	fields = clazz.getDeclaredFields();
	for(int i=0;i<fields.length;i++){
		if(fields[i].getName().equals("serialVersionUID")){
			fields = ArrayUtils.remove(fields, i);
			break;
		}
	}

	initDBMetaData();
	prepareSql();
}
 
Example 3
Project: Minecord   File: SayCommand.java   View Source Code Vote up 5 votes
public Result run(String[] argsOrig, MessageReceivedEvent e) {
	
	//Check for proper argument length
	if (argsOrig.length < 2) {
		return new Result(Outcome.WARNING, ":warning: Please specify a message.");
	}
	
	//Extract channel
	String[] args = ArrayUtils.remove(MessageUtils.getContent(e.getMessage(), true), 0);
	TextChannel channel = null;
	if (args[0].matches(MessageUtils.channelRegex)) {
		channel = e.getMessage().getMentionedChannels().get(0);
	} else if (args[0].matches(MessageUtils.idRegex)) {
		channel = DiscordUtils.getTextChannelById(args[0]);
	} else {
		return new Result(Outcome.ERROR, ":x: Not a valid channel!");
	}
	
	//Send the message
	String msg = String.join(" ", ArrayUtils.remove(args, 0));
	channel.sendMessage(msg).queue();
	
	//Log it
	EmbedBuilder eb = new EmbedBuilder();
	Guild guild = channel.getGuild();
	eb.setAuthor(e.getAuthor().getName() + " (" + e.getAuthor().getId() + ")",
		null, e.getAuthor().getAvatarUrl());
	eb.setDescription("**Sent a msg to `" + channel.getName() + "` (" + channel.getId() + ")**\non `" +
		guild.getName() + "` (" + guild.getId() + "):\n" + msg);
	eb.setThumbnail(guild.getIconUrl());
	MessageUtils.log(eb.build());
	
	return new Result(Outcome.SUCCESS);
}
 
Example 4
Project: pnc-repressurized   File: GuiAphorismTile.java   View Source Code Vote up 4 votes
@Override
protected void keyTyped(char par1, int par2) throws IOException {
    if (par2 == Keyboard.KEY_ESCAPE) {
        NetworkHandler.sendToServer(new PacketAphorismTileUpdate(tile));
    } else if (par2 == Keyboard.KEY_LEFT || par2 == Keyboard.KEY_UP) {
        cursorY--;
        if (cursorY < 0) cursorY = textLines.length - 1;
    } else if (par2 == Keyboard.KEY_DOWN || par2 == Keyboard.KEY_NUMPADENTER) {
        cursorY++;
        if (cursorY >= textLines.length) cursorY = 0;
    } else if (par2 == Keyboard.KEY_RETURN) {
        cursorY++;
        textLines = ArrayUtils.add(textLines, cursorY, "");
    } else if (par2 == Keyboard.KEY_BACK) {
        if (textLines[cursorY].length() > 0) {
            textLines[cursorY] = textLines[cursorY].substring(0, textLines[cursorY].length() - 1);
            if (textLines[cursorY].endsWith("\u00a7")) {
                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 (par2 == Keyboard.KEY_DELETE) {
        if (GuiScreen.isShiftKeyDown()) {
            textLines = new String[1];
            textLines[0] = "";
            cursorY = 0;
        } else {
            if (textLines.length > 1) {
                textLines = ArrayUtils.remove(textLines, cursorY);
                if (cursorY > textLines.length - 1)
                    cursorY = textLines.length - 1;
            }
        }
    } else if (ChatAllowedCharacters.isAllowedCharacter(par1)) {
        if (GuiScreen.isAltKeyDown()) {
            if (par1 >= 'a' && par1 <= 'f' || par1 >= 'l' && par1 <= 'o' || par1 == 'r' || par1 >= '0' && par1 <= '9') {
                textLines[cursorY] = textLines[cursorY] + "\u00a7" + par1;
            }
        } else {
            textLines[cursorY] = textLines[cursorY] + par1;
        }
    }
    tile.setTextLines(textLines);
    super.keyTyped(par1, par2);
}
 
Example 5
Project: Minecord   File: Config.java   View Source Code Vote up 4 votes
public static void read(File file) {
	
	//Look for client token
	String[] args = Bot.args;
	if (args.length > 1 && ArrayUtils.contains(args, "-t")) {
		int index = ArrayUtils.indexOf(args, "-t");
		if (index + 1 < args.length) {
			args = ArrayUtils.remove(args, index);
			String token = args[index];
			if (token.matches("{32,}")) {
				System.out.println("Found custom client token: " + token);
				clientToken = token;
				args = ArrayUtils.remove(args, index);
			}
			Bot.args = args;
		}
	}
	
	try {
		//Parse config JSON
		JSONObject config = new JSONObject(FileUtils.readFileToString(file, "UTF-8"));
		if (clientToken == null) {
			clientToken = config.getString("clientToken");
		}
		shardCount = config.getInt("shardCount");
		if (shardCount < 1) shardCount = 1;
		
		owner = config.getString("owner");
		devMode = config.getBoolean("devMode");
		debugMode = config.getBoolean("debugMode");
		logJDA = config.getBoolean("logJDA");
		logChannel = config.getString("logChannel");
		sendServerCount = config.getBoolean("sendServerCount");
		pwToken = config.getString("pwToken");
		netToken = config.getString("netToken");
		orgToken = config.getString("orgToken");
		game = config.getString("game");
		name = config.getString("name");
		prefix = config.getString("prefix");
		respondToMentions = config.getBoolean("respondToMentions");
		notificationTime = config.getInt("notificationTime");
		deleteCommands = config.getBoolean("deleteCommands");
		sendTyping = config.getBoolean("sendTyping");
		invite = config.getString("invite");
		showMemory = config.getBoolean("showMemory");
		elevatedSkipCooldown = config.getBoolean("elevatedSkipCooldown");
		
		JSONArray eu = config.getJSONArray("elevatedUsers");
		for (int i = 0; i < eu.length(); i++) {
			elevatedUsers.add(eu.getString(i));
		}
		
	} catch (JSONException | IOException e) {
		e.printStackTrace();
	}
}
 
Example 6
Project: Minecord   File: MsgCommand.java   View Source Code Vote up 4 votes
public Result run(String[] argsOrig, MessageReceivedEvent e) {
	
	//Check for proper argument length
	if (argsOrig.length < 2) {
		return new Result(Outcome.WARNING, ":warning: Please specify a message.");
	}
	
	//Extract user
	String[] args = ArrayUtils.remove(MessageUtils.getContent(e.getMessage(), true), 0);
	User user = null;
	if (args[0].matches(MessageUtils.mentionRegex)) {
		user = e.getMessage().getMentionedUsers().get(0);
		if (user.getId() == e.getJDA().getSelfUser().getId()) {
			user = e.getMessage().getMentionedUsers().get(1);
		}
	} else if (args[0].matches(MessageUtils.idRegex)) {
		user = e.getJDA().getUserById(args[0]);
	} else {
		return new Result(Outcome.ERROR, ":x: Not a valid user!");
	}
	
	//Send the message
	String msg = null;
	try {
		PrivateChannel channel = user.openPrivateChannel().submit().get();
		msg = String.join(" ", ArrayUtils.remove(args, 0));
		channel.sendMessage(msg).queue();
	} catch (InterruptedException | ExecutionException ex) {
		ex.printStackTrace();
		return new Result(Outcome.ERROR, ":x: An exception occured.");
	}
	
	EmbedBuilder eb = new EmbedBuilder();
	eb.setAuthor(e.getAuthor().getName() + " (" + e.getAuthor().getId() + ")",
		null, e.getAuthor().getAvatarUrl());
	eb.setDescription("**Sent a DM to " + user.getName() + " (" + user.getId() + "):**\n" + msg);
	eb.setThumbnail(user.getAvatarUrl());
	MessageUtils.log(eb.build());
	
	return new Result(Outcome.SUCCESS);
}
 
Example 7
Project: Minecord   File: NameCommand.java   View Source Code Vote up 4 votes
public Result run(String[] argsOrig, MessageReceivedEvent e) {
	
	//Check for proper argument length
	if (argsOrig.length < 1) {
		return new Result(Outcome.WARNING, ":warning: Please specify a guild.");
	}
	
	//Get guild
	String[] args = ArrayUtils.remove(MessageUtils.getContent(e.getMessage(), true), 0);
	Guild guild = null;
	if (args[0].matches(MessageUtils.idRegex)) {
		guild = DiscordUtils.getGuildById(args[0]);
	} else {
		return new Result(Outcome.ERROR, ":x: Not a valid guild!");
	}
	
	//Check for permissions
	if (!guild.getSelfMember().hasPermission(Permission.NICKNAME_CHANGE)) {
		return new Result(Outcome.WARNING, ":warning: No permissions!");
	}
	
	//Set the nickname
	String name = Config.getName();
	if (args.length > 1) {
		name = String.join(" ", ArrayUtils.remove(args, 0));
	}
	guild.getController().setNickname(guild.getSelfMember(), name).queue();
	
	//Log it
	EmbedBuilder eb = new EmbedBuilder();
	eb.setAuthor(e.getAuthor().getName() + " (" + e.getAuthor().getId() + ")",
		null, e.getAuthor().getAvatarUrl());
	String desc = null;
	if (args.length == 1) {
		desc = "**Reset nickname on `" + guild.getName() + "` (" + guild.getId() + "):**";
	} else {
		desc = "**Changed nickname on `" + guild.getName() + "` (" + guild.getId() + "):**\n" + name;
	}
	eb.setDescription(desc);
	eb.setThumbnail(guild.getIconUrl());
	MessageUtils.log(eb.build());
	
	return new Result(Outcome.SUCCESS);
}