// Path: src/main/java/nl/tudelft/ewi/gitolite/parser/rules/GroupRule.java
// @Data
// @Builder
// //@EqualsAndHashCode(doNotUseGetters = true)
// public class GroupRule implements RecursiveAndPrototypeStreamingGroup<GroupRule, Identifier>, Rule, Identifiable {
// 
// 	/**
// 	 * {@code @all} is a special group name that is often convenient to use if you really mean "all repos" or "all users".
// 	 */
// 	public final static GroupRule ALL = new GroupRule("@all") {
// 
// 		@Override
// 		public boolean contains(Object value) {
// 			return true;
// 		}
// 
// 		@Override
// 		public String toString() { return "@all"; }
// 
// 		@Override
// 		public void write(Writer writer) {}
// 
// 	};
// 
// 	@Getter
// 	private final String pattern;
// 
// 	@Getter
// 	private GroupRule parent;
// 
// 	@Singular
// 	private final List<Identifier> members;
// 
// 	@Singular
// 	private final List<GroupRule> groups;
// 
// 	public GroupRule(final String pattern, final Identifier... members) {
// 		this(pattern, null, Lists.newArrayList(members), Collections.emptyList());
// 	}
// 
// 	public GroupRule(final String pattern,
// 	                 final GroupRule parent,
// 	                 final Collection<? extends Identifier> members,
// 	                 final Collection<? extends GroupRule> groups) {
// 		Preconditions.checkNotNull(pattern);
// 		Preconditions.checkNotNull(groups);
// 		Preconditions.checkNotNull(members);
// 		Preconditions.checkArgument(pattern.matches("^\\@\\w[\\w._\\@+-]+$"), "\"%s\" is not a valid group name", pattern);
// 
// 		this.pattern = pattern;
// 		this.parent = parent;
// 		this.groups = Lists.newArrayList(groups);
// 		this.members = Lists.newArrayList(members);
// 	}
// 
// 	@Override
// 	public Stream<Identifier> getOwnMembersStream() {
// 		return members.stream();
// 	}
// 
// 	@Override
// 	public Stream<GroupRule> getOwnGroupsStream() {
// 		return groups.stream();
// 	}
// 
// 	@Override
// 	public void add(GroupRule group) {
// 		groups.add(group);
// 	}
// 
// 	@Override
// 	public boolean remove(Object element) {
// 		return members.remove(element) | groups.remove(element) | (parent != null && parent.remove(element));
// 	}
// 
// 	@Override
// 	public boolean add(Identifier value) {
// 		return members.add(value);
// 	}
// 
// 	@Override
// 	public boolean addAll(Collection<? extends Identifier> c) {
// 		return members.addAll(c);
// 	}
// 
// 	@Override
// 	public boolean removeAll(Collection<?> c) {
// 		return members.removeAll(c) | groups.removeAll(c);
// 	}
// 
// 	@Override
// 	public boolean retainAll(Collection<?> c) {
// 		return members.retainAll(c) | groups.retainAll(c);
// 	}
// 
// 	@Override
// 	public void clear() {
// 		members.clear();
// 		groups.clear();
// 	}
// 
// 	@Override
// 	public boolean removeIf(Predicate<? super Identifier> filter) {
// 		return members.removeIf(filter);
// 	}
// 
// 	@Override
// 	public void write(Writer writer) throws IOException {
// 		writer.write(String.format("%-20s=   %s\n", pattern, Joiner.on(' ').join(Stream.concat(getOwnGroupsStream(), getOwnMembersStream())
// 			.map(Identifiable::getPattern)
// 			.iterator())));
// 		writer.flush();
// 	}
// 
// 
// 	@Override
// 	public String toString() {
// 		return (String.format("%-20s=   %s\n", pattern, Joiner.on(' ').join(Stream.concat(getOwnGroupsStream(), getOwnMembersStream())
// 			.map(Identifiable::getPattern)
// 			.iterator())));
// 	}
// 
// }
// 
// Path: src/main/java/nl/tudelft/ewi/gitolite/objects/Identifiable.java
// public interface Identifiable extends Comparable<Identifiable>, Serializable {
// 
// 	String getPattern();
// 
// 	@Override
// 	default int compareTo(Identifiable o) {
// 		return getPattern().compareTo(o.getPattern());
// 	}
// 
// }
// 
// Path: src/main/java/nl/tudelft/ewi/gitolite/objects/Identifier.java
// @Value
// public class Identifier implements Identifiable {
// 
// 	/**
// 	 * The name for the identifier
// 	 */
// 	private final String pattern;
// 
// 	private final static WeakHashMap<String, WeakReference<Identifier>> identifiableMap = new WeakHashMap<>();
// 
// 	/**
// 	 * Get an identifier. As {@code Identifiers} should be immutable, they are stored in a
// 	 * {@code WeakHashMap} for caching purposes. This method tries to find {@code Identifiers}
// 	 * in the cache first, and only creates a new instance if not. Therefore, this method is
// 	 * preferred over using a constructor.
// 	 *
// 	 * @param name Name for the identifier.
// 	 * @return Identifier
// 	 */
// 	public static Identifier valueOf(String name) {
// 		WeakReference<Identifier> ref = identifiableMap.get(name);
// 		Identifier identifiable;
// 		if(ref == null || (identifiable = ref.get()) == null) {
// 			identifiable = new Identifier(name);
// 			identifiableMap.put(name, new WeakReference<>(identifiable));
// 		}
// 		return identifiable;
// 	}
// 
// }


import nl.tudelft.ewi.gitolite.parser.rules.GroupRule;
import nl.tudelft.ewi.gitolite.objects.Identifiable;
import nl.tudelft.ewi.gitolite.objects.Identifier;
import org.junit.Test;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
import static org.junit.Assert.assertThat;
import static org.hamcrest.Matchers.contains;




/**
 * @author Jan-Willem Gmelig Meyling
 */
public class TestGroupRule {

	@Test
	public void test1() throws IOException {
		Identifier foo = new Identifier("foo");
		Identifier bar = new Identifier("bar");

// Path: src/main/java/nl/tudelft/ewi/gitolite/parser/rules/GroupRule.java
// @Data
// @Builder
// //@EqualsAndHashCode(doNotUseGetters = true)
// public class GroupRule implements RecursiveAndPrototypeStreamingGroup<GroupRule, Identifier>, Rule, Identifiable {
// 
// 	/**
// 	 * {@code @all} is a special group name that is often convenient to use if you really mean "all repos" or "all users".
// 	 */
// 	public final static GroupRule ALL = new GroupRule("@all") {
// 
// 		@Override
// 		public boolean contains(Object value) {
// 			return true;
// 		}
// 
// 		@Override
// 		public String toString() { return "@all"; }
// 
// 		@Override
// 		public void write(Writer writer) {}
// 
// 	};
// 
// 	@Getter
// 	private final String pattern;
// 
// 	@Getter
// 	private GroupRule parent;
// 
// 	@Singular
// 	private final List<Identifier> members;
// 
// 	@Singular
// 	private final List<GroupRule> groups;
// 
// 	public GroupRule(final String pattern, final Identifier... members) {
// 		this(pattern, null, Lists.newArrayList(members), Collections.emptyList());
// 	}
// 
// 	public GroupRule(final String pattern,
// 	                 final GroupRule parent,
// 	                 final Collection<? extends Identifier> members,
// 	                 final Collection<? extends GroupRule> groups) {
// 		Preconditions.checkNotNull(pattern);
// 		Preconditions.checkNotNull(groups);
// 		Preconditions.checkNotNull(members);
// 		Preconditions.checkArgument(pattern.matches("^\\@\\w[\\w._\\@+-]+$"), "\"%s\" is not a valid group name", pattern);
// 
// 		this.pattern = pattern;
// 		this.parent = parent;
// 		this.groups = Lists.newArrayList(groups);
// 		this.members = Lists.newArrayList(members);
// 	}
// 
// 	@Override
// 	public Stream<Identifier> getOwnMembersStream() {
// 		return members.stream();
// 	}
// 
// 	@Override
// 	public Stream<GroupRule> getOwnGroupsStream() {
// 		return groups.stream();
// 	}
// 
// 	@Override
// 	public void add(GroupRule group) {
// 		groups.add(group);
// 	}
// 
// 	@Override
// 	public boolean remove(Object element) {
// 		return members.remove(element) | groups.remove(element) | (parent != null && parent.remove(element));
// 	}
// 
// 	@Override
// 	public boolean add(Identifier value) {
// 		return members.add(value);
// 	}
// 
// 	@Override
// 	public boolean addAll(Collection<? extends Identifier> c) {
// 		return members.addAll(c);
// 	}
// 
// 	@Override
// 	public boolean removeAll(Collection<?> c) {
// 		return members.removeAll(c) | groups.removeAll(c);
// 	}
// 
// 	@Override
// 	public boolean retainAll(Collection<?> c) {
// 		return members.retainAll(c) | groups.retainAll(c);
// 	}
// 
// 	@Override
// 	public void clear() {
// 		members.clear();
// 		groups.clear();
// 	}
// 
// 	@Override
// 	public boolean removeIf(Predicate<? super Identifier> filter) {
// 		return members.removeIf(filter);
// 	}
// 
// 	@Override
// 	public void write(Writer writer) throws IOException {
// 		writer.write(String.format("%-20s=   %s\n", pattern, Joiner.on(' ').join(Stream.concat(getOwnGroupsStream(), getOwnMembersStream())
// 			.map(Identifiable::getPattern)
// 			.iterator())));
// 		writer.flush();
// 	}
// 
// 
// 	@Override
// 	public String toString() {
// 		return (String.format("%-20s=   %s\n", pattern, Joiner.on(' ').join(Stream.concat(getOwnGroupsStream(), getOwnMembersStream())
// 			.map(Identifiable::getPattern)
// 			.iterator())));
// 	}
// 
// }
// 
// Path: src/main/java/nl/tudelft/ewi/gitolite/objects/Identifiable.java
// public interface Identifiable extends Comparable<Identifiable>, Serializable {
// 
// 	String getPattern();
// 
// 	@Override
// 	default int compareTo(Identifiable o) {
// 		return getPattern().compareTo(o.getPattern());
// 	}
// 
// }
// 
// Path: src/main/java/nl/tudelft/ewi/gitolite/objects/Identifier.java
// @Value
// public class Identifier implements Identifiable {
// 
// 	/**
// 	 * The name for the identifier
// 	 */
// 	private final String pattern;
// 
// 	private final static WeakHashMap<String, WeakReference<Identifier>> identifiableMap = new WeakHashMap<>();
// 
// 	/**
// 	 * Get an identifier. As {@code Identifiers} should be immutable, they are stored in a
// 	 * {@code WeakHashMap} for caching purposes. This method tries to find {@code Identifiers}
// 	 * in the cache first, and only creates a new instance if not. Therefore, this method is
// 	 * preferred over using a constructor.
// 	 *
// 	 * @param name Name for the identifier.
// 	 * @return Identifier
// 	 */
// 	public static Identifier valueOf(String name) {
// 		WeakReference<Identifier> ref = identifiableMap.get(name);
// 		Identifier identifiable;
// 		if(ref == null || (identifiable = ref.get()) == null) {
// 			identifiable = new Identifier(name);
// 			identifiableMap.put(name, new WeakReference<>(identifiable));
// 		}
// 		return identifiable;
// 	}
// 
// }


// Path: src/test/java/TestGroupRule.java
import nl.tudelft.ewi.gitolite.parser.rules.GroupRule;
import nl.tudelft.ewi.gitolite.objects.Identifiable;
import nl.tudelft.ewi.gitolite.objects.Identifier;
import org.junit.Test;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
import static org.junit.Assert.assertThat;
import static org.hamcrest.Matchers.contains;





/**
 * @author Jan-Willem Gmelig Meyling
 */
public class TestGroupRule {

	@Test
	public void test1() throws IOException {
		Identifier foo = new Identifier("foo");
		Identifier bar = new Identifier("bar");

		GroupRule test = GroupRule.builder()