tdf#164793: fix misplaced rounding
[LibreOffice.git] / ridljar / com / sun / star / uno / Any.java
blob2f4976436d4582486ce9c9c77b0eeef059e6e19e
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 package com.sun.star.uno;
23 /**
24 * The UNO IDL type any is mapped to java type <code>java.lang.Object</code>.
25 * <p>
26 * In special cases it is necessary to have an explicit any to additionally transport
27 * an exact type. For instance if you want to pass an object reference via
28 * an interprocess connection using an any, you should use this class to add
29 * an explicit interface type, so the remote counterpart doesn't need to invoke
30 * a queryInterface).
31 * </p>
33 public class Any {
34 /**
35 * The type of the any.
37 * @see #getType
39 protected Type _type;
41 /**
42 * The data of the any.
44 * @see #getObject
46 protected Object _object;
48 public static final Any VOID = new Any(new Type("void", TypeClass.VOID),
49 null);
50 // do not use Type.VOID here to avoid circular dependencies between
51 // static members of Any and Type
53 /**
54 * Constructs a new any.
56 * @param zInterface the type of the any.
57 * @param object the data of the any.
58 * @deprecated as of UDK 2.0
60 @Deprecated
61 public Any(Class<?> zInterface, Object object) {
62 this(new Type(zInterface), object);
65 /**
66 * Constructs a new any with a given type and value
68 * @param type the UNO type of the any.
69 * @param object the value of the any.
71 public Any(Type type, Object object) {
72 if (type.equals(Type.ANY)) {
73 throw new IllegalArgumentException("Any cannot contain Any");
75 _type = type;
76 _object = object;
79 /**
80 * Complete a UNO <code>ANY</code> (make sure it is wrapped up as an
81 * <code>Any</code> instance).
83 * @param any a Java value representing a UNO <code>ANY</code> value.
84 * @return a complete Java value (that is, an <code>Any</code> instance)
85 * representing the same UNO <code>ANY</code> value as the given argument.
86 * @since UDK 3.2.3
88 public static final Any complete(Object any) {
89 return any instanceof Any
90 ? (Any) any
91 : new Any(
92 new Type(any == null ? XInterface.class : any.getClass()), any);
95 /**
96 * Gets the type of the value within the any.
98 * @return the type of the value within the any.
100 public Type getType() {
101 return _type;
105 * Gets the value within the any.
107 * @return gets the value within the any.
109 public Object getObject() {
110 return _object;
114 * Indicates whether some other object is equal to this one.
116 * @param obj the reference object with which to compare.
117 * @return <code>true</code> if this object is the same as the obj argument;
118 * <code>false</code> otherwise.
119 * @see java.lang.Object#equals
121 @Override
122 public boolean equals(Object obj) {
123 return obj instanceof Any && _type.equals(((Any) obj)._type)
124 && (_object == null
125 ? ((Any) obj)._object == null
126 : _object.equals(((Any) obj)._object));
130 * Returns a hash code value for the object.
132 * @return a hash code value for this object.
133 * @see java.lang.Object#hashCode
135 @Override
136 public int hashCode() {
137 return _type.hashCode() * 13
138 + (_object == null ? 0 : _object.hashCode());
142 * Returns a string representation of the object.
144 * @return a string representation of the object.
145 * @see java.lang.Object#toString
147 @Override
148 public String toString() {
149 return "Any[" + _type + ", " + _object + "]";