com.github.dennisit.vplus.data.plugin.ask.AskMixup Maven / Gradle / Ivy
/*--------------------------------------------------------------------------
* Copyright (c) 2010-2020, Elon.su All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the elon developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Elon.su, you can also mail [email protected]
*--------------------------------------------------------------------------
*/
package com.github.dennisit.vplus.data.plugin.ask;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.List;
/**
* Created by Elon.su on 2018/1/18.
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AskMixup {
@ApiModelProperty("问题")
private String title;
@ApiModelProperty("待选项")
private List options;
public void validator() {
if (StringUtils.isBlank(getTitle()) || CollectionUtils.isEmpty(getOptions())) {
throw new IllegalArgumentException("错误题目");
}
}
@Override
public String toString() {
StringBuffer tmp = new StringBuffer();
tmp.append("\r\n").append("问题").append(this.getTitle()).append("\r\n");
for (int i = 0; i < getOptions().size(); i++) {
if (i < getOptions().size() - 1) {
tmp.append(i + 1).append(".").append(getOptions().get(i)).append("\r\n");
continue;
}
tmp.append(i + 1).append(".").append(getOptions().get(i));
}
return tmp.toString();
}
}