Implement hashCode and equals for encoded values

This commit is contained in:
Ben Gruver 2012-11-10 17:33:28 -08:00
parent ff9eb9fa61
commit b76e75c8bc
38 changed files with 1019 additions and 194 deletions

View File

@ -0,0 +1,54 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.base.value;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.iface.value.AnnotationEncodedValue;
public abstract class BaseAnnotationEncodedValue implements AnnotationEncodedValue {
@Override
public int hashCode() {
int hashCode = getType().hashCode();
return hashCode * 31 + getElements().hashCode();
}
@Override
public boolean equals(Object o) {
if (o != null && o instanceof AnnotationEncodedValue) {
return getType().equals(((AnnotationEncodedValue) o).getType()) &&
getElements().equals(((AnnotationEncodedValue) o).getElements());
}
return false;
}
public int getValueType() { return ValueType.ANNOTATION; }
}

View File

@ -0,0 +1,52 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.base.value;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.iface.value.ArrayEncodedValue;
public abstract class BaseArrayEncodedValue implements ArrayEncodedValue {
@Override
public int hashCode() {
return getValue().hashCode();
}
@Override
public boolean equals(Object o) {
if (o != null && o instanceof ArrayEncodedValue) {
return getValue().equals(((ArrayEncodedValue) o).getValue());
}
return false;
}
public int getValueType() { return ValueType.ARRAY; }
}

View File

@ -0,0 +1,52 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.base.value;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.iface.value.BooleanEncodedValue;
public abstract class BaseBooleanEncodedValue implements BooleanEncodedValue {
@Override
public int hashCode() {
return getValue()?1:0;
}
@Override
public boolean equals(Object o) {
if (o != null && o instanceof BooleanEncodedValue) {
return getValue() == ((BooleanEncodedValue) o).getValue();
}
return false;
}
public int getValueType() { return ValueType.BOOLEAN; }
}

View File

@ -0,0 +1,52 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.base.value;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.iface.value.ByteEncodedValue;
public abstract class BaseByteEncodedValue implements ByteEncodedValue {
@Override
public int hashCode() {
return getValue();
}
@Override
public boolean equals(Object o) {
if (o != null && o instanceof ByteEncodedValue) {
return getValue() == ((ByteEncodedValue) o).getValue();
}
return false;
}
public int getValueType() { return ValueType.BYTE; }
}

View File

@ -0,0 +1,52 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.base.value;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.iface.value.CharEncodedValue;
public abstract class BaseCharEncodedValue implements CharEncodedValue {
@Override
public int hashCode() {
return getValue();
}
@Override
public boolean equals(Object o) {
if (o != null && o instanceof CharEncodedValue) {
return getValue() == ((CharEncodedValue) o).getValue();
}
return false;
}
public int getValueType() { return ValueType.CHAR; }
}

View File

@ -0,0 +1,54 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.base.value;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.iface.value.DoubleEncodedValue;
public abstract class BaseDoubleEncodedValue implements DoubleEncodedValue {
@Override
public int hashCode() {
long value = Double.doubleToRawLongBits(getValue());
int hashCode = (int)value;
return hashCode*31 + (int)(value>>>32);
}
@Override
public boolean equals(Object o) {
if (o != null && o instanceof DoubleEncodedValue) {
return getValue() == ((DoubleEncodedValue) o).getValue();
}
return false;
}
public int getValueType() { return ValueType.DOUBLE; }
}

View File

@ -0,0 +1,52 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.base.value;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.iface.value.EnumEncodedValue;
public abstract class BaseEnumEncodedValue implements EnumEncodedValue {
@Override
public int hashCode() {
return getValue().hashCode();
}
@Override
public boolean equals(Object o) {
if (o != null && o instanceof EnumEncodedValue) {
return getValue().equals(((EnumEncodedValue) o).getValue());
}
return false;
}
public int getValueType() { return ValueType.ENUM; }
}

View File

@ -0,0 +1,52 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.base.value;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.iface.value.FieldEncodedValue;
public abstract class BaseFieldEncodedValue implements FieldEncodedValue {
@Override
public int hashCode() {
return getValue().hashCode();
}
@Override
public boolean equals(Object o) {
if (o != null && o instanceof FieldEncodedValue) {
return getValue().equals(((FieldEncodedValue) o).getValue());
}
return false;
}
public int getValueType() { return ValueType.FIELD; }
}

View File

@ -0,0 +1,52 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.base.value;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.iface.value.FloatEncodedValue;
public abstract class BaseFloatEncodedValue implements FloatEncodedValue {
@Override
public int hashCode() {
return Float.floatToRawIntBits(getValue());
}
@Override
public boolean equals(Object o) {
if (o != null && o instanceof FloatEncodedValue) {
return getValue() == ((FloatEncodedValue) o).getValue();
}
return false;
}
public int getValueType() { return ValueType.FLOAT; }
}

View File

@ -0,0 +1,52 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.base.value;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.iface.value.IntEncodedValue;
public abstract class BaseIntEncodedValue implements IntEncodedValue {
@Override
public int hashCode() {
return getValue();
}
@Override
public boolean equals(Object o) {
if (o != null && o instanceof IntEncodedValue) {
return getValue() == ((IntEncodedValue) o).getValue();
}
return false;
}
public int getValueType() { return ValueType.INT; }
}

View File

@ -0,0 +1,54 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.base.value;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.iface.value.LongEncodedValue;
public abstract class BaseLongEncodedValue implements LongEncodedValue {
@Override
public int hashCode() {
long value = getValue();
int hashCode = (int)value;
return hashCode*31 + (int)(value>>>32);
}
@Override
public boolean equals(Object o) {
if (o != null && o instanceof LongEncodedValue) {
return getValue() == ((LongEncodedValue) o).getValue();
}
return false;
}
public int getValueType() { return ValueType.LONG; }
}

View File

@ -0,0 +1,52 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.base.value;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.iface.value.MethodEncodedValue;
public abstract class BaseMethodEncodedValue implements MethodEncodedValue {
@Override
public int hashCode() {
return getValue().hashCode();
}
@Override
public boolean equals(Object o) {
if (o != null && o instanceof MethodEncodedValue) {
return getValue().equals(((MethodEncodedValue) o).getValue());
}
return false;
}
public int getValueType() { return ValueType.METHOD; }
}

View File

@ -0,0 +1,49 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.base.value;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.iface.value.NullEncodedValue;
public abstract class BaseNullEncodedValue implements NullEncodedValue {
@Override
public int hashCode() {
return 0;
}
@Override
public boolean equals(Object o) {
return o != null && o instanceof NullEncodedValue;
}
public int getValueType() { return ValueType.NULL; }
}

View File

@ -0,0 +1,52 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.base.value;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.iface.value.ShortEncodedValue;
public abstract class BaseShortEncodedValue implements ShortEncodedValue {
@Override
public int hashCode() {
return getValue();
}
@Override
public boolean equals(Object o) {
if (o != null && o instanceof ShortEncodedValue) {
return getValue() == ((ShortEncodedValue) o).getValue();
}
return false;
}
public int getValueType() { return ValueType.SHORT; }
}

View File

@ -0,0 +1,52 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.base.value;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.iface.value.StringEncodedValue;
public abstract class BaseStringEncodedValue implements StringEncodedValue {
@Override
public int hashCode() {
return getValue().hashCode();
}
@Override
public boolean equals(Object o) {
if (o != null && o instanceof StringEncodedValue) {
return getValue().equals(((StringEncodedValue) o).getValue());
}
return false;
}
public int getValueType() { return ValueType.STRING; }
}

View File

@ -0,0 +1,52 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.base.value;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.iface.value.TypeEncodedValue;
public abstract class BaseTypeEncodedValue implements TypeEncodedValue {
@Override
public int hashCode() {
return getValue().hashCode();
}
@Override
public boolean equals(Object o) {
if (o != null && o instanceof TypeEncodedValue) {
return getValue().equals(((TypeEncodedValue) o).getValue());
}
return false;
}
public int getValueType() { return ValueType.TYPE; }
}

View File

@ -32,6 +32,7 @@
package org.jf.dexlib2.dexbacked.value;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.base.value.BaseAnnotationEncodedValue;
import org.jf.dexlib2.dexbacked.DexBackedAnnotationElement;
import org.jf.dexlib2.dexbacked.DexBuffer;
import org.jf.dexlib2.dexbacked.DexReader;
@ -42,7 +43,7 @@ import org.jf.dexlib2.iface.value.AnnotationEncodedValue;
import javax.annotation.Nonnull;
import java.util.List;
public class DexBackedAnnotationEncodedValue implements AnnotationEncodedValue {
public class DexBackedAnnotationEncodedValue extends BaseAnnotationEncodedValue implements AnnotationEncodedValue {
@Nonnull public final DexBuffer dexBuf;
@Nonnull public final String type;
private final int elementsOffset;
@ -67,7 +68,6 @@ public class DexBackedAnnotationEncodedValue implements AnnotationEncodedValue {
}
}
@Override public int getValueType() { return ValueType.ANNOTATION; }
@Nonnull @Override public String getType() { return type; }
@Nonnull

View File

@ -32,6 +32,7 @@
package org.jf.dexlib2.dexbacked.value;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.base.value.BaseArrayEncodedValue;
import org.jf.dexlib2.dexbacked.DexBuffer;
import org.jf.dexlib2.dexbacked.DexReader;
import org.jf.dexlib2.dexbacked.util.VariableSizeList;
@ -41,7 +42,7 @@ import org.jf.dexlib2.iface.value.EncodedValue;
import javax.annotation.Nonnull;
import java.util.List;
public class DexBackedArrayEncodedValue implements ArrayEncodedValue {
public class DexBackedArrayEncodedValue extends BaseArrayEncodedValue implements ArrayEncodedValue {
@Nonnull public final DexBuffer dexBuf;
private final int encodedArrayOffset;
@ -58,8 +59,6 @@ public class DexBackedArrayEncodedValue implements ArrayEncodedValue {
}
}
@Override public int getValueType() { return ValueType.ARRAY; }
@Nonnull
@Override
public List<? extends EncodedValue> getValue() {

View File

@ -35,6 +35,7 @@ import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.iface.AnnotationElement;
import org.jf.dexlib2.iface.value.EncodedValue;
import org.jf.dexlib2.immutable.value.ImmutableEncodedValue;
import org.jf.dexlib2.immutable.value.ImmutableEncodedValueFactory;
import org.jf.util.ImmutableListConverter;
import javax.annotation.Nonnull;
@ -48,7 +49,7 @@ public class ImmutableAnnotationElement implements AnnotationElement {
public ImmutableAnnotationElement(@Nonnull String name,
@Nonnull EncodedValue value) {
this.name = name;
this.value = ImmutableEncodedValue.of(value);
this.value = ImmutableEncodedValueFactory.of(value);
}
public ImmutableAnnotationElement(@Nonnull String name,

View File

@ -37,6 +37,7 @@ import org.jf.dexlib2.iface.Annotation;
import org.jf.dexlib2.iface.Field;
import org.jf.dexlib2.iface.value.EncodedValue;
import org.jf.dexlib2.immutable.value.ImmutableEncodedValue;
import org.jf.dexlib2.immutable.value.ImmutableEncodedValueFactory;
import org.jf.util.ImmutableListConverter;
import org.jf.util.ImmutableListUtils;
@ -62,7 +63,7 @@ public class ImmutableField extends BaseFieldReference implements Field {
this.name = name;
this.type = type;
this.accessFlags = accessFlags;
this.initialValue = ImmutableEncodedValue.of(initialValue);
this.initialValue = ImmutableEncodedValueFactory.of(initialValue);
this.annotations = ImmutableAnnotation.immutableListOf(annotations);
}

View File

@ -32,7 +32,7 @@
package org.jf.dexlib2.immutable.value;
import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.base.value.BaseAnnotationEncodedValue;
import org.jf.dexlib2.iface.AnnotationElement;
import org.jf.dexlib2.iface.value.AnnotationEncodedValue;
import org.jf.dexlib2.immutable.ImmutableAnnotationElement;
@ -42,20 +42,19 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
public class ImmutableAnnotationEncodedValue extends ImmutableEncodedValue implements AnnotationEncodedValue {
public class ImmutableAnnotationEncodedValue extends BaseAnnotationEncodedValue
implements ImmutableEncodedValue, AnnotationEncodedValue {
@Nonnull public final String type;
@Nonnull public final ImmutableList<? extends ImmutableAnnotationElement> elements;
public ImmutableAnnotationEncodedValue(@Nonnull String type,
@Nullable List<? extends AnnotationElement> elements) {
super(ValueType.ANNOTATION);
this.type = type;
this.elements = ImmutableAnnotationElement.immutableListOf(elements);
}
public ImmutableAnnotationEncodedValue(@Nonnull String type,
@Nullable ImmutableList<? extends ImmutableAnnotationElement> elements) {
super(ValueType.ANNOTATION);
this.type = type;
this.elements = ImmutableListUtils.nullToEmptyList(elements);
}

View File

@ -32,24 +32,22 @@
package org.jf.dexlib2.immutable.value;
import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.base.value.BaseArrayEncodedValue;
import org.jf.dexlib2.iface.value.ArrayEncodedValue;
import org.jf.dexlib2.iface.value.EncodedValue;
import javax.annotation.Nonnull;
import java.util.List;
public class ImmutableArrayEncodedValue extends ImmutableEncodedValue implements ArrayEncodedValue {
@Nonnull
public final ImmutableList<? extends ImmutableEncodedValue> value;
public class ImmutableArrayEncodedValue extends BaseArrayEncodedValue
implements ImmutableEncodedValue, ArrayEncodedValue {
@Nonnull public final ImmutableList<? extends ImmutableEncodedValue> value;
public ImmutableArrayEncodedValue(@Nonnull List<? extends EncodedValue> value) {
super(ValueType.ARRAY);
this.value = ImmutableEncodedValue.immutableListOf(value);
this.value = ImmutableEncodedValueFactory.immutableListOf(value);
}
public ImmutableArrayEncodedValue(@Nonnull ImmutableList<ImmutableEncodedValue> value) {
super(ValueType.ARRAY);
this.value = value;
}
@ -60,8 +58,5 @@ public class ImmutableArrayEncodedValue extends ImmutableEncodedValue implements
return new ImmutableArrayEncodedValue(arrayEncodedValue.getValue());
}
@Nonnull
public ImmutableList<? extends ImmutableEncodedValue> getValue() {
return value;
}
@Nonnull public ImmutableList<? extends ImmutableEncodedValue> getValue() { return value; }
}

View File

@ -31,14 +31,14 @@
package org.jf.dexlib2.immutable.value;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.base.value.BaseBooleanEncodedValue;
import org.jf.dexlib2.iface.value.BooleanEncodedValue;
public class ImmutableBooleanEncodedValue extends ImmutableEncodedValue implements BooleanEncodedValue {
public class ImmutableBooleanEncodedValue extends BaseBooleanEncodedValue
implements ImmutableEncodedValue, BooleanEncodedValue {
public final boolean value;
public ImmutableBooleanEncodedValue(boolean value) {
super(ValueType.BOOLEAN);
this.value = value;
}
@ -49,7 +49,5 @@ public class ImmutableBooleanEncodedValue extends ImmutableEncodedValue implemen
return new ImmutableBooleanEncodedValue(booleanEncodedValue.getValue());
}
public boolean getValue() {
return value;
}
@Override public boolean getValue() { return value; }
}

View File

@ -31,14 +31,14 @@
package org.jf.dexlib2.immutable.value;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.base.value.BaseByteEncodedValue;
import org.jf.dexlib2.iface.value.ByteEncodedValue;
public class ImmutableByteEncodedValue extends ImmutableEncodedValue implements ByteEncodedValue {
public class ImmutableByteEncodedValue extends BaseByteEncodedValue
implements ImmutableEncodedValue, ByteEncodedValue {
public final byte value;
public ImmutableByteEncodedValue(byte value) {
super(ValueType.BYTE);
this.value = value;
}
@ -49,7 +49,5 @@ public class ImmutableByteEncodedValue extends ImmutableEncodedValue implements
return new ImmutableByteEncodedValue(byteEncodedValue.getValue());
}
public byte getValue() {
return value;
}
@Override public byte getValue() { return value; }
}

View File

@ -31,14 +31,14 @@
package org.jf.dexlib2.immutable.value;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.base.value.BaseCharEncodedValue;
import org.jf.dexlib2.iface.value.CharEncodedValue;
public class ImmutableCharEncodedValue extends ImmutableEncodedValue implements CharEncodedValue {
public class ImmutableCharEncodedValue extends BaseCharEncodedValue
implements ImmutableEncodedValue, CharEncodedValue {
public final char value;
public ImmutableCharEncodedValue(char value) {
super(ValueType.CHAR);
this.value = value;
}
@ -49,7 +49,5 @@ public class ImmutableCharEncodedValue extends ImmutableEncodedValue implements
return new ImmutableCharEncodedValue(charEncodedValue.getValue());
}
public char getValue() {
return value;
}
@Override public char getValue() { return value; }
}

View File

@ -31,14 +31,14 @@
package org.jf.dexlib2.immutable.value;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.base.value.BaseDoubleEncodedValue;
import org.jf.dexlib2.iface.value.DoubleEncodedValue;
public class ImmutableDoubleEncodedValue extends ImmutableEncodedValue implements DoubleEncodedValue {
public class ImmutableDoubleEncodedValue extends BaseDoubleEncodedValue
implements ImmutableEncodedValue, DoubleEncodedValue {
public final double value;
public ImmutableDoubleEncodedValue(double value) {
super(ValueType.DOUBLE);
this.value = value;
}
@ -49,7 +49,5 @@ public class ImmutableDoubleEncodedValue extends ImmutableEncodedValue implement
return new ImmutableDoubleEncodedValue(doubleEncodedValue.getValue());
}
public double getValue() {
return value;
}
@Override public double getValue() { return value; }
}

View File

@ -31,84 +31,7 @@
package org.jf.dexlib2.immutable.value;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.iface.value.*;
import org.jf.util.ImmutableListConverter;
import org.jf.dexlib2.iface.value.EncodedValue;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
public class ImmutableEncodedValue implements EncodedValue {
public final int type;
protected ImmutableEncodedValue(int type) {
this.type = type;
}
@Nullable
public static ImmutableEncodedValue of(@Nullable EncodedValue encodedValue) {
if (encodedValue == null) {
return null;
}
switch (encodedValue.getValueType()) {
case ValueType.BYTE:
return ImmutableByteEncodedValue.of((ByteEncodedValue)encodedValue);
case ValueType.SHORT:
return ImmutableShortEncodedValue.of((ShortEncodedValue)encodedValue);
case ValueType.CHAR:
return ImmutableCharEncodedValue.of((CharEncodedValue)encodedValue);
case ValueType.INT:
return ImmutableIntEncodedValue.of((IntEncodedValue)encodedValue);
case ValueType.LONG:
return ImmutableLongEncodedValue.of((LongEncodedValue)encodedValue);
case ValueType.FLOAT:
return ImmutableFloatEncodedValue.of((FloatEncodedValue)encodedValue);
case ValueType.DOUBLE:
return ImmutableDoubleEncodedValue.of((DoubleEncodedValue)encodedValue);
case ValueType.STRING:
return ImmutableStringEncodedValue.of((StringEncodedValue)encodedValue);
case ValueType.TYPE:
return ImmutableTypeEncodedValue.of((TypeEncodedValue)encodedValue);
case ValueType.FIELD:
return ImmutableFieldEncodedValue.of((FieldEncodedValue)encodedValue);
case ValueType.METHOD:
return ImmutableMethodEncodedValue.of((MethodEncodedValue)encodedValue);
case ValueType.ENUM:
return ImmutableEnumEncodedValue.of((EnumEncodedValue)encodedValue);
case ValueType.ARRAY:
return ImmutableArrayEncodedValue.of((ArrayEncodedValue)encodedValue);
case ValueType.ANNOTATION:
return ImmutableAnnotationEncodedValue.of((AnnotationEncodedValue)encodedValue);
case ValueType.NULL:
return ImmutableNullEncodedValue.INSTANCE;
case ValueType.BOOLEAN:
return ImmutableBooleanEncodedValue.of((BooleanEncodedValue)encodedValue);
default:
Preconditions.checkArgument(false);
return null;
}
}
public int getValueType() { return type; }
@Nonnull
public static ImmutableList<ImmutableEncodedValue> immutableListOf(@Nullable List<? extends EncodedValue> list) {
return CONVERTER.convert(list);
}
private static final ImmutableListConverter<ImmutableEncodedValue, EncodedValue> CONVERTER =
new ImmutableListConverter<ImmutableEncodedValue, EncodedValue>() {
@Override
protected boolean isImmutable(EncodedValue item) {
return item instanceof ImmutableEncodedValue;
}
@Override
protected ImmutableEncodedValue makeImmutable(EncodedValue item) {
return ImmutableEncodedValue.of(item);
}
};
public interface ImmutableEncodedValue extends EncodedValue {
}

View File

@ -0,0 +1,106 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.immutable.value;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.iface.value.*;
import org.jf.util.ImmutableListConverter;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
public class ImmutableEncodedValueFactory {
@Nullable
public static ImmutableEncodedValue of(@Nullable EncodedValue encodedValue) {
if (encodedValue == null) {
return null;
}
switch (encodedValue.getValueType()) {
case ValueType.BYTE:
return ImmutableByteEncodedValue.of((ByteEncodedValue)encodedValue);
case ValueType.SHORT:
return ImmutableShortEncodedValue.of((ShortEncodedValue)encodedValue);
case ValueType.CHAR:
return ImmutableCharEncodedValue.of((CharEncodedValue)encodedValue);
case ValueType.INT:
return ImmutableIntEncodedValue.of((IntEncodedValue)encodedValue);
case ValueType.LONG:
return ImmutableLongEncodedValue.of((LongEncodedValue)encodedValue);
case ValueType.FLOAT:
return ImmutableFloatEncodedValue.of((FloatEncodedValue)encodedValue);
case ValueType.DOUBLE:
return ImmutableDoubleEncodedValue.of((DoubleEncodedValue)encodedValue);
case ValueType.STRING:
return ImmutableStringEncodedValue.of((StringEncodedValue)encodedValue);
case ValueType.TYPE:
return ImmutableTypeEncodedValue.of((TypeEncodedValue)encodedValue);
case ValueType.FIELD:
return ImmutableFieldEncodedValue.of((FieldEncodedValue)encodedValue);
case ValueType.METHOD:
return ImmutableMethodEncodedValue.of((MethodEncodedValue)encodedValue);
case ValueType.ENUM:
return ImmutableEnumEncodedValue.of((EnumEncodedValue)encodedValue);
case ValueType.ARRAY:
return ImmutableArrayEncodedValue.of((ArrayEncodedValue)encodedValue);
case ValueType.ANNOTATION:
return ImmutableAnnotationEncodedValue.of((AnnotationEncodedValue)encodedValue);
case ValueType.NULL:
return ImmutableNullEncodedValue.INSTANCE;
case ValueType.BOOLEAN:
return ImmutableBooleanEncodedValue.of((BooleanEncodedValue)encodedValue);
default:
Preconditions.checkArgument(false);
return null;
}
}
@Nonnull
public static ImmutableList<ImmutableEncodedValue> immutableListOf(@Nullable List<? extends EncodedValue> list) {
return CONVERTER.convert(list);
}
private static final ImmutableListConverter<ImmutableEncodedValue, EncodedValue> CONVERTER =
new ImmutableListConverter<ImmutableEncodedValue, EncodedValue>() {
@Override
protected boolean isImmutable(EncodedValue item) {
return item instanceof ImmutableEncodedValue;
}
@Override
protected ImmutableEncodedValue makeImmutable(EncodedValue item) {
return of(item);
}
};
}

View File

@ -31,16 +31,16 @@
package org.jf.dexlib2.immutable.value;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.base.value.BaseEnumEncodedValue;
import org.jf.dexlib2.iface.value.EnumEncodedValue;
import javax.annotation.Nonnull;
public class ImmutableEnumEncodedValue extends ImmutableEncodedValue implements EnumEncodedValue {
public class ImmutableEnumEncodedValue extends BaseEnumEncodedValue
implements ImmutableEncodedValue, EnumEncodedValue {
@Nonnull public final String value;
public ImmutableEnumEncodedValue(@Nonnull String value) {
super(ValueType.ENUM);
this.value = value;
}
@ -51,7 +51,5 @@ public class ImmutableEnumEncodedValue extends ImmutableEncodedValue implements
return new ImmutableEnumEncodedValue(enumEncodedValue.getValue());
}
@Nonnull public String getValue() {
return value;
}
@Nonnull @Override public String getValue() { return value; }
}

View File

@ -31,17 +31,17 @@
package org.jf.dexlib2.immutable.value;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.base.value.BaseFieldEncodedValue;
import org.jf.dexlib2.iface.reference.FieldReference;
import org.jf.dexlib2.iface.value.FieldEncodedValue;
import javax.annotation.Nonnull;
public class ImmutableFieldEncodedValue extends ImmutableEncodedValue implements FieldEncodedValue {
public class ImmutableFieldEncodedValue extends BaseFieldEncodedValue
implements ImmutableEncodedValue, FieldEncodedValue {
@Nonnull public final FieldReference value;
public ImmutableFieldEncodedValue(@Nonnull FieldReference value) {
super(ValueType.FIELD);
this.value = value;
}
@ -52,8 +52,5 @@ public class ImmutableFieldEncodedValue extends ImmutableEncodedValue implements
return new ImmutableFieldEncodedValue(fieldEncodedValue.getValue());
}
@Nonnull
public FieldReference getValue() {
return value;
}
@Nonnull @Override public FieldReference getValue() { return value; }
}

View File

@ -31,14 +31,14 @@
package org.jf.dexlib2.immutable.value;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.base.value.BaseFloatEncodedValue;
import org.jf.dexlib2.iface.value.FloatEncodedValue;
public class ImmutableFloatEncodedValue extends ImmutableEncodedValue implements FloatEncodedValue {
public class ImmutableFloatEncodedValue extends BaseFloatEncodedValue
implements ImmutableEncodedValue, FloatEncodedValue {
public final float value;
public ImmutableFloatEncodedValue(float value) {
super(ValueType.FLOAT);
this.value = value;
}
@ -49,7 +49,5 @@ public class ImmutableFloatEncodedValue extends ImmutableEncodedValue implements
return new ImmutableFloatEncodedValue(floatEncodedValue.getValue());
}
public float getValue() {
return value;
}
@Override public float getValue() { return value; }
}

View File

@ -31,14 +31,14 @@
package org.jf.dexlib2.immutable.value;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.base.value.BaseIntEncodedValue;
import org.jf.dexlib2.iface.value.IntEncodedValue;
public class ImmutableIntEncodedValue extends ImmutableEncodedValue implements IntEncodedValue {
public class ImmutableIntEncodedValue extends BaseIntEncodedValue
implements ImmutableEncodedValue, IntEncodedValue {
public final int value;
public ImmutableIntEncodedValue(int value) {
super(ValueType.INT);
this.value = value;
}
@ -49,7 +49,5 @@ public class ImmutableIntEncodedValue extends ImmutableEncodedValue implements I
return new ImmutableIntEncodedValue(intEncodedValue.getValue());
}
public int getValue() {
return value;
}
@Override public int getValue() { return value; }
}

View File

@ -31,14 +31,14 @@
package org.jf.dexlib2.immutable.value;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.base.value.BaseLongEncodedValue;
import org.jf.dexlib2.iface.value.LongEncodedValue;
public class ImmutableLongEncodedValue extends ImmutableEncodedValue implements LongEncodedValue {
public class ImmutableLongEncodedValue extends BaseLongEncodedValue
implements ImmutableEncodedValue, LongEncodedValue {
public final long value;
public ImmutableLongEncodedValue(long value) {
super(ValueType.LONG);
this.value = value;
}
@ -49,7 +49,5 @@ public class ImmutableLongEncodedValue extends ImmutableEncodedValue implements
return new ImmutableLongEncodedValue(longEncodedValue.getValue());
}
public long getValue() {
return value;
}
@Override public long getValue() { return value; }
}

View File

@ -31,18 +31,17 @@
package org.jf.dexlib2.immutable.value;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.base.value.BaseMethodEncodedValue;
import org.jf.dexlib2.iface.reference.MethodReference;
import org.jf.dexlib2.iface.value.MethodEncodedValue;
import javax.annotation.Nonnull;
public class ImmutableMethodEncodedValue extends ImmutableEncodedValue implements MethodEncodedValue {
@Nonnull
public final MethodReference value;
public class ImmutableMethodEncodedValue extends BaseMethodEncodedValue
implements ImmutableEncodedValue, MethodEncodedValue {
@Nonnull public final MethodReference value;
public ImmutableMethodEncodedValue(@Nonnull MethodReference value) {
super(ValueType.METHOD);
this.value = value;
}
@ -53,8 +52,5 @@ public class ImmutableMethodEncodedValue extends ImmutableEncodedValue implement
return new ImmutableMethodEncodedValue(methodEncodedValue.getValue());
}
@Nonnull
public MethodReference getValue() {
return value;
}
@Nonnull @Override public MethodReference getValue() { return value; }
}

View File

@ -31,13 +31,12 @@
package org.jf.dexlib2.immutable.value;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.base.value.BaseNullEncodedValue;
import org.jf.dexlib2.iface.value.NullEncodedValue;
public class ImmutableNullEncodedValue extends ImmutableEncodedValue implements NullEncodedValue {
public class ImmutableNullEncodedValue extends BaseNullEncodedValue
implements ImmutableEncodedValue, NullEncodedValue {
public static final ImmutableNullEncodedValue INSTANCE = new ImmutableNullEncodedValue();
public ImmutableNullEncodedValue() {
super(ValueType.NULL);
}
private ImmutableNullEncodedValue() {}
}

View File

@ -31,14 +31,14 @@
package org.jf.dexlib2.immutable.value;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.base.value.BaseShortEncodedValue;
import org.jf.dexlib2.iface.value.ShortEncodedValue;
public class ImmutableShortEncodedValue extends ImmutableEncodedValue implements ShortEncodedValue {
public class ImmutableShortEncodedValue extends BaseShortEncodedValue
implements ImmutableEncodedValue, ShortEncodedValue {
public final short value;
public ImmutableShortEncodedValue(short value) {
super(ValueType.SHORT);
this.value = value;
}
@ -49,7 +49,5 @@ public class ImmutableShortEncodedValue extends ImmutableEncodedValue implements
return new ImmutableShortEncodedValue(shortEncodedValue.getValue());
}
public short getValue() {
return value;
}
@Override public short getValue() { return value; }
}

View File

@ -31,17 +31,16 @@
package org.jf.dexlib2.immutable.value;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.base.value.BaseStringEncodedValue;
import org.jf.dexlib2.iface.value.StringEncodedValue;
import javax.annotation.Nonnull;
public class ImmutableStringEncodedValue extends ImmutableEncodedValue implements StringEncodedValue {
@Nonnull
public final String value;
public class ImmutableStringEncodedValue extends BaseStringEncodedValue
implements ImmutableEncodedValue, StringEncodedValue {
@Nonnull public final String value;
public ImmutableStringEncodedValue(@Nonnull String value) {
super(ValueType.STRING);
this.value = value;
}
@ -52,8 +51,5 @@ public class ImmutableStringEncodedValue extends ImmutableEncodedValue implement
return new ImmutableStringEncodedValue(stringEncodedValue.getValue());
}
@Nonnull
public String getValue() {
return value;
}
@Nonnull @Override public String getValue() { return value; }
}

View File

@ -31,17 +31,16 @@
package org.jf.dexlib2.immutable.value;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.base.value.BaseTypeEncodedValue;
import org.jf.dexlib2.iface.value.TypeEncodedValue;
import javax.annotation.Nonnull;
public class ImmutableTypeEncodedValue extends ImmutableEncodedValue implements TypeEncodedValue {
@Nonnull
public final String value;
public class ImmutableTypeEncodedValue extends BaseTypeEncodedValue
implements ImmutableEncodedValue, TypeEncodedValue {
@Nonnull public final String value;
public ImmutableTypeEncodedValue(@Nonnull String value) {
super(ValueType.TYPE);
this.value = value;
}
@ -52,8 +51,5 @@ public class ImmutableTypeEncodedValue extends ImmutableEncodedValue implements
return new ImmutableTypeEncodedValue(typeEncodedValue.getValue());
}
@Nonnull
public String getValue() {
return value;
}
@Nonnull @Override public String getValue() { return value; }
}