OLD | NEW |
1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
4 // | 4 // |
5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
7 // met: | 7 // met: |
8 // | 8 // |
9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 * @author kenton@google.com (Kenton Varda) | 53 * @author kenton@google.com (Kenton Varda) |
54 */ | 54 */ |
55 public final class Internal { | 55 public final class Internal { |
56 | 56 |
57 private Internal() {} | 57 private Internal() {} |
58 | 58 |
59 static final Charset UTF_8 = Charset.forName("UTF-8"); | 59 static final Charset UTF_8 = Charset.forName("UTF-8"); |
60 static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1"); | 60 static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1"); |
61 | 61 |
62 /** | 62 /** |
63 * Throws an appropriate {@link NullPointerException} if the given objects is
{@code null}. | |
64 */ | |
65 static <T> T checkNotNull(T obj, String message) { | |
66 if (obj == null) { | |
67 throw new NullPointerException(message); | |
68 } | |
69 return obj; | |
70 } | |
71 | |
72 /** | |
73 * Helper called by generated code to construct default values for string | 63 * Helper called by generated code to construct default values for string |
74 * fields. | 64 * fields. |
75 * <p> | 65 * <p> |
76 * The protocol compiler does not actually contain a UTF-8 decoder -- it | 66 * The protocol compiler does not actually contain a UTF-8 decoder -- it |
77 * just pushes UTF-8-encoded text around without touching it. The one place | 67 * just pushes UTF-8-encoded text around without touching it. The one place |
78 * where this presents a problem is when generating Java string literals. | 68 * where this presents a problem is when generating Java string literals. |
79 * Unicode characters in the string literal would normally need to be encoded | 69 * Unicode characters in the string literal would normally need to be encoded |
80 * using a Unicode escape sequence, which would require decoding them. | 70 * using a Unicode escape sequence, which would require decoding them. |
81 * To get around this, protoc instead embeds the UTF-8 bytes into the | 71 * To get around this, protoc instead embeds the UTF-8 bytes into the |
82 * generated code and leaves it to the runtime library to decode them. | 72 * generated code and leaves it to the runtime library to decode them. |
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 * possible. Does not support null elements. | 604 * possible. Does not support null elements. |
615 */ | 605 */ |
616 public static interface IntList extends ProtobufList<Integer> { | 606 public static interface IntList extends ProtobufList<Integer> { |
617 | 607 |
618 /** | 608 /** |
619 * Like {@link #get(int)} but more efficient in that it doesn't box the retu
rned value. | 609 * Like {@link #get(int)} but more efficient in that it doesn't box the retu
rned value. |
620 */ | 610 */ |
621 int getInt(int index); | 611 int getInt(int index); |
622 | 612 |
623 /** | 613 /** |
624 * Like {@link #add(Object)} but more efficient in that it doesn't box the e
lement. | 614 * Like {@link #add(Integer)} but more efficient in that it doesn't box the
element. |
625 */ | 615 */ |
626 void addInt(int element); | 616 void addInt(int element); |
627 | 617 |
628 /** | 618 /** |
629 * Like {@link #set(int, Object)} but more efficient in that it doesn't box
the element. | 619 * Like {@link #set(int, Integer)} but more efficient in that it doesn't box
the element. |
630 */ | 620 */ |
631 int setInt(int index, int element); | 621 int setInt(int index, int element); |
632 | 622 |
633 /** | 623 /** |
634 * Returns a mutable clone of this list with the specified capacity. | 624 * Returns a mutable clone of this list with the specified capacity. |
635 */ | 625 */ |
636 @Override | 626 @Override |
637 IntList mutableCopyWithCapacity(int capacity); | 627 IntList mutableCopyWithCapacity(int capacity); |
638 } | 628 } |
639 | 629 |
640 /** | 630 /** |
641 * A {@link java.util.List} implementation that avoids boxing the elements int
o Booleans if | 631 * A {@link java.util.List} implementation that avoids boxing the elements int
o Booleans if |
642 * possible. Does not support null elements. | 632 * possible. Does not support null elements. |
643 */ | 633 */ |
644 public static interface BooleanList extends ProtobufList<Boolean> { | 634 public static interface BooleanList extends ProtobufList<Boolean> { |
645 | 635 |
646 /** | 636 /** |
647 * Like {@link #get(int)} but more efficient in that it doesn't box the retu
rned value. | 637 * Like {@link #get(int)} but more efficient in that it doesn't box the retu
rned value. |
648 */ | 638 */ |
649 boolean getBoolean(int index); | 639 boolean getBoolean(int index); |
650 | 640 |
651 /** | 641 /** |
652 * Like {@link #add(Object)} but more efficient in that it doesn't box the e
lement. | 642 * Like {@link #add(Boolean)} but more efficient in that it doesn't box the
element. |
653 */ | 643 */ |
654 void addBoolean(boolean element); | 644 void addBoolean(boolean element); |
655 | 645 |
656 /** | 646 /** |
657 * Like {@link #set(int, Object)} but more efficient in that it doesn't box
the element. | 647 * Like {@link #set(int, Boolean)} but more efficient in that it doesn't box
the element. |
658 */ | 648 */ |
659 boolean setBoolean(int index, boolean element); | 649 boolean setBoolean(int index, boolean element); |
660 | 650 |
661 /** | 651 /** |
662 * Returns a mutable clone of this list with the specified capacity. | 652 * Returns a mutable clone of this list with the specified capacity. |
663 */ | 653 */ |
664 @Override | 654 @Override |
665 BooleanList mutableCopyWithCapacity(int capacity); | 655 BooleanList mutableCopyWithCapacity(int capacity); |
666 } | 656 } |
667 | 657 |
668 /** | 658 /** |
669 * A {@link java.util.List} implementation that avoids boxing the elements int
o Longs if | 659 * A {@link java.util.List} implementation that avoids boxing the elements int
o Longs if |
670 * possible. Does not support null elements. | 660 * possible. Does not support null elements. |
671 */ | 661 */ |
672 public static interface LongList extends ProtobufList<Long> { | 662 public static interface LongList extends ProtobufList<Long> { |
673 | 663 |
674 /** | 664 /** |
675 * Like {@link #get(int)} but more efficient in that it doesn't box the retu
rned value. | 665 * Like {@link #get(int)} but more efficient in that it doesn't box the retu
rned value. |
676 */ | 666 */ |
677 long getLong(int index); | 667 long getLong(int index); |
678 | 668 |
679 /** | 669 /** |
680 * Like {@link #add(Object)} but more efficient in that it doesn't box the e
lement. | 670 * Like {@link #add(Long)} but more efficient in that it doesn't box the ele
ment. |
681 */ | 671 */ |
682 void addLong(long element); | 672 void addLong(long element); |
683 | 673 |
684 /** | 674 /** |
685 * Like {@link #set(int, Object)} but more efficient in that it doesn't box
the element. | 675 * Like {@link #set(int, Long)} but more efficient in that it doesn't box th
e element. |
686 */ | 676 */ |
687 long setLong(int index, long element); | 677 long setLong(int index, long element); |
688 | 678 |
689 /** | 679 /** |
690 * Returns a mutable clone of this list with the specified capacity. | 680 * Returns a mutable clone of this list with the specified capacity. |
691 */ | 681 */ |
692 @Override | 682 @Override |
693 LongList mutableCopyWithCapacity(int capacity); | 683 LongList mutableCopyWithCapacity(int capacity); |
694 } | 684 } |
695 | 685 |
696 /** | 686 /** |
697 * A {@link java.util.List} implementation that avoids boxing the elements int
o Doubles if | 687 * A {@link java.util.List} implementation that avoids boxing the elements int
o Doubles if |
698 * possible. Does not support null elements. | 688 * possible. Does not support null elements. |
699 */ | 689 */ |
700 public static interface DoubleList extends ProtobufList<Double> { | 690 public static interface DoubleList extends ProtobufList<Double> { |
701 | 691 |
702 /** | 692 /** |
703 * Like {@link #get(int)} but more efficient in that it doesn't box the retu
rned value. | 693 * Like {@link #get(int)} but more efficient in that it doesn't box the retu
rned value. |
704 */ | 694 */ |
705 double getDouble(int index); | 695 double getDouble(int index); |
706 | 696 |
707 /** | 697 /** |
708 * Like {@link #add(Object)} but more efficient in that it doesn't box the e
lement. | 698 * Like {@link #add(Double)} but more efficient in that it doesn't box the e
lement. |
709 */ | 699 */ |
710 void addDouble(double element); | 700 void addDouble(double element); |
711 | 701 |
712 /** | 702 /** |
713 * Like {@link #set(int, Object)} but more efficient in that it doesn't box
the element. | 703 * Like {@link #set(int, Double)} but more efficient in that it doesn't box
the element. |
714 */ | 704 */ |
715 double setDouble(int index, double element); | 705 double setDouble(int index, double element); |
716 | 706 |
717 /** | 707 /** |
718 * Returns a mutable clone of this list with the specified capacity. | 708 * Returns a mutable clone of this list with the specified capacity. |
719 */ | 709 */ |
720 @Override | 710 @Override |
721 DoubleList mutableCopyWithCapacity(int capacity); | 711 DoubleList mutableCopyWithCapacity(int capacity); |
722 } | 712 } |
723 | 713 |
724 /** | 714 /** |
725 * A {@link java.util.List} implementation that avoids boxing the elements int
o Floats if | 715 * A {@link java.util.List} implementation that avoids boxing the elements int
o Floats if |
726 * possible. Does not support null elements. | 716 * possible. Does not support null elements. |
727 */ | 717 */ |
728 public static interface FloatList extends ProtobufList<Float> { | 718 public static interface FloatList extends ProtobufList<Float> { |
729 | 719 |
730 /** | 720 /** |
731 * Like {@link #get(int)} but more efficient in that it doesn't box the retu
rned value. | 721 * Like {@link #get(int)} but more efficient in that it doesn't box the retu
rned value. |
732 */ | 722 */ |
733 float getFloat(int index); | 723 float getFloat(int index); |
734 | 724 |
735 /** | 725 /** |
736 * Like {@link #add(Object)} but more efficient in that it doesn't box the e
lement. | 726 * Like {@link #add(Float)} but more efficient in that it doesn't box the el
ement. |
737 */ | 727 */ |
738 void addFloat(float element); | 728 void addFloat(float element); |
739 | 729 |
740 /** | 730 /** |
741 * Like {@link #set(int, Object)} but more efficient in that it doesn't box
the element. | 731 * Like {@link #set(int, Float)} but more efficient in that it doesn't box t
he element. |
742 */ | 732 */ |
743 float setFloat(int index, float element); | 733 float setFloat(int index, float element); |
744 | 734 |
745 /** | 735 /** |
746 * Returns a mutable clone of this list with the specified capacity. | 736 * Returns a mutable clone of this list with the specified capacity. |
747 */ | 737 */ |
748 @Override | 738 @Override |
749 FloatList mutableCopyWithCapacity(int capacity); | 739 FloatList mutableCopyWithCapacity(int capacity); |
750 } | 740 } |
751 } | 741 } |
OLD | NEW |