-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
71 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...its/table/src/main/java/org/enso/table/data/column/operation/map/text/StringStringOp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.enso.table.data.column.operation.map.text; | ||
|
||
import org.enso.table.data.column.builder.object.StringBuilder; | ||
import org.enso.table.data.column.operation.map.MapOperation; | ||
import org.enso.table.data.column.operation.map.MapOperationProblemBuilder; | ||
import org.enso.table.data.column.storage.SpecializedStorage; | ||
import org.enso.table.data.column.storage.Storage; | ||
import org.enso.table.data.column.storage.StringStorage; | ||
import org.enso.table.error.UnexpectedTypeException; | ||
|
||
public abstract class StringStringOp extends MapOperation<String, SpecializedStorage<String>> { | ||
public StringStringOp(String name) { | ||
super(name); | ||
} | ||
|
||
protected abstract String doString(String a, String b); | ||
|
||
@Override | ||
public Storage<?> runMap(SpecializedStorage<String> storage, Object arg, MapOperationProblemBuilder problemBuilder) { | ||
int size = storage.size(); | ||
if (arg == null) { | ||
StringBuilder builder = new StringBuilder(size); | ||
builder.appendNulls(size); | ||
return builder.seal(); | ||
} else if (arg instanceof String argString) { | ||
String[] newVals = new String[size]; | ||
for (int i = 0; i < size; i++) { | ||
if (storage.isNa(i)) { | ||
newVals[i] = null; | ||
} else { | ||
newVals[i] = doString(storage.getItem(i), argString); | ||
} | ||
} | ||
return new StringStorage(newVals, size); | ||
} else { | ||
throw new UnexpectedTypeException("a Text"); | ||
} | ||
} | ||
|
||
@Override | ||
public Storage<?> runZip(SpecializedStorage<String> storage, Storage<?> arg, | ||
MapOperationProblemBuilder problemBuilder) { | ||
if (arg instanceof StringStorage v) { | ||
int size = storage.size(); | ||
String[] newVals = new String[size]; | ||
for (int i = 0; i < size; i++) { | ||
if (storage.isNa(i) || v.isNa(i)) { | ||
newVals[i] = null; | ||
} else { | ||
newVals[i] = doString(storage.getItem(i), v.getItem(i)); | ||
} | ||
} | ||
return new StringStorage(newVals, size); | ||
} else { | ||
throw new UnexpectedTypeException("a Text column"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters