KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > proxy > view > HistoryUtils


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20 package org.apache.directory.ldapstudio.proxy.view;
21
22
23 import java.util.ArrayList JavaDoc;
24 import java.util.Arrays JavaDoc;
25 import java.util.List JavaDoc;
26
27 import org.apache.directory.ldapstudio.proxy.Activator;
28 import org.apache.directory.ldapstudio.proxy.ProxyConstants;
29
30
31 /**
32  * This class is used to load and save Dialog History.
33  *
34  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
35  * @version $Rev$, $Date$
36  */

37 public class HistoryUtils
38 {
39     public static void save( String JavaDoc key, String JavaDoc value )
40     {
41         // get current history
42
String JavaDoc[] history = load( key );
43         List JavaDoc<String JavaDoc> list = new ArrayList JavaDoc<String JavaDoc>( Arrays.asList( history ) );
44
45         // add new value or move to first position
46
if ( list.contains( value ) )
47         {
48             list.remove( value );
49         }
50         list.add( 0, value );
51
52         // check history size
53
while ( list.size() > ProxyConstants.DIALOG_HISTORY_SIZE )
54         {
55             list.remove( list.size() - 1 );
56         }
57
58         // save
59
history = ( String JavaDoc[] ) list.toArray( new String JavaDoc[list.size()] );
60         Activator.getDefault().getDialogSettings().put( key, history );
61
62     }
63
64
65     public static String JavaDoc[] load( String JavaDoc key )
66     {
67         String JavaDoc[] history = Activator.getDefault().getDialogSettings().getArray( key );
68         if ( history == null )
69         {
70             history = new String JavaDoc[0];
71         }
72         return history;
73     }
74 }
75
Popular Tags