001package org.eclipse.aether.internal.impl.collect;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 * 
012 *  http://www.apache.org/licenses/LICENSE-2.0
013 * 
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.util.HashMap;
023import java.util.Map;
024import static java.util.Objects.requireNonNull;
025
026import org.eclipse.aether.RepositorySystemSession;
027import org.eclipse.aether.collection.DependencyGraphTransformationContext;
028
029/**
030 * Default implementation of {@link DependencyGraphTransformationContext}.
031 * Internal helper class for collector implementations.
032 */
033public class DefaultDependencyGraphTransformationContext
034    implements DependencyGraphTransformationContext
035{
036
037    private final RepositorySystemSession session;
038
039    private final Map<Object, Object> map;
040
041    public DefaultDependencyGraphTransformationContext( RepositorySystemSession session )
042    {
043        this.session = session;
044        this.map = new HashMap<>();
045    }
046
047    @Override
048    public RepositorySystemSession getSession()
049    {
050        return session;
051    }
052
053    @Override
054    public Object get( Object key )
055    {
056        return map.get( requireNonNull( key, "key cannot be null" ) );
057    }
058
059    @Override
060    public Object put( Object key, Object value )
061    {
062        requireNonNull( key, "key cannot be null" );
063        if ( value != null )
064        {
065            return map.put( key, value );
066        }
067        else
068        {
069            return map.remove( key );
070        }
071    }
072
073    @Override
074    public String toString()
075    {
076        return String.valueOf( map );
077    }
078
079}