Created
April 15, 2015 19:19
-
-
Save Ivorforce/9189b80dcfddc138bee0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright 2015 Lukas Tenbrink | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
package ivorius.ivtoolkit.maze.components; | |
import com.google.common.base.Function; | |
import com.google.common.collect.FluentIterable; | |
import com.google.common.collect.Iterables; | |
import com.google.common.collect.Maps; | |
import com.google.common.collect.Sets; | |
import ivorius.ivtoolkit.maze.MazeRoom; | |
import javax.annotation.Nullable; | |
import java.util.Map; | |
import java.util.Set; | |
/** | |
* Created by lukas on 15.04.15. | |
*/ | |
public class MazeComponents | |
{ | |
public static <T> MazeComponent<T> shift(final MazeComponent<T> component, final MazeRoom shift) | |
{ | |
return new SetMazeComponent<>(FluentIterable.from(component.rooms()).transform(new Function<MazeRoom, MazeRoom>() | |
{ | |
@Nullable | |
@Override | |
public MazeRoom apply(MazeRoom input) | |
{ | |
return input != null ? input.add(shift) : null; | |
} | |
}).toSet(), FluentIterable.from(component.exits().keySet()).transform(new Function<MazeRoomConnection, MazeRoomConnection>() | |
{ | |
@Nullable | |
@Override | |
public MazeRoomConnection apply(@Nullable MazeRoomConnection input) | |
{ | |
return input != null ? input.add(shift) : null; | |
} | |
}).toMap(new Function<MazeRoomConnection, T>() | |
{ | |
@Nullable | |
@Override | |
public T apply(@Nullable MazeRoomConnection input) | |
{ | |
return component.exits().get(input); | |
} | |
})); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment