@Test public void testUpdateFlags() { Set<Flag> flags = new HashSet<Flag>(); flags.add(Flag.O); flags.add(Flag.K); flags.add(Flag.o); flags.add(Flag.L); flags.add(Flag.V); flags = fp.updateFlags(flags, "+XZbt-fYV+L"); assertTrue(flags.contains(Flag.b)); assertTrue(flags.contains(Flag.t)); assertFalse(flags.contains(Flag.V)); assertTrue(flags.contains(Flag.L)); }
protected Set<Flag> updateFlags(Set<Flag> currentFlags, String flagsDelta) { char action = '.'; Flag currentFlag; Set<Flag> updatedFlags = new HashSet<Flag>(); updatedFlags.addAll(currentFlags); for (Character c : flagsDelta.toCharArray()) { currentFlag = null; switch (c) { case '+': case '-': action = c; break; default: try { currentFlag = Flag.valueOf("" + c); } catch (IllegalArgumentException e) { logger.debug("Illegal flag '" + c + "'."); } } if (currentFlag != null) { switch (action) { case '-': updatedFlags.remove(currentFlag); break; case '+': updatedFlags.add(currentFlag); break; } } } return updatedFlags; }
FlagsPlugin implements PluginWithDependencies { protected Set<Flag> updateFlags(Set<Flag> currentFlags, String flagsDelta) { char action = '.'; Flag currentFlag; Set<Flag> updatedFlags = new HashSet<Flag>(); updatedFlags.addAll(currentFlags); for (Character c : flagsDelta.toCharArray()) { currentFlag = null; switch (c) { case '+': case '-': action = c; break; default: try { currentFlag = Flag.valueOf("" + c); } catch (IllegalArgumentException e) { logger.debug("Illegal flag '" + c + "'."); } } if (currentFlag != null) { switch (action) { case '-': updatedFlags.remove(currentFlag); break; case '+': updatedFlags.add(currentFlag); break; } } } return updatedFlags; } }
FlagsPlugin implements PluginWithDependencies { protected Set<Flag> updateFlags(Set<Flag> currentFlags, String flagsDelta) { char action = '.'; Flag currentFlag; Set<Flag> updatedFlags = new HashSet<Flag>(); updatedFlags.addAll(currentFlags); for (Character c : flagsDelta.toCharArray()) { currentFlag = null; switch (c) { case '+': case '-': action = c; break; default: try { currentFlag = Flag.valueOf("" + c); } catch (IllegalArgumentException e) { logger.debug("Illegal flag '" + c + "'."); } } if (currentFlag != null) { switch (action) { case '-': updatedFlags.remove(currentFlag); break; case '+': updatedFlags.add(currentFlag); break; } } } return updatedFlags; } FlagsPlugin(); }
FlagsPlugin implements PluginWithDependencies { protected Set<Flag> updateFlags(Set<Flag> currentFlags, String flagsDelta) { char action = '.'; Flag currentFlag; Set<Flag> updatedFlags = new HashSet<Flag>(); updatedFlags.addAll(currentFlags); for (Character c : flagsDelta.toCharArray()) { currentFlag = null; switch (c) { case '+': case '-': action = c; break; default: try { currentFlag = Flag.valueOf("" + c); } catch (IllegalArgumentException e) { logger.debug("Illegal flag '" + c + "'."); } } if (currentFlag != null) { switch (action) { case '-': updatedFlags.remove(currentFlag); break; case '+': updatedFlags.add(currentFlag); break; } } } return updatedFlags; } FlagsPlugin(); String[] getDependencies(); void loadDependency(Plugin plugin); String getDescription(); void incomingEvent(Event e); void addEventDistributor(EventDistributor eventDistributor); void addWand(Wand wand); boolean isUser(Network network, String username); boolean isSuperuser(Network network, String nick); Set<Flag> getFlags(Network network, String channel, String nick); Set<Flag> getFlags(Network network, String nick); boolean hasFlag(Network network, String channel, String nick, Flag flag); }
FlagsPlugin implements PluginWithDependencies { protected Set<Flag> updateFlags(Set<Flag> currentFlags, String flagsDelta) { char action = '.'; Flag currentFlag; Set<Flag> updatedFlags = new HashSet<Flag>(); updatedFlags.addAll(currentFlags); for (Character c : flagsDelta.toCharArray()) { currentFlag = null; switch (c) { case '+': case '-': action = c; break; default: try { currentFlag = Flag.valueOf("" + c); } catch (IllegalArgumentException e) { logger.debug("Illegal flag '" + c + "'."); } } if (currentFlag != null) { switch (action) { case '-': updatedFlags.remove(currentFlag); break; case '+': updatedFlags.add(currentFlag); break; } } } return updatedFlags; } FlagsPlugin(); String[] getDependencies(); void loadDependency(Plugin plugin); String getDescription(); void incomingEvent(Event e); void addEventDistributor(EventDistributor eventDistributor); void addWand(Wand wand); boolean isUser(Network network, String username); boolean isSuperuser(Network network, String nick); Set<Flag> getFlags(Network network, String channel, String nick); Set<Flag> getFlags(Network network, String nick); boolean hasFlag(Network network, String channel, String nick, Flag flag);  }