/*
 * Copyright (C) 2011 Thomas Akehurst
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.github.tomakehurst.wiremock.mapping;

import static com.google.common.collect.Iterables.find;

import com.google.common.base.Predicate;


public class InMemoryMappings implements Mappings {
	
	private final SortedConcurrentMappingSet mappings = new SortedConcurrentMappingSet();
	
	@Override
	public ResponseDefinition getFor(Request request) {
		RequestResponseMapping matchingMapping = find(
				mappings,
				mappingMatching(request),
				RequestResponseMapping.notConfigured());
//		ResponseDefinition responseDef = ResponseDefinition.copyOf(matchingMapping.getResponse());
		ResponseDefinition responseDef = matchingMapping.getResponse();
		return responseDef;
//		return matchingMapping.getResponse();
	}
	
	private Predicate<RequestResponseMapping> mappingMatching(final Request request) {
		return new Predicate<RequestResponseMapping>() {
			public boolean apply(RequestResponseMapping input) {
				return input.getRequest().isMatchedBy(request);
			}
		};
	}

	@Override
	public void addMapping(RequestResponseMapping mapping) {
		mappings.add(mapping);
	}

	@Override
	public void reset() {
		mappings.clear();
	}

}

@@ -642,16 +642,97 @@
 pping;%0A%0A
+import static com.github.tomakehurst.wiremock.mapping.ResponseDefinition.copyOf;%0A
 import s
@@ -1172,230 +1172,53 @@
 ));%0A
-//%09%09ResponseDefinition responseDef = ResponseDefinition.copyOf(matchingMapping.getResponse());%0A%09%09ResponseDefinition responseDef = matchingMapping.getResponse();%0A%09%09return responseDef;%0A//%09%09return matchingMapping.getResponse(
+%09%09return copyOf(matchingMapping.getResponse()
 );%0A%09

Tidy up