-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfixes to object printers; added RotePrintHandler
- Loading branch information
1 parent
97aaafe
commit 8e6ff8f
Showing
9 changed files
with
195 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
Source/Size/src/ca/uqac/lif/azrael/size/NullPrintHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
Azrael, a serializer for Java objects | ||
Copyright (C) 2016-2019 Sylvain Hallé | ||
Laboratoire d'informatique formelle | ||
Université du Québec à Chicoutimi, Canada | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Lesser General Public License as published | ||
by the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package ca.uqac.lif.azrael.size; | ||
|
||
import ca.uqac.lif.azrael.PrintException; | ||
|
||
public class NullPrintHandler extends ReferencePrintHandler | ||
{ | ||
public NullPrintHandler(SizePrinter printer) | ||
{ | ||
super(printer); | ||
} | ||
|
||
@Override | ||
public boolean canHandle(Object o) | ||
{ | ||
return o == null; | ||
} | ||
|
||
@Override | ||
public Number getSize(Object o) throws PrintException | ||
{ | ||
return 0; | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
Source/Size/src/ca/uqac/lif/azrael/size/RotePrintHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
Azrael, a serializer for Java objects | ||
Copyright (C) 2016-2019 Sylvain Hallé | ||
Laboratoire d'informatique formelle | ||
Université du Québec à Chicoutimi, Canada | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Lesser General Public License as published | ||
by the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package ca.uqac.lif.azrael.size; | ||
|
||
import java.util.IdentityHashMap; | ||
|
||
import ca.uqac.lif.azrael.PrintHandler; | ||
|
||
/** | ||
* Print handler that returns a fixed size value for all objects matching | ||
* a given class name. Adding such a handler to a size printer can be useful | ||
* to cut off the recursive decomposition of "strange" objects. | ||
* | ||
* @author Sylvain Hallé | ||
*/ | ||
public class RotePrintHandler implements PrintHandler<Number> | ||
{ | ||
/** | ||
* A map of already seen objects | ||
*/ | ||
protected IdentityHashMap<Object,Integer> m_seenObjects; | ||
|
||
/** | ||
* The name of the class to match | ||
*/ | ||
protected String m_className; | ||
|
||
/** | ||
* The size to return for this object | ||
*/ | ||
protected int m_sizeToReturn; | ||
|
||
public RotePrintHandler(String class_name, int size) | ||
{ | ||
super(); | ||
m_className = class_name; | ||
m_sizeToReturn = size; | ||
m_seenObjects = new IdentityHashMap<Object,Integer>(); | ||
} | ||
|
||
@Override | ||
public boolean canHandle(Object o) | ||
{ | ||
return o != null && o.getClass().getSimpleName().compareTo(m_className) == 0; | ||
} | ||
|
||
@Override | ||
public Number handle(Object o) | ||
{ | ||
// We count objects only once | ||
if (m_seenObjects.containsKey(o)) | ||
{ | ||
return 0; | ||
} | ||
m_seenObjects.put(o, 1); | ||
return m_sizeToReturn; | ||
} | ||
|
||
@Override | ||
public void reset() | ||
{ | ||
m_seenObjects.clear(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters