Skip to content
Snippets Groups Projects
Commit 32d88206 authored by Adam Welc's avatar Adam Welc
Browse files

Consolidate attribute-related functionality in RAbstractContainer interface.

parent e9109050
Branches
No related tags found
No related merge requests found
Showing
with 165 additions and 17 deletions
......@@ -97,6 +97,11 @@ public final class RDataFrame implements RShareable, RAbstractContainer {
return null;
}
@Override
public void setDimensions(int[] newDimensions) {
Utils.nyi("data frame's dimensions need to be set using builtins");
}
@Override
public Class<?> getElementClass() {
return RDataFrame.class;
......@@ -121,17 +126,32 @@ public final class RDataFrame implements RShareable, RAbstractContainer {
return vector.getNames(attrProfiles);
}
@Override
public void setNames(RStringVector newNames) {
vector.setNames(newNames);
}
@Override
public RList getDimNames() {
Utils.nyi("data frame's dimnames needs to be obtained using builtins");
return null;
}
@Override
public void setDimNames(RList newDimNames) {
vector.setDimNames(newDimNames);
}
@Override
public Object getRowNames(RAttributeProfiles attrProfiles) {
return vector.getRowNames(attrProfiles);
}
@Override
public void setRowNames(RAbstractVector rowNames) {
vector.setRowNames(rowNames);
}
@Override
public RStringVector getClassHierarchy() {
return vector.getClassHierarchy();
......
......@@ -69,6 +69,11 @@ public class RExpression implements RShareable, RAbstractContainer {
return data.getDimensions();
}
@Override
public void setDimensions(int[] newDimensions) {
data.setDimensions(newDimensions);
}
public Class<?> getElementClass() {
return RExpression.class;
}
......@@ -81,19 +86,36 @@ public class RExpression implements RShareable, RAbstractContainer {
return data.getDataAtAsObject(index);
}
@Override
public RStringVector getNames(RAttributeProfiles attrProfiles) {
return data.getNames(attrProfiles);
}
@Override
public void setNames(RStringVector newNames) {
data.setNames(newNames);
}
@Override
public RList getDimNames() {
return data.getDimNames();
}
@Override
public void setDimNames(RList newDimNames) {
data.setDimNames(newDimNames);
}
@Override
public Object getRowNames(RAttributeProfiles attrProfiles) {
return data.getRowNames(attrProfiles);
}
@Override
public void setRowNames(RAbstractVector rowNames) {
data.setRowNames(rowNames);
}
public RStringVector getClassHierarchy() {
return data.getClassHierarchy();
}
......
......@@ -98,6 +98,11 @@ public final class RFactor implements RShareable, RAbstractContainer {
return vector.getDimensions();
}
@Override
public void setDimensions(int[] newDimensions) {
vector.setDimensions(newDimensions);
}
@Override
public Class<?> getElementClass() {
return RFactor.class;
......@@ -122,16 +127,31 @@ public final class RFactor implements RShareable, RAbstractContainer {
return vector.getNames(attrProfiles);
}
@Override
public void setNames(RStringVector newNames) {
vector.setNames(newNames);
}
@Override
public RList getDimNames() {
return vector.getDimNames();
}
@Override
public void setDimNames(RList newDimNames) {
vector.setDimNames(newDimNames);
}
@Override
public Object getRowNames(RAttributeProfiles attrProfiles) {
return vector.getRowNames(attrProfiles);
}
@Override
public void setRowNames(RAbstractVector rowNames) {
vector.setRowNames(rowNames);
}
@Override
public RStringVector getClassHierarchy() {
return vector.getClassHierarchy();
......
......@@ -72,8 +72,7 @@ public class RLanguage extends RLanguageRep implements RAbstractContainer, RAttr
}
public boolean isComplete() {
assert false;
return false;
throw RInternalError.shouldNotReachHere();
}
public int getLength() {
......@@ -93,18 +92,21 @@ public class RLanguage extends RLanguageRep implements RAbstractContainer, RAttr
return null;
}
@Override
public void setDimensions(int[] newDimensions) {
throw RInternalError.unimplemented();
}
public Class<?> getElementClass() {
return RLanguage.class;
}
public RVector materializeNonSharedVector() {
assert false;
return null;
throw RInternalError.shouldNotReachHere();
}
public RShareable materializeToShareable() {
assert false;
return null;
throw RInternalError.shouldNotReachHere();
}
public Object getDataAtAsObject(int index) {
......@@ -116,16 +118,31 @@ public class RLanguage extends RLanguageRep implements RAbstractContainer, RAttr
return (RStringVector) getAttr(attrProfiles, RRuntime.NAMES_ATTR_KEY);
}
@Override
public void setNames(RStringVector newNames) {
setAttr(RRuntime.NAMES_ATTR_KEY, newNames);
}
@Override
public RList getDimNames() {
return (RList) getAttr(localAttrProfiles, RRuntime.DIMNAMES_ATTR_KEY);
}
@Override
public void setDimNames(RList newDimNames) {
setAttr(RRuntime.DIMNAMES_ATTR_KEY, newDimNames);
}
@Override
public Object getRowNames(RAttributeProfiles attrProfiles) {
return getAttr(attrProfiles, RRuntime.ROWNAMES_ATTR_KEY);
}
@Override
public void setRowNames(RAbstractVector rowNames) {
setAttr(RRuntime.ROWNAMES_ATTR_KEY, rowNames);
}
public RStringVector getClassHierarchy() {
return RDataFactory.createStringVector(RRuntime.CLASS_LANGUAGE);
}
......
......@@ -129,6 +129,11 @@ public class RPairList extends RAttributeStorage implements RAttributable, RAbst
return new int[]{1};
}
@Override
public void setDimensions(int[] newDimensions) {
throw RInternalError.shouldNotReachHere();
}
public Class<?> getElementClass() {
return null;
}
......@@ -153,6 +158,7 @@ public class RPairList extends RAttributeStorage implements RAttributable, RAbst
return pl.car;
}
@Override
public RStringVector getNames(RAttributeProfiles attrProfiles) {
int l = getLength();
String[] data = new String[l];
......@@ -173,12 +179,29 @@ public class RPairList extends RAttributeStorage implements RAttributable, RAbst
return RDataFactory.createStringVector(data, complete);
}
@Override
public void setNames(RStringVector newNames) {
throw RInternalError.shouldNotReachHere();
}
@Override
public RList getDimNames() {
return null;
throw RInternalError.shouldNotReachHere();
}
@Override
public void setDimNames(RList newDimNames) {
throw RInternalError.shouldNotReachHere();
}
@Override
public Object getRowNames(RAttributeProfiles attrProfiles) {
return null;
throw RInternalError.shouldNotReachHere();
}
@Override
public void setRowNames(RAbstractVector rowNames) {
throw RInternalError.shouldNotReachHere();
}
public RStringVector getClassHierarchy() {
......
......@@ -50,6 +50,12 @@ public abstract class RSequence extends RBounded implements RAbstractVector {
return null;
}
@Override
public void setDimensions(int[] newDimensions) {
// should only be used on materialized sequence
throw RInternalError.shouldNotReachHere();
}
public final RVector createVector() {
return internalCreateVector();
}
......@@ -76,21 +82,37 @@ public abstract class RSequence extends RBounded implements RAbstractVector {
return null;
}
@Override
public void setNames(RStringVector newNames) {
// should only be used on materialized sequence
throw RInternalError.shouldNotReachHere();
}
@Override
public final RList getDimNames() {
return null;
}
@Override
public void setDimNames(RList newDimNames) {
// should only be used on materialized sequence
throw RInternalError.shouldNotReachHere();
}
@Override
public final Object getRowNames(RAttributeProfiles attrProfiles) {
return RNull.instance;
}
@Override
public void setRowNames(RAbstractVector rowNames) {
// should only be used on materialized sequence
throw RInternalError.shouldNotReachHere();
}
@Override
public final RAttributes initAttributes() {
// TODO implement
assert false;
return null;
throw RInternalError.shouldNotReachHere();
}
@Override
......
......@@ -43,14 +43,21 @@ public abstract class RToVectorClosure implements RAbstractVector {
return vector.isComplete();
}
@Override
public boolean hasDimensions() {
return vector.hasDimensions();
}
@Override
public int[] getDimensions() {
return vector.getDimensions();
}
@Override
public void setDimensions(int[] newDimensions) {
vector.setDimensions(newDimensions);
}
@Override
public final void verifyDimensions(int[] newDimensions, SourceSection sourceSection) {
vector.verifyDimensions(newDimensions, sourceSection);
......@@ -61,16 +68,31 @@ public abstract class RToVectorClosure implements RAbstractVector {
return vector.getNames(attrProfiles);
}
@Override
public void setNames(RStringVector newNames) {
vector.setNames(newNames);
}
@Override
public RList getDimNames() {
return vector.getDimNames();
}
@Override
public void setDimNames(RList newDimNames) {
vector.setDimNames(newDimNames);
}
@Override
public Object getRowNames(RAttributeProfiles attrProfiles) {
return vector.getRowNames(attrProfiles);
}
@Override
public void setRowNames(RAbstractVector rowNames) {
vector.setRowNames(rowNames);
}
@Override
public RAttributes initAttributes() {
return vector.initAttributes();
......
......@@ -34,6 +34,8 @@ public interface RAbstractContainer extends RAttributable, RClassHierarchy, RTyp
int[] getDimensions();
void setDimensions(int[] newDimensions);
Class<?> getElementClass();
RVector materializeNonSharedVector();
......@@ -44,10 +46,16 @@ public interface RAbstractContainer extends RAttributable, RClassHierarchy, RTyp
RStringVector getNames(RAttributeProfiles attrProfiles);
void setNames(RStringVector newNames);
RList getDimNames();
void setDimNames(RList newDimNames);
Object getRowNames(RAttributeProfiles attrProfiles);
void setRowNames(RAbstractVector rowNames);
/**
* Returns {@code true} if and only if the value has a {@code class} attribute added explicitly.
* When {@code true}, it is possible to call {@link RClassHierarchy#getClassHierarchy()}.
......
......@@ -28,10 +28,6 @@ import com.oracle.truffle.r.runtime.data.*;
public interface RAbstractVector extends RAbstractContainer {
boolean hasDimensions();
int[] getDimensions();
/**
* Creates a copy of the vector. This copies all of the contained data as well. If the data in
* the vector is to be updated upon copying, the corresponding {@code copyResetData()} method
......@@ -58,8 +54,6 @@ public interface RAbstractVector extends RAbstractContainer {
RVector materialize();
RList getDimNames();
boolean isMatrix();
boolean isArray();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment