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