Skip to content

Commit

Permalink
Minor perf improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Mar 17, 2014
1 parent e06e65b commit 5b89f5a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
12 changes: 10 additions & 2 deletions ui/api/src/main/java/org/jboss/forge/addon/ui/util/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

/**
* A utiliy class to handle commands
*
*
* @author <a href="ggastald@redhat.com">George Gastaldi</a>
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*/
Expand All @@ -31,7 +31,7 @@ public static Iterable<UICommand> getEnabledCommands(Iterable<UICommand> command
{
try
{
if (uiCommand.isEnabled(context) && !(uiCommand instanceof UIWizardStep))
if (isEnabled(uiCommand, context))
{
result.add(uiCommand);
}
Expand All @@ -46,6 +46,14 @@ public static Iterable<UICommand> getEnabledCommands(Iterable<UICommand> command
return result;
}

/**
* Returns true if this command can be invoked
*/
public static boolean isEnabled(UICommand command, UIContext context)
{
return (command.isEnabled(context) && !(command instanceof UIWizardStep));
}

private static String getMetadata(UICommand command, UIContext context)
{
String result = "!!! Failed to load Metadata via `" + UICommand.class.getName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

/**
* Creates and manages commands
*
*
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
* @author <a href="ggastald@redhat.com">George Gastaldi</a>
*/
Expand Down Expand Up @@ -64,9 +64,13 @@ public Iterable<UICommand> getCommands()
public Set<String> getEnabledCommandNames(UIContext context)
{
Set<String> commands = new TreeSet<>();
for (UICommand cmd : Commands.getEnabledCommands(getCommands(), context))
Iterable<UICommand> allCommands = getCommands();
for (UICommand cmd : allCommands)
{
commands.add(getCommandName(context, cmd));
if (Commands.isEnabled(cmd, context))
{
commands.add(getCommandName(context, cmd));
}
}
return commands;
}
Expand Down

0 comments on commit 5b89f5a

Please sign in to comment.