This project has retired. For details please refer to its Attic page.
JythonWrapperBase xref
View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.giraph.jython.wrappers;
19  
20  import org.python.core.PyObject;
21  
22  import com.google.common.base.Objects;
23  
24  // CHECKSTYLE: stop MethodNameCheck
25  
26  /**
27   * Base class for wrapping Jython objects
28   */
29  public class JythonWrapperBase extends PyObject {
30    /** The Jython object being wrapped */
31    private PyObject pyObject;
32  
33    /**
34     * Constructor
35     *
36     * @param pyObject Jython object to wrap
37     */
38    public JythonWrapperBase(PyObject pyObject) {
39      this.pyObject = pyObject;
40    }
41  
42    public PyObject getPyObject() {
43      return pyObject;
44    }
45  
46    public void setPyObject(PyObject pyObject) {
47      this.pyObject = pyObject;
48    }
49  
50    @Override
51    public PyObject __findattr_ex__(String name) {
52      return pyObject.__findattr_ex__(name);
53    }
54  
55    @Override
56    public void __setattr__(String name, PyObject value) {
57      pyObject.__setattr__(name, value);
58    }
59  
60    @Override
61    public boolean equals(Object obj) {
62      if (obj == null) {
63        return false;
64      }
65      if (this == obj) {
66        return true;
67      }
68      if (obj instanceof JythonWrapperBase) {
69        JythonWrapperBase other = (JythonWrapperBase) obj;
70        return Objects.equal(pyObject, other.pyObject);
71      }
72      return false;
73    }
74  
75    @Override
76    public int hashCode() {
77      return Objects.hashCode(pyObject);
78    }
79  }
80  
81  // CHECKSTYLE: resume MethodNameCheck