Factor out a method for converting PersonIdent to GitPerson

Created a new, common class for this kind of thing; hopefully it grows
some more methods.

Change-Id: I0a7d99e78a54694f898fd56822ae9cbd42f2df05
This commit is contained in:
Dave Borowitz
2014-08-07 13:40:03 -07:00
parent d4ab000a20
commit dc9c0d03ff
4 changed files with 49 additions and 24 deletions

View File

@@ -0,0 +1,42 @@
// Copyright (C) 2014 The Android Open Source Project
//
// 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.google.gerrit.server;
import com.google.gerrit.extensions.common.GitPerson;
import org.eclipse.jgit.lib.PersonIdent;
import java.sql.Timestamp;
/**
* Converters to classes in {@link com.google.gerrit.extensions.common}.
* <p>
* The server frequently needs to convert internal types to types exposed in the
* extension API, but the converters themselves are not part of this API. This
* class contains such converters as static utility methods.
*/
public class CommonConverters {
public static GitPerson toGitPerson(PersonIdent ident) {
GitPerson result = new GitPerson();
result.name = ident.getName();
result.email = ident.getEmailAddress();
result.date = new Timestamp(ident.getWhen().getTime());
result.tz = ident.getTimeZoneOffset();
return result;
}
private CommonConverters() {
}
}