Skip to content

Commit

Permalink
Remove raw types for AngularObject
Browse files Browse the repository at this point in the history
  • Loading branch information
Reamer committed Nov 12, 2024
1 parent 4a7fdb1 commit e45609b
Show file tree
Hide file tree
Showing 17 changed files with 79 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import scala.xml._
*/
abstract class AbstractAngularElem(val interpreterContext: InterpreterContext,
val modelName: String,
val angularObjects: Map[String, AngularObject[Any]],
val angularObjects: Map[String, AngularObject],
prefix: String,
label: String,
attributes1: MetaData,
Expand Down Expand Up @@ -70,7 +70,7 @@ abstract class AbstractAngularElem(val interpreterContext: InterpreterContext,
* @return
*/
@ZeppelinApi
def model(name: String, value: Any): AbstractAngularElem = {
def model(name: String, value: AnyRef): AbstractAngularElem = {
val registry = interpreterContext.getAngularObjectRegistry

// create AngularFunction in current paragraph
Expand All @@ -79,7 +79,7 @@ abstract class AbstractAngularElem(val interpreterContext: InterpreterContext,
Null)

val angularObject = addAngularObject(name, value)
.asInstanceOf[AngularObject[Any]]
.asInstanceOf[AngularObject]

newElem(
interpreterContext,
Expand Down Expand Up @@ -111,7 +111,7 @@ abstract class AbstractAngularElem(val interpreterContext: InterpreterContext,
* @return
*/
@ZeppelinApi
def model(): Any = {
def model(): AnyRef = {
if (angularObjects.contains(modelName)) {
angularObjects(modelName).get()
} else {
Expand All @@ -134,7 +134,7 @@ abstract class AbstractAngularElem(val interpreterContext: InterpreterContext,
Text(s"${functionName}=${functionName} + 1"),
Null)

val angularObject = addAngularObject(functionName, 0)
val angularObject = addAngularObject(functionName, Int.box(0))

angularObject.addWatcher(new AngularObjectWatcher(interpreterContext) {
override def watch(oldObject: scala.Any, newObject: scala.Any, context: InterpreterContext)
Expand All @@ -151,11 +151,11 @@ abstract class AbstractAngularElem(val interpreterContext: InterpreterContext,
elem)
}

protected def addAngularObject(name: String, value: Any): AngularObject[Any]
protected def addAngularObject(name: String, value: AnyRef): AngularObject

protected def newElem(interpreterContext: InterpreterContext,
name: String,
angularObjects: Map[String, AngularObject[Any]],
angularObjects: Map[String, AngularObject],
elem: scala.xml.Elem): AbstractAngularElem

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@ abstract class AbstractAngularModel(name: String) {
* @param newValue value
*/
@ZeppelinApi
def this(name: String, newValue: Any) = {
def this(name: String, newValue: AnyRef) = {
this(name)
value(newValue)
}

protected def getAngularObject(): AngularObject[Any]
protected def addAngularObject(value: Any): AngularObject[Any]
protected def getAngularObject(): AngularObject
protected def addAngularObject(value: AnyRef): AngularObject

/**
* Get value of the model
*
* @return
*/
@ZeppelinApi
def apply(): Any = {
def apply(): AnyRef = {
value()
}

Expand All @@ -59,7 +59,7 @@ abstract class AbstractAngularModel(name: String) {
* @return
*/
@ZeppelinApi
def value(): Any = {
def value(): AnyRef = {
val angularObject = getAngularObject()
if (angularObject == null) {
None
Expand All @@ -69,7 +69,7 @@ abstract class AbstractAngularModel(name: String) {
}

@ZeppelinApi
def apply(newValue: Any): Unit = {
def apply(newValue: AnyRef): Unit = {
value(newValue)
}

Expand All @@ -80,7 +80,7 @@ abstract class AbstractAngularModel(name: String) {
* @param newValue
*/
@ZeppelinApi
def value(newValue: Any): Unit = {
def value(newValue: AnyRef): Unit = {
var angularObject = getAngularObject()
if (angularObject == null) {
// create new object
Expand All @@ -92,7 +92,7 @@ abstract class AbstractAngularModel(name: String) {
}

@ZeppelinApi
def remove(): Any = {
def remove(): AnyRef = {
val angularObject = getAngularObject()

if (angularObject == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import scala.xml._
*/
class AngularElem(override val interpreterContext: InterpreterContext,
override val modelName: String,
override val angularObjects: Map[String, AngularObject[Any]],
override val angularObjects: Map[String, AngularObject],
prefix: String,
label: String,
attributes1: MetaData,
Expand All @@ -40,15 +40,15 @@ class AngularElem(override val interpreterContext: InterpreterContext,
interpreterContext, modelName, angularObjects, prefix, label, attributes1, scope,
minimizeEmpty, child: _*) {

override protected def addAngularObject(name: String, value: Any): AngularObject[Any] = {
override protected def addAngularObject(name: String, value: AnyRef): AngularObject = {
val registry = interpreterContext.getAngularObjectRegistry
registry.add(name, value, interpreterContext.getNoteId, null).asInstanceOf[AngularObject[Any]]
registry.add(name, value, interpreterContext.getNoteId, null).asInstanceOf[AngularObject]

}

override protected def newElem(interpreterContext: InterpreterContext,
name: String,
angularObjects: Map[String, AngularObject[Any]],
angularObjects: Map[String, AngularObject],
elem: scala.xml.Elem): angular.AbstractAngularElem = {
new AngularElem(
interpreterContext,
Expand All @@ -66,7 +66,7 @@ class AngularElem(override val interpreterContext: InterpreterContext,
object AngularElem {
implicit def Elem2AngularDisplayElem(elem: Elem): AbstractAngularElem = {
new AngularElem(InterpreterContext.get(), null,
Map[String, AngularObject[Any]](),
Map[String, AngularObject](),
elem.prefix, elem.label, elem.attributes, elem.scope, elem.minimizeEmpty, elem.child:_*);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ import org.apache.zeppelin.interpreter.InterpreterContext
class AngularModel(name: String)
extends org.apache.zeppelin.display.angular.AbstractAngularModel(name) {

def this(name: String, newValue: Any) = {
def this(name: String, newValue: AnyRef) = {
this(name)
value(newValue)
}

override protected def getAngularObject(): AngularObject[Any] = {
registry.get(name, context.getNoteId, null).asInstanceOf[AngularObject[Any]]
override protected def getAngularObject(): AngularObject = {
registry.get(name, context.getNoteId, null).asInstanceOf[AngularObject]
}

override protected def addAngularObject(value: Any): AngularObject[Any] = {
registry.add(name, value, context.getNoteId, null).asInstanceOf[AngularObject[Any]]
override protected def addAngularObject(value: AnyRef): AngularObject = {
registry.add(name, value, context.getNoteId, null).asInstanceOf[AngularObject]
}
}

Expand All @@ -46,7 +46,7 @@ object AngularModel {
new AngularModel(name)
}

def apply(name: String, newValue: Any): AbstractAngularModel = {
def apply(name: String, newValue: AnyRef): AbstractAngularModel = {
new AngularModel(name, newValue)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import scala.xml._
*/
class AngularElem(override val interpreterContext: InterpreterContext,
override val modelName: String,
override val angularObjects: Map[String, AngularObject[Any]],
override val angularObjects: Map[String, AngularObject],
prefix: String,
label: String,
attributes1: MetaData,
Expand All @@ -41,16 +41,16 @@ class AngularElem(override val interpreterContext: InterpreterContext,
interpreterContext, modelName, angularObjects, prefix, label, attributes1, scope,
minimizeEmpty, child: _*) {

override protected def addAngularObject(name: String, value: Any): AngularObject[Any] = {
override protected def addAngularObject(name: String, value: Object): AngularObject = {
val registry = interpreterContext.getAngularObjectRegistry
registry.add(name, value, interpreterContext.getNoteId, interpreterContext.getParagraphId)
.asInstanceOf[AngularObject[Any]]
.asInstanceOf[AngularObject]

}

override protected def newElem(interpreterContext: InterpreterContext,
name: String,
angularObjects: Map[String, AngularObject[Any]],
angularObjects: Map[String, AngularObject],
elem: scala.xml.Elem): angular.AbstractAngularElem = {
new AngularElem(
interpreterContext,
Expand All @@ -68,7 +68,7 @@ class AngularElem(override val interpreterContext: InterpreterContext,
object AngularElem {
implicit def Elem2AngularDisplayElem(elem: Elem): AbstractAngularElem = {
new AngularElem(InterpreterContext.get(), null,
Map[String, AngularObject[Any]](),
Map[String, AngularObject](),
elem.prefix, elem.label, elem.attributes, elem.scope, elem.minimizeEmpty, elem.child:_*);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ import org.apache.zeppelin.display.angular.AbstractAngularModel
class AngularModel(name: String)
extends org.apache.zeppelin.display.angular.AbstractAngularModel(name) {

def this(name: String, newValue: Any) = {
def this(name: String, newValue: AnyRef) = {
this(name)
value(newValue)
}

override protected def getAngularObject(): AngularObject[Any] = {
override protected def getAngularObject(): AngularObject = {
registry.get(name,
context.getNoteId, context.getParagraphId).asInstanceOf[AngularObject[Any]]
context.getNoteId, context.getParagraphId).asInstanceOf[AngularObject]
}

override protected def addAngularObject(value: Any): AngularObject[Any] = {
override protected def addAngularObject(value: AnyRef): AngularObject = {
registry.add(name, value,
context.getNoteId, context.getParagraphId).asInstanceOf[AngularObject[Any]]
context.getNoteId, context.getParagraphId).asInstanceOf[AngularObject]
}
}

Expand All @@ -47,7 +47,7 @@ object AngularModel {
new AngularModel(name)
}

def apply(name: String, newValue: Any): AbstractAngularModel = {
def apply(name: String, newValue: AnyRef): AbstractAngularModel = {
new AngularModel(name, newValue)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ trait AbstractAngularElemTest

// simulate click
def fireEvent(eventName: String, elem: org.apache.zeppelin.display.angular.AbstractAngularElem) = {
val angularObject: AngularObject[Any] = elem.angularObjects(eventName);
val angularObject: AngularObject = elem.angularObjects(eventName);
angularObject.set("event");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ with BeforeAndAfter with BeforeAndAfterEach with Eventually {
}

def angularModel(name: String): AbstractAngularModel
def angularModel(name: String, value: Any): AbstractAngularModel
def angularModel(name: String, value: AnyRef): AbstractAngularModel

"AngularModel" should "able to create AngularObject" in {
val registry = InterpreterContext.get().getAngularObjectRegistry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AngularModelTest extends AbstractAngularModelTest {
AngularModel(name)
}

override def angularModel(name: String, value: Any): AbstractAngularModel = {
override def angularModel(name: String, value: AnyRef): AbstractAngularModel = {
AngularModel(name, value)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AngularModelTest extends AbstractAngularModelTest {
AngularModel(name)
}

override def angularModel(name: String, value: Any): AbstractAngularModel = {
override def angularModel(name: String, value: AnyRef): AbstractAngularModel = {
AngularModel(name, value)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
*
* @param <T>
*/
public class AngularObject<T> implements JsonSerializable {
public class AngularObject implements JsonSerializable {
private static final Logger LOGGER = LoggerFactory.getLogger(AngularObject.class);
private static final Gson GSON = new Gson();

private String name;
private T object;
private Object object;

private transient AngularObjectListener listener;
private transient List<AngularObjectWatcher> watchers = new LinkedList<>();
Expand All @@ -66,7 +66,7 @@ public AngularObject() {
* @param paragraphId paragraphId belongs to. can be null
* @param listener event listener
*/
public AngularObject(String name, T o, String noteId, String paragraphId,
public AngularObject(String name, Object o, String noteId, String paragraphId,
AngularObjectListener listener) {
this.name = name;
this.noteId = noteId;
Expand Down Expand Up @@ -127,7 +127,7 @@ public boolean isGlobal() {
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AngularObject<?> that = (AngularObject<?>) o;
AngularObject that = (AngularObject) o;
return Objects.equals(name, that.name) &&
Objects.equals(noteId, that.noteId) &&
Objects.equals(paragraphId, that.paragraphId);
Expand Down Expand Up @@ -160,7 +160,7 @@ public void emit() {
* Set value
* @param o reference to new user provided object
*/
public void set(T o) {
public void set(Object o) {
set(o, true);
}

Expand All @@ -170,32 +170,29 @@ public void set(T o) {
* @param emit false on skip firing event for listener. note that it does not skip invoke
* watcher.watch() in any case
*/
public void set(T o, boolean emit) {
final T before = object;
final T after = o;
public void set(Object o, boolean emit) {
final Object before = object;
final Object after = o;
object = o;
if (emit) {
emit();
}
LOGGER.debug("Update angular object: {} with value: {}", name, o);
final Logger LOGGER = LoggerFactory.getLogger(AngularObject.class);
List<AngularObjectWatcher> ws = new LinkedList<>();
synchronized (watchers) {
ws.addAll(watchers);
}

ExecutorService executor = ExecutorFactory.singleton().createOrGet("angularObjectWatcher", 50);
for (final AngularObjectWatcher w : ws) {
executor.submit(new Runnable() {
@Override
public void run() {
try {
w.watch(before, after);
} catch (Exception e) {
LOGGER.error("Exception on watch", e);
}
Runnable task = () -> {
try {
w.watch(before, after);
} catch (Exception e) {
LOGGER.error("Exception on watch", e);
}
});
};
executor.submit(task);
}
}

Expand Down Expand Up @@ -262,7 +259,7 @@ public String toJson() {
return GSON.toJson(this);
}

public static AngularObject<?> fromJson(String json) {
public static AngularObject fromJson(String json) {
return GSON.fromJson(json, AngularObject.class);
}
}
Loading

0 comments on commit e45609b

Please sign in to comment.