/* * Main.java * * Created on 26. duben 2004, 14:47 */ package com.myapp; import org.openide.util.Lookup; import org.openide.util.lookup.Lookups; /** * * @author nenik */ public class Main { /** Creates a new instance of Main */ public Main() { } /** * @param args the command line arguments */ public static void main(String[] args) { String content1 = "String1"; String content2 = "String2"; Lookup fixed1 = Lookups.singleton(content1); Lookup fixed2 = Lookups.singleton(content2); Lookup.Template template = new Lookup.Template(String.class); MyProvider provider = new MyProvider(); provider.setLookup(fixed1); Lookup top = Lookups.proxy(provider); Lookup.Result r0 = top.lookup(template); r0.allInstances(); long time = System.currentTimeMillis(); top.lookup(template).allInstances(); time = System.currentTimeMillis() - time; System.out.println("initial time:" + time + "ms"); for (int i=0; i<1000; i++) top.lookup(template).allInstances(); provider.setLookup(fixed2); time = System.currentTimeMillis(); top.lookup(template).allInstances(); time = System.currentTimeMillis() - time; System.out.println("time after 1000 queries:" + time + "ms"); for (int i=0; i<100; i++) top.lookup(template).allInstances(); // TODO code application logic here } private static class MyProvider implements Lookup.Provider { private Lookup lookup; public Lookup getLookup() { return lookup; } void setLookup(Lookup lookup) { this.lookup = lookup; } } }