All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.xiaopy.python.MethodCache Maven / Gradle / Ivy

There is a newer version: 12.1.13
Show newest version
package com.xiaopy.python;

import java.util.*;

class MethodCache {

    private PyObject obj;
    private Map cache = new HashMap<>();

    public MethodCache(PyObject obj) {
        this.obj = obj;
    }

    public PyObject get(String name) {
        PyObject value = cache.get(name);
        if (value == null) {
            value = obj.get(name);
            if (value == null) {
                // Same wording as Python AttributeError.
                throw new UnsupportedOperationException(
                    String.format("'%s' object has no attribute '%s'",
                                  obj.type().get("__name__"), name));
            }
            cache.put(name, value);
        }
        return value;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy