/*
 * 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.collect.ImmutableSet;
import gnu.trove.procedure.TIntProcedure;
import gnu.trove.set.TIntSet;
import gnu.trove.set.hash.TIntHashSet;
import ivorius.ivtoolkit.math.AxisAlignedTransform2D;
import ivorius.ivtoolkit.tools.Ranges;

import java.util.Set;

/**
 * Created by lukas on 23.06.14.
 */
public class MazeRooms
{
    public static MazeRoom rotated(MazeRoom room, AxisAlignedTransform2D transform, int[] size)
    {
        if (room.getDimensions() < 3)
            throw new IllegalArgumentException();

        int[] roomPosition = room.getCoordinates();
        int[] transformedRoom = transform.apply(roomPosition, size);

        roomPosition[0] = transformedRoom[0];
        roomPosition[1] = transformedRoom[1];
        roomPosition[2] = transformedRoom[2];

        return new MazeRoom(roomPosition);
    }

    public static Set<MazePassage> neighbors(final MazeRoom room, TIntSet dimensions)
    {
        final ImmutableSet.Builder<MazePassage> set = ImmutableSet.builder();
        dimensions.forEach(value -> {
            set.add(new MazePassage(room, room.addInDimension(value, 1)));
            set.add(new MazePassage(room, room.addInDimension(value, -1)));
            return true;
        });
        return set.build();
    }

    public static Set<MazePassage> neighbors(MazeRoom room)
    {
        return neighbors(room, new TIntHashSet(Ranges.to(room.getDimensions())));
    }
}

@@ -667,166 +667,8 @@
 s;%0A%0A
-import com.google.common.collect.ImmutableSet;%0Aimport gnu.trove.procedure.TIntProcedure;%0Aimport gnu.trove.set.TIntSet;%0Aimport gnu.trove.set.hash.TIntHashSet;%0A
 impo
@@ -721,48 +721,44 @@
 2D;%0A
+%0A
 import 
-ivorius.ivtoolkit.tools.Ranges
+java.util.stream.IntStream
 ;%0A
-%0A
 impo
@@ -770,19 +770,29 @@
 va.util.
-Set
+stream.Stream
 ;%0A%0A/**%0A 
@@ -1369,38 +1369,38 @@
 lic static S
-et%3CMazePassage
+tream%3CMazeRoom
 %3E neighbors(
@@ -1424,15 +1424,17 @@
 om, 
-T
 IntS
-e
 t
+ream
  dim
@@ -1460,168 +1460,250 @@
     
-final ImmutableSet.Builder%3CMazePassage%3E set = ImmutableSet.builder(
+return IntStream.of(1, -1).mapToObj(m -%3E dimensions.mapToObj(d -%3E room.addInDimension(d, m))).flatMap(t -%3E t
 );%0A    
+%7D%0A%0A
     
-dimensions.forEach(value -%3E %7B%0A            set.add(new MazePassage(room
+public static Stream%3CMazeRoom%3E neighbors(MazeRoom room)%0A    %7B%0A        return neighbors(room, IntStream.range(0
 , room.
-addIn
+get
 Dime
@@ -1711,17 +1711,10 @@
 sion
+s
 (
-value, 1
 )));
@@ -1722,84 +1722,115 @@
     
-   
+%7D%0A%0A
     
- set.add(new MazePassage(r
+public static Stream%3CMazePassage%3E neighborPassages(final MazeR
 oom
-,
  room
-.addInDimension(value, -1)));
+, IntStream dimensions)
 %0A    
+%7B%0A
     
@@ -1844,51 +1844,69 @@
 urn 
-true;%0A        %7D);%0A        return set.build(
+neighbors(room, dimensions).map(r -%3E new MazePassage(room, r)
 );%0A 
@@ -1930,18 +1930,21 @@
 static S
-e
 t
+ream
 %3CMazePas
@@ -1949,32 +1949,39 @@
 assage%3E neighbor
+Passage
 s(MazeRoom room)
@@ -2020,57 +2020,42 @@
 room
-, new TIntHashSet(Ranges.to(room.getDimensions())
+).map(r -%3E new MazePassage(room, r
 ));%0A

Change MazeRooms.neighbors to also give out the MazeRooms directly.