more CSV stuff
This commit is contained in:
parent
e9e2256e82
commit
78d7972d28
|
@ -0,0 +1,36 @@
|
||||||
|
package persistence.customTags;
|
||||||
|
|
||||||
|
import abstraction.PersistenceAdapter;
|
||||||
|
import persistence.GenericDAO;
|
||||||
|
import tag.matcherImplementations.CustomTagMatcher;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class CSVCustomTagMatcherPersistenceAdapter implements PersistenceAdapter<CustomTagMatcher> {
|
||||||
|
|
||||||
|
private final GenericDAO<CustomTagMatcherEntity> customTagMatcherDAO;
|
||||||
|
|
||||||
|
public CSVCustomTagMatcherPersistenceAdapter(GenericDAO<CustomTagMatcherEntity> customTagMatcherDAO) {
|
||||||
|
this.customTagMatcherDAO = customTagMatcherDAO;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<CustomTagMatcher> getAll() {
|
||||||
|
return customTagMatcherDAO
|
||||||
|
.getALl()
|
||||||
|
.stream()
|
||||||
|
.map(CustomTagMatcherEntity::toCustomTagMatcher)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void add(CustomTagMatcher value) {
|
||||||
|
customTagMatcherDAO.add(new CustomTagMatcherEntity(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void remove(CustomTagMatcher value) {
|
||||||
|
customTagMatcherDAO.remove(new CustomTagMatcherEntity(value));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
package persistence.customTags;
|
||||||
|
|
||||||
|
import persistence.csv.CSVSerializable;
|
||||||
|
import tag.TagName;
|
||||||
|
import tag.matcherImplementations.CustomTagMatcher;
|
||||||
|
|
||||||
|
public class CustomTagMatcherEntity implements CSVSerializable {
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
private final String regexString;
|
||||||
|
|
||||||
|
public CustomTagMatcherEntity(CustomTagMatcher customTagMatcher) {
|
||||||
|
this.name = customTagMatcher.getTagName().name();
|
||||||
|
this.regexString = customTagMatcher.getRegex().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomTagMatcherEntity(String[] fields) {
|
||||||
|
this.name = fields[0];
|
||||||
|
this.regexString = fields[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomTagMatcherEntity(String name, String regexString) {
|
||||||
|
this.name = name;
|
||||||
|
this.regexString = regexString;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomTagMatcher toCustomTagMatcher() {
|
||||||
|
return new CustomTagMatcher(new TagName(name), regexString);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getHeaders() {
|
||||||
|
return new String[]{"name", "regexString"};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toCSVString() {
|
||||||
|
return name + CSVSerializable.seperator + regexString;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
|
CustomTagMatcherEntity that = (CustomTagMatcherEntity) o;
|
||||||
|
|
||||||
|
if (name != null ? !name.equals(that.name) : that.name != null) return false;
|
||||||
|
return regexString != null ? regexString.equals(that.regexString) : that.regexString == null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = name != null ? name.hashCode() : 0;
|
||||||
|
result = 31 * result + (regexString != null ? regexString.hashCode() : 0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,12 +21,12 @@ public class CSVLinkPersistenceAdapter implements PersistenceAdapter<Link> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(Link value) {
|
public void add(Link link) {
|
||||||
|
linkDAO.remove(new LinkEntity(link));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove(Link value) {
|
public void remove(Link link) {
|
||||||
|
linkDAO.add(new LinkEntity(link));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import persistence.tag.TagEntity;
|
||||||
import user.Username;
|
import user.Username;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -64,7 +65,7 @@ public class LinkEntity implements CSVSerializable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toCSVString() {
|
public String toCSVString() {
|
||||||
return Integer.toString(id) + CSVSerializable.seperator + creator + CSVSerializable.seperator + url + CSVSerializable.seperator + String.join(
|
return id + CSVSerializable.seperator + creator + CSVSerializable.seperator + url + CSVSerializable.seperator + String.join(
|
||||||
CSVSerializable.listSeperator,
|
CSVSerializable.listSeperator,
|
||||||
categoryIds
|
categoryIds
|
||||||
.stream()
|
.stream()
|
||||||
|
@ -84,11 +85,11 @@ public class LinkEntity implements CSVSerializable {
|
||||||
|
|
||||||
LinkEntity that = (LinkEntity) o;
|
LinkEntity that = (LinkEntity) o;
|
||||||
|
|
||||||
if (id != null ? !id.equals(that.id) : that.id != null) return false;
|
if (!Objects.equals(id, that.id)) return false;
|
||||||
if (creator != null ? !creator.equals(that.creator) : that.creator != null) return false;
|
if (!Objects.equals(creator, that.creator)) return false;
|
||||||
if (url != null ? !url.equals(that.url) : that.url != null) return false;
|
if (!Objects.equals(url, that.url)) return false;
|
||||||
if (categoryIds != null ? !categoryIds.equals(that.categoryIds) : that.categoryIds != null) return false;
|
if (!Objects.equals(categoryIds, that.categoryIds)) return false;
|
||||||
return tags != null ? tags.equals(that.tags) : that.tags == null;
|
return Objects.equals(tags, that.tags);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -18,6 +18,10 @@ public class CustomTagMatcher extends TagMatcher {
|
||||||
this.tagName = name;
|
this.tagName = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Pattern getRegex() {
|
||||||
|
return regex;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OptionalTag ifMatches(LinkUrl linkUrl) {
|
public OptionalTag ifMatches(LinkUrl linkUrl) {
|
||||||
Matcher matcher = regex.matcher(linkUrl.toString());
|
Matcher matcher = regex.matcher(linkUrl.toString());
|
||||||
|
|
Reference in a new issue