Java tutorial
/* * Copyright (C) 2015-2016 NS Solutions Corporation * * 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.htmlhifive.pitalium.core.model; import java.io.Serializable; import java.util.Arrays; import java.util.Collections; import java.util.List; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.htmlhifive.pitalium.common.util.JSONUtils; import com.htmlhifive.pitalium.image.model.CompareOption; import com.htmlhifive.pitalium.image.model.ScreenshotImage; /** * 1?????? */ @JsonInclude(JsonInclude.Include.NON_NULL) public class TargetResult implements Serializable { private static final long serialVersionUID = 1L; /** * ?? */ private ExecResult result; /** * ?????? */ private ScreenAreaResult target; /** * ??? */ private List<ScreenAreaResult> excludes; /** * ??{@link #target}????????? */ private Boolean moveTarget; /** * ???????? */ private List<DomSelector> hiddenElementSelectors; /** * ??? */ @JsonIgnore private ScreenshotImage image; /** * */ @JsonIgnore private CompareOption[] options; /** * ?????? */ public TargetResult() { } /** * ????? * * @param target ? * @param excludes ? * @param image ? */ public TargetResult(ScreenAreaResult target, List<ScreenAreaResult> excludes, ScreenshotImage image) { this(null, target, excludes, null, null, image, null); } /** * ????? * * @param result ? * @param target ? * @param excludes ? * @param moveTarget ??{@link #target}????????? * @param hiddenElementSelectors ???????? */ public TargetResult(ExecResult result, ScreenAreaResult target, List<ScreenAreaResult> excludes, Boolean moveTarget, List<DomSelector> hiddenElementSelectors) { this(result, target, excludes, moveTarget, hiddenElementSelectors, null, null); } /** * ????? * * @param result ? * @param target ? * @param excludes ? * @param moveTarget ??{@link #target}????????? * @param hiddenElementSelectors ???????? * @param image ? * @param options */ public TargetResult(ExecResult result, ScreenAreaResult target, List<ScreenAreaResult> excludes, Boolean moveTarget, List<DomSelector> hiddenElementSelectors, ScreenshotImage image, CompareOption[] options) { this.result = result; this.target = target; this.moveTarget = moveTarget; this.image = image; this.options = options; setExcludes(excludes); setHiddenElementSelectors(hiddenElementSelectors); } /** * ?????? * * @param excludes ? */ void setExcludes(List<ScreenAreaResult> excludes) { if (excludes == null || excludes.isEmpty()) { this.excludes = Collections.emptyList(); return; } this.excludes = Collections.unmodifiableList(excludes); } /** * ????????? * * @param hiddenElementSelectors ?????? */ void setHiddenElementSelectors(List<DomSelector> hiddenElementSelectors) { if (hiddenElementSelectors == null || hiddenElementSelectors.isEmpty()) { this.hiddenElementSelectors = Collections.emptyList(); return; } this.hiddenElementSelectors = Collections.unmodifiableList(hiddenElementSelectors); } /** * ????? * * @return ? */ public ExecResult getResult() { return result; } /** * ??????????? * * @return ??? */ public ScreenAreaResult getTarget() { return target; } /** * ??????? * * @return ? */ public List<ScreenAreaResult> getExcludes() { return excludes; } /** * ?{@link #target}???????????? * * @return ??????????true */ public Boolean isMoveTarget() { return moveTarget; } /** * ?????????? * * @return ????? */ public List<DomSelector> getHiddenElementSelectors() { return hiddenElementSelectors; } /** * ????? * * @return ? */ public ScreenshotImage getImage() { return image; } /** * ???? * * @return */ public CompareOption[] getOptions() { return options; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } TargetResult that = (TargetResult) o; if (result != that.result) { return false; } if (target != null ? !target.equals(that.target) : that.target != null) { return false; } if (excludes != null ? !excludes.equals(that.excludes) : that.excludes != null) { return false; } if (moveTarget != null ? !moveTarget.equals(that.moveTarget) : that.moveTarget != null) { return false; } if (hiddenElementSelectors != null ? !hiddenElementSelectors.equals(that.hiddenElementSelectors) : that.hiddenElementSelectors != null) { return false; } if (image != null ? !image.equals(that.image) : that.image != null) { return false; } // Probably incorrect - comparing Object[] arrays with Arrays.equals return Arrays.equals(options, that.options); } @Override public int hashCode() { int result1 = result != null ? result.hashCode() : 0; final int hashPrime = 31; result1 = hashPrime * result1 + (target != null ? target.hashCode() : 0); result1 = hashPrime * result1 + (excludes != null ? excludes.hashCode() : 0); result1 = hashPrime * result1 + (moveTarget != null ? moveTarget.hashCode() : 0); result1 = hashPrime * result1 + (hiddenElementSelectors != null ? hiddenElementSelectors.hashCode() : 0); result1 = hashPrime * result1 + (image != null ? image.hashCode() : 0); result1 = hashPrime * result1 + (options != null ? Arrays.hashCode(options) : 0); return result1; } @Override public String toString() { return JSONUtils.toString(this); } }