
com.github.joekerouac.common.tools.resource.impl.TextResource Maven / Gradle / Ivy
The newest version!
// Generated by delombok at Fri Mar 14 11:41:38 CST 2025
/*
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE
* file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
* to You 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.github.joekerouac.common.tools.resource.impl;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import com.github.joekerouac.common.tools.constant.Const;
import com.github.joekerouac.common.tools.constant.ExceptionProviderConst;
import com.github.joekerouac.common.tools.resource.Resource;
import com.github.joekerouac.common.tools.enums.ResourceType;
import com.github.joekerouac.common.tools.util.Assert;
/**
* 以提供的文本作为资源
*
* @author JoeKerouac
* @date 2022-10-14 14:37:00
* @since 1.0.0
*/
public class TextResource implements Resource {
/**
* {@link #name}字段名
*/
public static final String NAME_FIELD_NAME = "name";
/**
* {@link #text}字段名
*/
public static final String TEXT_FIELD_NAME = "text";
/**
* 资源名
*/
private final String name;
/**
* 实际的数据
*/
private final String text;
public TextResource(Map map) {
this(map.get(NAME_FIELD_NAME), map.get(TEXT_FIELD_NAME));
}
public TextResource(String name, String text) {
Assert.notBlank(name, "name must not be blank", ExceptionProviderConst.IllegalArgumentExceptionProvider);
Assert.notBlank(text, "text must not be blank", ExceptionProviderConst.IllegalArgumentExceptionProvider);
this.name = name;
this.text = text;
}
@Override
public Map toMap() {
Map map = new HashMap<>();
map.put(NAME_FIELD_NAME, name);
map.put(TEXT_FIELD_NAME, text);
return map;
}
@Override
public ResourceType type() {
return ResourceType.TEXT_RESOURCE;
}
@Override
public InputStream getInputStream() throws IOException {
return new ByteArrayInputStream(text.getBytes(Const.DEFAULT_CHARSET));
}
@Override
public String getName() {
return name;
}
@Override
public URL getUrl() throws IOException {
return null;
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
@lombok.Generated
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof TextResource)) return false;
final TextResource other = (TextResource) o;
if (!other.canEqual((java.lang.Object) this)) return false;
final java.lang.Object this$name = this.getName();
final java.lang.Object other$name = other.getName();
if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false;
final java.lang.Object this$text = this.getText();
final java.lang.Object other$text = other.getText();
if (this$text == null ? other$text != null : !this$text.equals(other$text)) return false;
return true;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
protected boolean canEqual(final java.lang.Object other) {
return other instanceof TextResource;
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
@lombok.Generated
public int hashCode() {
final int PRIME = 59;
int result = 1;
final java.lang.Object $name = this.getName();
result = result * PRIME + ($name == null ? 43 : $name.hashCode());
final java.lang.Object $text = this.getText();
result = result * PRIME + ($text == null ? 43 : $text.hashCode());
return result;
}
/**
* 实际的数据
*/
@java.lang.SuppressWarnings("all")
@lombok.Generated
public String getText() {
return this.text;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy