Skip to content

Commit

Permalink
Renamed old RawMemory methods
Browse files Browse the repository at this point in the history
setAllMemoryObjects -> setAllMemories
destroyMemoryObject -> destroyMemory
Uses and tests also changed

Issue CST-Group#62 solved.
  • Loading branch information
EltonCN committed Nov 28, 2024
1 parent 0cd9ba0 commit efdc3a7
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/main/java/br/unicamp/cst/behavior/bn/BgBComLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ public synchronized void writeBehaviorState(MemoryObject bs){
if(alreadyThere && sameInfo)
{// Remove MO from raw memory and discard it
if(rawMemory!=null)
rawMemory.destroyMemoryObject(bs);
rawMemory.destroyMemory(bs);
}else if(alreadyThere && !sameInfo){
//Update info from old MO and discard de unused new one
oldMO.setI(bs.getI()); //TODO I might need to change this in the future in case we implement a memory decay based on time
if(rawMemory!=null)
rawMemory.destroyMemoryObject(bs);
rawMemory.destroyMemory(bs);
}else
{//Simply add it to the list
this.behaviorsToBg.add(bs);
Expand Down Expand Up @@ -137,12 +137,12 @@ public synchronized void writeBGInstruction(MemoryObject bgI){
if(alreadyThere && sameInfo)
{// Remove MO from raw memory and discard it
if(rawMemory!=null)
rawMemory.destroyMemoryObject(bgI);
rawMemory.destroyMemory(bgI);
}else if(alreadyThere && !sameInfo)
{//Update info from old MO and discard de unused new one
oldMO.setI(bgI.getI()); //TODO I might need to change this in the future in case we implement a memory decay based on time
if(rawMemory!=null)
rawMemory.destroyMemoryObject(bgI);
rawMemory.destroyMemory(bgI);
}else
{//Simply add it to the list
this.bgToBehaviors.add(bgI);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/br/unicamp/cst/core/entities/MemoryBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public synchronized void put(MemoryObject content) {

if (memoryObjects.size() == maxCapacity) {
if (rawMemory != null)
rawMemory.destroyMemoryObject(memoryObjects.get(0));// Gets rid
rawMemory.destroyMemory(memoryObjects.get(0));// Gets rid
// of older
// content
// and
Expand Down Expand Up @@ -205,7 +205,7 @@ public synchronized MemoryObject getOldest() {
*/
public synchronized boolean remove(MemoryObject mo) {
if (rawMemory != null)
rawMemory.destroyMemoryObject(mo);// removes this mo form RawMemory
rawMemory.destroyMemory(mo);// removes this mo form RawMemory

return memoryObjects.remove(mo);// removes this mo from this buffer;

Expand All @@ -217,7 +217,7 @@ public synchronized boolean remove(MemoryObject mo) {
public synchronized void clear() {
if (rawMemory != null)
for (int i = 0; i < memoryObjects.size(); i++) {
rawMemory.destroyMemoryObject(memoryObjects.get(i));
rawMemory.destroyMemory(memoryObjects.get(i));
}
memoryObjects.clear();
}
Expand Down
30 changes: 29 additions & 1 deletion src/main/java/br/unicamp/cst/core/entities/RawMemory.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,23 @@ public synchronized List<Memory> getAllOfType(String type) {
/**
* Sets the list of all memories inside raw memory.
*
* @deprecated
*
* @param allMemories
* the allMemoryObjects to set.
*/
@Deprecated
public synchronized void setAllMemoryObjects(List<Memory> allMemories) {
setAllMemories(allMemories);
}

/**
* Sets the list of all memories inside raw memory.
*
* @param allMemories
* the allMemoryObjects to set.
*/
public synchronized void setAllMemories(List<Memory> allMemories) {
synchronized (this.allMemories) {
this.allMemories = allMemories;
for (Memory m : allMemories) {
Expand All @@ -95,6 +108,8 @@ public synchronized void setAllMemoryObjects(List<Memory> allMemories) {
}
}



/**
* Print Raw Memory contents.
*/
Expand Down Expand Up @@ -268,12 +283,25 @@ public synchronized MemoryObject createMemoryObject(String name) {
/**
* Destroys a given memory from raw memory
*
* @deprecated
*
* @param mo
* the memory to destroy.
*/
@Deprecated
public synchronized void destroyMemoryObject(Memory mo) {
destroyMemory(mo);
}

/**
* Destroys a given memory from raw memory
*
* @param memory
* the memory to destroy.
*/
public synchronized void destroyMemory(Memory memory) {
synchronized (allMemories) {
allMemories.remove(mo);
allMemories.remove(memory);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/br/unicamp/cst/memory/WorkingStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public synchronized void removeFromWorkingStorageWithDelete(Memory bpMo)
{
workingStorageContentList.remove(bpMo);
if(rawMemory!=null)
rawMemory.destroyMemoryObject(bpMo);
rawMemory.destroyMemory(bpMo);

}

Expand All @@ -354,7 +354,7 @@ public void clearWithDelete()
if(rawMemory!=null && workingStorageContentList!=null)
for(Memory mo: workingStorageContentList)
{
rawMemory.destroyMemoryObject(mo);
rawMemory.destroyMemory(mo);
}
this.workingStorageContentList.clear();

Expand Down
8 changes: 4 additions & 4 deletions src/test/java/br/unicamp/cst/core/entities/RawMemoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void getAllOfTypeTest(){
List<Memory> testList = Arrays.asList(new MemoryObject(), new MemoryObject(), new MemoryObject(), new MemoryObject());
testList.get(0).setType("TYPE");
testList.get(1).setType("TYPE");
rawMemory.setAllMemoryObjects(testList);
rawMemory.setAllMemories(testList);

assertEquals(2, rawMemory.getAllOfType("TYPE").size());
assertEquals(testList.subList(0,2), rawMemory.getAllOfType("TYPE"));
Expand All @@ -52,12 +52,12 @@ public void printContentTest(){
}

@Test
public void createAndDestroyMemoryObjectTest(){
public void createAndDestroyMemoryTest(){
RawMemory rawMemory = new RawMemory();
rawMemory.createMemoryObject("TYPE");

assertEquals(1, rawMemory.size());
rawMemory.destroyMemoryObject(rawMemory.getAllMemoryObjects().get(0));
rawMemory.destroyMemory(rawMemory.getAllMemoryObjects().get(0));

assertEquals(0, rawMemory.size());
}
Expand All @@ -66,7 +66,7 @@ public void createAndDestroyMemoryObjectTest(){
public void shutdownTest(){
RawMemory rawMemory = new RawMemory();
List<Memory> testList = Arrays.asList(new MemoryObject(), new MemoryObject(), new MemoryObject(), new MemoryObject());
rawMemory.setAllMemoryObjects(testList);
rawMemory.setAllMemories(testList);

assertEquals(4, rawMemory.size());

Expand Down

0 comments on commit efdc3a7

Please sign in to comment.