<commit_before><html>
	<head>
		<title>COPE - Attribute Reloaded Trail</title>
		<meta name="keywords" content="Persistence, Java">
		<meta name="description" content="COPE - a persistence framework for Java">
		<link rel="stylesheet" href="cope.css">
	</head>
	<body>
		<a href="http://www.exedio.com/">
			<img src="exedio.png" class="exedio">
		</a>
		<h1><a href="index.html">COPE</a></h1>
		<div>Cope with Object Persistence</div>
		
		<h2>Attribute Reloaded Trail</h2>
		<a href="http://sourceforge.net/">
			<img src="http://sourceforge.net/sflogo.php?group_id=152867&amp;type=1"
				class="sf" alt="SourceForge.net Logo" />
		</a>
		<div>
			While the <a href="attributes.html">Attribute Trail</a>
			covered the most fundamental attributes only,
			this trails shows you some more special ways to store data with COPE.
			Although most of the features below are not attributes in a formal sense
			(means subclasses of class <a href="api/com/exedio/cope/Attribute.html">Attribute</a>)
			you don't have to care about this until you want to develop such features yourself.
		</div>
		<h3><a name="contents">Contents</a></h3>
		<ul>
			<li><a href="#hashes">Hashes</a></li>
			<li><a href="#attributelists">Attribute Lists</a></li>
			<li><a href="#attributemaps">Attribute Maps</a></li>
			<li><a href="#dayattributes">Day Attributes</a></li>
			<li><a href="#further">Further Reading</a></li>
		</ul>
		<h3><a name="hashes">Hashes</a></h3>
		<div>
			If you want to store a string encoded by a hash algorithm,
			such as the password of the customer,
			then put the following into class <tt>Customer</tt>:
		</div>
<pre>
static final <a href="api/com/exedio/cope/pattern/MD5Hash.html">MD5Hash</a> password = new <a href="api/com/exedio/cope/pattern/MD5Hash.html#MD5Hash()">MD5Hash</a>();
</pre>
		<div>
			The instrumentor will generate a method for checking the password
			instead of a getter method:
		</div>
<pre>
boolean checkPassword(String password)
{
   return Customer.password.check(this, password);
}
</pre>
		<div>
			Using the super classes of <tt>MD5Hash</tt>
			you can choose any hash algorithm provided by the java.security package
			or even implement a custom algorithm.
		</div>
		<h3><a name="attributelists">Attribute Lists</a></h3>
		<div>
			Sometimes you may want to store multiple values for an attribute,
			such as multiple email addresses for the customer.
			This can be achieved with <i>attribute lists</i>:
		</div>
<pre>
static final <a href="api/com/exedio/cope/pattern/AttributeList.html">AttributeList</a>&lt;String&gt; emails =
    <a href="api/com/exedio/cope/pattern/AttributeList.html">AttributeList</a>.<a href="api/com/exedio/cope/pattern/AttributeList.html#newList(com.exedio.cope.FunctionAttribute)">newList</a>(new StringAttribute());
</pre>
		<div>
			Internally this is implemented by an extra table in the database,
			so you can store lists of any size.
			If you are sure, that the list cannot a exceed a certain size,
			you may decide to use a <i>limited attribute list</i>:
		</div>
<pre>
static final <a href="api/com/exedio/cope/pattern/AttributeListLimited.html">AttributeListLimited</a>&lt;String&gt; emails =
    <a href="api/com/exedio/cope/pattern/AttributeListLimited.html">AttributeListLimited</a>.<a href="api/com/exedio/cope/pattern/AttributeListLimited.html#newList(com.exedio.cope.FunctionAttribute, int)">newList</a>(new StringAttribute(OPTIONAL), 4);
</pre>
		<div>
			Internally there are 4 string attributes used for storing the elements of the list.
			If someone tries to store a list of more than 4 elements,
			an exception is thrown.
		</div>
		<h3><a name="attributemaps">Attribute Maps</a></h3>
		<div>
			Especially in international applications you may want to store multiple attribute values,
			such as one price of a product for each country or one description for each language.
			The following example specifies the latter:
		</div>
<pre>
static final <a href="api/com/exedio/cope/pattern/AttributeMap.html">AttributeMap</a>&lt;Language,String&gt; description =
    <a href="api/com/exedio/cope/pattern/AttributeMap.html">AttributeMap</a>.<a href="api/com/exedio/cope/pattern/AttributeMap.html#newMap(com.exedio.cope.FunctionAttribute, com.exedio.cope.FunctionAttribute)">newMap</a>(newItemAttribute(Language.class),
                        new StringAttribute());
</pre>
		<div>
			The instrumentor will create appropriate methods for accessing the <i>attribute map</i>:
		</div>
<pre>
String getDescription(Language k)
{
    return Product.description.get(this, k);
}

void setDescription(Language k, String description)
{
    Product.description.set(this, k, description);
}
</pre>
		<div>
			This example assumes, that there is already a persistent item <tt>Language</tt>.
			If you decide to use use a fixed set of languages in your application,
			you may use an enum instead:
		</div>
<pre>
static enum Language { DE, EN, PL; }

static final <a href="api/com/exedio/cope/pattern/AttributeMap.html">AttributeMap</a>&lt;Language,String&gt; description =
    <a href="api/com/exedio/cope/pattern/AttributeMap.html">AttributeMap</a>.<a href="api/com/exedio/cope/pattern/AttributeMap.html#newMap(com.exedio.cope.FunctionAttribute, com.exedio.cope.FunctionAttribute)">newMap</a>(newEnumAttribute(Language.class),
                        new StringAttribute());
</pre>
		<h3><a name="dayattributes">Day Attributes</a></h3>
		<div>
			Class <a href="api/com/exedio/cope/DateAttribute.html">DateAttribute</a>
			already stores time stamps with millisecond precision.<commit_msg>add limited attribute maps<commit_after><html>
	<head>
		<title>COPE - Attribute Reloaded Trail</title>
		<meta name="keywords" content="Persistence, Java">
		<meta name="description" content="COPE - a persistence framework for Java">
		<link rel="stylesheet" href="cope.css">
	</head>
	<body>
		<a href="http://www.exedio.com/">
			<img src="exedio.png" class="exedio">
		</a>
		<h1><a href="index.html">COPE</a></h1>
		<div>Cope with Object Persistence</div>
		
		<h2>Attribute Reloaded Trail</h2>
		<a href="http://sourceforge.net/">
			<img src="http://sourceforge.net/sflogo.php?group_id=152867&amp;type=1"
				class="sf" alt="SourceForge.net Logo" />
		</a>
		<div>
			While the <a href="attributes.html">Attribute Trail</a>
			covered the most fundamental attributes only,
			this trails shows you some more special ways to store data with COPE.
			Although most of the features below are not attributes in a formal sense
			(means subclasses of class <a href="api/com/exedio/cope/Attribute.html">Attribute</a>)
			you don't have to care about this until you want to develop such features yourself.
		</div>
		<h3><a name="contents">Contents</a></h3>
		<ul>
			<li><a href="#hashes">Hashes</a></li>
			<li><a href="#attributelists">Attribute Lists</a></li>
			<li><a href="#attributemaps">Attribute Maps</a></li>
			<li><a href="#dayattributes">Day Attributes</a></li>
			<li><a href="#further">Further Reading</a></li>
		</ul>
		<h3><a name="hashes">Hashes</a></h3>
		<div>
			If you want to store a string encoded by a hash algorithm,
			such as the password of the customer,
			then put the following into class <tt>Customer</tt>:
		</div>
<pre>
static final <a href="api/com/exedio/cope/pattern/MD5Hash.html">MD5Hash</a> password = new <a href="api/com/exedio/cope/pattern/MD5Hash.html#MD5Hash()">MD5Hash</a>();
</pre>
		<div>
			The instrumentor will generate a method for checking the password
			instead of a getter method:
		</div>
<pre>
boolean checkPassword(String password)
{
   return Customer.password.check(this, password);
}
</pre>
		<div>
			Using the super classes of <tt>MD5Hash</tt>
			you can choose any hash algorithm provided by the java.security package
			or even implement a custom algorithm.
		</div>
		<h3><a name="attributelists">Attribute Lists</a></h3>
		<div>
			Sometimes you may want to store multiple values for an attribute,
			such as multiple email addresses for the customer.
			This can be achieved with <i>attribute lists</i>:
		</div>
<pre>
static final <a href="api/com/exedio/cope/pattern/AttributeList.html">AttributeList</a>&lt;String&gt; emails =
    <a href="api/com/exedio/cope/pattern/AttributeList.html">AttributeList</a>.<a href="api/com/exedio/cope/pattern/AttributeList.html#newList(com.exedio.cope.FunctionAttribute)">newList</a>(new StringAttribute());
</pre>
		<div>
			Internally this is implemented by an extra table in the database,
			so you can store lists of any size.
			If you are sure, that the list cannot a exceed a certain size,
			you may decide to use a <i>limited attribute list</i>:
		</div>
<pre>
static final <a href="api/com/exedio/cope/pattern/AttributeListLimited.html">AttributeListLimited</a>&lt;String&gt; emails =
    <a href="api/com/exedio/cope/pattern/AttributeListLimited.html">AttributeListLimited</a>.<a href="api/com/exedio/cope/pattern/AttributeListLimited.html#newList(com.exedio.cope.FunctionAttribute, int)">newList</a>(new StringAttribute(OPTIONAL), 4);
</pre>
		<div>
			Internally there are 4 string attributes used for storing the elements of the list.
			If someone tries to store a list of more than 4 elements,
			an exception is thrown.
		</div>
		<h3><a name="attributemaps">Attribute Maps</a></h3>
		<div>
			Especially in international applications you may want to store multiple attribute values,
			such as one price of a product for each country or one description for each language.
			The following example specifies the latter:
		</div>
<pre>
static final <a href="api/com/exedio/cope/pattern/AttributeMap.html">AttributeMap</a>&lt;Language,String&gt; description =
    <a href="api/com/exedio/cope/pattern/AttributeMap.html">AttributeMap</a>.<a href="api/com/exedio/cope/pattern/AttributeMap.html#newMap(com.exedio.cope.FunctionAttribute, com.exedio.cope.FunctionAttribute)">newMap</a>(newItemAttribute(Language.class),
                        new StringAttribute());
</pre>
		<div>
			The instrumentor will create appropriate methods for accessing the <i>attribute map</i>:
		</div>
<pre>
String getDescription(Language k)
{
    return Product.description.get(this, k);
}

void setDescription(Language k, String description)
{
    Product.description.set(this, k, description);
}
</pre>
		<div>
			This example assumes, that there is already a persistent item <tt>Language</tt>.
			If you decide to use use a fixed set of languages in your application,
			you may use an enum instead:
		</div>
<pre>
static enum Language { DE, EN, PL; }

static final <a href="api/com/exedio/cope/pattern/AttributeMap.html">AttributeMap</a>&lt;Language,String&gt; description =
    <a href="api/com/exedio/cope/pattern/AttributeMap.html">AttributeMap</a>.<a href="api/com/exedio/cope/pattern/AttributeMap.html#newMap(com.exedio.cope.FunctionAttribute, com.exedio.cope.FunctionAttribute)">newMap</a>(newEnumAttribute(Language.class),
                        new StringAttribute());
</pre>
		<div>
			As with <i>attribute lists</i> this is implemented by an extra table in the database,
			so you can store maps of any size.
			If the key space of the map is limited to an enum,
			you may decide to use a <i>limited attribute map</i> instead:
		</div>
<pre>
static enum Language { DE, EN, PL; }

static final <a href="api/com/exedio/cope/pattern/AttributeMapLimited.html">AttributeMapLimited</a>&lt;Language,String&gt; description =
    <a href="api/com/exedio/cope/pattern/AttributeMapLimited.html">AttributeMapLimited</a>.<a href="api/com/exedio/cope/pattern/AttributeMapLimited.html#newMap(java.lang.Class, com.exedio.cope.FunctionAttribute)">newMap</a>(Language.class,
                        new StringAttribute(OPTIONAL));
</pre>
		<div>
			Internally three string attributes
			<tt>nameDE</tt>, <tt>nameEN</tt>, <tt>namePL</tt>
			are used for storing the values of the map.
		</div>
		<h3><a name="dayattributes">Day Attributes</a></h3>
		<div>
			Class <a href="api/com/exedio/cope/DateAttribute.html">DateAttribute</a>
			already stores time stamps with millisecond precision.
{'fraction_non_alphanumeric': 0.1392552044455503, 'fraction_numerical': 0.004976362279173924, 'mean_word_length': 4.431531531531531, 'pattern_counts': {'":': 0, '<': 317, '<?xml version=': 0, '>': 317, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2446655', 'n_tokens_mistral': 4174, 'n_tokens_neox': 3887, 'n_words': 1069}