<commit_before>/** 
 *  Copyright (c) 2015 The original author or authors
 *
 *  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 org.reveno.atp.core.views;

import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
import org.reveno.atp.api.domain.Repository;
import org.reveno.atp.core.api.ViewsStorage;
import org.reveno.atp.core.views.ViewsManager.ViewHandlerHolder;

import java.util.Map;

public class ViewsProcessor {

	public void process(Repository repo) {
		repository.repositorySource(repo);
		repo.getEntityTypes().forEach(c -> repo.getEntities(c).forEach((k,v) -> map(c, k, v)));
		repository.repositorySource(null);
	}
	
	public void process(Map<Class<?>, Long2ObjectLinkedOpenHashMap<Object>> marked) {
		repository.marked(marked);
		marked.forEach((k, v) -> v.long2ObjectEntrySet().forEach(e -> map(k, e.getLongKey(), e.getValue())));
	}

	public void erase() {
		storage.clearAll();
	}
	
	@SuppressWarnings("unchecked")
	protected void map(Class<?> entityType, long id, Object entity) {
		ViewHandlerHolder<Object, Object> holder = (ViewHandlerHolder<Object, Object>) manager.resolveEntity(entityType);
		if (holder == null) 
			return;
		
		if (id >= 0) {
			repository.currentId(id);
			repository.currentViewType(holder.viewType);
			
			Object view = holder.mapper.map(id, entity, repository);
			storage.insert(id, view);
		} else {
			storage.remove(holder.viewType, Math.abs(id));
		}
	}<commit_msg>and the last important one.<commit_after>/** 
 *  Copyright (c) 2015 The original author or authors
 *
 *  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 org.reveno.atp.core.views;

import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
import org.reveno.atp.api.domain.Repository;
import org.reveno.atp.core.api.ViewsStorage;
import org.reveno.atp.core.views.ViewsManager.ViewHandlerHolder;

import java.util.Map;

public class ViewsProcessor {

	public void process(Repository repo) {
		repository.repositorySource(repo);
		repo.getEntityTypes().forEach(c -> repo.getEntities(c).forEach((k,v) -> map(c, k, v)));
		repository.repositorySource(null);
	}
	
	public void process(Map<Class<?>, Long2ObjectLinkedOpenHashMap<Object>> marked) {
		repository.marked(marked);
		marked.forEach((k, v) -> v.long2ObjectEntrySet().forEach(e -> map(k, e.getLongKey(), e.getValue())));
	}

	public void erase() {
		storage.clearAll();
	}
	
	@SuppressWarnings("unchecked")
	/**
	 * TODO we should strongly support mutable views to be GC-friendly
	 */
	protected void map(Class<?> entityType, long id, Object entity) {
		ViewHandlerHolder<Object, Object> holder = (ViewHandlerHolder<Object, Object>) manager.resolveEntity(entityType);
		if (holder == null) 
			return;
		
		if (id >= 0) {
			repository.currentId(id);
			repository.currentViewType(holder.viewType);
			
			Object view = holder.mapper.map(id, entity, repository);
			storage.insert(id, view);
		} else {
			storage.remove(holder.viewType, Math.abs(id));
		}
	}
{'fraction_non_alphanumeric': 0.12118177265898848, 'fraction_numerical': 0.006009013520280421, 'mean_word_length': 4.3624161073825505, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3229669', 'n_tokens_mistral': 1291, 'n_tokens_neox': 1211, 'n_words': 340}