// Path: java/core/src/main/java/eu/mais_h/mathsync/Summarizer.java
// public interface Summarizer {
// 
//   /**
//    * Produces a summary at a given level of detail.
//    *
//    * <p>The larger detail level is, the bigger summary will consume on the wire, but the more
//    * information it conveys.</p>
//    *
//    * @param level the level of detail.
//    * @return a summary of the current state at the requested level of detail.
//    */
//   Summary summarize(int level);
// }
// 
// Path: java/core/src/main/java/eu/mais_h/mathsync/SummarizerFromItems.java
// public class SummarizerFromItems implements Summarizer {
// 
//   private final SerializedItems items;
//   private final Digester digester;
//   private final BucketSelector selector;
// 
//   SummarizerFromItems(SerializedItems items, Digester digester, BucketSelector selector) {
//     this.items = items;
//     this.digester = digester;
//     this.selector = selector;
//   }
// 
//   /**
//    * {@inheritDoc}
//    *
//    * <p>Summaries produced have a size of <code>O(2^level)</code>.</p>
//    */
//   @Override
//   public Summary summarize(int level) {
//     int size = Defaults.ibfSizeFromLevel(level);
//     Summary empty;
//     if (size > items.size()) {
//       empty = FullContent.EMPTY;
//     } else {
//       empty = new Ibf(size, digester, selector);
//     }
//     Summary filled = empty.plus(items.iterator());
//     return filled;
//   }
// 
//   /**
//    * Builds a simple summarizer.
//    *
//    * @param items the set of containing all items in the current state.
//    * @param serializer the serializer to use to serialize items.
//    * @return a summarizer with {@link Sha1Digester SHA-1 digester} and default spread.
//    */
//   public static <T> Summarizer simple(Set<? extends T> items, Serializer<? super T> serializer) {
//     return custom(items, serializer, Sha1Digester.get(), Defaults.defaultSelector());
//   }
// 
//   /**
//    * Builds a custom summarizer.
//    *
//    * @param items the set of containing all items in the current state.
//    * @param serializer the serializer to use to serialize items.
//    * @param digester the custom digester to use.
//    * @param selector the strategy to choose buckets to store items in.
//    * @return a summarizer corresponding to the input.
//    */
//   public static <T> Summarizer custom(Set<? extends T> items, Serializer<? super T> serializer, Digester digester, BucketSelector selector) {
//     return new SummarizerFromItems(new SerializedItems(items, serializer), digester, selector);
//   }
// }
// 
// Path: java/core/src/main/java/eu/mais_h/mathsync/serialize/StringSerializer.java
// public class StringSerializer<T> implements Serializer<T> {
// 
//   private final Function<T, String> toString;
// 
//   private StringSerializer(Function<T, String> toString) {
//     this.toString = toString;
//   }
// 
//   @Override
//   public byte[] serialize(T item) {
//     String stringified = toString.apply(item);
//     byte[] result;
//     try {
//       result = stringified.getBytes("UTF-8");
//     } catch (UnsupportedEncodingException e) {
//       throw new AssertionError("JVM does not support UTF-8 encoding");
//     }
//     return result;
//   }
// 
//   /**
//    * Retrieves an instance of this serializer.
//    *
//    * @param toString the function to convert items to string as an intermediate representation.
//    * @return an instance of this serializer kind.
//    */
//   public static <T> Serializer<T> create(Function<T, String> toString) {
//     return new StringSerializer<>(toString);
//   }
// 
//   /**
//    * Retrieves an instance of this serializer directly serializing strings.
//    *
//    * @return an instance of this serializer kind.
//    */
//   public static Serializer<String> create() {
//     return create(new Function<String, String>() {
// 
//       @Override
//       public String apply(String t) {
//         return t;
//       }
//     });
//   }
// }
// 
// Path: java/core/src/main/java/eu/mais_h/mathsync/util/Function.java
// public interface Function<T, R> {
// 
//   /**
//    * Applies this function to the given argument.
//    * 
//    * @param t the function argument.
//    * @return the function result.
//    */
//   R apply(T t);
// }


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import eu.mais_h.mathsync.Summarizer;
import eu.mais_h.mathsync.SummarizerFromItems;
import eu.mais_h.mathsync.serialize.StringSerializer;
import eu.mais_h.mathsync.util.Function;
package eu.mais_h.mathsync.test;





public class SummaryServlet extends HttpServlet {

  private static final long serialVersionUID = 8629863338196207094L;

  private final Map<String, String> content = Collections.synchronizedMap(new HashMap<String, String>());
// Path: java/core/src/main/java/eu/mais_h/mathsync/Summarizer.java
// public interface Summarizer {
// 
//   /**
//    * Produces a summary at a given level of detail.
//    *
//    * <p>The larger detail level is, the bigger summary will consume on the wire, but the more
//    * information it conveys.</p>
//    *
//    * @param level the level of detail.
//    * @return a summary of the current state at the requested level of detail.
//    */
//   Summary summarize(int level);
// }
// 
// Path: java/core/src/main/java/eu/mais_h/mathsync/SummarizerFromItems.java
// public class SummarizerFromItems implements Summarizer {
// 
//   private final SerializedItems items;
//   private final Digester digester;
//   private final BucketSelector selector;
// 
//   SummarizerFromItems(SerializedItems items, Digester digester, BucketSelector selector) {
//     this.items = items;
//     this.digester = digester;
//     this.selector = selector;
//   }
// 
//   /**
//    * {@inheritDoc}
//    *
//    * <p>Summaries produced have a size of <code>O(2^level)</code>.</p>
//    */
//   @Override
//   public Summary summarize(int level) {
//     int size = Defaults.ibfSizeFromLevel(level);
//     Summary empty;
//     if (size > items.size()) {
//       empty = FullContent.EMPTY;
//     } else {
//       empty = new Ibf(size, digester, selector);
//     }
//     Summary filled = empty.plus(items.iterator());
//     return filled;
//   }
// 
//   /**
//    * Builds a simple summarizer.
//    *
//    * @param items the set of containing all items in the current state.
//    * @param serializer the serializer to use to serialize items.
//    * @return a summarizer with {@link Sha1Digester SHA-1 digester} and default spread.
//    */
//   public static <T> Summarizer simple(Set<? extends T> items, Serializer<? super T> serializer) {
//     return custom(items, serializer, Sha1Digester.get(), Defaults.defaultSelector());
//   }
// 
//   /**
//    * Builds a custom summarizer.
//    *
//    * @param items the set of containing all items in the current state.
//    * @param serializer the serializer to use to serialize items.
//    * @param digester the custom digester to use.
//    * @param selector the strategy to choose buckets to store items in.
//    * @return a summarizer corresponding to the input.
//    */
//   public static <T> Summarizer custom(Set<? extends T> items, Serializer<? super T> serializer, Digester digester, BucketSelector selector) {
//     return new SummarizerFromItems(new SerializedItems(items, serializer), digester, selector);
//   }
// }
// 
// Path: java/core/src/main/java/eu/mais_h/mathsync/serialize/StringSerializer.java
// public class StringSerializer<T> implements Serializer<T> {
// 
//   private final Function<T, String> toString;
// 
//   private StringSerializer(Function<T, String> toString) {
//     this.toString = toString;
//   }
// 
//   @Override
//   public byte[] serialize(T item) {
//     String stringified = toString.apply(item);
//     byte[] result;
//     try {
//       result = stringified.getBytes("UTF-8");
//     } catch (UnsupportedEncodingException e) {
//       throw new AssertionError("JVM does not support UTF-8 encoding");
//     }
//     return result;
//   }
// 
//   /**
//    * Retrieves an instance of this serializer.
//    *
//    * @param toString the function to convert items to string as an intermediate representation.
//    * @return an instance of this serializer kind.
//    */
//   public static <T> Serializer<T> create(Function<T, String> toString) {
//     return new StringSerializer<>(toString);
//   }
// 
//   /**
//    * Retrieves an instance of this serializer directly serializing strings.
//    *
//    * @return an instance of this serializer kind.
//    */
//   public static Serializer<String> create() {
//     return create(new Function<String, String>() {
// 
//       @Override
//       public String apply(String t) {
//         return t;
//       }
//     });
//   }
// }
// 
// Path: java/core/src/main/java/eu/mais_h/mathsync/util/Function.java
// public interface Function<T, R> {
// 
//   /**
//    * Applies this function to the given argument.
//    * 
//    * @param t the function argument.
//    * @return the function result.
//    */
//   R apply(T t);
// }


// Path: integration-test/java-webapp/src/main/java/eu/mais_h/mathsync/test/SummaryServlet.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import eu.mais_h.mathsync.Summarizer;
import eu.mais_h.mathsync.SummarizerFromItems;
import eu.mais_h.mathsync.serialize.StringSerializer;
import eu.mais_h.mathsync.util.Function;

package eu.mais_h.mathsync.test;





public class SummaryServlet extends HttpServlet {

  private static final long serialVersionUID = 8629863338196207094L;

  private final Map<String, String> content = Collections.synchronizedMap(new HashMap<String, String>());
  private final Summarizer summarizer = SummarizerFromItems.simple(content.entrySet(), StringSerializer.create(new Function<Entry<String, String>, String>() {