/*
 * 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 com.facebook.presto.execution.resourceGroups;

import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;

public final class ResourceGroupId
{
    private final List<String> segments;

    public ResourceGroupId(String name)
    {
        this(ImmutableList.of(requireNonNull(name, "name is null")));
    }

    public ResourceGroupId(ResourceGroupId parent, String name)
    {
        this(ImmutableList.<String>builder().addAll(requireNonNull(parent, "parent is null").segments).add(requireNonNull(name, "name is null")).build());
    }

    private ResourceGroupId(List<String> segments)
    {
        checkArgument(!segments.isEmpty(), "Resource group id is empty");
        for (String segment : segments) {
            checkArgument(!segment.isEmpty(), "Empty segment in resource group id");
            checkArgument(segment.indexOf('.') < 0, "Invalid resource group id. '%s' contains a '.'", Joiner.on(".").join(segments));
        }
        this.segments = segments;
    }

    public String getLastSegment()
    {
        return segments.get(segments.size() - 1);
    }

    public List<String> getSegments()
    {
        return segments;
    }

    public Optional<ResourceGroupId> getParent()
    {
        if (segments.size() == 1) {
            return Optional.empty();
        }
        return Optional.of(new ResourceGroupId(segments.subList(0, segments.size() - 1)));
    }

    public static ResourceGroupId fromString(String value)
    {
        requireNonNull(value, "value is null");
        return new ResourceGroupId(Splitter.on(".").splitToList(value));
    }

    @Override
    public String toString()
    {
        return Joiner.on(".").join(segments);
    }

    @Override
    public boolean equals(Object o)
    {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        ResourceGroupId that = (ResourceGroupId) o;
        return Objects.equals(segments, that.segments);
    }

    @Override
    public int hashCode()
    {
        return Objects.hash(segments);
    }
}

@@ -621,128 +621,29 @@
 ort 
-com.google.common.base.Joiner;%0Aimport com.google.common.base.Splitter;%0Aimport com.google.common.collect.Immutable
+java.util.Array
 List;%0A
-%0A
 impo
@@ -733,106 +733,220 @@
 tic 
-com.google.common.base.Preconditions.checkArgument;%0Aimport static java.util.Objects.requireNonNull
+java.lang.String.format;%0Aimport static java.util.Arrays.asList;%0Aimport static java.util.Collections.singletonList;%0Aimport static java.util.Objects.requireNonNull;%0Aimport static java.util.stream.Collectors.joining
 ;%0A%0Ap
@@ -1086,24 +1086,21 @@
 his(
-Immutable
+singleton
 List
-.of
 (req
@@ -1230,46 +1230,14 @@
 his(
-ImmutableList.%3CString%3Ebuilder().addAll
+append
 (req
@@ -1286,14 +1286,10 @@
 ents
-).add(
+, 
 requ
@@ -1325,17 +1325,201 @@
 l%22))
+)
-.build())
+;%0A    %7D%0A%0A    private static List%3CString%3E append(List%3CString%3E list, String element)%0A    %7B%0A        List%3CString%3E result = new ArrayList%3C%3E(list);%0A        result.add(element);%0A        return result
 ;%0A  
@@ -1777,24 +1777,110 @@
 group id%22);%0A
+            String id = segments.stream()%0A                    .collect(joining(%22.%22));%0A
             
@@ -1973,37 +1973,10 @@
 '%22, 
-Joiner.on(%22.%22).join(segments)
+id
 );%0A 
@@ -2587,45 +2587,241 @@
 pId(
-Splitter.on(%22.%22).splitToList(value));
+asList(value.split(%22%5C%5C.%22)));%0A    %7D%0A%0A    private static void checkArgument(boolean argument, String format, Object... args)%0A    %7B%0A        if (!argument) %7B%0A            throw new IllegalArgumentException(format(format, args));%0A        %7D
 %0A   
@@ -2892,36 +2892,63 @@
 urn 
-Joiner.on(%22.%22).join(segments
+segments.stream()%0A                .collect(joining(%22.%22)
 );%0A 

Refactor ResourceGroupId to not use Guava