Line data Source code
1 : // Copyright (C) 2018 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.entities.converter; 16 : 17 : import com.google.errorprone.annotations.Immutable; 18 : import com.google.gerrit.entities.Change; 19 : import com.google.gerrit.entities.PatchSet; 20 : import com.google.gerrit.proto.Entities; 21 : import com.google.protobuf.Parser; 22 : 23 104 : @Immutable 24 104 : public enum PatchSetIdProtoConverter implements ProtoConverter<Entities.PatchSet_Id, PatchSet.Id> { 25 104 : INSTANCE; 26 : 27 104 : private final ProtoConverter<Entities.Change_Id, Change.Id> changeIdConverter = 28 : ChangeIdProtoConverter.INSTANCE; 29 : 30 : @Override 31 : public Entities.PatchSet_Id toProto(PatchSet.Id patchSetId) { 32 104 : return Entities.PatchSet_Id.newBuilder() 33 104 : .setChangeId(changeIdConverter.toProto(patchSetId.changeId())) 34 104 : .setId(patchSetId.get()) 35 104 : .build(); 36 : } 37 : 38 : @Override 39 : public PatchSet.Id fromProto(Entities.PatchSet_Id proto) { 40 101 : return PatchSet.id(changeIdConverter.fromProto(proto.getChangeId()), proto.getId()); 41 : } 42 : 43 : @Override 44 : public Parser<Entities.PatchSet_Id> getParser() { 45 0 : return Entities.PatchSet_Id.parser(); 46 : } 47 : }