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

javolution.util.internal.collection.ComparatorCollectionImpl Maven / Gradle / Ivy

Go to download

Only the Java Core part of Javolution library, with slight modifications for use in MSFTBX.

The newest version!
/*
 * 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.collection;

import java.util.Comparator;
import java.util.Iterator;

import javolution.util.function.Equality;
import javolution.util.internal.comparator.WrapperComparatorImpl;
import javolution.util.service.CollectionService;

/**
 * A view using a custom comparator.
 */
public class ComparatorCollectionImpl extends CollectionView {

    private static final long serialVersionUID = 0x600L; // Version.
    protected final Equality comparator;
    
    @SuppressWarnings("unchecked")
    public ComparatorCollectionImpl(CollectionService target, Comparator comparator) {
        super(target);
        this.comparator = (comparator instanceof Equality) ?
                (Equality) comparator : new WrapperComparatorImpl(comparator);
    }

    @Override
    public boolean add(E element) {
        return target().add(element);
    }

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

    @Override
    public Equality comparator() {
        return comparator;
    }

    @Override
    public boolean isEmpty() {
        return target().isEmpty();
    }

    @Override
    public Iterator iterator() {
        return target().iterator();
    }

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

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy