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

org.eclipse.packagedrone.utils.MapOnce Maven / Gradle / Ivy

The newest version!
/*******************************************************************************
 * Copyright (c) 2016 IBH SYSTEMS GmbH and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBH SYSTEMS GmbH - initial API and implementation
 *******************************************************************************/
package org.eclipse.packagedrone.utils;

import java.util.Optional;
import java.util.function.Function;

/**
 * Map only once
 * 

* This class helps to map from a source value to a target value where many * mapping variants are possible. After the first successful mapping (the * mapping result is not {@code null}) further mapping calls will be ignored. *

* * @param * the type of the input type * @param * the type of the result type */ public class MapOnce { private final T value; private Optional result = Optional.empty (); public MapOnce ( final T value ) { this.value = value; } public void map ( final Function> func ) { if ( !this.result.isPresent () ) { this.result = func.apply ( this.value ); } } /** * Get the mapping result * * @return the mapping result, may be {@link Optional#empty()} but is never * {@code null} */ public Optional get () { return this.result; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy