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

com.redhat.ceylon.compiler.java.language.InternalMap Maven / Gradle / Ivy

There is a newer version: 1.3.3
Show newest version
package com.redhat.ceylon.compiler.java.language;

import java.util.HashMap;

import com.redhat.ceylon.compiler.java.metadata.Annotation;
import com.redhat.ceylon.compiler.java.metadata.Annotations;
import com.redhat.ceylon.compiler.java.metadata.Ceylon;
import com.redhat.ceylon.compiler.java.metadata.Class;
import com.redhat.ceylon.compiler.java.metadata.Ignore;
import com.redhat.ceylon.compiler.java.metadata.TypeInfo;
import com.redhat.ceylon.compiler.java.runtime.model.TypeDescriptor;

import ceylon.language.Entry;
import ceylon.language.Iterator;
import ceylon.language.finished_;
import ceylon.language.impl.BaseIterator;
import ceylon.language.impl.BaseMap;

/** An immutable map returned by certain methods and functions of the language module.
 * This is only to avoid depending on ceylon.collection.
 * 
 * @author Enrique Zamudio
 */
@Ceylon(major = 8)
@Class
public class InternalMap 
extends BaseMap {

    private final class MapIterator extends
            BaseIterator> {
    	
	    private final 
	    java.util.Iterator> 
	    inner = map.entrySet().iterator();

	    private MapIterator(TypeDescriptor $reifiedElement) {
		    super($reifiedElement);
	    }

	    @Override
	    @Annotations(@Annotation("formal"))
	    @TypeInfo(value="ceylon.language::Entry|ceylon.language::Finished", 
	             erased=true)
	    public Object next() {
	        if (inner.hasNext()) {
	            java.util.Map.Entry 
	            entry = inner.next();
	            return new Entry($reifiedKey, $reifiedItem, 
	            		entry.getKey(), entry.getValue());
	        }
	        return finished_.get_();
	    }
    }

	private final java.util.Map map;
    
    @Ignore
    private TypeDescriptor $reifiedItem;

    @Ignore
    private TypeDescriptor $reifiedKey;

    public InternalMap(
    		@Ignore TypeDescriptor $reifiedKey, 
    		@Ignore TypeDescriptor $reifiedItem,
            final java.util.Map map) {
        super($reifiedKey, $reifiedItem);
        this.map = map;
        this.$reifiedKey = $reifiedKey;
        this.$reifiedItem = $reifiedItem;
    }
    
    @Override
    @Annotations(@Annotation("formal"))
    @TypeInfo("Item|ceylon.language::Nothing")
    public Item get(Object key) {
        return map.get(key);
    }

    @Override
    @Annotations(@Annotation("default"))
    public boolean defines(Object key) {
        return map.containsKey(key);
    }

    @Override
    @Annotations({ @Annotation("actual"), @Annotation("default") })
    public boolean getEmpty() {
        return map.isEmpty();
    }

    @Override
    @Annotations(@Annotation("formal"))
    @TypeInfo("ceylon.language::Iterator>")
    public Iterator> 
    iterator() {
        return new MapIterator(TypeDescriptor.klass(Entry.class, 
        		$reifiedKey, $reifiedItem));
    }

    @Override
    @Annotations(@Annotation("formal"))
    public long getSize() {
        return map.size();
    }
    
    @Override
    @Annotations(@Annotation("formal"))
    public InternalMap $clone() {
        return new InternalMap(
                $reifiedKey, $reifiedItem, 
        		new HashMap(map));
    }

    @Override
    @Ignore
    public TypeDescriptor $getType$() {
        return TypeDescriptor.klass(InternalMap.class,
        		$reifiedKey, $reifiedItem);
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy