All Downloads are FREE. Search and download functionalities are using the official Maven repository.

us.bpsm.edn.parser.DefaultSetFactory Maven / Gradle / Ivy

Go to download

edn-java is an parser and printer for 'edn' written in Java, for Java and requiring no external dependencies.

There is a newer version: 0.7.1
Show newest version
// (c) 2012 B Smith-Mannschott -- Distributed under the Eclipse Public License
package us.bpsm.edn.parser;

import us.bpsm.edn.EdnSyntaxException;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

final class DefaultSetFactory implements CollectionBuilder.Factory {
    public CollectionBuilder builder() {
        return new CollectionBuilder() {
            Set set = new HashSet();
            public void add(Object o) {
                if (!set.add(o)) {
                    throw new EdnSyntaxException(
                      "Set contains duplicate element '" + o + "'.");
                }
            }
            public Object build() {
                return Collections.unmodifiableSet(set);
            }
        };
    }
}