// Path: src/main/java/com/netflix/nfgraph/compressed/NFCompressedGraphIntPointers.java
// public class NFCompressedGraphIntPointers implements NFCompressedGraphPointers {
// 
//     private final Map<String, int[]>pointersByOrdinal;
// 
//     public NFCompressedGraphIntPointers() {
//         this.pointersByOrdinal = new HashMap<String, int[]>();
//     }
// 
//     /**
//      * @return the offset into the {@link NFCompressedGraph}'s byte array for the node identified by the given type and ordinal.
//      */
//     public long getPointer(String nodeType, int ordinal) {
//         int pointers[] = pointersByOrdinal.get(nodeType);
//         if(pointers == null)
//             throw new NFGraphException("Undefined node type: " + nodeType);
//         if(ordinal < pointers.length) {
//             if(pointers[ordinal] == -1)
//                 return -1;
//             return 0xFFFFFFFFL & pointers[ordinal];
//         }
//         return -1;
//     }
// 
//     public void addPointers(String nodeType, int pointers[]) {
//         pointersByOrdinal.put(nodeType, pointers);
//     }
// 
//     public int numPointers(String nodeType) {
//         return pointersByOrdinal.get(nodeType).length;
//     }
// 
//     @Override
//     public Map<String, long[]> asMap() {
//         Map<String, long[]> map = new HashMap<String, long[]>();
// 
//         for(Map.Entry<String, int[]> entry : pointersByOrdinal.entrySet()) {
//             map.put(entry.getKey(), toLongArray(entry.getValue()));
//         }
// 
//         return map;
//     }
// 
//     private long[] toLongArray(int[] arr) {
//         long l[] = new long[arr.length];
// 
//         for(int i=0;i<arr.length;i++) {
//             l[i] = arr[i];
//         }
// 
//         return l;
//     }
// 
// }
// 
// Path: src/main/java/com/netflix/nfgraph/compressed/NFCompressedGraphLongPointers.java
// public class NFCompressedGraphLongPointers implements NFCompressedGraphPointers {
// 
//     private final Map<String, long[]>pointersByOrdinal;
// 
//     public NFCompressedGraphLongPointers() {
//         this.pointersByOrdinal = new HashMap<String, long[]>();
//     }
// 
//     /**
//      * @return the offset into the {@link NFCompressedGraph}'s byte array for the node identified by the given type and ordinal.
//      */
//     public long getPointer(String nodeType, int ordinal) {
//         long pointers[] = pointersByOrdinal.get(nodeType);
//         if(pointers == null)
//             throw new NFGraphException("Undefined node type: " + nodeType);
//         if(ordinal < pointers.length)
//             return pointers[ordinal];
//         return -1;
//     }
// 
//     public void addPointers(String nodeType, long pointers[]) {
//         pointersByOrdinal.put(nodeType, pointers);
//     }
// 
//     public int numPointers(String nodeType) {
//         return pointersByOrdinal.get(nodeType).length;
//     }
// 
//     public Map<String, long[]> asMap() {
//         return pointersByOrdinal;
//     }
// 
// }
// 
// Path: src/main/java/com/netflix/nfgraph/compressed/NFCompressedGraphPointers.java
// public interface NFCompressedGraphPointers {
// 
//     /**
//      * @return the offset into the {@link NFCompressedGraph}'s byte array for the node identified by the given type and ordinal.
//      */
//     public long getPointer(String nodeType, int ordinal);
// 
//     public int numPointers(String nodeType);
// 
//     public Map<String, long[]> asMap();
// 
// }


import com.netflix.nfgraph.compressed.NFCompressedGraphIntPointers;
import com.netflix.nfgraph.compressed.NFCompressedGraphLongPointers;
import com.netflix.nfgraph.compressed.NFCompressedGraphPointers;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import org.junit.Assert;
import org.junit.Test;
/*
 *  Copyright 2014-2022 Netflix, Inc.
 *
 *     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.netflix.nfgraph.serializer;




public class NFCompressedGraphPointersSerializerTest {

    @Test
    public void dataLengthLessthan4GBUsesIntegerPointers() throws IOException {
        NFCompressedGraphLongPointers pointers = new NFCompressedGraphLongPointers();
        pointers.addPointers("test", new long[] { 1, 2, 3 });

        NFCompressedGraphPointersSerializer serializer = new NFCompressedGraphPointersSerializer(pointers, (long)Integer.MAX_VALUE * 2);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(baos);

        serializer.serializePointers(dos);

        DataInputStream dis = new DataInputStream(new ByteArrayInputStream(baos.toByteArray()));

        NFCompressedGraphPointers deserialized = new NFCompressedGraphPointersDeserializer().deserializePointers(dis);

// Path: src/main/java/com/netflix/nfgraph/compressed/NFCompressedGraphIntPointers.java
// public class NFCompressedGraphIntPointers implements NFCompressedGraphPointers {
// 
//     private final Map<String, int[]>pointersByOrdinal;
// 
//     public NFCompressedGraphIntPointers() {
//         this.pointersByOrdinal = new HashMap<String, int[]>();
//     }
// 
//     /**
//      * @return the offset into the {@link NFCompressedGraph}'s byte array for the node identified by the given type and ordinal.
//      */
//     public long getPointer(String nodeType, int ordinal) {
//         int pointers[] = pointersByOrdinal.get(nodeType);
//         if(pointers == null)
//             throw new NFGraphException("Undefined node type: " + nodeType);
//         if(ordinal < pointers.length) {
//             if(pointers[ordinal] == -1)
//                 return -1;
//             return 0xFFFFFFFFL & pointers[ordinal];
//         }
//         return -1;
//     }
// 
//     public void addPointers(String nodeType, int pointers[]) {
//         pointersByOrdinal.put(nodeType, pointers);
//     }
// 
//     public int numPointers(String nodeType) {
//         return pointersByOrdinal.get(nodeType).length;
//     }
// 
//     @Override
//     public Map<String, long[]> asMap() {
//         Map<String, long[]> map = new HashMap<String, long[]>();
// 
//         for(Map.Entry<String, int[]> entry : pointersByOrdinal.entrySet()) {
//             map.put(entry.getKey(), toLongArray(entry.getValue()));
//         }
// 
//         return map;
//     }
// 
//     private long[] toLongArray(int[] arr) {
//         long l[] = new long[arr.length];
// 
//         for(int i=0;i<arr.length;i++) {
//             l[i] = arr[i];
//         }
// 
//         return l;
//     }
// 
// }
// 
// Path: src/main/java/com/netflix/nfgraph/compressed/NFCompressedGraphLongPointers.java
// public class NFCompressedGraphLongPointers implements NFCompressedGraphPointers {
// 
//     private final Map<String, long[]>pointersByOrdinal;
// 
//     public NFCompressedGraphLongPointers() {
//         this.pointersByOrdinal = new HashMap<String, long[]>();
//     }
// 
//     /**
//      * @return the offset into the {@link NFCompressedGraph}'s byte array for the node identified by the given type and ordinal.
//      */
//     public long getPointer(String nodeType, int ordinal) {
//         long pointers[] = pointersByOrdinal.get(nodeType);
//         if(pointers == null)
//             throw new NFGraphException("Undefined node type: " + nodeType);
//         if(ordinal < pointers.length)
//             return pointers[ordinal];
//         return -1;
//     }
// 
//     public void addPointers(String nodeType, long pointers[]) {
//         pointersByOrdinal.put(nodeType, pointers);
//     }
// 
//     public int numPointers(String nodeType) {
//         return pointersByOrdinal.get(nodeType).length;
//     }
// 
//     public Map<String, long[]> asMap() {
//         return pointersByOrdinal;
//     }
// 
// }
// 
// Path: src/main/java/com/netflix/nfgraph/compressed/NFCompressedGraphPointers.java
// public interface NFCompressedGraphPointers {
// 
//     /**
//      * @return the offset into the {@link NFCompressedGraph}'s byte array for the node identified by the given type and ordinal.
//      */
//     public long getPointer(String nodeType, int ordinal);
// 
//     public int numPointers(String nodeType);
// 
//     public Map<String, long[]> asMap();
// 
// }


// Path: src/test/java/com/netflix/nfgraph/serializer/NFCompressedGraphPointersSerializerTest.java
import com.netflix.nfgraph.compressed.NFCompressedGraphIntPointers;
import com.netflix.nfgraph.compressed.NFCompressedGraphLongPointers;
import com.netflix.nfgraph.compressed.NFCompressedGraphPointers;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import org.junit.Assert;
import org.junit.Test;

/*
 *  Copyright 2014-2022 Netflix, Inc.
 *
 *     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.netflix.nfgraph.serializer;




public class NFCompressedGraphPointersSerializerTest {

    @Test
    public void dataLengthLessthan4GBUsesIntegerPointers() throws IOException {
        NFCompressedGraphLongPointers pointers = new NFCompressedGraphLongPointers();
        pointers.addPointers("test", new long[] { 1, 2, 3 });

        NFCompressedGraphPointersSerializer serializer = new NFCompressedGraphPointersSerializer(pointers, (long)Integer.MAX_VALUE * 2);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(baos);

        serializer.serializePointers(dos);

        DataInputStream dis = new DataInputStream(new ByteArrayInputStream(baos.toByteArray()));

        NFCompressedGraphPointers deserialized = new NFCompressedGraphPointersDeserializer().deserializePointers(dis);

        Assert.assertTrue(deserialized instanceof NFCompressedGraphIntPointers);