// 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/main/java/nl/tudelft/ewi/gitolite/permission/Permission.java
// public interface Permission {
// 
// 	/**
// 	 * @return the {@link BasePermission} for this {@link Permission}.
// 	 */
// 	BasePermission getBasePermission();
// 
// 	/**
// 	 * @return the {@link PermissionModifier PermissionModifiers} for this {@link Permission}.
// 	 * If the current {@code Permission} is a {@link BasePermission}, then it returns an empty list.
// 	 */
// 	Collection<PermissionModifier> getModifiers();
// 
// 	/**
// 	 * Regular expression that matches permissions
// 	 */
// 	Pattern PERMISSION_PATTERN = Pattern.compile("^(-|C|R|RW\\+?)((?:C?D?|D?C?)M?)$");
// 
// 	/**
// 	 * @return String value of this permission.
// 	 */
// 	String valueOf();
// 
// 	/**
// 	 * Parse a {@code Permission}.
// 	 * @param input String to parse
// 	 * @return the parsed permission.
// 	 */
// 	static Permission valueOf(String input) {
// 		Matcher matcher = PERMISSION_PATTERN.matcher(input);
// 		if(!matcher.matches()) {
// 			throw new IllegalArgumentException(String.format("Input %s should be in the format %s",
// 				input, PERMISSION_PATTERN.pattern()));
// 		}
// 		BasePermission basePermission = BasePermission.parse(matcher.group(1));
// 		SortedSet<PermissionModifier> modifiers = PermissionModifier.parse(matcher.group(2));
// 		if(modifiers.isEmpty()) {
// 			return basePermission;
// 		}
// 		return new PermissionWithModifier(basePermission, modifiers);
// 	}
// 
// }


import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.SneakyThrows;
import nl.tudelft.ewi.gitolite.objects.Identifiable;
import nl.tudelft.ewi.gitolite.objects.Identifier;
import nl.tudelft.ewi.gitolite.permission.Permission;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Collection;
	public AccessRule(final Permission permission, String refex, final Identifier... identifiable) {
		this(permission, refex, new InlineUserGroup(identifiable));
	}

	/**
	 * Shorthand that allows you to write constructs like: {@code new RepositoryRule(Permission.RW_PLUS, foo)}.
	 * @param permission {@link Permission} for this {@code Rule}.
	 * @param refex refex for the rule
	 * @param groups groups for this rule.
	 * @param members members for this rule.
	 */
	public AccessRule(final Permission permission, final String refex,  final Collection<? extends GroupRule> groups, final Collection<? extends Identifier> members) {
		this(permission, refex, new InlineUserGroup(groups, members));
	}

	protected AccessRule(final Permission permission, final String refex, final InlineUserGroup members) {
		this.permission = permission;
		this.refex = refex;
		this.members = members;
		invariant();
	}

	protected final void invariant() {
		// There is a lot room for improvement here, but at least we ensure valid usernames for most cases.
		for(Identifier member : members) {
			Preconditions.checkArgument(member.getPattern().matches(USER_PATTERN), "\"%s\" is not a valid user name", member);
		}
	}

	public String getAdjustedRefex() {
// 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/main/java/nl/tudelft/ewi/gitolite/permission/Permission.java
// public interface Permission {
// 
// 	/**
// 	 * @return the {@link BasePermission} for this {@link Permission}.
// 	 */
// 	BasePermission getBasePermission();
// 
// 	/**
// 	 * @return the {@link PermissionModifier PermissionModifiers} for this {@link Permission}.
// 	 * If the current {@code Permission} is a {@link BasePermission}, then it returns an empty list.
// 	 */
// 	Collection<PermissionModifier> getModifiers();
// 
// 	/**
// 	 * Regular expression that matches permissions
// 	 */
// 	Pattern PERMISSION_PATTERN = Pattern.compile("^(-|C|R|RW\\+?)((?:C?D?|D?C?)M?)$");
// 
// 	/**
// 	 * @return String value of this permission.
// 	 */
// 	String valueOf();
// 
// 	/**
// 	 * Parse a {@code Permission}.
// 	 * @param input String to parse
// 	 * @return the parsed permission.
// 	 */
// 	static Permission valueOf(String input) {
// 		Matcher matcher = PERMISSION_PATTERN.matcher(input);
// 		if(!matcher.matches()) {
// 			throw new IllegalArgumentException(String.format("Input %s should be in the format %s",
// 				input, PERMISSION_PATTERN.pattern()));
// 		}
// 		BasePermission basePermission = BasePermission.parse(matcher.group(1));
// 		SortedSet<PermissionModifier> modifiers = PermissionModifier.parse(matcher.group(2));
// 		if(modifiers.isEmpty()) {
// 			return basePermission;
// 		}
// 		return new PermissionWithModifier(basePermission, modifiers);
// 	}
// 
// }


// Path: src/main/java/nl/tudelft/ewi/gitolite/parser/rules/AccessRule.java
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.SneakyThrows;
import nl.tudelft.ewi.gitolite.objects.Identifiable;
import nl.tudelft.ewi.gitolite.objects.Identifier;
import nl.tudelft.ewi.gitolite.permission.Permission;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Collection;

	public AccessRule(final Permission permission, String refex, final Identifier... identifiable) {
		this(permission, refex, new InlineUserGroup(identifiable));
	}

	/**
	 * Shorthand that allows you to write constructs like: {@code new RepositoryRule(Permission.RW_PLUS, foo)}.
	 * @param permission {@link Permission} for this {@code Rule}.
	 * @param refex refex for the rule
	 * @param groups groups for this rule.
	 * @param members members for this rule.
	 */
	public AccessRule(final Permission permission, final String refex,  final Collection<? extends GroupRule> groups, final Collection<? extends Identifier> members) {
		this(permission, refex, new InlineUserGroup(groups, members));
	}

	protected AccessRule(final Permission permission, final String refex, final InlineUserGroup members) {
		this.permission = permission;
		this.refex = refex;
		this.members = members;
		invariant();
	}

	protected final void invariant() {
		// There is a lot room for improvement here, but at least we ensure valid usernames for most cases.
		for(Identifier member : members) {
			Preconditions.checkArgument(member.getPattern().matches(USER_PATTERN), "\"%s\" is not a valid user name", member);
		}
	}

	public String getAdjustedRefex() {
		if(Strings.isNullOrEmpty(refex)) {