// Path: src/main/java/kafka/common/ErrorMapping.java
// public abstract class ErrorMapping {
//     public static final ByteBuffer EmptyByteBuffer = ByteBuffer.allocate(0);
// 
//     public static final short UnknownCode = -1;
//     public static final short NoError = 0;
//     public static final short OffsetOutOfRangeCode = 1;
//     public static final short InvalidMessageCode = 2;
//     public static final short UnknownTopicOrPartitionCode = 3;
//     public static final short InvalidFetchSizeCode = 4;
//     public static final short LeaderNotAvailableCode = 5;
//     public static final short NotLeaderForPartitionCode = 6;
//     public static final short RequestTimedOutCode = 7;
//     public static final short BrokerNotAvailableCode = 8;
//     public static final short ReplicaNotAvailableCode = 9;
//     public static final short MessageSizeTooLargeCode = 10;
//     public static final short StaleControllerEpochCode = 11;
//     public static final short OffsetMetadataTooLargeCode = 12;
//     public static final short StaleLeaderEpochCode = 13;
// 
//     private static BiMap<Class<? extends Throwable>, Short> exceptionToCode;
// 
//     static {
//         exceptionToCode.put(OffsetOutOfRangeException.class, OffsetOutOfRangeCode);
//         exceptionToCode.put(InvalidMessageException.class, InvalidMessageCode);
//         exceptionToCode.put(UnknownTopicOrPartitionException.class, UnknownTopicOrPartitionCode);
//         exceptionToCode.put(InvalidMessageSizeException.class, InvalidFetchSizeCode);
//         exceptionToCode.put(NotLeaderForPartitionException.class, NotLeaderForPartitionCode);
//         exceptionToCode.put(LeaderNotAvailableException.class, LeaderNotAvailableCode);
//         exceptionToCode.put(RequestTimedOutException.class, RequestTimedOutCode);
//         exceptionToCode.put(BrokerNotAvailableException.class, BrokerNotAvailableCode);
//         exceptionToCode.put(ReplicaNotAvailableException.class, ReplicaNotAvailableCode);
//         exceptionToCode.put(MessageSizeTooLargeException.class, MessageSizeTooLargeCode);
//         exceptionToCode.put(ControllerMovedException.class, StaleControllerEpochCode);
//         exceptionToCode.put(OffsetMetadataTooLargeException.class, OffsetMetadataTooLargeCode);
//     }
// 
//     public static Short codeFor(Class<? extends Throwable> exception) {
//         return Objects.firstNonNull(exceptionToCode.get(exception), UnknownCode);
//     }
// 
//     public static void maybeThrowException(Short code) {
//         Throwable throwable = exceptionFor(code);
//         if (throwable != null) {
//             throw Throwables.propagate(throwable);
//         }
//     }
// 
//     static Logger logger = LoggerFactory.getLogger(ErrorMapping.class);
// 
//     public static KafkaException exceptionFor(Short code) {
//         Class<? extends Throwable> throwable = exceptionToCode.inverse().get(code);
//         if (throwable == null) return null;
// 
//         try {
//             return (KafkaException) throwable.newInstance();
//         } catch (Exception e) {
//             logger.error("create instance of {} error", throwable, e);
//         }
//         return null;
//     }
// }
// 
// Path: src/main/java/kafka/common/TopicAndPartition.java
// public class TopicAndPartition {
//     public final String topic;
//     public final int partition;
// 
//     public TopicAndPartition(String topic, int partition) {
//         this.topic = topic;
//         this.partition = partition;
//     }
// 
//     public TopicAndPartition(Tuple2<String, Integer> tuple) {
//         this(tuple._1, tuple._2);
//     }
// 
//     public TopicAndPartition(Partition partition) {
//         this(partition.topic, partition.partitionId);
//     }
// 
//     public TopicAndPartition(Replica replica) {
//         this(replica.topic, replica.partitionId);
//     }
// 
//     public Tuple2<String, Integer> asTuple() {
//         return Tuple2.make(topic, partition);
//     }
// 
//     @Override
//     public String toString() {
//         return String.format("[%s,%d]", topic, partition);
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//         if (this == o) return true;
//         if (o == null || getClass() != o.getClass()) return false;
// 
//         TopicAndPartition that = (TopicAndPartition) o;
// 
//         if (partition != that.partition) return false;
//         if (topic != null ? !topic.equals(that.topic) : that.topic != null) return false;
// 
//         return true;
//     }
// 
//     @Override
//     public int hashCode() {
//         int result = topic != null ? topic.hashCode() : 0;
//         result = 31 * result + partition;
//         return result;
//     }
// }


import com.google.common.collect.Table;
import kafka.common.ErrorMapping;
import kafka.common.TopicAndPartition;
import kafka.utils.*;
import java.nio.ByteBuffer;
import java.util.Map;
import static kafka.api.ApiUtils.*;
                                        new ProducerResponseStatus(error, offset));
                            }
                        });
                    }
                });

        return new ProducerResponse(correlationId, status);
    }

    public Map<TopicAndPartition, ProducerResponseStatus> status;

    public ProducerResponse(int correlationId, Map<TopicAndPartition, ProducerResponseStatus> status) {
        super(correlationId);
        this.status = status;

        statusGroupedByTopic = Utils.groupBy(status, new Function2<TopicAndPartition, ProducerResponseStatus, String>() {
            @Override
            public String apply(TopicAndPartition arg1, ProducerResponseStatus arg2) {
                return arg1.topic;
            }
        });
    }

    /**
     * Partitions the status map into a map of maps (one for each topic).
     */
    private Table<String, TopicAndPartition, ProducerResponseStatus> statusGroupedByTopic;

    public boolean hasError() {
        return Utils.exists(status.values(), new Function1<ProducerResponseStatus, Boolean>() {
// Path: src/main/java/kafka/common/ErrorMapping.java
// public abstract class ErrorMapping {
//     public static final ByteBuffer EmptyByteBuffer = ByteBuffer.allocate(0);
// 
//     public static final short UnknownCode = -1;
//     public static final short NoError = 0;
//     public static final short OffsetOutOfRangeCode = 1;
//     public static final short InvalidMessageCode = 2;
//     public static final short UnknownTopicOrPartitionCode = 3;
//     public static final short InvalidFetchSizeCode = 4;
//     public static final short LeaderNotAvailableCode = 5;
//     public static final short NotLeaderForPartitionCode = 6;
//     public static final short RequestTimedOutCode = 7;
//     public static final short BrokerNotAvailableCode = 8;
//     public static final short ReplicaNotAvailableCode = 9;
//     public static final short MessageSizeTooLargeCode = 10;
//     public static final short StaleControllerEpochCode = 11;
//     public static final short OffsetMetadataTooLargeCode = 12;
//     public static final short StaleLeaderEpochCode = 13;
// 
//     private static BiMap<Class<? extends Throwable>, Short> exceptionToCode;
// 
//     static {
//         exceptionToCode.put(OffsetOutOfRangeException.class, OffsetOutOfRangeCode);
//         exceptionToCode.put(InvalidMessageException.class, InvalidMessageCode);
//         exceptionToCode.put(UnknownTopicOrPartitionException.class, UnknownTopicOrPartitionCode);
//         exceptionToCode.put(InvalidMessageSizeException.class, InvalidFetchSizeCode);
//         exceptionToCode.put(NotLeaderForPartitionException.class, NotLeaderForPartitionCode);
//         exceptionToCode.put(LeaderNotAvailableException.class, LeaderNotAvailableCode);
//         exceptionToCode.put(RequestTimedOutException.class, RequestTimedOutCode);
//         exceptionToCode.put(BrokerNotAvailableException.class, BrokerNotAvailableCode);
//         exceptionToCode.put(ReplicaNotAvailableException.class, ReplicaNotAvailableCode);
//         exceptionToCode.put(MessageSizeTooLargeException.class, MessageSizeTooLargeCode);
//         exceptionToCode.put(ControllerMovedException.class, StaleControllerEpochCode);
//         exceptionToCode.put(OffsetMetadataTooLargeException.class, OffsetMetadataTooLargeCode);
//     }
// 
//     public static Short codeFor(Class<? extends Throwable> exception) {
//         return Objects.firstNonNull(exceptionToCode.get(exception), UnknownCode);
//     }
// 
//     public static void maybeThrowException(Short code) {
//         Throwable throwable = exceptionFor(code);
//         if (throwable != null) {
//             throw Throwables.propagate(throwable);
//         }
//     }
// 
//     static Logger logger = LoggerFactory.getLogger(ErrorMapping.class);
// 
//     public static KafkaException exceptionFor(Short code) {
//         Class<? extends Throwable> throwable = exceptionToCode.inverse().get(code);
//         if (throwable == null) return null;
// 
//         try {
//             return (KafkaException) throwable.newInstance();
//         } catch (Exception e) {
//             logger.error("create instance of {} error", throwable, e);
//         }
//         return null;
//     }
// }
// 
// Path: src/main/java/kafka/common/TopicAndPartition.java
// public class TopicAndPartition {
//     public final String topic;
//     public final int partition;
// 
//     public TopicAndPartition(String topic, int partition) {
//         this.topic = topic;
//         this.partition = partition;
//     }
// 
//     public TopicAndPartition(Tuple2<String, Integer> tuple) {
//         this(tuple._1, tuple._2);
//     }
// 
//     public TopicAndPartition(Partition partition) {
//         this(partition.topic, partition.partitionId);
//     }
// 
//     public TopicAndPartition(Replica replica) {
//         this(replica.topic, replica.partitionId);
//     }
// 
//     public Tuple2<String, Integer> asTuple() {
//         return Tuple2.make(topic, partition);
//     }
// 
//     @Override
//     public String toString() {
//         return String.format("[%s,%d]", topic, partition);
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//         if (this == o) return true;
//         if (o == null || getClass() != o.getClass()) return false;
// 
//         TopicAndPartition that = (TopicAndPartition) o;
// 
//         if (partition != that.partition) return false;
//         if (topic != null ? !topic.equals(that.topic) : that.topic != null) return false;
// 
//         return true;
//     }
// 
//     @Override
//     public int hashCode() {
//         int result = topic != null ? topic.hashCode() : 0;
//         result = 31 * result + partition;
//         return result;
//     }
// }


// Path: src/main/java/kafka/api/ProducerResponse.java
import com.google.common.collect.Table;
import kafka.common.ErrorMapping;
import kafka.common.TopicAndPartition;
import kafka.utils.*;
import java.nio.ByteBuffer;
import java.util.Map;
import static kafka.api.ApiUtils.*;

                                        new ProducerResponseStatus(error, offset));
                            }
                        });
                    }
                });

        return new ProducerResponse(correlationId, status);
    }

    public Map<TopicAndPartition, ProducerResponseStatus> status;

    public ProducerResponse(int correlationId, Map<TopicAndPartition, ProducerResponseStatus> status) {
        super(correlationId);
        this.status = status;

        statusGroupedByTopic = Utils.groupBy(status, new Function2<TopicAndPartition, ProducerResponseStatus, String>() {
            @Override
            public String apply(TopicAndPartition arg1, ProducerResponseStatus arg2) {
                return arg1.topic;
            }
        });
    }

    /**
     * Partitions the status map into a map of maps (one for each topic).
     */
    private Table<String, TopicAndPartition, ProducerResponseStatus> statusGroupedByTopic;

    public boolean hasError() {
        return Utils.exists(status.values(), new Function1<ProducerResponseStatus, Boolean>() {
            @Override