]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/hints/HintStackTest.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.utils.datastructures / src / org / simantics / utils / datastructures / hints / HintStackTest.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 /*
13  *
14  * @author Toni Kalajainen
15  */
16 package org.simantics.utils.datastructures.hints;
17
18 import org.simantics.utils.datastructures.hints.IHintContext.Key;
19 import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
20
21 public class HintStackTest {
22
23         public static final Key KEY = new KeyOf(Double.class);
24         
25         /**
26          * @param args
27          */
28         public static void main(String[] args) {
29                 IHintStack stack = new HintStack();
30                 stack.addHintListener(new IHintListener() {
31                         @Override
32                         public void hintChanged(IHintObservable sender, Key key,
33                                         Object oldValue, Object newValue) {
34                                 System.out.println("Hint changed: "+key+"="+newValue+" (was "+oldValue+")");
35                         }
36
37                         @Override
38                         public void hintRemoved(IHintObservable sender, Key key,
39                                         Object oldValue) {
40                                 System.out.println("Hint removed: "+key+" (was "+oldValue+")");
41                         }});
42                 IHintContext c1 = new HintContext();
43                 IHintContext c2 = new HintContext();
44                 
45                 c1.setHint(KEY, 1.0);
46                 c2.setHint(KEY, 2.0);
47                 
48                 // KEY added
49                 stack.addHintContext(c1, 0);
50                 // KEY overridden
51                 stack.addHintContext(c2, 1);
52                 
53                 // underlying removed, do not do anything
54                 stack.removeHintContext(c1);
55                 
56                 // add over prev value, override
57                 stack.addHintContext(c1, 2);
58                 
59                 // should not do anything, is overridden
60                 c2.setHint(KEY, 3.0);
61                 
62                 // changed. overrides c2
63                 c1.setHint(KEY, 4.0);
64                 
65                 // removed. c2's value 3 becomes effective
66                 c1.removeHint(KEY);
67         }
68
69 }