// Path: src/main/java/com/ccreanga/bitbucket/rest/client/model/CommentAnchor.java
// public class CommentAnchor implements Serializable {
// 
//     private String fromHash;
//     @Nonnull
//     private String toHash;
//     private long line;
//     private LineType lineType;
//     private FileType fileType;
//     @Nonnull
//     private String path;
//     private String srcPath;
//     private boolean orphaned;
// 
//     private CommentAnchor() {
//     }
// 
//     public CommentAnchor(String fromHash, String toHash, long line, LineType lineType, FileType fileType, String path, String srcPath, boolean orphaned) {
//         this.fromHash = fromHash;
//         this.toHash = toHash;
//         this.line = line;
//         this.lineType = lineType;
//         this.fileType = fileType;
//         this.path = path;
//         this.srcPath = srcPath;
//         this.orphaned = orphaned;
//     }
// 
//     public String getFromHash() {
//         return fromHash;
//     }
// 
//     public String getToHash() {
//         return toHash;
//     }
// 
//     public long getLine() {
//         return line;
//     }
// 
//     public LineType getLineType() {
//         return lineType;
//     }
// 
//     public FileType getFileType() {
//         return fileType;
//     }
// 
//     public String getPath() {
//         return path;
//     }
// 
//     public String getSrcPath() {
//         return srcPath;
//     }
// 
//     public boolean isOrphaned() {
//         return orphaned;
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//         if (this == o) return true;
//         if (o == null || getClass() != o.getClass()) return false;
//         CommentAnchor that = (CommentAnchor) o;
//         return Objects.equals(line, that.line) &&
//                 Objects.equals(orphaned, that.orphaned) &&
//                 Objects.equals(fromHash, that.fromHash) &&
//                 Objects.equals(toHash, that.toHash) &&
//                 Objects.equals(lineType, that.lineType) &&
//                 Objects.equals(fileType, that.fileType) &&
//                 Objects.equals(path, that.path) &&
//                 Objects.equals(srcPath, that.srcPath);
//     }
// 
//     @Override
//     public int hashCode() {
//         return Objects.hash(fromHash, toHash, line, lineType, fileType, path, srcPath, orphaned);
//     }
// 
//     @Override
//     public String toString() {
//         return "CommentAnchor{" +
//                 "fromHash='" + fromHash + '\'' +
//                 ", toHash='" + toHash + '\'' +
//                 ", line=" + line +
//                 ", lineType=" + lineType +
//                 ", fileType=" + fileType +
//                 ", path='" + path + '\'' +
//                 ", srcPath='" + srcPath + '\'' +
//                 ", orphaned=" + orphaned +
//                 '}';
//     }
// }
// 
// Path: src/main/java/com/ccreanga/bitbucket/rest/client/model/FileType.java
// public enum FileType implements Serializable {
//     FROM,TO
// }
// 
// Path: src/main/java/com/ccreanga/bitbucket/rest/client/model/LineType.java
// public enum LineType implements Serializable {
//     ADDED,REMOVED,CONTEXT;
// }
// 
// Path: src/main/java/com/ccreanga/bitbucket/rest/client/http/responseparsers/ParserUtil.java
// public class ParserUtil {
// 
//     public static boolean optionalJsonBoolean(JsonObject json, String name) {
//         JsonElement element = json.get(name);
//         if ((element == null) || (element.isJsonNull()))
//             return false;
//         return element.getAsBoolean();
//     }
// 
//     public static long optionalJsonLong(JsonObject json, String name) {
//         JsonElement element = json.get(name);
//         if ((element == null) || (element.isJsonNull()))
//             return -1;
//         return element.getAsLong();
//     }
// 
//     public static String optionalJsonString(JsonObject json, String name) {
//         JsonElement element = json.get(name);
//         if ((element == null) || (element.isJsonNull()))
//             return null;
//         return element.getAsString();
//     }
// }


import com.ccreanga.bitbucket.rest.client.model.CommentAnchor;
import com.ccreanga.bitbucket.rest.client.model.FileType;
import com.ccreanga.bitbucket.rest.client.model.LineType;
import java.util.function.Function;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import static com.ccreanga.bitbucket.rest.client.http.responseparsers.ParserUtil.*;
/*
 *
 *  *
 *  * 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.ccreanga.bitbucket.rest.client.http.responseparsers;



public class CommentAnchorParser implements Function<JsonElement, CommentAnchor> {
    @Override
    public CommentAnchor apply(JsonElement jsonElement) {
        if (jsonElement == null || !jsonElement.isJsonObject()) {
            return null;
        }

        JsonObject json = jsonElement.getAsJsonObject();
        return new CommentAnchor(
                optionalJsonString(json, "fromHash"),
                json.get("toHash").getAsString(),
                optionalJsonLong(json, "line"),
// Path: src/main/java/com/ccreanga/bitbucket/rest/client/model/CommentAnchor.java
// public class CommentAnchor implements Serializable {
// 
//     private String fromHash;
//     @Nonnull
//     private String toHash;
//     private long line;
//     private LineType lineType;
//     private FileType fileType;
//     @Nonnull
//     private String path;
//     private String srcPath;
//     private boolean orphaned;
// 
//     private CommentAnchor() {
//     }
// 
//     public CommentAnchor(String fromHash, String toHash, long line, LineType lineType, FileType fileType, String path, String srcPath, boolean orphaned) {
//         this.fromHash = fromHash;
//         this.toHash = toHash;
//         this.line = line;
//         this.lineType = lineType;
//         this.fileType = fileType;
//         this.path = path;
//         this.srcPath = srcPath;
//         this.orphaned = orphaned;
//     }
// 
//     public String getFromHash() {
//         return fromHash;
//     }
// 
//     public String getToHash() {
//         return toHash;
//     }
// 
//     public long getLine() {
//         return line;
//     }
// 
//     public LineType getLineType() {
//         return lineType;
//     }
// 
//     public FileType getFileType() {
//         return fileType;
//     }
// 
//     public String getPath() {
//         return path;
//     }
// 
//     public String getSrcPath() {
//         return srcPath;
//     }
// 
//     public boolean isOrphaned() {
//         return orphaned;
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//         if (this == o) return true;
//         if (o == null || getClass() != o.getClass()) return false;
//         CommentAnchor that = (CommentAnchor) o;
//         return Objects.equals(line, that.line) &&
//                 Objects.equals(orphaned, that.orphaned) &&
//                 Objects.equals(fromHash, that.fromHash) &&
//                 Objects.equals(toHash, that.toHash) &&
//                 Objects.equals(lineType, that.lineType) &&
//                 Objects.equals(fileType, that.fileType) &&
//                 Objects.equals(path, that.path) &&
//                 Objects.equals(srcPath, that.srcPath);
//     }
// 
//     @Override
//     public int hashCode() {
//         return Objects.hash(fromHash, toHash, line, lineType, fileType, path, srcPath, orphaned);
//     }
// 
//     @Override
//     public String toString() {
//         return "CommentAnchor{" +
//                 "fromHash='" + fromHash + '\'' +
//                 ", toHash='" + toHash + '\'' +
//                 ", line=" + line +
//                 ", lineType=" + lineType +
//                 ", fileType=" + fileType +
//                 ", path='" + path + '\'' +
//                 ", srcPath='" + srcPath + '\'' +
//                 ", orphaned=" + orphaned +
//                 '}';
//     }
// }
// 
// Path: src/main/java/com/ccreanga/bitbucket/rest/client/model/FileType.java
// public enum FileType implements Serializable {
//     FROM,TO
// }
// 
// Path: src/main/java/com/ccreanga/bitbucket/rest/client/model/LineType.java
// public enum LineType implements Serializable {
//     ADDED,REMOVED,CONTEXT;
// }
// 
// Path: src/main/java/com/ccreanga/bitbucket/rest/client/http/responseparsers/ParserUtil.java
// public class ParserUtil {
// 
//     public static boolean optionalJsonBoolean(JsonObject json, String name) {
//         JsonElement element = json.get(name);
//         if ((element == null) || (element.isJsonNull()))
//             return false;
//         return element.getAsBoolean();
//     }
// 
//     public static long optionalJsonLong(JsonObject json, String name) {
//         JsonElement element = json.get(name);
//         if ((element == null) || (element.isJsonNull()))
//             return -1;
//         return element.getAsLong();
//     }
// 
//     public static String optionalJsonString(JsonObject json, String name) {
//         JsonElement element = json.get(name);
//         if ((element == null) || (element.isJsonNull()))
//             return null;
//         return element.getAsString();
//     }
// }


// Path: src/main/java/com/ccreanga/bitbucket/rest/client/http/responseparsers/CommentAnchorParser.java
import com.ccreanga.bitbucket.rest.client.model.CommentAnchor;
import com.ccreanga.bitbucket.rest.client.model.FileType;
import com.ccreanga.bitbucket.rest.client.model.LineType;
import java.util.function.Function;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import static com.ccreanga.bitbucket.rest.client.http.responseparsers.ParserUtil.*;

/*
 *
 *  *
 *  * 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.ccreanga.bitbucket.rest.client.http.responseparsers;



public class CommentAnchorParser implements Function<JsonElement, CommentAnchor> {
    @Override
    public CommentAnchor apply(JsonElement jsonElement) {
        if (jsonElement == null || !jsonElement.isJsonObject()) {
            return null;
        }

        JsonObject json = jsonElement.getAsJsonObject();
        return new CommentAnchor(
                optionalJsonString(json, "fromHash"),
                json.get("toHash").getAsString(),
                optionalJsonLong(json, "line"),
                json.has("lineType")?LineType.valueOf(json.get("lineType").getAsString()):null,