Merge branch '1.6.0-SNAPSHOT'

Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/b48b13ac
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/b48b13ac
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/b48b13ac

Branch: refs/heads/master
Commit: b48b13acbd51ae4e004d5a773bb18a26a491dfe8
Parents: a723216 1f7dd2d
Author: Mike Drob <md...@cloudera.com>
Authored: Mon Apr 28 23:20:51 2014 -0400
Committer: Mike Drob <md...@cloudera.com>
Committed: Mon Apr 28 23:20:51 2014 -0400

----------------------------------------------------------------------
 .../util/shell/command/HistoryCommandTest.java  | 90 ++++++++++++++++++++
 .../accumulo/shell/commands/HistoryCommand.java | 31 +++----
 2 files changed, 102 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/b48b13ac/shell/src/main/java/org/apache/accumulo/shell/commands/HistoryCommand.java
----------------------------------------------------------------------
diff --cc 
shell/src/main/java/org/apache/accumulo/shell/commands/HistoryCommand.java
index 1c1314a,0000000..74817a3
mode 100644,000000..100644
--- a/shell/src/main/java/org/apache/accumulo/shell/commands/HistoryCommand.java
+++ b/shell/src/main/java/org/apache/accumulo/shell/commands/HistoryCommand.java
@@@ -1,82 -1,0 +1,75 @@@
 +/*
 + * Licensed to the Apache Software Foundation (ASF) under one or more
 + * contributor license agreements.  See the NOTICE file distributed with
 + * this work for additional information regarding copyright ownership.
 + * The ASF licenses this file to You under the Apache License, Version 2.0
 + * (the "License"); you may not use this file except in compliance with
 + * the License.  You may obtain a copy of the License at
 + *
 + *     http://www.apache.org/licenses/LICENSE-2.0
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the License is distributed on an "AS IS" BASIS,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the License for the specific language governing permissions and
 + * limitations under the License.
 + */
 +package org.apache.accumulo.shell.commands;
 +
 +import java.io.IOException;
 +import java.util.Iterator;
- import java.util.ListIterator;
 +
 +import jline.console.history.History.Entry;
 +
 +import org.apache.accumulo.shell.Shell;
 +import org.apache.accumulo.shell.Shell.Command;
 +import org.apache.commons.cli.CommandLine;
 +import org.apache.commons.cli.Option;
 +import org.apache.commons.cli.Options;
- import org.apache.commons.collections.iterators.AbstractIteratorDecorator;
++
++import com.google.common.base.Function;
++import com.google.common.collect.Iterators;
 +
 +public class HistoryCommand extends Command {
 +  private Option clearHist;
 +  private Option disablePaginationOpt;
 +  
-   @SuppressWarnings("unchecked")
 +  @Override
 +  public int execute(final String fullCommand, final CommandLine cl, final 
Shell shellState) throws IOException {
 +    if (cl.hasOption(clearHist.getOpt())) {
 +      shellState.getReader().getHistory().clear();
 +    } else {
-       ListIterator<Entry> it = shellState.getReader().getHistory().entries();
-       shellState.printLines(new HistoryLineIterator(it), 
!cl.hasOption(disablePaginationOpt.getOpt()));
++      Iterator<Entry> source = shellState.getReader().getHistory().entries();
++      Iterator<String> historyIterator = Iterators.transform(source, new 
Function<Entry,String>() {
++        @Override
++        public String apply(Entry input) {
++          return String.format("%d: %s", input.index() + 1, input.value());
++        }
++      });
++
++      shellState.printLines(historyIterator, 
!cl.hasOption(disablePaginationOpt.getOpt()));
 +    }
 +    
 +    return 0;
 +  }
 +  
-   /**
-    * Decorator that converts an Iterator<History.Entry> to an 
Iterator<String>.
-    */
-   private static class HistoryLineIterator extends AbstractIteratorDecorator {
-     public HistoryLineIterator(Iterator<Entry> iterator) {
-       super(iterator);
-     }
-     
-     @Override
-     public String next() {
-       return super.next().toString();
-     }
-   }
-   
 +  @Override
 +  public String description() {
 +    return ("generates a list of commands previously executed");
 +  }
 +  
 +  @Override
 +  public int numArgs() {
 +    return 0;
 +  }
 +  
 +  @Override
 +  public Options getOptions() {
 +    final Options o = new Options();
 +    clearHist = new Option("c", "clear", false, "clear history file");
 +    o.addOption(clearHist);
 +    disablePaginationOpt = new Option("np", "no-pagination", false, "disable 
pagination of output");
 +    o.addOption(disablePaginationOpt);
 +    return o;
 +  }
 +}

Reply via email to