Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2010, 2011 SAP AG All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: Lazar Kirchev, SAP AG - initial API and implementation /
 
 
 package org.eclipse.equinox.console.common;
 
A helper class, which implements history.
 
 public class HistoryHolder {
 
     private static final int MAX = 100;
     private final byte[][] history;
     private int size;
     private int pos;
 
     public HistoryHolder() {
          = new byte[][];
     }
 
     public synchronized void reset() {
          = 0;
          = 0;
         for (int i = 0; i < i++) {
             [i] = null;
         }
     }
 
     public synchronized void add(byte[] data) {
         try {
             data = new String(data"US-ASCII").trim().getBytes("US-ASCII");
         } catch (UnsupportedEncodingException e) {
 
         }
         if (data.length == 0) {
              = ;
             return;
         }
         for (int i = 0; i < i++) {
             if (Arrays.equals([i], data)) {
                 System.arraycopy(i + 1, i - i - 1);
                 [ - 1] = data;
                  = ;
                 return;
             }
         }
         if ( >= ) {
             System.arraycopy(, 1, , 0,  - 1);
             --;
         }
         [++] = data;
          = ;
     }
 
     public synchronized byte[] next() {
         if ( >=  - 1) {
             return null;
         }
         return [++];
     }
 
     public synchronized byte[] last() {
         if ( > 0) {
              =  - 1;
             return [];
         } else {
             return null;
         }
     }
 
     public synchronized byte[] first() {
         if ( > 0) {
              = 0;
             return [];
         } else {
             return null;
         }
     }
 
     public synchronized byte[] prev() {
         if ( == 0) {
             return null;
         }
         if ( == 0) {
             return [];
         } else {
             return [--];
         }
     }
New to GrepCode? Check out our FAQ X