Skip to content

Commit

Permalink
Reorganization of the storage values
Browse files Browse the repository at this point in the history
  • Loading branch information
spoto committed Jan 13, 2024
1 parent 805620e commit 47ef0ce
Show file tree
Hide file tree
Showing 88 changed files with 887 additions and 582 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 Fausto Spoto
Copyright 2024 Fausto Spoto
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 Fausto Spoto
Copyright 2024 Fausto Spoto
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Copyright 2024 Fausto Spoto
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package io.hotmoka.beans.api.values;

import io.hotmoka.annotations.Immutable;

/**
* A {@code char} value stored in blockchain.
*/
@Immutable
public interface CharValue extends StorageValue {

/**
* Yields the character inside this value.
*
* @return the character
*/
char getValue();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Copyright 2024 Fausto Spoto
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package io.hotmoka.beans.api.values;

import io.hotmoka.annotations.Immutable;

/**
* A {@code double} value stored in blockchain.
*/
@Immutable
public interface DoubleValue extends StorageValue {

/**
* Yields the double inside this object.
*
* @return the double
*/
double getValue();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Copyright 2024 Fausto Spoto
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package io.hotmoka.beans.api.values;

import io.hotmoka.annotations.Immutable;

/**
* A {@code float} value stored in blockchain.
*/
@Immutable
public interface FloatValue extends StorageValue {

/**
* Yields the float inside this value.
*
* @return the float
*/
float getValue();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Copyright 2021 Fausto Spoto
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package io.hotmoka.beans.api.values;

import io.hotmoka.annotations.Immutable;

/**
* An {@code int} value stored in the store of a node.
*/
@Immutable
public interface IntValue extends StorageValue {

/**
* Yields the {@code int} inside this value.
*
* @return the {@code int}
*/
int getValue();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Copyright 2024 Fausto Spoto
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package io.hotmoka.beans.api.values;

import io.hotmoka.annotations.Immutable;

/**
* A {@code long} value stored in blockchain.
*/
@Immutable
public interface LongValue extends StorageValue {

/**
* Yields the long inside this value.
*
* @return the long
*/
long getValue();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Copyright 2021 Fausto Spoto
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package io.hotmoka.beans.api.values;

import io.hotmoka.annotations.Immutable;

/**
* The {@code null} value stored in blockchain.
*/
@Immutable
public interface NullValue extends StorageValue {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Copyright 2024 Fausto Spoto
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package io.hotmoka.beans.api.values;

import io.hotmoka.annotations.Immutable;

/**
* A {@code short} value stored in blockchain.
*/
@Immutable
public interface ShortValue extends StorageValue {

/**
* Yields the short inside this value.
*
* @return the short
*/
short getValue();
}
83 changes: 81 additions & 2 deletions io-hotmoka-beans/src/main/java/io/hotmoka/beans/StorageValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,26 @@
import io.hotmoka.beans.api.types.StorageType;
import io.hotmoka.beans.api.values.BooleanValue;
import io.hotmoka.beans.api.values.ByteValue;
import io.hotmoka.beans.api.values.CharValue;
import io.hotmoka.beans.api.values.DoubleValue;
import io.hotmoka.beans.api.values.FloatValue;
import io.hotmoka.beans.api.values.IntValue;
import io.hotmoka.beans.api.values.LongValue;
import io.hotmoka.beans.api.values.NullValue;
import io.hotmoka.beans.api.values.ShortValue;
import io.hotmoka.beans.api.values.StorageValue;
import io.hotmoka.beans.internal.gson.StorageTypeDecoder;
import io.hotmoka.beans.internal.gson.StorageTypeEncoder;
import io.hotmoka.beans.internal.gson.StorageTypeJson;
import io.hotmoka.beans.internal.values.BooleanValueImpl;
import io.hotmoka.beans.internal.values.ByteValueImpl;
import io.hotmoka.beans.internal.values.CharValueImpl;
import io.hotmoka.beans.internal.values.DoubleValueImpl;
import io.hotmoka.beans.internal.values.FloatValueImpl;
import io.hotmoka.beans.internal.values.IntValueImpl;
import io.hotmoka.beans.internal.values.LongValueImpl;
import io.hotmoka.beans.internal.values.NullValueImpl;
import io.hotmoka.beans.internal.values.ShortValueImpl;
import io.hotmoka.beans.internal.values.StorageValueImpl;
import io.hotmoka.marshalling.api.UnmarshallingContext;

Expand All @@ -40,12 +54,17 @@ private StorageValues() {}
/**
* The true Boolean value.
*/
public final static BooleanValue TRUE = new BooleanValueImpl(true);
public final static BooleanValue TRUE = BooleanValueImpl.TRUE;

/**
* The false Boolean value.
*/
public final static BooleanValue FALSE = new BooleanValueImpl(false);
public final static BooleanValue FALSE = BooleanValueImpl.FALSE;

/**
* The {@code null} value.
*/
public final static NullValue NULL = NullValueImpl.NULL;

/**
* Yields the storage value corresponding to the given boolean value.
Expand All @@ -67,6 +86,66 @@ public static ByteValue byteOf(byte value) {
return new ByteValueImpl(value);
}

/**
* Yields the storage value corresponding to the given character value.
*
* @param value the character value
* @return the corresponding storage value
*/
public static CharValue charOf(char value) {
return new CharValueImpl(value);
}

/**
* Yields the storage value corresponding to the given short value.
*
* @param value the short value
* @return the corresponding storage value
*/
public static ShortValue shortOf(short value) {
return new ShortValueImpl(value);
}

/**
* Yields the storage value corresponding to the given {@code int} value.
*
* @param value the {@code int} value
* @return the corresponding storage value
*/
public static IntValue intOf(int value) {
return new IntValueImpl(value);
}

/**
* Yields the storage value corresponding to the given long value.
*
* @param value the long value
* @return the corresponding storage value
*/
public static LongValue longOf(long value) {
return new LongValueImpl(value);
}

/**
* Yields the storage value corresponding to the given double value.
*
* @param value the double value
* @return the corresponding storage value
*/
public static DoubleValue doubleOf(double value) {
return new DoubleValueImpl(value);
}

/**
* Yields the storage value corresponding to the given float value.
*
* @param value the float value
* @return the corresponding storage value
*/
public static FloatValue floatOf(float value) {
return new FloatValueImpl(value);
}

/**
* Yields a storage value from the given string and of the given type.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,23 @@
import io.hotmoka.marshalling.api.MarshallingContext;

/**
* A {@code boolean} value stored in blockchain.
* Implementation of a {@code boolean} value stored in blockchain.
*/
@Immutable
public final class BooleanValueImpl extends StorageValueImpl implements BooleanValue {
static final byte SELECTOR_TRUE = 0;
static final byte SELECTOR_FALSE = 1;

/**
* The true Boolean value.
*/
public final static BooleanValue TRUE = new BooleanValueImpl(true);

/**
* The false Boolean value.
*/
public final static BooleanValue FALSE = new BooleanValueImpl(false);

/**
* The value.
*/
Expand All @@ -41,7 +51,7 @@ public final class BooleanValueImpl extends StorageValueImpl implements BooleanV
*
* @param value the value
*/
public BooleanValueImpl(boolean value) {
private BooleanValueImpl(boolean value) {
this.value = value;
}

Expand Down
Loading

0 comments on commit 47ef0ce

Please sign in to comment.