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

javolution.util.internal.table.MappedTableImpl Maven / Gradle / Ivy

/*
 * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
 * Copyright (C) 2012 - Javolution (http://javolution.org/)
 * All rights reserved.
 * 
 * Permission to use, copy, modify, and distribute this software is
 * freely granted, provided that this notice is preserved.
 */
package javolution.util.internal.table;

import javolution.util.function.Equalities;
import javolution.util.function.Equality;
import javolution.util.function.Function;
import javolution.util.service.TableService;

/**
 * A mapped view over a table.
 */
public class MappedTableImpl extends TableView {

	private static final long serialVersionUID = 0x600L; // Version.
	protected final Function function;

	@SuppressWarnings("unchecked")
	public MappedTableImpl(TableService target,
			Function function) {
		super((TableService) target); // Beware target is of type 
		this.function = function;
	}

	@Override
	public void add(int index, R element) {
		throw new UnsupportedOperationException(
				"New elements cannot be added to mapped views");
	}

	@Override
	public boolean add(R element) {
		throw new UnsupportedOperationException(
				"New elements cannot be added to mapped views");
	}

	@Override
	public void clear() {
		target().clear();
	}

	@Override
	public Equality comparator() {
		return Equalities.STANDARD;
	}

	@SuppressWarnings("unchecked")
	@Override
	public R get(int index) {
		return function.apply((E) target().get(index));
	}

	@SuppressWarnings("unchecked")
	@Override
	public R remove(int index) {
		return function.apply((E) target().remove(index));
	}

	@Override
	public R set(int index, R element) {
		throw new UnsupportedOperationException(
				"Elements cannot be set to mapped views");
	}

	@Override
	public int size() {
		return target().size();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy