singleton

  1. enum
  2. google juice
  3. private static

enum

http://bazaar.launchpad.net/~ryoji-kodakari/tiddlywikisplitter/tsr/view/head:/src/main/java/tiddsite/tiddsite/Tsr.java

        public enum Singleton
        {
            INSTANCE;
            class Index
            {
                public El best()
                {
                    cross.clear();
                    final Set<Range> rs = imap.keySet();
                    Range bsRange = null;
                    for (final Range r : rs)
                    {
                        if (bsRange == null)
                        {
                            bsRange = r;
                        }
                        else if (r.spos() < bsRange.spos())
                        {
                            bsRange = r;
                        }
                    }
                    for (final Range r : rs)
                    {
                        if (bsRange == null)
                        {
                            bsRange = r;
                        }
                        else if ((r.spos() < bsRange.spos()) && (bsRange.epos() < r.epos()))
                        {
                        }
                        else if ((bsRange.spos() < r.spos()) && (r.epos() < bsRange.epos()))
                        {
                        }
                        else if ((r.spos() < bsRange.spos()) && (bsRange.spos() < r.epos()))
                        {
                            cross.add(r);
                        }
                        else if ((bsRange.spos() < r.spos()) && (r.spos() < bsRange.epos()))
                        {
                            cross.add(r);
                        }
                    }
                    if ((cross.size() > 0) && (bsRange != null))
                    {
                        Collections.sort(cross, new Comparator<Range>()
                        {
                            public int compare(final Range r0, final Range r1)
                            {
                                if (r0.spos() > r1.spos())
                                {
                                    return +1;
                                }
                                else if (r0.spos() < r1.spos())
                                {
                                    return -1;
                                }
                                else
                                {
                                    return 0;
                                }
                            }
                        });

                        final El original = imap.get(bsRange);
                        System.out.println("Escape Problem:\t" + original.getName() + ":" + bsRange.spos() + ":" + bsRange.epos());
                        for (final Range range : cross)
                        {
                            System.out.println("C\t\t" + imap.get(range) + ":" + range.spos() + ":" + range.epos());
                        }
                        final Range escapeRange = cross.get(0);
                        final El escel = imap.get(escapeRange);
                        if (nowiki.equals(escel) | userhtml.equals(escel) | code.equals(escel))
                        {
                            rmap.put(escape, escapeRange);
                            return escape;
                        }
                        if (original.equals(em) | original.equals(tc))
                        {
                            rmap.put(escape, escapeRange);
                            return escape;
                        }
                    }

                    if (imap.size() != 0)
                    {
                        System.out.println("ranges:\t" + imap.size());
                        for (final Range r : rs)
                        {
                            System.out.println(r.spos() + "> >" + r.epos() + "\t" + imap.get(r).getName());
                        }
                        System.out.println("best:\t" + imap.get(bsRange).getName());
                    }
                    return imap.get(bsRange);
                }

                public Map<Range, El> imap()
                {
                    return this.imap;
                }

                public Map<El, Range> rmap()
                {
                    return this.rmap;
                }

                private final List<Range> cross = Collections.synchronizedList(new ArrayList<Range>());
                private final Map<Range, El> imap = Collections.synchronizedMap(new HashMap<Range, El>());
                private final Map<El, Range> rmap = Collections.synchronizedMap(new HashMap<El, Range>());
            }

            public Map<String, String> escbf()
            {
                return escbf;
            }

            public StringBuffer escsb()
            {
                return escsb;
            }

            public Index idx()
            {
                return idx;
            }

            private final Map<String, String> escbf = Collections.synchronizedMap(new HashMap<String, String>());
            private final StringBuffer escsb = new StringBuffer();
            private final Index idx = new Index();
        }

google juice

http://bazaar.launchpad.net/~ryoji-kodakari/newsrecorder/newsrecorder-binary/view/head:/src/main/java/jp/newsrecorder/settings/SettingImpl.java

@Singleton
public class SettingImpl implements Setting{
@ImplementedBy(SettingImpl.class)
public interface Setting

private static

PMF
http://www.javacoffeebreak.com/articles/designpatterns/index.html

public class SingletonObject
{
  private SingletonObject()
  {
  }

  public static SingletonObject getSingletonObject()
  {
    if (ref == null)
        ref = new SingletonObject();		
    return ref;
  }

  private static SingletonObject ref;
}
    last modified: 23 July 2011 [ View wiki source Close ]
     
SEARCH DIFFERENCE ATTACHMENT RECENT POST