-
-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Linked values, line breaks issue and naming fixes #63
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package com.github.miachm.sods; | ||
|
||
import java.time.LocalDate; | ||
import java.util.Objects; | ||
import java.util.*; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why use an asterisk here? |
||
|
||
class Cell extends TableField { | ||
private Object value; | ||
|
@@ -10,8 +10,10 @@ class Cell extends TableField { | |
private GroupCell group; | ||
private OfficeAnnotation annotation; | ||
|
||
Cell() | ||
{ | ||
private List<LinkedValue> linkedValues; | ||
|
||
Cell() { | ||
linkedValues = new ArrayList<>(); | ||
} | ||
|
||
GroupCell getGroup() { | ||
|
@@ -56,6 +58,7 @@ void clear() | |
formula = null; | ||
style = Style.default_style; | ||
annotation = null; | ||
linkedValues = new ArrayList<>(); | ||
} | ||
|
||
String getFormula() { | ||
|
@@ -102,6 +105,22 @@ public void setAnnotation(OfficeAnnotation annotation) { | |
this.annotation = annotation; | ||
} | ||
|
||
List<LinkedValue> getLinkedValues() { | ||
return linkedValues; | ||
} | ||
|
||
boolean hasLinkedValues() { | ||
return !linkedValues.isEmpty(); | ||
} | ||
|
||
void setLinkedValues(List<LinkedValue> linkedValues) { | ||
this.linkedValues = linkedValues; | ||
} | ||
|
||
void addLinkedValue(LinkedValue linkedValue) { | ||
this.linkedValues.add(linkedValue); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
|
@@ -124,6 +143,7 @@ public boolean equals(Object o) { | |
if (!Objects.equals(formula, cell.formula)) return false; | ||
if (!Objects.equals(annotation, cell.annotation)) return false; | ||
if (!Objects.equals(num_repeated, cell.num_repeated)) return false; | ||
if (!Objects.equals(linkedValues, cell.linkedValues)) return false; | ||
return style.equals(cell.getStyle()); | ||
} | ||
|
||
|
@@ -139,6 +159,7 @@ public int hashCode() | |
result = 31 * result + style.hashCode(); | ||
result = 31 * result + (group != null ? group.hashCode() : 0); | ||
result = 31 * result + annotation.hashCode(); | ||
result = 31 * result + linkedValues.hashCode(); | ||
return result; | ||
} | ||
|
||
|
@@ -147,6 +168,7 @@ public String toString() { | |
if (getGroup() == null || getGroup().getCell() == this) | ||
return "Cell{" + | ||
"value=" + value + | ||
", linkedValues='" + Arrays.toString(linkedValues.toArray()) + '\'' + | ||
", formula='" + formula + '\'' + | ||
", style=" + style + | ||
", num_repeated=" + num_repeated + | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package com.github.miachm.sods; | ||
|
||
import java.io.File; | ||
import java.net.URI; | ||
import java.net.URL; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Represents a value linked to a sheet, file, URI or URL. | ||
*/ | ||
public class LinkedValue { | ||
private final String href; | ||
private final String value; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why a value? I thought this feature was for linking a cell to another. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi Miguel, To address your comments:
Feel free to use this as you'd like, I know I am already using this in a project where SODS is consumed. Sorry I do not have more time to help now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't get me wrong, I am grateful for any contribution. My comments try to balance between being appreciative and giving meaningful feedback according to the library standards. But sometimes I can excesively direct. I understand not everyone have the time to fully contribute to the development (dam, I don't even have the time myself). Yep, some classes in SODS are becoming in god classes, specially ODSReader/ODSWritter like you mentioned. Nevertheless I try to keep the external-user API as consistent as posible, that's why the build pattern does not fit with the current implementation, because it presents to the user a completely different style. Eventually I'll need to deprecate the API and re-design it, but, you know, not enough time! Thanks again, let's see if I can finish the feature and release another version. |
||
|
||
LinkedValue(String href, String value) { | ||
this.href = href; | ||
this.value = value; | ||
} | ||
|
||
public static LinkedValue.Builder builder() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the builder pattern. Althought I understand the value of the pattern, is not consistent with the rest of API. SODS usually uses a more direct-straightforward style to the user. |
||
return new LinkedValue.Builder(); | ||
} | ||
|
||
String getHref() { | ||
return href; | ||
} | ||
|
||
String getValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
LinkedValue that = (LinkedValue) o; | ||
return Objects.equals(href, that.href) && Objects.equals(value, that.value); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(href, value); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "LinkedValue{" + | ||
"href='" + href + '\'' + | ||
", value=" + value + | ||
'}'; | ||
} | ||
|
||
public static class Builder { | ||
private String href; | ||
private String value; | ||
|
||
public LinkedValue build() { | ||
return new LinkedValue(href, value); | ||
} | ||
|
||
public LinkedValue.Builder value(String value) { | ||
this.value = value; | ||
return this; | ||
} | ||
|
||
public LinkedValue.Builder href(Sheet sheet) { | ||
this.href = '#' + sheet.getName() + ".A1"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why A1? |
||
// this.href = '#' + sheet.getName(); // TODO: remove this - not compatible with Excel | ||
return this; | ||
} | ||
|
||
public LinkedValue.Builder href(File file) { | ||
this.href = file.toURI().toString(); | ||
return this; | ||
} | ||
|
||
public LinkedValue.Builder href(URL url) { | ||
this.href = url.toString(); | ||
return this; | ||
} | ||
|
||
public LinkedValue.Builder href(URI uri) { | ||
this.href = uri.toString(); | ||
return this; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use the next format in SODS for versioning:
X.Y.Z
X refers to API versions. Changes within the same X are compatible. The API of the version 1.1.0 is completely compatible with 1.5.0 (although not the other way around). The day we redesign the API, we need to update the X.
Y refers to additional features. There are aditional features in the API, although the API is still backwards-compatible.
Z refers to a bugfixing release. There are no aditional features or changes in the API
This is a new feature. Therefore, we need to update the Y version.