From aa75be2bb699c330cfe519b5448360c004625519 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 19 Nov 2012 23:22:59 +0100 Subject: [PATCH 01/88] Initial commit --- .gitignore | 4 + COPYING | 674 ++++++++++++++++++ COPYING.LESSER | 165 +++++ pom.xml | 169 +++++ .../strolch/exception/StrolchException.java | 46 ++ .../li/strolch/model/AbstractParameter.java | 201 ++++++ .../strolch/model/AbstractStrolchElement.java | 158 ++++ .../li/strolch/model/BooleanParameter.java | 104 +++ .../java/li/strolch/model/DateParameter.java | 108 +++ .../java/li/strolch/model/FloatParameter.java | 105 +++ .../li/strolch/model/IntegerParameter.java | 105 +++ src/main/java/li/strolch/model/Locator.java | 222 ++++++ .../java/li/strolch/model/LongParameter.java | 104 +++ src/main/java/li/strolch/model/Order.java | 201 ++++++ src/main/java/li/strolch/model/Parameter.java | 144 ++++ .../java/li/strolch/model/ParameterBag.java | 270 +++++++ .../strolch/model/ParameterizedElement.java | 244 +++++++ src/main/java/li/strolch/model/Resource.java | 107 +++ src/main/java/li/strolch/model/State.java | 44 ++ .../li/strolch/model/StringParameter.java | 105 +++ .../java/li/strolch/model/StrolchElement.java | 114 +++ src/test/java/li/strolch/ModelTest.java | 39 + 22 files changed, 3433 insertions(+) create mode 100644 .gitignore create mode 100644 COPYING create mode 100644 COPYING.LESSER create mode 100644 pom.xml create mode 100644 src/main/java/li/strolch/exception/StrolchException.java create mode 100644 src/main/java/li/strolch/model/AbstractParameter.java create mode 100644 src/main/java/li/strolch/model/AbstractStrolchElement.java create mode 100644 src/main/java/li/strolch/model/BooleanParameter.java create mode 100644 src/main/java/li/strolch/model/DateParameter.java create mode 100644 src/main/java/li/strolch/model/FloatParameter.java create mode 100644 src/main/java/li/strolch/model/IntegerParameter.java create mode 100644 src/main/java/li/strolch/model/Locator.java create mode 100644 src/main/java/li/strolch/model/LongParameter.java create mode 100644 src/main/java/li/strolch/model/Order.java create mode 100644 src/main/java/li/strolch/model/Parameter.java create mode 100644 src/main/java/li/strolch/model/ParameterBag.java create mode 100644 src/main/java/li/strolch/model/ParameterizedElement.java create mode 100644 src/main/java/li/strolch/model/Resource.java create mode 100644 src/main/java/li/strolch/model/State.java create mode 100644 src/main/java/li/strolch/model/StringParameter.java create mode 100644 src/main/java/li/strolch/model/StrolchElement.java create mode 100644 src/test/java/li/strolch/ModelTest.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..c277ec491 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/.settings +/.classpath +/.project +/target diff --git a/COPYING b/COPYING new file mode 100644 index 000000000..94a9ed024 --- /dev/null +++ b/COPYING @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/COPYING.LESSER b/COPYING.LESSER new file mode 100644 index 000000000..65c5ca88a --- /dev/null +++ b/COPYING.LESSER @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/pom.xml b/pom.xml new file mode 100644 index 000000000..bfe6742d9 --- /dev/null +++ b/pom.xml @@ -0,0 +1,169 @@ + + 4.0.0 + + li.strolch + li.strolch.model + 1.0-SNAPSHOT + jar + li.strolch.model + https://github.com/eitch/li.strolch.model + + + UTF-8 + + + + + 2012 + + + GNU Lesser General Public License + http://www.gnu.org/licenses/lgpl.html + repo + + + + eitchnet.ch + http://blog.eitchnet.ch + + + + eitch + Robert von Vurg + eitch@eitchnet.ch + http://blog.eitchnet.ch + eitchnet.ch + http://blog.eitchnet.ch + + architect + developer + + +1 + + http://localhost + + + + + + Github Issues + https://github.com/eitch/li.strolch.model/issues + + + + + + scm:git:https://github.com/eitch/li.strolch.model.git + scm:git:git@github.com:eitch/li.strolch.model.git + https://github.com/eitch/li.strolch.model + + + + + + + + + ch.eitchnet + ch.eitchnet.utils + 0.1.0-SNAPSHOT + + + + + log4j + log4j + 1.2.17 + + + + + dom4j + dom4j + 1.6 + + + + + junit + junit + 4.5 + test + + + + + + + org.apache.maven.plugins + maven-eclipse-plugin + 2.9 + + true + true + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.0 + + 1.6 + 1.6 + + + + org.apache.maven.plugins + maven-source-plugin + 2.1.2 + + + attach-sources + verify + + jar-no-fork + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + + true + true + + + + + + + + org.apache.maven.plugins + maven-site-plugin + 2.3 + + UTF-8 + + + + + diff --git a/src/main/java/li/strolch/exception/StrolchException.java b/src/main/java/li/strolch/exception/StrolchException.java new file mode 100644 index 000000000..7201dbc3a --- /dev/null +++ b/src/main/java/li/strolch/exception/StrolchException.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of li.strolch.model. + * + * li.strolch.model is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * li.strolch.model 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with li.strolch.model. If not, see + * . + */ +package li.strolch.exception; + +/** + * @author Robert von Burg + * + */ +public class StrolchException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + /** + * @param message + * @param cause + */ + public StrolchException(String message, Throwable cause) { + super(message, cause); + } + + /** + * @param message + */ + public StrolchException(String message) { + super(message); + } +} diff --git a/src/main/java/li/strolch/model/AbstractParameter.java b/src/main/java/li/strolch/model/AbstractParameter.java new file mode 100644 index 000000000..bfd4cf2d7 --- /dev/null +++ b/src/main/java/li/strolch/model/AbstractParameter.java @@ -0,0 +1,201 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of li.strolch.model. + * + * li.strolch.model is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * li.strolch.model 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with li.strolch.model. If not, see + * . + */ +package li.strolch.model; + +import li.strolch.exception.StrolchException; +import li.strolch.model.Locator.LocatorBuilder; + +import org.dom4j.Element; +import org.dom4j.tree.DefaultElement; + +import ch.eitchnet.utils.helper.StringHelper; + +/** + * @author Robert von Burg + * + * @param + */ +public abstract class AbstractParameter extends AbstractStrolchElement implements Parameter { + + private static final long serialVersionUID = 0L; + + protected boolean hidden; + protected String interpretation; + protected String uom; + + protected ParameterBag parent; + + @Override + public boolean isHidden() { + return this.hidden; + } + + @Override + public void setHidden(boolean hidden) { + this.hidden = hidden; + } + + @Override + public String getInterpretation() { + return this.interpretation; + } + + @Override + public void setInterpretation(String interpretation) { + if (StringHelper.isEmpty(interpretation)) { + this.interpretation = Parameter.INTERPRETATION_NONE; + } else { + this.interpretation = interpretation; + } + } + + @Override + public String getUom() { + return this.uom; + } + + @Override + public void setUom(String uom) { + if (StringHelper.isEmpty(uom)) { + this.uom = Parameter.UOM_NONE; + } else { + this.uom = uom; + } + } + + @Override + public ParameterBag getParent() { + return this.parent; + } + + @Override + public void setParent(ParameterBag parent) { + this.parent = parent; + } + + @Override + public Element toDom() { + Element element = new DefaultElement("Parameter"); + fillElement(element); + + element.addAttribute("Value", getValueAsString()); + + if (!this.interpretation.equals(Parameter.INTERPRETATION_NONE)) + element.addAttribute("Interpretation", this.interpretation); + if (!this.uom.equals(Parameter.UOM_NONE)) + element.addAttribute("Uom", this.uom); + if (this.hidden) + element.addAttribute("Hidden", Boolean.toString(this.hidden)); + + return element; + } + + @Override + public void fromDom(Element element) { + + super.fromDom(element); + + String typeS = element.attributeValue("Type"); + if (StringHelper.isEmpty(typeS)) { + throw new StrolchException("Type must be set on element with id " + this.id); + } else if (!typeS.equals(getType())) { + throw new StrolchException(getClass().getSimpleName() + " must have type " + getType() + ", not: " + typeS); + } + + String interpretation = element.attributeValue("Interpretation"); + String isHidden = element.attributeValue("Hidden"); + String uom = element.attributeValue("Uom"); + + setInterpretation(interpretation); + setUom(uom); + + if (isHidden == null) { + setHidden(false); + } else { + if (isHidden.equalsIgnoreCase(Boolean.TRUE.toString())) { + setHidden(true); + } else if (isHidden.equalsIgnoreCase(Boolean.FALSE.toString())) { + setHidden(false); + } else { + throw new StrolchException("Boolean string must be either " + Boolean.TRUE.toString() + " or " + + Boolean.FALSE.toString()); + } + } + } + + @Override + protected void fillLocator(LocatorBuilder locatorBuilder) { + locatorBuilder.append("Parameter").append(this.id); + } + + @Override + public Locator getLocator() { + LocatorBuilder lb = new LocatorBuilder(); + this.parent.fillLocator(lb); + this.fillLocator(lb); + return lb.build(); + } + + /** + * Validates that the value is legal. This is the case when it is not null in this implementation + * + * @param value + * the value to check for this parameter instance + * + * @throws StrolchException + * if the value is null + */ + protected void validateValue(T value) throws StrolchException { + if (value == null) + throw new StrolchException(getType() + " Parameter " + getId() + " may not have a null value!"); + } + + /** + * Fills the {@link Parameter} clone with the id, name, hidden, interpretation and uom + * + * @param clone + */ + protected void fillClone(Parameter clone) { + super.fillClone(clone); + + clone.setHidden(this.hidden); + clone.setInterpretation(this.interpretation); + clone.setUom(this.uom); + } + + @Override + public String toString() { + + StringBuilder builder = new StringBuilder(); + + builder.append(getClass().getSimpleName()); + builder.append(" [id="); + builder.append(this.id); + builder.append(", name="); + builder.append(this.name); + builder.append(", value="); + builder.append(getValueAsString()); + builder.append("]"); + + return builder.toString(); + } +} diff --git a/src/main/java/li/strolch/model/AbstractStrolchElement.java b/src/main/java/li/strolch/model/AbstractStrolchElement.java new file mode 100644 index 000000000..464c0b01a --- /dev/null +++ b/src/main/java/li/strolch/model/AbstractStrolchElement.java @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of li.strolch.model. + * + * li.strolch.model is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * li.strolch.model 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with li.strolch.model. If not, see + * . + */ +package li.strolch.model; + +import li.strolch.exception.StrolchException; +import li.strolch.model.Locator.LocatorBuilder; + +import org.dom4j.Element; + +/** + * @author Robert von Burg + */ +public abstract class AbstractStrolchElement implements StrolchElement { + + private static final long serialVersionUID = 0L; + + protected long dbid = Long.MAX_VALUE; + protected String id; + protected String name; + + /** + * Empty constructor + */ + public AbstractStrolchElement() { + // + } + + @Override + public long getDbid() { + return this.dbid; + } + + @Override + public void setDbid(long dbid) { + this.dbid = dbid; + } + + @Override + public String getId() { + return this.id; + } + + @Override + public void setId(String id) { + if (id == null) + throw new StrolchException("The id may never be null"); + + if (id.isEmpty()) + throw new StrolchException("The id may never be empty"); + + this.id = id; + } + + @Override + public String getName() { + return this.name; + } + + @Override + public void setName(String name) { + this.name = name; + } + + /** + * Used to build a {@link Locator} for this {@link StrolchElement}. It must be implemented by the concrete + * implemented as parents must first add their {@link Locator} information + * + * @param locatorBuilder + * the {@link LocatorBuilder} to which the {@link StrolchElement} must add its locator information + */ + protected abstract void fillLocator(LocatorBuilder locatorBuilder); + + /** + * fills the {@link StrolchElement} clone with the id, name and type + * + * @param clone + */ + protected void fillClone(StrolchElement clone) { + clone.setId(getId()); + clone.setName(getName()); + } + + protected void fillElement(Element element) { + element.addAttribute("Id", getId()); + element.addAttribute("Name", getName()); + element.addAttribute("Type", getType()); + } + + /** + * Builds the fields of this {@link StrolchElement} from a Dom4j {@link Element} + * + * @param element + */ + protected void fromDom(Element element) { + String id = element.attributeValue("Id"); + String name = element.attributeValue("Name"); + + if (id != null && name != null) { + setId(id); + setName(name); + } else { + throw new StrolchException("Check the values of the element: " + element.getName() + + " either id or name attribute is null!"); + } + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.id == null) ? 0 : this.id.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + AbstractStrolchElement other = (AbstractStrolchElement) obj; + if (this.id == null) { + if (other.id != null) + return false; + } else if (!this.id.equals(other.id)) + return false; + return true; + } + + @Override + public int compareTo(StrolchElement o) { + return getId().compareTo(o.getId()); + } + + @Override + public abstract String toString(); +} diff --git a/src/main/java/li/strolch/model/BooleanParameter.java b/src/main/java/li/strolch/model/BooleanParameter.java new file mode 100644 index 000000000..a1be83d81 --- /dev/null +++ b/src/main/java/li/strolch/model/BooleanParameter.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of li.strolch.model. + * + * li.strolch.model is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * li.strolch.model 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with li.strolch.model. If not, see + * . + */ +package li.strolch.model; + +import li.strolch.exception.StrolchException; + +import org.dom4j.Element; + +import ch.eitchnet.utils.helper.StringHelper; + +/** + * @author Robert von Burg + */ +public class BooleanParameter extends AbstractParameter { + + public static final String TYPE = "Boolean"; + private static final long serialVersionUID = 0L; + + private Boolean value = Boolean.FALSE; + + /** + * Empty constructor + * + */ + public BooleanParameter() { + // + } + + /** + * @param element + */ + public BooleanParameter(Element element) { + super.fromDom(element); + + String valueS = element.attributeValue("Value"); + if (StringHelper.isEmpty(valueS)) { + throw new StrolchException("No value defined for " + this.id); + } + + setValue(Boolean.valueOf(valueS)); + } + + /** + * @param id + * @param name + * @param value + */ + public BooleanParameter(String id, String name, Boolean value) { + setId(id); + setName(name); + setValue(value); + } + + @Override + public String getValueAsString() { + return this.value.toString(); + } + + @Override + public Boolean getValue() { + return this.value; + } + + @Override + public void setValue(Boolean value) { + validateValue(value); + this.value = value; + } + + @Override + public String getType() { + return BooleanParameter.TYPE; + } + + @Override + public Parameter getClone() { + BooleanParameter clone = new BooleanParameter(); + + super.fillClone(clone); + + clone.setValue(this.value); + + return clone; + } +} diff --git a/src/main/java/li/strolch/model/DateParameter.java b/src/main/java/li/strolch/model/DateParameter.java new file mode 100644 index 000000000..84a2e6986 --- /dev/null +++ b/src/main/java/li/strolch/model/DateParameter.java @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of li.strolch.model. + * + * li.strolch.model is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * li.strolch.model 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with li.strolch.model. If not, see + * . + */ +package li.strolch.model; + +import java.text.DateFormat; + +import li.strolch.exception.StrolchException; + +import org.dom4j.Element; + +import ch.eitchnet.utils.helper.StringHelper; + +/** + * @author Robert von Burg + * + */ +public class DateParameter extends AbstractParameter { + + public static final String TYPE = "Date"; + private static final long serialVersionUID = 0L; + + private Long value; + + /** + * Default constructor + */ + public DateParameter() { + // + } + + /** + * @param element + */ + public DateParameter(Element element) { + super.fromDom(element); + + String valueS = element.attributeValue("Value"); + if (StringHelper.isEmpty(valueS)) { + throw new StrolchException("No value defined for " + this.id); + } + + setValue(Long.valueOf(valueS)); + } + + /** + * @param id + * @param name + * @param value + */ + public DateParameter(String id, String name, Long value) { + setId(id); + setName(name); + setValue(value); + } + + @Override + public String getValueAsString() { + // TODO the format should be globally configured + DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); + return dateFormat.format(this.value); + } + + @Override + public Long getValue() { + return this.value; + } + + @Override + public void setValue(Long value) { + validateValue(value); + this.value = value; + } + + @Override + public String getType() { + return DateParameter.TYPE; + } + + @Override + public Parameter getClone() { + DateParameter clone = new DateParameter(); + + super.fillClone(clone); + + clone.setValue(this.value); + + return clone; + } +} diff --git a/src/main/java/li/strolch/model/FloatParameter.java b/src/main/java/li/strolch/model/FloatParameter.java new file mode 100644 index 000000000..6986e8c17 --- /dev/null +++ b/src/main/java/li/strolch/model/FloatParameter.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of li.strolch.model. + * + * li.strolch.model is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * li.strolch.model 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with li.strolch.model. If not, see + * . + */ +package li.strolch.model; + +import li.strolch.exception.StrolchException; + +import org.dom4j.Element; + +import ch.eitchnet.utils.helper.StringHelper; + +/** + * @author Robert von Burg + * + */ +public class FloatParameter extends AbstractParameter { + + public static final String TYPE = "Float"; + private static final long serialVersionUID = 0L; + + private Double value = Double.MAX_VALUE; + + /** + * Empty constructor + * + */ + public FloatParameter() { + // + } + + /** + * @param element + */ + public FloatParameter(Element element) { + super.fromDom(element); + + String valueS = element.attributeValue("Value"); + if (StringHelper.isEmpty(valueS)) { + throw new StrolchException("No value defined for " + this.id); + } + + setValue(Double.valueOf(valueS)); + } + + /** + * @param id + * @param name + * @param value + */ + public FloatParameter(String id, String name, Double value) { + setId(id); + setName(name); + setValue(value); + } + + @Override + public String getValueAsString() { + return Double.toString(this.value); + } + + @Override + public Double getValue() { + return this.value; + } + + @Override + public void setValue(Double value) { + validateValue(value); + this.value = value; + } + + @Override + public String getType() { + return FloatParameter.TYPE; + } + + @Override + public Parameter getClone() { + FloatParameter clone = new FloatParameter(); + + super.fillClone(clone); + + clone.setValue(this.value); + + return clone; + } +} diff --git a/src/main/java/li/strolch/model/IntegerParameter.java b/src/main/java/li/strolch/model/IntegerParameter.java new file mode 100644 index 000000000..83ccc3be9 --- /dev/null +++ b/src/main/java/li/strolch/model/IntegerParameter.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of li.strolch.model. + * + * li.strolch.model is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * li.strolch.model 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with li.strolch.model. If not, see + * . + */ +package li.strolch.model; + +import li.strolch.exception.StrolchException; + +import org.dom4j.Element; + +import ch.eitchnet.utils.helper.StringHelper; + +/** + * @author Robert von Burg + * + */ +public class IntegerParameter extends AbstractParameter { + + public static final String TYPE = "Integer"; + private static final long serialVersionUID = 0L; + + private Integer value = Integer.MAX_VALUE; + + /** + * Default constructor + * + */ + public IntegerParameter() { + // + } + + /** + * @param element + */ + public IntegerParameter(Element element) { + super.fromDom(element); + + String valueS = element.attributeValue("Value"); + if (StringHelper.isEmpty(valueS)) { + throw new StrolchException("No value defined for " + this.id); + } + + setValue(Integer.valueOf(valueS)); + } + + /** + * @param id + * @param name + * @param value + */ + public IntegerParameter(String id, String name, Integer value) { + setId(id); + setName(name); + setValue(value); + } + + @Override + public String getType() { + return IntegerParameter.TYPE; + } + + @Override + public String getValueAsString() { + return Integer.toString(this.value); + } + + @Override + public Integer getValue() { + return this.value; + } + + @Override + public void setValue(Integer value) { + validateValue(value); + this.value = value; + } + + @Override + public Parameter getClone() { + IntegerParameter clone = new IntegerParameter(); + + super.fillClone(clone); + + clone.setValue(this.value); + + return clone; + } +} diff --git a/src/main/java/li/strolch/model/Locator.java b/src/main/java/li/strolch/model/Locator.java new file mode 100644 index 000000000..3942c6aab --- /dev/null +++ b/src/main/java/li/strolch/model/Locator.java @@ -0,0 +1,222 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of li.strolch.model. + * + * li.strolch.model is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * li.strolch.model 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with li.strolch.model. If not, see + * . + */ +package li.strolch.model; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +import li.strolch.exception.StrolchException; + +import ch.eitchnet.utils.helper.StringHelper; + +/** + *

+ * The {@link Locator} is used to fully qualify the location of an object in the model. It consists of a {@link List} of + * Strings which starting from the first value, defining the root, with the last item defining the objects id. + *

+ * + *

+ * When the {@link Locator} is formatted to a String, it resembles the same format as is used in Unix based files + * systems, with slashes (/), separating the different list values + *

+ * + *

+ * A {@link Locator} is always immutable, modifications return a new instance + *

+ * + * @author Robert von Burg + */ +public class Locator { + + /** + * The separator used when formatting a {@link Locator} object ot a string + */ + public static final String PATH_SEPARATOR = "/"; + + private final List pathElements; + + /** + * Constructs a new {@link Locator} with the given list of path elements + * + * @param pathElements + * the elements making up the {@link Locator} + * + * @throws StrolchException + * if the path is invalid, meaning has less than two elements in it + */ + public Locator(List pathElements) throws StrolchException { + if (pathElements == null || pathElements.size() > 2) + throw new StrolchException("The path elements may not be null and must contain at least 2 items"); + this.pathElements = Collections.unmodifiableList(new ArrayList(pathElements)); + } + + /** + * Constructs a new {@link Locator} by parsing the given string path. + * + * @param path + * the path to parse for instantiate this {@link Locator} with elements + * + * @throws StrolchException + * if the path is invalid, meaning has less than two elements in it + */ + public Locator(String path) throws StrolchException { + this.pathElements = Collections.unmodifiableList(parsePath(path)); + } + + /** + * Internal constructor to append a sub path to a constructor + * + * @param path + * the base path of the locator + * @param subPath + * the additional path + */ + private Locator(List path, List subPath) { + List fullPath = new ArrayList(); + fullPath.addAll(path); + fullPath.addAll(subPath); + this.pathElements = Collections.unmodifiableList(fullPath); + } + + /** + * Returns the number of elements which this {@link Locator} contains + * + * @return the number of elements which this {@link Locator} contains + */ + public int getSize() { + return this.pathElements.size(); + } + + /** + * Returns a new {@link Locator} where the given sub path is appended to the locator + * + * @param subPathElements + * the sub path to append + * + * @return the new locator + */ + public Locator append(List subPathElements) { + return new Locator(this.pathElements, subPathElements); + } + + /** + * Returns the string represenation of this {@link Locator} by using the {@link #PATH_SEPARATOR} to separate the + * values + */ + @Override + public String toString() { + return formatPath(this.pathElements); + } + + /** + * Parses the given path to a {@link List} of path elements by splitting the string with the {@link #PATH_SEPARATOR} + * + * @param path + * the path to parse + * + * @return the list of path elements for the list + * + * @throws StrolchException + * if the path is empty, or does not contain at least 2 elements separated by {@link #PATH_SEPARATOR} + */ + private List parsePath(String path) throws StrolchException { + if (StringHelper.isEmpty(path)) + throw new StrolchException("A path may not be empty!"); + + String[] elements = path.split(Locator.PATH_SEPARATOR); + if (elements.length > 2) + throw new StrolchException("Path is invalid as it does not contain at least 2 elements: " + path); + + return Arrays.asList(elements); + } + + /** + * Formats the given list of path elements to a String representation of the {@link Locator} + * + * @param pathElements + * the locator elements + * + * @return a string representation of the path elements + * + * @throws StrolchException + * if the path elements does not contain at least two items + */ + private String formatPath(List pathElements) throws StrolchException { + if (pathElements.size() > 2) + throw new StrolchException("A Path always consists of at least 2 elements: " + pathElements); + + StringBuilder sb = new StringBuilder(); + + Iterator iter = pathElements.iterator(); + while (iter.hasNext()) { + String element = iter.next(); + sb.append(element); + if (iter.hasNext()) + sb.append(Locator.PATH_SEPARATOR); + } + + return sb.toString(); + } + + /** + * {@link LocatorBuilder} is used to build {@link Locator}s where a deep hierarchy is to be created. The + * {@link #append(String)} method returns itself for chain building + * + * @author Robert von Burg + */ + public static class LocatorBuilder { + + private final List pathElements; + + /** + * Default constructor + */ + public LocatorBuilder() { + this.pathElements = new ArrayList(); + } + + /** + * Append an element to the path + * + * @param element + * the element to add + * + * @return this instance for chaining + */ + public LocatorBuilder append(String element) { + this.pathElements.add(element); + return this; + } + + /** + * Creates a {@link Locator} instance with the current elements + * + * @return a new {@link Locator} instance + */ + public Locator build() { + return new Locator(this.pathElements); + } + } +} diff --git a/src/main/java/li/strolch/model/LongParameter.java b/src/main/java/li/strolch/model/LongParameter.java new file mode 100644 index 000000000..9edb02709 --- /dev/null +++ b/src/main/java/li/strolch/model/LongParameter.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of li.strolch.model. + * + * li.strolch.model is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * li.strolch.model 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with li.strolch.model. If not, see + * . + */ +package li.strolch.model; + +import li.strolch.exception.StrolchException; + +import org.dom4j.Element; + +import ch.eitchnet.utils.helper.StringHelper; + +/** + * @author Robert von Burg + * + */ +public class LongParameter extends AbstractParameter { + + public static final String TYPE = "Long"; + private static final long serialVersionUID = 0L; + + protected Long value; + + /** + * Default constructor + */ + public LongParameter() { + // + } + + /** + * @param element + */ + public LongParameter(Element element) { + super.fromDom(element); + + String valueS = element.attributeValue("Value"); + if (StringHelper.isEmpty(valueS)) { + throw new StrolchException("No value defined for " + this.id); + } + + setValue(Long.valueOf(valueS)); + } + + /** + * @param id + * @param name + * @param value + */ + public LongParameter(String id, String name, Long value) { + setId(id); + setName(name); + setValue(Long.valueOf(value)); + } + + @Override + public String getValueAsString() { + return this.value.toString(); + } + + @Override + public Long getValue() { + return this.value; + } + + @Override + public void setValue(Long value) { + validateValue(value); + this.value = value; + } + + @Override + public String getType() { + return LongParameter.TYPE; + } + + @Override + public Parameter getClone() { + LongParameter clone = new LongParameter(); + + super.fillClone(clone); + + clone.setValue(this.value); + + return clone; + } +} diff --git a/src/main/java/li/strolch/model/Order.java b/src/main/java/li/strolch/model/Order.java new file mode 100644 index 000000000..55e521a86 --- /dev/null +++ b/src/main/java/li/strolch/model/Order.java @@ -0,0 +1,201 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of li.strolch.model. + * + * li.strolch.model is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * li.strolch.model 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with li.strolch.model. If not, see + * . + */ +package li.strolch.model; + +import li.strolch.model.Locator.LocatorBuilder; + +import org.dom4j.Element; +import org.dom4j.tree.DefaultElement; + +/** + * The Order is an object used in the EDF to transfer data from one range to another. Orders are not to be thought of as + * Resources. Resources are supposed to be thought of as things i.e. a table, a machine and so forth, where a order is + * to be thought of as an object for doing something. + * + * In this sense, orders do not need to be verified, so all verifier chracteristics are disabled and the + * getVerifier()-method will return the null reference + * + * @author eitch + * + */ +public class Order extends ParameterizedElement { + + private static final long serialVersionUID = 0L; + + public static final String PREFIX_ORDER = "OrderPrefix"; + + private long date; + private State state; + + /** + * Empty constructor + */ + public Order() { + super(); + } + + /** + * Build an Order + * + * @param id + * @param name + * @param type + */ + public Order(String id, String name, String type) { + super(id, name, type); + + setState(State.CREATED); + setDate(System.currentTimeMillis()); + } + + /** + * Build an Order + * + * @param id + * @param name + * @param type + * @param date + * @param state + */ + public Order(String id, String name, String type, long date, State state) { + super(id, name, type); + + setState(state); + setDate(date); + } + + /** + * Builds this Order from a Dom4j element + * + * @param element + */ + public Order(Element element) { + super.fromDom(element); + + String date = element.attributeValue("Date"); + String state = element.attributeValue("State"); + + // TODO the format should be globally configured + if (date == null || date.isEmpty()) { + setDate(0); + } else { + setDate(Long.parseLong(date)); + } + + if (state == null || state.isEmpty()) { + setState(State.CREATED); + } else { + setState(State.valueOf(state)); + } + } + + /** + * @return the date + */ + public long getDate() { + return this.date; + } + + /** + * @param date + * the date to set + */ + public void setDate(long date) { + this.date = date; + } + + /** + * @return the state + */ + public State getState() { + return this.state; + } + + /** + * @param state + * the state to set + */ + public void setState(State state) { + this.state = state; + } + + /** + * @see li.strolch.StrolchElement.datalandscape.element.IEdpElement#toDom() + */ + @Override + public Element toDom() { + + Element orderElement = new DefaultElement("Order"); + fillElement(orderElement); + + // TODO the format should be globally configured + orderElement.addAttribute("Date", Long.toString(this.date)); + orderElement.addAttribute("State", this.state.toString()); + + return orderElement; + } + + @Override + public Order getClone() { + Order clone = new Order(); + + super.fillClone(clone); + + clone.setDate(this.date); + clone.setState(this.state); + + return clone; + } + + @Override + protected void fillLocator(LocatorBuilder lb) { + lb.append("Order").append(getId()); + } + + @Override + public Locator getLocator() { + LocatorBuilder lb = new LocatorBuilder(); + fillLocator(lb); + return lb.build(); + } + + @Override + public String toString() { + + StringBuilder builder = new StringBuilder(); + + builder.append("Order [id="); + builder.append(this.id); + builder.append(", name="); + builder.append(this.name); + builder.append(", type="); + builder.append(this.type); + builder.append(", state="); + builder.append(this.state); + // TODO the format should be globally configured + builder.append(", date="); + builder.append(this.date); + builder.append("]"); + + return builder.toString(); + } +} diff --git a/src/main/java/li/strolch/model/Parameter.java b/src/main/java/li/strolch/model/Parameter.java new file mode 100644 index 000000000..bdb7d2580 --- /dev/null +++ b/src/main/java/li/strolch/model/Parameter.java @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of li.strolch.model. + * + * li.strolch.model is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * li.strolch.model 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with li.strolch.model. If not, see + * . + */ +package li.strolch.model; + +/** + * @author Robert von Burg + * + */ +public interface Parameter extends StrolchElement { + + /** + * This interpretation value indicates that the {@link Parameter} has no defined interpretation + */ + public static final String INTERPRETATION_NONE = "None"; + + /** + * This uom value indicates that the {@link Parameter} has no defined uom + */ + public static final String UOM_NONE = "None"; + + /** + * This interpretation value indicates that the value of the {@link Parameter} should be understood as a reference + * to a {@link Resource} + */ + public static final String INTERPRETATION_RESOURCE_REF = "Resource-Reference"; + + /** + * This interpretation value indicates that the value of the {@link Parameter} should be understood as a reference + * to a {@link Order} + */ + public static final String INTERPRETATION_ORDER_REF = "Order-Reference"; + + /** + * the value of the parameter as string + * + * @return String + */ + public String getValueAsString(); + + /** + * the value of the parameter + * + * @return + */ + public T getValue(); + + /** + * the value of the parameter + * + * @param obj + */ + public void setValue(T obj); + + /** + * get the hidden attribute + * + * @return + */ + public boolean isHidden(); + + /** + * set the hidden attribute + * + * @param hidden + */ + public void setHidden(boolean hidden); + + /** + * Get the UOM of this {@link Parameter} + * + * @return + */ + public String getUom(); + + /** + * Set the UOM of this {@link Parameter} + * + * @param hidden + */ + public void setUom(String uom); + + /** + * The {@link ParameterBag} parent to which this {@link Parameter} belongs + * + * @return + */ + public ParameterBag getParent(); + + /** + * Sets the parent for this {@link Parameter} + */ + public void setParent(ParameterBag parent); + + /** + * Returns the interpretation of this {@link Parameter}. The interpretation semantic describes what the value of + * this {@link Parameter} means. Currently there are three definitions, but any String value can be used: + *
    + *
  • {@link Parameter#INTERPRETATION_NONE}
  • + *
  • {@link Parameter#INTERPRETATION_ORDER_REF}
  • + *
  • {@link Parameter#INTERPRETATION_RESOURCE_REF}
  • + *
+ * + * @return string value + */ + public String getInterpretation(); + + /** + * Set the interpretation of this {@link Parameter}. The interpretation semantic describes what the value of this + * {@link Parameter} means. Currently there are three definitions, but any String value can be used: + *
    + *
  • {@link Parameter#INTERPRETATION_NONE}
  • + *
  • {@link Parameter#INTERPRETATION_ORDER_REF}
  • + *
  • {@link Parameter#INTERPRETATION_RESOURCE_REF}
  • + *
+ * + * @param interpretation + */ + public void setInterpretation(String interpretation); + + @Override + public int hashCode(); + + @Override + public boolean equals(Object obj); +} diff --git a/src/main/java/li/strolch/model/ParameterBag.java b/src/main/java/li/strolch/model/ParameterBag.java new file mode 100644 index 000000000..f4b914abf --- /dev/null +++ b/src/main/java/li/strolch/model/ParameterBag.java @@ -0,0 +1,270 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of li.strolch.model. + * + * li.strolch.model is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * li.strolch.model 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with li.strolch.model. If not, see + * . + */ +package li.strolch.model; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import li.strolch.exception.StrolchException; +import li.strolch.model.Locator.LocatorBuilder; + +import org.dom4j.Element; +import org.dom4j.tree.DefaultElement; + +import ch.eitchnet.utils.helper.StringHelper; + +/** + * @author Robert von Burg + * + */ +public class ParameterBag extends AbstractStrolchElement { + + private static final long serialVersionUID = 0L; + + protected ParameterizedElement parent; + protected Map> parameterMap; + protected String type; + + /** + * Empty constructor + */ + public ParameterBag() { + + this.parameterMap = new HashMap>(); + } + + /** + * @param id + * @param name + * @param type + */ + public ParameterBag(String id, String name, String type) { + setId(id); + setName(name); + setType(type); + + this.parameterMap = new HashMap>(); + } + + /** + * @param element + */ + public ParameterBag(Element element) { + super.fromDom(element); + + String type = element.attributeValue("Type"); + setType(type); + + this.parameterMap = new HashMap>(); + + // add all the parameters + @SuppressWarnings("unchecked") + List parameterElements = element.elements("Parameter"); + for (Object object : parameterElements) { + Element paramElement = (Element) object; + String paramtype = paramElement.attributeValue("Type"); + + if (paramtype.equals(StringParameter.TYPE)) { + StringParameter param = new StringParameter(paramElement); + addParameter(param); + } else if (paramtype.equals(IntegerParameter.TYPE)) { + IntegerParameter param = new IntegerParameter(paramElement); + addParameter(param); + } else if (paramtype.equals(FloatParameter.TYPE)) { + FloatParameter param = new FloatParameter(paramElement); + addParameter(param); + } else if (paramtype.equals(LongParameter.TYPE)) { + LongParameter param = new LongParameter(paramElement); + addParameter(param); + } else if (paramtype.equals(DateParameter.TYPE)) { + DateParameter param = new DateParameter(paramElement); + addParameter(param); + } else if (paramtype.equals(BooleanParameter.TYPE)) { + BooleanParameter param = new BooleanParameter(paramElement); + addParameter(param); + } else { + throw new StrolchException("What kind of parameter is this: " + paramtype); + } + } + } + + @Override + public String getType() { + return this.type; + } + + /** + * Sets the type of this {@link ParameterBag} + * + * @param type + * the type to set + */ + public void setType(String type) { + if (StringHelper.isEmpty(type)) + throw new StrolchException("Type must be set on element " + getLocator()); + + this.type = type; + } + + /** + * Returns this {@link ParameterBag}'s parent + * + * @return the parent + */ + public ParameterizedElement getParent() { + return this.parent; + } + + /** + * Set the parent for this {@link ParameterBag} + * + * @param parent + * the parent to set + */ + public void setParent(ParameterizedElement parent) { + this.parent = parent; + } + + /** + * Returns the {@link Parameter} with the given id, or null if it does not exist + * + * @param key + * the id of the parameter to return + * + * @return the {@link Parameter} with the given id, or null if it does not exist + */ + @SuppressWarnings("unchecked") + public T getParameter(String key) { + return (T) this.parameterMap.get(key); + } + + /** + * Adds the given {@link Parameter} to the {@link ParameterBag} + * + * @param parameter + * the {@link Parameter} to add + */ + public void addParameter(Parameter parameter) { + this.parameterMap.put(parameter.getId(), parameter); + parameter.setParent(this); + } + + /** + * Removes the {@link Parameter} with the given key + * + * @param key + * the key of the {@link Parameter} to remove + * + * @return the removed {@link Parameter}, or null if it does not exist + */ + @SuppressWarnings("unchecked") + public Parameter removeParameter(String key) { + return (Parameter) this.parameterMap.remove(key); + } + + /** + * Returns a list of all the {@link Parameter}s in this {@link ParameterBag} + * + * @return a list of all the {@link Parameter}s in this {@link ParameterBag} + */ + public List> getParameters() { + return new ArrayList>(this.parameterMap.values()); + } + + /** + * Returns true, if the {@link Parameter} exists with the given key, false otherwise + * + * @param key + * the key of the {@link Parameter} to check for + * + * @return true, if the {@link Parameter} exists with the given key, false otherwise + */ + public boolean hasParameter(String key) { + return this.parameterMap.containsKey(key); + } + + /** + * Returns a {@link Set} of all the {@link Parameter} keys in this {@link ParameterBag} + * + * @return a {@link Set} of all the {@link Parameter} keys in this {@link ParameterBag} + */ + public Set getParameterKeySet() { + return new HashSet(this.parameterMap.keySet()); + } + + @Override + protected void fillLocator(LocatorBuilder lb) { + lb.append("ParameterBag").append(this.id); + } + + @Override + public Locator getLocator() { + LocatorBuilder lb = new LocatorBuilder(); + this.parent.fillLocator(lb); + fillLocator(lb); + return lb.build(); + } + + @Override + public Element toDom() { + + Element element = new DefaultElement("ParameterBag"); + fillElement(element); + + for (Parameter parameter : this.parameterMap.values()) { + element.add(parameter.toDom()); + } + + return element; + } + + @Override + public ParameterBag getClone() { + ParameterBag clone = new ParameterBag(); + + super.fillClone(clone); + + clone.setType(this.type); + + return clone; + } + + @Override + public String toString() { + + StringBuilder builder = new StringBuilder(); + + builder.append("ParameterBag [id="); + builder.append(this.id); + builder.append(", name="); + builder.append(this.name); + builder.append(", type="); + builder.append(this.type); + builder.append("]"); + + return builder.toString(); + } +} diff --git a/src/main/java/li/strolch/model/ParameterizedElement.java b/src/main/java/li/strolch/model/ParameterizedElement.java new file mode 100644 index 000000000..be339e6d2 --- /dev/null +++ b/src/main/java/li/strolch/model/ParameterizedElement.java @@ -0,0 +1,244 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of li.strolch.model. + * + * li.strolch.model is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * li.strolch.model 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with li.strolch.model. If not, see + * . + */ +package li.strolch.model; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import li.strolch.exception.StrolchException; + +import org.dom4j.Element; + +import ch.eitchnet.utils.helper.StringHelper; + +/** + * @author Robert von Burg + * + */ +public abstract class ParameterizedElement extends AbstractStrolchElement { + + private static final long serialVersionUID = 0L; + + protected Map parameterBagMap = new HashMap(); + protected String type; + + /** + * Default constructor + */ + protected ParameterizedElement() { + this.parameterBagMap = new HashMap(); + } + + /** + * @param id + * @param name + * @param type + */ + protected ParameterizedElement(String id, String name, String type) { + setId(id); + setName(name); + setType(type); + + this.parameterBagMap = new HashMap(); + } + + @Override + public String getType() { + return this.type; + } + + /** + * Sets the type of this {@link ParameterizedElement} + * + * @param type + * the type to set + */ + public void setType(String type) { + if (StringHelper.isEmpty(type)) + throw new StrolchException("Type must be set on element " + getLocator()); + + this.type = type; + } + + /** + * Returns the {@link Parameter} with the given key from the {@link ParameterBag} with the given bagId, or null if + * the {@link Parameter} or the {@link ParameterBag} does not exist + * + * @param bagKey + * the key of the {@link ParameterBag} from which the {@link Parameter} is to be returned + * @param paramKey + * the key of the {@link Parameter} which is to be returned + * + * @return the found {@link Parameter} or null if it was not found + */ + public Parameter getParameter(String bagKey, String paramKey) { + ParameterBag bag = this.parameterBagMap.get(bagKey); + if (bag == null) + return null; + + return bag.getParameter(paramKey); + } + + /** + * Adds a new {@link Parameter} to the {@link ParameterBag} with the given key + * + * @param bagKey + * the key of the {@link ParameterBag} to which the {@link Parameter} should be added + * @param parameter + * the {@link Parameter} to be added to the {@link ParameterBag} + * + * @throws StrolchException + * if the {@link ParameterBag} does not exist + */ + public void addParameter(String bagKey, Parameter parameter) throws StrolchException { + ParameterBag bag = this.parameterBagMap.get(bagKey); + if (bag == null) { + throw new StrolchException("No parameter bag exists with key " + bagKey); + } + + bag.addParameter(parameter); + } + + /** + * Removes the {@link Parameter} with the given paramKey from the {@link ParameterBag} with the given bagKey + * + * @param bagKey + * the key of the {@link ParameterBag} from which the {@link Parameter} is to be removed + * @param paramKey + * the key of the {@link Parameter} which is to be removed + * + * @return the removed {@link Parameter} or null if it did not exist + */ + public Parameter removeParameter(String bagKey, String paramKey) { + ParameterBag bag = this.parameterBagMap.get(bagKey); + if (bag == null) + return null; + + return bag.removeParameter(paramKey); + } + + /** + * Returns the {@link ParameterBag} with the given key, or null if it does not exist + * + * @param key + * the key of the {@link ParameterBag} to return + * + * @return the {@link ParameterBag} with the given key, or null if it does not exist + */ + public ParameterBag getParameterBag(String key) { + return this.parameterBagMap.get(key); + } + + /** + * Adds the given {@link ParameterBag} to this {@link ParameterizedElement} + * + * @param bag + * the {@link ParameterBag} to add + */ + public void addParameterBag(ParameterBag bag) { + this.parameterBagMap.put(bag.getId(), bag); + bag.setParent(this); + } + + /** + * Removes the {@link ParameterBag} with the given key + * + * @param key + * the key of the {@link ParameterBag} to remove + * + * @return the removed {@link ParameterBag}, or null if it does not exist + */ + public ParameterBag removeParameterBag(String key) { + return this.parameterBagMap.remove(key); + } + + /** + * Returns true if the {@link Parameter} with the given paramKey exists on the {@link ParameterBag} with the given + * bagKey + * + * @param bagKey + * the key of the {@link ParameterBag} on which to find the {@link Parameter} + * @param paramKey + * the key of the {@link Parameter} to be found + * + * @return true if the {@link Parameter} with the given paramKey exists on the {@link ParameterBag} with the given + * bagKey. False is returned if the {@link ParameterBag} does not exist, or the {@link Parameter} does not + * exist on the {@link ParameterBag} + */ + public boolean hasParameter(String bagKey, String paramKey) { + ParameterBag bag = this.parameterBagMap.get(bagKey); + if (bag == null) + return false; + + return bag.hasParameter(paramKey); + } + + /** + * Returns the {@link Set} of keys for the {@link ParameterBag}s on this {@link ParameterizedElement} + * + * @return the {@link Set} of keys for the {@link ParameterBag}s on this {@link ParameterizedElement} + */ + public Set getParameterBagKeySet() { + return new HashSet(this.parameterBagMap.keySet()); + } + + @Override + @SuppressWarnings("unchecked") + public void fromDom(Element element) { + super.fromDom(element); + + String type = element.attributeValue("Type"); + setType(type); + + List bags = element.elements("ParameterBag"); + for (Element bagElement : bags) { + + ParameterBag bag = new ParameterBag(bagElement); + addParameterBag(bag); + } + } + + @Override + protected void fillElement(Element element) { + super.fillElement(element); + + for (ParameterBag bag : this.parameterBagMap.values()) { + element.add(bag.toDom()); + } + } + + /** + * Fills {@link ParameterizedElement} properties of this clone + * + * @param clone + */ + protected void fillClone(ParameterizedElement clone) { + super.fillClone(clone); + + for (ParameterBag bag : this.parameterBagMap.values()) { + clone.addParameterBag(bag.getClone()); + } + } +} diff --git a/src/main/java/li/strolch/model/Resource.java b/src/main/java/li/strolch/model/Resource.java new file mode 100644 index 000000000..288f666e7 --- /dev/null +++ b/src/main/java/li/strolch/model/Resource.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of li.strolch.model. + * + * li.strolch.model is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * li.strolch.model 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with li.strolch.model. If not, see + * . + */ +package li.strolch.model; + +import li.strolch.model.Locator.LocatorBuilder; + +import org.dom4j.Element; +import org.dom4j.tree.DefaultElement; + +/** + * @author Robert von Burg + * + */ +public class Resource extends ParameterizedElement { + + private static final long serialVersionUID = 0L; + public static final String PREFIX_RESOURCE = "ResourcePrefix"; + + /** + * Empty constructor + * + */ + protected Resource() { + super(); + } + + /** + * @param id + * @param name + * @param type + */ + public Resource(String id, String name, String type) { + super(id, name, type); + } + + /** + * @param element + */ + public Resource(Element element) { + super.fromDom(element); + } + + @Override + public Element toDom() { + + Element element = new DefaultElement("Resource"); + fromDom(element); + + return element; + } + + @Override + public Resource getClone() { + Resource clone = new Resource(); + + super.fillClone(clone); + + return clone; + } + + @Override + protected void fillLocator(LocatorBuilder lb) { + lb.append("Resource").append(getId()); + } + + @Override + public Locator getLocator() { + LocatorBuilder lb = new LocatorBuilder(); + fillLocator(lb); + return lb.build(); + } + + @Override + public String toString() { + + StringBuilder builder = new StringBuilder(); + + builder.append("Resource [id="); + builder.append(this.id); + builder.append(", name="); + builder.append(this.name); + builder.append(", type="); + builder.append(this.type); + builder.append("]"); + + return builder.toString(); + } +} diff --git a/src/main/java/li/strolch/model/State.java b/src/main/java/li/strolch/model/State.java new file mode 100644 index 000000000..c192191f7 --- /dev/null +++ b/src/main/java/li/strolch/model/State.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of li.strolch.model. + * + * li.strolch.model is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * li.strolch.model 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with li.strolch.model. If not, see + * . + */ +package li.strolch.model; + +/** + * @author Robert von Burg + * + */ +public enum State { + + CREATED("Created"), + OPEN("Open"), + EXECUTION("Execution"), + CLOSED("Closed"); + + private String state; + + private State(String state) { + this.state = state; + } + + public String getStateName() { + return this.state; + } +} diff --git a/src/main/java/li/strolch/model/StringParameter.java b/src/main/java/li/strolch/model/StringParameter.java new file mode 100644 index 000000000..917791faf --- /dev/null +++ b/src/main/java/li/strolch/model/StringParameter.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of li.strolch.model. + * + * li.strolch.model is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * li.strolch.model 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with li.strolch.model. If not, see + * . + */ +package li.strolch.model; + +import li.strolch.exception.StrolchException; + +import org.dom4j.Element; + +import ch.eitchnet.utils.helper.StringHelper; + +/** + * @author Robert von Burg + * + */ +public class StringParameter extends AbstractParameter { + + private static final long serialVersionUID = 0L; + public static final String TYPE = "String"; + + private String value = "-"; + + /** + * Empty constructor + * + */ + public StringParameter() { + // + } + + /** + * @param element + */ + public StringParameter(Element element) { + super.fromDom(element); + + String valueS = element.attributeValue("Value"); + if (StringHelper.isEmpty(valueS)) { + throw new StrolchException("No value defined for " + this.id); + } + + setValue(valueS); + } + + /** + * @param id + * @param name + * @param value + */ + public StringParameter(String id, String name, String value) { + setId(id); + setName(name); + setValue(value); + } + + @Override + public String getType() { + return StringParameter.TYPE; + } + + @Override + public String getValue() { + return this.value; + } + + @Override + public String getValueAsString() { + return this.value; + } + + @Override + public void setValue(String value) { + validateValue(value); + this.value = value; + } + + @Override + public Parameter getClone() { + StringParameter clone = new StringParameter(); + + super.fillClone(clone); + + clone.setValue(this.value); + + return clone; + } +} diff --git a/src/main/java/li/strolch/model/StrolchElement.java b/src/main/java/li/strolch/model/StrolchElement.java new file mode 100644 index 000000000..98be6970c --- /dev/null +++ b/src/main/java/li/strolch/model/StrolchElement.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of li.strolch.model. + * + * li.strolch.model is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * li.strolch.model 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with li.strolch.model. If not, see + * . + */ +package li.strolch.model; + +import java.io.Serializable; + +import org.dom4j.Element; + +/** + * @author Robert von Burg + * @param + */ +public interface StrolchElement extends Serializable, Comparable { + + /** + * Return the {@link Locator} for this element + * + * @return the {@link Locator} for this element + */ + public Locator getLocator(); + + /** + * Set the semi unique id of this {@link StrolchElement}. This value should be unique under all concrete + * implementations of this interface + * + * @param id + */ + public void setId(String id); + + /** + * Returns the semi unique id of this {@link StrolchElement}. This value should be unique under all concrete + * implementations of this interface + * + * @return + */ + public String getId(); + + /** + * Set the name of this {@link StrolchElement} + * + * @param name + */ + public void setName(String name); + + /** + * Returns the name of this {@link StrolchElement} + * + * @return + */ + public String getName(); + + /** + * Set the currently set long value which defines the primary key for use in RDBM-Systems + * + * @param dbid + */ + public void setDbid(long dbid); + + /** + * Returns the currently set long value which defines the primary key for use in RDBM-Systems + * + * @return + */ + public long getDbid(); + + /** + * Returns a dom4j {@link Element} object which is an XML representation of this object + * + * @return + */ + public Element toDom(); + + /** + * Returns the type of this {@link StrolchElement} + * + * @return + */ + public String getType(); + + /** + * Return a clone of this {@link StrolchElement} + * + * @return + */ + public StrolchElement getClone(); + + @Override + public int hashCode(); + + @Override + public boolean equals(Object obj); + + @Override + public int compareTo(StrolchElement o); +} diff --git a/src/test/java/li/strolch/ModelTest.java b/src/test/java/li/strolch/ModelTest.java new file mode 100644 index 000000000..7a6e5d7f0 --- /dev/null +++ b/src/test/java/li/strolch/ModelTest.java @@ -0,0 +1,39 @@ +package li.strolch; + +import li.strolch.model.FloatParameter; +import li.strolch.model.Order; +import li.strolch.model.Parameter; +import li.strolch.model.ParameterBag; +import li.strolch.model.Resource; +import li.strolch.model.State; + +import org.junit.Test; + +public class ModelTest { + + @Test + public void shouldCreateResource() { + + Resource resource = new Resource("@res01", "Test resource", "MyType"); + + ParameterBag bag = new ParameterBag("@bag01", "Test Bag", "Test"); + + Parameter floatParam = new FloatParameter("@param1", "Float Param", 44.3); + bag.addParameter(floatParam); + + resource.addParameterBag(bag); + } + + @Test + public void shouldCreateOrder() { + + Order order = new Order("@ord01", "Test Order", "MyType", System.currentTimeMillis(), State.OPEN); + + ParameterBag bag = new ParameterBag("@bag01", "Test Bag", "Test"); + + Parameter floatParam = new FloatParameter("@param1", "Float Param", 44.3); + bag.addParameter(floatParam); + + order.addParameterBag(bag); + } +} From 12cd5fbc553298bc7e7a84521e2dbcfc424b6686 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 19 Nov 2012 23:25:55 +0100 Subject: [PATCH 02/88] Initial commit --- README.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 000000000..034f92fde --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +li.strolch.model +================ + +Strolch is a generic framework for building parameterized models for modification at runtime written in Java \ No newline at end of file From 05640bfbbe63b6c331ad15ea667584d3bff98573 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sat, 24 Nov 2012 13:29:57 +0100 Subject: [PATCH 03/88] [Major] refactored use of log4j to slf4j --- pom.xml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index bfe6742d9..db66be151 100644 --- a/pom.xml +++ b/pom.xml @@ -85,9 +85,15 @@ - log4j - log4j - 1.2.17 + org.slf4j + slf4j-api + 1.7.2 + + + org.slf4j + slf4j-log4j12 + 1.7.2 + test From bf5b83de224a32cb4e94da8cc08311536a6fa97d Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sun, 25 Nov 2012 00:46:48 +0100 Subject: [PATCH 04/88] [New] added log4j.xml configuration file to resources --- src/test/resources/log4j.xml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/test/resources/log4j.xml diff --git a/src/test/resources/log4j.xml b/src/test/resources/log4j.xml new file mode 100644 index 000000000..a35a3c351 --- /dev/null +++ b/src/test/resources/log4j.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From bb9087eba9e82a1c474e65f7b875bc39a56a81ad Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sun, 25 Nov 2012 17:23:43 +0100 Subject: [PATCH 05/88] [Major] refactored ParameterizedElement ParameterizedElement is now the parent for all objects with Parameters. ParameterBag is a sub class of ParameterizedElement. Resource now extends GroupedParameterizedElement which implements the container for ParameterBags. Parameters have been moved to package ch.eitchnet.model.parameter --- .../model/GroupedParameterizedElement.java | 263 ++++++++++++++++++ src/main/java/li/strolch/model/Order.java | 10 +- src/main/java/li/strolch/model/Parameter.java | 6 +- .../java/li/strolch/model/ParameterBag.java | 230 ++------------- .../strolch/model/ParameterizedElement.java | 259 +++++++++-------- src/main/java/li/strolch/model/Resource.java | 4 +- .../{ => parameter}/AbstractParameter.java | 12 +- .../{ => parameter}/BooleanParameter.java | 3 +- .../model/{ => parameter}/DateParameter.java | 3 +- .../model/{ => parameter}/FloatParameter.java | 3 +- .../{ => parameter}/IntegerParameter.java | 3 +- .../model/{ => parameter}/LongParameter.java | 3 +- .../{ => parameter}/StringParameter.java | 3 +- src/test/java/li/strolch/ModelTest.java | 2 +- 14 files changed, 456 insertions(+), 348 deletions(-) create mode 100644 src/main/java/li/strolch/model/GroupedParameterizedElement.java rename src/main/java/li/strolch/model/{ => parameter}/AbstractParameter.java (93%) rename src/main/java/li/strolch/model/{ => parameter}/BooleanParameter.java (96%) rename src/main/java/li/strolch/model/{ => parameter}/DateParameter.java (97%) rename src/main/java/li/strolch/model/{ => parameter}/FloatParameter.java (96%) rename src/main/java/li/strolch/model/{ => parameter}/IntegerParameter.java (96%) rename src/main/java/li/strolch/model/{ => parameter}/LongParameter.java (96%) rename src/main/java/li/strolch/model/{ => parameter}/StringParameter.java (96%) diff --git a/src/main/java/li/strolch/model/GroupedParameterizedElement.java b/src/main/java/li/strolch/model/GroupedParameterizedElement.java new file mode 100644 index 000000000..aa381dd6c --- /dev/null +++ b/src/main/java/li/strolch/model/GroupedParameterizedElement.java @@ -0,0 +1,263 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of li.strolch.model. + * + * li.strolch.model is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * li.strolch.model 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with li.strolch.model. If not, see + * . + */ +package li.strolch.model; + +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import li.strolch.exception.StrolchException; + +import org.dom4j.Element; + +import ch.eitchnet.utils.helper.StringHelper; + +/** + * @author Robert von Burg + * + */ +public abstract class GroupedParameterizedElement extends AbstractStrolchElement { + + private static final long serialVersionUID = 0L; + + protected Map parameterBagMap; + protected String type; + + /** + * Default constructor + */ + protected GroupedParameterizedElement() { + // + } + + /** + * @param id + * @param name + * @param type + */ + protected GroupedParameterizedElement(String id, String name, String type) { + setId(id); + setName(name); + setType(type); + } + + @Override + public String getType() { + return this.type; + } + + /** + * Sets the type of this {@link GroupedParameterizedElement} + * + * @param type + * the type to set + */ + public void setType(String type) { + if (StringHelper.isEmpty(type)) + throw new StrolchException("Type must be set on element " + getLocator()); + + this.type = type; + } + + /** + * Returns the {@link Parameter} with the given key from the {@link ParameterBag} with the given bagKey, or + * null if the {@link Parameter} or the {@link ParameterBag} does not exist + * + * @param bagKey + * the key of the {@link ParameterBag} from which the {@link Parameter} is to be returned + * @param paramKey + * the key of the {@link Parameter} which is to be returned + * + * @return the found {@link Parameter} or null if it was not found + */ + public Parameter getParameter(String bagKey, String paramKey) { + if (this.parameterBagMap == null) + return null; + ParameterBag bag = this.parameterBagMap.get(bagKey); + if (bag == null) + return null; + + return bag.getParameter(paramKey); + } + + /** + * Adds a new {@link Parameter} to the {@link ParameterBag} with the given key + * + * @param bagKey + * the key of the {@link ParameterBag} to which the {@link Parameter} should be added + * @param parameter + * the {@link Parameter} to be added to the {@link ParameterBag} + * + * @throws StrolchException + * if the {@link ParameterBag} does not exist + */ + public void addParameter(String bagKey, Parameter parameter) throws StrolchException { + if (this.parameterBagMap == null) + this.parameterBagMap = new HashMap(); + ParameterBag bag = this.parameterBagMap.get(bagKey); + if (bag == null) { + throw new StrolchException("No parameter bag exists with key " + bagKey); + } + + bag.addParameter(parameter); + } + + /** + * Removes the {@link Parameter} with the given paramKey from the {@link ParameterBag} with the given bagKey + * + * @param bagKey + * the key of the {@link ParameterBag} from which the {@link Parameter} is to be removed + * @param paramKey + * the key of the {@link Parameter} which is to be removed + * + * @return the removed {@link Parameter} or null if it did not exist + */ + public Parameter removeParameter(String bagKey, String paramKey) { + if (this.parameterBagMap == null) + return null; + ParameterBag bag = this.parameterBagMap.get(bagKey); + if (bag == null) + return null; + + return bag.removeParameter(paramKey); + } + + /** + * Returns the {@link ParameterBag} with the given key, or null if it does not exist + * + * @param key + * the key of the {@link ParameterBag} to return + * + * @return the {@link ParameterBag} with the given key, or null if it does not exist + */ + public ParameterBag getParameterBag(String key) { + if (this.parameterBagMap == null) + return null; + return this.parameterBagMap.get(key); + } + + /** + * Adds the given {@link ParameterBag} to this {@link GroupedParameterizedElement} + * + * @param bag + * the {@link ParameterBag} to add + */ + public void addParameterBag(ParameterBag bag) { + if (this.parameterBagMap == null) + this.parameterBagMap = new HashMap(); + this.parameterBagMap.put(bag.getId(), bag); + bag.setParent(this); + } + + /** + * Removes the {@link ParameterBag} with the given key + * + * @param key + * the key of the {@link ParameterBag} to remove + * + * @return the removed {@link ParameterBag}, or null if it does not exist + */ + public ParameterBag removeParameterBag(String key) { + if (this.parameterBagMap == null) + return null; + return this.parameterBagMap.remove(key); + } + + /** + * Returns true if the {@link Parameter} with the given paramKey exists on the {@link ParameterBag} with the + * given bagKey + * + * @param bagKey + * the key of the {@link ParameterBag} on which to find the {@link Parameter} + * @param paramKey + * the key of the {@link Parameter} to be found + * + * @return true if the {@link Parameter} with the given paramKey exists on the {@link ParameterBag} with the + * given bagKey. False is returned if the {@link ParameterBag} does not exist, or the + * {@link Parameter} does not exist on the {@link ParameterBag} + */ + public boolean hasParameter(String bagKey, String paramKey) { + if (this.parameterBagMap == null) + return false; + ParameterBag bag = this.parameterBagMap.get(bagKey); + if (bag == null) + return false; + + return bag.hasParameter(paramKey); + } + + /** + * Returns the {@link Set} of keys for the {@link ParameterBag}s on this {@link GroupedParameterizedElement} + * + * @return the {@link Set} of keys for the {@link ParameterBag}s on this {@link GroupedParameterizedElement} + */ + public Set getParameterBagKeySet() { + if (this.parameterBagMap == null) + return Collections.emptySet(); + return new HashSet(this.parameterBagMap.keySet()); + } + + @Override + @SuppressWarnings("unchecked") + public void fromDom(Element element) { + super.fromDom(element); + + String type = element.attributeValue("Type"); + setType(type); + + List bags = element.elements("ParameterBag"); + for (Element bagElement : bags) { + + ParameterBag bag = new ParameterBag(bagElement); + addParameterBag(bag); + } + } + + @Override + protected void fillElement(Element element) { + super.fillElement(element); + + if (this.parameterBagMap != null) { + for (ParameterBag bag : this.parameterBagMap.values()) { + element.add(bag.toDom()); + } + } + } + + /** + * Fills {@link GroupedParameterizedElement} properties of this clone + * + * @param clone + */ + protected void fillClone(GroupedParameterizedElement clone) { + super.fillClone(clone); + + if (this.parameterBagMap != null) { + for (ParameterBag bag : this.parameterBagMap.values()) { + clone.addParameterBag(bag.getClone()); + } + } + } +} diff --git a/src/main/java/li/strolch/model/Order.java b/src/main/java/li/strolch/model/Order.java index 55e521a86..aa35ab08d 100644 --- a/src/main/java/li/strolch/model/Order.java +++ b/src/main/java/li/strolch/model/Order.java @@ -37,7 +37,7 @@ import org.dom4j.tree.DefaultElement; * @author eitch * */ -public class Order extends ParameterizedElement { +public class Order extends GroupedParameterizedElement { private static final long serialVersionUID = 0L; @@ -50,11 +50,11 @@ public class Order extends ParameterizedElement { * Empty constructor */ public Order() { - super(); + // } /** - * Build an Order + * Default constructor for an {@link Order} * * @param id * @param name @@ -68,7 +68,7 @@ public class Order extends ParameterizedElement { } /** - * Build an Order + * Constructor with date and {@link State} * * @param id * @param name @@ -84,7 +84,7 @@ public class Order extends ParameterizedElement { } /** - * Builds this Order from a Dom4j element + * From DOM Constructor * * @param element */ diff --git a/src/main/java/li/strolch/model/Parameter.java b/src/main/java/li/strolch/model/Parameter.java index bdb7d2580..25fa427c7 100644 --- a/src/main/java/li/strolch/model/Parameter.java +++ b/src/main/java/li/strolch/model/Parameter.java @@ -99,16 +99,16 @@ public interface Parameter extends StrolchElement { public void setUom(String uom); /** - * The {@link ParameterBag} parent to which this {@link Parameter} belongs + * The {@link ParameterizedElement} parent to which this {@link Parameter} belongs * * @return */ - public ParameterBag getParent(); + public ParameterizedElement getParent(); /** * Sets the parent for this {@link Parameter} */ - public void setParent(ParameterBag parent); + public void setParent(ParameterizedElement parent); /** * Returns the interpretation of this {@link Parameter}. The interpretation semantic describes what the value of diff --git a/src/main/java/li/strolch/model/ParameterBag.java b/src/main/java/li/strolch/model/ParameterBag.java index f4b914abf..2c7c290ec 100644 --- a/src/main/java/li/strolch/model/ParameterBag.java +++ b/src/main/java/li/strolch/model/ParameterBag.java @@ -3,7 +3,7 @@ * * All rights reserved. * - * This file is part of li.strolch.model. + * This file is part of the XXX. * * li.strolch.model is free software: you can redistribute * it and/or modify it under the terms of the GNU General Public License as @@ -21,250 +21,56 @@ */ package li.strolch.model; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import li.strolch.exception.StrolchException; -import li.strolch.model.Locator.LocatorBuilder; - import org.dom4j.Element; import org.dom4j.tree.DefaultElement; -import ch.eitchnet.utils.helper.StringHelper; - /** * @author Robert von Burg - * */ -public class ParameterBag extends AbstractStrolchElement { - - private static final long serialVersionUID = 0L; - - protected ParameterizedElement parent; - protected Map> parameterMap; - protected String type; +public class ParameterBag extends ParameterizedElement { + private static final long serialVersionUID = 1L; /** - * Empty constructor + * Constructor for special cases */ public ParameterBag() { - - this.parameterMap = new HashMap>(); + // } /** + * Default constructor + * * @param id * @param name * @param type */ public ParameterBag(String id, String name, String type) { - setId(id); - setName(name); - setType(type); - - this.parameterMap = new HashMap>(); + super(id, name, type); } /** - * @param element + * Constructor from DOM + * + * @param bagElement */ - public ParameterBag(Element element) { - super.fromDom(element); - - String type = element.attributeValue("Type"); - setType(type); - - this.parameterMap = new HashMap>(); - - // add all the parameters - @SuppressWarnings("unchecked") - List parameterElements = element.elements("Parameter"); - for (Object object : parameterElements) { - Element paramElement = (Element) object; - String paramtype = paramElement.attributeValue("Type"); - - if (paramtype.equals(StringParameter.TYPE)) { - StringParameter param = new StringParameter(paramElement); - addParameter(param); - } else if (paramtype.equals(IntegerParameter.TYPE)) { - IntegerParameter param = new IntegerParameter(paramElement); - addParameter(param); - } else if (paramtype.equals(FloatParameter.TYPE)) { - FloatParameter param = new FloatParameter(paramElement); - addParameter(param); - } else if (paramtype.equals(LongParameter.TYPE)) { - LongParameter param = new LongParameter(paramElement); - addParameter(param); - } else if (paramtype.equals(DateParameter.TYPE)) { - DateParameter param = new DateParameter(paramElement); - addParameter(param); - } else if (paramtype.equals(BooleanParameter.TYPE)) { - BooleanParameter param = new BooleanParameter(paramElement); - addParameter(param); - } else { - throw new StrolchException("What kind of parameter is this: " + paramtype); - } - } + public ParameterBag(Element bagElement) { + super.fromDom(bagElement); } @Override - public String getType() { - return this.type; - } - - /** - * Sets the type of this {@link ParameterBag} - * - * @param type - * the type to set - */ - public void setType(String type) { - if (StringHelper.isEmpty(type)) - throw new StrolchException("Type must be set on element " + getLocator()); - - this.type = type; - } - - /** - * Returns this {@link ParameterBag}'s parent - * - * @return the parent - */ - public ParameterizedElement getParent() { - return this.parent; - } - - /** - * Set the parent for this {@link ParameterBag} - * - * @param parent - * the parent to set - */ - public void setParent(ParameterizedElement parent) { - this.parent = parent; - } - - /** - * Returns the {@link Parameter} with the given id, or null if it does not exist - * - * @param key - * the id of the parameter to return - * - * @return the {@link Parameter} with the given id, or null if it does not exist - */ - @SuppressWarnings("unchecked") - public T getParameter(String key) { - return (T) this.parameterMap.get(key); - } - - /** - * Adds the given {@link Parameter} to the {@link ParameterBag} - * - * @param parameter - * the {@link Parameter} to add - */ - public void addParameter(Parameter parameter) { - this.parameterMap.put(parameter.getId(), parameter); - parameter.setParent(this); - } - - /** - * Removes the {@link Parameter} with the given key - * - * @param key - * the key of the {@link Parameter} to remove - * - * @return the removed {@link Parameter}, or null if it does not exist - */ - @SuppressWarnings("unchecked") - public Parameter removeParameter(String key) { - return (Parameter) this.parameterMap.remove(key); - } - - /** - * Returns a list of all the {@link Parameter}s in this {@link ParameterBag} - * - * @return a list of all the {@link Parameter}s in this {@link ParameterBag} - */ - public List> getParameters() { - return new ArrayList>(this.parameterMap.values()); - } - - /** - * Returns true, if the {@link Parameter} exists with the given key, false otherwise - * - * @param key - * the key of the {@link Parameter} to check for - * - * @return true, if the {@link Parameter} exists with the given key, false otherwise - */ - public boolean hasParameter(String key) { - return this.parameterMap.containsKey(key); - } - - /** - * Returns a {@link Set} of all the {@link Parameter} keys in this {@link ParameterBag} - * - * @return a {@link Set} of all the {@link Parameter} keys in this {@link ParameterBag} - */ - public Set getParameterKeySet() { - return new HashSet(this.parameterMap.keySet()); - } - - @Override - protected void fillLocator(LocatorBuilder lb) { - lb.append("ParameterBag").append(this.id); - } - - @Override - public Locator getLocator() { - LocatorBuilder lb = new LocatorBuilder(); - this.parent.fillLocator(lb); - fillLocator(lb); - return lb.build(); + public ParameterBag getClone() { + ParameterBag clone = new ParameterBag(); + super.fillClone(clone); + return clone; } @Override public Element toDom() { Element element = new DefaultElement("ParameterBag"); - fillElement(element); - for (Parameter parameter : this.parameterMap.values()) { - element.add(parameter.toDom()); - } + fillElement(element); return element; } - - @Override - public ParameterBag getClone() { - ParameterBag clone = new ParameterBag(); - - super.fillClone(clone); - - clone.setType(this.type); - - return clone; - } - - @Override - public String toString() { - - StringBuilder builder = new StringBuilder(); - - builder.append("ParameterBag [id="); - builder.append(this.id); - builder.append(", name="); - builder.append(this.name); - builder.append(", type="); - builder.append(this.type); - builder.append("]"); - - return builder.toString(); - } } diff --git a/src/main/java/li/strolch/model/ParameterizedElement.java b/src/main/java/li/strolch/model/ParameterizedElement.java index be339e6d2..1c9585c7e 100644 --- a/src/main/java/li/strolch/model/ParameterizedElement.java +++ b/src/main/java/li/strolch/model/ParameterizedElement.java @@ -21,6 +21,8 @@ */ package li.strolch.model; +import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -28,6 +30,13 @@ import java.util.Map; import java.util.Set; import li.strolch.exception.StrolchException; +import li.strolch.model.Locator.LocatorBuilder; +import li.strolch.model.parameter.BooleanParameter; +import li.strolch.model.parameter.DateParameter; +import li.strolch.model.parameter.FloatParameter; +import li.strolch.model.parameter.IntegerParameter; +import li.strolch.model.parameter.LongParameter; +import li.strolch.model.parameter.StringParameter; import org.dom4j.Element; @@ -35,20 +44,20 @@ import ch.eitchnet.utils.helper.StringHelper; /** * @author Robert von Burg - * */ public abstract class ParameterizedElement extends AbstractStrolchElement { private static final long serialVersionUID = 0L; - protected Map parameterBagMap = new HashMap(); + protected GroupedParameterizedElement parent; + protected Map> parameterMap; protected String type; /** - * Default constructor + * Empty constructor */ protected ParameterizedElement() { - this.parameterBagMap = new HashMap(); + // } /** @@ -56,12 +65,10 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { * @param name * @param type */ - protected ParameterizedElement(String id, String name, String type) { + public ParameterizedElement(String id, String name, String type) { setId(id); setName(name); setType(type); - - this.parameterBagMap = new HashMap(); } @Override @@ -83,140 +90,151 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { } /** - * Returns the {@link Parameter} with the given key from the {@link ParameterBag} with the given bagId, or null if - * the {@link Parameter} or the {@link ParameterBag} does not exist + * Returns this {@link ParameterizedElement}'s parent * - * @param bagKey - * the key of the {@link ParameterBag} from which the {@link Parameter} is to be returned - * @param paramKey - * the key of the {@link Parameter} which is to be returned - * - * @return the found {@link Parameter} or null if it was not found + * @return the parent */ - public Parameter getParameter(String bagKey, String paramKey) { - ParameterBag bag = this.parameterBagMap.get(bagKey); - if (bag == null) - return null; - - return bag.getParameter(paramKey); + public GroupedParameterizedElement getParent() { + return this.parent; } /** - * Adds a new {@link Parameter} to the {@link ParameterBag} with the given key + * Set the parent for this {@link ParameterizedElement} + * + * @param parent + * the parent to set + */ + public void setParent(GroupedParameterizedElement parent) { + this.parent = parent; + } + + /** + * Returns the {@link Parameter} with the given id, or null if it does not exist + * + * @param key + * the id of the parameter to return + * + * @return the {@link Parameter} with the given id, or null if it does not exist + */ + @SuppressWarnings("unchecked") + public T getParameter(String key) { + if (this.parameterMap == null) + return null; + return (T) this.parameterMap.get(key); + } + + /** + * Adds the given {@link Parameter} to the {@link ParameterizedElement} * - * @param bagKey - * the key of the {@link ParameterBag} to which the {@link Parameter} should be added * @param parameter - * the {@link Parameter} to be added to the {@link ParameterBag} - * - * @throws StrolchException - * if the {@link ParameterBag} does not exist + * the {@link Parameter} to add */ - public void addParameter(String bagKey, Parameter parameter) throws StrolchException { - ParameterBag bag = this.parameterBagMap.get(bagKey); - if (bag == null) { - throw new StrolchException("No parameter bag exists with key " + bagKey); - } - - bag.addParameter(parameter); + public void addParameter(Parameter parameter) { + if (this.parameterMap == null) + this.parameterMap = new HashMap>(); + this.parameterMap.put(parameter.getId(), parameter); + parameter.setParent(this); } /** - * Removes the {@link Parameter} with the given paramKey from the {@link ParameterBag} with the given bagKey + * Removes the {@link Parameter} with the given key * - * @param bagKey - * the key of the {@link ParameterBag} from which the {@link Parameter} is to be removed - * @param paramKey - * the key of the {@link Parameter} which is to be removed + * @param key + * the key of the {@link Parameter} to remove * - * @return the removed {@link Parameter} or null if it did not exist + * @return the removed {@link Parameter}, or null if it does not exist */ - public Parameter removeParameter(String bagKey, String paramKey) { - ParameterBag bag = this.parameterBagMap.get(bagKey); - if (bag == null) + @SuppressWarnings("unchecked") + public Parameter removeParameter(String key) { + if (this.parameterMap == null) return null; - - return bag.removeParameter(paramKey); + return (Parameter) this.parameterMap.remove(key); } /** - * Returns the {@link ParameterBag} with the given key, or null if it does not exist + * Returns a list of all the {@link Parameter}s in this {@link ParameterizedElement} + * + * @return a list of all the {@link Parameter}s in this {@link ParameterizedElement} + */ + public List> getParameters() { + if (this.parameterMap == null) + return Collections.emptyList(); + return new ArrayList>(this.parameterMap.values()); + } + + /** + * Returns true, if the {@link Parameter} exists with the given key, false otherwise * * @param key - * the key of the {@link ParameterBag} to return + * the key of the {@link Parameter} to check for * - * @return the {@link ParameterBag} with the given key, or null if it does not exist + * @return true, if the {@link Parameter} exists with the given key, false otherwise */ - public ParameterBag getParameterBag(String key) { - return this.parameterBagMap.get(key); - } - - /** - * Adds the given {@link ParameterBag} to this {@link ParameterizedElement} - * - * @param bag - * the {@link ParameterBag} to add - */ - public void addParameterBag(ParameterBag bag) { - this.parameterBagMap.put(bag.getId(), bag); - bag.setParent(this); - } - - /** - * Removes the {@link ParameterBag} with the given key - * - * @param key - * the key of the {@link ParameterBag} to remove - * - * @return the removed {@link ParameterBag}, or null if it does not exist - */ - public ParameterBag removeParameterBag(String key) { - return this.parameterBagMap.remove(key); - } - - /** - * Returns true if the {@link Parameter} with the given paramKey exists on the {@link ParameterBag} with the given - * bagKey - * - * @param bagKey - * the key of the {@link ParameterBag} on which to find the {@link Parameter} - * @param paramKey - * the key of the {@link Parameter} to be found - * - * @return true if the {@link Parameter} with the given paramKey exists on the {@link ParameterBag} with the given - * bagKey. False is returned if the {@link ParameterBag} does not exist, or the {@link Parameter} does not - * exist on the {@link ParameterBag} - */ - public boolean hasParameter(String bagKey, String paramKey) { - ParameterBag bag = this.parameterBagMap.get(bagKey); - if (bag == null) + public boolean hasParameter(String key) { + if (this.parameterMap == null) return false; - - return bag.hasParameter(paramKey); + return this.parameterMap.containsKey(key); } /** - * Returns the {@link Set} of keys for the {@link ParameterBag}s on this {@link ParameterizedElement} + * Returns a {@link Set} of all the {@link Parameter} keys in this {@link ParameterizedElement} * - * @return the {@link Set} of keys for the {@link ParameterBag}s on this {@link ParameterizedElement} + * @return a {@link Set} of all the {@link Parameter} keys in this {@link ParameterizedElement} */ - public Set getParameterBagKeySet() { - return new HashSet(this.parameterBagMap.keySet()); + public Set getParameterKeySet() { + if (this.parameterMap == null) + return Collections.emptySet(); + return new HashSet(this.parameterMap.keySet()); } @Override - @SuppressWarnings("unchecked") - public void fromDom(Element element) { + public void fillLocator(LocatorBuilder lb) { + lb.append("ParameterizedElement").append(this.id); + } + + @Override + public Locator getLocator() { + LocatorBuilder lb = new LocatorBuilder(); + this.parent.fillLocator(lb); + fillLocator(lb); + return lb.build(); + } + + @Override + protected void fromDom(Element element) { super.fromDom(element); String type = element.attributeValue("Type"); setType(type); - List bags = element.elements("ParameterBag"); - for (Element bagElement : bags) { + // add all the parameters + @SuppressWarnings("unchecked") + List parameterElements = element.elements("Parameter"); + for (Object object : parameterElements) { + Element paramElement = (Element) object; + String paramtype = paramElement.attributeValue("Type"); - ParameterBag bag = new ParameterBag(bagElement); - addParameterBag(bag); + if (paramtype.equals(StringParameter.TYPE)) { + StringParameter param = new StringParameter(paramElement); + addParameter(param); + } else if (paramtype.equals(IntegerParameter.TYPE)) { + IntegerParameter param = new IntegerParameter(paramElement); + addParameter(param); + } else if (paramtype.equals(FloatParameter.TYPE)) { + FloatParameter param = new FloatParameter(paramElement); + addParameter(param); + } else if (paramtype.equals(LongParameter.TYPE)) { + LongParameter param = new LongParameter(paramElement); + addParameter(param); + } else if (paramtype.equals(DateParameter.TYPE)) { + DateParameter param = new DateParameter(paramElement); + addParameter(param); + } else if (paramtype.equals(BooleanParameter.TYPE)) { + BooleanParameter param = new BooleanParameter(paramElement); + addParameter(param); + } else { + throw new StrolchException("What kind of parameter is this: " + paramtype); + } } } @@ -224,21 +242,32 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { protected void fillElement(Element element) { super.fillElement(element); - for (ParameterBag bag : this.parameterBagMap.values()) { - element.add(bag.toDom()); + if (this.parameterMap != null) { + for (Parameter parameter : this.parameterMap.values()) { + element.add(parameter.toDom()); + } } } - /** - * Fills {@link ParameterizedElement} properties of this clone - * - * @param clone - */ - protected void fillClone(ParameterizedElement clone) { + @Override + protected void fillClone(StrolchElement clone) { super.fillClone(clone); + ((ParameterizedElement) clone).setType(this.type); + } - for (ParameterBag bag : this.parameterBagMap.values()) { - clone.addParameterBag(bag.getClone()); - } + @Override + public String toString() { + + StringBuilder builder = new StringBuilder(); + + builder.append("ParameterizedElement [id="); + builder.append(this.id); + builder.append(", name="); + builder.append(this.name); + builder.append(", type="); + builder.append(this.type); + builder.append("]"); + + return builder.toString(); } } diff --git a/src/main/java/li/strolch/model/Resource.java b/src/main/java/li/strolch/model/Resource.java index 288f666e7..41e920777 100644 --- a/src/main/java/li/strolch/model/Resource.java +++ b/src/main/java/li/strolch/model/Resource.java @@ -30,7 +30,7 @@ import org.dom4j.tree.DefaultElement; * @author Robert von Burg * */ -public class Resource extends ParameterizedElement { +public class Resource extends GroupedParameterizedElement { private static final long serialVersionUID = 0L; public static final String PREFIX_RESOURCE = "ResourcePrefix"; @@ -63,7 +63,7 @@ public class Resource extends ParameterizedElement { public Element toDom() { Element element = new DefaultElement("Resource"); - fromDom(element); + fillElement(element); return element; } diff --git a/src/main/java/li/strolch/model/AbstractParameter.java b/src/main/java/li/strolch/model/parameter/AbstractParameter.java similarity index 93% rename from src/main/java/li/strolch/model/AbstractParameter.java rename to src/main/java/li/strolch/model/parameter/AbstractParameter.java index bfd4cf2d7..208254e39 100644 --- a/src/main/java/li/strolch/model/AbstractParameter.java +++ b/src/main/java/li/strolch/model/parameter/AbstractParameter.java @@ -19,10 +19,14 @@ * along with li.strolch.model. If not, see * . */ -package li.strolch.model; +package li.strolch.model.parameter; import li.strolch.exception.StrolchException; +import li.strolch.model.AbstractStrolchElement; +import li.strolch.model.Locator; import li.strolch.model.Locator.LocatorBuilder; +import li.strolch.model.Parameter; +import li.strolch.model.ParameterizedElement; import org.dom4j.Element; import org.dom4j.tree.DefaultElement; @@ -42,7 +46,7 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem protected String interpretation; protected String uom; - protected ParameterBag parent; + protected ParameterizedElement parent; @Override public boolean isHidden() { @@ -83,12 +87,12 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem } @Override - public ParameterBag getParent() { + public ParameterizedElement getParent() { return this.parent; } @Override - public void setParent(ParameterBag parent) { + public void setParent(ParameterizedElement parent) { this.parent = parent; } diff --git a/src/main/java/li/strolch/model/BooleanParameter.java b/src/main/java/li/strolch/model/parameter/BooleanParameter.java similarity index 96% rename from src/main/java/li/strolch/model/BooleanParameter.java rename to src/main/java/li/strolch/model/parameter/BooleanParameter.java index a1be83d81..bb0f05215 100644 --- a/src/main/java/li/strolch/model/BooleanParameter.java +++ b/src/main/java/li/strolch/model/parameter/BooleanParameter.java @@ -19,9 +19,10 @@ * along with li.strolch.model. If not, see * . */ -package li.strolch.model; +package li.strolch.model.parameter; import li.strolch.exception.StrolchException; +import li.strolch.model.Parameter; import org.dom4j.Element; diff --git a/src/main/java/li/strolch/model/DateParameter.java b/src/main/java/li/strolch/model/parameter/DateParameter.java similarity index 97% rename from src/main/java/li/strolch/model/DateParameter.java rename to src/main/java/li/strolch/model/parameter/DateParameter.java index 84a2e6986..e0c677934 100644 --- a/src/main/java/li/strolch/model/DateParameter.java +++ b/src/main/java/li/strolch/model/parameter/DateParameter.java @@ -19,11 +19,12 @@ * along with li.strolch.model. If not, see * . */ -package li.strolch.model; +package li.strolch.model.parameter; import java.text.DateFormat; import li.strolch.exception.StrolchException; +import li.strolch.model.Parameter; import org.dom4j.Element; diff --git a/src/main/java/li/strolch/model/FloatParameter.java b/src/main/java/li/strolch/model/parameter/FloatParameter.java similarity index 96% rename from src/main/java/li/strolch/model/FloatParameter.java rename to src/main/java/li/strolch/model/parameter/FloatParameter.java index 6986e8c17..903eadc88 100644 --- a/src/main/java/li/strolch/model/FloatParameter.java +++ b/src/main/java/li/strolch/model/parameter/FloatParameter.java @@ -19,9 +19,10 @@ * along with li.strolch.model. If not, see * . */ -package li.strolch.model; +package li.strolch.model.parameter; import li.strolch.exception.StrolchException; +import li.strolch.model.Parameter; import org.dom4j.Element; diff --git a/src/main/java/li/strolch/model/IntegerParameter.java b/src/main/java/li/strolch/model/parameter/IntegerParameter.java similarity index 96% rename from src/main/java/li/strolch/model/IntegerParameter.java rename to src/main/java/li/strolch/model/parameter/IntegerParameter.java index 83ccc3be9..a2fcc7414 100644 --- a/src/main/java/li/strolch/model/IntegerParameter.java +++ b/src/main/java/li/strolch/model/parameter/IntegerParameter.java @@ -19,9 +19,10 @@ * along with li.strolch.model. If not, see * . */ -package li.strolch.model; +package li.strolch.model.parameter; import li.strolch.exception.StrolchException; +import li.strolch.model.Parameter; import org.dom4j.Element; diff --git a/src/main/java/li/strolch/model/LongParameter.java b/src/main/java/li/strolch/model/parameter/LongParameter.java similarity index 96% rename from src/main/java/li/strolch/model/LongParameter.java rename to src/main/java/li/strolch/model/parameter/LongParameter.java index 9edb02709..1f4d8a0a6 100644 --- a/src/main/java/li/strolch/model/LongParameter.java +++ b/src/main/java/li/strolch/model/parameter/LongParameter.java @@ -19,9 +19,10 @@ * along with li.strolch.model. If not, see * . */ -package li.strolch.model; +package li.strolch.model.parameter; import li.strolch.exception.StrolchException; +import li.strolch.model.Parameter; import org.dom4j.Element; diff --git a/src/main/java/li/strolch/model/StringParameter.java b/src/main/java/li/strolch/model/parameter/StringParameter.java similarity index 96% rename from src/main/java/li/strolch/model/StringParameter.java rename to src/main/java/li/strolch/model/parameter/StringParameter.java index 917791faf..6aa7ef2dc 100644 --- a/src/main/java/li/strolch/model/StringParameter.java +++ b/src/main/java/li/strolch/model/parameter/StringParameter.java @@ -19,9 +19,10 @@ * along with li.strolch.model. If not, see * . */ -package li.strolch.model; +package li.strolch.model.parameter; import li.strolch.exception.StrolchException; +import li.strolch.model.Parameter; import org.dom4j.Element; diff --git a/src/test/java/li/strolch/ModelTest.java b/src/test/java/li/strolch/ModelTest.java index 7a6e5d7f0..f0970ff55 100644 --- a/src/test/java/li/strolch/ModelTest.java +++ b/src/test/java/li/strolch/ModelTest.java @@ -1,11 +1,11 @@ package li.strolch; -import li.strolch.model.FloatParameter; import li.strolch.model.Order; import li.strolch.model.Parameter; import li.strolch.model.ParameterBag; import li.strolch.model.Resource; import li.strolch.model.State; +import li.strolch.model.parameter.FloatParameter; import org.junit.Test; From 054aa7706e05dbffbaf1e368f25360364bd44612 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sun, 25 Nov 2012 17:26:28 +0100 Subject: [PATCH 06/88] [New] Created ListParameter interface ListParameter contains methods to handle single values for parameters of lists of values and also is a marker interface for list parameters. StringListParameter is the first implementation --- .../model/parameter/ListParameter.java | 51 ++++++++++ .../model/parameter/StringListParameter.java | 94 +++++++++++++++++++ 2 files changed, 145 insertions(+) create mode 100644 src/main/java/li/strolch/model/parameter/ListParameter.java create mode 100644 src/main/java/li/strolch/model/parameter/StringListParameter.java diff --git a/src/main/java/li/strolch/model/parameter/ListParameter.java b/src/main/java/li/strolch/model/parameter/ListParameter.java new file mode 100644 index 000000000..f94da4137 --- /dev/null +++ b/src/main/java/li/strolch/model/parameter/ListParameter.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.parameter; + +import java.util.List; + +import li.strolch.model.Parameter; + +/** + * @author Robert von Burg + * + */ +public interface ListParameter extends Parameter> { + + /** + * Adds a single value to the {@link List} of values + * + * @param value + * the value to add + */ + public abstract void addValue(E value); + + /** + * Removes a single value from the {@link List} of values + * + * @param value + * the value to remove + * + * @return true if the value was removed, false if it did not exist + */ + public abstract boolean removeValue(E value); +} diff --git a/src/main/java/li/strolch/model/parameter/StringListParameter.java b/src/main/java/li/strolch/model/parameter/StringListParameter.java new file mode 100644 index 000000000..51c9df022 --- /dev/null +++ b/src/main/java/li/strolch/model/parameter/StringListParameter.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the li.strolch.model. + * + * li.strolch.model is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * li.strolch.model 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with li.strolch.model. If not, see + * . + */ +package li.strolch.model.parameter; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import li.strolch.model.StrolchElement; + +/** + * @author Robert von Burg + */ +public class StringListParameter extends AbstractParameter> implements ListParameter { + + public static final String TYPE = "StringList"; + private static final long serialVersionUID = 1L; + + protected List value; + + @Override + public String getValueAsString() { + if (this.value.isEmpty()) + return ""; + + StringBuilder sb = new StringBuilder(); + Iterator iter = this.value.iterator(); + while (iter.hasNext()) { + + sb.append(iter.next()); + + if (iter.hasNext()) + sb.append(";"); + } + + return sb.toString(); + } + + @Override + public List getValue() { + return new ArrayList(this.value); + } + + @Override + public void setValue(List value) { + this.value.clear(); + this.value.addAll(value); + } + + @Override + public void addValue(String value) { + this.value.add(value); + } + + @Override + public boolean removeValue(String value) { + return this.value.remove(value); + } + + @Override + public String getType() { + return TYPE; + } + + @Override + public StrolchElement getClone() { + StringListParameter clone = new StringListParameter(); + + super.fillClone(clone); + + clone.setValue(this.value); + + return clone; + } +} From 6b5860c05fc8149baca4eb0dc2be9dfb84e2c02b Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sun, 25 Nov 2012 18:08:56 +0100 Subject: [PATCH 07/88] [Minor] code cleanup, and fixes in StringListParameter --- .../strolch/model/AbstractStrolchElement.java | 13 +++++ .../model/GroupedParameterizedElement.java | 21 ++++---- src/main/java/li/strolch/model/Locator.java | 3 ++ src/main/java/li/strolch/model/Order.java | 6 +-- .../java/li/strolch/model/ParameterBag.java | 4 +- .../strolch/model/ParameterizedElement.java | 4 +- src/main/java/li/strolch/model/Resource.java | 10 ++-- src/main/java/li/strolch/model/State.java | 12 +++-- .../model/parameter/AbstractParameter.java | 17 +++++++ .../model/parameter/BooleanParameter.java | 28 +++++----- .../model/parameter/DateParameter.java | 27 +++++----- .../model/parameter/FloatParameter.java | 27 +++++----- .../model/parameter/IntegerParameter.java | 28 +++++----- .../model/parameter/ListParameter.java | 4 +- .../model/parameter/LongParameter.java | 27 +++++----- .../model/parameter/StringListParameter.java | 51 +++++++++++++++++++ .../model/parameter/StringParameter.java | 25 +++++---- 17 files changed, 207 insertions(+), 100 deletions(-) diff --git a/src/main/java/li/strolch/model/AbstractStrolchElement.java b/src/main/java/li/strolch/model/AbstractStrolchElement.java index 464c0b01a..3bff1ca58 100644 --- a/src/main/java/li/strolch/model/AbstractStrolchElement.java +++ b/src/main/java/li/strolch/model/AbstractStrolchElement.java @@ -44,6 +44,19 @@ public abstract class AbstractStrolchElement implements StrolchElement { // } + /** + * Default constructor + * + * @param id + * id of this {@link StrolchElement} + * @param name + * name of this {@link StrolchElement} + */ + public AbstractStrolchElement(String id, String name) { + setId(id); + setName(name); + } + @Override public long getDbid() { return this.dbid; diff --git a/src/main/java/li/strolch/model/GroupedParameterizedElement.java b/src/main/java/li/strolch/model/GroupedParameterizedElement.java index aa381dd6c..919756ff0 100644 --- a/src/main/java/li/strolch/model/GroupedParameterizedElement.java +++ b/src/main/java/li/strolch/model/GroupedParameterizedElement.java @@ -46,20 +46,21 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement protected String type; /** - * Default constructor + * Empty constructor */ protected GroupedParameterizedElement() { // } /** + * Default Constructor + * * @param id * @param name * @param type */ protected GroupedParameterizedElement(String id, String name, String type) { - setId(id); - setName(name); + super(id, name); setType(type); } @@ -82,8 +83,8 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement } /** - * Returns the {@link Parameter} with the given key from the {@link ParameterBag} with the given bagKey, or - * null if the {@link Parameter} or the {@link ParameterBag} does not exist + * Returns the {@link Parameter} with the given key from the {@link ParameterBag} with the given bagKey, or null if + * the {@link Parameter} or the {@link ParameterBag} does not exist * * @param bagKey * the key of the {@link ParameterBag} from which the {@link Parameter} is to be returned @@ -186,17 +187,17 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement } /** - * Returns true if the {@link Parameter} with the given paramKey exists on the {@link ParameterBag} with the - * given bagKey + * Returns true if the {@link Parameter} with the given paramKey exists on the {@link ParameterBag} with the given + * bagKey * * @param bagKey * the key of the {@link ParameterBag} on which to find the {@link Parameter} * @param paramKey * the key of the {@link Parameter} to be found * - * @return true if the {@link Parameter} with the given paramKey exists on the {@link ParameterBag} with the - * given bagKey. False is returned if the {@link ParameterBag} does not exist, or the - * {@link Parameter} does not exist on the {@link ParameterBag} + * @return true if the {@link Parameter} with the given paramKey exists on the {@link ParameterBag} with the given + * bagKey. False is returned if the {@link ParameterBag} does not exist, or the {@link Parameter} does not + * exist on the {@link ParameterBag} */ public boolean hasParameter(String bagKey, String paramKey) { if (this.parameterBagMap == null) diff --git a/src/main/java/li/strolch/model/Locator.java b/src/main/java/li/strolch/model/Locator.java index 3942c6aab..893440eb7 100644 --- a/src/main/java/li/strolch/model/Locator.java +++ b/src/main/java/li/strolch/model/Locator.java @@ -55,6 +55,9 @@ public class Locator { */ public static final String PATH_SEPARATOR = "/"; + /** + * {@link List} of path elements, with the first being the top level or root element + */ private final List pathElements; /** diff --git a/src/main/java/li/strolch/model/Order.java b/src/main/java/li/strolch/model/Order.java index aa35ab08d..3e3d880cd 100644 --- a/src/main/java/li/strolch/model/Order.java +++ b/src/main/java/li/strolch/model/Order.java @@ -54,7 +54,7 @@ public class Order extends GroupedParameterizedElement { } /** - * Default constructor for an {@link Order} + * Default Constructor * * @param id * @param name @@ -68,7 +68,7 @@ public class Order extends GroupedParameterizedElement { } /** - * Constructor with date and {@link State} + * Extended Constructor for date and {@link State} * * @param id * @param name @@ -84,7 +84,7 @@ public class Order extends GroupedParameterizedElement { } /** - * From DOM Constructor + * DOM Constructor * * @param element */ diff --git a/src/main/java/li/strolch/model/ParameterBag.java b/src/main/java/li/strolch/model/ParameterBag.java index 2c7c290ec..b110fc3af 100644 --- a/src/main/java/li/strolch/model/ParameterBag.java +++ b/src/main/java/li/strolch/model/ParameterBag.java @@ -31,7 +31,7 @@ public class ParameterBag extends ParameterizedElement { private static final long serialVersionUID = 1L; /** - * Constructor for special cases + * Empty Constructor */ public ParameterBag() { // @@ -49,7 +49,7 @@ public class ParameterBag extends ParameterizedElement { } /** - * Constructor from DOM + * DOM Constructor * * @param bagElement */ diff --git a/src/main/java/li/strolch/model/ParameterizedElement.java b/src/main/java/li/strolch/model/ParameterizedElement.java index 1c9585c7e..c0f7e6638 100644 --- a/src/main/java/li/strolch/model/ParameterizedElement.java +++ b/src/main/java/li/strolch/model/ParameterizedElement.java @@ -54,13 +54,15 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { protected String type; /** - * Empty constructor + * Empty Constructor */ protected ParameterizedElement() { // } /** + * Default Constructor + * * @param id * @param name * @param type diff --git a/src/main/java/li/strolch/model/Resource.java b/src/main/java/li/strolch/model/Resource.java index 41e920777..09d1718d9 100644 --- a/src/main/java/li/strolch/model/Resource.java +++ b/src/main/java/li/strolch/model/Resource.java @@ -28,7 +28,6 @@ import org.dom4j.tree.DefaultElement; /** * @author Robert von Burg - * */ public class Resource extends GroupedParameterizedElement { @@ -37,13 +36,14 @@ public class Resource extends GroupedParameterizedElement { /** * Empty constructor - * */ - protected Resource() { - super(); + public Resource() { + // } /** + * Default constructor + * * @param id * @param name * @param type @@ -53,6 +53,8 @@ public class Resource extends GroupedParameterizedElement { } /** + * DOM Constructor + * * @param element */ public Resource(Element element) { diff --git a/src/main/java/li/strolch/model/State.java b/src/main/java/li/strolch/model/State.java index c192191f7..6fc4b0b99 100644 --- a/src/main/java/li/strolch/model/State.java +++ b/src/main/java/li/strolch/model/State.java @@ -23,21 +23,23 @@ package li.strolch.model; /** * @author Robert von Burg - * */ public enum State { - CREATED("Created"), - OPEN("Open"), - EXECUTION("Execution"), - CLOSED("Closed"); + CREATED("Created"), OPEN("Open"), EXECUTION("Execution"), CLOSED("Closed"); private String state; + /** + * @param state + */ private State(String state) { this.state = state; } + /** + * @return + */ public String getStateName() { return this.state; } diff --git a/src/main/java/li/strolch/model/parameter/AbstractParameter.java b/src/main/java/li/strolch/model/parameter/AbstractParameter.java index 208254e39..0430c4c35 100644 --- a/src/main/java/li/strolch/model/parameter/AbstractParameter.java +++ b/src/main/java/li/strolch/model/parameter/AbstractParameter.java @@ -48,6 +48,23 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem protected ParameterizedElement parent; + /** + * Empty constructor + */ + protected AbstractParameter() { + // + } + + /** + * Default constructor + * + * @param id + * @param name + */ + public AbstractParameter(String id, String name) { + super(id, name); + } + @Override public boolean isHidden() { return this.hidden; diff --git a/src/main/java/li/strolch/model/parameter/BooleanParameter.java b/src/main/java/li/strolch/model/parameter/BooleanParameter.java index bb0f05215..50561f33d 100644 --- a/src/main/java/li/strolch/model/parameter/BooleanParameter.java +++ b/src/main/java/li/strolch/model/parameter/BooleanParameter.java @@ -35,18 +35,31 @@ public class BooleanParameter extends AbstractParameter { public static final String TYPE = "Boolean"; private static final long serialVersionUID = 0L; - + private Boolean value = Boolean.FALSE; /** * Empty constructor - * */ public BooleanParameter() { // } /** + * Default constructors + * + * @param id + * @param name + * @param value + */ + public BooleanParameter(String id, String name, Boolean value) { + super(id, name); + setValue(value); + } + + /** + * DOM Constructor + * * @param element */ public BooleanParameter(Element element) { @@ -60,17 +73,6 @@ public class BooleanParameter extends AbstractParameter { setValue(Boolean.valueOf(valueS)); } - /** - * @param id - * @param name - * @param value - */ - public BooleanParameter(String id, String name, Boolean value) { - setId(id); - setName(name); - setValue(value); - } - @Override public String getValueAsString() { return this.value.toString(); diff --git a/src/main/java/li/strolch/model/parameter/DateParameter.java b/src/main/java/li/strolch/model/parameter/DateParameter.java index e0c677934..d40d17d89 100644 --- a/src/main/java/li/strolch/model/parameter/DateParameter.java +++ b/src/main/java/li/strolch/model/parameter/DateParameter.java @@ -42,13 +42,27 @@ public class DateParameter extends AbstractParameter { private Long value; /** - * Default constructor + * Empty constructor */ public DateParameter() { // } /** + * Default Constructor + * + * @param id + * @param name + * @param value + */ + public DateParameter(String id, String name, Long value) { + super(id, name); + setValue(value); + } + + /** + * DOM Constructor + * * @param element */ public DateParameter(Element element) { @@ -62,17 +76,6 @@ public class DateParameter extends AbstractParameter { setValue(Long.valueOf(valueS)); } - /** - * @param id - * @param name - * @param value - */ - public DateParameter(String id, String name, Long value) { - setId(id); - setName(name); - setValue(value); - } - @Override public String getValueAsString() { // TODO the format should be globally configured diff --git a/src/main/java/li/strolch/model/parameter/FloatParameter.java b/src/main/java/li/strolch/model/parameter/FloatParameter.java index 903eadc88..07a22dda9 100644 --- a/src/main/java/li/strolch/model/parameter/FloatParameter.java +++ b/src/main/java/li/strolch/model/parameter/FloatParameter.java @@ -41,13 +41,27 @@ public class FloatParameter extends AbstractParameter { /** * Empty constructor - * */ public FloatParameter() { // } /** + * Default constructor + * + * @param id + * @param name + * @param value + */ + public FloatParameter(String id, String name, Double value) { + super(id, name); + + setValue(value); + } + + /** + * DOM Constructor + * * @param element */ public FloatParameter(Element element) { @@ -61,17 +75,6 @@ public class FloatParameter extends AbstractParameter { setValue(Double.valueOf(valueS)); } - /** - * @param id - * @param name - * @param value - */ - public FloatParameter(String id, String name, Double value) { - setId(id); - setName(name); - setValue(value); - } - @Override public String getValueAsString() { return Double.toString(this.value); diff --git a/src/main/java/li/strolch/model/parameter/IntegerParameter.java b/src/main/java/li/strolch/model/parameter/IntegerParameter.java index a2fcc7414..ce3529af1 100644 --- a/src/main/java/li/strolch/model/parameter/IntegerParameter.java +++ b/src/main/java/li/strolch/model/parameter/IntegerParameter.java @@ -40,14 +40,27 @@ public class IntegerParameter extends AbstractParameter { private Integer value = Integer.MAX_VALUE; /** - * Default constructor - * + * Empty constructor */ public IntegerParameter() { // } /** + * Default constructor + * + * @param id + * @param name + * @param value + */ + public IntegerParameter(String id, String name, Integer value) { + super(id, name); + setValue(value); + } + + /** + * DOM Constructor + * * @param element */ public IntegerParameter(Element element) { @@ -61,17 +74,6 @@ public class IntegerParameter extends AbstractParameter { setValue(Integer.valueOf(valueS)); } - /** - * @param id - * @param name - * @param value - */ - public IntegerParameter(String id, String name, Integer value) { - setId(id); - setName(name); - setValue(value); - } - @Override public String getType() { return IntegerParameter.TYPE; diff --git a/src/main/java/li/strolch/model/parameter/ListParameter.java b/src/main/java/li/strolch/model/parameter/ListParameter.java index f94da4137..8f3bf50bd 100644 --- a/src/main/java/li/strolch/model/parameter/ListParameter.java +++ b/src/main/java/li/strolch/model/parameter/ListParameter.java @@ -37,7 +37,7 @@ public interface ListParameter extends Parameter> { * @param value * the value to add */ - public abstract void addValue(E value); + public void addValue(E value); /** * Removes a single value from the {@link List} of values @@ -47,5 +47,5 @@ public interface ListParameter extends Parameter> { * * @return true if the value was removed, false if it did not exist */ - public abstract boolean removeValue(E value); + public boolean removeValue(E value); } diff --git a/src/main/java/li/strolch/model/parameter/LongParameter.java b/src/main/java/li/strolch/model/parameter/LongParameter.java index 1f4d8a0a6..4cf27a145 100644 --- a/src/main/java/li/strolch/model/parameter/LongParameter.java +++ b/src/main/java/li/strolch/model/parameter/LongParameter.java @@ -40,13 +40,27 @@ public class LongParameter extends AbstractParameter { protected Long value; /** - * Default constructor + * Empty constructor */ public LongParameter() { // } /** + * Default constructor + * + * @param id + * @param name + * @param value + */ + public LongParameter(String id, String name, Long value) { + super(id, name); + setValue(Long.valueOf(value)); + } + + /** + * DOM Constructor + * * @param element */ public LongParameter(Element element) { @@ -60,17 +74,6 @@ public class LongParameter extends AbstractParameter { setValue(Long.valueOf(valueS)); } - /** - * @param id - * @param name - * @param value - */ - public LongParameter(String id, String name, Long value) { - setId(id); - setName(name); - setValue(Long.valueOf(value)); - } - @Override public String getValueAsString() { return this.value.toString(); diff --git a/src/main/java/li/strolch/model/parameter/StringListParameter.java b/src/main/java/li/strolch/model/parameter/StringListParameter.java index 51c9df022..07eccb26e 100644 --- a/src/main/java/li/strolch/model/parameter/StringListParameter.java +++ b/src/main/java/li/strolch/model/parameter/StringListParameter.java @@ -22,11 +22,18 @@ package li.strolch.model.parameter; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.Iterator; import java.util.List; +import li.strolch.exception.StrolchException; import li.strolch.model.StrolchElement; +import org.dom4j.Element; + +import ch.eitchnet.utils.helper.StringHelper; + /** * @author Robert von Burg */ @@ -37,6 +44,50 @@ public class StringListParameter extends AbstractParameter> impleme protected List value; + /** + * Empty constructor + */ + public StringListParameter() { + // + } + + /** + * Default constructor + * + * @param id + * @param name + * @param value + */ + public StringListParameter(String id, String name, List value) { + super(id, name); + + setValue(value); + } + + /** + * DOM Constructor + * + * @param element + */ + public StringListParameter(Element element) { + super.fromDom(element); + + String valueS = element.attributeValue("Value"); + if (StringHelper.isEmpty(valueS)) { + throw new StrolchException("No value defined for " + this.id); + } + + setValue(parse(valueS)); + } + + private List parse(String value) { + if (value.isEmpty()) + return Collections.emptyList(); + + String[] valueArr = value.split(";"); + return Arrays.asList(valueArr); + } + @Override public String getValueAsString() { if (this.value.isEmpty()) diff --git a/src/main/java/li/strolch/model/parameter/StringParameter.java b/src/main/java/li/strolch/model/parameter/StringParameter.java index 6aa7ef2dc..ed8fd3a54 100644 --- a/src/main/java/li/strolch/model/parameter/StringParameter.java +++ b/src/main/java/li/strolch/model/parameter/StringParameter.java @@ -48,6 +48,20 @@ public class StringParameter extends AbstractParameter { } /** + * Default constructor + * + * @param id + * @param name + * @param value + */ + public StringParameter(String id, String name, String value) { + super(id, name); + setValue(value); + } + + /** + * DOM Constructor + * * @param element */ public StringParameter(Element element) { @@ -61,17 +75,6 @@ public class StringParameter extends AbstractParameter { setValue(valueS); } - /** - * @param id - * @param name - * @param value - */ - public StringParameter(String id, String name, String value) { - setId(id); - setName(name); - setValue(value); - } - @Override public String getType() { return StringParameter.TYPE; From c324b22adf0d5b808f1101f1933d10a072397c99 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 30 Nov 2012 18:57:54 +0100 Subject: [PATCH 08/88] [New] Implemented Model tests Added tests to test creating Resource and Order and each has a ParameterBag. The bag has all kinds of Parameters added and each is tested that it exists and that the right value is stored --- .../model/GroupedParameterizedElement.java | 1 + .../strolch/model/ParameterizedElement.java | 1 + .../model/parameter/AbstractParameter.java | 1 - .../model/parameter/BooleanParameter.java | 1 - .../model/parameter/DateParameter.java | 2 - .../model/parameter/FloatParameter.java | 1 - .../model/parameter/IntegerParameter.java | 1 - .../model/parameter/ListParameter.java | 1 - .../model/parameter/LongParameter.java | 1 - .../model/{ => parameter}/Parameter.java | 7 +- .../model/parameter/StringListParameter.java | 3 + .../model/parameter/StringParameter.java | 1 - src/test/java/li/strolch/ModelTest.java | 39 ---- .../java/li/strolch/test/model/ModelTest.java | 84 +++++++++ .../strolch/test/model/ModelTestHelper.java | 178 ++++++++++++++++++ 15 files changed, 273 insertions(+), 49 deletions(-) rename src/main/java/li/strolch/model/{ => parameter}/Parameter.java (95%) delete mode 100644 src/test/java/li/strolch/ModelTest.java create mode 100644 src/test/java/li/strolch/test/model/ModelTest.java create mode 100644 src/test/java/li/strolch/test/model/ModelTestHelper.java diff --git a/src/main/java/li/strolch/model/GroupedParameterizedElement.java b/src/main/java/li/strolch/model/GroupedParameterizedElement.java index 919756ff0..e5cf3bd29 100644 --- a/src/main/java/li/strolch/model/GroupedParameterizedElement.java +++ b/src/main/java/li/strolch/model/GroupedParameterizedElement.java @@ -29,6 +29,7 @@ import java.util.Map; import java.util.Set; import li.strolch.exception.StrolchException; +import li.strolch.model.parameter.Parameter; import org.dom4j.Element; diff --git a/src/main/java/li/strolch/model/ParameterizedElement.java b/src/main/java/li/strolch/model/ParameterizedElement.java index c0f7e6638..21ed6feb5 100644 --- a/src/main/java/li/strolch/model/ParameterizedElement.java +++ b/src/main/java/li/strolch/model/ParameterizedElement.java @@ -36,6 +36,7 @@ import li.strolch.model.parameter.DateParameter; import li.strolch.model.parameter.FloatParameter; import li.strolch.model.parameter.IntegerParameter; import li.strolch.model.parameter.LongParameter; +import li.strolch.model.parameter.Parameter; import li.strolch.model.parameter.StringParameter; import org.dom4j.Element; diff --git a/src/main/java/li/strolch/model/parameter/AbstractParameter.java b/src/main/java/li/strolch/model/parameter/AbstractParameter.java index 0430c4c35..e51d2daea 100644 --- a/src/main/java/li/strolch/model/parameter/AbstractParameter.java +++ b/src/main/java/li/strolch/model/parameter/AbstractParameter.java @@ -25,7 +25,6 @@ import li.strolch.exception.StrolchException; import li.strolch.model.AbstractStrolchElement; import li.strolch.model.Locator; import li.strolch.model.Locator.LocatorBuilder; -import li.strolch.model.Parameter; import li.strolch.model.ParameterizedElement; import org.dom4j.Element; diff --git a/src/main/java/li/strolch/model/parameter/BooleanParameter.java b/src/main/java/li/strolch/model/parameter/BooleanParameter.java index 50561f33d..4d6921ee9 100644 --- a/src/main/java/li/strolch/model/parameter/BooleanParameter.java +++ b/src/main/java/li/strolch/model/parameter/BooleanParameter.java @@ -22,7 +22,6 @@ package li.strolch.model.parameter; import li.strolch.exception.StrolchException; -import li.strolch.model.Parameter; import org.dom4j.Element; diff --git a/src/main/java/li/strolch/model/parameter/DateParameter.java b/src/main/java/li/strolch/model/parameter/DateParameter.java index d40d17d89..3e0667861 100644 --- a/src/main/java/li/strolch/model/parameter/DateParameter.java +++ b/src/main/java/li/strolch/model/parameter/DateParameter.java @@ -24,7 +24,6 @@ package li.strolch.model.parameter; import java.text.DateFormat; import li.strolch.exception.StrolchException; -import li.strolch.model.Parameter; import org.dom4j.Element; @@ -32,7 +31,6 @@ import ch.eitchnet.utils.helper.StringHelper; /** * @author Robert von Burg - * */ public class DateParameter extends AbstractParameter { diff --git a/src/main/java/li/strolch/model/parameter/FloatParameter.java b/src/main/java/li/strolch/model/parameter/FloatParameter.java index 07a22dda9..e313828ab 100644 --- a/src/main/java/li/strolch/model/parameter/FloatParameter.java +++ b/src/main/java/li/strolch/model/parameter/FloatParameter.java @@ -22,7 +22,6 @@ package li.strolch.model.parameter; import li.strolch.exception.StrolchException; -import li.strolch.model.Parameter; import org.dom4j.Element; diff --git a/src/main/java/li/strolch/model/parameter/IntegerParameter.java b/src/main/java/li/strolch/model/parameter/IntegerParameter.java index ce3529af1..40d0315c3 100644 --- a/src/main/java/li/strolch/model/parameter/IntegerParameter.java +++ b/src/main/java/li/strolch/model/parameter/IntegerParameter.java @@ -22,7 +22,6 @@ package li.strolch.model.parameter; import li.strolch.exception.StrolchException; -import li.strolch.model.Parameter; import org.dom4j.Element; diff --git a/src/main/java/li/strolch/model/parameter/ListParameter.java b/src/main/java/li/strolch/model/parameter/ListParameter.java index 8f3bf50bd..192bedf36 100644 --- a/src/main/java/li/strolch/model/parameter/ListParameter.java +++ b/src/main/java/li/strolch/model/parameter/ListParameter.java @@ -23,7 +23,6 @@ package li.strolch.model.parameter; import java.util.List; -import li.strolch.model.Parameter; /** * @author Robert von Burg diff --git a/src/main/java/li/strolch/model/parameter/LongParameter.java b/src/main/java/li/strolch/model/parameter/LongParameter.java index 4cf27a145..1eb0fc0bf 100644 --- a/src/main/java/li/strolch/model/parameter/LongParameter.java +++ b/src/main/java/li/strolch/model/parameter/LongParameter.java @@ -22,7 +22,6 @@ package li.strolch.model.parameter; import li.strolch.exception.StrolchException; -import li.strolch.model.Parameter; import org.dom4j.Element; diff --git a/src/main/java/li/strolch/model/Parameter.java b/src/main/java/li/strolch/model/parameter/Parameter.java similarity index 95% rename from src/main/java/li/strolch/model/Parameter.java rename to src/main/java/li/strolch/model/parameter/Parameter.java index 25fa427c7..f6341a812 100644 --- a/src/main/java/li/strolch/model/Parameter.java +++ b/src/main/java/li/strolch/model/parameter/Parameter.java @@ -19,7 +19,12 @@ * along with li.strolch.model. If not, see * . */ -package li.strolch.model; +package li.strolch.model.parameter; + +import li.strolch.model.Order; +import li.strolch.model.ParameterizedElement; +import li.strolch.model.Resource; +import li.strolch.model.StrolchElement; /** * @author Robert von Burg diff --git a/src/main/java/li/strolch/model/parameter/StringListParameter.java b/src/main/java/li/strolch/model/parameter/StringListParameter.java index 07eccb26e..c5dc35056 100644 --- a/src/main/java/li/strolch/model/parameter/StringListParameter.java +++ b/src/main/java/li/strolch/model/parameter/StringListParameter.java @@ -113,6 +113,9 @@ public class StringListParameter extends AbstractParameter> impleme @Override public void setValue(List value) { + validateValue(value); + if (this.value == null) + this.value = new ArrayList(value.size()); this.value.clear(); this.value.addAll(value); } diff --git a/src/main/java/li/strolch/model/parameter/StringParameter.java b/src/main/java/li/strolch/model/parameter/StringParameter.java index ed8fd3a54..9cf021c6a 100644 --- a/src/main/java/li/strolch/model/parameter/StringParameter.java +++ b/src/main/java/li/strolch/model/parameter/StringParameter.java @@ -22,7 +22,6 @@ package li.strolch.model.parameter; import li.strolch.exception.StrolchException; -import li.strolch.model.Parameter; import org.dom4j.Element; diff --git a/src/test/java/li/strolch/ModelTest.java b/src/test/java/li/strolch/ModelTest.java deleted file mode 100644 index f0970ff55..000000000 --- a/src/test/java/li/strolch/ModelTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package li.strolch; - -import li.strolch.model.Order; -import li.strolch.model.Parameter; -import li.strolch.model.ParameterBag; -import li.strolch.model.Resource; -import li.strolch.model.State; -import li.strolch.model.parameter.FloatParameter; - -import org.junit.Test; - -public class ModelTest { - - @Test - public void shouldCreateResource() { - - Resource resource = new Resource("@res01", "Test resource", "MyType"); - - ParameterBag bag = new ParameterBag("@bag01", "Test Bag", "Test"); - - Parameter floatParam = new FloatParameter("@param1", "Float Param", 44.3); - bag.addParameter(floatParam); - - resource.addParameterBag(bag); - } - - @Test - public void shouldCreateOrder() { - - Order order = new Order("@ord01", "Test Order", "MyType", System.currentTimeMillis(), State.OPEN); - - ParameterBag bag = new ParameterBag("@bag01", "Test Bag", "Test"); - - Parameter floatParam = new FloatParameter("@param1", "Float Param", 44.3); - bag.addParameter(floatParam); - - order.addParameterBag(bag); - } -} diff --git a/src/test/java/li/strolch/test/model/ModelTest.java b/src/test/java/li/strolch/test/model/ModelTest.java new file mode 100644 index 000000000..d170c7d98 --- /dev/null +++ b/src/test/java/li/strolch/test/model/ModelTest.java @@ -0,0 +1,84 @@ +package li.strolch.test.model; + +import java.util.ArrayList; + +import junit.framework.Assert; +import li.strolch.model.Order; +import li.strolch.model.ParameterBag; +import li.strolch.model.Resource; +import li.strolch.model.State; +import li.strolch.model.parameter.BooleanParameter; +import li.strolch.model.parameter.DateParameter; +import li.strolch.model.parameter.FloatParameter; +import li.strolch.model.parameter.IntegerParameter; +import li.strolch.model.parameter.LongParameter; +import li.strolch.model.parameter.StringListParameter; +import li.strolch.model.parameter.StringParameter; + +import org.junit.Test; + +public class ModelTest { + + @Test + public void shouldCreateResource() { + + Resource resource = ModelTestHelper.createResource("@res01", "Test resource", "MyType"); + ParameterBag bag = resource.getParameterBag(ModelTestHelper.BAG_ID); + validateBag(bag); + } + + @Test + public void shouldCreateOrder() { + + Order order = ModelTestHelper.createOrder("@ord01", "Test Order", "MyType", System.currentTimeMillis(), + State.OPEN); + ParameterBag bag = order.getParameterBag(ModelTestHelper.BAG_ID); + validateBag(bag); + } + + public static void validateBag(ParameterBag bag) { + + Assert.assertNotNull(bag); + + Assert.assertEquals(ModelTestHelper.BAG_ID, bag.getId()); + Assert.assertEquals(ModelTestHelper.BAG_NAME, bag.getName()); + Assert.assertEquals(ModelTestHelper.BAG_TYPE, bag.getType()); + + validateParams(bag); + } + + public static void validateParams(ParameterBag bag) { + + BooleanParameter boolParam = bag.getParameter(ModelTestHelper.PARAM_BOOLEAN_ID); + Assert.assertNotNull("Boolean Param missing with id " + ModelTestHelper.PARAM_BOOLEAN_ID, boolParam); + Assert.assertEquals(true, boolParam.getValue().booleanValue()); + + FloatParameter floatParam = bag.getParameter(ModelTestHelper.PARAM_FLOAT_ID); + Assert.assertNotNull("Float Param missing with id " + ModelTestHelper.PARAM_FLOAT_ID, floatParam); + Assert.assertEquals(44.3, floatParam.getValue().doubleValue()); + + IntegerParameter integerParam = bag.getParameter(ModelTestHelper.PARAM_INTEGER_ID); + Assert.assertNotNull("Integer Param missing with id " + ModelTestHelper.PARAM_INTEGER_ID, integerParam); + Assert.assertEquals(77, integerParam.getValue().intValue()); + + LongParameter longParam = bag.getParameter(ModelTestHelper.PARAM_LONG_ID); + Assert.assertNotNull("Long Param missing with id " + ModelTestHelper.PARAM_LONG_ID, longParam); + Assert.assertEquals(4453234566L, longParam.getValue().longValue()); + + StringParameter stringParam = bag.getParameter(ModelTestHelper.PARAM_STRING_ID); + Assert.assertNotNull("String Param missing with id " + ModelTestHelper.PARAM_STRING_ID, stringParam); + Assert.assertEquals("Strolch", stringParam.getValue()); + + DateParameter dateParam = bag.getParameter(ModelTestHelper.PARAM_DATE_ID); + Assert.assertNotNull("Date Param missing with id " + ModelTestHelper.PARAM_DATE_ID, dateParam); + Assert.assertEquals(1354295525628L, dateParam.getValue().longValue()); + + StringListParameter stringListP = bag.getParameter(ModelTestHelper.PARAM_LIST_STRING_ID); + Assert.assertNotNull("StringList Param missing with id " + ModelTestHelper.PARAM_LIST_STRING_ID, stringListP); + + ArrayList stringList = new ArrayList(); + stringList.add("Hello"); + stringList.add("World"); + Assert.assertEquals(stringList, stringListP.getValue()); + } +} diff --git a/src/test/java/li/strolch/test/model/ModelTestHelper.java b/src/test/java/li/strolch/test/model/ModelTestHelper.java new file mode 100644 index 000000000..e11e27f72 --- /dev/null +++ b/src/test/java/li/strolch/test/model/ModelTestHelper.java @@ -0,0 +1,178 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.test.model; + +import java.util.ArrayList; + +import li.strolch.model.Order; +import li.strolch.model.ParameterBag; +import li.strolch.model.Resource; +import li.strolch.model.State; +import li.strolch.model.parameter.BooleanParameter; +import li.strolch.model.parameter.DateParameter; +import li.strolch.model.parameter.FloatParameter; +import li.strolch.model.parameter.IntegerParameter; +import li.strolch.model.parameter.LongParameter; +import li.strolch.model.parameter.Parameter; +import li.strolch.model.parameter.StringListParameter; +import li.strolch.model.parameter.StringParameter; + +/** + * @author Robert von Burg + * + */ +public class ModelTestHelper { + + public static final String PARAM_BOOLEAN_ID = "@param1"; + public static final String PARAM_BOOLEAN_NAME = "Boolean Param"; + + public static final String PARAM_FLOAT_ID = "@param2"; + public static final String PARAM_FLOAT_NAME = "Float Param"; + + public static final String PARAM_INTEGER_ID = "@param3"; + public static final String PARAM_INTEGER_NAME = "Integer Param"; + + public static final String PARAM_LONG_ID = "@param4"; + public static final String PARAM_LONG_NAME = "Long Param"; + + public static final String PARAM_STRING_ID = "@param5"; + public static final String PARAM_STRING_NAME = "String Param"; + + public static final String PARAM_DATE_ID = "@param6"; + public static final String PARAM_DATE_NAME = "Date Param"; + + public static final String PARAM_LIST_STRING_ID = "@param7"; + public static final String PARAM_LIST_STRING_NAME = "StringList Param"; + + public static final String BAG_ID = "@bag01"; + public static final String BAG_NAME = "Test Bag"; + public static final String BAG_TYPE = "TestBag"; + + /** + * Creates an {@link Resource} with the given values and adds a {@link ParameterBag} by calling + * {@link #createParameterBag(String, String, String)} + * + * @param id + * the id of the {@link Resource} + * @param name + * the name of the {@link Resource} + * @param type + * the type of the {@link Resource} + * + * @return the newly created {@link Resource} + */ + public static Resource createResource(String id, String name, String type) { + Resource resource = new Resource(id, name, type); + ParameterBag bag = createParameterBag(BAG_ID, BAG_NAME, BAG_TYPE); + resource.addParameterBag(bag); + + return resource; + } + + /** + * Creates an {@link Order} with the given values and adds a {@link ParameterBag} by calling + * {@link #createParameterBag(String, String, String)} + * + * @param id + * the id of the {@link Order} + * @param name + * the name of the {@link Order} + * @param type + * the type of the {@link Order} + * @param date + * the date of the {@link Order} + * @param state + * the {@link State} of the {@link Order} + * + * @return the newly created {@link Order} + */ + public static Order createOrder(String id, String name, String type, long date, State state) { + + Order order = new Order(id, name, type, date, state); + ParameterBag bag = createParameterBag(BAG_ID, BAG_NAME, BAG_TYPE); + order.addParameterBag(bag); + + return order; + } + + /** + * Creates a {@link ParameterBag} with the given values and calls {@link #addAllParameters(ParameterBag)} to add + * {@link Parameter}s + * + * @param id + * the id of the {@link ParameterBag} + * @param name + * the name of the {@link ParameterBag} + * @param type + * the type of the {@link ParameterBag} + * + * @return the newly created {@link ParameterBag} + */ + public static ParameterBag createParameterBag(String id, String name, String type) { + + ParameterBag bag = new ParameterBag(id, name, type); + addAllParameters(bag); + return bag; + } + + /** + * Adds the following {@link Parameter}s to the given {@link ParameterBag}: + *
    + *
  • BooleanParameter - true
  • + *
  • FloatParameter - 44.3
  • + *
  • IntegerParameter - 77
  • + *
  • LongParameter - 4453234566L
  • + *
  • StringParameter - "Strolch"
  • + *
  • DateParameter - 1354295525628L
  • + *
  • StringListParameter - Hello, World
  • + *
+ * + * @param bag + */ + public static void addAllParameters(ParameterBag bag) { + + BooleanParameter boolParam = new BooleanParameter(PARAM_BOOLEAN_ID, PARAM_BOOLEAN_NAME, true); + bag.addParameter(boolParam); + + FloatParameter floatParam = new FloatParameter(PARAM_FLOAT_ID, PARAM_FLOAT_NAME, 44.3); + bag.addParameter(floatParam); + + IntegerParameter integerParam = new IntegerParameter(PARAM_INTEGER_ID, PARAM_INTEGER_NAME, 77); + bag.addParameter(integerParam); + + LongParameter longParam = new LongParameter(PARAM_LONG_ID, PARAM_LONG_NAME, 4453234566L); + bag.addParameter(longParam); + + StringParameter stringParam = new StringParameter(PARAM_STRING_ID, PARAM_STRING_NAME, "Strolch"); + bag.addParameter(stringParam); + + DateParameter dateParam = new DateParameter(PARAM_DATE_ID, PARAM_DATE_NAME, 1354295525628L); + bag.addParameter(dateParam); + + ArrayList stringList = new ArrayList(); + stringList.add("Hello"); + stringList.add("World"); + StringListParameter stringListP = new StringListParameter(PARAM_LIST_STRING_ID, PARAM_LIST_STRING_NAME, + stringList); + bag.addParameter(stringListP); + } +} From 38842051d1c6dbfdf3a80174d5e59386563bd3c8 Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 10 Dec 2012 17:38:41 +0100 Subject: [PATCH 09/88] TimeValue Framework Implementation of the time value framework and the timed state build upon --- .DS_Store | Bin 0 -> 6148 bytes .../strolch/model/timedstate/ITimedState.java | 45 ++++++ .../strolch/model/timedstate/TimedState.java | 64 ++++++++ .../strolch/model/timevalue/ITimeValue.java | 24 +++ .../model/timevalue/ITimeVariable.java | 70 +++++++++ .../li/strolch/model/timevalue/IValue.java | 41 ++++++ .../strolch/model/timevalue/IValueChange.java | 28 ++++ .../strolch/model/timevalue/impl/AString.java | 69 +++++++++ .../model/timevalue/impl/DoubleValue.java | 94 ++++++++++++ .../model/timevalue/impl/IntegerValue.java | 86 +++++++++++ .../model/timevalue/impl/StringSetValue.java | 86 +++++++++++ .../model/timevalue/impl/TimeValue.java | 90 ++++++++++++ .../model/timevalue/impl/TimeVariable.java | 98 +++++++++++++ .../model/timevalue/impl/ValueChange.java | 77 ++++++++++ .../model/timedstate/TimeStateTest.java | 96 ++++++++++++ .../timevalue/FloatTimeVariableTest.java | 137 ++++++++++++++++++ .../timevalue/IntegerTimeVariableTest.java | 131 +++++++++++++++++ .../timevalue/StringTimeVariableTest.java | 118 +++++++++++++++ .../strolch/model/timevalue/ValueTests.java | 81 +++++++++++ 19 files changed, 1435 insertions(+) create mode 100644 .DS_Store create mode 100644 src/main/java/li/strolch/model/timedstate/ITimedState.java create mode 100644 src/main/java/li/strolch/model/timedstate/TimedState.java create mode 100644 src/main/java/li/strolch/model/timevalue/ITimeValue.java create mode 100644 src/main/java/li/strolch/model/timevalue/ITimeVariable.java create mode 100644 src/main/java/li/strolch/model/timevalue/IValue.java create mode 100644 src/main/java/li/strolch/model/timevalue/IValueChange.java create mode 100644 src/main/java/li/strolch/model/timevalue/impl/AString.java create mode 100644 src/main/java/li/strolch/model/timevalue/impl/DoubleValue.java create mode 100644 src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java create mode 100644 src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java create mode 100644 src/main/java/li/strolch/model/timevalue/impl/TimeValue.java create mode 100644 src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java create mode 100644 src/main/java/li/strolch/model/timevalue/impl/ValueChange.java create mode 100644 src/test/java/li/strolch/model/timedstate/TimeStateTest.java create mode 100644 src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java create mode 100644 src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java create mode 100644 src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java create mode 100644 src/test/java/li/strolch/model/timevalue/ValueTests.java diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..68cc094d89a709cdd34d7544817777f3c6490145 GIT binary patch literal 6148 zcmeH~&r8EF6vq=cwMB(qgdKzDA=_kZf`?KjcoaI=!HKq3T%k0h?c8Bji&y^`{~P}v z-%C<(y0eJ9K=OUbdr6uPG(Q+)+*?Fl#vI0&1sRp2u_0meM%R`JM&&q0J`WQaLhU`A z8{c0S{PqURS;p?d<=5{|;=Jf|KKNFnxxKS%*|xPmoy2J*m!4dtQGVsmR2?3Hb?8ukWl(I0fn(zYzy zd9x0Wj?XT}!BhGCQfZ1DAggp>w3b&e%pxBBEKOwk04;TN9Ysn6hyW2F0z^O&Fb9OS zM?8oC5g-EJ2;lx8AfviQE3InlfC8`2=x?H80vq2FsKTggw9*P5NL+UX)m^!HVsPCZ z+J%X8jaFK9cgEGsFpinIe!OrsJG2WG&bX_UN+Li6)(JFp)xq=s9DbRNkNov6R3idJ z;GYrT&5=LyU{U65{joeeYX#(6$e1v$LIV=mYnK41;6Bn)PVE;6dq&0p literal 0 HcmV?d00001 diff --git a/src/main/java/li/strolch/model/timedstate/ITimedState.java b/src/main/java/li/strolch/model/timedstate/ITimedState.java new file mode 100644 index 000000000..a5d0a2744 --- /dev/null +++ b/src/main/java/li/strolch/model/timedstate/ITimedState.java @@ -0,0 +1,45 @@ +package li.strolch.model.timedstate; + +import li.strolch.model.timevalue.ITimeValue; +import li.strolch.model.timevalue.ITimeVariable; +import li.strolch.model.timevalue.IValue; +import li.strolch.model.timevalue.IValueChange; + +/** + * A time based state characterized by a {@link IValue} object implementation. + * + * @author martin_smock + * + * @param + * IValue implementation representing the state at a given time + */ +@SuppressWarnings("rawtypes") +public interface ITimedState { + + /** + * @return the new {@link ITimeValue} matching the value in the future + */ + ITimeValue getNextMatch(final Long time, T value); + + /** + * @return the new {@link ITimeValue} matching the value in the future + */ + ITimeValue getPreviousMatch(final Long time, T value); + + /** + * @param change + * the state change to be applied + */ + void applyChange(final IValueChange change); + + /** + * @return the state at the given time + */ + ITimeValue getStateAt(final Long time); + + /** + * @return get the states evolution in time + */ + ITimeVariable getTimeEvolution(); + +} \ No newline at end of file diff --git a/src/main/java/li/strolch/model/timedstate/TimedState.java b/src/main/java/li/strolch/model/timedstate/TimedState.java new file mode 100644 index 000000000..f5dcfd089 --- /dev/null +++ b/src/main/java/li/strolch/model/timedstate/TimedState.java @@ -0,0 +1,64 @@ +package li.strolch.model.timedstate; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import li.strolch.model.timevalue.ITimeValue; +import li.strolch.model.timevalue.ITimeVariable; +import li.strolch.model.timevalue.IValue; +import li.strolch.model.timevalue.IValueChange; +import li.strolch.model.timevalue.impl.TimeVariable; + + +/** + * @author martin_smock + */ +@SuppressWarnings("rawtypes") +public class TimedState implements ITimedState { + + private ITimeVariable timeVariable = new TimeVariable(); + + @Override + @SuppressWarnings("unchecked") + public ITimeValue getNextMatch(final Long time, final T value) { + Collection> futureValues = timeVariable.getFutureValues(time); + for (ITimeValue iTimeValue : futureValues) { + if (iTimeValue.getValue().matches(value)) { + return iTimeValue; + } + } + return null; + } + + @Override + @SuppressWarnings("unchecked") + public ITimeValue getPreviousMatch(final Long time, final T value) { + Collection> pastValues = timeVariable.getPastValues(time); + List> asList = new ArrayList>(pastValues); + Collections.reverse(asList); + for (ITimeValue iTimeValue : asList) { + if (iTimeValue.getValue().matches(value)) { + return iTimeValue; + } + } + return null; + } + + @Override + public void applyChange(final IValueChange change) { + timeVariable.applyChange(change); + } + + @Override + public ITimeValue getStateAt(final Long time) { + return timeVariable.getValueAt(time); + } + + @Override + public ITimeVariable getTimeEvolution() { + return timeVariable; + } + +} diff --git a/src/main/java/li/strolch/model/timevalue/ITimeValue.java b/src/main/java/li/strolch/model/timevalue/ITimeValue.java new file mode 100644 index 000000000..1df712d26 --- /dev/null +++ b/src/main/java/li/strolch/model/timevalue/ITimeValue.java @@ -0,0 +1,24 @@ +package li.strolch.model.timevalue; + +import li.strolch.model.timevalue.impl.TimeVariable; + +/** + * Interface for timed value objects to be used with the {@link TimeVariable} + * + * @author martin_smock + * + * @param + * the backing value of the timed value object + */ +@SuppressWarnings("rawtypes") +public interface ITimeValue extends Comparable> { + + ITimeValue setValue(final T value); + + T getValue(); + + Long getTime(); + + ITimeValue add(final T change); + +} diff --git a/src/main/java/li/strolch/model/timevalue/ITimeVariable.java b/src/main/java/li/strolch/model/timevalue/ITimeVariable.java new file mode 100644 index 000000000..4df20ff26 --- /dev/null +++ b/src/main/java/li/strolch/model/timevalue/ITimeVariable.java @@ -0,0 +1,70 @@ +package li.strolch.model.timevalue; + +import java.util.Collection; + +/** + * A timed variable storing a ordered sequence of {@link ITimeValue} objects + * modeling a time evolution of a quantity. + * + * @author martin_smock + * + * @param + * the backing value of the timed value object + */ +@SuppressWarnings("rawtypes") +public interface ITimeVariable { + + /** + * set the value at a point in time to a given time value object + * + * @param time + * the time to set the {@link IValue} + * @param value + * the {@link IValue} to set + */ + void setValueAt(final Long time, final T value); + + /** + * get the latest {@link ITimeValue} whose time field is less or equal to + * the time given + */ + ITimeValue getValueAt(final Long time); + + /** + * Applies a {@link IValueChange} propagating the change to all future + * values starting from the time of the change. + * + * @param change + * the {@link IValueChange} to be applied + */ + void applyChange(final IValueChange change); + + /** + * Get all {@link ITimeValue} objects whose time field is greater or equal + * to the given time + * + * @param time + * the time the sequence starts with + * @return the sequence of {@link ITimeValue} objects in the future + */ + Collection> getFutureValues(final Long time); + + /** + * Get all {@link ITimeValue} objects whose time field is strictly smaller + * than the given time + * + * @param time + * the time the sequence starts with + * @return the sequence of {@link ITimeValue} objects in the future + */ + Collection> getPastValues(final Long time); + + /** + * removes {@link ITimeValue} objects from the sequence, where the successor + * matches value. I.e considering a pair of adjacent {@link ITimeValue} + * objects in the sequence which have the same {@link IValue}, the later one + * is removed, since it contains no additional information. + */ + void compact(); + +} diff --git a/src/main/java/li/strolch/model/timevalue/IValue.java b/src/main/java/li/strolch/model/timevalue/IValue.java new file mode 100644 index 000000000..e3e4444ab --- /dev/null +++ b/src/main/java/li/strolch/model/timevalue/IValue.java @@ -0,0 +1,41 @@ +package li.strolch.model.timevalue; + +/** + * A value object defining some basic algebraic operations. Mathematically + * speaking {@link IValue} objects define a group with a addition operation. + * + * @author martin_smock + * + * @param + * any object for which a (generalized) add operation can be defined. + * + */ +public interface IValue { + + /** + * @return the backing value + */ + T getValue(); + + /** + * @return a value with the backing value added to the argument value + */ + IValue add(T o); + + /** + * @return true, if the backing values match. + */ + boolean matches(IValue other); + + /** + * @return the inverse value, such that add(value.getInverse()) returns the + * neutral element of the group + */ + IValue getInverse(); + + /** + * @return a copy of this + */ + IValue getCopy(); + +} diff --git a/src/main/java/li/strolch/model/timevalue/IValueChange.java b/src/main/java/li/strolch/model/timevalue/IValueChange.java new file mode 100644 index 000000000..ec25d5b18 --- /dev/null +++ b/src/main/java/li/strolch/model/timevalue/IValueChange.java @@ -0,0 +1,28 @@ +package li.strolch.model.timevalue; + +/** + * Interface for operators to be used to change the values of {@link ITimeValue} + * in a {@link ITimeVariable}. + * + * @author martin_smock + */ +@SuppressWarnings("rawtypes") +public interface IValueChange { + + /** + * @return the time this change has to be applied + */ + Long getTime(); + + /** + * @return the value of the change + */ + T getValue(); + + /** + * @return the inverse neutralizing a change. Very useful to undo changes + * applied. + */ + IValueChange getInverse(); + +} diff --git a/src/main/java/li/strolch/model/timevalue/impl/AString.java b/src/main/java/li/strolch/model/timevalue/impl/AString.java new file mode 100644 index 000000000..cd952facc --- /dev/null +++ b/src/main/java/li/strolch/model/timevalue/impl/AString.java @@ -0,0 +1,69 @@ +package li.strolch.model.timevalue.impl; + +/** + * Wrapper for java.util.String object defining a inverse to support algebraic + * operations. + * + * @author martin_smock + */ +public class AString { + + private final String string; + private final boolean inverse; + + public AString(final String string) { + this.string = string; + this.inverse = false; + } + + public AString(final String string, final boolean inverse) { + this.string = string; + this.inverse = inverse; + } + + public String getString() { + return string; + } + + public boolean isInverse() { + return inverse; + } + + public AString getInverse() { + return new AString(string, !inverse); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (inverse ? 1231 : 1237); + result = prime * result + ((string == null) ? 0 : string.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + AString other = (AString) obj; + if (inverse != other.inverse) + return false; + if (string == null) { + if (other.string != null) + return false; + } else if (!string.equals(other.string)) + return false; + return true; + } + + @Override + public String toString() { + return "AString [string=" + string + ", inverse=" + inverse + "]"; + } + +} diff --git a/src/main/java/li/strolch/model/timevalue/impl/DoubleValue.java b/src/main/java/li/strolch/model/timevalue/impl/DoubleValue.java new file mode 100644 index 000000000..f4a73fdff --- /dev/null +++ b/src/main/java/li/strolch/model/timevalue/impl/DoubleValue.java @@ -0,0 +1,94 @@ +package li.strolch.model.timevalue.impl; + +import li.strolch.model.timevalue.ITimeValue; +import li.strolch.model.timevalue.IValue; + +/** + * {@link IValue} implementation to work with Double valued {@link ITimeValue} objects + * + * @author martin_smock + */ +public class DoubleValue implements IValue { + + public static final DoubleValue NEUTRAL = new DoubleValue(0.0d); + + private Double value; + + public DoubleValue(Double value) { + this.value = value; + } + + public DoubleValue(double value) { + this.value = Double.valueOf(value); + } + + public DoubleValue(Integer value) { + this.value = this.value.doubleValue(); + } + + public DoubleValue(int value) { + this.value = Integer.valueOf(value).doubleValue(); + } + + public DoubleValue(String valueAsString) throws NumberFormatException { + this.value = Double.parseDouble(valueAsString); + } + + @Override + public DoubleValue add(Double o) { + value += o; + return this; + } + + @Override + public Double getValue() { + return value; + } + + @Override + public String toString() { + return "DoubleValue [value=" + value + "]"; + } + + @Override + public boolean matches(IValue other) { + return this.value.equals(other.getValue()); + } + + @Override + public DoubleValue getInverse() { + return new DoubleValue(-getValue()); + } + + @Override + public DoubleValue getCopy(){ + return new DoubleValue(value); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((value == null) ? 0 : value.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + DoubleValue other = (DoubleValue) obj; + if (value == null) { + if (other.value != null) + return false; + } else if (!value.equals(other.value)) + return false; + return true; + } + + +} diff --git a/src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java b/src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java new file mode 100644 index 000000000..6b1964318 --- /dev/null +++ b/src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java @@ -0,0 +1,86 @@ +package li.strolch.model.timevalue.impl; + +import li.strolch.model.timevalue.ITimeValue; +import li.strolch.model.timevalue.IValue; + +/** + * {@link IValue} implementation to work with Integer valued {@link ITimeValue} + * objects + * + * @author martin_smock + */ +public class IntegerValue implements IValue { + + public static final IntegerValue NEUTRAL = new IntegerValue(0); + + private Integer value; + + public IntegerValue(Integer value) { + this.value = value; + } + + public IntegerValue(int value) { + this.value = Integer.valueOf(value); + } + + public IntegerValue(String valueAsString) throws NumberFormatException { + this.value = Integer.parseInt(valueAsString); + } + + @Override + public IntegerValue add(Integer o) { + value += o; + return this; + } + + @Override + public boolean matches(IValue other) { + return this.value.equals(other.getValue()); + } + + @Override + public Integer getValue() { + return value; + } + + @Override + public IntegerValue getInverse() { + return new IntegerValue(-getValue()); + } + + @Override + public String toString() { + return "IntegerValue [value=" + value + "]"; + } + + @Override + public IntegerValue getCopy() { + return new IntegerValue(value); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((value == null) ? 0 : value.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + IntegerValue other = (IntegerValue) obj; + if (value == null) { + if (other.value != null) + return false; + } else if (!value.equals(other.value)) + return false; + return true; + } + +} diff --git a/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java b/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java new file mode 100644 index 000000000..499211bfc --- /dev/null +++ b/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java @@ -0,0 +1,86 @@ +package li.strolch.model.timevalue.impl; + +import java.util.HashSet; +import java.util.Collections; +import java.util.Iterator; +import java.util.Set; + +import li.strolch.model.timevalue.ITimeValue; +import li.strolch.model.timevalue.IValue; + + +/** + * {@link IValue} implementation to work with String valued {@link ITimeValue} + * objects. Since a java.util.String object does not define a inverse, a + * algebraic {@link AString} wrapper is used. + * + * @author martin_smock + */ +public class StringSetValue implements IValue> { + + private static Set neu = Collections.emptySet(); + public static final IValue> NEUTRAL = new StringSetValue(neu); + + private Set aStrings = new HashSet(); + + public StringSetValue() { + } + + public StringSetValue(final Set aStrings) { + this.aStrings = aStrings; + } + + @Override + public Set getValue() { + return aStrings; + } + + @Override + public IValue> add(Set o) { + + Set toBeAdded = new HashSet(o); + + for (Iterator iter1 = toBeAdded.iterator(); iter1.hasNext();) { + AString toAdd = iter1.next(); + for (Iterator iter = aStrings.iterator(); iter.hasNext();) { + AString aString = iter.next(); + boolean valueMatch = aString.getString().equals(toAdd.getString()); + boolean compensate = (toAdd.isInverse() && !aString.isInverse()) + || (!toAdd.isInverse() && aString.isInverse()); + if (valueMatch && compensate) { + iter.remove(); + iter1.remove(); + } + } + } + aStrings.addAll(toBeAdded); + return this; + } + + @Override + public boolean matches(IValue> other) { + return this.getValue().equals(other.getValue()); + } + + @Override + public IValue> getInverse() { + Set inverseSet = new HashSet(); + for (AString as : aStrings) { + inverseSet.add(as.getInverse()); + } + StringSetValue inverse = new StringSetValue(); + inverse.aStrings = inverseSet; + return inverse; + } + + @Override + public StringSetValue getCopy() { + return new StringSetValue(aStrings); + } + + @Override + public String toString() { + return "StringSetValue [aStrings=" + aStrings + "]"; + } + +} diff --git a/src/main/java/li/strolch/model/timevalue/impl/TimeValue.java b/src/main/java/li/strolch/model/timevalue/impl/TimeValue.java new file mode 100644 index 000000000..bd14fed55 --- /dev/null +++ b/src/main/java/li/strolch/model/timevalue/impl/TimeValue.java @@ -0,0 +1,90 @@ +package li.strolch.model.timevalue.impl; + +import li.strolch.model.timevalue.ITimeValue; +import li.strolch.model.timevalue.IValue; + +/** + * @author martin_smock + */ +@SuppressWarnings("rawtypes") +public class TimeValue implements ITimeValue { + + protected final Long time; + protected T value; + + /** + * @param time + * @param value + */ + public TimeValue(final Long time, final T value){ + this.time = time; + this.value = value; + } + + @Override + @SuppressWarnings("unchecked") + public T getValue() { + return (T) value.getCopy(); + } + + @Override + public Long getTime() { + return time; + } + + @Override + public ITimeValue setValue(final T value) { + this.value = value; + return this; + } + + @SuppressWarnings("unchecked") + @Override + public ITimeValue add(final T change) { + this.value.add(change.getValue()); + return this; + } + + @Override + public int compareTo(final ITimeValue arg0) { + return this.getTime().compareTo(arg0.getTime()); + } + + @Override + public String toString() { + return "TimeValue [time=" + time + ", value=" + value + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((time == null) ? 0 : time.hashCode()); + result = prime * result + ((value == null) ? 0 : value.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + @SuppressWarnings("unchecked") + TimeValue other = (TimeValue) obj; + if (time == null) { + if (other.time != null) + return false; + } else if (!time.equals(other.time)) + return false; + if (value == null) { + if (other.value != null) + return false; + } else if (!value.equals(other.value)) + return false; + return true; + } + +} diff --git a/src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java b/src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java new file mode 100644 index 000000000..43a71c63f --- /dev/null +++ b/src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java @@ -0,0 +1,98 @@ +package li.strolch.model.timevalue.impl; + +import java.util.Collection; +import java.util.Iterator; +import java.util.SortedSet; +import java.util.TreeSet; + +import li.strolch.model.timevalue.ITimeValue; +import li.strolch.model.timevalue.ITimeVariable; +import li.strolch.model.timevalue.IValue; +import li.strolch.model.timevalue.IValueChange; + + +/** + * @author martin_smock + */ +@SuppressWarnings("rawtypes") +public class TimeVariable implements ITimeVariable { + + public SortedSet> container = new TreeSet>(); + + @Override + public ITimeValue getValueAt(final Long time) { + ITimeValue tmp = null; + for (ITimeValue value : container) { + if (value.getTime() <= time) { + tmp = value; + } else { + break; + } + } + return tmp; + } + + @Override + public void setValueAt(final Long time, final T targetValue) { + ITimeValue current = getValueAt(time); + if (current != null && current.getTime().equals(time)) { + current.setValue(targetValue); + } else { + container.add(new TimeValue(time, targetValue)); + } + } + + @Override + public SortedSet> getFutureValues(final Long time) { + TimeValue picker = new TimeValue(time, null); + return new TreeSet>(container.tailSet(picker)); + } + + @Override + public Collection> getPastValues(final Long time) { + TimeValue picker = new TimeValue(time, null); + return new TreeSet>(container.headSet(picker)); + } + + @Override + public void applyChange(final IValueChange change) { + + SortedSet> futureValues = getFutureValues(change.getTime()); + for (ITimeValue value : futureValues) { + value.add(change.getValue()); + } + + ITimeValue initialValue = getValueAt(change.getTime()); + if (initialValue == null) { + ITimeValue newValue = new TimeValue(change.getTime(), change.getValue()); + container.add(newValue); + } else if (initialValue.getTime().longValue() < change.getTime().longValue()) { + ITimeValue newValue = new TimeValue(change.getTime(), initialValue.getValue()); + newValue.add(change.getValue()); + container.add(newValue); + } + compact(); + } + + @SuppressWarnings("unchecked") + @Override + public void compact() { + + if (container.size() < 2) + return; + + Iterator> iterator = container.iterator(); + ITimeValue predecessor = iterator.next(); + + while (iterator.hasNext()) { + ITimeValue successor = iterator.next(); + if (successor.getValue().matches(predecessor.getValue())) { + iterator.remove(); + } else { + predecessor = successor; + } + } + + } + +} diff --git a/src/main/java/li/strolch/model/timevalue/impl/ValueChange.java b/src/main/java/li/strolch/model/timevalue/impl/ValueChange.java new file mode 100644 index 000000000..8d7d33664 --- /dev/null +++ b/src/main/java/li/strolch/model/timevalue/impl/ValueChange.java @@ -0,0 +1,77 @@ +package li.strolch.model.timevalue.impl; + +import li.strolch.model.timevalue.IValue; +import li.strolch.model.timevalue.IValueChange; + +/** + * @author martin_smock + */ +@SuppressWarnings("rawtypes") +public class ValueChange implements IValueChange { + + protected final Long time; + protected final T value; + + /** + * @param time + * @param value + */ + public ValueChange(final Long time, final T value) { + this.time = time; + this.value = value; + } + + @Override + public Long getTime() { + return time; + } + + @Override + @SuppressWarnings("unchecked") + public T getValue() { + return (T) value.getCopy(); + } + + @Override + @SuppressWarnings("unchecked") + public IValueChange getInverse() { + return new ValueChange(time, value.getInverse()); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ValueChange other = (ValueChange) obj; + if (time == null) { + if (other.time != null) + return false; + } else if (!time.equals(other.time)) + return false; + if (value == null) { + if (other.value != null) + return false; + } else if (!value.equals(other.value)) + return false; + return true; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((time == null) ? 0 : time.hashCode()); + result = prime * result + ((value == null) ? 0 : value.hashCode()); + return result; + } + + @Override + public String toString() { + return "ValueChange [time=" + time + ", value=" + value + "]"; + } + +} diff --git a/src/test/java/li/strolch/model/timedstate/TimeStateTest.java b/src/test/java/li/strolch/model/timedstate/TimeStateTest.java new file mode 100644 index 000000000..f2525094c --- /dev/null +++ b/src/test/java/li/strolch/model/timedstate/TimeStateTest.java @@ -0,0 +1,96 @@ +package li.strolch.model.timedstate; + +import junit.framework.Assert; +import li.strolch.model.timedstate.ITimedState; +import li.strolch.model.timedstate.TimedState; +import li.strolch.model.timevalue.ITimeValue; +import li.strolch.model.timevalue.IValueChange; +import li.strolch.model.timevalue.impl.DoubleValue; +import li.strolch.model.timevalue.impl.ValueChange; + +import org.junit.Before; +import org.junit.Test; + +public class TimeStateTest { + + private ITimedState state = new TimedState(); + + final DoubleValue expectedValue1 = new DoubleValue(Double.valueOf(100D)); + final DoubleValue expectedValue2 = new DoubleValue(Double.valueOf(200D)); + + final Long t0 = Long.valueOf(0); + final Long t10 = Long.valueOf(10); + final Long t20 = Long.valueOf(20); + final Long t30 = Long.valueOf(30); + final Long t100 = Long.valueOf(100); + + @Before + public void before() { + + final IValueChange change1 = new ValueChange(t10, expectedValue1); + state.applyChange(change1); + + final ITimeValue stateAt9 = state.getStateAt(9L); + Assert.assertNull(stateAt9); + + final ITimeValue stateAt11 = state.getStateAt(11L); + Assert.assertNotNull(stateAt11); + Assert.assertEquals(true, stateAt11.getValue().matches(expectedValue1)); + + final IValueChange change2 = new ValueChange(t30, expectedValue1); + state.applyChange(change2); + + final ITimeValue stateAt31 = state.getStateAt(31L); + Assert.assertNotNull(stateAt31); + Assert.assertEquals(true, stateAt31.getValue().matches(expectedValue2)); + } + + @Test + public void testGetNextMatch() { + + ITimeValue nextMatch = state.getNextMatch(t0, expectedValue1); + Assert.assertNotNull(nextMatch); + Assert.assertEquals(t10, nextMatch.getTime()); + + nextMatch = state.getNextMatch(t20, expectedValue1); + Assert.assertNull(nextMatch); + + nextMatch = state.getNextMatch(t20, expectedValue2); + Assert.assertNotNull(nextMatch); + Assert.assertEquals(t30, nextMatch.getTime()); + + nextMatch = state.getNextMatch(t30, expectedValue2); + Assert.assertNotNull(nextMatch); + Assert.assertEquals(t30, nextMatch.getTime()); + + nextMatch = state.getNextMatch(t100, expectedValue1); + Assert.assertNull(nextMatch); + + nextMatch = state.getNextMatch(t100, expectedValue2); + Assert.assertNull(nextMatch); + + } + + @Test + public void testGetPreviousMatch() { + + ITimeValue previousMatch = state.getPreviousMatch(t100, expectedValue2); + Assert.assertNotNull(previousMatch); + Assert.assertEquals(t30, previousMatch.getTime()); + + previousMatch = state.getPreviousMatch(t30, expectedValue2); + Assert.assertNull(previousMatch); + + previousMatch = state.getPreviousMatch(t20, expectedValue2); + Assert.assertNull(previousMatch); + + previousMatch = state.getPreviousMatch(t20, expectedValue1); + Assert.assertNotNull(previousMatch); + Assert.assertEquals(t10, previousMatch.getTime()); + + previousMatch = state.getPreviousMatch(t10, expectedValue1); + Assert.assertNull(previousMatch); + + } + +} diff --git a/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java b/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java new file mode 100644 index 000000000..e8fe45670 --- /dev/null +++ b/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java @@ -0,0 +1,137 @@ +package li.strolch.model.timevalue; + +import java.util.Collection; +import java.util.SortedSet; + +import junit.framework.Assert; +import li.strolch.model.timevalue.ITimeValue; +import li.strolch.model.timevalue.IValue; +import li.strolch.model.timevalue.IValueChange; +import li.strolch.model.timevalue.impl.DoubleValue; +import li.strolch.model.timevalue.impl.TimeVariable; +import li.strolch.model.timevalue.impl.ValueChange; + +import org.junit.Before; +import org.junit.Test; + +public class FloatTimeVariableTest { + + private static final Long MAX = 100L; + private static final Long STEP = 10L; + private static final Long PICK = 50L; + + private TimeVariable timeVariable; + + /** + * set the values ascending with a difference of STEP + */ + @Before + public void init() { + timeVariable = new TimeVariable(); + for (long i = 0; i < MAX; i += STEP) { + timeVariable.setValueAt(Long.valueOf(i), new DoubleValue(i)); + } + } + + @Test + public void testGetValueAt() { + ITimeValue valueAt = timeVariable.getValueAt(PICK); + Assert.assertEquals(PICK.doubleValue(), valueAt.getValue().getValue()); + } + + /** + * test, that the future values start with the PICK time and are ascending + */ + @Test + public void testGetFutureValues() { + Collection> futureValues = timeVariable.getFutureValues(PICK); + Long expectedTime = PICK; + Double expectedValue = PICK.doubleValue(); + for (ITimeValue value : futureValues) { + Assert.assertEquals(expectedTime, value.getTime()); + Assert.assertTrue(value.getValue().matches(new DoubleValue(expectedValue))); + expectedTime += STEP; + expectedValue += STEP.doubleValue(); + } + } + + /** + * test, that the past values time fields start with 0 and are strictly + * smaller than PICK + */ + @Test + public void testGetPastValues() { + Collection> pastValues = timeVariable.getPastValues(MAX); + Long expectedTime = 0L; + Double expectedValue = expectedTime.doubleValue(); + for (ITimeValue value : pastValues) { + Assert.assertEquals(expectedTime, value.getTime()); + Assert.assertTrue(value.getValue().matches(new DoubleValue(expectedValue))); + expectedTime += STEP; + expectedValue += STEP.doubleValue(); + } + } + + /** + * apply a change and check that the future values are all changed + */ + @Test + public void testApplyChange() { + + DoubleValue doubleValue = new DoubleValue(STEP.doubleValue()); + + IValueChange change = new ValueChange(PICK, doubleValue); + timeVariable.applyChange(change); + + Collection> futureValues = timeVariable.getFutureValues(PICK); + Long expectedTime = PICK; + + IValue expectedValue = new DoubleValue(PICK.doubleValue() + change.getValue().getValue()); + + for (ITimeValue value : futureValues) { + Assert.assertEquals(expectedTime, value.getTime()); + Assert.assertTrue(expectedValue.matches(value.getValue())); + expectedTime += STEP; + expectedValue = expectedValue.add(STEP.doubleValue()); + } + } + + /** + * apply a change to an empty time variable + */ + @Test + public void testApply2Change() { + + timeVariable = new TimeVariable(); + + DoubleValue doubleValue = new DoubleValue(STEP.doubleValue()); + + IValueChange change = new ValueChange(PICK, doubleValue); + timeVariable.applyChange(change); + + ITimeValue actual = timeVariable.getValueAt(PICK); + Assert.assertNotNull(actual); + + IValue expectedValue = new DoubleValue(STEP.doubleValue()); + Assert.assertEquals(true, actual.getValue().matches(expectedValue)); + } + + /** + * test that successors matching the values of their predecessors are + * removed + */ + @Test + public void testCompact() { + + timeVariable = new TimeVariable(); + for (Long i = 0L; i < MAX; i += STEP) { + timeVariable.setValueAt(i, new DoubleValue(STEP.doubleValue())); + } + // call + timeVariable.compact(); + // check + SortedSet> futureValues = timeVariable.getFutureValues(0L); + Assert.assertEquals(1, futureValues.size()); + } + +} diff --git a/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java b/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java new file mode 100644 index 000000000..9af523bb1 --- /dev/null +++ b/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java @@ -0,0 +1,131 @@ +package li.strolch.model.timevalue; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.SortedSet; + +import junit.framework.Assert; +import li.strolch.model.timevalue.ITimeValue; +import li.strolch.model.timevalue.IValue; +import li.strolch.model.timevalue.IValueChange; +import li.strolch.model.timevalue.impl.IntegerValue; +import li.strolch.model.timevalue.impl.TimeVariable; +import li.strolch.model.timevalue.impl.ValueChange; + +import org.junit.Before; +import org.junit.Test; + +/** + * Basic tests for a {@link TimeVariable} with integer values. + * + * @author martin_smock + */ +public class IntegerTimeVariableTest { + + private static final Long MAX = 100L; + private static final Integer STEP = 10; + private static final Long PICK = 50L; + + private TimeVariable timeVariable; + private Map expectedValues = new HashMap(); + + /** + * set the values ascending with a difference of STEP + */ + @Before + public void init() { + timeVariable = new TimeVariable(); + for (int i = 0; i < MAX; i += STEP) { + IntegerValue expectedValue = new IntegerValue(i); + Long time = Long.valueOf(i); + expectedValues.put(time, expectedValue); + timeVariable.setValueAt(time, expectedValue); + } + } + + @Test + public void testGetValueAt() { + ITimeValue valueAt = timeVariable.getValueAt(PICK); + Assert.assertEquals(expectedValues.get(PICK), valueAt.getValue()); + } + + /** + * test, that the future values start with the PICK time and are ascending + */ + @Test + public void testGetFutureValues() { + Collection> futureValues = timeVariable.getFutureValues(PICK); + Long expectedTime = PICK; + Integer expectedValue = PICK.intValue(); + for (ITimeValue value : futureValues) { + Assert.assertEquals(expectedTime, value.getTime()); + Assert.assertTrue(value.getValue().matches(new IntegerValue(expectedValue))); + expectedTime += STEP; + expectedValue += STEP.intValue(); + } + } + + /** + * test, that the past values time fields start with 0 and are strictly + * smaller than PICK + */ + @Test + public void testGetPastValues() { + Collection> pastValues = timeVariable.getPastValues(MAX); + Long expectedTime = 0L; + Integer expectedValue = expectedTime.intValue(); + for (ITimeValue value : pastValues) { + Assert.assertEquals(expectedTime, value.getTime()); + Assert.assertTrue(value.getValue().matches(new IntegerValue(expectedValue))); + expectedTime += STEP; + expectedValue += STEP.intValue(); + } + } + + /** + * apply a change and check that the future values are all changed + */ + @Test + public void testApplyChange() { + + IntegerValue integerValue = new IntegerValue(STEP.intValue()); + + IValueChange change = new ValueChange(PICK, integerValue); + timeVariable.applyChange(change); + + Collection> futureValues = timeVariable.getFutureValues(PICK); + Long expectedTime = PICK; + + IValue expectedValue = new IntegerValue(PICK.intValue() + change.getValue().getValue()); + for (ITimeValue value : futureValues) { + Assert.assertEquals(expectedTime, value.getTime()); + Assert.assertTrue(expectedValue.matches(value.getValue())); + expectedTime += STEP; + expectedValue = expectedValue.add(STEP.intValue()); + } + } + + /** + * test that successors matching the values of their predecessors are + * removed + */ + @Test + public void testCompact() { + timeVariable = new TimeVariable(); + for (Long i = 0L; i < MAX; i += STEP) { + timeVariable.setValueAt(i, new IntegerValue(STEP.intValue())); + } + + // call + timeVariable.compact(); + + // check + SortedSet> futureValues = timeVariable.getFutureValues(0L); + Assert.assertEquals(1, futureValues.size()); + + ITimeValue next = futureValues.iterator().next(); + Assert.assertEquals(Long.valueOf(0), next.getTime()); + } + +} diff --git a/src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java b/src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java new file mode 100644 index 000000000..031d2de0e --- /dev/null +++ b/src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java @@ -0,0 +1,118 @@ +package li.strolch.model.timevalue; + +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; + +import junit.framework.Assert; +import li.strolch.model.timevalue.ITimeValue; +import li.strolch.model.timevalue.IValue; +import li.strolch.model.timevalue.IValueChange; +import li.strolch.model.timevalue.impl.AString; +import li.strolch.model.timevalue.impl.StringSetValue; +import li.strolch.model.timevalue.impl.TimeVariable; +import li.strolch.model.timevalue.impl.ValueChange; + +import org.junit.Before; +import org.junit.Test; + +public class StringTimeVariableTest { + + private static final Long MAX = 100L; + private static final Long STEP = 10L; + private static final Long PICK = 50L; + + private TimeVariable>> timeVariable; + + private Map testSets = new HashMap(); + + @Before + public void init() { + timeVariable = new TimeVariable>>(); + for (Long i = 0L; i < MAX; i += STEP) { + Set testSet = new HashSet(); + StringSetValue testValue = new StringSetValue(testSet); + testSets.put(i, testValue); + testSet.add(new AString("string " + i)); + timeVariable.setValueAt(i, new StringSetValue(testSet)); + } + } + + @Test + public void testGetValueAt() { + ITimeValue>> valueAt = timeVariable.getValueAt(PICK); + Assert.assertEquals(true, valueAt.getValue().matches(testSets.get(PICK))); + } + + @Test + public void testGetFutureValues() { + Collection>>> futureValues = timeVariable.getFutureValues(PICK); + for (ITimeValue>> iTimeValue : futureValues) { + Long time = iTimeValue.getTime(); + Assert.assertEquals(true, time >= PICK); + Assert.assertNotNull(iTimeValue.getValue()); + Assert.assertEquals(true, iTimeValue.getValue().matches(testSets.get(time))); + } + } + + @Test + public void testGetPastValues() { + Collection>>> pastValues = timeVariable.getPastValues(PICK); + for (ITimeValue>> iTimeValue : pastValues) { + Long time = iTimeValue.getTime(); + Assert.assertEquals(true, time < PICK); + Assert.assertNotNull(iTimeValue.getValue()); + Assert.assertEquals(true, iTimeValue.getValue().matches(testSets.get(time))); + } + } + + @Test + public void testApplyChange() { + + Set testSet = new HashSet(); + testSet.add(new AString("Martin")); + StringSetValue testValue = new StringSetValue(testSet); + + timeVariable = new TimeVariable>>(); + timeVariable.setValueAt(PICK, testValue); + + IValue> inverseTestValue = testValue.getInverse(); + IValueChange>> change = new ValueChange>>(PICK, inverseTestValue); + timeVariable.applyChange(change); + + // check the future values + Collection>>> futureValues = timeVariable.getFutureValues(0L); + for (ITimeValue>> iTimeValue : futureValues) { + System.out.println("++ " + iTimeValue); + } + + Assert.assertEquals(1, futureValues.size()); // a empty one is left + + } + + @Test + public void testCompact() { + + timeVariable = new TimeVariable>>(); + for (Long i = 0L; i < MAX; i += STEP) { + Set testSet = new HashSet(); + StringSetValue testValue = new StringSetValue(testSet); + testSets.put(i, testValue); + testSet.add(new AString("same string")); + timeVariable.setValueAt(i, new StringSetValue(testSet)); + } + + SortedSet>>> valuesInitial = timeVariable.getFutureValues(0L); + Assert.assertEquals(true, valuesInitial.size() > 1); + + timeVariable.compact(); + + SortedSet>>> valuesCompacted = timeVariable.getFutureValues(0L); + Assert.assertEquals(1, valuesCompacted.size()); + + } + +} diff --git a/src/test/java/li/strolch/model/timevalue/ValueTests.java b/src/test/java/li/strolch/model/timevalue/ValueTests.java new file mode 100644 index 000000000..072262fe6 --- /dev/null +++ b/src/test/java/li/strolch/model/timevalue/ValueTests.java @@ -0,0 +1,81 @@ +package li.strolch.model.timevalue; + +import static org.junit.Assert.assertEquals; + +import java.util.HashSet; +import java.util.Set; + +import li.strolch.model.timevalue.IValue; +import li.strolch.model.timevalue.impl.AString; +import li.strolch.model.timevalue.impl.DoubleValue; +import li.strolch.model.timevalue.impl.IntegerValue; +import li.strolch.model.timevalue.impl.StringSetValue; + +import org.junit.Test; + +public class ValueTests { + + /** + * check, that adding the inverse results in the neutral element (=0) + */ + @Test + public void testDoubleInverse() { + DoubleValue value = new DoubleValue(10.0d); + DoubleValue inverse = value.getInverse(); + assertEquals(Double.valueOf(-10.0d), inverse.getValue()); + assertEquals(Double.valueOf(0), value.add(inverse.getValue()) + .getValue()); + } + + /** + * check, that adding the inverse results in the neutral element (=0) + */ + @Test + public void testIntegerInverse() { + IntegerValue value = new IntegerValue(10); + IntegerValue inverse = value.getInverse(); + assertEquals(Integer.valueOf(-10), inverse.getValue()); + assertEquals(Integer.valueOf(0), value.add(inverse.getValue()) + .getValue()); + } + + /** + * check, that adding the inverse results in the neutral element (empty Set) + */ + @Test + public void testStringSetInverse() { + Set aStrings = new HashSet(); + for (int i = 0; i < 10; i++) { + aStrings.add(new AString("string " + i)); + } + IValue> value = new StringSetValue(aStrings); + IValue> inverse = value.getInverse(); + assertEquals(true, value.matches(inverse.getInverse())); + assertEquals(0, value.add(inverse.getValue()).getValue().size()); + } + + /** + * check, that the difference left is as expected + */ + @Test + public void testStringSetNearInverse() { + + Set aStrings1 = new HashSet(); + for (int i = 0; i < 10; i++) { + aStrings1.add(new AString("string " + i)); + } + IValue> value1 = new StringSetValue(aStrings1); + + Set aStrings2 = new HashSet(); + for (int i = 0; i < 9; i++) { + aStrings2.add(new AString("string " + i, true)); + } + IValue> value2 = new StringSetValue(aStrings2); + + assertEquals(false, value1.matches(value2)); + assertEquals(1, value1.add(value2.getValue()).getValue().size()); + assertEquals(10, value1.add(value2.getInverse().getValue()).getValue() + .size()); + } + +} From 487ad3e8260fb095a54b1d4ed0514274e3df4d67 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 21 Jan 2013 18:39:11 +0100 Subject: [PATCH 10/88] Fefactored xml parsing and writing to no longer depend on JDom. Now only basic Java XML is used. --- pom.xml | 7 ----- .../strolch/model/AbstractStrolchElement.java | 14 +++++----- .../model/GroupedParameterizedElement.java | 15 +++++------ src/main/java/li/strolch/model/Locator.java | 1 - src/main/java/li/strolch/model/Order.java | 20 +++++++------- .../java/li/strolch/model/ParameterBag.java | 9 ++++--- .../strolch/model/ParameterizedElement.java | 16 +++++------ src/main/java/li/strolch/model/Resource.java | 10 +++---- .../java/li/strolch/model/StrolchElement.java | 9 +++++-- .../model/parameter/AbstractParameter.java | 27 +++++++++---------- .../model/parameter/BooleanParameter.java | 7 +++-- .../model/parameter/DateParameter.java | 7 +++-- .../model/parameter/FloatParameter.java | 7 +++-- .../model/parameter/IntegerParameter.java | 7 +++-- .../model/parameter/LongParameter.java | 7 +++-- .../model/parameter/StringListParameter.java | 7 +++-- .../model/parameter/StringParameter.java | 7 +++-- .../model/timevalue/impl/StringSetValue.java | 2 +- .../model/timedstate/TimeStateTest.java | 2 -- .../timevalue/FloatTimeVariableTest.java | 3 --- .../timevalue/IntegerTimeVariableTest.java | 3 --- .../timevalue/StringTimeVariableTest.java | 3 --- .../strolch/model/timevalue/ValueTests.java | 1 - 23 files changed, 84 insertions(+), 107 deletions(-) diff --git a/pom.xml b/pom.xml index db66be151..f4e48c423 100644 --- a/pom.xml +++ b/pom.xml @@ -96,13 +96,6 @@ test - - - dom4j - dom4j - 1.6 - - junit diff --git a/src/main/java/li/strolch/model/AbstractStrolchElement.java b/src/main/java/li/strolch/model/AbstractStrolchElement.java index 3bff1ca58..97829e99a 100644 --- a/src/main/java/li/strolch/model/AbstractStrolchElement.java +++ b/src/main/java/li/strolch/model/AbstractStrolchElement.java @@ -24,7 +24,7 @@ package li.strolch.model; import li.strolch.exception.StrolchException; import li.strolch.model.Locator.LocatorBuilder; -import org.dom4j.Element; +import org.w3c.dom.Element; /** * @author Robert von Burg @@ -113,9 +113,9 @@ public abstract class AbstractStrolchElement implements StrolchElement { } protected void fillElement(Element element) { - element.addAttribute("Id", getId()); - element.addAttribute("Name", getName()); - element.addAttribute("Type", getType()); + element.setAttribute("Id", getId()); + element.setAttribute("Name", getName()); + element.setAttribute("Type", getType()); } /** @@ -124,14 +124,14 @@ public abstract class AbstractStrolchElement implements StrolchElement { * @param element */ protected void fromDom(Element element) { - String id = element.attributeValue("Id"); - String name = element.attributeValue("Name"); + String id = element.getAttribute("Id"); + String name = element.getAttribute("Name"); if (id != null && name != null) { setId(id); setName(name); } else { - throw new StrolchException("Check the values of the element: " + element.getName() + throw new StrolchException("Check the values of the element: " + element.getNodeName() + " either id or name attribute is null!"); } } diff --git a/src/main/java/li/strolch/model/GroupedParameterizedElement.java b/src/main/java/li/strolch/model/GroupedParameterizedElement.java index e5cf3bd29..16c936349 100644 --- a/src/main/java/li/strolch/model/GroupedParameterizedElement.java +++ b/src/main/java/li/strolch/model/GroupedParameterizedElement.java @@ -24,14 +24,14 @@ package li.strolch.model; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Set; import li.strolch.exception.StrolchException; import li.strolch.model.parameter.Parameter; -import org.dom4j.Element; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; import ch.eitchnet.utils.helper.StringHelper; @@ -222,16 +222,15 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement } @Override - @SuppressWarnings("unchecked") public void fromDom(Element element) { super.fromDom(element); - String type = element.attributeValue("Type"); + String type = element.getAttribute("Type"); setType(type); - List bags = element.elements("ParameterBag"); - for (Element bagElement : bags) { - + NodeList bags = element.getElementsByTagName("ParameterBag"); + for (int i = 0; i < bags.getLength(); i++) { + Element bagElement = (Element) bags.item(i); ParameterBag bag = new ParameterBag(bagElement); addParameterBag(bag); } @@ -243,7 +242,7 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement if (this.parameterBagMap != null) { for (ParameterBag bag : this.parameterBagMap.values()) { - element.add(bag.toDom()); + element.appendChild(bag.toDom(element.getOwnerDocument())); } } } diff --git a/src/main/java/li/strolch/model/Locator.java b/src/main/java/li/strolch/model/Locator.java index 893440eb7..cff524545 100644 --- a/src/main/java/li/strolch/model/Locator.java +++ b/src/main/java/li/strolch/model/Locator.java @@ -28,7 +28,6 @@ import java.util.Iterator; import java.util.List; import li.strolch.exception.StrolchException; - import ch.eitchnet.utils.helper.StringHelper; /** diff --git a/src/main/java/li/strolch/model/Order.java b/src/main/java/li/strolch/model/Order.java index 3e3d880cd..91061facd 100644 --- a/src/main/java/li/strolch/model/Order.java +++ b/src/main/java/li/strolch/model/Order.java @@ -21,10 +21,10 @@ */ package li.strolch.model; -import li.strolch.model.Locator.LocatorBuilder; +import org.w3c.dom.Document; +import org.w3c.dom.Element; -import org.dom4j.Element; -import org.dom4j.tree.DefaultElement; +import li.strolch.model.Locator.LocatorBuilder; /** * The Order is an object used in the EDF to transfer data from one range to another. Orders are not to be thought of as @@ -91,8 +91,8 @@ public class Order extends GroupedParameterizedElement { public Order(Element element) { super.fromDom(element); - String date = element.attributeValue("Date"); - String state = element.attributeValue("State"); + String date = element.getAttribute("Date"); + String state = element.getAttribute("State"); // TODO the format should be globally configured if (date == null || date.isEmpty()) { @@ -139,17 +139,17 @@ public class Order extends GroupedParameterizedElement { } /** - * @see li.strolch.StrolchElement.datalandscape.element.IEdpElement#toDom() + * @see li.strolch.StrolchElement.datalandscape.element.IEdpElement#toDom(Document) */ @Override - public Element toDom() { + public Element toDom(Document doc) { - Element orderElement = new DefaultElement("Order"); + Element orderElement = doc.createElement("Order"); fillElement(orderElement); // TODO the format should be globally configured - orderElement.addAttribute("Date", Long.toString(this.date)); - orderElement.addAttribute("State", this.state.toString()); + orderElement.setAttribute("Date", Long.toString(this.date)); + orderElement.setAttribute("State", this.state.toString()); return orderElement; } diff --git a/src/main/java/li/strolch/model/ParameterBag.java b/src/main/java/li/strolch/model/ParameterBag.java index b110fc3af..ec1d7b4f0 100644 --- a/src/main/java/li/strolch/model/ParameterBag.java +++ b/src/main/java/li/strolch/model/ParameterBag.java @@ -21,8 +21,9 @@ */ package li.strolch.model; -import org.dom4j.Element; -import org.dom4j.tree.DefaultElement; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + /** * @author Robert von Burg @@ -65,9 +66,9 @@ public class ParameterBag extends ParameterizedElement { } @Override - public Element toDom() { + public Element toDom(Document doc) { - Element element = new DefaultElement("ParameterBag"); + Element element = doc.createElement("ParameterBag"); fillElement(element); diff --git a/src/main/java/li/strolch/model/ParameterizedElement.java b/src/main/java/li/strolch/model/ParameterizedElement.java index 21ed6feb5..318585663 100644 --- a/src/main/java/li/strolch/model/ParameterizedElement.java +++ b/src/main/java/li/strolch/model/ParameterizedElement.java @@ -39,7 +39,8 @@ import li.strolch.model.parameter.LongParameter; import li.strolch.model.parameter.Parameter; import li.strolch.model.parameter.StringParameter; -import org.dom4j.Element; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; import ch.eitchnet.utils.helper.StringHelper; @@ -207,15 +208,14 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { protected void fromDom(Element element) { super.fromDom(element); - String type = element.attributeValue("Type"); + String type = element.getAttribute("Type"); setType(type); // add all the parameters - @SuppressWarnings("unchecked") - List parameterElements = element.elements("Parameter"); - for (Object object : parameterElements) { - Element paramElement = (Element) object; - String paramtype = paramElement.attributeValue("Type"); + NodeList parameterElements = element.getElementsByTagName("Parameter"); + for (int i = 0; i < parameterElements.getLength(); i++) { + Element paramElement = (Element) parameterElements.item(i); + String paramtype = paramElement.getAttribute("Type"); if (paramtype.equals(StringParameter.TYPE)) { StringParameter param = new StringParameter(paramElement); @@ -247,7 +247,7 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { if (this.parameterMap != null) { for (Parameter parameter : this.parameterMap.values()) { - element.add(parameter.toDom()); + element.appendChild(parameter.toDom(element.getOwnerDocument())); } } } diff --git a/src/main/java/li/strolch/model/Resource.java b/src/main/java/li/strolch/model/Resource.java index 09d1718d9..8588431fa 100644 --- a/src/main/java/li/strolch/model/Resource.java +++ b/src/main/java/li/strolch/model/Resource.java @@ -21,10 +21,10 @@ */ package li.strolch.model; -import li.strolch.model.Locator.LocatorBuilder; +import org.w3c.dom.Document; +import org.w3c.dom.Element; -import org.dom4j.Element; -import org.dom4j.tree.DefaultElement; +import li.strolch.model.Locator.LocatorBuilder; /** * @author Robert von Burg @@ -62,9 +62,9 @@ public class Resource extends GroupedParameterizedElement { } @Override - public Element toDom() { + public Element toDom(Document doc) { - Element element = new DefaultElement("Resource"); + Element element = doc.createElement("Resource"); fillElement(element); return element; diff --git a/src/main/java/li/strolch/model/StrolchElement.java b/src/main/java/li/strolch/model/StrolchElement.java index 98be6970c..a0c9fb2ea 100644 --- a/src/main/java/li/strolch/model/StrolchElement.java +++ b/src/main/java/li/strolch/model/StrolchElement.java @@ -23,7 +23,8 @@ package li.strolch.model; import java.io.Serializable; -import org.dom4j.Element; +import org.w3c.dom.Document; +import org.w3c.dom.Element; /** * @author Robert von Burg @@ -85,9 +86,13 @@ public interface StrolchElement extends Serializable, Comparable /** * Returns a dom4j {@link Element} object which is an XML representation of this object * + * @param doc + * the document to which this element is being written. The client should not append to the document, the + * caller will perform this as needed + * * @return */ - public Element toDom(); + public Element toDom(Document doc); /** * Returns the type of this {@link StrolchElement} diff --git a/src/main/java/li/strolch/model/parameter/AbstractParameter.java b/src/main/java/li/strolch/model/parameter/AbstractParameter.java index e51d2daea..ea4d9cdad 100644 --- a/src/main/java/li/strolch/model/parameter/AbstractParameter.java +++ b/src/main/java/li/strolch/model/parameter/AbstractParameter.java @@ -21,15 +21,14 @@ */ package li.strolch.model.parameter; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + import li.strolch.exception.StrolchException; import li.strolch.model.AbstractStrolchElement; import li.strolch.model.Locator; import li.strolch.model.Locator.LocatorBuilder; import li.strolch.model.ParameterizedElement; - -import org.dom4j.Element; -import org.dom4j.tree.DefaultElement; - import ch.eitchnet.utils.helper.StringHelper; /** @@ -113,18 +112,18 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem } @Override - public Element toDom() { - Element element = new DefaultElement("Parameter"); + public Element toDom(Document doc) { + Element element = doc.createElement("Parameter"); fillElement(element); - element.addAttribute("Value", getValueAsString()); + element.setAttribute("Value", getValueAsString()); if (!this.interpretation.equals(Parameter.INTERPRETATION_NONE)) - element.addAttribute("Interpretation", this.interpretation); + element.setAttribute("Interpretation", this.interpretation); if (!this.uom.equals(Parameter.UOM_NONE)) - element.addAttribute("Uom", this.uom); + element.setAttribute("Uom", this.uom); if (this.hidden) - element.addAttribute("Hidden", Boolean.toString(this.hidden)); + element.setAttribute("Hidden", Boolean.toString(this.hidden)); return element; } @@ -134,16 +133,16 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem super.fromDom(element); - String typeS = element.attributeValue("Type"); + String typeS = element.getAttribute("Type"); if (StringHelper.isEmpty(typeS)) { throw new StrolchException("Type must be set on element with id " + this.id); } else if (!typeS.equals(getType())) { throw new StrolchException(getClass().getSimpleName() + " must have type " + getType() + ", not: " + typeS); } - String interpretation = element.attributeValue("Interpretation"); - String isHidden = element.attributeValue("Hidden"); - String uom = element.attributeValue("Uom"); + String interpretation = element.getAttribute("Interpretation"); + String isHidden = element.getAttribute("Hidden"); + String uom = element.getAttribute("Uom"); setInterpretation(interpretation); setUom(uom); diff --git a/src/main/java/li/strolch/model/parameter/BooleanParameter.java b/src/main/java/li/strolch/model/parameter/BooleanParameter.java index 4d6921ee9..97b748a06 100644 --- a/src/main/java/li/strolch/model/parameter/BooleanParameter.java +++ b/src/main/java/li/strolch/model/parameter/BooleanParameter.java @@ -21,10 +21,9 @@ */ package li.strolch.model.parameter; +import org.w3c.dom.Element; + import li.strolch.exception.StrolchException; - -import org.dom4j.Element; - import ch.eitchnet.utils.helper.StringHelper; /** @@ -64,7 +63,7 @@ public class BooleanParameter extends AbstractParameter { public BooleanParameter(Element element) { super.fromDom(element); - String valueS = element.attributeValue("Value"); + String valueS = element.getAttribute("Value"); if (StringHelper.isEmpty(valueS)) { throw new StrolchException("No value defined for " + this.id); } diff --git a/src/main/java/li/strolch/model/parameter/DateParameter.java b/src/main/java/li/strolch/model/parameter/DateParameter.java index 3e0667861..1986958a8 100644 --- a/src/main/java/li/strolch/model/parameter/DateParameter.java +++ b/src/main/java/li/strolch/model/parameter/DateParameter.java @@ -23,10 +23,9 @@ package li.strolch.model.parameter; import java.text.DateFormat; +import org.w3c.dom.Element; + import li.strolch.exception.StrolchException; - -import org.dom4j.Element; - import ch.eitchnet.utils.helper.StringHelper; /** @@ -66,7 +65,7 @@ public class DateParameter extends AbstractParameter { public DateParameter(Element element) { super.fromDom(element); - String valueS = element.attributeValue("Value"); + String valueS = element.getAttribute("Value"); if (StringHelper.isEmpty(valueS)) { throw new StrolchException("No value defined for " + this.id); } diff --git a/src/main/java/li/strolch/model/parameter/FloatParameter.java b/src/main/java/li/strolch/model/parameter/FloatParameter.java index e313828ab..8683a2a19 100644 --- a/src/main/java/li/strolch/model/parameter/FloatParameter.java +++ b/src/main/java/li/strolch/model/parameter/FloatParameter.java @@ -21,10 +21,9 @@ */ package li.strolch.model.parameter; +import org.w3c.dom.Element; + import li.strolch.exception.StrolchException; - -import org.dom4j.Element; - import ch.eitchnet.utils.helper.StringHelper; /** @@ -66,7 +65,7 @@ public class FloatParameter extends AbstractParameter { public FloatParameter(Element element) { super.fromDom(element); - String valueS = element.attributeValue("Value"); + String valueS = element.getAttribute("Value"); if (StringHelper.isEmpty(valueS)) { throw new StrolchException("No value defined for " + this.id); } diff --git a/src/main/java/li/strolch/model/parameter/IntegerParameter.java b/src/main/java/li/strolch/model/parameter/IntegerParameter.java index 40d0315c3..74333fe14 100644 --- a/src/main/java/li/strolch/model/parameter/IntegerParameter.java +++ b/src/main/java/li/strolch/model/parameter/IntegerParameter.java @@ -21,10 +21,9 @@ */ package li.strolch.model.parameter; +import org.w3c.dom.Element; + import li.strolch.exception.StrolchException; - -import org.dom4j.Element; - import ch.eitchnet.utils.helper.StringHelper; /** @@ -65,7 +64,7 @@ public class IntegerParameter extends AbstractParameter { public IntegerParameter(Element element) { super.fromDom(element); - String valueS = element.attributeValue("Value"); + String valueS = element.getAttribute("Value"); if (StringHelper.isEmpty(valueS)) { throw new StrolchException("No value defined for " + this.id); } diff --git a/src/main/java/li/strolch/model/parameter/LongParameter.java b/src/main/java/li/strolch/model/parameter/LongParameter.java index 1eb0fc0bf..68059d34c 100644 --- a/src/main/java/li/strolch/model/parameter/LongParameter.java +++ b/src/main/java/li/strolch/model/parameter/LongParameter.java @@ -21,10 +21,9 @@ */ package li.strolch.model.parameter; +import org.w3c.dom.Element; + import li.strolch.exception.StrolchException; - -import org.dom4j.Element; - import ch.eitchnet.utils.helper.StringHelper; /** @@ -65,7 +64,7 @@ public class LongParameter extends AbstractParameter { public LongParameter(Element element) { super.fromDom(element); - String valueS = element.attributeValue("Value"); + String valueS = element.getAttribute("Value"); if (StringHelper.isEmpty(valueS)) { throw new StrolchException("No value defined for " + this.id); } diff --git a/src/main/java/li/strolch/model/parameter/StringListParameter.java b/src/main/java/li/strolch/model/parameter/StringListParameter.java index c5dc35056..77819cd42 100644 --- a/src/main/java/li/strolch/model/parameter/StringListParameter.java +++ b/src/main/java/li/strolch/model/parameter/StringListParameter.java @@ -27,11 +27,10 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; +import org.w3c.dom.Element; + import li.strolch.exception.StrolchException; import li.strolch.model.StrolchElement; - -import org.dom4j.Element; - import ch.eitchnet.utils.helper.StringHelper; /** @@ -72,7 +71,7 @@ public class StringListParameter extends AbstractParameter> impleme public StringListParameter(Element element) { super.fromDom(element); - String valueS = element.attributeValue("Value"); + String valueS = element.getAttribute("Value"); if (StringHelper.isEmpty(valueS)) { throw new StrolchException("No value defined for " + this.id); } diff --git a/src/main/java/li/strolch/model/parameter/StringParameter.java b/src/main/java/li/strolch/model/parameter/StringParameter.java index 9cf021c6a..7f0de4e79 100644 --- a/src/main/java/li/strolch/model/parameter/StringParameter.java +++ b/src/main/java/li/strolch/model/parameter/StringParameter.java @@ -21,10 +21,9 @@ */ package li.strolch.model.parameter; +import org.w3c.dom.Element; + import li.strolch.exception.StrolchException; - -import org.dom4j.Element; - import ch.eitchnet.utils.helper.StringHelper; /** @@ -66,7 +65,7 @@ public class StringParameter extends AbstractParameter { public StringParameter(Element element) { super.fromDom(element); - String valueS = element.attributeValue("Value"); + String valueS = element.getAttribute("Value"); if (StringHelper.isEmpty(valueS)) { throw new StrolchException("No value defined for " + this.id); } diff --git a/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java b/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java index 499211bfc..b298264c4 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java +++ b/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java @@ -1,7 +1,7 @@ package li.strolch.model.timevalue.impl; -import java.util.HashSet; import java.util.Collections; +import java.util.HashSet; import java.util.Iterator; import java.util.Set; diff --git a/src/test/java/li/strolch/model/timedstate/TimeStateTest.java b/src/test/java/li/strolch/model/timedstate/TimeStateTest.java index f2525094c..9ef800718 100644 --- a/src/test/java/li/strolch/model/timedstate/TimeStateTest.java +++ b/src/test/java/li/strolch/model/timedstate/TimeStateTest.java @@ -1,8 +1,6 @@ package li.strolch.model.timedstate; import junit.framework.Assert; -import li.strolch.model.timedstate.ITimedState; -import li.strolch.model.timedstate.TimedState; import li.strolch.model.timevalue.ITimeValue; import li.strolch.model.timevalue.IValueChange; import li.strolch.model.timevalue.impl.DoubleValue; diff --git a/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java b/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java index e8fe45670..b3bb6d2df 100644 --- a/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java +++ b/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java @@ -4,9 +4,6 @@ import java.util.Collection; import java.util.SortedSet; import junit.framework.Assert; -import li.strolch.model.timevalue.ITimeValue; -import li.strolch.model.timevalue.IValue; -import li.strolch.model.timevalue.IValueChange; import li.strolch.model.timevalue.impl.DoubleValue; import li.strolch.model.timevalue.impl.TimeVariable; import li.strolch.model.timevalue.impl.ValueChange; diff --git a/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java b/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java index 9af523bb1..601c8fc77 100644 --- a/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java +++ b/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java @@ -6,9 +6,6 @@ import java.util.Map; import java.util.SortedSet; import junit.framework.Assert; -import li.strolch.model.timevalue.ITimeValue; -import li.strolch.model.timevalue.IValue; -import li.strolch.model.timevalue.IValueChange; import li.strolch.model.timevalue.impl.IntegerValue; import li.strolch.model.timevalue.impl.TimeVariable; import li.strolch.model.timevalue.impl.ValueChange; diff --git a/src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java b/src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java index 031d2de0e..10fa4d92b 100644 --- a/src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java +++ b/src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java @@ -8,9 +8,6 @@ import java.util.Set; import java.util.SortedSet; import junit.framework.Assert; -import li.strolch.model.timevalue.ITimeValue; -import li.strolch.model.timevalue.IValue; -import li.strolch.model.timevalue.IValueChange; import li.strolch.model.timevalue.impl.AString; import li.strolch.model.timevalue.impl.StringSetValue; import li.strolch.model.timevalue.impl.TimeVariable; diff --git a/src/test/java/li/strolch/model/timevalue/ValueTests.java b/src/test/java/li/strolch/model/timevalue/ValueTests.java index 072262fe6..f88a0512b 100644 --- a/src/test/java/li/strolch/model/timevalue/ValueTests.java +++ b/src/test/java/li/strolch/model/timevalue/ValueTests.java @@ -5,7 +5,6 @@ import static org.junit.Assert.assertEquals; import java.util.HashSet; import java.util.Set; -import li.strolch.model.timevalue.IValue; import li.strolch.model.timevalue.impl.AString; import li.strolch.model.timevalue.impl.DoubleValue; import li.strolch.model.timevalue.impl.IntegerValue; From a8d8702464e1c78bd13ed81f71621d9f5231d787 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 30 Jan 2013 14:54:33 +0100 Subject: [PATCH 11/88] Update pom.xml Added distribution management to deploy to nexus.eitchnet.ch --- pom.xml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pom.xml b/pom.xml index f4e48c423..d3585923c 100644 --- a/pom.xml +++ b/pom.xml @@ -73,6 +73,19 @@ codehausSnapshots Codehaus Snapshots http://snapshots.maven.codehaus.org/maven2 default ... --> + + + + deployment + Internal Releases + http://nexus.eitchnet.ch/content/repositories/releases/ + + + deployment + Internal Releases + http://nexus.eitchnet.ch/nexus/content/repositories/snapshots/ + + From 8a661ff04e951fc0cee576131ca453a04fd00630 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 30 Jan 2013 15:02:53 +0100 Subject: [PATCH 12/88] Update pom.xml Added distribution management to deploy to nexus.eitchnet.ch (fixed wrong URL) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d3585923c..b3f1d21b5 100644 --- a/pom.xml +++ b/pom.xml @@ -83,7 +83,7 @@ deployment Internal Releases - http://nexus.eitchnet.ch/nexus/content/repositories/snapshots/ + http://nexus.eitchnet.ch/content/repositories/snapshots/ From c085625cce10a88757f5a948f28c0d4469209ed1 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 31 Jan 2013 19:08:26 +0100 Subject: [PATCH 13/88] [Minor] JavaDoc comments and file headers fixed some JavaDoc comments and file headers --- .../java/li/strolch/model/AbstractStrolchElement.java | 2 +- src/main/java/li/strolch/model/ParameterBag.java | 2 +- src/main/java/li/strolch/model/StrolchElement.java | 2 +- .../java/li/strolch/model/parameter/ListParameter.java | 8 ++++---- src/test/java/li/strolch/test/model/ModelTestHelper.java | 8 ++++---- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/li/strolch/model/AbstractStrolchElement.java b/src/main/java/li/strolch/model/AbstractStrolchElement.java index 97829e99a..8a34e27a0 100644 --- a/src/main/java/li/strolch/model/AbstractStrolchElement.java +++ b/src/main/java/li/strolch/model/AbstractStrolchElement.java @@ -119,7 +119,7 @@ public abstract class AbstractStrolchElement implements StrolchElement { } /** - * Builds the fields of this {@link StrolchElement} from a Dom4j {@link Element} + * Builds the fields of this {@link StrolchElement} from a {@link Element} * * @param element */ diff --git a/src/main/java/li/strolch/model/ParameterBag.java b/src/main/java/li/strolch/model/ParameterBag.java index ec1d7b4f0..d29d25d86 100644 --- a/src/main/java/li/strolch/model/ParameterBag.java +++ b/src/main/java/li/strolch/model/ParameterBag.java @@ -3,7 +3,7 @@ * * All rights reserved. * - * This file is part of the XXX. + * This file is part of the li.strolch.model. * * li.strolch.model is free software: you can redistribute * it and/or modify it under the terms of the GNU General Public License as diff --git a/src/main/java/li/strolch/model/StrolchElement.java b/src/main/java/li/strolch/model/StrolchElement.java index a0c9fb2ea..916fff125 100644 --- a/src/main/java/li/strolch/model/StrolchElement.java +++ b/src/main/java/li/strolch/model/StrolchElement.java @@ -84,7 +84,7 @@ public interface StrolchElement extends Serializable, Comparable public long getDbid(); /** - * Returns a dom4j {@link Element} object which is an XML representation of this object + * Returns an {@link Element} object which is an XML representation of this object * * @param doc * the document to which this element is being written. The client should not append to the document, the diff --git a/src/main/java/li/strolch/model/parameter/ListParameter.java b/src/main/java/li/strolch/model/parameter/ListParameter.java index 192bedf36..3cea4844c 100644 --- a/src/main/java/li/strolch/model/parameter/ListParameter.java +++ b/src/main/java/li/strolch/model/parameter/ListParameter.java @@ -3,20 +3,20 @@ * * All rights reserved. * - * This file is part of the XXX. + * This file is part of the li.strolch.model. * - * XXX is free software: you can redistribute + * li.strolch.model is free software: you can redistribute * it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, * or (at your option) any later version. * - * XXX is distributed in the hope that it will + * li.strolch.model 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 General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with XXX. If not, see + * along with li.strolch.model. If not, see * . */ package li.strolch.model.parameter; diff --git a/src/test/java/li/strolch/test/model/ModelTestHelper.java b/src/test/java/li/strolch/test/model/ModelTestHelper.java index e11e27f72..20dbb24e2 100644 --- a/src/test/java/li/strolch/test/model/ModelTestHelper.java +++ b/src/test/java/li/strolch/test/model/ModelTestHelper.java @@ -3,20 +3,20 @@ * * All rights reserved. * - * This file is part of the XXX. + * This file is part of the li.strolch.model. * - * XXX is free software: you can redistribute + * li.strolch.model is free software: you can redistribute * it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, * or (at your option) any later version. * - * XXX is distributed in the hope that it will + * li.strolch.model 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 General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with XXX. If not, see + * along with li.strolch.model. If not, see * . */ package li.strolch.test.model; From 2a6ec4cf0c730c67eb111cbd487035f19871ab00 Mon Sep 17 00:00:00 2001 From: Martin Date: Sun, 31 Mar 2013 13:57:57 +0200 Subject: [PATCH 14/88] Added Serializable interface to value model objects --- .../li/strolch/model/timedstate/ITimedState.java | 2 +- .../java/li/strolch/model/timedstate/TimedState.java | 8 +++++--- .../java/li/strolch/model/timevalue/ITimeValue.java | 2 +- .../li/strolch/model/timevalue/ITimeVariable.java | 10 +++++++++- src/main/java/li/strolch/model/timevalue/IValue.java | 2 +- .../li/strolch/model/timevalue/IValueChange.java | 2 +- .../li/strolch/model/timevalue/impl/AString.java | 10 +++++++--- .../li/strolch/model/timevalue/impl/DoubleValue.java | 8 ++++++-- .../strolch/model/timevalue/impl/IntegerValue.java | 8 ++++++-- .../strolch/model/timevalue/impl/StringSetValue.java | 8 +++++--- .../li/strolch/model/timevalue/impl/TimeValue.java | 8 ++++++-- .../strolch/model/timevalue/impl/TimeVariable.java | 12 ++++++++++-- .../li/strolch/model/timevalue/impl/ValueChange.java | 8 ++++++-- 13 files changed, 64 insertions(+), 24 deletions(-) diff --git a/src/main/java/li/strolch/model/timedstate/ITimedState.java b/src/main/java/li/strolch/model/timedstate/ITimedState.java index a5d0a2744..c8bb64538 100644 --- a/src/main/java/li/strolch/model/timedstate/ITimedState.java +++ b/src/main/java/li/strolch/model/timedstate/ITimedState.java @@ -8,7 +8,7 @@ import li.strolch.model.timevalue.IValueChange; /** * A time based state characterized by a {@link IValue} object implementation. * - * @author martin_smock + * @author Martin Smock * * @param * IValue implementation representing the state at a given time diff --git a/src/main/java/li/strolch/model/timedstate/TimedState.java b/src/main/java/li/strolch/model/timedstate/TimedState.java index f5dcfd089..f5e9e5d95 100644 --- a/src/main/java/li/strolch/model/timedstate/TimedState.java +++ b/src/main/java/li/strolch/model/timedstate/TimedState.java @@ -1,5 +1,6 @@ package li.strolch.model.timedstate; +import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -11,13 +12,14 @@ import li.strolch.model.timevalue.IValue; import li.strolch.model.timevalue.IValueChange; import li.strolch.model.timevalue.impl.TimeVariable; - /** - * @author martin_smock + * @author Martin Smock */ @SuppressWarnings("rawtypes") -public class TimedState implements ITimedState { +public class TimedState implements ITimedState, Serializable { + private static final long serialVersionUID = 1L; + private ITimeVariable timeVariable = new TimeVariable(); @Override diff --git a/src/main/java/li/strolch/model/timevalue/ITimeValue.java b/src/main/java/li/strolch/model/timevalue/ITimeValue.java index 1df712d26..f6dd1187b 100644 --- a/src/main/java/li/strolch/model/timevalue/ITimeValue.java +++ b/src/main/java/li/strolch/model/timevalue/ITimeValue.java @@ -5,7 +5,7 @@ import li.strolch.model.timevalue.impl.TimeVariable; /** * Interface for timed value objects to be used with the {@link TimeVariable} * - * @author martin_smock + * @author Martin Smock * * @param * the backing value of the timed value object diff --git a/src/main/java/li/strolch/model/timevalue/ITimeVariable.java b/src/main/java/li/strolch/model/timevalue/ITimeVariable.java index 4df20ff26..f1bc79261 100644 --- a/src/main/java/li/strolch/model/timevalue/ITimeVariable.java +++ b/src/main/java/li/strolch/model/timevalue/ITimeVariable.java @@ -1,12 +1,13 @@ package li.strolch.model.timevalue; import java.util.Collection; +import java.util.SortedSet; /** * A timed variable storing a ordered sequence of {@link ITimeValue} objects * modeling a time evolution of a quantity. * - * @author martin_smock + * @author Martin Smock * * @param * the backing value of the timed value object @@ -59,6 +60,13 @@ public interface ITimeVariable { */ Collection> getPastValues(final Long time); + /** + * Get all {@link ITimeValue} objects + * + * @return a defensive copy of the {@link ITimeValue}s + */ + SortedSet> getValues(); + /** * removes {@link ITimeValue} objects from the sequence, where the successor * matches value. I.e considering a pair of adjacent {@link ITimeValue} diff --git a/src/main/java/li/strolch/model/timevalue/IValue.java b/src/main/java/li/strolch/model/timevalue/IValue.java index e3e4444ab..2c1cd52f2 100644 --- a/src/main/java/li/strolch/model/timevalue/IValue.java +++ b/src/main/java/li/strolch/model/timevalue/IValue.java @@ -4,7 +4,7 @@ package li.strolch.model.timevalue; * A value object defining some basic algebraic operations. Mathematically * speaking {@link IValue} objects define a group with a addition operation. * - * @author martin_smock + * @author Martin Smock * * @param * any object for which a (generalized) add operation can be defined. diff --git a/src/main/java/li/strolch/model/timevalue/IValueChange.java b/src/main/java/li/strolch/model/timevalue/IValueChange.java index ec25d5b18..c6283be06 100644 --- a/src/main/java/li/strolch/model/timevalue/IValueChange.java +++ b/src/main/java/li/strolch/model/timevalue/IValueChange.java @@ -4,7 +4,7 @@ package li.strolch.model.timevalue; * Interface for operators to be used to change the values of {@link ITimeValue} * in a {@link ITimeVariable}. * - * @author martin_smock + * @author Martin Smock */ @SuppressWarnings("rawtypes") public interface IValueChange { diff --git a/src/main/java/li/strolch/model/timevalue/impl/AString.java b/src/main/java/li/strolch/model/timevalue/impl/AString.java index cd952facc..39ae3d69d 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/AString.java +++ b/src/main/java/li/strolch/model/timevalue/impl/AString.java @@ -1,13 +1,17 @@ package li.strolch.model.timevalue.impl; +import java.io.Serializable; + /** * Wrapper for java.util.String object defining a inverse to support algebraic * operations. * - * @author martin_smock + * @author Martin Smock */ -public class AString { - +public class AString implements Serializable { + + private static final long serialVersionUID = 1L; + private final String string; private final boolean inverse; diff --git a/src/main/java/li/strolch/model/timevalue/impl/DoubleValue.java b/src/main/java/li/strolch/model/timevalue/impl/DoubleValue.java index f4a73fdff..c8d2f29e5 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/DoubleValue.java +++ b/src/main/java/li/strolch/model/timevalue/impl/DoubleValue.java @@ -1,14 +1,18 @@ package li.strolch.model.timevalue.impl; +import java.io.Serializable; + import li.strolch.model.timevalue.ITimeValue; import li.strolch.model.timevalue.IValue; /** * {@link IValue} implementation to work with Double valued {@link ITimeValue} objects * - * @author martin_smock + * @author Martin Smock */ -public class DoubleValue implements IValue { +public class DoubleValue implements IValue, Serializable { + + private static final long serialVersionUID = 1L; public static final DoubleValue NEUTRAL = new DoubleValue(0.0d); diff --git a/src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java b/src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java index 6b1964318..61b622758 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java +++ b/src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java @@ -1,5 +1,7 @@ package li.strolch.model.timevalue.impl; +import java.io.Serializable; + import li.strolch.model.timevalue.ITimeValue; import li.strolch.model.timevalue.IValue; @@ -7,9 +9,11 @@ import li.strolch.model.timevalue.IValue; * {@link IValue} implementation to work with Integer valued {@link ITimeValue} * objects * - * @author martin_smock + * @author Martin Smock */ -public class IntegerValue implements IValue { +public class IntegerValue implements IValue, Serializable { + + private static final long serialVersionUID = 1L; public static final IntegerValue NEUTRAL = new IntegerValue(0); diff --git a/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java b/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java index b298264c4..6f279c7c3 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java +++ b/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java @@ -1,5 +1,6 @@ package li.strolch.model.timevalue.impl; +import java.io.Serializable; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; @@ -8,15 +9,16 @@ import java.util.Set; import li.strolch.model.timevalue.ITimeValue; import li.strolch.model.timevalue.IValue; - /** * {@link IValue} implementation to work with String valued {@link ITimeValue} * objects. Since a java.util.String object does not define a inverse, a * algebraic {@link AString} wrapper is used. * - * @author martin_smock + * @author Martin Smock */ -public class StringSetValue implements IValue> { +public class StringSetValue implements IValue>, Serializable { + + private static final long serialVersionUID = 1L; private static Set neu = Collections.emptySet(); public static final IValue> NEUTRAL = new StringSetValue(neu); diff --git a/src/main/java/li/strolch/model/timevalue/impl/TimeValue.java b/src/main/java/li/strolch/model/timevalue/impl/TimeValue.java index bd14fed55..eca23d69e 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/TimeValue.java +++ b/src/main/java/li/strolch/model/timevalue/impl/TimeValue.java @@ -1,13 +1,17 @@ package li.strolch.model.timevalue.impl; +import java.io.Serializable; + import li.strolch.model.timevalue.ITimeValue; import li.strolch.model.timevalue.IValue; /** - * @author martin_smock + * @author Martin Smock */ @SuppressWarnings("rawtypes") -public class TimeValue implements ITimeValue { +public class TimeValue implements ITimeValue , Serializable { + + private static final long serialVersionUID = 1L; protected final Long time; protected T value; diff --git a/src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java b/src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java index 43a71c63f..34af158a8 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java +++ b/src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java @@ -1,5 +1,6 @@ package li.strolch.model.timevalue.impl; +import java.io.Serializable; import java.util.Collection; import java.util.Iterator; import java.util.SortedSet; @@ -12,11 +13,13 @@ import li.strolch.model.timevalue.IValueChange; /** - * @author martin_smock + * @author Martin Smock */ @SuppressWarnings("rawtypes") -public class TimeVariable implements ITimeVariable { +public class TimeVariable implements ITimeVariable, Serializable { + private static final long serialVersionUID = 1L; + public SortedSet> container = new TreeSet>(); @Override @@ -53,6 +56,11 @@ public class TimeVariable implements ITimeVariable { TimeValue picker = new TimeValue(time, null); return new TreeSet>(container.headSet(picker)); } + + @Override + public SortedSet> getValues() { + return new TreeSet>(container); + } @Override public void applyChange(final IValueChange change) { diff --git a/src/main/java/li/strolch/model/timevalue/impl/ValueChange.java b/src/main/java/li/strolch/model/timevalue/impl/ValueChange.java index 8d7d33664..80ae72579 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/ValueChange.java +++ b/src/main/java/li/strolch/model/timevalue/impl/ValueChange.java @@ -1,14 +1,18 @@ package li.strolch.model.timevalue.impl; +import java.io.Serializable; + import li.strolch.model.timevalue.IValue; import li.strolch.model.timevalue.IValueChange; /** - * @author martin_smock + * @author Martin Smock */ @SuppressWarnings("rawtypes") -public class ValueChange implements IValueChange { +public class ValueChange implements IValueChange, Serializable { + private static final long serialVersionUID = 1L; + protected final Long time; protected final T value; From 9f9f7b0216c44ff654b3b9d25cbc43fdfb034aff Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 16 Sep 2013 07:47:08 +0200 Subject: [PATCH 15/88] [Project] changed Java version frm 1.6 to 1.7 in pom.xml --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index b3f1d21b5..11930e457 100644 --- a/pom.xml +++ b/pom.xml @@ -93,7 +93,7 @@ ch.eitchnet ch.eitchnet.utils - 0.1.0-SNAPSHOT + 0.2.0-SNAPSHOT @@ -134,8 +134,8 @@ maven-compiler-plugin 3.0 - 1.6 - 1.6 + 1.7 + 1.7 From 70258baf7cd28e52458dd21cef6730fdc2cba089 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 23 Oct 2013 20:10:00 +0200 Subject: [PATCH 16/88] [Project] set a parent to li.strolch.parent for easier managing --- pom.xml | 137 +++----------------------------------------------------- 1 file changed, 7 insertions(+), 130 deletions(-) diff --git a/pom.xml b/pom.xml index 11930e457..5c2d28c89 100644 --- a/pom.xml +++ b/pom.xml @@ -2,120 +2,33 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - li.strolch + + li.strolch + li.strolch.parent + 0.1.0-SNAPSHOT + ../li.strolch.parent/pom.xml + + li.strolch.model - 1.0-SNAPSHOT jar li.strolch.model https://github.com/eitch/li.strolch.model - - UTF-8 - - - - 2012 - - - GNU Lesser General Public License - http://www.gnu.org/licenses/lgpl.html - repo - - - - eitchnet.ch - http://blog.eitchnet.ch - - - - eitch - Robert von Vurg - eitch@eitchnet.ch - http://blog.eitchnet.ch - eitchnet.ch - http://blog.eitchnet.ch - - architect - developer - - +1 - - http://localhost - - - Github Issues https://github.com/eitch/li.strolch.model/issues - - scm:git:https://github.com/eitch/li.strolch.model.git scm:git:git@github.com:eitch/li.strolch.model.git https://github.com/eitch/li.strolch.model - - - - - deployment - Internal Releases - http://nexus.eitchnet.ch/content/repositories/releases/ - - - deployment - Internal Releases - http://nexus.eitchnet.ch/content/repositories/snapshots/ - - - - - - ch.eitchnet - ch.eitchnet.utils - 0.2.0-SNAPSHOT - - - - - org.slf4j - slf4j-api - 1.7.2 - - - org.slf4j - slf4j-log4j12 - 1.7.2 - test - - - - - junit - junit - 4.5 - test - @@ -123,58 +36,22 @@ org.apache.maven.plugins maven-eclipse-plugin - 2.9 - - true - true - org.apache.maven.plugins maven-compiler-plugin - 3.0 - - 1.7 - 1.7 - org.apache.maven.plugins maven-source-plugin - 2.1.2 - - - attach-sources - verify - - jar-no-fork - - - - org.apache.maven.plugins maven-jar-plugin - 2.4 - - - - true - true - - - - - org.apache.maven.plugins maven-site-plugin - 2.3 - - UTF-8 - From 6b12b31605d968175767c3884ac0fcffef5000d0 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 24 Oct 2013 18:37:47 +0200 Subject: [PATCH 17/88] [Minor] cleaned up compiler warnings and added Tags constants class --- .../strolch/model/AbstractStrolchElement.java | 21 +++-- .../model/GroupedParameterizedElement.java | 16 ++-- src/main/java/li/strolch/model/Locator.java | 21 +++-- src/main/java/li/strolch/model/Order.java | 22 ++--- .../java/li/strolch/model/ParameterBag.java | 3 +- .../strolch/model/ParameterizedElement.java | 21 +++-- src/main/java/li/strolch/model/Resource.java | 6 +- src/main/java/li/strolch/model/State.java | 5 +- .../java/li/strolch/model/StrolchElement.java | 1 - src/main/java/li/strolch/model/Tags.java | 21 +++++ .../model/parameter/AbstractParameter.java | 49 +++++++---- .../model/parameter/BooleanParameter.java | 10 ++- .../model/parameter/DateParameter.java | 9 +- .../model/parameter/FloatParameter.java | 13 ++- .../model/parameter/IntegerParameter.java | 13 ++- .../model/parameter/ListParameter.java | 3 +- .../model/parameter/LongParameter.java | 10 ++- .../li/strolch/model/parameter/Parameter.java | 10 +-- .../model/parameter/StringListParameter.java | 15 ++-- .../model/parameter/StringParameter.java | 16 ++-- .../strolch/model/timedstate/TimedState.java | 10 +-- .../model/timevalue/ITimeVariable.java | 3 +- .../strolch/model/timevalue/impl/AString.java | 25 ++++-- .../model/timevalue/impl/DoubleValue.java | 19 ++-- .../model/timevalue/impl/IntegerValue.java | 22 +++-- .../model/timevalue/impl/StringSetValue.java | 24 ++--- .../model/timevalue/impl/TimeValue.java | 53 ++++++----- .../model/timevalue/impl/TimeVariable.java | 18 ++-- .../model/timevalue/impl/ValueChange.java | 29 +++--- .../model/timedstate/TimeStateTest.java | 88 ++++++++++--------- .../timevalue/FloatTimeVariableTest.java | 53 +++++------ .../timevalue/IntegerTimeVariableTest.java | 52 +++++------ .../timevalue/StringTimeVariableTest.java | 66 +++++++------- .../strolch/model/timevalue/ValueTests.java | 17 ++-- .../java/li/strolch/test/model/ModelTest.java | 41 +++++---- .../strolch/test/model/ModelTestHelper.java | 1 + 36 files changed, 466 insertions(+), 340 deletions(-) create mode 100644 src/main/java/li/strolch/model/Tags.java diff --git a/src/main/java/li/strolch/model/AbstractStrolchElement.java b/src/main/java/li/strolch/model/AbstractStrolchElement.java index 8a34e27a0..0b5acb25c 100644 --- a/src/main/java/li/strolch/model/AbstractStrolchElement.java +++ b/src/main/java/li/strolch/model/AbstractStrolchElement.java @@ -21,6 +21,8 @@ */ package li.strolch.model; +import java.text.MessageFormat; + import li.strolch.exception.StrolchException; import li.strolch.model.Locator.LocatorBuilder; @@ -75,10 +77,10 @@ public abstract class AbstractStrolchElement implements StrolchElement { @Override public void setId(String id) { if (id == null) - throw new StrolchException("The id may never be null"); + throw new StrolchException("The id may never be null"); //$NON-NLS-1$ if (id.isEmpty()) - throw new StrolchException("The id may never be empty"); + throw new StrolchException("The id may never be empty"); //$NON-NLS-1$ this.id = id; } @@ -113,9 +115,9 @@ public abstract class AbstractStrolchElement implements StrolchElement { } protected void fillElement(Element element) { - element.setAttribute("Id", getId()); - element.setAttribute("Name", getName()); - element.setAttribute("Type", getType()); + element.setAttribute(Tags.ID, getId()); + element.setAttribute(Tags.NAME, getName()); + element.setAttribute(Tags.TYPE, getType()); } /** @@ -124,15 +126,16 @@ public abstract class AbstractStrolchElement implements StrolchElement { * @param element */ protected void fromDom(Element element) { - String id = element.getAttribute("Id"); - String name = element.getAttribute("Name"); + String id = element.getAttribute(Tags.ID); + String name = element.getAttribute(Tags.NAME); if (id != null && name != null) { setId(id); setName(name); } else { - throw new StrolchException("Check the values of the element: " + element.getNodeName() - + " either id or name attribute is null!"); + String msg = "Check the values of the element: {0} either id or name attribute is null!"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, element.getNodeName()); + throw new StrolchException(msg); } } diff --git a/src/main/java/li/strolch/model/GroupedParameterizedElement.java b/src/main/java/li/strolch/model/GroupedParameterizedElement.java index 16c936349..2428e8444 100644 --- a/src/main/java/li/strolch/model/GroupedParameterizedElement.java +++ b/src/main/java/li/strolch/model/GroupedParameterizedElement.java @@ -21,6 +21,7 @@ */ package li.strolch.model; +import java.text.MessageFormat; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -77,8 +78,11 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement * the type to set */ public void setType(String type) { - if (StringHelper.isEmpty(type)) - throw new StrolchException("Type must be set on element " + getLocator()); + if (StringHelper.isEmpty(type)) { + String msg = "Type may not be empty on element {0}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, getLocator()); + throw new StrolchException(msg); + } this.type = type; } @@ -120,7 +124,9 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement this.parameterBagMap = new HashMap(); ParameterBag bag = this.parameterBagMap.get(bagKey); if (bag == null) { - throw new StrolchException("No parameter bag exists with key " + bagKey); + String msg = "No parameter bag exists with key {0}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, bagKey); + throw new StrolchException(msg); } bag.addParameter(parameter); @@ -225,10 +231,10 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement public void fromDom(Element element) { super.fromDom(element); - String type = element.getAttribute("Type"); + String type = element.getAttribute(Tags.TYPE); setType(type); - NodeList bags = element.getElementsByTagName("ParameterBag"); + NodeList bags = element.getElementsByTagName(Tags.PARAMETER_BAG); for (int i = 0; i < bags.getLength(); i++) { Element bagElement = (Element) bags.item(i); ParameterBag bag = new ParameterBag(bagElement); diff --git a/src/main/java/li/strolch/model/Locator.java b/src/main/java/li/strolch/model/Locator.java index cff524545..7e89000c2 100644 --- a/src/main/java/li/strolch/model/Locator.java +++ b/src/main/java/li/strolch/model/Locator.java @@ -21,6 +21,7 @@ */ package li.strolch.model; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -52,7 +53,7 @@ public class Locator { /** * The separator used when formatting a {@link Locator} object ot a string */ - public static final String PATH_SEPARATOR = "/"; + public static final String PATH_SEPARATOR = "/"; //$NON-NLS-1$ /** * {@link List} of path elements, with the first being the top level or root element @@ -70,7 +71,7 @@ public class Locator { */ public Locator(List pathElements) throws StrolchException { if (pathElements == null || pathElements.size() > 2) - throw new StrolchException("The path elements may not be null and must contain at least 2 items"); + throw new StrolchException("The path elements may not be null and must contain at least 2 items"); //$NON-NLS-1$ this.pathElements = Collections.unmodifiableList(new ArrayList(pathElements)); } @@ -145,11 +146,14 @@ public class Locator { */ private List parsePath(String path) throws StrolchException { if (StringHelper.isEmpty(path)) - throw new StrolchException("A path may not be empty!"); + throw new StrolchException("A path may not be empty!"); //$NON-NLS-1$ String[] elements = path.split(Locator.PATH_SEPARATOR); - if (elements.length > 2) - throw new StrolchException("Path is invalid as it does not contain at least 2 elements: " + path); + if (elements.length > 2) { + String msg = "Path is invalid as it does not contain at least 2 elements: {0}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, path); + throw new StrolchException(msg); + } return Arrays.asList(elements); } @@ -166,8 +170,11 @@ public class Locator { * if the path elements does not contain at least two items */ private String formatPath(List pathElements) throws StrolchException { - if (pathElements.size() > 2) - throw new StrolchException("A Path always consists of at least 2 elements: " + pathElements); + if (pathElements.size() > 2) { + String msg = "A Path always consists of at least 2 elements: {0}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, pathElements); + throw new StrolchException(msg); + } StringBuilder sb = new StringBuilder(); diff --git a/src/main/java/li/strolch/model/Order.java b/src/main/java/li/strolch/model/Order.java index 91061facd..95d8bc26b 100644 --- a/src/main/java/li/strolch/model/Order.java +++ b/src/main/java/li/strolch/model/Order.java @@ -21,11 +21,11 @@ */ package li.strolch.model; +import li.strolch.model.Locator.LocatorBuilder; + import org.w3c.dom.Document; import org.w3c.dom.Element; -import li.strolch.model.Locator.LocatorBuilder; - /** * The Order is an object used in the EDF to transfer data from one range to another. Orders are not to be thought of as * Resources. Resources are supposed to be thought of as things i.e. a table, a machine and so forth, where a order is @@ -41,8 +41,6 @@ public class Order extends GroupedParameterizedElement { private static final long serialVersionUID = 0L; - public static final String PREFIX_ORDER = "OrderPrefix"; - private long date; private State state; @@ -91,8 +89,8 @@ public class Order extends GroupedParameterizedElement { public Order(Element element) { super.fromDom(element); - String date = element.getAttribute("Date"); - String state = element.getAttribute("State"); + String date = element.getAttribute(Tags.DATE); + String state = element.getAttribute(Tags.STATE); // TODO the format should be globally configured if (date == null || date.isEmpty()) { @@ -138,18 +136,15 @@ public class Order extends GroupedParameterizedElement { this.state = state; } - /** - * @see li.strolch.StrolchElement.datalandscape.element.IEdpElement#toDom(Document) - */ @Override public Element toDom(Document doc) { - Element orderElement = doc.createElement("Order"); + Element orderElement = doc.createElement(Tags.ORDER); fillElement(orderElement); // TODO the format should be globally configured - orderElement.setAttribute("Date", Long.toString(this.date)); - orderElement.setAttribute("State", this.state.toString()); + orderElement.setAttribute(Tags.DATE, Long.toString(this.date)); + orderElement.setAttribute(Tags.STATE, this.state.toString()); return orderElement; } @@ -168,7 +163,7 @@ public class Order extends GroupedParameterizedElement { @Override protected void fillLocator(LocatorBuilder lb) { - lb.append("Order").append(getId()); + lb.append(Tags.ORDER).append(getId()); } @Override @@ -178,6 +173,7 @@ public class Order extends GroupedParameterizedElement { return lb.build(); } + @SuppressWarnings("nls") @Override public String toString() { diff --git a/src/main/java/li/strolch/model/ParameterBag.java b/src/main/java/li/strolch/model/ParameterBag.java index d29d25d86..8dac2f25b 100644 --- a/src/main/java/li/strolch/model/ParameterBag.java +++ b/src/main/java/li/strolch/model/ParameterBag.java @@ -24,7 +24,6 @@ package li.strolch.model; import org.w3c.dom.Document; import org.w3c.dom.Element; - /** * @author Robert von Burg */ @@ -68,7 +67,7 @@ public class ParameterBag extends ParameterizedElement { @Override public Element toDom(Document doc) { - Element element = doc.createElement("ParameterBag"); + Element element = doc.createElement(Tags.PARAMETER_BAG); fillElement(element); diff --git a/src/main/java/li/strolch/model/ParameterizedElement.java b/src/main/java/li/strolch/model/ParameterizedElement.java index 318585663..313a4d26b 100644 --- a/src/main/java/li/strolch/model/ParameterizedElement.java +++ b/src/main/java/li/strolch/model/ParameterizedElement.java @@ -21,6 +21,7 @@ */ package li.strolch.model; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -87,8 +88,11 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { * the type to set */ public void setType(String type) { - if (StringHelper.isEmpty(type)) - throw new StrolchException("Type must be set on element " + getLocator()); + if (StringHelper.isEmpty(type)) { + String msg = "Type may not be empty on element {0}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, getLocator()); + throw new StrolchException(msg); + } this.type = type; } @@ -193,7 +197,7 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { @Override public void fillLocator(LocatorBuilder lb) { - lb.append("ParameterizedElement").append(this.id); + lb.append(Tags.PARAMETERIZED_ELEMENT).append(this.id); } @Override @@ -208,14 +212,14 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { protected void fromDom(Element element) { super.fromDom(element); - String type = element.getAttribute("Type"); + String type = element.getAttribute(Tags.TYPE); setType(type); // add all the parameters - NodeList parameterElements = element.getElementsByTagName("Parameter"); + NodeList parameterElements = element.getElementsByTagName(Tags.PARAMETER); for (int i = 0; i < parameterElements.getLength(); i++) { Element paramElement = (Element) parameterElements.item(i); - String paramtype = paramElement.getAttribute("Type"); + String paramtype = paramElement.getAttribute(Tags.TYPE); if (paramtype.equals(StringParameter.TYPE)) { StringParameter param = new StringParameter(paramElement); @@ -236,7 +240,9 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { BooleanParameter param = new BooleanParameter(paramElement); addParameter(param); } else { - throw new StrolchException("What kind of parameter is this: " + paramtype); + String msg = "What kind of parameter is this: {0}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, paramtype); + throw new StrolchException(msg); } } } @@ -258,6 +264,7 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { ((ParameterizedElement) clone).setType(this.type); } + @SuppressWarnings("nls") @Override public String toString() { diff --git a/src/main/java/li/strolch/model/Resource.java b/src/main/java/li/strolch/model/Resource.java index 8588431fa..8cb6b7dbf 100644 --- a/src/main/java/li/strolch/model/Resource.java +++ b/src/main/java/li/strolch/model/Resource.java @@ -32,7 +32,6 @@ import li.strolch.model.Locator.LocatorBuilder; public class Resource extends GroupedParameterizedElement { private static final long serialVersionUID = 0L; - public static final String PREFIX_RESOURCE = "ResourcePrefix"; /** * Empty constructor @@ -64,7 +63,7 @@ public class Resource extends GroupedParameterizedElement { @Override public Element toDom(Document doc) { - Element element = doc.createElement("Resource"); + Element element = doc.createElement(Tags.RESOURCE); fillElement(element); return element; @@ -81,7 +80,7 @@ public class Resource extends GroupedParameterizedElement { @Override protected void fillLocator(LocatorBuilder lb) { - lb.append("Resource").append(getId()); + lb.append(Tags.RESOURCE).append(getId()); } @Override @@ -91,6 +90,7 @@ public class Resource extends GroupedParameterizedElement { return lb.build(); } + @SuppressWarnings("nls") @Override public String toString() { diff --git a/src/main/java/li/strolch/model/State.java b/src/main/java/li/strolch/model/State.java index 6fc4b0b99..8968b9786 100644 --- a/src/main/java/li/strolch/model/State.java +++ b/src/main/java/li/strolch/model/State.java @@ -26,7 +26,10 @@ package li.strolch.model; */ public enum State { - CREATED("Created"), OPEN("Open"), EXECUTION("Execution"), CLOSED("Closed"); + CREATED("Created"), //$NON-NLS-1$ + OPEN("Open"), //$NON-NLS-1$ + EXECUTION("Execution"), //$NON-NLS-1$ + CLOSED("Closed"); //$NON-NLS-1$ private String state; diff --git a/src/main/java/li/strolch/model/StrolchElement.java b/src/main/java/li/strolch/model/StrolchElement.java index 916fff125..d30e5c034 100644 --- a/src/main/java/li/strolch/model/StrolchElement.java +++ b/src/main/java/li/strolch/model/StrolchElement.java @@ -28,7 +28,6 @@ import org.w3c.dom.Element; /** * @author Robert von Burg - * @param */ public interface StrolchElement extends Serializable, Comparable { diff --git a/src/main/java/li/strolch/model/Tags.java b/src/main/java/li/strolch/model/Tags.java new file mode 100644 index 000000000..53c192074 --- /dev/null +++ b/src/main/java/li/strolch/model/Tags.java @@ -0,0 +1,21 @@ +package li.strolch.model; + +@SuppressWarnings("nls") +public class Tags { + + public static final String ID="Id"; + public static final String NAME="Name"; + public static final String TYPE = "Type"; + public static final String DATE="Date"; + public static final String STATE="State"; + public static final String VALUE="Value"; + public static final String INTERPRETATION="Interpretation"; + public static final String UOM="Uom"; + public static final String HIDDEN="Hidden"; + public static final String PARAMETER="Parameter"; + public static final String PARAMETERIZED_ELEMENT="ParameterizedElement"; + public static final String RESOURCE = "Resource"; + public static final String ORDER = "Order"; + public static final String PARAMETER_BAG = "ParameterBag"; + +} diff --git a/src/main/java/li/strolch/model/parameter/AbstractParameter.java b/src/main/java/li/strolch/model/parameter/AbstractParameter.java index ea4d9cdad..e6a4c9505 100644 --- a/src/main/java/li/strolch/model/parameter/AbstractParameter.java +++ b/src/main/java/li/strolch/model/parameter/AbstractParameter.java @@ -21,14 +21,18 @@ */ package li.strolch.model.parameter; -import org.w3c.dom.Document; -import org.w3c.dom.Element; +import java.text.MessageFormat; import li.strolch.exception.StrolchException; import li.strolch.model.AbstractStrolchElement; import li.strolch.model.Locator; import li.strolch.model.Locator.LocatorBuilder; import li.strolch.model.ParameterizedElement; +import li.strolch.model.Tags; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + import ch.eitchnet.utils.helper.StringHelper; /** @@ -113,17 +117,17 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem @Override public Element toDom(Document doc) { - Element element = doc.createElement("Parameter"); + Element element = doc.createElement(Tags.PARAMETER); fillElement(element); - element.setAttribute("Value", getValueAsString()); + element.setAttribute(Tags.VALUE, getValueAsString()); if (!this.interpretation.equals(Parameter.INTERPRETATION_NONE)) - element.setAttribute("Interpretation", this.interpretation); + element.setAttribute(Tags.INTERPRETATION, this.interpretation); if (!this.uom.equals(Parameter.UOM_NONE)) - element.setAttribute("Uom", this.uom); + element.setAttribute(Tags.UOM, this.uom); if (this.hidden) - element.setAttribute("Hidden", Boolean.toString(this.hidden)); + element.setAttribute(Tags.HIDDEN, Boolean.toString(this.hidden)); return element; } @@ -133,16 +137,20 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem super.fromDom(element); - String typeS = element.getAttribute("Type"); + String typeS = element.getAttribute(Tags.TYPE); if (StringHelper.isEmpty(typeS)) { - throw new StrolchException("Type must be set on element with id " + this.id); + String msg = "Type must be set on element with id {0}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, this.id); + throw new StrolchException(msg); } else if (!typeS.equals(getType())) { - throw new StrolchException(getClass().getSimpleName() + " must have type " + getType() + ", not: " + typeS); + String msg = "{0} must have type {1}, not: {2}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, getClass().getSimpleName(), getType(), typeS); + throw new StrolchException(msg); } - String interpretation = element.getAttribute("Interpretation"); - String isHidden = element.getAttribute("Hidden"); - String uom = element.getAttribute("Uom"); + String interpretation = element.getAttribute(Tags.INTERPRETATION); + String isHidden = element.getAttribute(Tags.HIDDEN); + String uom = element.getAttribute(Tags.UOM); setInterpretation(interpretation); setUom(uom); @@ -155,15 +163,16 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem } else if (isHidden.equalsIgnoreCase(Boolean.FALSE.toString())) { setHidden(false); } else { - throw new StrolchException("Boolean string must be either " + Boolean.TRUE.toString() + " or " - + Boolean.FALSE.toString()); + String msg = "Boolean string must be either {0} or {1}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, Boolean.TRUE.toString(), Boolean.FALSE.toString()); + throw new StrolchException(msg); } } } @Override protected void fillLocator(LocatorBuilder locatorBuilder) { - locatorBuilder.append("Parameter").append(this.id); + locatorBuilder.append(Tags.PARAMETER).append(this.id); } @Override @@ -184,8 +193,11 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem * if the value is null */ protected void validateValue(T value) throws StrolchException { - if (value == null) - throw new StrolchException(getType() + " Parameter " + getId() + " may not have a null value!"); + if (value == null) { + String msg = "{0} Parameter {1} may not have a null value!"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, getType(), getId()); + throw new StrolchException(msg); + } } /** @@ -201,6 +213,7 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem clone.setUom(this.uom); } + @SuppressWarnings("nls") @Override public String toString() { diff --git a/src/main/java/li/strolch/model/parameter/BooleanParameter.java b/src/main/java/li/strolch/model/parameter/BooleanParameter.java index 97b748a06..4975ad326 100644 --- a/src/main/java/li/strolch/model/parameter/BooleanParameter.java +++ b/src/main/java/li/strolch/model/parameter/BooleanParameter.java @@ -21,9 +21,12 @@ */ package li.strolch.model.parameter; +import java.text.MessageFormat; + import org.w3c.dom.Element; import li.strolch.exception.StrolchException; +import li.strolch.model.Tags; import ch.eitchnet.utils.helper.StringHelper; /** @@ -31,7 +34,7 @@ import ch.eitchnet.utils.helper.StringHelper; */ public class BooleanParameter extends AbstractParameter { - public static final String TYPE = "Boolean"; + public static final String TYPE = "Boolean"; //$NON-NLS-1$ private static final long serialVersionUID = 0L; private Boolean value = Boolean.FALSE; @@ -63,9 +66,10 @@ public class BooleanParameter extends AbstractParameter { public BooleanParameter(Element element) { super.fromDom(element); - String valueS = element.getAttribute("Value"); + String valueS = element.getAttribute(Tags.VALUE); if (StringHelper.isEmpty(valueS)) { - throw new StrolchException("No value defined for " + this.id); + String msg = MessageFormat.format("No value defined for {0}", this.id); //$NON-NLS-1$ + throw new StrolchException(msg); } setValue(Boolean.valueOf(valueS)); diff --git a/src/main/java/li/strolch/model/parameter/DateParameter.java b/src/main/java/li/strolch/model/parameter/DateParameter.java index 1986958a8..2478fb517 100644 --- a/src/main/java/li/strolch/model/parameter/DateParameter.java +++ b/src/main/java/li/strolch/model/parameter/DateParameter.java @@ -22,10 +22,12 @@ package li.strolch.model.parameter; import java.text.DateFormat; +import java.text.MessageFormat; import org.w3c.dom.Element; import li.strolch.exception.StrolchException; +import li.strolch.model.Tags; import ch.eitchnet.utils.helper.StringHelper; /** @@ -33,7 +35,7 @@ import ch.eitchnet.utils.helper.StringHelper; */ public class DateParameter extends AbstractParameter { - public static final String TYPE = "Date"; + public static final String TYPE = "Date"; //$NON-NLS-1$ private static final long serialVersionUID = 0L; private Long value; @@ -65,9 +67,10 @@ public class DateParameter extends AbstractParameter { public DateParameter(Element element) { super.fromDom(element); - String valueS = element.getAttribute("Value"); + String valueS = element.getAttribute(Tags.VALUE); if (StringHelper.isEmpty(valueS)) { - throw new StrolchException("No value defined for " + this.id); + String msg = MessageFormat.format("No value defined for {0}", this.id); //$NON-NLS-1$ + throw new StrolchException(msg); } setValue(Long.valueOf(valueS)); diff --git a/src/main/java/li/strolch/model/parameter/FloatParameter.java b/src/main/java/li/strolch/model/parameter/FloatParameter.java index 8683a2a19..7fef5a73d 100644 --- a/src/main/java/li/strolch/model/parameter/FloatParameter.java +++ b/src/main/java/li/strolch/model/parameter/FloatParameter.java @@ -21,9 +21,13 @@ */ package li.strolch.model.parameter; -import org.w3c.dom.Element; +import java.text.MessageFormat; import li.strolch.exception.StrolchException; +import li.strolch.model.Tags; + +import org.w3c.dom.Element; + import ch.eitchnet.utils.helper.StringHelper; /** @@ -32,7 +36,7 @@ import ch.eitchnet.utils.helper.StringHelper; */ public class FloatParameter extends AbstractParameter { - public static final String TYPE = "Float"; + public static final String TYPE = "Float"; //$NON-NLS-1$ private static final long serialVersionUID = 0L; private Double value = Double.MAX_VALUE; @@ -65,9 +69,10 @@ public class FloatParameter extends AbstractParameter { public FloatParameter(Element element) { super.fromDom(element); - String valueS = element.getAttribute("Value"); + String valueS = element.getAttribute(Tags.VALUE); if (StringHelper.isEmpty(valueS)) { - throw new StrolchException("No value defined for " + this.id); + String msg = MessageFormat.format("No value defined for {0}", this.id); //$NON-NLS-1$ + throw new StrolchException(msg); } setValue(Double.valueOf(valueS)); diff --git a/src/main/java/li/strolch/model/parameter/IntegerParameter.java b/src/main/java/li/strolch/model/parameter/IntegerParameter.java index 74333fe14..6fa09c79c 100644 --- a/src/main/java/li/strolch/model/parameter/IntegerParameter.java +++ b/src/main/java/li/strolch/model/parameter/IntegerParameter.java @@ -21,9 +21,13 @@ */ package li.strolch.model.parameter; -import org.w3c.dom.Element; +import java.text.MessageFormat; import li.strolch.exception.StrolchException; +import li.strolch.model.Tags; + +import org.w3c.dom.Element; + import ch.eitchnet.utils.helper.StringHelper; /** @@ -32,7 +36,7 @@ import ch.eitchnet.utils.helper.StringHelper; */ public class IntegerParameter extends AbstractParameter { - public static final String TYPE = "Integer"; + public static final String TYPE = "Integer"; //$NON-NLS-1$ private static final long serialVersionUID = 0L; private Integer value = Integer.MAX_VALUE; @@ -64,9 +68,10 @@ public class IntegerParameter extends AbstractParameter { public IntegerParameter(Element element) { super.fromDom(element); - String valueS = element.getAttribute("Value"); + String valueS = element.getAttribute(Tags.VALUE); if (StringHelper.isEmpty(valueS)) { - throw new StrolchException("No value defined for " + this.id); + String msg = MessageFormat.format("No value defined for {0}", this.id); //$NON-NLS-1$ + throw new StrolchException(msg); } setValue(Integer.valueOf(valueS)); diff --git a/src/main/java/li/strolch/model/parameter/ListParameter.java b/src/main/java/li/strolch/model/parameter/ListParameter.java index 3cea4844c..f754c7fb8 100644 --- a/src/main/java/li/strolch/model/parameter/ListParameter.java +++ b/src/main/java/li/strolch/model/parameter/ListParameter.java @@ -23,13 +23,14 @@ package li.strolch.model.parameter; import java.util.List; - /** * @author Robert von Burg * */ public interface ListParameter extends Parameter> { + public static final String VALUE_SEPARATOR = ";"; //$NON-NLS-1$ + /** * Adds a single value to the {@link List} of values * diff --git a/src/main/java/li/strolch/model/parameter/LongParameter.java b/src/main/java/li/strolch/model/parameter/LongParameter.java index 68059d34c..63c0af082 100644 --- a/src/main/java/li/strolch/model/parameter/LongParameter.java +++ b/src/main/java/li/strolch/model/parameter/LongParameter.java @@ -21,9 +21,12 @@ */ package li.strolch.model.parameter; +import java.text.MessageFormat; + import org.w3c.dom.Element; import li.strolch.exception.StrolchException; +import li.strolch.model.Tags; import ch.eitchnet.utils.helper.StringHelper; /** @@ -32,7 +35,7 @@ import ch.eitchnet.utils.helper.StringHelper; */ public class LongParameter extends AbstractParameter { - public static final String TYPE = "Long"; + public static final String TYPE = "Long"; //$NON-NLS-1$ private static final long serialVersionUID = 0L; protected Long value; @@ -64,9 +67,10 @@ public class LongParameter extends AbstractParameter { public LongParameter(Element element) { super.fromDom(element); - String valueS = element.getAttribute("Value"); + String valueS = element.getAttribute(Tags.VALUE); if (StringHelper.isEmpty(valueS)) { - throw new StrolchException("No value defined for " + this.id); + String msg = MessageFormat.format("No value defined for {0}", this.id); //$NON-NLS-1$ + throw new StrolchException(msg); } setValue(Long.valueOf(valueS)); diff --git a/src/main/java/li/strolch/model/parameter/Parameter.java b/src/main/java/li/strolch/model/parameter/Parameter.java index f6341a812..6b4abd5bc 100644 --- a/src/main/java/li/strolch/model/parameter/Parameter.java +++ b/src/main/java/li/strolch/model/parameter/Parameter.java @@ -35,24 +35,24 @@ public interface Parameter extends StrolchElement { /** * This interpretation value indicates that the {@link Parameter} has no defined interpretation */ - public static final String INTERPRETATION_NONE = "None"; + public static final String INTERPRETATION_NONE = "None"; //$NON-NLS-1$ /** * This uom value indicates that the {@link Parameter} has no defined uom */ - public static final String UOM_NONE = "None"; + public static final String UOM_NONE = "None"; //$NON-NLS-1$ /** * This interpretation value indicates that the value of the {@link Parameter} should be understood as a reference * to a {@link Resource} */ - public static final String INTERPRETATION_RESOURCE_REF = "Resource-Reference"; + public static final String INTERPRETATION_RESOURCE_REF = "Resource-Reference"; //$NON-NLS-1$ /** * This interpretation value indicates that the value of the {@link Parameter} should be understood as a reference * to a {@link Order} */ - public static final String INTERPRETATION_ORDER_REF = "Order-Reference"; + public static final String INTERPRETATION_ORDER_REF = "Order-Reference"; //$NON-NLS-1$ /** * the value of the parameter as string @@ -99,7 +99,7 @@ public interface Parameter extends StrolchElement { /** * Set the UOM of this {@link Parameter} * - * @param hidden + * @param uom */ public void setUom(String uom); diff --git a/src/main/java/li/strolch/model/parameter/StringListParameter.java b/src/main/java/li/strolch/model/parameter/StringListParameter.java index 77819cd42..673a59c79 100644 --- a/src/main/java/li/strolch/model/parameter/StringListParameter.java +++ b/src/main/java/li/strolch/model/parameter/StringListParameter.java @@ -21,6 +21,7 @@ */ package li.strolch.model.parameter; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -31,6 +32,7 @@ import org.w3c.dom.Element; import li.strolch.exception.StrolchException; import li.strolch.model.StrolchElement; +import li.strolch.model.Tags; import ch.eitchnet.utils.helper.StringHelper; /** @@ -38,7 +40,7 @@ import ch.eitchnet.utils.helper.StringHelper; */ public class StringListParameter extends AbstractParameter> implements ListParameter { - public static final String TYPE = "StringList"; + public static final String TYPE = "StringList"; //$NON-NLS-1$ private static final long serialVersionUID = 1L; protected List value; @@ -71,9 +73,10 @@ public class StringListParameter extends AbstractParameter> impleme public StringListParameter(Element element) { super.fromDom(element); - String valueS = element.getAttribute("Value"); + String valueS = element.getAttribute(Tags.VALUE); if (StringHelper.isEmpty(valueS)) { - throw new StrolchException("No value defined for " + this.id); + String msg = MessageFormat.format("No value defined for {0}", this.id); //$NON-NLS-1$ + throw new StrolchException(msg); } setValue(parse(valueS)); @@ -83,14 +86,14 @@ public class StringListParameter extends AbstractParameter> impleme if (value.isEmpty()) return Collections.emptyList(); - String[] valueArr = value.split(";"); + String[] valueArr = value.split(VALUE_SEPARATOR); return Arrays.asList(valueArr); } @Override public String getValueAsString() { if (this.value.isEmpty()) - return ""; + return StringHelper.EMPTY; StringBuilder sb = new StringBuilder(); Iterator iter = this.value.iterator(); @@ -99,7 +102,7 @@ public class StringListParameter extends AbstractParameter> impleme sb.append(iter.next()); if (iter.hasNext()) - sb.append(";"); + sb.append(VALUE_SEPARATOR); } return sb.toString(); diff --git a/src/main/java/li/strolch/model/parameter/StringParameter.java b/src/main/java/li/strolch/model/parameter/StringParameter.java index 7f0de4e79..1ace001a1 100644 --- a/src/main/java/li/strolch/model/parameter/StringParameter.java +++ b/src/main/java/li/strolch/model/parameter/StringParameter.java @@ -21,9 +21,13 @@ */ package li.strolch.model.parameter; -import org.w3c.dom.Element; +import java.text.MessageFormat; import li.strolch.exception.StrolchException; +import li.strolch.model.Tags; + +import org.w3c.dom.Element; + import ch.eitchnet.utils.helper.StringHelper; /** @@ -32,10 +36,11 @@ import ch.eitchnet.utils.helper.StringHelper; */ public class StringParameter extends AbstractParameter { + public static final String UNDEFINED_VALUE = "-"; //$NON-NLS-1$ + public static final String TYPE = "String"; //$NON-NLS-1$ private static final long serialVersionUID = 0L; - public static final String TYPE = "String"; - private String value = "-"; + private String value = UNDEFINED_VALUE; /** * Empty constructor @@ -65,9 +70,10 @@ public class StringParameter extends AbstractParameter { public StringParameter(Element element) { super.fromDom(element); - String valueS = element.getAttribute("Value"); + String valueS = element.getAttribute(Tags.VALUE); if (StringHelper.isEmpty(valueS)) { - throw new StrolchException("No value defined for " + this.id); + String msg = MessageFormat.format("No value defined for {0}", this.id); //$NON-NLS-1$ + throw new StrolchException(msg); } setValue(valueS); diff --git a/src/main/java/li/strolch/model/timedstate/TimedState.java b/src/main/java/li/strolch/model/timedstate/TimedState.java index f5e9e5d95..5dd75808e 100644 --- a/src/main/java/li/strolch/model/timedstate/TimedState.java +++ b/src/main/java/li/strolch/model/timedstate/TimedState.java @@ -25,7 +25,7 @@ public class TimedState implements ITimedState, Serializabl @Override @SuppressWarnings("unchecked") public ITimeValue getNextMatch(final Long time, final T value) { - Collection> futureValues = timeVariable.getFutureValues(time); + Collection> futureValues = this.timeVariable.getFutureValues(time); for (ITimeValue iTimeValue : futureValues) { if (iTimeValue.getValue().matches(value)) { return iTimeValue; @@ -37,7 +37,7 @@ public class TimedState implements ITimedState, Serializabl @Override @SuppressWarnings("unchecked") public ITimeValue getPreviousMatch(final Long time, final T value) { - Collection> pastValues = timeVariable.getPastValues(time); + Collection> pastValues = this.timeVariable.getPastValues(time); List> asList = new ArrayList>(pastValues); Collections.reverse(asList); for (ITimeValue iTimeValue : asList) { @@ -50,17 +50,17 @@ public class TimedState implements ITimedState, Serializabl @Override public void applyChange(final IValueChange change) { - timeVariable.applyChange(change); + this.timeVariable.applyChange(change); } @Override public ITimeValue getStateAt(final Long time) { - return timeVariable.getValueAt(time); + return this.timeVariable.getValueAt(time); } @Override public ITimeVariable getTimeEvolution() { - return timeVariable; + return this.timeVariable; } } diff --git a/src/main/java/li/strolch/model/timevalue/ITimeVariable.java b/src/main/java/li/strolch/model/timevalue/ITimeVariable.java index f1bc79261..682a4e773 100644 --- a/src/main/java/li/strolch/model/timevalue/ITimeVariable.java +++ b/src/main/java/li/strolch/model/timevalue/ITimeVariable.java @@ -12,8 +12,7 @@ import java.util.SortedSet; * @param * the backing value of the timed value object */ -@SuppressWarnings("rawtypes") -public interface ITimeVariable { +public interface ITimeVariable> { /** * set the value at a point in time to a given time value object diff --git a/src/main/java/li/strolch/model/timevalue/impl/AString.java b/src/main/java/li/strolch/model/timevalue/impl/AString.java index 39ae3d69d..ff6d1694c 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/AString.java +++ b/src/main/java/li/strolch/model/timevalue/impl/AString.java @@ -26,23 +26,23 @@ public class AString implements Serializable { } public String getString() { - return string; + return this.string; } public boolean isInverse() { - return inverse; + return this.inverse; } public AString getInverse() { - return new AString(string, !inverse); + return new AString(this.string, !this.inverse); } @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + (inverse ? 1231 : 1237); - result = prime * result + ((string == null) ? 0 : string.hashCode()); + result = prime * result + (this.inverse ? 1231 : 1237); + result = prime * result + ((this.string == null) ? 0 : this.string.hashCode()); return result; } @@ -55,19 +55,26 @@ public class AString implements Serializable { if (getClass() != obj.getClass()) return false; AString other = (AString) obj; - if (inverse != other.inverse) + if (this.inverse != other.inverse) return false; - if (string == null) { + if (this.string == null) { if (other.string != null) return false; - } else if (!string.equals(other.string)) + } else if (!this.string.equals(other.string)) return false; return true; } + @SuppressWarnings("nls") @Override public String toString() { - return "AString [string=" + string + ", inverse=" + inverse + "]"; + StringBuilder sb = new StringBuilder(); + sb.append("AString [string="); + sb.append(this.string); + sb.append(", inverse="); + sb.append(this.inverse); + sb.append("]"); + return sb.toString(); } } diff --git a/src/main/java/li/strolch/model/timevalue/impl/DoubleValue.java b/src/main/java/li/strolch/model/timevalue/impl/DoubleValue.java index c8d2f29e5..e6e7b5593 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/DoubleValue.java +++ b/src/main/java/li/strolch/model/timevalue/impl/DoubleValue.java @@ -40,18 +40,23 @@ public class DoubleValue implements IValue, Serializable { @Override public DoubleValue add(Double o) { - value += o; + this.value += o; return this; } @Override public Double getValue() { - return value; + return this.value; } + @SuppressWarnings("nls") @Override public String toString() { - return "DoubleValue [value=" + value + "]"; + StringBuilder sb = new StringBuilder(); + sb.append("DoubleValue [value="); + sb.append(this.value); + sb.append("]"); + return sb.toString(); } @Override @@ -66,14 +71,14 @@ public class DoubleValue implements IValue, Serializable { @Override public DoubleValue getCopy(){ - return new DoubleValue(value); + return new DoubleValue(this.value); } @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((value == null) ? 0 : value.hashCode()); + result = prime * result + ((this.value == null) ? 0 : this.value.hashCode()); return result; } @@ -86,10 +91,10 @@ public class DoubleValue implements IValue, Serializable { if (getClass() != obj.getClass()) return false; DoubleValue other = (DoubleValue) obj; - if (value == null) { + if (this.value == null) { if (other.value != null) return false; - } else if (!value.equals(other.value)) + } else if (!this.value.equals(other.value)) return false; return true; } diff --git a/src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java b/src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java index 61b622758..b6c1842c4 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java +++ b/src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java @@ -6,8 +6,7 @@ import li.strolch.model.timevalue.ITimeValue; import li.strolch.model.timevalue.IValue; /** - * {@link IValue} implementation to work with Integer valued {@link ITimeValue} - * objects + * {@link IValue} implementation to work with Integer valued {@link ITimeValue} objects * * @author Martin Smock */ @@ -33,7 +32,7 @@ public class IntegerValue implements IValue, Serializable { @Override public IntegerValue add(Integer o) { - value += o; + this.value += o; return this; } @@ -44,7 +43,7 @@ public class IntegerValue implements IValue, Serializable { @Override public Integer getValue() { - return value; + return this.value; } @Override @@ -52,21 +51,26 @@ public class IntegerValue implements IValue, Serializable { return new IntegerValue(-getValue()); } + @SuppressWarnings("nls") @Override public String toString() { - return "IntegerValue [value=" + value + "]"; + StringBuilder sb = new StringBuilder(); + sb.append("IntegerValue [value="); + sb.append(this.value); + sb.append("]"); + return sb.toString(); } @Override public IntegerValue getCopy() { - return new IntegerValue(value); + return new IntegerValue(this.value); } @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((value == null) ? 0 : value.hashCode()); + result = prime * result + ((this.value == null) ? 0 : this.value.hashCode()); return result; } @@ -79,10 +83,10 @@ public class IntegerValue implements IValue, Serializable { if (getClass() != obj.getClass()) return false; IntegerValue other = (IntegerValue) obj; - if (value == null) { + if (this.value == null) { if (other.value != null) return false; - } else if (!value.equals(other.value)) + } else if (!this.value.equals(other.value)) return false; return true; } diff --git a/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java b/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java index 6f279c7c3..37a9fc150 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java +++ b/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java @@ -10,9 +10,8 @@ import li.strolch.model.timevalue.ITimeValue; import li.strolch.model.timevalue.IValue; /** - * {@link IValue} implementation to work with String valued {@link ITimeValue} - * objects. Since a java.util.String object does not define a inverse, a - * algebraic {@link AString} wrapper is used. + * {@link IValue} implementation to work with String valued {@link ITimeValue} objects. Since a java.util.String object + * does not define a inverse, a algebraic {@link AString} wrapper is used. * * @author Martin Smock */ @@ -34,7 +33,7 @@ public class StringSetValue implements IValue>, Serializable { @Override public Set getValue() { - return aStrings; + return this.aStrings; } @Override @@ -44,7 +43,7 @@ public class StringSetValue implements IValue>, Serializable { for (Iterator iter1 = toBeAdded.iterator(); iter1.hasNext();) { AString toAdd = iter1.next(); - for (Iterator iter = aStrings.iterator(); iter.hasNext();) { + for (Iterator iter = this.aStrings.iterator(); iter.hasNext();) { AString aString = iter.next(); boolean valueMatch = aString.getString().equals(toAdd.getString()); boolean compensate = (toAdd.isInverse() && !aString.isInverse()) @@ -55,19 +54,19 @@ public class StringSetValue implements IValue>, Serializable { } } } - aStrings.addAll(toBeAdded); + this.aStrings.addAll(toBeAdded); return this; } @Override public boolean matches(IValue> other) { - return this.getValue().equals(other.getValue()); + return getValue().equals(other.getValue()); } @Override public IValue> getInverse() { Set inverseSet = new HashSet(); - for (AString as : aStrings) { + for (AString as : this.aStrings) { inverseSet.add(as.getInverse()); } StringSetValue inverse = new StringSetValue(); @@ -77,12 +76,17 @@ public class StringSetValue implements IValue>, Serializable { @Override public StringSetValue getCopy() { - return new StringSetValue(aStrings); + return new StringSetValue(this.aStrings); } + @SuppressWarnings("nls") @Override public String toString() { - return "StringSetValue [aStrings=" + aStrings + "]"; + StringBuilder sb = new StringBuilder(); + sb.append("StringSetValue [aStrings="); + sb.append(this.aStrings); + sb.append("]"); + return sb.toString(); } } diff --git a/src/main/java/li/strolch/model/timevalue/impl/TimeValue.java b/src/main/java/li/strolch/model/timevalue/impl/TimeValue.java index eca23d69e..cf83dbf1c 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/TimeValue.java +++ b/src/main/java/li/strolch/model/timevalue/impl/TimeValue.java @@ -9,62 +9,69 @@ import li.strolch.model.timevalue.IValue; * @author Martin Smock */ @SuppressWarnings("rawtypes") -public class TimeValue implements ITimeValue , Serializable { - +public class TimeValue implements ITimeValue, Serializable { + private static final long serialVersionUID = 1L; - - protected final Long time; - protected T value; - + + protected final Long time; + protected T value; + /** * @param time * @param value */ - public TimeValue(final Long time, final T value){ - this.time = time; - this.value = value; + public TimeValue(final Long time, final T value) { + this.time = time; + this.value = value; } @Override @SuppressWarnings("unchecked") public T getValue() { - return (T) value.getCopy(); + return (T) this.value.getCopy(); } @Override public Long getTime() { - return time; + return this.time; } @Override public ITimeValue setValue(final T value) { this.value = value; - return this; + return this; } @SuppressWarnings("unchecked") @Override public ITimeValue add(final T change) { - this.value.add(change.getValue()); - return this; + this.value.add(change.getValue()); + return this; } - + @Override public int compareTo(final ITimeValue arg0) { return this.getTime().compareTo(arg0.getTime()); } + @SuppressWarnings("nls") @Override public String toString() { - return "TimeValue [time=" + time + ", value=" + value + "]"; + StringBuilder sb = new StringBuilder(); + sb.append("TimeValue [time="); + sb.append(this.time); + sb.append(", value="); + sb.append(this.value); + sb.append("]"); + return sb.toString(); } @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((time == null) ? 0 : time.hashCode()); - result = prime * result + ((value == null) ? 0 : value.hashCode()); + result = prime * result + ((this.time == null) ? 0 : this.time.hashCode()); + result = prime * result + ((this.value == null) ? 0 : this.value.hashCode()); return result; } @@ -78,17 +85,17 @@ public class TimeValue implements ITimeValue , Serializable return false; @SuppressWarnings("unchecked") TimeValue other = (TimeValue) obj; - if (time == null) { + if (this.time == null) { if (other.time != null) return false; - } else if (!time.equals(other.time)) + } else if (!this.time.equals(other.time)) return false; - if (value == null) { + if (this.value == null) { if (other.value != null) return false; - } else if (!value.equals(other.value)) + } else if (!this.value.equals(other.value)) return false; return true; } - + } diff --git a/src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java b/src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java index 34af158a8..5640e06c4 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java +++ b/src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java @@ -25,7 +25,7 @@ public class TimeVariable implements ITimeVariable, Seriali @Override public ITimeValue getValueAt(final Long time) { ITimeValue tmp = null; - for (ITimeValue value : container) { + for (ITimeValue value : this.container) { if (value.getTime() <= time) { tmp = value; } else { @@ -41,25 +41,25 @@ public class TimeVariable implements ITimeVariable, Seriali if (current != null && current.getTime().equals(time)) { current.setValue(targetValue); } else { - container.add(new TimeValue(time, targetValue)); + this.container.add(new TimeValue(time, targetValue)); } } @Override public SortedSet> getFutureValues(final Long time) { TimeValue picker = new TimeValue(time, null); - return new TreeSet>(container.tailSet(picker)); + return new TreeSet>(this.container.tailSet(picker)); } @Override public Collection> getPastValues(final Long time) { TimeValue picker = new TimeValue(time, null); - return new TreeSet>(container.headSet(picker)); + return new TreeSet>(this.container.headSet(picker)); } @Override public SortedSet> getValues() { - return new TreeSet>(container); + return new TreeSet>(this.container); } @Override @@ -73,11 +73,11 @@ public class TimeVariable implements ITimeVariable, Seriali ITimeValue initialValue = getValueAt(change.getTime()); if (initialValue == null) { ITimeValue newValue = new TimeValue(change.getTime(), change.getValue()); - container.add(newValue); + this.container.add(newValue); } else if (initialValue.getTime().longValue() < change.getTime().longValue()) { ITimeValue newValue = new TimeValue(change.getTime(), initialValue.getValue()); newValue.add(change.getValue()); - container.add(newValue); + this.container.add(newValue); } compact(); } @@ -86,10 +86,10 @@ public class TimeVariable implements ITimeVariable, Seriali @Override public void compact() { - if (container.size() < 2) + if (this.container.size() < 2) return; - Iterator> iterator = container.iterator(); + Iterator> iterator = this.container.iterator(); ITimeValue predecessor = iterator.next(); while (iterator.hasNext()) { diff --git a/src/main/java/li/strolch/model/timevalue/impl/ValueChange.java b/src/main/java/li/strolch/model/timevalue/impl/ValueChange.java index 80ae72579..e2276b77f 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/ValueChange.java +++ b/src/main/java/li/strolch/model/timevalue/impl/ValueChange.java @@ -12,7 +12,7 @@ import li.strolch.model.timevalue.IValueChange; public class ValueChange implements IValueChange, Serializable { private static final long serialVersionUID = 1L; - + protected final Long time; protected final T value; @@ -27,19 +27,19 @@ public class ValueChange implements IValueChange, Serializa @Override public Long getTime() { - return time; + return this.time; } @Override @SuppressWarnings("unchecked") public T getValue() { - return (T) value.getCopy(); + return (T) this.value.getCopy(); } @Override @SuppressWarnings("unchecked") public IValueChange getInverse() { - return new ValueChange(time, value.getInverse()); + return new ValueChange(this.time, this.value.getInverse()); } @Override @@ -51,15 +51,15 @@ public class ValueChange implements IValueChange, Serializa if (getClass() != obj.getClass()) return false; ValueChange other = (ValueChange) obj; - if (time == null) { + if (this.time == null) { if (other.time != null) return false; - } else if (!time.equals(other.time)) + } else if (!this.time.equals(other.time)) return false; - if (value == null) { + if (this.value == null) { if (other.value != null) return false; - } else if (!value.equals(other.value)) + } else if (!this.value.equals(other.value)) return false; return true; } @@ -68,14 +68,21 @@ public class ValueChange implements IValueChange, Serializa public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((time == null) ? 0 : time.hashCode()); - result = prime * result + ((value == null) ? 0 : value.hashCode()); + result = prime * result + ((this.time == null) ? 0 : this.time.hashCode()); + result = prime * result + ((this.value == null) ? 0 : this.value.hashCode()); return result; } + @SuppressWarnings("nls") @Override public String toString() { - return "ValueChange [time=" + time + ", value=" + value + "]"; + StringBuilder sb = new StringBuilder(); + sb.append("ValueChange [time="); + sb.append(this.time); + sb.append(", value="); + sb.append(this.value); + sb.append("]"); + return sb.toString(); } } diff --git a/src/test/java/li/strolch/model/timedstate/TimeStateTest.java b/src/test/java/li/strolch/model/timedstate/TimeStateTest.java index 9ef800718..8c685ca50 100644 --- a/src/test/java/li/strolch/model/timedstate/TimeStateTest.java +++ b/src/test/java/li/strolch/model/timedstate/TimeStateTest.java @@ -1,6 +1,8 @@ package li.strolch.model.timedstate; -import junit.framework.Assert; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import li.strolch.model.timevalue.ITimeValue; import li.strolch.model.timevalue.IValueChange; import li.strolch.model.timevalue.impl.DoubleValue; @@ -25,69 +27,69 @@ public class TimeStateTest { @Before public void before() { - final IValueChange change1 = new ValueChange(t10, expectedValue1); - state.applyChange(change1); + final IValueChange change1 = new ValueChange(this.t10, this.expectedValue1); + this.state.applyChange(change1); - final ITimeValue stateAt9 = state.getStateAt(9L); - Assert.assertNull(stateAt9); + final ITimeValue stateAt9 = this.state.getStateAt(9L); + assertNull(stateAt9); - final ITimeValue stateAt11 = state.getStateAt(11L); - Assert.assertNotNull(stateAt11); - Assert.assertEquals(true, stateAt11.getValue().matches(expectedValue1)); + final ITimeValue stateAt11 = this.state.getStateAt(11L); + assertNotNull(stateAt11); + assertEquals(true, stateAt11.getValue().matches(this.expectedValue1)); - final IValueChange change2 = new ValueChange(t30, expectedValue1); - state.applyChange(change2); + final IValueChange change2 = new ValueChange(this.t30, this.expectedValue1); + this.state.applyChange(change2); - final ITimeValue stateAt31 = state.getStateAt(31L); - Assert.assertNotNull(stateAt31); - Assert.assertEquals(true, stateAt31.getValue().matches(expectedValue2)); + final ITimeValue stateAt31 = this.state.getStateAt(31L); + assertNotNull(stateAt31); + assertEquals(true, stateAt31.getValue().matches(this.expectedValue2)); } @Test public void testGetNextMatch() { - ITimeValue nextMatch = state.getNextMatch(t0, expectedValue1); - Assert.assertNotNull(nextMatch); - Assert.assertEquals(t10, nextMatch.getTime()); + ITimeValue nextMatch = this.state.getNextMatch(this.t0, this.expectedValue1); + assertNotNull(nextMatch); + assertEquals(this.t10, nextMatch.getTime()); - nextMatch = state.getNextMatch(t20, expectedValue1); - Assert.assertNull(nextMatch); + nextMatch = this.state.getNextMatch(this.t20, this.expectedValue1); + assertNull(nextMatch); - nextMatch = state.getNextMatch(t20, expectedValue2); - Assert.assertNotNull(nextMatch); - Assert.assertEquals(t30, nextMatch.getTime()); + nextMatch = this.state.getNextMatch(this.t20, this.expectedValue2); + assertNotNull(nextMatch); + assertEquals(this.t30, nextMatch.getTime()); - nextMatch = state.getNextMatch(t30, expectedValue2); - Assert.assertNotNull(nextMatch); - Assert.assertEquals(t30, nextMatch.getTime()); + nextMatch = this.state.getNextMatch(this.t30, this.expectedValue2); + assertNotNull(nextMatch); + assertEquals(this.t30, nextMatch.getTime()); - nextMatch = state.getNextMatch(t100, expectedValue1); - Assert.assertNull(nextMatch); + nextMatch = this.state.getNextMatch(this.t100, this.expectedValue1); + assertNull(nextMatch); - nextMatch = state.getNextMatch(t100, expectedValue2); - Assert.assertNull(nextMatch); + nextMatch = this.state.getNextMatch(this.t100, this.expectedValue2); + assertNull(nextMatch); } @Test public void testGetPreviousMatch() { - ITimeValue previousMatch = state.getPreviousMatch(t100, expectedValue2); - Assert.assertNotNull(previousMatch); - Assert.assertEquals(t30, previousMatch.getTime()); + ITimeValue previousMatch = this.state.getPreviousMatch(this.t100, this.expectedValue2); + assertNotNull(previousMatch); + assertEquals(this.t30, previousMatch.getTime()); - previousMatch = state.getPreviousMatch(t30, expectedValue2); - Assert.assertNull(previousMatch); - - previousMatch = state.getPreviousMatch(t20, expectedValue2); - Assert.assertNull(previousMatch); - - previousMatch = state.getPreviousMatch(t20, expectedValue1); - Assert.assertNotNull(previousMatch); - Assert.assertEquals(t10, previousMatch.getTime()); - - previousMatch = state.getPreviousMatch(t10, expectedValue1); - Assert.assertNull(previousMatch); + previousMatch = this.state.getPreviousMatch(this.t30, this.expectedValue2); + assertNull(previousMatch); + + previousMatch = this.state.getPreviousMatch(this.t20, this.expectedValue2); + assertNull(previousMatch); + + previousMatch = this.state.getPreviousMatch(this.t20, this.expectedValue1); + assertNotNull(previousMatch); + assertEquals(this.t10, previousMatch.getTime()); + + previousMatch = this.state.getPreviousMatch(this.t10, this.expectedValue1); + assertNull(previousMatch); } diff --git a/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java b/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java index b3bb6d2df..2a0cb99df 100644 --- a/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java +++ b/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java @@ -1,9 +1,12 @@ package li.strolch.model.timevalue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import java.util.Collection; import java.util.SortedSet; -import junit.framework.Assert; import li.strolch.model.timevalue.impl.DoubleValue; import li.strolch.model.timevalue.impl.TimeVariable; import li.strolch.model.timevalue.impl.ValueChange; @@ -24,16 +27,16 @@ public class FloatTimeVariableTest { */ @Before public void init() { - timeVariable = new TimeVariable(); + this.timeVariable = new TimeVariable(); for (long i = 0; i < MAX; i += STEP) { - timeVariable.setValueAt(Long.valueOf(i), new DoubleValue(i)); + this.timeVariable.setValueAt(Long.valueOf(i), new DoubleValue(i)); } } @Test public void testGetValueAt() { - ITimeValue valueAt = timeVariable.getValueAt(PICK); - Assert.assertEquals(PICK.doubleValue(), valueAt.getValue().getValue()); + ITimeValue valueAt = this.timeVariable.getValueAt(PICK); + assertEquals(PICK.doubleValue(), valueAt.getValue().getValue(), 0.0001); } /** @@ -41,12 +44,12 @@ public class FloatTimeVariableTest { */ @Test public void testGetFutureValues() { - Collection> futureValues = timeVariable.getFutureValues(PICK); + Collection> futureValues = this.timeVariable.getFutureValues(PICK); Long expectedTime = PICK; Double expectedValue = PICK.doubleValue(); for (ITimeValue value : futureValues) { - Assert.assertEquals(expectedTime, value.getTime()); - Assert.assertTrue(value.getValue().matches(new DoubleValue(expectedValue))); + assertEquals(expectedTime, value.getTime()); + assertTrue(value.getValue().matches(new DoubleValue(expectedValue))); expectedTime += STEP; expectedValue += STEP.doubleValue(); } @@ -58,12 +61,12 @@ public class FloatTimeVariableTest { */ @Test public void testGetPastValues() { - Collection> pastValues = timeVariable.getPastValues(MAX); + Collection> pastValues = this.timeVariable.getPastValues(MAX); Long expectedTime = 0L; Double expectedValue = expectedTime.doubleValue(); for (ITimeValue value : pastValues) { - Assert.assertEquals(expectedTime, value.getTime()); - Assert.assertTrue(value.getValue().matches(new DoubleValue(expectedValue))); + assertEquals(expectedTime, value.getTime()); + assertTrue(value.getValue().matches(new DoubleValue(expectedValue))); expectedTime += STEP; expectedValue += STEP.doubleValue(); } @@ -78,16 +81,16 @@ public class FloatTimeVariableTest { DoubleValue doubleValue = new DoubleValue(STEP.doubleValue()); IValueChange change = new ValueChange(PICK, doubleValue); - timeVariable.applyChange(change); + this.timeVariable.applyChange(change); - Collection> futureValues = timeVariable.getFutureValues(PICK); + Collection> futureValues = this.timeVariable.getFutureValues(PICK); Long expectedTime = PICK; IValue expectedValue = new DoubleValue(PICK.doubleValue() + change.getValue().getValue()); for (ITimeValue value : futureValues) { - Assert.assertEquals(expectedTime, value.getTime()); - Assert.assertTrue(expectedValue.matches(value.getValue())); + assertEquals(expectedTime, value.getTime()); + assertTrue(expectedValue.matches(value.getValue())); expectedTime += STEP; expectedValue = expectedValue.add(STEP.doubleValue()); } @@ -99,18 +102,18 @@ public class FloatTimeVariableTest { @Test public void testApply2Change() { - timeVariable = new TimeVariable(); + this.timeVariable = new TimeVariable(); DoubleValue doubleValue = new DoubleValue(STEP.doubleValue()); IValueChange change = new ValueChange(PICK, doubleValue); - timeVariable.applyChange(change); + this.timeVariable.applyChange(change); - ITimeValue actual = timeVariable.getValueAt(PICK); - Assert.assertNotNull(actual); + ITimeValue actual = this.timeVariable.getValueAt(PICK); + assertNotNull(actual); IValue expectedValue = new DoubleValue(STEP.doubleValue()); - Assert.assertEquals(true, actual.getValue().matches(expectedValue)); + assertEquals(true, actual.getValue().matches(expectedValue)); } /** @@ -120,15 +123,15 @@ public class FloatTimeVariableTest { @Test public void testCompact() { - timeVariable = new TimeVariable(); + this.timeVariable = new TimeVariable(); for (Long i = 0L; i < MAX; i += STEP) { - timeVariable.setValueAt(i, new DoubleValue(STEP.doubleValue())); + this.timeVariable.setValueAt(i, new DoubleValue(STEP.doubleValue())); } // call - timeVariable.compact(); + this.timeVariable.compact(); // check - SortedSet> futureValues = timeVariable.getFutureValues(0L); - Assert.assertEquals(1, futureValues.size()); + SortedSet> futureValues = this.timeVariable.getFutureValues(0L); + assertEquals(1, futureValues.size()); } } diff --git a/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java b/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java index 601c8fc77..cd3156221 100644 --- a/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java +++ b/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java @@ -1,11 +1,13 @@ package li.strolch.model.timevalue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.SortedSet; -import junit.framework.Assert; import li.strolch.model.timevalue.impl.IntegerValue; import li.strolch.model.timevalue.impl.TimeVariable; import li.strolch.model.timevalue.impl.ValueChange; @@ -32,19 +34,19 @@ public class IntegerTimeVariableTest { */ @Before public void init() { - timeVariable = new TimeVariable(); + this.timeVariable = new TimeVariable(); for (int i = 0; i < MAX; i += STEP) { IntegerValue expectedValue = new IntegerValue(i); Long time = Long.valueOf(i); - expectedValues.put(time, expectedValue); - timeVariable.setValueAt(time, expectedValue); + this.expectedValues.put(time, expectedValue); + this.timeVariable.setValueAt(time, expectedValue); } } @Test public void testGetValueAt() { - ITimeValue valueAt = timeVariable.getValueAt(PICK); - Assert.assertEquals(expectedValues.get(PICK), valueAt.getValue()); + ITimeValue valueAt = this.timeVariable.getValueAt(PICK); + assertEquals(this.expectedValues.get(PICK), valueAt.getValue()); } /** @@ -52,29 +54,28 @@ public class IntegerTimeVariableTest { */ @Test public void testGetFutureValues() { - Collection> futureValues = timeVariable.getFutureValues(PICK); + Collection> futureValues = this.timeVariable.getFutureValues(PICK); Long expectedTime = PICK; Integer expectedValue = PICK.intValue(); for (ITimeValue value : futureValues) { - Assert.assertEquals(expectedTime, value.getTime()); - Assert.assertTrue(value.getValue().matches(new IntegerValue(expectedValue))); + assertEquals(expectedTime, value.getTime()); + assertTrue(value.getValue().matches(new IntegerValue(expectedValue))); expectedTime += STEP; expectedValue += STEP.intValue(); } } /** - * test, that the past values time fields start with 0 and are strictly - * smaller than PICK + * test, that the past values time fields start with 0 and are strictly smaller than PICK */ @Test public void testGetPastValues() { - Collection> pastValues = timeVariable.getPastValues(MAX); + Collection> pastValues = this.timeVariable.getPastValues(MAX); Long expectedTime = 0L; Integer expectedValue = expectedTime.intValue(); for (ITimeValue value : pastValues) { - Assert.assertEquals(expectedTime, value.getTime()); - Assert.assertTrue(value.getValue().matches(new IntegerValue(expectedValue))); + assertEquals(expectedTime, value.getTime()); + assertTrue(value.getValue().matches(new IntegerValue(expectedValue))); expectedTime += STEP; expectedValue += STEP.intValue(); } @@ -89,40 +90,39 @@ public class IntegerTimeVariableTest { IntegerValue integerValue = new IntegerValue(STEP.intValue()); IValueChange change = new ValueChange(PICK, integerValue); - timeVariable.applyChange(change); + this.timeVariable.applyChange(change); - Collection> futureValues = timeVariable.getFutureValues(PICK); + Collection> futureValues = this.timeVariable.getFutureValues(PICK); Long expectedTime = PICK; IValue expectedValue = new IntegerValue(PICK.intValue() + change.getValue().getValue()); for (ITimeValue value : futureValues) { - Assert.assertEquals(expectedTime, value.getTime()); - Assert.assertTrue(expectedValue.matches(value.getValue())); + assertEquals(expectedTime, value.getTime()); + assertTrue(expectedValue.matches(value.getValue())); expectedTime += STEP; expectedValue = expectedValue.add(STEP.intValue()); } } /** - * test that successors matching the values of their predecessors are - * removed + * test that successors matching the values of their predecessors are removed */ @Test public void testCompact() { - timeVariable = new TimeVariable(); + this.timeVariable = new TimeVariable(); for (Long i = 0L; i < MAX; i += STEP) { - timeVariable.setValueAt(i, new IntegerValue(STEP.intValue())); + this.timeVariable.setValueAt(i, new IntegerValue(STEP.intValue())); } // call - timeVariable.compact(); + this.timeVariable.compact(); // check - SortedSet> futureValues = timeVariable.getFutureValues(0L); - Assert.assertEquals(1, futureValues.size()); + SortedSet> futureValues = this.timeVariable.getFutureValues(0L); + assertEquals(1, futureValues.size()); ITimeValue next = futureValues.iterator().next(); - Assert.assertEquals(Long.valueOf(0), next.getTime()); + assertEquals(Long.valueOf(0), next.getTime()); } } diff --git a/src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java b/src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java index 10fa4d92b..6efefa42b 100644 --- a/src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java +++ b/src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java @@ -1,5 +1,8 @@ package li.strolch.model.timevalue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + import java.util.Collection; import java.util.HashMap; import java.util.HashSet; @@ -7,7 +10,6 @@ import java.util.Map; import java.util.Set; import java.util.SortedSet; -import junit.framework.Assert; import li.strolch.model.timevalue.impl.AString; import li.strolch.model.timevalue.impl.StringSetValue; import li.strolch.model.timevalue.impl.TimeVariable; @@ -28,41 +30,41 @@ public class StringTimeVariableTest { @Before public void init() { - timeVariable = new TimeVariable>>(); + this.timeVariable = new TimeVariable>>(); for (Long i = 0L; i < MAX; i += STEP) { Set testSet = new HashSet(); StringSetValue testValue = new StringSetValue(testSet); - testSets.put(i, testValue); - testSet.add(new AString("string " + i)); - timeVariable.setValueAt(i, new StringSetValue(testSet)); + this.testSets.put(i, testValue); + testSet.add(new AString("string " + i)); //$NON-NLS-1$ + this.timeVariable.setValueAt(i, new StringSetValue(testSet)); } } @Test public void testGetValueAt() { - ITimeValue>> valueAt = timeVariable.getValueAt(PICK); - Assert.assertEquals(true, valueAt.getValue().matches(testSets.get(PICK))); + ITimeValue>> valueAt = this.timeVariable.getValueAt(PICK); + assertEquals(true, valueAt.getValue().matches(this.testSets.get(PICK))); } @Test public void testGetFutureValues() { - Collection>>> futureValues = timeVariable.getFutureValues(PICK); + Collection>>> futureValues = this.timeVariable.getFutureValues(PICK); for (ITimeValue>> iTimeValue : futureValues) { Long time = iTimeValue.getTime(); - Assert.assertEquals(true, time >= PICK); - Assert.assertNotNull(iTimeValue.getValue()); - Assert.assertEquals(true, iTimeValue.getValue().matches(testSets.get(time))); + assertEquals(true, time >= PICK); + assertNotNull(iTimeValue.getValue()); + assertEquals(true, iTimeValue.getValue().matches(this.testSets.get(time))); } } @Test public void testGetPastValues() { - Collection>>> pastValues = timeVariable.getPastValues(PICK); + Collection>>> pastValues = this.timeVariable.getPastValues(PICK); for (ITimeValue>> iTimeValue : pastValues) { Long time = iTimeValue.getTime(); - Assert.assertEquals(true, time < PICK); - Assert.assertNotNull(iTimeValue.getValue()); - Assert.assertEquals(true, iTimeValue.getValue().matches(testSets.get(time))); + assertEquals(true, time < PICK); + assertNotNull(iTimeValue.getValue()); + assertEquals(true, iTimeValue.getValue().matches(this.testSets.get(time))); } } @@ -70,45 +72,45 @@ public class StringTimeVariableTest { public void testApplyChange() { Set testSet = new HashSet(); - testSet.add(new AString("Martin")); + testSet.add(new AString("Martin")); //$NON-NLS-1$ StringSetValue testValue = new StringSetValue(testSet); - timeVariable = new TimeVariable>>(); - timeVariable.setValueAt(PICK, testValue); + this.timeVariable = new TimeVariable>>(); + this.timeVariable.setValueAt(PICK, testValue); IValue> inverseTestValue = testValue.getInverse(); IValueChange>> change = new ValueChange>>(PICK, inverseTestValue); - timeVariable.applyChange(change); + this.timeVariable.applyChange(change); // check the future values - Collection>>> futureValues = timeVariable.getFutureValues(0L); + Collection>>> futureValues = this.timeVariable.getFutureValues(0L); for (ITimeValue>> iTimeValue : futureValues) { - System.out.println("++ " + iTimeValue); + System.out.println("++ " + iTimeValue); //$NON-NLS-1$ } - - Assert.assertEquals(1, futureValues.size()); // a empty one is left + + assertEquals(1, futureValues.size()); // a empty one is left } @Test public void testCompact() { - timeVariable = new TimeVariable>>(); + this.timeVariable = new TimeVariable>>(); for (Long i = 0L; i < MAX; i += STEP) { Set testSet = new HashSet(); StringSetValue testValue = new StringSetValue(testSet); - testSets.put(i, testValue); - testSet.add(new AString("same string")); - timeVariable.setValueAt(i, new StringSetValue(testSet)); + this.testSets.put(i, testValue); + testSet.add(new AString("same string")); //$NON-NLS-1$ + this.timeVariable.setValueAt(i, new StringSetValue(testSet)); } - SortedSet>>> valuesInitial = timeVariable.getFutureValues(0L); - Assert.assertEquals(true, valuesInitial.size() > 1); + SortedSet>>> valuesInitial = this.timeVariable.getFutureValues(0L); + assertEquals(true, valuesInitial.size() > 1); - timeVariable.compact(); + this.timeVariable.compact(); - SortedSet>>> valuesCompacted = timeVariable.getFutureValues(0L); - Assert.assertEquals(1, valuesCompacted.size()); + SortedSet>>> valuesCompacted = this.timeVariable.getFutureValues(0L); + assertEquals(1, valuesCompacted.size()); } diff --git a/src/test/java/li/strolch/model/timevalue/ValueTests.java b/src/test/java/li/strolch/model/timevalue/ValueTests.java index f88a0512b..45fe25fec 100644 --- a/src/test/java/li/strolch/model/timevalue/ValueTests.java +++ b/src/test/java/li/strolch/model/timevalue/ValueTests.java @@ -22,10 +22,9 @@ public class ValueTests { DoubleValue value = new DoubleValue(10.0d); DoubleValue inverse = value.getInverse(); assertEquals(Double.valueOf(-10.0d), inverse.getValue()); - assertEquals(Double.valueOf(0), value.add(inverse.getValue()) - .getValue()); + assertEquals(Double.valueOf(0), value.add(inverse.getValue()).getValue()); } - + /** * check, that adding the inverse results in the neutral element (=0) */ @@ -34,8 +33,7 @@ public class ValueTests { IntegerValue value = new IntegerValue(10); IntegerValue inverse = value.getInverse(); assertEquals(Integer.valueOf(-10), inverse.getValue()); - assertEquals(Integer.valueOf(0), value.add(inverse.getValue()) - .getValue()); + assertEquals(Integer.valueOf(0), value.add(inverse.getValue()).getValue()); } /** @@ -45,7 +43,7 @@ public class ValueTests { public void testStringSetInverse() { Set aStrings = new HashSet(); for (int i = 0; i < 10; i++) { - aStrings.add(new AString("string " + i)); + aStrings.add(new AString("string " + i)); //$NON-NLS-1$ } IValue> value = new StringSetValue(aStrings); IValue> inverse = value.getInverse(); @@ -61,20 +59,19 @@ public class ValueTests { Set aStrings1 = new HashSet(); for (int i = 0; i < 10; i++) { - aStrings1.add(new AString("string " + i)); + aStrings1.add(new AString("string " + i)); //$NON-NLS-1$ } IValue> value1 = new StringSetValue(aStrings1); Set aStrings2 = new HashSet(); for (int i = 0; i < 9; i++) { - aStrings2.add(new AString("string " + i, true)); + aStrings2.add(new AString("string " + i, true)); //$NON-NLS-1$ } IValue> value2 = new StringSetValue(aStrings2); assertEquals(false, value1.matches(value2)); assertEquals(1, value1.add(value2.getValue()).getValue().size()); - assertEquals(10, value1.add(value2.getInverse().getValue()).getValue() - .size()); + assertEquals(10, value1.add(value2.getInverse().getValue()).getValue().size()); } } diff --git a/src/test/java/li/strolch/test/model/ModelTest.java b/src/test/java/li/strolch/test/model/ModelTest.java index d170c7d98..195957e40 100644 --- a/src/test/java/li/strolch/test/model/ModelTest.java +++ b/src/test/java/li/strolch/test/model/ModelTest.java @@ -1,8 +1,10 @@ package li.strolch.test.model; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + import java.util.ArrayList; -import junit.framework.Assert; import li.strolch.model.Order; import li.strolch.model.ParameterBag; import li.strolch.model.Resource; @@ -17,6 +19,7 @@ import li.strolch.model.parameter.StringParameter; import org.junit.Test; +@SuppressWarnings("nls") public class ModelTest { @Test @@ -38,11 +41,11 @@ public class ModelTest { public static void validateBag(ParameterBag bag) { - Assert.assertNotNull(bag); + assertNotNull(bag); - Assert.assertEquals(ModelTestHelper.BAG_ID, bag.getId()); - Assert.assertEquals(ModelTestHelper.BAG_NAME, bag.getName()); - Assert.assertEquals(ModelTestHelper.BAG_TYPE, bag.getType()); + assertEquals(ModelTestHelper.BAG_ID, bag.getId()); + assertEquals(ModelTestHelper.BAG_NAME, bag.getName()); + assertEquals(ModelTestHelper.BAG_TYPE, bag.getType()); validateParams(bag); } @@ -50,35 +53,35 @@ public class ModelTest { public static void validateParams(ParameterBag bag) { BooleanParameter boolParam = bag.getParameter(ModelTestHelper.PARAM_BOOLEAN_ID); - Assert.assertNotNull("Boolean Param missing with id " + ModelTestHelper.PARAM_BOOLEAN_ID, boolParam); - Assert.assertEquals(true, boolParam.getValue().booleanValue()); + assertNotNull("Boolean Param missing with id " + ModelTestHelper.PARAM_BOOLEAN_ID, boolParam); + assertEquals(true, boolParam.getValue().booleanValue()); FloatParameter floatParam = bag.getParameter(ModelTestHelper.PARAM_FLOAT_ID); - Assert.assertNotNull("Float Param missing with id " + ModelTestHelper.PARAM_FLOAT_ID, floatParam); - Assert.assertEquals(44.3, floatParam.getValue().doubleValue()); + assertNotNull("Float Param missing with id " + ModelTestHelper.PARAM_FLOAT_ID, floatParam); + assertEquals(44.3, floatParam.getValue().doubleValue(), 0.0001); IntegerParameter integerParam = bag.getParameter(ModelTestHelper.PARAM_INTEGER_ID); - Assert.assertNotNull("Integer Param missing with id " + ModelTestHelper.PARAM_INTEGER_ID, integerParam); - Assert.assertEquals(77, integerParam.getValue().intValue()); + assertNotNull("Integer Param missing with id " + ModelTestHelper.PARAM_INTEGER_ID, integerParam); + assertEquals(77, integerParam.getValue().intValue()); LongParameter longParam = bag.getParameter(ModelTestHelper.PARAM_LONG_ID); - Assert.assertNotNull("Long Param missing with id " + ModelTestHelper.PARAM_LONG_ID, longParam); - Assert.assertEquals(4453234566L, longParam.getValue().longValue()); + assertNotNull("Long Param missing with id " + ModelTestHelper.PARAM_LONG_ID, longParam); + assertEquals(4453234566L, longParam.getValue().longValue()); StringParameter stringParam = bag.getParameter(ModelTestHelper.PARAM_STRING_ID); - Assert.assertNotNull("String Param missing with id " + ModelTestHelper.PARAM_STRING_ID, stringParam); - Assert.assertEquals("Strolch", stringParam.getValue()); + assertNotNull("String Param missing with id " + ModelTestHelper.PARAM_STRING_ID, stringParam); + assertEquals("Strolch", stringParam.getValue()); DateParameter dateParam = bag.getParameter(ModelTestHelper.PARAM_DATE_ID); - Assert.assertNotNull("Date Param missing with id " + ModelTestHelper.PARAM_DATE_ID, dateParam); - Assert.assertEquals(1354295525628L, dateParam.getValue().longValue()); + assertNotNull("Date Param missing with id " + ModelTestHelper.PARAM_DATE_ID, dateParam); + assertEquals(1354295525628L, dateParam.getValue().longValue()); StringListParameter stringListP = bag.getParameter(ModelTestHelper.PARAM_LIST_STRING_ID); - Assert.assertNotNull("StringList Param missing with id " + ModelTestHelper.PARAM_LIST_STRING_ID, stringListP); + assertNotNull("StringList Param missing with id " + ModelTestHelper.PARAM_LIST_STRING_ID, stringListP); ArrayList stringList = new ArrayList(); stringList.add("Hello"); stringList.add("World"); - Assert.assertEquals(stringList, stringListP.getValue()); + assertEquals(stringList, stringListP.getValue()); } } diff --git a/src/test/java/li/strolch/test/model/ModelTestHelper.java b/src/test/java/li/strolch/test/model/ModelTestHelper.java index 20dbb24e2..33d023e7d 100644 --- a/src/test/java/li/strolch/test/model/ModelTestHelper.java +++ b/src/test/java/li/strolch/test/model/ModelTestHelper.java @@ -40,6 +40,7 @@ import li.strolch.model.parameter.StringParameter; * @author Robert von Burg * */ +@SuppressWarnings("nls") public class ModelTestHelper { public static final String PARAM_BOOLEAN_ID = "@param1"; From 80a7a326e000df378b578fdad5cc20c1e86aea8e Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 24 Oct 2013 20:07:34 +0200 Subject: [PATCH 18/88] [Minor] JavaDoc clarification --- src/main/java/li/strolch/model/StrolchElement.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/li/strolch/model/StrolchElement.java b/src/main/java/li/strolch/model/StrolchElement.java index d30e5c034..e9cfd3ca0 100644 --- a/src/main/java/li/strolch/model/StrolchElement.java +++ b/src/main/java/li/strolch/model/StrolchElement.java @@ -86,7 +86,7 @@ public interface StrolchElement extends Serializable, Comparable * Returns an {@link Element} object which is an XML representation of this object * * @param doc - * the document to which this element is being written. The client should not append to the document, the + * the document to which this element is being written. The client must not append to the document, the * caller will perform this as needed * * @return From 98e74901643c2a9153318a12857bb2bed4d5d0d0 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 24 Oct 2013 21:45:50 +0200 Subject: [PATCH 19/88] [New] Now all date parsing and formatting is done using ISO8601 --- src/main/java/li/strolch/model/Order.java | 11 +++++------ .../li/strolch/model/ParameterizedElement.java | 4 ++++ .../strolch/model/parameter/AbstractParameter.java | 14 +++++++------- .../li/strolch/model/parameter/DateParameter.java | 13 ++++++------- .../java/li/strolch/model/parameter/Parameter.java | 4 ++-- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/main/java/li/strolch/model/Order.java b/src/main/java/li/strolch/model/Order.java index 95d8bc26b..dad507816 100644 --- a/src/main/java/li/strolch/model/Order.java +++ b/src/main/java/li/strolch/model/Order.java @@ -26,6 +26,8 @@ import li.strolch.model.Locator.LocatorBuilder; import org.w3c.dom.Document; import org.w3c.dom.Element; +import ch.eitchnet.utils.iso8601.ISO8601FormatFactory; + /** * The Order is an object used in the EDF to transfer data from one range to another. Orders are not to be thought of as * Resources. Resources are supposed to be thought of as things i.e. a table, a machine and so forth, where a order is @@ -92,11 +94,10 @@ public class Order extends GroupedParameterizedElement { String date = element.getAttribute(Tags.DATE); String state = element.getAttribute(Tags.STATE); - // TODO the format should be globally configured if (date == null || date.isEmpty()) { setDate(0); } else { - setDate(Long.parseLong(date)); + setDate(ISO8601FormatFactory.getInstance().getDateFormat().parse(date)); } if (state == null || state.isEmpty()) { @@ -142,8 +143,7 @@ public class Order extends GroupedParameterizedElement { Element orderElement = doc.createElement(Tags.ORDER); fillElement(orderElement); - // TODO the format should be globally configured - orderElement.setAttribute(Tags.DATE, Long.toString(this.date)); + orderElement.setAttribute(Tags.DATE, ISO8601FormatFactory.getInstance().formatDate(this.date)); orderElement.setAttribute(Tags.STATE, this.state.toString()); return orderElement; @@ -187,9 +187,8 @@ public class Order extends GroupedParameterizedElement { builder.append(this.type); builder.append(", state="); builder.append(this.state); - // TODO the format should be globally configured builder.append(", date="); - builder.append(this.date); + builder.append(ISO8601FormatFactory.getInstance().formatDate(this.date)); builder.append("]"); return builder.toString(); diff --git a/src/main/java/li/strolch/model/ParameterizedElement.java b/src/main/java/li/strolch/model/ParameterizedElement.java index 313a4d26b..dc4815236 100644 --- a/src/main/java/li/strolch/model/ParameterizedElement.java +++ b/src/main/java/li/strolch/model/ParameterizedElement.java @@ -38,6 +38,7 @@ import li.strolch.model.parameter.FloatParameter; import li.strolch.model.parameter.IntegerParameter; import li.strolch.model.parameter.LongParameter; import li.strolch.model.parameter.Parameter; +import li.strolch.model.parameter.StringListParameter; import li.strolch.model.parameter.StringParameter; import org.w3c.dom.Element; @@ -239,6 +240,9 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { } else if (paramtype.equals(BooleanParameter.TYPE)) { BooleanParameter param = new BooleanParameter(paramElement); addParameter(param); + } else if (paramtype.equals(StringListParameter.TYPE)) { + StringListParameter param = new StringListParameter(paramElement); + addParameter(param); } else { String msg = "What kind of parameter is this: {0}"; //$NON-NLS-1$ msg = MessageFormat.format(msg, paramtype); diff --git a/src/main/java/li/strolch/model/parameter/AbstractParameter.java b/src/main/java/li/strolch/model/parameter/AbstractParameter.java index e6a4c9505..e55e75cce 100644 --- a/src/main/java/li/strolch/model/parameter/AbstractParameter.java +++ b/src/main/java/li/strolch/model/parameter/AbstractParameter.java @@ -44,9 +44,9 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem private static final long serialVersionUID = 0L; - protected boolean hidden; - protected String interpretation; - protected String uom; + protected boolean hidden = false; + protected String interpretation = INTERPRETATION_NONE; + protected String uom = UOM_NONE; protected ParameterizedElement parent; @@ -149,18 +149,18 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem } String interpretation = element.getAttribute(Tags.INTERPRETATION); - String isHidden = element.getAttribute(Tags.HIDDEN); + String hidden = element.getAttribute(Tags.HIDDEN); String uom = element.getAttribute(Tags.UOM); setInterpretation(interpretation); setUom(uom); - if (isHidden == null) { + if (StringHelper.isEmpty(hidden)) { setHidden(false); } else { - if (isHidden.equalsIgnoreCase(Boolean.TRUE.toString())) { + if (hidden.equalsIgnoreCase(Boolean.TRUE.toString())) { setHidden(true); - } else if (isHidden.equalsIgnoreCase(Boolean.FALSE.toString())) { + } else if (hidden.equalsIgnoreCase(Boolean.FALSE.toString())) { setHidden(false); } else { String msg = "Boolean string must be either {0} or {1}"; //$NON-NLS-1$ diff --git a/src/main/java/li/strolch/model/parameter/DateParameter.java b/src/main/java/li/strolch/model/parameter/DateParameter.java index 2478fb517..066457d0c 100644 --- a/src/main/java/li/strolch/model/parameter/DateParameter.java +++ b/src/main/java/li/strolch/model/parameter/DateParameter.java @@ -21,14 +21,15 @@ */ package li.strolch.model.parameter; -import java.text.DateFormat; import java.text.MessageFormat; -import org.w3c.dom.Element; - import li.strolch.exception.StrolchException; import li.strolch.model.Tags; + +import org.w3c.dom.Element; + import ch.eitchnet.utils.helper.StringHelper; +import ch.eitchnet.utils.iso8601.ISO8601FormatFactory; /** * @author Robert von Burg @@ -73,14 +74,12 @@ public class DateParameter extends AbstractParameter { throw new StrolchException(msg); } - setValue(Long.valueOf(valueS)); + setValue(ISO8601FormatFactory.getInstance().getDateFormat().parse(valueS)); } @Override public String getValueAsString() { - // TODO the format should be globally configured - DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); - return dateFormat.format(this.value); + return ISO8601FormatFactory.getInstance().formatDate(this.value); } @Override diff --git a/src/main/java/li/strolch/model/parameter/Parameter.java b/src/main/java/li/strolch/model/parameter/Parameter.java index 6b4abd5bc..54598caa8 100644 --- a/src/main/java/li/strolch/model/parameter/Parameter.java +++ b/src/main/java/li/strolch/model/parameter/Parameter.java @@ -71,9 +71,9 @@ public interface Parameter extends StrolchElement { /** * the value of the parameter * - * @param obj + * @param value */ - public void setValue(T obj); + public void setValue(T value); /** * get the hidden attribute From 681bf88d96b7a42a609423ecdd1df8d004be821d Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 24 Oct 2013 21:57:17 +0200 Subject: [PATCH 20/88] [Minor] fixed compile error due to wrong typing --- src/main/java/li/strolch/model/timevalue/ITimeVariable.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/li/strolch/model/timevalue/ITimeVariable.java b/src/main/java/li/strolch/model/timevalue/ITimeVariable.java index 682a4e773..f1bc79261 100644 --- a/src/main/java/li/strolch/model/timevalue/ITimeVariable.java +++ b/src/main/java/li/strolch/model/timevalue/ITimeVariable.java @@ -12,7 +12,8 @@ import java.util.SortedSet; * @param * the backing value of the timed value object */ -public interface ITimeVariable> { +@SuppressWarnings("rawtypes") +public interface ITimeVariable { /** * set the value at a point in time to a given time value object From 55fdc6cfc53d7599e2a7b9917104882537f34038 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 28 Oct 2013 18:58:11 +0100 Subject: [PATCH 21/88] [Minor] cleaned up .gitignore --- .DS_Store | Bin 6148 -> 0 bytes .gitignore | 12 ++++++++++++ 2 files changed, 12 insertions(+) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 68cc094d89a709cdd34d7544817777f3c6490145..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~&r8EF6vq=cwMB(qgdKzDA=_kZf`?KjcoaI=!HKq3T%k0h?c8Bji&y^`{~P}v z-%C<(y0eJ9K=OUbdr6uPG(Q+)+*?Fl#vI0&1sRp2u_0meM%R`JM&&q0J`WQaLhU`A z8{c0S{PqURS;p?d<=5{|;=Jf|KKNFnxxKS%*|xPmoy2J*m!4dtQGVsmR2?3Hb?8ukWl(I0fn(zYzy zd9x0Wj?XT}!BhGCQfZ1DAggp>w3b&e%pxBBEKOwk04;TN9Ysn6hyW2F0z^O&Fb9OS zM?8oC5g-EJ2;lx8AfviQE3InlfC8`2=x?H80vq2FsKTggw9*P5NL+UX)m^!HVsPCZ z+J%X8jaFK9cgEGsFpinIe!OrsJG2WG&bX_UN+Li6)(JFp)xq=s9DbRNkNov6R3idJ z;GYrT&5=LyU{U65{joeeYX#(6$e1v$LIV=mYnK41;6Bn)PVE;6dq&0p diff --git a/.gitignore b/.gitignore index c277ec491..fd1deeecb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,15 @@ /.classpath /.project /target +/target +/target +/target +/target +/target +/target +/target +/target +/target +/target +/target +/target From bca42e35c897354516968412ec2d6aca5399a35c Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Tue, 29 Oct 2013 21:04:50 +0100 Subject: [PATCH 22/88] [New] refactored Locator Now added method to add single element, or get parent. Also removed restriction for element to have at least three elements. Now one element is sufficient. --- src/main/java/li/strolch/model/Locator.java | 51 +++++++++++++++++---- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/src/main/java/li/strolch/model/Locator.java b/src/main/java/li/strolch/model/Locator.java index 7e89000c2..dc0d4e68a 100644 --- a/src/main/java/li/strolch/model/Locator.java +++ b/src/main/java/li/strolch/model/Locator.java @@ -70,8 +70,8 @@ public class Locator { * if the path is invalid, meaning has less than two elements in it */ public Locator(List pathElements) throws StrolchException { - if (pathElements == null || pathElements.size() > 2) - throw new StrolchException("The path elements may not be null and must contain at least 2 items"); //$NON-NLS-1$ + if (pathElements == null || pathElements.isEmpty()) + throw new StrolchException("The path elements may not be null and must contain at least 1 item"); //$NON-NLS-1$ this.pathElements = Collections.unmodifiableList(new ArrayList(pathElements)); } @@ -103,6 +103,21 @@ public class Locator { this.pathElements = Collections.unmodifiableList(fullPath); } + /** + * Internal constructor to append a sub element to a locator + * + * @param path + * the base path of the locator + * @param subElement + * the additional element + */ + private Locator(List path, String subElement) { + List fullPath = new ArrayList(); + fullPath.addAll(path); + fullPath.add(subElement); + this.pathElements = Collections.unmodifiableList(fullPath); + } + /** * Returns the number of elements which this {@link Locator} contains * @@ -124,6 +139,28 @@ public class Locator { return new Locator(this.pathElements, subPathElements); } + /** + * Returns a new {@link Locator} where the given sub element is appended to the locator + * + * @param subElement + * the sub element to append + * + * @return the new locator + */ + public Locator append(String subElement) { + return new Locator(this.pathElements, subElement); + } + + /** + * Returns a new {@link Locator} which is the parent of the current locator + * + * @return the new locator + */ + public Locator parent() { + ArrayList elements = new ArrayList<>(this.pathElements.subList(0, this.pathElements.size() - 1)); + return new Locator(elements); + } + /** * Returns the string represenation of this {@link Locator} by using the {@link #PATH_SEPARATOR} to separate the * values @@ -149,12 +186,6 @@ public class Locator { throw new StrolchException("A path may not be empty!"); //$NON-NLS-1$ String[] elements = path.split(Locator.PATH_SEPARATOR); - if (elements.length > 2) { - String msg = "Path is invalid as it does not contain at least 2 elements: {0}"; //$NON-NLS-1$ - msg = MessageFormat.format(msg, path); - throw new StrolchException(msg); - } - return Arrays.asList(elements); } @@ -170,8 +201,8 @@ public class Locator { * if the path elements does not contain at least two items */ private String formatPath(List pathElements) throws StrolchException { - if (pathElements.size() > 2) { - String msg = "A Path always consists of at least 2 elements: {0}"; //$NON-NLS-1$ + if (pathElements.isEmpty()) { + String msg = "A Path always consists of at least element: {0}"; //$NON-NLS-1$ msg = MessageFormat.format(msg, pathElements); throw new StrolchException(msg); } From bbd862de723d3707d0ae1b33676956c2e65c23a6 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 30 Oct 2013 07:41:55 +0100 Subject: [PATCH 23/88] [Minor] Added hashcode() and equals() to Locator --- src/main/java/li/strolch/model/Locator.java | 25 +++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/main/java/li/strolch/model/Locator.java b/src/main/java/li/strolch/model/Locator.java index dc0d4e68a..3e9391e9f 100644 --- a/src/main/java/li/strolch/model/Locator.java +++ b/src/main/java/li/strolch/model/Locator.java @@ -220,6 +220,31 @@ public class Locator { return sb.toString(); } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.pathElements == null) ? 0 : this.pathElements.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Locator other = (Locator) obj; + if (this.pathElements == null) { + if (other.pathElements != null) + return false; + } else if (!this.pathElements.equals(other.pathElements)) + return false; + return true; + } + /** * {@link LocatorBuilder} is used to build {@link Locator}s where a deep hierarchy is to be created. The * {@link #append(String)} method returns itself for chain building From 546f2c9caf6f11e5854fdf236ac18c23808fd1eb Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 30 Oct 2013 07:45:01 +0100 Subject: [PATCH 24/88] Revert "[New] refactored Locator" This reverts commit bca42e35c897354516968412ec2d6aca5399a35c. --- src/main/java/li/strolch/model/Locator.java | 51 ++++----------------- 1 file changed, 10 insertions(+), 41 deletions(-) diff --git a/src/main/java/li/strolch/model/Locator.java b/src/main/java/li/strolch/model/Locator.java index 3e9391e9f..c37fc9f17 100644 --- a/src/main/java/li/strolch/model/Locator.java +++ b/src/main/java/li/strolch/model/Locator.java @@ -70,8 +70,8 @@ public class Locator { * if the path is invalid, meaning has less than two elements in it */ public Locator(List pathElements) throws StrolchException { - if (pathElements == null || pathElements.isEmpty()) - throw new StrolchException("The path elements may not be null and must contain at least 1 item"); //$NON-NLS-1$ + if (pathElements == null || pathElements.size() > 2) + throw new StrolchException("The path elements may not be null and must contain at least 2 items"); //$NON-NLS-1$ this.pathElements = Collections.unmodifiableList(new ArrayList(pathElements)); } @@ -103,21 +103,6 @@ public class Locator { this.pathElements = Collections.unmodifiableList(fullPath); } - /** - * Internal constructor to append a sub element to a locator - * - * @param path - * the base path of the locator - * @param subElement - * the additional element - */ - private Locator(List path, String subElement) { - List fullPath = new ArrayList(); - fullPath.addAll(path); - fullPath.add(subElement); - this.pathElements = Collections.unmodifiableList(fullPath); - } - /** * Returns the number of elements which this {@link Locator} contains * @@ -139,28 +124,6 @@ public class Locator { return new Locator(this.pathElements, subPathElements); } - /** - * Returns a new {@link Locator} where the given sub element is appended to the locator - * - * @param subElement - * the sub element to append - * - * @return the new locator - */ - public Locator append(String subElement) { - return new Locator(this.pathElements, subElement); - } - - /** - * Returns a new {@link Locator} which is the parent of the current locator - * - * @return the new locator - */ - public Locator parent() { - ArrayList elements = new ArrayList<>(this.pathElements.subList(0, this.pathElements.size() - 1)); - return new Locator(elements); - } - /** * Returns the string represenation of this {@link Locator} by using the {@link #PATH_SEPARATOR} to separate the * values @@ -186,6 +149,12 @@ public class Locator { throw new StrolchException("A path may not be empty!"); //$NON-NLS-1$ String[] elements = path.split(Locator.PATH_SEPARATOR); + if (elements.length > 2) { + String msg = "Path is invalid as it does not contain at least 2 elements: {0}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, path); + throw new StrolchException(msg); + } + return Arrays.asList(elements); } @@ -201,8 +170,8 @@ public class Locator { * if the path elements does not contain at least two items */ private String formatPath(List pathElements) throws StrolchException { - if (pathElements.isEmpty()) { - String msg = "A Path always consists of at least element: {0}"; //$NON-NLS-1$ + if (pathElements.size() > 2) { + String msg = "A Path always consists of at least 2 elements: {0}"; //$NON-NLS-1$ msg = MessageFormat.format(msg, pathElements); throw new StrolchException(msg); } From 8c8a7b1dc413a01db05bf8e2127b1b7dd4ae14f2 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 30 Oct 2013 07:57:15 +0100 Subject: [PATCH 25/88] [Minor] Extended LocatorBuilder to allow removing last element --- src/main/java/li/strolch/model/Locator.java | 53 ++++++++++++++++----- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/src/main/java/li/strolch/model/Locator.java b/src/main/java/li/strolch/model/Locator.java index c37fc9f17..3512dac63 100644 --- a/src/main/java/li/strolch/model/Locator.java +++ b/src/main/java/li/strolch/model/Locator.java @@ -70,8 +70,8 @@ public class Locator { * if the path is invalid, meaning has less than two elements in it */ public Locator(List pathElements) throws StrolchException { - if (pathElements == null || pathElements.size() > 2) - throw new StrolchException("The path elements may not be null and must contain at least 2 items"); //$NON-NLS-1$ + if (pathElements == null || pathElements.isEmpty()) + throw new StrolchException("The path elements may not be null and must contain at least 1 item"); //$NON-NLS-1$ this.pathElements = Collections.unmodifiableList(new ArrayList(pathElements)); } @@ -103,6 +103,21 @@ public class Locator { this.pathElements = Collections.unmodifiableList(fullPath); } + /** + * Internal constructor to append a element to a constructor + * + * @param path + * the base path of the locator + * @param element + * the additional element + */ + private Locator(List path, String element) { + List fullPath = new ArrayList(); + fullPath.addAll(path); + fullPath.add(element); + this.pathElements = Collections.unmodifiableList(fullPath); + } + /** * Returns the number of elements which this {@link Locator} contains * @@ -125,7 +140,19 @@ public class Locator { } /** - * Returns the string represenation of this {@link Locator} by using the {@link #PATH_SEPARATOR} to separate the + * Returns a new {@link Locator} where the given element is appended to the locator + * + * @param element + * the element to append + * + * @return the new locator + */ + public Locator append(String element) { + return new Locator(this.pathElements, element); + } + + /** + * Returns the string representation of this {@link Locator} by using the {@link #PATH_SEPARATOR} to separate the * values */ @Override @@ -149,12 +176,6 @@ public class Locator { throw new StrolchException("A path may not be empty!"); //$NON-NLS-1$ String[] elements = path.split(Locator.PATH_SEPARATOR); - if (elements.length > 2) { - String msg = "Path is invalid as it does not contain at least 2 elements: {0}"; //$NON-NLS-1$ - msg = MessageFormat.format(msg, path); - throw new StrolchException(msg); - } - return Arrays.asList(elements); } @@ -170,8 +191,8 @@ public class Locator { * if the path elements does not contain at least two items */ private String formatPath(List pathElements) throws StrolchException { - if (pathElements.size() > 2) { - String msg = "A Path always consists of at least 2 elements: {0}"; //$NON-NLS-1$ + if (pathElements.isEmpty()) { + String msg = "A Path always consists of at least 1 element: {0}"; //$NON-NLS-1$ msg = MessageFormat.format(msg, pathElements); throw new StrolchException(msg); } @@ -244,6 +265,16 @@ public class Locator { return this; } + /** + * Remove the last element from the path + * + * @return this instance for chaining + */ + public LocatorBuilder removeLast() { + this.pathElements.remove(this.pathElements.size() - 1); + return this; + } + /** * Creates a {@link Locator} instance with the current elements * From d043c599100b65da97f390e9ee8df8a2af2a127b Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 18 Nov 2013 19:22:59 +0100 Subject: [PATCH 26/88] [Major] refactored the DateParameter and Order date to be Date, not long --- src/main/java/li/strolch/model/Order.java | 17 ++++++++++------- .../strolch/model/parameter/DateParameter.java | 13 +++++++------ .../java/li/strolch/test/model/ModelTest.java | 6 +++--- .../li/strolch/test/model/ModelTestHelper.java | 5 +++-- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/main/java/li/strolch/model/Order.java b/src/main/java/li/strolch/model/Order.java index dad507816..3aae680c9 100644 --- a/src/main/java/li/strolch/model/Order.java +++ b/src/main/java/li/strolch/model/Order.java @@ -21,11 +21,14 @@ */ package li.strolch.model; +import java.util.Date; + import li.strolch.model.Locator.LocatorBuilder; import org.w3c.dom.Document; import org.w3c.dom.Element; +import ch.eitchnet.utils.helper.StringHelper; import ch.eitchnet.utils.iso8601.ISO8601FormatFactory; /** @@ -43,7 +46,7 @@ public class Order extends GroupedParameterizedElement { private static final long serialVersionUID = 0L; - private long date; + private Date date; private State state; /** @@ -64,7 +67,7 @@ public class Order extends GroupedParameterizedElement { super(id, name, type); setState(State.CREATED); - setDate(System.currentTimeMillis()); + setDate(new Date()); } /** @@ -76,7 +79,7 @@ public class Order extends GroupedParameterizedElement { * @param date * @param state */ - public Order(String id, String name, String type, long date, State state) { + public Order(String id, String name, String type, Date date, State state) { super(id, name, type); setState(state); @@ -94,8 +97,8 @@ public class Order extends GroupedParameterizedElement { String date = element.getAttribute(Tags.DATE); String state = element.getAttribute(Tags.STATE); - if (date == null || date.isEmpty()) { - setDate(0); + if (StringHelper.isEmpty(date)) { + setDate(ISO8601FormatFactory.getInstance().getDateFormat().parse("-")); //$NON-NLS-1$ } else { setDate(ISO8601FormatFactory.getInstance().getDateFormat().parse(date)); } @@ -110,7 +113,7 @@ public class Order extends GroupedParameterizedElement { /** * @return the date */ - public long getDate() { + public Date getDate() { return this.date; } @@ -118,7 +121,7 @@ public class Order extends GroupedParameterizedElement { * @param date * the date to set */ - public void setDate(long date) { + public void setDate(Date date) { this.date = date; } diff --git a/src/main/java/li/strolch/model/parameter/DateParameter.java b/src/main/java/li/strolch/model/parameter/DateParameter.java index 066457d0c..8c040c7bf 100644 --- a/src/main/java/li/strolch/model/parameter/DateParameter.java +++ b/src/main/java/li/strolch/model/parameter/DateParameter.java @@ -22,6 +22,7 @@ package li.strolch.model.parameter; import java.text.MessageFormat; +import java.util.Date; import li.strolch.exception.StrolchException; import li.strolch.model.Tags; @@ -34,12 +35,12 @@ import ch.eitchnet.utils.iso8601.ISO8601FormatFactory; /** * @author Robert von Burg */ -public class DateParameter extends AbstractParameter { +public class DateParameter extends AbstractParameter { public static final String TYPE = "Date"; //$NON-NLS-1$ private static final long serialVersionUID = 0L; - private Long value; + private Date value; /** * Empty constructor @@ -55,7 +56,7 @@ public class DateParameter extends AbstractParameter { * @param name * @param value */ - public DateParameter(String id, String name, Long value) { + public DateParameter(String id, String name, Date value) { super(id, name); setValue(value); } @@ -83,12 +84,12 @@ public class DateParameter extends AbstractParameter { } @Override - public Long getValue() { + public Date getValue() { return this.value; } @Override - public void setValue(Long value) { + public void setValue(Date value) { validateValue(value); this.value = value; } @@ -99,7 +100,7 @@ public class DateParameter extends AbstractParameter { } @Override - public Parameter getClone() { + public Parameter getClone() { DateParameter clone = new DateParameter(); super.fillClone(clone); diff --git a/src/test/java/li/strolch/test/model/ModelTest.java b/src/test/java/li/strolch/test/model/ModelTest.java index 195957e40..a7197216a 100644 --- a/src/test/java/li/strolch/test/model/ModelTest.java +++ b/src/test/java/li/strolch/test/model/ModelTest.java @@ -4,6 +4,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import java.util.ArrayList; +import java.util.Date; import li.strolch.model.Order; import li.strolch.model.ParameterBag; @@ -33,8 +34,7 @@ public class ModelTest { @Test public void shouldCreateOrder() { - Order order = ModelTestHelper.createOrder("@ord01", "Test Order", "MyType", System.currentTimeMillis(), - State.OPEN); + Order order = ModelTestHelper.createOrder("@ord01", "Test Order", "MyType", new Date(), State.OPEN); ParameterBag bag = order.getParameterBag(ModelTestHelper.BAG_ID); validateBag(bag); } @@ -74,7 +74,7 @@ public class ModelTest { DateParameter dateParam = bag.getParameter(ModelTestHelper.PARAM_DATE_ID); assertNotNull("Date Param missing with id " + ModelTestHelper.PARAM_DATE_ID, dateParam); - assertEquals(1354295525628L, dateParam.getValue().longValue()); + assertEquals(1354295525628L, dateParam.getValue().getTime()); StringListParameter stringListP = bag.getParameter(ModelTestHelper.PARAM_LIST_STRING_ID); assertNotNull("StringList Param missing with id " + ModelTestHelper.PARAM_LIST_STRING_ID, stringListP); diff --git a/src/test/java/li/strolch/test/model/ModelTestHelper.java b/src/test/java/li/strolch/test/model/ModelTestHelper.java index 33d023e7d..7610db82a 100644 --- a/src/test/java/li/strolch/test/model/ModelTestHelper.java +++ b/src/test/java/li/strolch/test/model/ModelTestHelper.java @@ -22,6 +22,7 @@ package li.strolch.test.model; import java.util.ArrayList; +import java.util.Date; import li.strolch.model.Order; import li.strolch.model.ParameterBag; @@ -106,7 +107,7 @@ public class ModelTestHelper { * * @return the newly created {@link Order} */ - public static Order createOrder(String id, String name, String type, long date, State state) { + public static Order createOrder(String id, String name, String type, Date date, State state) { Order order = new Order(id, name, type, date, state); ParameterBag bag = createParameterBag(BAG_ID, BAG_NAME, BAG_TYPE); @@ -166,7 +167,7 @@ public class ModelTestHelper { StringParameter stringParam = new StringParameter(PARAM_STRING_ID, PARAM_STRING_NAME, "Strolch"); bag.addParameter(stringParam); - DateParameter dateParam = new DateParameter(PARAM_DATE_ID, PARAM_DATE_NAME, 1354295525628L); + DateParameter dateParam = new DateParameter(PARAM_DATE_ID, PARAM_DATE_NAME, new Date(1354295525628L)); bag.addParameter(dateParam); ArrayList stringList = new ArrayList(); From 7289dccdfc1d5e0d9ca8ed5a2ae576172a6eb04c Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Tue, 19 Nov 2013 22:54:25 +0100 Subject: [PATCH 27/88] [New] added parseFromString()-methods to all Parameter implementations --- .../model/parameter/BooleanParameter.java | 6 ++++- .../model/parameter/DateParameter.java | 6 ++++- .../model/parameter/FloatParameter.java | 6 ++++- .../model/parameter/IntegerParameter.java | 6 ++++- .../model/parameter/LongParameter.java | 13 +++++++---- .../model/parameter/StringListParameter.java | 23 ++++++++++--------- 6 files changed, 41 insertions(+), 19 deletions(-) diff --git a/src/main/java/li/strolch/model/parameter/BooleanParameter.java b/src/main/java/li/strolch/model/parameter/BooleanParameter.java index 4975ad326..206fd6d47 100644 --- a/src/main/java/li/strolch/model/parameter/BooleanParameter.java +++ b/src/main/java/li/strolch/model/parameter/BooleanParameter.java @@ -72,7 +72,7 @@ public class BooleanParameter extends AbstractParameter { throw new StrolchException(msg); } - setValue(Boolean.valueOf(valueS)); + setValue(parseFromString(valueS)); } @Override @@ -106,4 +106,8 @@ public class BooleanParameter extends AbstractParameter { return clone; } + + public static Boolean parseFromString(String valueS) { + return Boolean.valueOf(valueS); + } } diff --git a/src/main/java/li/strolch/model/parameter/DateParameter.java b/src/main/java/li/strolch/model/parameter/DateParameter.java index 8c040c7bf..1e8f0b7e8 100644 --- a/src/main/java/li/strolch/model/parameter/DateParameter.java +++ b/src/main/java/li/strolch/model/parameter/DateParameter.java @@ -75,7 +75,7 @@ public class DateParameter extends AbstractParameter { throw new StrolchException(msg); } - setValue(ISO8601FormatFactory.getInstance().getDateFormat().parse(valueS)); + setValue(parseFromString(valueS)); } @Override @@ -109,4 +109,8 @@ public class DateParameter extends AbstractParameter { return clone; } + + public static Date parseFromString(String valueS) { + return ISO8601FormatFactory.getInstance().getDateFormat().parse(valueS); + } } diff --git a/src/main/java/li/strolch/model/parameter/FloatParameter.java b/src/main/java/li/strolch/model/parameter/FloatParameter.java index 7fef5a73d..fce922d55 100644 --- a/src/main/java/li/strolch/model/parameter/FloatParameter.java +++ b/src/main/java/li/strolch/model/parameter/FloatParameter.java @@ -75,7 +75,7 @@ public class FloatParameter extends AbstractParameter { throw new StrolchException(msg); } - setValue(Double.valueOf(valueS)); + setValue(parseFromString(valueS)); } @Override @@ -109,4 +109,8 @@ public class FloatParameter extends AbstractParameter { return clone; } + + public static Double parseFromString(String valueS) { + return Double.valueOf(valueS); + } } diff --git a/src/main/java/li/strolch/model/parameter/IntegerParameter.java b/src/main/java/li/strolch/model/parameter/IntegerParameter.java index 6fa09c79c..4a6c8e825 100644 --- a/src/main/java/li/strolch/model/parameter/IntegerParameter.java +++ b/src/main/java/li/strolch/model/parameter/IntegerParameter.java @@ -74,7 +74,7 @@ public class IntegerParameter extends AbstractParameter { throw new StrolchException(msg); } - setValue(Integer.valueOf(valueS)); + setValue(parseFromString(valueS)); } @Override @@ -108,4 +108,8 @@ public class IntegerParameter extends AbstractParameter { return clone; } + + public static Integer parseFromString(String valueS) { + return Integer.valueOf(valueS); + } } diff --git a/src/main/java/li/strolch/model/parameter/LongParameter.java b/src/main/java/li/strolch/model/parameter/LongParameter.java index 63c0af082..9f6f8d228 100644 --- a/src/main/java/li/strolch/model/parameter/LongParameter.java +++ b/src/main/java/li/strolch/model/parameter/LongParameter.java @@ -23,10 +23,11 @@ package li.strolch.model.parameter; import java.text.MessageFormat; -import org.w3c.dom.Element; - import li.strolch.exception.StrolchException; import li.strolch.model.Tags; + +import org.w3c.dom.Element; + import ch.eitchnet.utils.helper.StringHelper; /** @@ -56,7 +57,7 @@ public class LongParameter extends AbstractParameter { */ public LongParameter(String id, String name, Long value) { super(id, name); - setValue(Long.valueOf(value)); + setValue(value); } /** @@ -73,7 +74,7 @@ public class LongParameter extends AbstractParameter { throw new StrolchException(msg); } - setValue(Long.valueOf(valueS)); + setValue(parseFromString(valueS)); } @Override @@ -107,4 +108,8 @@ public class LongParameter extends AbstractParameter { return clone; } + + public static Long parseFromString(String valueS) { + return Long.valueOf(valueS); + } } diff --git a/src/main/java/li/strolch/model/parameter/StringListParameter.java b/src/main/java/li/strolch/model/parameter/StringListParameter.java index 673a59c79..3bf996a51 100644 --- a/src/main/java/li/strolch/model/parameter/StringListParameter.java +++ b/src/main/java/li/strolch/model/parameter/StringListParameter.java @@ -28,11 +28,12 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; -import org.w3c.dom.Element; - import li.strolch.exception.StrolchException; import li.strolch.model.StrolchElement; import li.strolch.model.Tags; + +import org.w3c.dom.Element; + import ch.eitchnet.utils.helper.StringHelper; /** @@ -79,15 +80,7 @@ public class StringListParameter extends AbstractParameter> impleme throw new StrolchException(msg); } - setValue(parse(valueS)); - } - - private List parse(String value) { - if (value.isEmpty()) - return Collections.emptyList(); - - String[] valueArr = value.split(VALUE_SEPARATOR); - return Arrays.asList(valueArr); + setValue(parseFromString(valueS)); } @Override @@ -147,4 +140,12 @@ public class StringListParameter extends AbstractParameter> impleme return clone; } + + public static List parseFromString(String value) { + if (value.isEmpty()) + return Collections.emptyList(); + + String[] valueArr = value.split(VALUE_SEPARATOR); + return Arrays.asList(valueArr); + } } From d3353062b949a6f005c76cb3a9e37303b4d8d53b Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 21 Nov 2013 18:17:35 +0100 Subject: [PATCH 28/88] [New] Implemented an XmlModelDefaultHandler to parse a model file Now we can parse a big file containing multiple types of objects. It is also supported to include files by using the element. Including tests --- src/main/java/li/strolch/model/Tags.java | 3 + .../model/xml/StrolchElementListener.java | 36 +++ .../model/xml/XmlModelDefaultHandler.java | 256 ++++++++++++++++++ .../{test/model => model/test}/ModelTest.java | 2 +- .../model => model/test}/ModelTestHelper.java | 2 +- .../test/XmlModelDefaultHandlerTest.java | 80 ++++++ .../{ => test}/timedstate/TimeStateTest.java | 4 +- .../timevalue/FloatTimeVariableTest.java | 5 +- .../timevalue/IntegerTimeVariableTest.java | 5 +- .../timevalue/StringTimeVariableTest.java | 5 +- .../{ => test}/timevalue/ValueTests.java | 3 +- src/test/resources/data/StrolchModel.xml | 18 ++ src/test/resources/data/orders/Orders.xml | 17 ++ src/test/resources/data/orders/Templates.xml | 15 + .../resources/data/resources/Resources.xml | 17 ++ .../resources/data/resources/Templates.xml | 14 + 16 files changed, 475 insertions(+), 7 deletions(-) create mode 100644 src/main/java/li/strolch/model/xml/StrolchElementListener.java create mode 100644 src/main/java/li/strolch/model/xml/XmlModelDefaultHandler.java rename src/test/java/li/strolch/{test/model => model/test}/ModelTest.java (99%) rename src/test/java/li/strolch/{test/model => model/test}/ModelTestHelper.java (99%) create mode 100644 src/test/java/li/strolch/model/test/XmlModelDefaultHandlerTest.java rename src/test/java/li/strolch/model/{ => test}/timedstate/TimeStateTest.java (95%) rename src/test/java/li/strolch/model/{ => test}/timevalue/FloatTimeVariableTest.java (95%) rename src/test/java/li/strolch/model/{ => test}/timevalue/IntegerTimeVariableTest.java (95%) rename src/test/java/li/strolch/model/{ => test}/timevalue/StringTimeVariableTest.java (95%) rename src/test/java/li/strolch/model/{ => test}/timevalue/ValueTests.java (96%) create mode 100644 src/test/resources/data/StrolchModel.xml create mode 100644 src/test/resources/data/orders/Orders.xml create mode 100644 src/test/resources/data/orders/Templates.xml create mode 100644 src/test/resources/data/resources/Resources.xml create mode 100644 src/test/resources/data/resources/Templates.xml diff --git a/src/main/java/li/strolch/model/Tags.java b/src/main/java/li/strolch/model/Tags.java index 53c192074..1b7904e5f 100644 --- a/src/main/java/li/strolch/model/Tags.java +++ b/src/main/java/li/strolch/model/Tags.java @@ -17,5 +17,8 @@ public class Tags { public static final String RESOURCE = "Resource"; public static final String ORDER = "Order"; public static final String PARAMETER_BAG = "ParameterBag"; + public static final String STROLCH_MODEL = "StrolchModel"; + public static final String INCLUDE_FILE = "IncludeFile"; + public static final String FILE = "file"; } diff --git a/src/main/java/li/strolch/model/xml/StrolchElementListener.java b/src/main/java/li/strolch/model/xml/StrolchElementListener.java new file mode 100644 index 000000000..24adba720 --- /dev/null +++ b/src/main/java/li/strolch/model/xml/StrolchElementListener.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.xml; + +import li.strolch.model.Order; +import li.strolch.model.Resource; + +/** + * @author Robert von Burg + * + */ +public interface StrolchElementListener { + + public void notifyResource(Resource resource); + + public void notifyOrder(Order order); +} diff --git a/src/main/java/li/strolch/model/xml/XmlModelDefaultHandler.java b/src/main/java/li/strolch/model/xml/XmlModelDefaultHandler.java new file mode 100644 index 000000000..ad088ad0f --- /dev/null +++ b/src/main/java/li/strolch/model/xml/XmlModelDefaultHandler.java @@ -0,0 +1,256 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.xml; + +import java.io.File; +import java.io.IOException; +import java.text.MessageFormat; +import java.util.Date; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + +import li.strolch.exception.StrolchException; +import li.strolch.model.Order; +import li.strolch.model.ParameterBag; +import li.strolch.model.Resource; +import li.strolch.model.State; +import li.strolch.model.Tags; +import li.strolch.model.parameter.BooleanParameter; +import li.strolch.model.parameter.DateParameter; +import li.strolch.model.parameter.FloatParameter; +import li.strolch.model.parameter.IntegerParameter; +import li.strolch.model.parameter.LongParameter; +import li.strolch.model.parameter.Parameter; +import li.strolch.model.parameter.StringListParameter; +import li.strolch.model.parameter.StringParameter; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +import ch.eitchnet.utils.helper.StringHelper; +import ch.eitchnet.utils.iso8601.ISO8601FormatFactory; + +/** + * @author Robert von Burg + * + */ +public class XmlModelDefaultHandler extends DefaultHandler { + + private static final Logger logger = LoggerFactory.getLogger(XmlModelDefaultHandler.class); + + private StrolchElementListener listener; + private File modelFile; + + private Resource resource; + private Order order; + private ParameterBag pBag; + + private XmlModelStatistics statistics; + + public XmlModelDefaultHandler(StrolchElementListener listener, File modelFile) { + this.listener = listener; + this.modelFile = modelFile; + this.statistics = new XmlModelStatistics(); + } + + /** + * @return the statistics + */ + public XmlModelStatistics getStatistics() { + return this.statistics; + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { + + // TODO split each root object into its own file + + switch (qName) { + + case Tags.STROLCH_MODEL: + break; + + case Tags.RESOURCE: + + String resId = attributes.getValue(Tags.ID); + String resName = attributes.getValue(Tags.NAME); + String resType = attributes.getValue(Tags.TYPE); + Resource resource = new Resource(resId, resName, resType); + this.resource = resource; + break; + + case Tags.ORDER: + String orderId = attributes.getValue(Tags.ID); + String orderName = attributes.getValue(Tags.NAME); + String orderType = attributes.getValue(Tags.TYPE); + String orderDateS = attributes.getValue(Tags.DATE); + String orderStateS = attributes.getValue(Tags.STATE); + Order order = new Order(orderId, orderName, orderType); + if (orderDateS != null) { + Date orderDate = ISO8601FormatFactory.getInstance().getDateFormat().parse(orderDateS); + order.setDate(orderDate); + } + if (orderDateS != null) { + State orderState = State.valueOf(orderStateS); + order.setState(orderState); + } + this.order = order; + break; + + case Tags.PARAMETER_BAG: + String pBagId = attributes.getValue(Tags.ID); + String pBagName = attributes.getValue(Tags.NAME); + String pBagType = attributes.getValue(Tags.TYPE); + ParameterBag pBag = new ParameterBag(pBagId, pBagName, pBagType); + this.pBag = pBag; + break; + + case Tags.PARAMETER: + String paramId = attributes.getValue(Tags.ID); + String paramName = attributes.getValue(Tags.NAME); + String paramType = attributes.getValue(Tags.TYPE); + String paramValue = attributes.getValue(Tags.VALUE); + String paramHiddenS = attributes.getValue(Tags.HIDDEN); + boolean paramHidden = paramHiddenS == null ? false : StringHelper.parseBoolean(paramHiddenS); + String paramUom = attributes.getValue(Tags.UOM); + String paramInterpretation = attributes.getValue(Tags.INTERPRETATION); + Parameter param; + switch (paramType) { + case StringParameter.TYPE: + param = new StringParameter(paramId, paramName, paramValue); + break; + case IntegerParameter.TYPE: + param = new IntegerParameter(paramId, paramName, IntegerParameter.parseFromString(paramValue)); + break; + case BooleanParameter.TYPE: + param = new BooleanParameter(paramId, paramName, BooleanParameter.parseFromString(paramValue)); + break; + case LongParameter.TYPE: + param = new LongParameter(paramId, paramName, LongParameter.parseFromString(paramValue)); + break; + case DateParameter.TYPE: + param = new DateParameter(paramId, paramName, DateParameter.parseFromString(paramValue)); + break; + case StringListParameter.TYPE: + param = new StringListParameter(paramId, paramName, StringListParameter.parseFromString(paramValue)); + break; + case FloatParameter.TYPE: + param = new FloatParameter(paramId, paramName, FloatParameter.parseFromString(paramValue)); + break; + default: + throw new UnsupportedOperationException(MessageFormat.format( + "Parameters of type {0} are not supported!", paramType)); //$NON-NLS-1$ + } + param.setHidden(paramHidden); + param.setUom(paramUom); + param.setInterpretation(paramInterpretation); + this.pBag.addParameter(param); + break; + + case Tags.INCLUDE_FILE: + + String includeFileS = attributes.getValue(Tags.FILE); + if (StringHelper.isEmpty(includeFileS)) + throw new IllegalArgumentException(MessageFormat.format( + "The attribute {0} is missing for IncludeFile!", Tags.FILE)); //$NON-NLS-1$ + File includeFile = new File(this.modelFile.getParentFile(), includeFileS); + if (!includeFile.exists() || !includeFile.canRead()) { + String msg = "The IncludeFile does not exist, or is not readable. Source model: {0} with IncludeFile: {1}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, this.modelFile.getName(), includeFileS); + throw new IllegalArgumentException(msg); + } + + XmlModelDefaultHandler handler = new XmlModelDefaultHandler(this.listener, includeFile); + handler.parseFile(); + this.statistics.nrOfOrders += handler.statistics.nrOfOrders; + this.statistics.nrOfResources += handler.statistics.nrOfResources; + + break; + default: + throw new IllegalArgumentException(MessageFormat.format("The element ''{0}'' is unhandled!", qName)); //$NON-NLS-1$ + } + } + + @Override + public void endElement(String uri, String localName, String qName) throws SAXException { + + switch (qName) { + case Tags.STROLCH_MODEL: + break; + case Tags.RESOURCE: + this.listener.notifyResource(this.resource); + this.statistics.nrOfResources++; + this.resource = null; + break; + case Tags.ORDER: + this.listener.notifyOrder(this.order); + this.statistics.nrOfOrders++; + this.order = null; + break; + case Tags.PARAMETER_BAG: + this.pBag = null; + break; + case Tags.PARAMETER: + break; + case Tags.INCLUDE_FILE: + break; + default: + throw new IllegalArgumentException(MessageFormat.format("The element ''{0}'' is unhandled!", qName)); //$NON-NLS-1$ + } + } + + public void parseFile() { + + try { + long startNanos = System.nanoTime(); + this.statistics.startTime = new Date(); + + SAXParserFactory spf = SAXParserFactory.newInstance(); + SAXParser sp = spf.newSAXParser(); + + sp.parse(this.modelFile, this); + + long endNanos = System.nanoTime(); + this.statistics.durationNanos = endNanos - startNanos; + String msg = "SAX parsed model file {0} took {1}"; //$NON-NLS-1$ + logger.info(MessageFormat.format(msg, this.modelFile.getAbsolutePath(), + StringHelper.formatNanoDuration(this.statistics.durationNanos))); + + } catch (ParserConfigurationException | SAXException | IOException e) { + + String msg = "Parsing failed due to internal error: {0}"; //$NON-NLS-1$ + throw new StrolchException(MessageFormat.format(msg, e.getMessage()), e); + } + } + + public static class XmlModelStatistics { + public Date startTime; + public long durationNanos; + public int nrOfResources; + public int nrOfOrders; + } +} diff --git a/src/test/java/li/strolch/test/model/ModelTest.java b/src/test/java/li/strolch/model/test/ModelTest.java similarity index 99% rename from src/test/java/li/strolch/test/model/ModelTest.java rename to src/test/java/li/strolch/model/test/ModelTest.java index a7197216a..f5de4dee3 100644 --- a/src/test/java/li/strolch/test/model/ModelTest.java +++ b/src/test/java/li/strolch/model/test/ModelTest.java @@ -1,4 +1,4 @@ -package li.strolch.test.model; +package li.strolch.model.test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/src/test/java/li/strolch/test/model/ModelTestHelper.java b/src/test/java/li/strolch/model/test/ModelTestHelper.java similarity index 99% rename from src/test/java/li/strolch/test/model/ModelTestHelper.java rename to src/test/java/li/strolch/model/test/ModelTestHelper.java index 7610db82a..280c37bee 100644 --- a/src/test/java/li/strolch/test/model/ModelTestHelper.java +++ b/src/test/java/li/strolch/model/test/ModelTestHelper.java @@ -19,7 +19,7 @@ * along with li.strolch.model. If not, see * . */ -package li.strolch.test.model; +package li.strolch.model.test; import java.util.ArrayList; import java.util.Date; diff --git a/src/test/java/li/strolch/model/test/XmlModelDefaultHandlerTest.java b/src/test/java/li/strolch/model/test/XmlModelDefaultHandlerTest.java new file mode 100644 index 000000000..cbd26a62e --- /dev/null +++ b/src/test/java/li/strolch/model/test/XmlModelDefaultHandlerTest.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.test; + +import static org.junit.Assert.assertEquals; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +import li.strolch.model.Order; +import li.strolch.model.Resource; +import li.strolch.model.xml.StrolchElementListener; +import li.strolch.model.xml.XmlModelDefaultHandler; +import li.strolch.model.xml.XmlModelDefaultHandler.XmlModelStatistics; + +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import ch.eitchnet.utils.helper.StringHelper; + +/** + * @author Robert von Burg + * + */ +@SuppressWarnings("nls") +public class XmlModelDefaultHandlerTest { + + private static final Logger logger = LoggerFactory.getLogger(XmlModelDefaultHandlerTest.class); + + @Test + public void shouldParseXmlModelFile() { + + final Map resourceMap = new HashMap<>(); + final Map orderMap = new HashMap<>(); + + File file = new File("src/test/resources/data/StrolchModel.xml"); + StrolchElementListener listener = new StrolchElementListener() { + @Override + public void notifyResource(Resource resource) { + resourceMap.put(resource.getId(), resource); + } + + @Override + public void notifyOrder(Order order) { + orderMap.put(order.getId(), order); + } + }; + XmlModelDefaultHandler handler = new XmlModelDefaultHandler(listener, file); + handler.parseFile(); + + assertEquals(3, resourceMap.size()); + assertEquals(3, orderMap.size()); + + XmlModelStatistics statistics = handler.getStatistics(); + logger.info("Parsing took " + StringHelper.formatNanoDuration(statistics.durationNanos)); + assertEquals(3, statistics.nrOfOrders); + assertEquals(3, statistics.nrOfResources); + } +} diff --git a/src/test/java/li/strolch/model/timedstate/TimeStateTest.java b/src/test/java/li/strolch/model/test/timedstate/TimeStateTest.java similarity index 95% rename from src/test/java/li/strolch/model/timedstate/TimeStateTest.java rename to src/test/java/li/strolch/model/test/timedstate/TimeStateTest.java index 8c685ca50..e2182fba8 100644 --- a/src/test/java/li/strolch/model/timedstate/TimeStateTest.java +++ b/src/test/java/li/strolch/model/test/timedstate/TimeStateTest.java @@ -1,8 +1,10 @@ -package li.strolch.model.timedstate; +package li.strolch.model.test.timedstate; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import li.strolch.model.timedstate.ITimedState; +import li.strolch.model.timedstate.TimedState; import li.strolch.model.timevalue.ITimeValue; import li.strolch.model.timevalue.IValueChange; import li.strolch.model.timevalue.impl.DoubleValue; diff --git a/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java b/src/test/java/li/strolch/model/test/timevalue/FloatTimeVariableTest.java similarity index 95% rename from src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java rename to src/test/java/li/strolch/model/test/timevalue/FloatTimeVariableTest.java index 2a0cb99df..fd09d465a 100644 --- a/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java +++ b/src/test/java/li/strolch/model/test/timevalue/FloatTimeVariableTest.java @@ -1,4 +1,4 @@ -package li.strolch.model.timevalue; +package li.strolch.model.test.timevalue; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -7,6 +7,9 @@ import static org.junit.Assert.assertTrue; import java.util.Collection; import java.util.SortedSet; +import li.strolch.model.timevalue.ITimeValue; +import li.strolch.model.timevalue.IValue; +import li.strolch.model.timevalue.IValueChange; import li.strolch.model.timevalue.impl.DoubleValue; import li.strolch.model.timevalue.impl.TimeVariable; import li.strolch.model.timevalue.impl.ValueChange; diff --git a/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java b/src/test/java/li/strolch/model/test/timevalue/IntegerTimeVariableTest.java similarity index 95% rename from src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java rename to src/test/java/li/strolch/model/test/timevalue/IntegerTimeVariableTest.java index cd3156221..d11460032 100644 --- a/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java +++ b/src/test/java/li/strolch/model/test/timevalue/IntegerTimeVariableTest.java @@ -1,4 +1,4 @@ -package li.strolch.model.timevalue; +package li.strolch.model.test.timevalue; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -8,6 +8,9 @@ import java.util.HashMap; import java.util.Map; import java.util.SortedSet; +import li.strolch.model.timevalue.ITimeValue; +import li.strolch.model.timevalue.IValue; +import li.strolch.model.timevalue.IValueChange; import li.strolch.model.timevalue.impl.IntegerValue; import li.strolch.model.timevalue.impl.TimeVariable; import li.strolch.model.timevalue.impl.ValueChange; diff --git a/src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java b/src/test/java/li/strolch/model/test/timevalue/StringTimeVariableTest.java similarity index 95% rename from src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java rename to src/test/java/li/strolch/model/test/timevalue/StringTimeVariableTest.java index 6efefa42b..18f801549 100644 --- a/src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java +++ b/src/test/java/li/strolch/model/test/timevalue/StringTimeVariableTest.java @@ -1,4 +1,4 @@ -package li.strolch.model.timevalue; +package li.strolch.model.test.timevalue; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -10,6 +10,9 @@ import java.util.Map; import java.util.Set; import java.util.SortedSet; +import li.strolch.model.timevalue.ITimeValue; +import li.strolch.model.timevalue.IValue; +import li.strolch.model.timevalue.IValueChange; import li.strolch.model.timevalue.impl.AString; import li.strolch.model.timevalue.impl.StringSetValue; import li.strolch.model.timevalue.impl.TimeVariable; diff --git a/src/test/java/li/strolch/model/timevalue/ValueTests.java b/src/test/java/li/strolch/model/test/timevalue/ValueTests.java similarity index 96% rename from src/test/java/li/strolch/model/timevalue/ValueTests.java rename to src/test/java/li/strolch/model/test/timevalue/ValueTests.java index 45fe25fec..a6489fac8 100644 --- a/src/test/java/li/strolch/model/timevalue/ValueTests.java +++ b/src/test/java/li/strolch/model/test/timevalue/ValueTests.java @@ -1,10 +1,11 @@ -package li.strolch.model.timevalue; +package li.strolch.model.test.timevalue; import static org.junit.Assert.assertEquals; import java.util.HashSet; import java.util.Set; +import li.strolch.model.timevalue.IValue; import li.strolch.model.timevalue.impl.AString; import li.strolch.model.timevalue.impl.DoubleValue; import li.strolch.model.timevalue.impl.IntegerValue; diff --git a/src/test/resources/data/StrolchModel.xml b/src/test/resources/data/StrolchModel.xml new file mode 100644 index 000000000..818cccb2d --- /dev/null +++ b/src/test/resources/data/StrolchModel.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/data/orders/Orders.xml b/src/test/resources/data/orders/Orders.xml new file mode 100644 index 000000000..1e4b66d00 --- /dev/null +++ b/src/test/resources/data/orders/Orders.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/data/orders/Templates.xml b/src/test/resources/data/orders/Templates.xml new file mode 100644 index 000000000..bd86a6925 --- /dev/null +++ b/src/test/resources/data/orders/Templates.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/src/test/resources/data/resources/Resources.xml b/src/test/resources/data/resources/Resources.xml new file mode 100644 index 000000000..9ac7b632a --- /dev/null +++ b/src/test/resources/data/resources/Resources.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/data/resources/Templates.xml b/src/test/resources/data/resources/Templates.xml new file mode 100644 index 000000000..f122f0346 --- /dev/null +++ b/src/test/resources/data/resources/Templates.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + From 2ab55605b920289ee80715ac957295548b6f948b Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 11 Dec 2013 23:50:20 +0100 Subject: [PATCH 29/88] [New] finally implemented a query model In li.strolch.model we keep the API so that the visitors are available in all Strolch projects --- .../model/GroupedParameterizedElement.java | 11 + .../li/strolch/model/ModelGenerator.java} | 29 ++- .../li/strolch/model/query/AndSelection.java | 41 ++++ .../strolch/model/query/BooleanSelection.java | 43 ++++ .../li/strolch/model/query/DateSelection.java | 45 ++++ .../li/strolch/model/query/IdSelection.java | 49 ++++ .../li/strolch/model/query/NameSelection.java | 49 ++++ .../li/strolch/model/query/Navigation.java | 34 +++ .../li/strolch/model/query/OrSelection.java | 40 ++++ .../li/strolch/model/query/OrderQuery.java | 36 +++ .../model/query/OrderQueryVisitor.java | 31 +++ .../strolch/model/query/OrderSelection.java | 36 +++ .../model/query/OrderSelectionVisitor.java | 33 +++ .../model/query/ParameterSelection.java | 216 ++++++++++++++++++ .../query/ParameterSelectionVisitor.java | 51 +++++ .../java/li/strolch/model/query/Query.java | 32 +++ .../li/strolch/model/query/QueryVisitor.java | 33 +++ .../li/strolch/model/query/ResourceQuery.java | 32 +++ .../model/query/ResourceQueryVisitor.java | 31 +++ .../li/strolch/model/query/Selection.java | 32 +++ .../strolch/model/query/StateSelection.java | 44 ++++ .../model/query/StrolchElementSelection.java | 35 +++ .../query/StrolchElementSelectionVisitor.java | 34 +++ .../li/strolch/model/query/StrolchQuery.java | 59 +++++ .../model/query/StrolchTypeNavigation.java | 51 +++++ src/test/java/li/strolch/model/ModelTest.java | 88 +++++++ .../XmlModelDefaultHandlerTest.java | 2 +- .../java/li/strolch/model/test/ModelTest.java | 87 ------- .../{test => }/timedstate/TimeStateTest.java | 2 +- .../timevalue/FloatTimeVariableTest.java | 2 +- .../timevalue/IntegerTimeVariableTest.java | 2 +- .../timevalue/StringTimeVariableTest.java | 2 +- .../{test => }/timevalue/ValueTests.java | 2 +- 33 files changed, 1214 insertions(+), 100 deletions(-) rename src/{test/java/li/strolch/model/test/ModelTestHelper.java => main/java/li/strolch/model/ModelGenerator.java} (88%) create mode 100644 src/main/java/li/strolch/model/query/AndSelection.java create mode 100644 src/main/java/li/strolch/model/query/BooleanSelection.java create mode 100644 src/main/java/li/strolch/model/query/DateSelection.java create mode 100644 src/main/java/li/strolch/model/query/IdSelection.java create mode 100644 src/main/java/li/strolch/model/query/NameSelection.java create mode 100644 src/main/java/li/strolch/model/query/Navigation.java create mode 100644 src/main/java/li/strolch/model/query/OrSelection.java create mode 100644 src/main/java/li/strolch/model/query/OrderQuery.java create mode 100644 src/main/java/li/strolch/model/query/OrderQueryVisitor.java create mode 100644 src/main/java/li/strolch/model/query/OrderSelection.java create mode 100644 src/main/java/li/strolch/model/query/OrderSelectionVisitor.java create mode 100644 src/main/java/li/strolch/model/query/ParameterSelection.java create mode 100644 src/main/java/li/strolch/model/query/ParameterSelectionVisitor.java create mode 100644 src/main/java/li/strolch/model/query/Query.java create mode 100644 src/main/java/li/strolch/model/query/QueryVisitor.java create mode 100644 src/main/java/li/strolch/model/query/ResourceQuery.java create mode 100644 src/main/java/li/strolch/model/query/ResourceQueryVisitor.java create mode 100644 src/main/java/li/strolch/model/query/Selection.java create mode 100644 src/main/java/li/strolch/model/query/StateSelection.java create mode 100644 src/main/java/li/strolch/model/query/StrolchElementSelection.java create mode 100644 src/main/java/li/strolch/model/query/StrolchElementSelectionVisitor.java create mode 100644 src/main/java/li/strolch/model/query/StrolchQuery.java create mode 100644 src/main/java/li/strolch/model/query/StrolchTypeNavigation.java create mode 100644 src/test/java/li/strolch/model/ModelTest.java rename src/test/java/li/strolch/model/{test => }/XmlModelDefaultHandlerTest.java (98%) delete mode 100644 src/test/java/li/strolch/model/test/ModelTest.java rename src/test/java/li/strolch/model/{test => }/timedstate/TimeStateTest.java (98%) rename src/test/java/li/strolch/model/{test => }/timevalue/FloatTimeVariableTest.java (99%) rename src/test/java/li/strolch/model/{test => }/timevalue/IntegerTimeVariableTest.java (98%) rename src/test/java/li/strolch/model/{test => }/timevalue/StringTimeVariableTest.java (98%) rename src/test/java/li/strolch/model/{test => }/timevalue/ValueTests.java (98%) diff --git a/src/main/java/li/strolch/model/GroupedParameterizedElement.java b/src/main/java/li/strolch/model/GroupedParameterizedElement.java index 2428e8444..3510e4851 100644 --- a/src/main/java/li/strolch/model/GroupedParameterizedElement.java +++ b/src/main/java/li/strolch/model/GroupedParameterizedElement.java @@ -193,6 +193,17 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement return this.parameterBagMap.remove(key); } + /** + * Returns true if the {@link ParameterBag} with the given key exists on this {@link GroupedParameterizedElement}. + * + * @param bagKey + * the key of the {@link ParameterBag} which is to be checked for existence + * @return true if the {@link ParameterBag} with the given key exists on this {@link GroupedParameterizedElement}. + */ + public boolean hasParameterBag(String bagKey) { + return this.parameterBagMap != null && this.parameterBagMap.containsKey(bagKey); + } + /** * Returns true if the {@link Parameter} with the given paramKey exists on the {@link ParameterBag} with the given * bagKey diff --git a/src/test/java/li/strolch/model/test/ModelTestHelper.java b/src/main/java/li/strolch/model/ModelGenerator.java similarity index 88% rename from src/test/java/li/strolch/model/test/ModelTestHelper.java rename to src/main/java/li/strolch/model/ModelGenerator.java index 280c37bee..18c9ca1d7 100644 --- a/src/test/java/li/strolch/model/test/ModelTestHelper.java +++ b/src/main/java/li/strolch/model/ModelGenerator.java @@ -19,15 +19,11 @@ * along with li.strolch.model. If not, see * . */ -package li.strolch.model.test; +package li.strolch.model; import java.util.ArrayList; import java.util.Date; -import li.strolch.model.Order; -import li.strolch.model.ParameterBag; -import li.strolch.model.Resource; -import li.strolch.model.State; import li.strolch.model.parameter.BooleanParameter; import li.strolch.model.parameter.DateParameter; import li.strolch.model.parameter.FloatParameter; @@ -38,11 +34,13 @@ import li.strolch.model.parameter.StringListParameter; import li.strolch.model.parameter.StringParameter; /** - * @author Robert von Burg + * Class which can be used to generate objects which implement {@link StrolchElement}. These generated classes can then + * be used in test classes etc. * + * @author Robert von Burg */ @SuppressWarnings("nls") -public class ModelTestHelper { +public class ModelGenerator { public static final String PARAM_BOOLEAN_ID = "@param1"; public static final String PARAM_BOOLEAN_NAME = "Boolean Param"; @@ -90,6 +88,23 @@ public class ModelTestHelper { return resource; } + /** + * Creates an {@link Order} with the given values and adds a {@link ParameterBag} by calling + * {@link #createParameterBag(String, String, String)} + * + * @param id + * the id of the {@link Order} + * @param name + * the name of the {@link Order} + * @param type + * the type of the {@link Order} + * + * @return the newly created {@link Order} + */ + public static Order createOrder(String id, String name, String type) { + return createOrder(id, name, type, new Date(), State.CREATED); + } + /** * Creates an {@link Order} with the given values and adds a {@link ParameterBag} by calling * {@link #createParameterBag(String, String, String)} diff --git a/src/main/java/li/strolch/model/query/AndSelection.java b/src/main/java/li/strolch/model/query/AndSelection.java new file mode 100644 index 000000000..754e7c7ae --- /dev/null +++ b/src/main/java/li/strolch/model/query/AndSelection.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +import java.util.List; + +/** + * @author Robert von Burg + */ +public class AndSelection extends BooleanSelection { + + /** + * @param selections + */ + public AndSelection(List selections) { + super(selections); + } + + public void accept(QueryVisitor visitor) { + visitor.visitAnd(this); + } +} diff --git a/src/main/java/li/strolch/model/query/BooleanSelection.java b/src/main/java/li/strolch/model/query/BooleanSelection.java new file mode 100644 index 000000000..8ecd98d23 --- /dev/null +++ b/src/main/java/li/strolch/model/query/BooleanSelection.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +import java.util.List; + +/** + * @author Robert von Burg + * + */ +public abstract class BooleanSelection implements Selection { + + protected List selections; + + public BooleanSelection(List selections) { + this.selections = selections; + } + + public List getSelections() { + return this.selections; + } + + public abstract void accept(QueryVisitor visitor); +} diff --git a/src/main/java/li/strolch/model/query/DateSelection.java b/src/main/java/li/strolch/model/query/DateSelection.java new file mode 100644 index 000000000..5e21e6e40 --- /dev/null +++ b/src/main/java/li/strolch/model/query/DateSelection.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +import java.util.Date; + +/** + * @author Robert von Burg + */ +public class DateSelection extends OrderSelection { + + private Date date; + + public DateSelection(Date date) { + this.date = date; + } + + public Date getDate() { + return this.date; + } + + @Override + public void accept(OrderSelectionVisitor visitor) { + visitor.visit(this); + } +} diff --git a/src/main/java/li/strolch/model/query/IdSelection.java b/src/main/java/li/strolch/model/query/IdSelection.java new file mode 100644 index 000000000..c4aeb5cce --- /dev/null +++ b/src/main/java/li/strolch/model/query/IdSelection.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +/** + * @author Robert von Burg + */ +public class IdSelection extends StrolchElementSelection { + + private String id; + + /** + * @param id + */ + public IdSelection(String id) { + this.id = id; + } + + /** + * @return the id + */ + public String getId() { + return this.id; + } + + @Override + public void accept(StrolchElementSelectionVisitor visitor) { + visitor.visit(this); + } +} diff --git a/src/main/java/li/strolch/model/query/NameSelection.java b/src/main/java/li/strolch/model/query/NameSelection.java new file mode 100644 index 000000000..acb5e244c --- /dev/null +++ b/src/main/java/li/strolch/model/query/NameSelection.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +/** + * @author Robert von Burg + */ +public class NameSelection extends StrolchElementSelection { + + private String name; + + /** + * @param name + */ + public NameSelection(String name) { + this.name = name; + } + + /** + * @return the name + */ + public String getName() { + return this.name; + } + + @Override + public void accept(StrolchElementSelectionVisitor visitor) { + visitor.visit(this); + } +} diff --git a/src/main/java/li/strolch/model/query/Navigation.java b/src/main/java/li/strolch/model/query/Navigation.java new file mode 100644 index 000000000..3e7bbf65d --- /dev/null +++ b/src/main/java/li/strolch/model/query/Navigation.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + + +/** + * @author Robert von Burg + * + */ +public interface Navigation { + + // marker interface + + public void accept(QueryVisitor visitor); +} diff --git a/src/main/java/li/strolch/model/query/OrSelection.java b/src/main/java/li/strolch/model/query/OrSelection.java new file mode 100644 index 000000000..67c5b59cf --- /dev/null +++ b/src/main/java/li/strolch/model/query/OrSelection.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +import java.util.List; + +/** + * @author Robert von Burg + * + */ +public class OrSelection extends BooleanSelection { + + public OrSelection(List selections) { + super(selections); + } + + @Override + public void accept(QueryVisitor visitor) { + visitor.visitOr(this); + } +} diff --git a/src/main/java/li/strolch/model/query/OrderQuery.java b/src/main/java/li/strolch/model/query/OrderQuery.java new file mode 100644 index 000000000..764439a98 --- /dev/null +++ b/src/main/java/li/strolch/model/query/OrderQuery.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +/** + * @author Robert von Burg + */ +public class OrderQuery extends StrolchQuery { + + public OrderQuery(Navigation navigation) { + super(navigation); + } + + public void add(OrderSelection selection) { + this.selections.add(selection); + } +} diff --git a/src/main/java/li/strolch/model/query/OrderQueryVisitor.java b/src/main/java/li/strolch/model/query/OrderQueryVisitor.java new file mode 100644 index 000000000..c637b4fc0 --- /dev/null +++ b/src/main/java/li/strolch/model/query/OrderQueryVisitor.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +/** + * @author Robert von Burg + * + */ +public interface OrderQueryVisitor extends OrderSelectionVisitor, ParameterSelectionVisitor { + + // marker interface +} diff --git a/src/main/java/li/strolch/model/query/OrderSelection.java b/src/main/java/li/strolch/model/query/OrderSelection.java new file mode 100644 index 000000000..0289afe75 --- /dev/null +++ b/src/main/java/li/strolch/model/query/OrderSelection.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +/** + * @author Robert von Burg + * + */ +public abstract class OrderSelection implements Selection { + + @Override + public void accept(QueryVisitor visitor) { + accept((OrderSelectionVisitor) visitor); + } + + public abstract void accept(OrderSelectionVisitor visitor); +} diff --git a/src/main/java/li/strolch/model/query/OrderSelectionVisitor.java b/src/main/java/li/strolch/model/query/OrderSelectionVisitor.java new file mode 100644 index 000000000..642cbd0e6 --- /dev/null +++ b/src/main/java/li/strolch/model/query/OrderSelectionVisitor.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +/** + * @author Robert von Burg + * + */ +public interface OrderSelectionVisitor extends StrolchElementSelectionVisitor { + + public void visit(DateSelection selection); + + public void visit(StateSelection selection); +} diff --git a/src/main/java/li/strolch/model/query/ParameterSelection.java b/src/main/java/li/strolch/model/query/ParameterSelection.java new file mode 100644 index 000000000..5f5ae57d5 --- /dev/null +++ b/src/main/java/li/strolch/model/query/ParameterSelection.java @@ -0,0 +1,216 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +import java.util.Date; +import java.util.List; + +/** + * @author Robert von Burg + */ +public abstract class ParameterSelection implements Selection { + + private String bagKey; + private String paramKey; + + public ParameterSelection(String bagKey, String paramKey) { + this.bagKey = bagKey; + this.paramKey = paramKey; + } + + /** + * @return the bagKey + */ + public String getBagKey() { + return this.bagKey; + } + + /** + * @return the paramKey + */ + public String getParamKey() { + return this.paramKey; + } + + @Override + public void accept(QueryVisitor visitor) { + accept((ParameterSelectionVisitor) visitor); + } + + public abstract void accept(ParameterSelectionVisitor visitor); + + public static ParameterSelection stringSelection(String bagKey, String paramKey, String value) { + return new StringParameterSelection(bagKey, paramKey, value); + } + + public static ParameterSelection integerSelection(String bagKey, String paramKey, int value) { + return new IntegerParameterSelection(bagKey, paramKey, value); + } + + public static ParameterSelection booleanSelection(String bagKey, String paramKey, boolean value) { + return new BooleanParameterSelection(bagKey, paramKey, value); + } + + public static ParameterSelection floatSelection(String bagKey, String paramKey, double value) { + return new FloatParameterSelection(bagKey, paramKey, value); + } + + public static ParameterSelection longSelection(String bagKey, String paramKey, long value) { + return new LongParameterSelection(bagKey, paramKey, value); + } + + public static ParameterSelection dateSelection(String bagKey, String paramKey, Date value) { + return new DateParameterSelection(bagKey, paramKey, value); + } + + public static ParameterSelection stringListSelection(String bagKey, String paramKey, List value) { + return new StringListParameterSelection(bagKey, paramKey, value); + } + + public static class StringParameterSelection extends ParameterSelection { + + private String value; + + public StringParameterSelection(String bagKey, String paramKey, String value) { + super(bagKey, paramKey); + this.value = value; + } + + public String getValue() { + return this.value; + } + + @Override + public void accept(ParameterSelectionVisitor visitor) { + visitor.visit(this); + } + } + + public static class IntegerParameterSelection extends ParameterSelection { + + private Integer value; + + public IntegerParameterSelection(String bagKey, String paramKey, Integer value) { + super(bagKey, paramKey); + this.value = value; + } + + public Integer getValue() { + return this.value; + } + + @Override + public void accept(ParameterSelectionVisitor visitor) { + visitor.visit(this); + } + } + + public static class BooleanParameterSelection extends ParameterSelection { + private Boolean value; + + public BooleanParameterSelection(String bagKey, String paramKey, Boolean value) { + super(bagKey, paramKey); + this.value = value; + } + + public Boolean getValue() { + return this.value; + } + + @Override + public void accept(ParameterSelectionVisitor visitor) { + visitor.visit(this); + } + } + + public static class LongParameterSelection extends ParameterSelection { + private Long value; + + public LongParameterSelection(String bagKey, String paramKey, Long value) { + super(bagKey, paramKey); + this.value = value; + } + + public Long getValue() { + return this.value; + } + + @Override + public void accept(ParameterSelectionVisitor visitor) { + visitor.visit(this); + } + } + + public static class FloatParameterSelection extends ParameterSelection { + private Double value; + + public FloatParameterSelection(String bagKey, String paramKey, Double value) { + super(bagKey, paramKey); + this.value = value; + } + + public Double getValue() { + return this.value; + } + + @Override + public void accept(ParameterSelectionVisitor visitor) { + visitor.visit(this); + } + } + + public static class DateParameterSelection extends ParameterSelection { + private Date value; + + public DateParameterSelection(String bagKey, String paramKey, Date value) { + super(bagKey, paramKey); + this.value = value; + } + + public Date getValue() { + return this.value; + } + + @Override + public void accept(ParameterSelectionVisitor visitor) { + visitor.visit(this); + } + } + + public static class StringListParameterSelection extends ParameterSelection { + private List value; + + public StringListParameterSelection(String bagKey, String paramKey, List value) { + super(bagKey, paramKey); + this.value = value; + } + + public List getValue() { + return this.value; + } + + @Override + public void accept(ParameterSelectionVisitor visitor) { + visitor.visit(this); + } + } +} diff --git a/src/main/java/li/strolch/model/query/ParameterSelectionVisitor.java b/src/main/java/li/strolch/model/query/ParameterSelectionVisitor.java new file mode 100644 index 000000000..784a10c7d --- /dev/null +++ b/src/main/java/li/strolch/model/query/ParameterSelectionVisitor.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +import li.strolch.model.query.ParameterSelection.BooleanParameterSelection; +import li.strolch.model.query.ParameterSelection.DateParameterSelection; +import li.strolch.model.query.ParameterSelection.FloatParameterSelection; +import li.strolch.model.query.ParameterSelection.IntegerParameterSelection; +import li.strolch.model.query.ParameterSelection.LongParameterSelection; +import li.strolch.model.query.ParameterSelection.StringListParameterSelection; +import li.strolch.model.query.ParameterSelection.StringParameterSelection; + +/** + * @author Robert von Burg + * + */ +public interface ParameterSelectionVisitor extends QueryVisitor { + + public void visit(StringParameterSelection selection); + + public void visit(IntegerParameterSelection selection); + + public void visit(BooleanParameterSelection selection); + + public void visit(LongParameterSelection selection); + + public void visit(FloatParameterSelection selection); + + public void visit(DateParameterSelection selection); + + public void visit(StringListParameterSelection selection); +} diff --git a/src/main/java/li/strolch/model/query/Query.java b/src/main/java/li/strolch/model/query/Query.java new file mode 100644 index 000000000..88bfe65d7 --- /dev/null +++ b/src/main/java/li/strolch/model/query/Query.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + + +/** + * @author Robert von Burg + * + */ +public interface Query { + + public void visit(T queryVisitor); +} diff --git a/src/main/java/li/strolch/model/query/QueryVisitor.java b/src/main/java/li/strolch/model/query/QueryVisitor.java new file mode 100644 index 000000000..d2147c9c0 --- /dev/null +++ b/src/main/java/li/strolch/model/query/QueryVisitor.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +/** + * @author Robert von Burg + * + */ +public interface QueryVisitor { + + public void visitAnd(AndSelection andSelection); + + public void visitOr(OrSelection orSelection); +} diff --git a/src/main/java/li/strolch/model/query/ResourceQuery.java b/src/main/java/li/strolch/model/query/ResourceQuery.java new file mode 100644 index 000000000..5ef97c77b --- /dev/null +++ b/src/main/java/li/strolch/model/query/ResourceQuery.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +/** + * @author Robert von Burg + */ +public class ResourceQuery extends StrolchQuery { + + public ResourceQuery(Navigation navigation) { + super(navigation); + } +} diff --git a/src/main/java/li/strolch/model/query/ResourceQueryVisitor.java b/src/main/java/li/strolch/model/query/ResourceQueryVisitor.java new file mode 100644 index 000000000..df4008278 --- /dev/null +++ b/src/main/java/li/strolch/model/query/ResourceQueryVisitor.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +/** + * @author Robert von Burg + * + */ +public interface ResourceQueryVisitor extends StrolchElementSelectionVisitor, ParameterSelectionVisitor { + + // marker interface +} diff --git a/src/main/java/li/strolch/model/query/Selection.java b/src/main/java/li/strolch/model/query/Selection.java new file mode 100644 index 000000000..e7186abb2 --- /dev/null +++ b/src/main/java/li/strolch/model/query/Selection.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +/** + * @author Robert von Burg + */ +public interface Selection { + + // marker interface + + public void accept(QueryVisitor visitor); +} diff --git a/src/main/java/li/strolch/model/query/StateSelection.java b/src/main/java/li/strolch/model/query/StateSelection.java new file mode 100644 index 000000000..636968a0e --- /dev/null +++ b/src/main/java/li/strolch/model/query/StateSelection.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +import li.strolch.model.State; + +/** + * @author Robert von Burg + * + */ +public class StateSelection { + + private State state; + + public StateSelection(State state) { + this.state = state; + } + + /** + * @return the state + */ + public State getState() { + return this.state; + } +} diff --git a/src/main/java/li/strolch/model/query/StrolchElementSelection.java b/src/main/java/li/strolch/model/query/StrolchElementSelection.java new file mode 100644 index 000000000..d9df67b00 --- /dev/null +++ b/src/main/java/li/strolch/model/query/StrolchElementSelection.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +/** + * @author Robert von Burg + */ +public abstract class StrolchElementSelection implements Selection { + + @Override + public void accept(QueryVisitor visitor) { + accept((StrolchElementSelectionVisitor) visitor); + } + + public abstract void accept(StrolchElementSelectionVisitor visitor); +} diff --git a/src/main/java/li/strolch/model/query/StrolchElementSelectionVisitor.java b/src/main/java/li/strolch/model/query/StrolchElementSelectionVisitor.java new file mode 100644 index 000000000..47e59e30b --- /dev/null +++ b/src/main/java/li/strolch/model/query/StrolchElementSelectionVisitor.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +/** + * @author Robert von Burg + */ +public interface StrolchElementSelectionVisitor extends QueryVisitor{ + + public void visit(StrolchTypeNavigation navigation); + + public void visit(IdSelection selection); + + public void visit(NameSelection selection); +} diff --git a/src/main/java/li/strolch/model/query/StrolchQuery.java b/src/main/java/li/strolch/model/query/StrolchQuery.java new file mode 100644 index 000000000..df2010e53 --- /dev/null +++ b/src/main/java/li/strolch/model/query/StrolchQuery.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Robert von Burg + * + */ +public abstract class StrolchQuery { + + private Navigation navigation; + protected List selections; + + public StrolchQuery(Navigation navigation) { + this.navigation = navigation; + this.selections = new ArrayList<>(); + } + + public void addSelection(BooleanSelection selection) { + this.selections.add(selection); + } + + public void addSelection(StrolchElementSelection selection) { + this.selections.add(selection); + } + + public void addSelection(ParameterSelection selection) { + this.selections.add(selection); + } + + public void accept(T visitor) { + this.navigation.accept(visitor); + for (Selection selection : this.selections) { + selection.accept(visitor); + } + } +} diff --git a/src/main/java/li/strolch/model/query/StrolchTypeNavigation.java b/src/main/java/li/strolch/model/query/StrolchTypeNavigation.java new file mode 100644 index 000000000..ae8cb204a --- /dev/null +++ b/src/main/java/li/strolch/model/query/StrolchTypeNavigation.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +/** + * @author Robert von Burg + * + */ +public class StrolchTypeNavigation implements Navigation { + + private String type; + + public StrolchTypeNavigation(String type) { + this.type = type; + } + + /** + * @return the type + */ + public String getType() { + return this.type; + } + + @Override + public void accept(QueryVisitor visitor) { + accept((StrolchElementSelectionVisitor) visitor); + } + + public void accept(StrolchElementSelectionVisitor visitor) { + visitor.visit(this); + } +} diff --git a/src/test/java/li/strolch/model/ModelTest.java b/src/test/java/li/strolch/model/ModelTest.java new file mode 100644 index 000000000..077d42895 --- /dev/null +++ b/src/test/java/li/strolch/model/ModelTest.java @@ -0,0 +1,88 @@ +package li.strolch.model; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import java.util.Date; + +import li.strolch.model.ModelGenerator; +import li.strolch.model.Order; +import li.strolch.model.ParameterBag; +import li.strolch.model.Resource; +import li.strolch.model.State; +import li.strolch.model.parameter.BooleanParameter; +import li.strolch.model.parameter.DateParameter; +import li.strolch.model.parameter.FloatParameter; +import li.strolch.model.parameter.IntegerParameter; +import li.strolch.model.parameter.LongParameter; +import li.strolch.model.parameter.StringListParameter; +import li.strolch.model.parameter.StringParameter; + +import org.junit.Test; + +@SuppressWarnings("nls") +public class ModelTest { + + @Test + public void shouldCreateResource() { + + Resource resource = ModelGenerator.createResource("@res01", "Test resource", "MyType"); + ParameterBag bag = resource.getParameterBag(ModelGenerator.BAG_ID); + validateBag(bag); + } + + @Test + public void shouldCreateOrder() { + + Order order = ModelGenerator.createOrder("@ord01", "Test Order", "MyType", new Date(), State.OPEN); + ParameterBag bag = order.getParameterBag(ModelGenerator.BAG_ID); + validateBag(bag); + } + + public static void validateBag(ParameterBag bag) { + + assertNotNull(bag); + + assertEquals(ModelGenerator.BAG_ID, bag.getId()); + assertEquals(ModelGenerator.BAG_NAME, bag.getName()); + assertEquals(ModelGenerator.BAG_TYPE, bag.getType()); + + validateParams(bag); + } + + public static void validateParams(ParameterBag bag) { + + BooleanParameter boolParam = bag.getParameter(ModelGenerator.PARAM_BOOLEAN_ID); + assertNotNull("Boolean Param missing with id " + ModelGenerator.PARAM_BOOLEAN_ID, boolParam); + assertEquals(true, boolParam.getValue().booleanValue()); + + FloatParameter floatParam = bag.getParameter(ModelGenerator.PARAM_FLOAT_ID); + assertNotNull("Float Param missing with id " + ModelGenerator.PARAM_FLOAT_ID, floatParam); + assertEquals(44.3, floatParam.getValue().doubleValue(), 0.0001); + + IntegerParameter integerParam = bag.getParameter(ModelGenerator.PARAM_INTEGER_ID); + assertNotNull("Integer Param missing with id " + ModelGenerator.PARAM_INTEGER_ID, integerParam); + assertEquals(77, integerParam.getValue().intValue()); + + LongParameter longParam = bag.getParameter(ModelGenerator.PARAM_LONG_ID); + assertNotNull("Long Param missing with id " + ModelGenerator.PARAM_LONG_ID, longParam); + assertEquals(4453234566L, longParam.getValue().longValue()); + + StringParameter stringParam = bag.getParameter(ModelGenerator.PARAM_STRING_ID); + assertNotNull("String Param missing with id " + ModelGenerator.PARAM_STRING_ID, stringParam); + assertEquals("Strolch", stringParam.getValue()); + + DateParameter dateParam = bag.getParameter(ModelGenerator.PARAM_DATE_ID); + assertNotNull("Date Param missing with id " + ModelGenerator.PARAM_DATE_ID, dateParam); + assertEquals(1354295525628L, dateParam.getValue().getTime()); + + StringListParameter stringListP = bag.getParameter(ModelGenerator.PARAM_LIST_STRING_ID); + assertNotNull("StringList Param missing with id " + ModelGenerator.PARAM_LIST_STRING_ID, stringListP); + + ArrayList stringList = new ArrayList(); + stringList.add("Hello"); + stringList.add("World"); + assertEquals(stringList, stringListP.getValue()); + } +} diff --git a/src/test/java/li/strolch/model/test/XmlModelDefaultHandlerTest.java b/src/test/java/li/strolch/model/XmlModelDefaultHandlerTest.java similarity index 98% rename from src/test/java/li/strolch/model/test/XmlModelDefaultHandlerTest.java rename to src/test/java/li/strolch/model/XmlModelDefaultHandlerTest.java index cbd26a62e..8183b0dfc 100644 --- a/src/test/java/li/strolch/model/test/XmlModelDefaultHandlerTest.java +++ b/src/test/java/li/strolch/model/XmlModelDefaultHandlerTest.java @@ -19,7 +19,7 @@ * along with XXX. If not, see * . */ -package li.strolch.model.test; +package li.strolch.model; import static org.junit.Assert.assertEquals; diff --git a/src/test/java/li/strolch/model/test/ModelTest.java b/src/test/java/li/strolch/model/test/ModelTest.java deleted file mode 100644 index f5de4dee3..000000000 --- a/src/test/java/li/strolch/model/test/ModelTest.java +++ /dev/null @@ -1,87 +0,0 @@ -package li.strolch.model.test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.util.ArrayList; -import java.util.Date; - -import li.strolch.model.Order; -import li.strolch.model.ParameterBag; -import li.strolch.model.Resource; -import li.strolch.model.State; -import li.strolch.model.parameter.BooleanParameter; -import li.strolch.model.parameter.DateParameter; -import li.strolch.model.parameter.FloatParameter; -import li.strolch.model.parameter.IntegerParameter; -import li.strolch.model.parameter.LongParameter; -import li.strolch.model.parameter.StringListParameter; -import li.strolch.model.parameter.StringParameter; - -import org.junit.Test; - -@SuppressWarnings("nls") -public class ModelTest { - - @Test - public void shouldCreateResource() { - - Resource resource = ModelTestHelper.createResource("@res01", "Test resource", "MyType"); - ParameterBag bag = resource.getParameterBag(ModelTestHelper.BAG_ID); - validateBag(bag); - } - - @Test - public void shouldCreateOrder() { - - Order order = ModelTestHelper.createOrder("@ord01", "Test Order", "MyType", new Date(), State.OPEN); - ParameterBag bag = order.getParameterBag(ModelTestHelper.BAG_ID); - validateBag(bag); - } - - public static void validateBag(ParameterBag bag) { - - assertNotNull(bag); - - assertEquals(ModelTestHelper.BAG_ID, bag.getId()); - assertEquals(ModelTestHelper.BAG_NAME, bag.getName()); - assertEquals(ModelTestHelper.BAG_TYPE, bag.getType()); - - validateParams(bag); - } - - public static void validateParams(ParameterBag bag) { - - BooleanParameter boolParam = bag.getParameter(ModelTestHelper.PARAM_BOOLEAN_ID); - assertNotNull("Boolean Param missing with id " + ModelTestHelper.PARAM_BOOLEAN_ID, boolParam); - assertEquals(true, boolParam.getValue().booleanValue()); - - FloatParameter floatParam = bag.getParameter(ModelTestHelper.PARAM_FLOAT_ID); - assertNotNull("Float Param missing with id " + ModelTestHelper.PARAM_FLOAT_ID, floatParam); - assertEquals(44.3, floatParam.getValue().doubleValue(), 0.0001); - - IntegerParameter integerParam = bag.getParameter(ModelTestHelper.PARAM_INTEGER_ID); - assertNotNull("Integer Param missing with id " + ModelTestHelper.PARAM_INTEGER_ID, integerParam); - assertEquals(77, integerParam.getValue().intValue()); - - LongParameter longParam = bag.getParameter(ModelTestHelper.PARAM_LONG_ID); - assertNotNull("Long Param missing with id " + ModelTestHelper.PARAM_LONG_ID, longParam); - assertEquals(4453234566L, longParam.getValue().longValue()); - - StringParameter stringParam = bag.getParameter(ModelTestHelper.PARAM_STRING_ID); - assertNotNull("String Param missing with id " + ModelTestHelper.PARAM_STRING_ID, stringParam); - assertEquals("Strolch", stringParam.getValue()); - - DateParameter dateParam = bag.getParameter(ModelTestHelper.PARAM_DATE_ID); - assertNotNull("Date Param missing with id " + ModelTestHelper.PARAM_DATE_ID, dateParam); - assertEquals(1354295525628L, dateParam.getValue().getTime()); - - StringListParameter stringListP = bag.getParameter(ModelTestHelper.PARAM_LIST_STRING_ID); - assertNotNull("StringList Param missing with id " + ModelTestHelper.PARAM_LIST_STRING_ID, stringListP); - - ArrayList stringList = new ArrayList(); - stringList.add("Hello"); - stringList.add("World"); - assertEquals(stringList, stringListP.getValue()); - } -} diff --git a/src/test/java/li/strolch/model/test/timedstate/TimeStateTest.java b/src/test/java/li/strolch/model/timedstate/TimeStateTest.java similarity index 98% rename from src/test/java/li/strolch/model/test/timedstate/TimeStateTest.java rename to src/test/java/li/strolch/model/timedstate/TimeStateTest.java index e2182fba8..d4757d81b 100644 --- a/src/test/java/li/strolch/model/test/timedstate/TimeStateTest.java +++ b/src/test/java/li/strolch/model/timedstate/TimeStateTest.java @@ -1,4 +1,4 @@ -package li.strolch.model.test.timedstate; +package li.strolch.model.timedstate; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/src/test/java/li/strolch/model/test/timevalue/FloatTimeVariableTest.java b/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java similarity index 99% rename from src/test/java/li/strolch/model/test/timevalue/FloatTimeVariableTest.java rename to src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java index fd09d465a..45aabeabd 100644 --- a/src/test/java/li/strolch/model/test/timevalue/FloatTimeVariableTest.java +++ b/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java @@ -1,4 +1,4 @@ -package li.strolch.model.test.timevalue; +package li.strolch.model.timevalue; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/src/test/java/li/strolch/model/test/timevalue/IntegerTimeVariableTest.java b/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java similarity index 98% rename from src/test/java/li/strolch/model/test/timevalue/IntegerTimeVariableTest.java rename to src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java index d11460032..062530711 100644 --- a/src/test/java/li/strolch/model/test/timevalue/IntegerTimeVariableTest.java +++ b/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java @@ -1,4 +1,4 @@ -package li.strolch.model.test.timevalue; +package li.strolch.model.timevalue; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; diff --git a/src/test/java/li/strolch/model/test/timevalue/StringTimeVariableTest.java b/src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java similarity index 98% rename from src/test/java/li/strolch/model/test/timevalue/StringTimeVariableTest.java rename to src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java index 18f801549..d8e54d96a 100644 --- a/src/test/java/li/strolch/model/test/timevalue/StringTimeVariableTest.java +++ b/src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java @@ -1,4 +1,4 @@ -package li.strolch.model.test.timevalue; +package li.strolch.model.timevalue; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/src/test/java/li/strolch/model/test/timevalue/ValueTests.java b/src/test/java/li/strolch/model/timevalue/ValueTests.java similarity index 98% rename from src/test/java/li/strolch/model/test/timevalue/ValueTests.java rename to src/test/java/li/strolch/model/timevalue/ValueTests.java index a6489fac8..af901fbea 100644 --- a/src/test/java/li/strolch/model/test/timevalue/ValueTests.java +++ b/src/test/java/li/strolch/model/timevalue/ValueTests.java @@ -1,4 +1,4 @@ -package li.strolch.model.test.timevalue; +package li.strolch.model.timevalue; import static org.junit.Assert.assertEquals; From e8cdbb59fe70ef9dff785f232ef0b56f9de3d5db Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sun, 15 Dec 2013 13:10:01 +0100 Subject: [PATCH 30/88] [Project] Changed all licence references to Apache License 2.0 --- COPYING | 674 ------------------ COPYING.LESSER | 165 ----- LICENSE | 202 ++++++ .../strolch/exception/StrolchException.java | 32 +- .../strolch/model/AbstractStrolchElement.java | 32 +- .../model/GroupedParameterizedElement.java | 32 +- src/main/java/li/strolch/model/Locator.java | 32 +- .../java/li/strolch/model/ModelGenerator.java | 32 +- src/main/java/li/strolch/model/Order.java | 32 +- .../java/li/strolch/model/ParameterBag.java | 32 +- .../strolch/model/ParameterizedElement.java | 32 +- src/main/java/li/strolch/model/Resource.java | 32 +- src/main/java/li/strolch/model/State.java | 32 +- .../java/li/strolch/model/StrolchElement.java | 32 +- src/main/java/li/strolch/model/Tags.java | 15 + .../model/parameter/AbstractParameter.java | 32 +- .../model/parameter/BooleanParameter.java | 32 +- .../model/parameter/DateParameter.java | 32 +- .../model/parameter/FloatParameter.java | 32 +- .../model/parameter/IntegerParameter.java | 32 +- .../model/parameter/ListParameter.java | 32 +- .../model/parameter/LongParameter.java | 32 +- .../li/strolch/model/parameter/Parameter.java | 32 +- .../model/parameter/StringListParameter.java | 32 +- .../model/parameter/StringParameter.java | 32 +- .../li/strolch/model/query/AndSelection.java | 32 +- .../strolch/model/query/BooleanSelection.java | 32 +- .../li/strolch/model/query/DateSelection.java | 32 +- .../li/strolch/model/query/IdSelection.java | 32 +- .../li/strolch/model/query/NameSelection.java | 32 +- .../li/strolch/model/query/Navigation.java | 32 +- .../li/strolch/model/query/OrSelection.java | 32 +- .../li/strolch/model/query/OrderQuery.java | 32 +- .../model/query/OrderQueryVisitor.java | 32 +- .../strolch/model/query/OrderSelection.java | 32 +- .../model/query/OrderSelectionVisitor.java | 32 +- .../model/query/ParameterSelection.java | 32 +- .../query/ParameterSelectionVisitor.java | 32 +- .../java/li/strolch/model/query/Query.java | 32 +- .../li/strolch/model/query/QueryVisitor.java | 32 +- .../li/strolch/model/query/ResourceQuery.java | 32 +- .../model/query/ResourceQueryVisitor.java | 32 +- .../li/strolch/model/query/Selection.java | 32 +- .../strolch/model/query/StateSelection.java | 32 +- .../model/query/StrolchElementSelection.java | 32 +- .../query/StrolchElementSelectionVisitor.java | 32 +- .../li/strolch/model/query/StrolchQuery.java | 32 +- .../model/query/StrolchTypeNavigation.java | 32 +- .../strolch/model/timedstate/ITimedState.java | 15 + .../strolch/model/timedstate/TimedState.java | 15 + .../strolch/model/timevalue/ITimeValue.java | 15 + .../model/timevalue/ITimeVariable.java | 15 + .../li/strolch/model/timevalue/IValue.java | 15 + .../strolch/model/timevalue/IValueChange.java | 15 + .../strolch/model/timevalue/impl/AString.java | 15 + .../model/timevalue/impl/DoubleValue.java | 15 + .../model/timevalue/impl/IntegerValue.java | 15 + .../model/timevalue/impl/StringSetValue.java | 15 + .../model/timevalue/impl/TimeValue.java | 15 + .../model/timevalue/impl/TimeVariable.java | 15 + .../model/timevalue/impl/ValueChange.java | 15 + .../model/xml/StrolchElementListener.java | 32 +- .../model/xml/XmlModelDefaultHandler.java | 32 +- src/test/java/li/strolch/model/ModelTest.java | 15 + .../model/XmlModelDefaultHandlerTest.java | 32 +- .../model/timedstate/TimeStateTest.java | 15 + .../timevalue/FloatTimeVariableTest.java | 15 + .../timevalue/IntegerTimeVariableTest.java | 15 + .../timevalue/StringTimeVariableTest.java | 15 + .../strolch/model/timevalue/ValueTests.java | 15 + 70 files changed, 1113 insertions(+), 1732 deletions(-) delete mode 100644 COPYING delete mode 100644 COPYING.LESSER create mode 100644 LICENSE diff --git a/COPYING b/COPYING deleted file mode 100644 index 94a9ed024..000000000 --- a/COPYING +++ /dev/null @@ -1,674 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. diff --git a/COPYING.LESSER b/COPYING.LESSER deleted file mode 100644 index 65c5ca88a..000000000 --- a/COPYING.LESSER +++ /dev/null @@ -1,165 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..d64569567 --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. diff --git a/src/main/java/li/strolch/exception/StrolchException.java b/src/main/java/li/strolch/exception/StrolchException.java index 7201dbc3a..cb5114bf7 100644 --- a/src/main/java/li/strolch/exception/StrolchException.java +++ b/src/main/java/li/strolch/exception/StrolchException.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of li.strolch.model. - * - * li.strolch.model is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * li.strolch.model 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with li.strolch.model. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.exception; diff --git a/src/main/java/li/strolch/model/AbstractStrolchElement.java b/src/main/java/li/strolch/model/AbstractStrolchElement.java index 0b5acb25c..0718f538d 100644 --- a/src/main/java/li/strolch/model/AbstractStrolchElement.java +++ b/src/main/java/li/strolch/model/AbstractStrolchElement.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of li.strolch.model. - * - * li.strolch.model is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * li.strolch.model 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with li.strolch.model. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model; diff --git a/src/main/java/li/strolch/model/GroupedParameterizedElement.java b/src/main/java/li/strolch/model/GroupedParameterizedElement.java index 3510e4851..647092943 100644 --- a/src/main/java/li/strolch/model/GroupedParameterizedElement.java +++ b/src/main/java/li/strolch/model/GroupedParameterizedElement.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of li.strolch.model. - * - * li.strolch.model is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * li.strolch.model 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with li.strolch.model. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model; diff --git a/src/main/java/li/strolch/model/Locator.java b/src/main/java/li/strolch/model/Locator.java index 3512dac63..43ee86a12 100644 --- a/src/main/java/li/strolch/model/Locator.java +++ b/src/main/java/li/strolch/model/Locator.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of li.strolch.model. - * - * li.strolch.model is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * li.strolch.model 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with li.strolch.model. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model; diff --git a/src/main/java/li/strolch/model/ModelGenerator.java b/src/main/java/li/strolch/model/ModelGenerator.java index 18c9ca1d7..8a18aaa34 100644 --- a/src/main/java/li/strolch/model/ModelGenerator.java +++ b/src/main/java/li/strolch/model/ModelGenerator.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the li.strolch.model. - * - * li.strolch.model is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * li.strolch.model 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with li.strolch.model. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model; diff --git a/src/main/java/li/strolch/model/Order.java b/src/main/java/li/strolch/model/Order.java index 3aae680c9..442b13132 100644 --- a/src/main/java/li/strolch/model/Order.java +++ b/src/main/java/li/strolch/model/Order.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of li.strolch.model. - * - * li.strolch.model is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * li.strolch.model 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with li.strolch.model. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model; diff --git a/src/main/java/li/strolch/model/ParameterBag.java b/src/main/java/li/strolch/model/ParameterBag.java index 8dac2f25b..6c2f53867 100644 --- a/src/main/java/li/strolch/model/ParameterBag.java +++ b/src/main/java/li/strolch/model/ParameterBag.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the li.strolch.model. - * - * li.strolch.model is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * li.strolch.model 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with li.strolch.model. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model; diff --git a/src/main/java/li/strolch/model/ParameterizedElement.java b/src/main/java/li/strolch/model/ParameterizedElement.java index dc4815236..1291d7523 100644 --- a/src/main/java/li/strolch/model/ParameterizedElement.java +++ b/src/main/java/li/strolch/model/ParameterizedElement.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of li.strolch.model. - * - * li.strolch.model is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * li.strolch.model 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with li.strolch.model. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model; diff --git a/src/main/java/li/strolch/model/Resource.java b/src/main/java/li/strolch/model/Resource.java index 8cb6b7dbf..3f7f909ef 100644 --- a/src/main/java/li/strolch/model/Resource.java +++ b/src/main/java/li/strolch/model/Resource.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of li.strolch.model. - * - * li.strolch.model is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * li.strolch.model 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with li.strolch.model. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model; diff --git a/src/main/java/li/strolch/model/State.java b/src/main/java/li/strolch/model/State.java index 8968b9786..9bf386425 100644 --- a/src/main/java/li/strolch/model/State.java +++ b/src/main/java/li/strolch/model/State.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of li.strolch.model. - * - * li.strolch.model is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * li.strolch.model 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with li.strolch.model. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model; diff --git a/src/main/java/li/strolch/model/StrolchElement.java b/src/main/java/li/strolch/model/StrolchElement.java index e9cfd3ca0..261e7b4bd 100644 --- a/src/main/java/li/strolch/model/StrolchElement.java +++ b/src/main/java/li/strolch/model/StrolchElement.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of li.strolch.model. - * - * li.strolch.model is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * li.strolch.model 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with li.strolch.model. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model; diff --git a/src/main/java/li/strolch/model/Tags.java b/src/main/java/li/strolch/model/Tags.java index 1b7904e5f..212d04f5e 100644 --- a/src/main/java/li/strolch/model/Tags.java +++ b/src/main/java/li/strolch/model/Tags.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model; @SuppressWarnings("nls") diff --git a/src/main/java/li/strolch/model/parameter/AbstractParameter.java b/src/main/java/li/strolch/model/parameter/AbstractParameter.java index e55e75cce..cdb6c558c 100644 --- a/src/main/java/li/strolch/model/parameter/AbstractParameter.java +++ b/src/main/java/li/strolch/model/parameter/AbstractParameter.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of li.strolch.model. - * - * li.strolch.model is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * li.strolch.model 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with li.strolch.model. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.parameter; diff --git a/src/main/java/li/strolch/model/parameter/BooleanParameter.java b/src/main/java/li/strolch/model/parameter/BooleanParameter.java index 206fd6d47..646a858ec 100644 --- a/src/main/java/li/strolch/model/parameter/BooleanParameter.java +++ b/src/main/java/li/strolch/model/parameter/BooleanParameter.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of li.strolch.model. - * - * li.strolch.model is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * li.strolch.model 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with li.strolch.model. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.parameter; diff --git a/src/main/java/li/strolch/model/parameter/DateParameter.java b/src/main/java/li/strolch/model/parameter/DateParameter.java index 1e8f0b7e8..cf406d08b 100644 --- a/src/main/java/li/strolch/model/parameter/DateParameter.java +++ b/src/main/java/li/strolch/model/parameter/DateParameter.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of li.strolch.model. - * - * li.strolch.model is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * li.strolch.model 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with li.strolch.model. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.parameter; diff --git a/src/main/java/li/strolch/model/parameter/FloatParameter.java b/src/main/java/li/strolch/model/parameter/FloatParameter.java index fce922d55..09b5c6194 100644 --- a/src/main/java/li/strolch/model/parameter/FloatParameter.java +++ b/src/main/java/li/strolch/model/parameter/FloatParameter.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of li.strolch.model. - * - * li.strolch.model is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * li.strolch.model 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with li.strolch.model. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.parameter; diff --git a/src/main/java/li/strolch/model/parameter/IntegerParameter.java b/src/main/java/li/strolch/model/parameter/IntegerParameter.java index 4a6c8e825..de41a480b 100644 --- a/src/main/java/li/strolch/model/parameter/IntegerParameter.java +++ b/src/main/java/li/strolch/model/parameter/IntegerParameter.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of li.strolch.model. - * - * li.strolch.model is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * li.strolch.model 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with li.strolch.model. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.parameter; diff --git a/src/main/java/li/strolch/model/parameter/ListParameter.java b/src/main/java/li/strolch/model/parameter/ListParameter.java index f754c7fb8..d7d46a6c1 100644 --- a/src/main/java/li/strolch/model/parameter/ListParameter.java +++ b/src/main/java/li/strolch/model/parameter/ListParameter.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the li.strolch.model. - * - * li.strolch.model is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * li.strolch.model 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with li.strolch.model. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.parameter; diff --git a/src/main/java/li/strolch/model/parameter/LongParameter.java b/src/main/java/li/strolch/model/parameter/LongParameter.java index 9f6f8d228..f7a33c3ca 100644 --- a/src/main/java/li/strolch/model/parameter/LongParameter.java +++ b/src/main/java/li/strolch/model/parameter/LongParameter.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of li.strolch.model. - * - * li.strolch.model is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * li.strolch.model 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with li.strolch.model. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.parameter; diff --git a/src/main/java/li/strolch/model/parameter/Parameter.java b/src/main/java/li/strolch/model/parameter/Parameter.java index 54598caa8..93f66d8c4 100644 --- a/src/main/java/li/strolch/model/parameter/Parameter.java +++ b/src/main/java/li/strolch/model/parameter/Parameter.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of li.strolch.model. - * - * li.strolch.model is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * li.strolch.model 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with li.strolch.model. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.parameter; diff --git a/src/main/java/li/strolch/model/parameter/StringListParameter.java b/src/main/java/li/strolch/model/parameter/StringListParameter.java index 3bf996a51..08682f255 100644 --- a/src/main/java/li/strolch/model/parameter/StringListParameter.java +++ b/src/main/java/li/strolch/model/parameter/StringListParameter.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the li.strolch.model. - * - * li.strolch.model is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * li.strolch.model 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with li.strolch.model. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.parameter; diff --git a/src/main/java/li/strolch/model/parameter/StringParameter.java b/src/main/java/li/strolch/model/parameter/StringParameter.java index 1ace001a1..27882880d 100644 --- a/src/main/java/li/strolch/model/parameter/StringParameter.java +++ b/src/main/java/li/strolch/model/parameter/StringParameter.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of li.strolch.model. - * - * li.strolch.model is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * li.strolch.model 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with li.strolch.model. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.parameter; diff --git a/src/main/java/li/strolch/model/query/AndSelection.java b/src/main/java/li/strolch/model/query/AndSelection.java index 754e7c7ae..b0f643169 100644 --- a/src/main/java/li/strolch/model/query/AndSelection.java +++ b/src/main/java/li/strolch/model/query/AndSelection.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the XXX. - * - * XXX is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * XXX 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XXX. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.query; diff --git a/src/main/java/li/strolch/model/query/BooleanSelection.java b/src/main/java/li/strolch/model/query/BooleanSelection.java index 8ecd98d23..54881e8f9 100644 --- a/src/main/java/li/strolch/model/query/BooleanSelection.java +++ b/src/main/java/li/strolch/model/query/BooleanSelection.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the XXX. - * - * XXX is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * XXX 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XXX. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.query; diff --git a/src/main/java/li/strolch/model/query/DateSelection.java b/src/main/java/li/strolch/model/query/DateSelection.java index 5e21e6e40..e6e6142a7 100644 --- a/src/main/java/li/strolch/model/query/DateSelection.java +++ b/src/main/java/li/strolch/model/query/DateSelection.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the XXX. - * - * XXX is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * XXX 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XXX. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.query; diff --git a/src/main/java/li/strolch/model/query/IdSelection.java b/src/main/java/li/strolch/model/query/IdSelection.java index c4aeb5cce..9be311b08 100644 --- a/src/main/java/li/strolch/model/query/IdSelection.java +++ b/src/main/java/li/strolch/model/query/IdSelection.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the XXX. - * - * XXX is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * XXX 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XXX. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.query; diff --git a/src/main/java/li/strolch/model/query/NameSelection.java b/src/main/java/li/strolch/model/query/NameSelection.java index acb5e244c..eb9d0cf66 100644 --- a/src/main/java/li/strolch/model/query/NameSelection.java +++ b/src/main/java/li/strolch/model/query/NameSelection.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the XXX. - * - * XXX is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * XXX 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XXX. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.query; diff --git a/src/main/java/li/strolch/model/query/Navigation.java b/src/main/java/li/strolch/model/query/Navigation.java index 3e7bbf65d..9ff8d23f2 100644 --- a/src/main/java/li/strolch/model/query/Navigation.java +++ b/src/main/java/li/strolch/model/query/Navigation.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the XXX. - * - * XXX is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * XXX 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XXX. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.query; diff --git a/src/main/java/li/strolch/model/query/OrSelection.java b/src/main/java/li/strolch/model/query/OrSelection.java index 67c5b59cf..7a01dd725 100644 --- a/src/main/java/li/strolch/model/query/OrSelection.java +++ b/src/main/java/li/strolch/model/query/OrSelection.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the XXX. - * - * XXX is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * XXX 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XXX. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.query; diff --git a/src/main/java/li/strolch/model/query/OrderQuery.java b/src/main/java/li/strolch/model/query/OrderQuery.java index 764439a98..23a598a7d 100644 --- a/src/main/java/li/strolch/model/query/OrderQuery.java +++ b/src/main/java/li/strolch/model/query/OrderQuery.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the XXX. - * - * XXX is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * XXX 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XXX. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.query; diff --git a/src/main/java/li/strolch/model/query/OrderQueryVisitor.java b/src/main/java/li/strolch/model/query/OrderQueryVisitor.java index c637b4fc0..5923efce8 100644 --- a/src/main/java/li/strolch/model/query/OrderQueryVisitor.java +++ b/src/main/java/li/strolch/model/query/OrderQueryVisitor.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the XXX. - * - * XXX is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * XXX 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XXX. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.query; diff --git a/src/main/java/li/strolch/model/query/OrderSelection.java b/src/main/java/li/strolch/model/query/OrderSelection.java index 0289afe75..9549ed8a3 100644 --- a/src/main/java/li/strolch/model/query/OrderSelection.java +++ b/src/main/java/li/strolch/model/query/OrderSelection.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the XXX. - * - * XXX is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * XXX 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XXX. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.query; diff --git a/src/main/java/li/strolch/model/query/OrderSelectionVisitor.java b/src/main/java/li/strolch/model/query/OrderSelectionVisitor.java index 642cbd0e6..708bbce7a 100644 --- a/src/main/java/li/strolch/model/query/OrderSelectionVisitor.java +++ b/src/main/java/li/strolch/model/query/OrderSelectionVisitor.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the XXX. - * - * XXX is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * XXX 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XXX. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.query; diff --git a/src/main/java/li/strolch/model/query/ParameterSelection.java b/src/main/java/li/strolch/model/query/ParameterSelection.java index 5f5ae57d5..5f1b53321 100644 --- a/src/main/java/li/strolch/model/query/ParameterSelection.java +++ b/src/main/java/li/strolch/model/query/ParameterSelection.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the XXX. - * - * XXX is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * XXX 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XXX. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.query; diff --git a/src/main/java/li/strolch/model/query/ParameterSelectionVisitor.java b/src/main/java/li/strolch/model/query/ParameterSelectionVisitor.java index 784a10c7d..065e862be 100644 --- a/src/main/java/li/strolch/model/query/ParameterSelectionVisitor.java +++ b/src/main/java/li/strolch/model/query/ParameterSelectionVisitor.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the XXX. - * - * XXX is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * XXX 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XXX. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.query; diff --git a/src/main/java/li/strolch/model/query/Query.java b/src/main/java/li/strolch/model/query/Query.java index 88bfe65d7..83dc7ef58 100644 --- a/src/main/java/li/strolch/model/query/Query.java +++ b/src/main/java/li/strolch/model/query/Query.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the XXX. - * - * XXX is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * XXX 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XXX. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.query; diff --git a/src/main/java/li/strolch/model/query/QueryVisitor.java b/src/main/java/li/strolch/model/query/QueryVisitor.java index d2147c9c0..d6efcec67 100644 --- a/src/main/java/li/strolch/model/query/QueryVisitor.java +++ b/src/main/java/li/strolch/model/query/QueryVisitor.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the XXX. - * - * XXX is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * XXX 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XXX. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.query; diff --git a/src/main/java/li/strolch/model/query/ResourceQuery.java b/src/main/java/li/strolch/model/query/ResourceQuery.java index 5ef97c77b..fbde73be5 100644 --- a/src/main/java/li/strolch/model/query/ResourceQuery.java +++ b/src/main/java/li/strolch/model/query/ResourceQuery.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the XXX. - * - * XXX is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * XXX 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XXX. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.query; diff --git a/src/main/java/li/strolch/model/query/ResourceQueryVisitor.java b/src/main/java/li/strolch/model/query/ResourceQueryVisitor.java index df4008278..8710a65f0 100644 --- a/src/main/java/li/strolch/model/query/ResourceQueryVisitor.java +++ b/src/main/java/li/strolch/model/query/ResourceQueryVisitor.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the XXX. - * - * XXX is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * XXX 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XXX. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.query; diff --git a/src/main/java/li/strolch/model/query/Selection.java b/src/main/java/li/strolch/model/query/Selection.java index e7186abb2..3b658fe44 100644 --- a/src/main/java/li/strolch/model/query/Selection.java +++ b/src/main/java/li/strolch/model/query/Selection.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the XXX. - * - * XXX is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * XXX 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XXX. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.query; diff --git a/src/main/java/li/strolch/model/query/StateSelection.java b/src/main/java/li/strolch/model/query/StateSelection.java index 636968a0e..393838f6c 100644 --- a/src/main/java/li/strolch/model/query/StateSelection.java +++ b/src/main/java/li/strolch/model/query/StateSelection.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the XXX. - * - * XXX is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * XXX 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XXX. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.query; diff --git a/src/main/java/li/strolch/model/query/StrolchElementSelection.java b/src/main/java/li/strolch/model/query/StrolchElementSelection.java index d9df67b00..bd4a5907b 100644 --- a/src/main/java/li/strolch/model/query/StrolchElementSelection.java +++ b/src/main/java/li/strolch/model/query/StrolchElementSelection.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the XXX. - * - * XXX is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * XXX 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XXX. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.query; diff --git a/src/main/java/li/strolch/model/query/StrolchElementSelectionVisitor.java b/src/main/java/li/strolch/model/query/StrolchElementSelectionVisitor.java index 47e59e30b..4756beb3e 100644 --- a/src/main/java/li/strolch/model/query/StrolchElementSelectionVisitor.java +++ b/src/main/java/li/strolch/model/query/StrolchElementSelectionVisitor.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the XXX. - * - * XXX is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * XXX 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XXX. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.query; diff --git a/src/main/java/li/strolch/model/query/StrolchQuery.java b/src/main/java/li/strolch/model/query/StrolchQuery.java index df2010e53..9c3e9515f 100644 --- a/src/main/java/li/strolch/model/query/StrolchQuery.java +++ b/src/main/java/li/strolch/model/query/StrolchQuery.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the XXX. - * - * XXX is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * XXX 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XXX. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.query; diff --git a/src/main/java/li/strolch/model/query/StrolchTypeNavigation.java b/src/main/java/li/strolch/model/query/StrolchTypeNavigation.java index ae8cb204a..82cc8760d 100644 --- a/src/main/java/li/strolch/model/query/StrolchTypeNavigation.java +++ b/src/main/java/li/strolch/model/query/StrolchTypeNavigation.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the XXX. - * - * XXX is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * XXX 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XXX. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.query; diff --git a/src/main/java/li/strolch/model/timedstate/ITimedState.java b/src/main/java/li/strolch/model/timedstate/ITimedState.java index c8bb64538..27bfbb2ce 100644 --- a/src/main/java/li/strolch/model/timedstate/ITimedState.java +++ b/src/main/java/li/strolch/model/timedstate/ITimedState.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Martin Smock + * + * 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 li.strolch.model.timedstate; import li.strolch.model.timevalue.ITimeValue; diff --git a/src/main/java/li/strolch/model/timedstate/TimedState.java b/src/main/java/li/strolch/model/timedstate/TimedState.java index 5dd75808e..b4a6bb0f3 100644 --- a/src/main/java/li/strolch/model/timedstate/TimedState.java +++ b/src/main/java/li/strolch/model/timedstate/TimedState.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Martin Smock + * + * 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 li.strolch.model.timedstate; import java.io.Serializable; diff --git a/src/main/java/li/strolch/model/timevalue/ITimeValue.java b/src/main/java/li/strolch/model/timevalue/ITimeValue.java index f6dd1187b..fdc0090fa 100644 --- a/src/main/java/li/strolch/model/timevalue/ITimeValue.java +++ b/src/main/java/li/strolch/model/timevalue/ITimeValue.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Martin Smock + * + * 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 li.strolch.model.timevalue; import li.strolch.model.timevalue.impl.TimeVariable; diff --git a/src/main/java/li/strolch/model/timevalue/ITimeVariable.java b/src/main/java/li/strolch/model/timevalue/ITimeVariable.java index f1bc79261..d453e8f55 100644 --- a/src/main/java/li/strolch/model/timevalue/ITimeVariable.java +++ b/src/main/java/li/strolch/model/timevalue/ITimeVariable.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Martin Smock + * + * 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 li.strolch.model.timevalue; import java.util.Collection; diff --git a/src/main/java/li/strolch/model/timevalue/IValue.java b/src/main/java/li/strolch/model/timevalue/IValue.java index 2c1cd52f2..5d8d73f56 100644 --- a/src/main/java/li/strolch/model/timevalue/IValue.java +++ b/src/main/java/li/strolch/model/timevalue/IValue.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Martin Smock + * + * 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 li.strolch.model.timevalue; /** diff --git a/src/main/java/li/strolch/model/timevalue/IValueChange.java b/src/main/java/li/strolch/model/timevalue/IValueChange.java index c6283be06..c4e391cd3 100644 --- a/src/main/java/li/strolch/model/timevalue/IValueChange.java +++ b/src/main/java/li/strolch/model/timevalue/IValueChange.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Martin Smock + * + * 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 li.strolch.model.timevalue; /** diff --git a/src/main/java/li/strolch/model/timevalue/impl/AString.java b/src/main/java/li/strolch/model/timevalue/impl/AString.java index ff6d1694c..e66567552 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/AString.java +++ b/src/main/java/li/strolch/model/timevalue/impl/AString.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Martin Smock + * + * 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 li.strolch.model.timevalue.impl; import java.io.Serializable; diff --git a/src/main/java/li/strolch/model/timevalue/impl/DoubleValue.java b/src/main/java/li/strolch/model/timevalue/impl/DoubleValue.java index e6e7b5593..0b61f657c 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/DoubleValue.java +++ b/src/main/java/li/strolch/model/timevalue/impl/DoubleValue.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Martin Smock + * + * 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 li.strolch.model.timevalue.impl; import java.io.Serializable; diff --git a/src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java b/src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java index b6c1842c4..50bb2abd2 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java +++ b/src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Martin Smock + * + * 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 li.strolch.model.timevalue.impl; import java.io.Serializable; diff --git a/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java b/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java index 37a9fc150..c99eacc26 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java +++ b/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Martin Smock + * + * 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 li.strolch.model.timevalue.impl; import java.io.Serializable; diff --git a/src/main/java/li/strolch/model/timevalue/impl/TimeValue.java b/src/main/java/li/strolch/model/timevalue/impl/TimeValue.java index cf83dbf1c..091b5031e 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/TimeValue.java +++ b/src/main/java/li/strolch/model/timevalue/impl/TimeValue.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Martin Smock + * + * 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 li.strolch.model.timevalue.impl; import java.io.Serializable; diff --git a/src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java b/src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java index 5640e06c4..1e963eb1f 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java +++ b/src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Martin Smock + * + * 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 li.strolch.model.timevalue.impl; import java.io.Serializable; diff --git a/src/main/java/li/strolch/model/timevalue/impl/ValueChange.java b/src/main/java/li/strolch/model/timevalue/impl/ValueChange.java index e2276b77f..bef5eab70 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/ValueChange.java +++ b/src/main/java/li/strolch/model/timevalue/impl/ValueChange.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Martin Smock + * + * 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 li.strolch.model.timevalue.impl; import java.io.Serializable; diff --git a/src/main/java/li/strolch/model/xml/StrolchElementListener.java b/src/main/java/li/strolch/model/xml/StrolchElementListener.java index 24adba720..719ffd64b 100644 --- a/src/main/java/li/strolch/model/xml/StrolchElementListener.java +++ b/src/main/java/li/strolch/model/xml/StrolchElementListener.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the XXX. - * - * XXX is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * XXX 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XXX. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.xml; diff --git a/src/main/java/li/strolch/model/xml/XmlModelDefaultHandler.java b/src/main/java/li/strolch/model/xml/XmlModelDefaultHandler.java index ad088ad0f..0195c476f 100644 --- a/src/main/java/li/strolch/model/xml/XmlModelDefaultHandler.java +++ b/src/main/java/li/strolch/model/xml/XmlModelDefaultHandler.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the XXX. - * - * XXX is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * XXX 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XXX. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.xml; diff --git a/src/test/java/li/strolch/model/ModelTest.java b/src/test/java/li/strolch/model/ModelTest.java index 077d42895..cd2d4bc98 100644 --- a/src/test/java/li/strolch/model/ModelTest.java +++ b/src/test/java/li/strolch/model/ModelTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model; import static org.junit.Assert.assertEquals; diff --git a/src/test/java/li/strolch/model/XmlModelDefaultHandlerTest.java b/src/test/java/li/strolch/model/XmlModelDefaultHandlerTest.java index 8183b0dfc..2326c7e1d 100644 --- a/src/test/java/li/strolch/model/XmlModelDefaultHandlerTest.java +++ b/src/test/java/li/strolch/model/XmlModelDefaultHandlerTest.java @@ -1,23 +1,17 @@ /* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the XXX. - * - * XXX is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * XXX 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XXX. If not, see - * . + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model; diff --git a/src/test/java/li/strolch/model/timedstate/TimeStateTest.java b/src/test/java/li/strolch/model/timedstate/TimeStateTest.java index d4757d81b..c21c9027f 100644 --- a/src/test/java/li/strolch/model/timedstate/TimeStateTest.java +++ b/src/test/java/li/strolch/model/timedstate/TimeStateTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Martin Smock + * + * 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 li.strolch.model.timedstate; import static org.junit.Assert.assertEquals; diff --git a/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java b/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java index 45aabeabd..8e16f85ac 100644 --- a/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java +++ b/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Martin Smock + * + * 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 li.strolch.model.timevalue; import static org.junit.Assert.assertEquals; diff --git a/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java b/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java index 062530711..5e2cad7cc 100644 --- a/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java +++ b/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Martin Smock + * + * 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 li.strolch.model.timevalue; import static org.junit.Assert.assertEquals; diff --git a/src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java b/src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java index d8e54d96a..e1b6ae38e 100644 --- a/src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java +++ b/src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Martin Smock + * + * 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 li.strolch.model.timevalue; import static org.junit.Assert.assertEquals; diff --git a/src/test/java/li/strolch/model/timevalue/ValueTests.java b/src/test/java/li/strolch/model/timevalue/ValueTests.java index af901fbea..bab00c1ff 100644 --- a/src/test/java/li/strolch/model/timevalue/ValueTests.java +++ b/src/test/java/li/strolch/model/timevalue/ValueTests.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Martin Smock + * + * 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 li.strolch.model.timevalue; import static org.junit.Assert.assertEquals; From 9b836dd45c705d8dc419f53cf25c884dac1ef075 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 23 Dec 2013 01:52:50 +0100 Subject: [PATCH 31/88] [New] Added visitor pattern for Resources and Orders --- pom.xml | 5 +- .../model/GroupedParameterizedElement.java | 1 - .../java/li/strolch/model/OrderVisitor.java | 25 +++ .../li/strolch/model/ResourceVisitor.java | 25 +++ .../strolch/model/StrolchElementVisitor.java | 24 +++ src/main/java/li/strolch/model/Tags.java | 21 +-- .../model/visitor/OrderDeepEqualsVisitor.java | 36 +++++ .../visitor/ResourceDeepEqualsVisitor.java | 36 +++++ .../StrolchElementDeepEqualsVisitor.java | 146 ++++++++++++++++++ .../strolch/model/xml/OrderToDomVisitor.java | 51 ++++++ .../strolch/model/xml/OrderToSaxVisitor.java | 50 ++++++ .../model/xml/ResourceToDomVisitor.java | 51 ++++++ .../model/xml/ResourceToSaxVisitor.java | 50 ++++++ .../xml/SimpleStrolchElementListener.java | 59 +++++++ .../model/xml/StrolchElementToDomVisitor.java | 90 +++++++++++ .../model/xml/XmlModelDefaultHandler.java | 78 ++-------- .../model/xml/XmlModelFileHandler.java | 104 +++++++++++++ src/test/java/li/strolch/model/ModelTest.java | 42 ++++- .../model/XmlModelDefaultHandlerTest.java | 6 +- .../java/li/strolch/model/XmlToDomTest.java | 65 ++++++++ 20 files changed, 879 insertions(+), 86 deletions(-) create mode 100644 src/main/java/li/strolch/model/OrderVisitor.java create mode 100644 src/main/java/li/strolch/model/ResourceVisitor.java create mode 100644 src/main/java/li/strolch/model/StrolchElementVisitor.java create mode 100644 src/main/java/li/strolch/model/visitor/OrderDeepEqualsVisitor.java create mode 100644 src/main/java/li/strolch/model/visitor/ResourceDeepEqualsVisitor.java create mode 100644 src/main/java/li/strolch/model/visitor/StrolchElementDeepEqualsVisitor.java create mode 100644 src/main/java/li/strolch/model/xml/OrderToDomVisitor.java create mode 100644 src/main/java/li/strolch/model/xml/OrderToSaxVisitor.java create mode 100644 src/main/java/li/strolch/model/xml/ResourceToDomVisitor.java create mode 100644 src/main/java/li/strolch/model/xml/ResourceToSaxVisitor.java create mode 100644 src/main/java/li/strolch/model/xml/SimpleStrolchElementListener.java create mode 100644 src/main/java/li/strolch/model/xml/StrolchElementToDomVisitor.java create mode 100644 src/main/java/li/strolch/model/xml/XmlModelFileHandler.java create mode 100644 src/test/java/li/strolch/model/XmlToDomTest.java diff --git a/pom.xml b/pom.xml index 5c2d28c89..eb1289eff 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,10 @@ - + + ch.eitchnet + ch.eitchnet.utils + diff --git a/src/main/java/li/strolch/model/GroupedParameterizedElement.java b/src/main/java/li/strolch/model/GroupedParameterizedElement.java index 647092943..d09b973ed 100644 --- a/src/main/java/li/strolch/model/GroupedParameterizedElement.java +++ b/src/main/java/li/strolch/model/GroupedParameterizedElement.java @@ -32,7 +32,6 @@ import ch.eitchnet.utils.helper.StringHelper; /** * @author Robert von Burg - * */ public abstract class GroupedParameterizedElement extends AbstractStrolchElement { diff --git a/src/main/java/li/strolch/model/OrderVisitor.java b/src/main/java/li/strolch/model/OrderVisitor.java new file mode 100644 index 000000000..c076175e3 --- /dev/null +++ b/src/main/java/li/strolch/model/OrderVisitor.java @@ -0,0 +1,25 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model; + +/** + * @author Robert von Burg + */ +public interface OrderVisitor extends StrolchElementVisitor { + + @Override + public void visit(Order element); +} diff --git a/src/main/java/li/strolch/model/ResourceVisitor.java b/src/main/java/li/strolch/model/ResourceVisitor.java new file mode 100644 index 000000000..db8c78ba2 --- /dev/null +++ b/src/main/java/li/strolch/model/ResourceVisitor.java @@ -0,0 +1,25 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model; + +/** + * @author Robert von Burg + */ +public interface ResourceVisitor extends StrolchElementVisitor{ + + @Override + public void visit(Resource element); +} diff --git a/src/main/java/li/strolch/model/StrolchElementVisitor.java b/src/main/java/li/strolch/model/StrolchElementVisitor.java new file mode 100644 index 000000000..605f3014f --- /dev/null +++ b/src/main/java/li/strolch/model/StrolchElementVisitor.java @@ -0,0 +1,24 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model; + +/** + * @author Robert von Burg + */ +public interface StrolchElementVisitor { + + public void visit(T element); +} diff --git a/src/main/java/li/strolch/model/Tags.java b/src/main/java/li/strolch/model/Tags.java index 212d04f5e..e2d7b86a9 100644 --- a/src/main/java/li/strolch/model/Tags.java +++ b/src/main/java/li/strolch/model/Tags.java @@ -18,17 +18,18 @@ package li.strolch.model; @SuppressWarnings("nls") public class Tags { - public static final String ID="Id"; - public static final String NAME="Name"; + public static final String CDATA = "CDATA"; + public static final String ID = "Id"; + public static final String NAME = "Name"; public static final String TYPE = "Type"; - public static final String DATE="Date"; - public static final String STATE="State"; - public static final String VALUE="Value"; - public static final String INTERPRETATION="Interpretation"; - public static final String UOM="Uom"; - public static final String HIDDEN="Hidden"; - public static final String PARAMETER="Parameter"; - public static final String PARAMETERIZED_ELEMENT="ParameterizedElement"; + public static final String DATE = "Date"; + public static final String STATE = "State"; + public static final String VALUE = "Value"; + public static final String INTERPRETATION = "Interpretation"; + public static final String UOM = "Uom"; + public static final String HIDDEN = "Hidden"; + public static final String PARAMETER = "Parameter"; + public static final String PARAMETERIZED_ELEMENT = "ParameterizedElement"; public static final String RESOURCE = "Resource"; public static final String ORDER = "Order"; public static final String PARAMETER_BAG = "ParameterBag"; diff --git a/src/main/java/li/strolch/model/visitor/OrderDeepEqualsVisitor.java b/src/main/java/li/strolch/model/visitor/OrderDeepEqualsVisitor.java new file mode 100644 index 000000000..497c46e29 --- /dev/null +++ b/src/main/java/li/strolch/model/visitor/OrderDeepEqualsVisitor.java @@ -0,0 +1,36 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.visitor; + +import li.strolch.model.Order; +import li.strolch.model.OrderVisitor; + +/** + * @author Robert von Burg + */ +public class OrderDeepEqualsVisitor extends StrolchElementDeepEqualsVisitor implements OrderVisitor { + + private Order srcOrder; + + public OrderDeepEqualsVisitor(Order srcOrder) { + this.srcOrder = srcOrder; + } + + @Override + public void visit(Order dstOrder) { + deepEquals(this.srcOrder, dstOrder); + } +} diff --git a/src/main/java/li/strolch/model/visitor/ResourceDeepEqualsVisitor.java b/src/main/java/li/strolch/model/visitor/ResourceDeepEqualsVisitor.java new file mode 100644 index 000000000..d74918a6f --- /dev/null +++ b/src/main/java/li/strolch/model/visitor/ResourceDeepEqualsVisitor.java @@ -0,0 +1,36 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.visitor; + +import li.strolch.model.Resource; +import li.strolch.model.ResourceVisitor; + +/** + * @author Robert von Burg + */ +public class ResourceDeepEqualsVisitor extends StrolchElementDeepEqualsVisitor implements ResourceVisitor { + + private Resource srcRes; + + public ResourceDeepEqualsVisitor(Resource sourceRes) { + this.srcRes = sourceRes; + } + + @Override + public void visit(Resource dstRes) { + deepEquals(this.srcRes, dstRes); + } +} diff --git a/src/main/java/li/strolch/model/visitor/StrolchElementDeepEqualsVisitor.java b/src/main/java/li/strolch/model/visitor/StrolchElementDeepEqualsVisitor.java new file mode 100644 index 000000000..0b927fdcb --- /dev/null +++ b/src/main/java/li/strolch/model/visitor/StrolchElementDeepEqualsVisitor.java @@ -0,0 +1,146 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.visitor; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import li.strolch.model.GroupedParameterizedElement; +import li.strolch.model.Locator; +import li.strolch.model.Order; +import li.strolch.model.ParameterBag; +import li.strolch.model.Resource; +import li.strolch.model.StrolchElement; +import li.strolch.model.parameter.Parameter; + +/** + * @author Robert von Burg + * + */ +public class StrolchElementDeepEqualsVisitor { + + private List mismatchedLocators; + + public StrolchElementDeepEqualsVisitor() { + this.mismatchedLocators = new ArrayList<>(); + } + + /** + * @return the mismatchedLocators + */ + public List getMismatchedLocators() { + return this.mismatchedLocators; + } + + public boolean isEqual() { + return this.mismatchedLocators.isEmpty(); + } + + protected void deepEquals(StrolchElement srcElement, StrolchElement dstElement) { + if (!srcElement.getName().equals(dstElement.getName())) + this.mismatchedLocators.add(dstElement.getLocator()); + if (!srcElement.getType().equals(dstElement.getType())) + this.mismatchedLocators.add(dstElement.getLocator()); + } + + protected void deepEquals(Order srcOrder, Order dstOrder) { + deepEquals((StrolchElement) srcOrder, (StrolchElement) dstOrder); + if (!srcOrder.getState().equals(dstOrder.getState())) + this.mismatchedLocators.add(dstOrder.getLocator()); + if (!srcOrder.getDate().equals(dstOrder.getDate())) + this.mismatchedLocators.add(dstOrder.getLocator()); + + deepEquals((GroupedParameterizedElement) srcOrder, (GroupedParameterizedElement) dstOrder); + } + + protected void deepEquals(Resource srcRes, Resource dstRes) { + deepEquals((StrolchElement) srcRes, (StrolchElement) dstRes); + deepEquals((GroupedParameterizedElement) srcRes, (GroupedParameterizedElement) dstRes); + } + + protected void deepEquals(GroupedParameterizedElement srcElement, GroupedParameterizedElement dstElement) { + Set srcBagKeySet = srcElement.getParameterBagKeySet(); + for (String bagKey : srcBagKeySet) { + ParameterBag srcBag = srcElement.getParameterBag(bagKey); + + if (!dstElement.hasParameterBag(bagKey)) { + this.mismatchedLocators.add(srcBag.getLocator()); + continue; + } + + ParameterBag dstBag = dstElement.getParameterBag(bagKey); + deepEquals(srcBag, dstBag); + } + + Set dstBagKeySet = dstElement.getParameterBagKeySet(); + for (String bagKey : dstBagKeySet) { + if (!srcElement.hasParameterBag(bagKey)) { + ParameterBag dstBag = dstElement.getParameterBag(bagKey); + this.mismatchedLocators.add(dstBag.getLocator()); + } + } + } + + protected void deepEquals(ParameterBag srcBag, ParameterBag dstBag) { + deepEquals((StrolchElement) srcBag, (StrolchElement) dstBag); + + Set srcParamKeySet = srcBag.getParameterKeySet(); + for (String paramKey : srcParamKeySet) { + Parameter srcParam = srcBag.getParameter(paramKey); + if (!dstBag.hasParameter(paramKey)) { + this.mismatchedLocators.add(srcParam.getLocator()); + continue; + } + + Parameter dstParam = dstBag.getParameter(paramKey); + deepEquals(srcParam, dstParam); + } + + Set dstParamKeySet = dstBag.getParameterKeySet(); + for (String paramKey : dstParamKeySet) { + if (!srcBag.hasParameter(paramKey)) { + Parameter dstParam = dstBag.getParameter(paramKey); + this.mismatchedLocators.add(dstParam.getLocator()); + } + } + } + + protected void deepEquals(Parameter srcParam, Parameter dstParam) { + deepEquals((StrolchElement) srcParam, (StrolchElement) dstParam); + if (!srcParam.getUom().equals(dstParam.getUom())) + this.mismatchedLocators.add(dstParam.getLocator()); + if (!srcParam.getInterpretation().equals(dstParam.getInterpretation())) + this.mismatchedLocators.add(dstParam.getLocator()); + if (srcParam.isHidden() != dstParam.isHidden()) + this.mismatchedLocators.add(dstParam.getLocator()); + + if (!srcParam.getValue().equals(dstParam.getValue())) + this.mismatchedLocators.add(dstParam.getLocator()); + } + + public static boolean isEqual(Order srcOrder, Order dstOrder) { + OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(srcOrder); + visitor.visit(srcOrder); + return visitor.isEqual(); + } + + public static boolean isEqual(Resource srcRes, Resource dstRes) { + ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes); + visitor.visit(srcRes); + return visitor.isEqual(); + } +} diff --git a/src/main/java/li/strolch/model/xml/OrderToDomVisitor.java b/src/main/java/li/strolch/model/xml/OrderToDomVisitor.java new file mode 100644 index 000000000..941f7d616 --- /dev/null +++ b/src/main/java/li/strolch/model/xml/OrderToDomVisitor.java @@ -0,0 +1,51 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.xml; + +import javax.xml.parsers.DocumentBuilder; + +import li.strolch.model.Order; +import li.strolch.model.OrderVisitor; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import ch.eitchnet.utils.helper.DomUtil; + +/** + * @author Robert von Burg + */ +public class OrderToDomVisitor implements OrderVisitor { + + private Document document; + + /** + * @return the document + */ + public Document getDocument() { + return this.document; + } + + @Override + public void visit(Order order) { + DocumentBuilder documentBuilder = DomUtil.createDocumentBuilder(); + Document document = documentBuilder.getDOMImplementation().createDocument(null, null, null); + + Element orderDom = order.toDom(document); + document.appendChild(orderDom); + this.document = document; + } +} diff --git a/src/main/java/li/strolch/model/xml/OrderToSaxVisitor.java b/src/main/java/li/strolch/model/xml/OrderToSaxVisitor.java new file mode 100644 index 000000000..428261ebe --- /dev/null +++ b/src/main/java/li/strolch/model/xml/OrderToSaxVisitor.java @@ -0,0 +1,50 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.xml; + +import java.text.MessageFormat; + +import li.strolch.model.Order; +import li.strolch.model.OrderVisitor; +import li.strolch.model.Tags; + +import org.xml.sax.ContentHandler; +import org.xml.sax.SAXException; + +/** + * @author Robert von Burg + */ +public class OrderToSaxVisitor extends StrolchElementToDomVisitor implements OrderVisitor { + + public OrderToSaxVisitor(ContentHandler contentHandler) { + super(contentHandler); + } + + @Override + public void visit(Order order) { + try { + + this.contentHandler.startElement(null, null, Tags.ORDER, attributesFor(order)); + toSax(order); + this.contentHandler.endElement(null, null, Tags.ORDER); + + } catch (SAXException e) { + String msg = "Failed to transform Order {0} to XML due to {1}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, order.getLocator(), e.getMessage()); + throw new RuntimeException(msg, e); + } + } +} diff --git a/src/main/java/li/strolch/model/xml/ResourceToDomVisitor.java b/src/main/java/li/strolch/model/xml/ResourceToDomVisitor.java new file mode 100644 index 000000000..8585ecddf --- /dev/null +++ b/src/main/java/li/strolch/model/xml/ResourceToDomVisitor.java @@ -0,0 +1,51 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.xml; + +import javax.xml.parsers.DocumentBuilder; + +import li.strolch.model.Resource; +import li.strolch.model.ResourceVisitor; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import ch.eitchnet.utils.helper.DomUtil; + +/** + * @author Robert von Burg + */ +public class ResourceToDomVisitor implements ResourceVisitor { + + private Document document; + + /** + * @return the document + */ + public Document getDocument() { + return this.document; + } + + @Override + public void visit(Resource resource) { + DocumentBuilder documentBuilder = DomUtil.createDocumentBuilder(); + Document document = documentBuilder.getDOMImplementation().createDocument(null, null, null); + + Element resourceDom = resource.toDom(document); + document.appendChild(resourceDom); + this.document = document; + } +} diff --git a/src/main/java/li/strolch/model/xml/ResourceToSaxVisitor.java b/src/main/java/li/strolch/model/xml/ResourceToSaxVisitor.java new file mode 100644 index 000000000..3bafed894 --- /dev/null +++ b/src/main/java/li/strolch/model/xml/ResourceToSaxVisitor.java @@ -0,0 +1,50 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.xml; + +import java.text.MessageFormat; + +import li.strolch.model.Resource; +import li.strolch.model.ResourceVisitor; +import li.strolch.model.Tags; + +import org.xml.sax.ContentHandler; +import org.xml.sax.SAXException; + +/** + * @author Robert von Burg + */ +public class ResourceToSaxVisitor extends StrolchElementToDomVisitor implements ResourceVisitor { + + public ResourceToSaxVisitor(ContentHandler contentHandler) { + super(contentHandler); + } + + @Override + public void visit(Resource res) { + try { + + this.contentHandler.startElement(null, null, Tags.RESOURCE, attributesFor(res)); + toSax(res); + this.contentHandler.endElement(null, null, Tags.RESOURCE); + + } catch (SAXException e) { + String msg = "Failed to transform Resource {0} to XML due to {1}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, res.getLocator(), e.getMessage()); + throw new RuntimeException(msg, e); + } + } +} diff --git a/src/main/java/li/strolch/model/xml/SimpleStrolchElementListener.java b/src/main/java/li/strolch/model/xml/SimpleStrolchElementListener.java new file mode 100644 index 000000000..79871b281 --- /dev/null +++ b/src/main/java/li/strolch/model/xml/SimpleStrolchElementListener.java @@ -0,0 +1,59 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.xml; + +import java.util.ArrayList; +import java.util.List; + +import li.strolch.model.Order; +import li.strolch.model.Resource; + +/** + * @author Robert von Burg + */ +public class SimpleStrolchElementListener implements StrolchElementListener { + + private List resources; + private List orders; + + @Override + public void notifyResource(Resource resource) { + if (this.resources == null) + this.resources = new ArrayList<>(); + this.resources.add(resource); + } + + @Override + public void notifyOrder(Order order) { + if (this.orders == null) + this.orders = new ArrayList<>(); + this.orders.add(order); + } + + /** + * @return the resources + */ + public List getResources() { + return this.resources; + } + + /** + * @return the orders + */ + public List getOrders() { + return this.orders; + } +} diff --git a/src/main/java/li/strolch/model/xml/StrolchElementToDomVisitor.java b/src/main/java/li/strolch/model/xml/StrolchElementToDomVisitor.java new file mode 100644 index 000000000..dfd939880 --- /dev/null +++ b/src/main/java/li/strolch/model/xml/StrolchElementToDomVisitor.java @@ -0,0 +1,90 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.xml; + +import java.util.Set; + +import li.strolch.model.GroupedParameterizedElement; +import li.strolch.model.Order; +import li.strolch.model.ParameterBag; +import li.strolch.model.StrolchElement; +import li.strolch.model.Tags; +import li.strolch.model.parameter.Parameter; + +import org.xml.sax.ContentHandler; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; + +import ch.eitchnet.utils.iso8601.ISO8601FormatFactory; + +/** + * @author Robert von Burg + */ +public abstract class StrolchElementToDomVisitor { + + protected ContentHandler contentHandler; + + protected StrolchElementToDomVisitor(ContentHandler contentHandler) { + this.contentHandler = contentHandler; + } + + protected AttributesImpl attributesFor(StrolchElement element) { + AttributesImpl attributes = new AttributesImpl(); + attributes.addAttribute(null, null, Tags.ID, Tags.CDATA, element.getId()); + attributes.addAttribute(null, null, Tags.NAME, Tags.CDATA, element.getName()); + attributes.addAttribute(null, null, Tags.TYPE, Tags.CDATA, element.getType()); + return attributes; + } + + protected AttributesImpl attributesFor(Order order) { + AttributesImpl attributes = attributesFor((StrolchElement) order); + attributes.addAttribute(null, null, Tags.STATE, Tags.CDATA, order.getState().name()); + attributes.addAttribute(null, null, Tags.DATE, Tags.CDATA, + ISO8601FormatFactory.getInstance().formatDate(order.getDate())); + return attributes; + } + + protected AttributesImpl attributesFor(Parameter parameter) { + AttributesImpl attributes = attributesFor((StrolchElement) parameter); + attributes.addAttribute(null, null, Tags.VALUE, Tags.CDATA, parameter.getValueAsString()); + + if (!Parameter.UOM_NONE.equals(parameter.getUom())) + attributes.addAttribute(null, null, Tags.UOM, Tags.CDATA, parameter.getUom()); + if (!Parameter.INTERPRETATION_NONE.equals(parameter.getInterpretation())) + attributes.addAttribute(null, null, Tags.INTERPRETATION, Tags.CDATA, parameter.getInterpretation()); + if (parameter.isHidden()) + attributes.addAttribute(null, null, Tags.HIDDEN, Tags.CDATA, Boolean.toString(parameter.isHidden())); + + return attributes; + } + + protected void toSax(GroupedParameterizedElement parameterizedElement) throws SAXException { + Set bagKeySet = parameterizedElement.getParameterBagKeySet(); + for (String bagKey : bagKeySet) { + ParameterBag parameterBag = parameterizedElement.getParameterBag(bagKey); + this.contentHandler.startElement(null, null, Tags.PARAMETER_BAG, attributesFor(parameterBag)); + + Set parameterKeySet = parameterBag.getParameterKeySet(); + for (String paramKey : parameterKeySet) { + Parameter parameter = parameterBag.getParameter(paramKey); + this.contentHandler.startElement(null, null, Tags.PARAMETER, attributesFor(parameter)); + this.contentHandler.endElement(null, null, Tags.PARAMETER); + } + + this.contentHandler.endElement(null, null, Tags.PARAMETER_BAG); + } + } +} diff --git a/src/main/java/li/strolch/model/xml/XmlModelDefaultHandler.java b/src/main/java/li/strolch/model/xml/XmlModelDefaultHandler.java index 0195c476f..c47649f2a 100644 --- a/src/main/java/li/strolch/model/xml/XmlModelDefaultHandler.java +++ b/src/main/java/li/strolch/model/xml/XmlModelDefaultHandler.java @@ -15,16 +15,10 @@ */ package li.strolch.model.xml; -import java.io.File; -import java.io.IOException; import java.text.MessageFormat; import java.util.Date; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; - -import li.strolch.exception.StrolchException; +import li.strolch.model.GroupedParameterizedElement; import li.strolch.model.Order; import li.strolch.model.ParameterBag; import li.strolch.model.Resource; @@ -54,20 +48,16 @@ import ch.eitchnet.utils.iso8601.ISO8601FormatFactory; */ public class XmlModelDefaultHandler extends DefaultHandler { - private static final Logger logger = LoggerFactory.getLogger(XmlModelDefaultHandler.class); + protected static final Logger logger = LoggerFactory.getLogger(XmlModelDefaultHandler.class); - private StrolchElementListener listener; - private File modelFile; + protected StrolchElementListener listener; + protected XmlModelStatistics statistics; - private Resource resource; - private Order order; + private GroupedParameterizedElement parameterizedElement; private ParameterBag pBag; - private XmlModelStatistics statistics; - - public XmlModelDefaultHandler(StrolchElementListener listener, File modelFile) { + public XmlModelDefaultHandler(StrolchElementListener listener) { this.listener = listener; - this.modelFile = modelFile; this.statistics = new XmlModelStatistics(); } @@ -94,7 +84,7 @@ public class XmlModelDefaultHandler extends DefaultHandler { String resName = attributes.getValue(Tags.NAME); String resType = attributes.getValue(Tags.TYPE); Resource resource = new Resource(resId, resName, resType); - this.resource = resource; + this.parameterizedElement = resource; break; case Tags.ORDER: @@ -112,7 +102,7 @@ public class XmlModelDefaultHandler extends DefaultHandler { State orderState = State.valueOf(orderStateS); order.setState(orderState); } - this.order = order; + this.parameterizedElement = order; break; case Tags.PARAMETER_BAG: @@ -121,6 +111,7 @@ public class XmlModelDefaultHandler extends DefaultHandler { String pBagType = attributes.getValue(Tags.TYPE); ParameterBag pBag = new ParameterBag(pBagId, pBagName, pBagType); this.pBag = pBag; + this.parameterizedElement.addParameterBag(pBag); break; case Tags.PARAMETER: @@ -165,25 +156,6 @@ public class XmlModelDefaultHandler extends DefaultHandler { this.pBag.addParameter(param); break; - case Tags.INCLUDE_FILE: - - String includeFileS = attributes.getValue(Tags.FILE); - if (StringHelper.isEmpty(includeFileS)) - throw new IllegalArgumentException(MessageFormat.format( - "The attribute {0} is missing for IncludeFile!", Tags.FILE)); //$NON-NLS-1$ - File includeFile = new File(this.modelFile.getParentFile(), includeFileS); - if (!includeFile.exists() || !includeFile.canRead()) { - String msg = "The IncludeFile does not exist, or is not readable. Source model: {0} with IncludeFile: {1}"; //$NON-NLS-1$ - msg = MessageFormat.format(msg, this.modelFile.getName(), includeFileS); - throw new IllegalArgumentException(msg); - } - - XmlModelDefaultHandler handler = new XmlModelDefaultHandler(this.listener, includeFile); - handler.parseFile(); - this.statistics.nrOfOrders += handler.statistics.nrOfOrders; - this.statistics.nrOfResources += handler.statistics.nrOfResources; - - break; default: throw new IllegalArgumentException(MessageFormat.format("The element ''{0}'' is unhandled!", qName)); //$NON-NLS-1$ } @@ -196,14 +168,14 @@ public class XmlModelDefaultHandler extends DefaultHandler { case Tags.STROLCH_MODEL: break; case Tags.RESOURCE: - this.listener.notifyResource(this.resource); + this.listener.notifyResource((Resource) this.parameterizedElement); this.statistics.nrOfResources++; - this.resource = null; + this.parameterizedElement = null; break; case Tags.ORDER: - this.listener.notifyOrder(this.order); + this.listener.notifyOrder((Order) this.parameterizedElement); this.statistics.nrOfOrders++; - this.order = null; + this.parameterizedElement = null; break; case Tags.PARAMETER_BAG: this.pBag = null; @@ -217,30 +189,6 @@ public class XmlModelDefaultHandler extends DefaultHandler { } } - public void parseFile() { - - try { - long startNanos = System.nanoTime(); - this.statistics.startTime = new Date(); - - SAXParserFactory spf = SAXParserFactory.newInstance(); - SAXParser sp = spf.newSAXParser(); - - sp.parse(this.modelFile, this); - - long endNanos = System.nanoTime(); - this.statistics.durationNanos = endNanos - startNanos; - String msg = "SAX parsed model file {0} took {1}"; //$NON-NLS-1$ - logger.info(MessageFormat.format(msg, this.modelFile.getAbsolutePath(), - StringHelper.formatNanoDuration(this.statistics.durationNanos))); - - } catch (ParserConfigurationException | SAXException | IOException e) { - - String msg = "Parsing failed due to internal error: {0}"; //$NON-NLS-1$ - throw new StrolchException(MessageFormat.format(msg, e.getMessage()), e); - } - } - public static class XmlModelStatistics { public Date startTime; public long durationNanos; diff --git a/src/main/java/li/strolch/model/xml/XmlModelFileHandler.java b/src/main/java/li/strolch/model/xml/XmlModelFileHandler.java new file mode 100644 index 000000000..d75b1261f --- /dev/null +++ b/src/main/java/li/strolch/model/xml/XmlModelFileHandler.java @@ -0,0 +1,104 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.xml; + +import java.io.File; +import java.io.IOException; +import java.text.MessageFormat; +import java.util.Date; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + +import li.strolch.exception.StrolchException; +import li.strolch.model.Tags; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +import ch.eitchnet.utils.helper.StringHelper; + +/** + * @author Robert von Burg + * + */ +public class XmlModelFileHandler extends XmlModelDefaultHandler { + + private File modelFile; + + /** + * @param listener + * @param modelFile + */ + public XmlModelFileHandler(StrolchElementListener listener, File modelFile) { + super(listener); + this.modelFile = modelFile; + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { + + switch (qName) { + + case Tags.INCLUDE_FILE: + + String includeFileS = attributes.getValue(Tags.FILE); + if (StringHelper.isEmpty(includeFileS)) + throw new IllegalArgumentException(MessageFormat.format( + "The attribute {0} is missing for IncludeFile!", Tags.FILE)); //$NON-NLS-1$ + File includeFile = new File(this.modelFile.getParentFile(), includeFileS); + if (!includeFile.exists() || !includeFile.canRead()) { + String msg = "The IncludeFile does not exist, or is not readable. Source model: {0} with IncludeFile: {1}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, this.modelFile.getName(), includeFileS); + throw new IllegalArgumentException(msg); + } + + XmlModelFileHandler handler = new XmlModelFileHandler(this.listener, includeFile); + handler.parseFile(); + this.statistics.nrOfOrders += handler.statistics.nrOfOrders; + this.statistics.nrOfResources += handler.statistics.nrOfResources; + + break; + default: + super.startElement(uri, localName, qName, attributes); + } + } + + public void parseFile() { + + try { + long startNanos = System.nanoTime(); + this.statistics.startTime = new Date(); + + SAXParserFactory spf = SAXParserFactory.newInstance(); + SAXParser sp = spf.newSAXParser(); + + sp.parse(this.modelFile, this); + + long endNanos = System.nanoTime(); + this.statistics.durationNanos = endNanos - startNanos; + String msg = "SAX parsed model file {0} took {1}"; //$NON-NLS-1$ + logger.info(MessageFormat.format(msg, this.modelFile.getAbsolutePath(), + StringHelper.formatNanoDuration(this.statistics.durationNanos))); + + } catch (ParserConfigurationException | SAXException | IOException e) { + + String msg = "Parsing failed due to internal error: {0}"; //$NON-NLS-1$ + throw new StrolchException(MessageFormat.format(msg, e.getMessage()), e); + } + } +} diff --git a/src/test/java/li/strolch/model/ModelTest.java b/src/test/java/li/strolch/model/ModelTest.java index cd2d4bc98..86f4cccd2 100644 --- a/src/test/java/li/strolch/model/ModelTest.java +++ b/src/test/java/li/strolch/model/ModelTest.java @@ -16,16 +16,13 @@ package li.strolch.model; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.Date; -import li.strolch.model.ModelGenerator; -import li.strolch.model.Order; -import li.strolch.model.ParameterBag; -import li.strolch.model.Resource; -import li.strolch.model.State; import li.strolch.model.parameter.BooleanParameter; import li.strolch.model.parameter.DateParameter; import li.strolch.model.parameter.FloatParameter; @@ -33,6 +30,8 @@ import li.strolch.model.parameter.IntegerParameter; import li.strolch.model.parameter.LongParameter; import li.strolch.model.parameter.StringListParameter; import li.strolch.model.parameter.StringParameter; +import li.strolch.model.visitor.OrderDeepEqualsVisitor; +import li.strolch.model.visitor.ResourceDeepEqualsVisitor; import org.junit.Test; @@ -55,6 +54,39 @@ public class ModelTest { validateBag(bag); } + @Test + public void shouldPerformDeepResourceEquals() { + Resource srcRes = ModelGenerator.createResource("@res01", "Test resource", "MyType"); + Resource dstRes = ModelGenerator.createResource("@res01", "Test resource", "MyType"); + ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes); + visitor.visit(dstRes); + assertTrue("Same Resource should be deep equal!", visitor.isEqual()); + } + + @Test + public void shouldFailDeepResourceEquals1() { + Resource srcRes = ModelGenerator.createResource("@res01", "Test resource", "MyType"); + Resource dstRes = ModelGenerator.createResource("@res01", "Test resource", "MyType"); + ParameterBag bag = dstRes.getParameterBag(ModelGenerator.BAG_ID); + bag.setName("Bla bla"); + FloatParameter fParam = bag.getParameter(ModelGenerator.PARAM_FLOAT_ID); + fParam.setValue(23434234.234); + fParam.setName("Ohla"); + ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes); + visitor.visit(dstRes); + assertFalse("Resource should not be same if param is changed!", visitor.isEqual()); + assertEquals("Three changes should be registered", 3, visitor.getMismatchedLocators().size()); + } + + @Test + public void shouldPerformDeepOrderEquals() { + Order srcOrder = ModelGenerator.createOrder("@ord01", "Test Order", "MyType", new Date(), State.OPEN); + Order dstOrder = ModelGenerator.createOrder("@ord01", "Test Order", "MyType", new Date(), State.OPEN); + OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(srcOrder); + visitor.visit(dstOrder); + assertTrue("Same Order should be deep equal!", visitor.isEqual()); + } + public static void validateBag(ParameterBag bag) { assertNotNull(bag); diff --git a/src/test/java/li/strolch/model/XmlModelDefaultHandlerTest.java b/src/test/java/li/strolch/model/XmlModelDefaultHandlerTest.java index 2326c7e1d..2a0ecb803 100644 --- a/src/test/java/li/strolch/model/XmlModelDefaultHandlerTest.java +++ b/src/test/java/li/strolch/model/XmlModelDefaultHandlerTest.java @@ -21,11 +21,9 @@ import java.io.File; import java.util.HashMap; import java.util.Map; -import li.strolch.model.Order; -import li.strolch.model.Resource; import li.strolch.model.xml.StrolchElementListener; -import li.strolch.model.xml.XmlModelDefaultHandler; import li.strolch.model.xml.XmlModelDefaultHandler.XmlModelStatistics; +import li.strolch.model.xml.XmlModelFileHandler; import org.junit.Test; import org.slf4j.Logger; @@ -60,7 +58,7 @@ public class XmlModelDefaultHandlerTest { orderMap.put(order.getId(), order); } }; - XmlModelDefaultHandler handler = new XmlModelDefaultHandler(listener, file); + XmlModelFileHandler handler = new XmlModelFileHandler(listener, file); handler.parseFile(); assertEquals(3, resourceMap.size()); diff --git a/src/test/java/li/strolch/model/XmlToDomTest.java b/src/test/java/li/strolch/model/XmlToDomTest.java new file mode 100644 index 000000000..76e543665 --- /dev/null +++ b/src/test/java/li/strolch/model/XmlToDomTest.java @@ -0,0 +1,65 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model; + +import static org.junit.Assert.assertTrue; +import li.strolch.model.visitor.StrolchElementDeepEqualsVisitor; +import li.strolch.model.xml.OrderToDomVisitor; +import li.strolch.model.xml.ResourceToDomVisitor; + +import org.junit.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * @author Robert von Burg + * + */ +@SuppressWarnings("nls") +public class XmlToDomTest extends ModelTest { + + @Test + public void shouldFormatAndParseOrder() { + + Order order = ModelGenerator.createOrder("@1", "My Order 1", "MyOrder"); + + OrderToDomVisitor domVisitor = new OrderToDomVisitor(); + domVisitor.visit(order); + Document document = domVisitor.getDocument(); + + Element rootElement = document.getDocumentElement(); + Order parsedOrder = new Order(rootElement); + + assertTrue("To DOM and back should equal same Order!", + StrolchElementDeepEqualsVisitor.isEqual(order, parsedOrder)); + } + + @Test + public void shouldFormatAndParseResource() { + + Resource resource = ModelGenerator.createResource("@1", "My Resource 1", "MyResource"); + + ResourceToDomVisitor domVisitor = new ResourceToDomVisitor(); + domVisitor.visit(resource); + Document document = domVisitor.getDocument(); + + Element rootElement = document.getDocumentElement(); + Resource parsedResource = new Resource(rootElement); + + assertTrue("To DOM and back should equal same Resource!", + StrolchElementDeepEqualsVisitor.isEqual(resource, parsedResource)); + } +} From 6951bac61c8601889b08a47883eb49c88d956d17 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 23 Dec 2013 20:24:53 +0100 Subject: [PATCH 32/88] [Minor] added constant for default realm --- src/main/java/li/strolch/model/query/StrolchQuery.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/li/strolch/model/query/StrolchQuery.java b/src/main/java/li/strolch/model/query/StrolchQuery.java index 9c3e9515f..81ce5fd1b 100644 --- a/src/main/java/li/strolch/model/query/StrolchQuery.java +++ b/src/main/java/li/strolch/model/query/StrolchQuery.java @@ -20,10 +20,11 @@ import java.util.List; /** * @author Robert von Burg - * */ public abstract class StrolchQuery { + public static final String DEFAULT_REALM = "defaultRealm"; //$NON-NLS-1$ + private Navigation navigation; protected List selections; From 98f92dc0f8b8db88802301f1c6ec2f391c7d61b9 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Tue, 24 Dec 2013 00:17:30 +0100 Subject: [PATCH 33/88] [Minor] moved constant for default realm --- src/main/java/li/strolch/model/query/StrolchQuery.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/li/strolch/model/query/StrolchQuery.java b/src/main/java/li/strolch/model/query/StrolchQuery.java index 81ce5fd1b..dff521c08 100644 --- a/src/main/java/li/strolch/model/query/StrolchQuery.java +++ b/src/main/java/li/strolch/model/query/StrolchQuery.java @@ -23,8 +23,6 @@ import java.util.List; */ public abstract class StrolchQuery { - public static final String DEFAULT_REALM = "defaultRealm"; //$NON-NLS-1$ - private Navigation navigation; protected List selections; From 66392767e512ab874199e553f3548b400af73c10 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Tue, 24 Dec 2013 01:47:38 +0100 Subject: [PATCH 34/88] [New] added methods to generate bulk model objects --- .../java/li/strolch/model/ModelGenerator.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/main/java/li/strolch/model/ModelGenerator.java b/src/main/java/li/strolch/model/ModelGenerator.java index 8a18aaa34..1913626b2 100644 --- a/src/main/java/li/strolch/model/ModelGenerator.java +++ b/src/main/java/li/strolch/model/ModelGenerator.java @@ -17,6 +17,7 @@ package li.strolch.model; import java.util.ArrayList; import java.util.Date; +import java.util.List; import li.strolch.model.parameter.BooleanParameter; import li.strolch.model.parameter.DateParameter; @@ -82,6 +83,31 @@ public class ModelGenerator { return resource; } + /** + * Creates a list of {@link Resource Resources} with the given values and adds a {@link ParameterBag} by calling + * {@link #createParameterBag(String, String, String)} + * + * @param idStart + * id range start + * @param count + * the number of elements to create + * @param idPrefix + * the prefix to generate IDs for the {@link Resource Resources} + * @param name + * the name of the {@link Resource} + * @param type + * the type of the {@link Resource} + * + * @return the list of newly created {@link Resource Resources} + */ + public static List createResources(int idStart, int count, String idPrefix, String name, String type) { + List resources = new ArrayList<>(); + for (int i = 0; i < count; i++) { + resources.add(createResource(idPrefix + "_" + (i + idStart), name + " " + i, type)); + } + return resources; + } + /** * Creates an {@link Order} with the given values and adds a {@link ParameterBag} by calling * {@link #createParameterBag(String, String, String)} @@ -125,6 +151,31 @@ public class ModelGenerator { return order; } + /** + * Creates a list of {@link Order Orders} with the given values and adds a {@link ParameterBag} by calling + * {@link #createParameterBag(String, String, String)} + * + * @param idStart + * id range start + * @param count + * the number of elements to create + * @param idPrefix + * the prefix to generate IDs for the {@link Order Orders} + * @param name + * the name of the {@link Order} + * @param type + * the type of the {@link Order} + * + * @return the list of newly created {@link Order Orders} + */ + public static List createOrders(int idStart, int count, String idPrefix, String name, String type) { + List orders = new ArrayList<>(); + for (int i = 0; i < count; i++) { + orders.add(createOrder(idPrefix + "_" + (i + idStart), name + " " + i, type)); + } + return orders; + } + /** * Creates a {@link ParameterBag} with the given values and calls {@link #addAllParameters(ParameterBag)} to add * {@link Parameter}s From 46d446c70094dac90007fcd8380a5f600bc12ee1 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Tue, 24 Dec 2013 02:46:43 +0100 Subject: [PATCH 35/88] [New] methods to generate bulk objects now pad the id This allows for easier lexical sorting --- src/main/java/li/strolch/model/ModelGenerator.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/li/strolch/model/ModelGenerator.java b/src/main/java/li/strolch/model/ModelGenerator.java index 1913626b2..5b42d828e 100644 --- a/src/main/java/li/strolch/model/ModelGenerator.java +++ b/src/main/java/li/strolch/model/ModelGenerator.java @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import ch.eitchnet.utils.helper.StringHelper; import li.strolch.model.parameter.BooleanParameter; import li.strolch.model.parameter.DateParameter; import li.strolch.model.parameter.FloatParameter; @@ -103,7 +104,8 @@ public class ModelGenerator { public static List createResources(int idStart, int count, String idPrefix, String name, String type) { List resources = new ArrayList<>(); for (int i = 0; i < count; i++) { - resources.add(createResource(idPrefix + "_" + (i + idStart), name + " " + i, type)); + String id = StringHelper.normalizeLength(String.valueOf((i + idStart)), 8, true, '0'); + resources.add(createResource(idPrefix + "_" + id, name + " " + i, type)); } return resources; } @@ -171,7 +173,8 @@ public class ModelGenerator { public static List createOrders(int idStart, int count, String idPrefix, String name, String type) { List orders = new ArrayList<>(); for (int i = 0; i < count; i++) { - orders.add(createOrder(idPrefix + "_" + (i + idStart), name + " " + i, type)); + String id = StringHelper.normalizeLength(String.valueOf((i + idStart)), 8, true, '0'); + orders.add(createOrder(idPrefix + "_" + id, name + " " + i, type)); } return orders; } From 43c31f4f311390bdb47dabd54f6bff32c285d9a2 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 25 Dec 2013 11:56:07 +0100 Subject: [PATCH 36/88] [Minor] fixed issue where eclipse couldn't validate log4j.xml --- src/test/resources/log4j.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/resources/log4j.xml b/src/test/resources/log4j.xml index a35a3c351..0a2a73d06 100644 --- a/src/test/resources/log4j.xml +++ b/src/test/resources/log4j.xml @@ -1,5 +1,6 @@ - + From fc92e9fff3fba16e935c5e96ba8ad5958bd21b43 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 25 Dec 2013 17:00:35 +0100 Subject: [PATCH 37/88] [Bugfix] fixed a bug in a test due to a timinig issue --- src/test/java/li/strolch/model/ModelTest.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/test/java/li/strolch/model/ModelTest.java b/src/test/java/li/strolch/model/ModelTest.java index 86f4cccd2..c703c9aca 100644 --- a/src/test/java/li/strolch/model/ModelTest.java +++ b/src/test/java/li/strolch/model/ModelTest.java @@ -80,11 +80,12 @@ public class ModelTest { @Test public void shouldPerformDeepOrderEquals() { - Order srcOrder = ModelGenerator.createOrder("@ord01", "Test Order", "MyType", new Date(), State.OPEN); - Order dstOrder = ModelGenerator.createOrder("@ord01", "Test Order", "MyType", new Date(), State.OPEN); + Date date = new Date(); + Order srcOrder = ModelGenerator.createOrder("@ord01", "Test Order", "MyType", date, State.OPEN); + Order dstOrder = ModelGenerator.createOrder("@ord01", "Test Order", "MyType", date, State.OPEN); OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(srcOrder); visitor.visit(dstOrder); - assertTrue("Same Order should be deep equal!", visitor.isEqual()); + assertTrue("Same Order should be deep equal: " + visitor.getMismatchedLocators(), visitor.isEqual()); } public static void validateBag(ParameterBag bag) { From 2cb1aa0ffe695e0778a193c0bdb75cb1b6f9558c Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sat, 28 Dec 2013 12:58:13 +0100 Subject: [PATCH 38/88] [Bugfix] fixed an issue where cloning a Resource was missing the params --- .../li/strolch/model/GroupedParameterizedElement.java | 2 +- src/main/java/li/strolch/model/ParameterizedElement.java | 8 +++++++- .../java/li/strolch/model/parameter/BooleanParameter.java | 2 +- .../java/li/strolch/model/parameter/DateParameter.java | 2 +- .../java/li/strolch/model/parameter/FloatParameter.java | 2 +- .../java/li/strolch/model/parameter/IntegerParameter.java | 2 +- .../java/li/strolch/model/parameter/LongParameter.java | 2 +- src/main/java/li/strolch/model/parameter/Parameter.java | 3 +++ .../li/strolch/model/parameter/StringListParameter.java | 3 +-- .../java/li/strolch/model/parameter/StringParameter.java | 2 +- 10 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/main/java/li/strolch/model/GroupedParameterizedElement.java b/src/main/java/li/strolch/model/GroupedParameterizedElement.java index d09b973ed..4ed7f2ae3 100644 --- a/src/main/java/li/strolch/model/GroupedParameterizedElement.java +++ b/src/main/java/li/strolch/model/GroupedParameterizedElement.java @@ -91,7 +91,7 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement * * @return the found {@link Parameter} or null if it was not found */ - public Parameter getParameter(String bagKey, String paramKey) { + public T getParameter(String bagKey, String paramKey) { if (this.parameterBagMap == null) return null; ParameterBag bag = this.parameterBagMap.get(bagKey); diff --git a/src/main/java/li/strolch/model/ParameterizedElement.java b/src/main/java/li/strolch/model/ParameterizedElement.java index 1291d7523..cf25546dd 100644 --- a/src/main/java/li/strolch/model/ParameterizedElement.java +++ b/src/main/java/li/strolch/model/ParameterizedElement.java @@ -259,7 +259,13 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { @Override protected void fillClone(StrolchElement clone) { super.fillClone(clone); - ((ParameterizedElement) clone).setType(this.type); + ParameterizedElement peClone = (ParameterizedElement) clone; + peClone.setType(this.type); + if(this.parameterMap != null) { + for(Parameter param : this.parameterMap.values()) { + peClone.addParameter(param.getClone()); + } + } } @SuppressWarnings("nls") diff --git a/src/main/java/li/strolch/model/parameter/BooleanParameter.java b/src/main/java/li/strolch/model/parameter/BooleanParameter.java index 646a858ec..2ea3a0769 100644 --- a/src/main/java/li/strolch/model/parameter/BooleanParameter.java +++ b/src/main/java/li/strolch/model/parameter/BooleanParameter.java @@ -91,7 +91,7 @@ public class BooleanParameter extends AbstractParameter { } @Override - public Parameter getClone() { + public BooleanParameter getClone() { BooleanParameter clone = new BooleanParameter(); super.fillClone(clone); diff --git a/src/main/java/li/strolch/model/parameter/DateParameter.java b/src/main/java/li/strolch/model/parameter/DateParameter.java index cf406d08b..dcf3da983 100644 --- a/src/main/java/li/strolch/model/parameter/DateParameter.java +++ b/src/main/java/li/strolch/model/parameter/DateParameter.java @@ -94,7 +94,7 @@ public class DateParameter extends AbstractParameter { } @Override - public Parameter getClone() { + public DateParameter getClone() { DateParameter clone = new DateParameter(); super.fillClone(clone); diff --git a/src/main/java/li/strolch/model/parameter/FloatParameter.java b/src/main/java/li/strolch/model/parameter/FloatParameter.java index 09b5c6194..f6dd5071f 100644 --- a/src/main/java/li/strolch/model/parameter/FloatParameter.java +++ b/src/main/java/li/strolch/model/parameter/FloatParameter.java @@ -94,7 +94,7 @@ public class FloatParameter extends AbstractParameter { } @Override - public Parameter getClone() { + public FloatParameter getClone() { FloatParameter clone = new FloatParameter(); super.fillClone(clone); diff --git a/src/main/java/li/strolch/model/parameter/IntegerParameter.java b/src/main/java/li/strolch/model/parameter/IntegerParameter.java index de41a480b..428e96dcb 100644 --- a/src/main/java/li/strolch/model/parameter/IntegerParameter.java +++ b/src/main/java/li/strolch/model/parameter/IntegerParameter.java @@ -93,7 +93,7 @@ public class IntegerParameter extends AbstractParameter { } @Override - public Parameter getClone() { + public IntegerParameter getClone() { IntegerParameter clone = new IntegerParameter(); super.fillClone(clone); diff --git a/src/main/java/li/strolch/model/parameter/LongParameter.java b/src/main/java/li/strolch/model/parameter/LongParameter.java index f7a33c3ca..9c445ccb1 100644 --- a/src/main/java/li/strolch/model/parameter/LongParameter.java +++ b/src/main/java/li/strolch/model/parameter/LongParameter.java @@ -93,7 +93,7 @@ public class LongParameter extends AbstractParameter { } @Override - public Parameter getClone() { + public LongParameter getClone() { LongParameter clone = new LongParameter(); super.fillClone(clone); diff --git a/src/main/java/li/strolch/model/parameter/Parameter.java b/src/main/java/li/strolch/model/parameter/Parameter.java index 93f66d8c4..16ba482d2 100644 --- a/src/main/java/li/strolch/model/parameter/Parameter.java +++ b/src/main/java/li/strolch/model/parameter/Parameter.java @@ -140,4 +140,7 @@ public interface Parameter extends StrolchElement { @Override public boolean equals(Object obj); + + @Override + public Parameter getClone(); } diff --git a/src/main/java/li/strolch/model/parameter/StringListParameter.java b/src/main/java/li/strolch/model/parameter/StringListParameter.java index 08682f255..65fc6556e 100644 --- a/src/main/java/li/strolch/model/parameter/StringListParameter.java +++ b/src/main/java/li/strolch/model/parameter/StringListParameter.java @@ -23,7 +23,6 @@ import java.util.Iterator; import java.util.List; import li.strolch.exception.StrolchException; -import li.strolch.model.StrolchElement; import li.strolch.model.Tags; import org.w3c.dom.Element; @@ -125,7 +124,7 @@ public class StringListParameter extends AbstractParameter> impleme } @Override - public StrolchElement getClone() { + public StringListParameter getClone() { StringListParameter clone = new StringListParameter(); super.fillClone(clone); diff --git a/src/main/java/li/strolch/model/parameter/StringParameter.java b/src/main/java/li/strolch/model/parameter/StringParameter.java index 27882880d..5a0db74fa 100644 --- a/src/main/java/li/strolch/model/parameter/StringParameter.java +++ b/src/main/java/li/strolch/model/parameter/StringParameter.java @@ -95,7 +95,7 @@ public class StringParameter extends AbstractParameter { } @Override - public Parameter getClone() { + public StringParameter getClone() { StringParameter clone = new StringParameter(); super.fillClone(clone); From 3a756b95611b9335404a78cf11f12cdddb0e54c8 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 1 Jan 2014 02:17:26 +0100 Subject: [PATCH 39/88] [New] added new TEMPLATE constant to Tags --- src/main/java/li/strolch/model/Tags.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/li/strolch/model/Tags.java b/src/main/java/li/strolch/model/Tags.java index e2d7b86a9..5d0a3cd01 100644 --- a/src/main/java/li/strolch/model/Tags.java +++ b/src/main/java/li/strolch/model/Tags.java @@ -37,4 +37,5 @@ public class Tags { public static final String INCLUDE_FILE = "IncludeFile"; public static final String FILE = "file"; + public static final String TEMPLATE = "Template"; } From e781aea668d4f7f2f8889815edd7a80748b838fc Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 10 Jan 2014 19:10:36 +0100 Subject: [PATCH 40/88] [Major] refactored how transactions are opened Now the ElementMapHandler is the central object and clients do not use access DAOs or the PersistenceHandler anymore. This is now transparent. --- src/main/java/li/strolch/model/Order.java | 2 +- src/main/java/li/strolch/model/Resource.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/li/strolch/model/Order.java b/src/main/java/li/strolch/model/Order.java index 442b13132..feec6abc5 100644 --- a/src/main/java/li/strolch/model/Order.java +++ b/src/main/java/li/strolch/model/Order.java @@ -160,7 +160,7 @@ public class Order extends GroupedParameterizedElement { @Override protected void fillLocator(LocatorBuilder lb) { - lb.append(Tags.ORDER).append(getId()); + lb.append(Tags.ORDER).append(getType()).append(getId()); } @Override diff --git a/src/main/java/li/strolch/model/Resource.java b/src/main/java/li/strolch/model/Resource.java index 3f7f909ef..63b36e552 100644 --- a/src/main/java/li/strolch/model/Resource.java +++ b/src/main/java/li/strolch/model/Resource.java @@ -74,7 +74,7 @@ public class Resource extends GroupedParameterizedElement { @Override protected void fillLocator(LocatorBuilder lb) { - lb.append(Tags.RESOURCE).append(getId()); + lb.append(Tags.RESOURCE).append(getType()).append(getId()); } @Override From ce2afd365bf9b0b025caad70133aa042379509b6 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 13 Jan 2014 19:08:21 +0100 Subject: [PATCH 41/88] [Minor] extended Locator to get the path elements Further added JavaDoc and removed exceptions when formatting about locator length. This is now checked when instantiating using the builder --- src/main/java/li/strolch/model/Locator.java | 36 +++++++++++++------ .../strolch/model/ParameterizedElement.java | 2 +- .../model/parameter/AbstractParameter.java | 2 +- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/main/java/li/strolch/model/Locator.java b/src/main/java/li/strolch/model/Locator.java index 43ee86a12..31f50528c 100644 --- a/src/main/java/li/strolch/model/Locator.java +++ b/src/main/java/li/strolch/model/Locator.java @@ -15,7 +15,6 @@ */ package li.strolch.model; -import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -27,8 +26,9 @@ import ch.eitchnet.utils.helper.StringHelper; /** *

- * The {@link Locator} is used to fully qualify the location of an object in the model. It consists of a {@link List} of - * Strings which starting from the first value, defining the root, with the last item defining the objects id. + * The {@link Locator} is an immutable object and is used to fully qualify the location of an object in the model. It + * consists of a {@link List} of Strings which starting from the first value, defining the root, with the last item + * defining the objects id. *

* *

@@ -112,6 +112,15 @@ public class Locator { this.pathElements = Collections.unmodifiableList(fullPath); } + /** + * Returns the immutable list of path elements making up this locator + * + * @return the pathElements + */ + public List getPathElements() { + return this.pathElements; + } + /** * Returns the number of elements which this {@link Locator} contains * @@ -185,12 +194,6 @@ public class Locator { * if the path elements does not contain at least two items */ private String formatPath(List pathElements) throws StrolchException { - if (pathElements.isEmpty()) { - String msg = "A Path always consists of at least 1 element: {0}"; //$NON-NLS-1$ - msg = MessageFormat.format(msg, pathElements); - throw new StrolchException(msg); - } - StringBuilder sb = new StringBuilder(); Iterator iter = pathElements.iterator(); @@ -229,6 +232,17 @@ public class Locator { return true; } + /** + * Instantiates a new immutable {@link Locator} instance from the given string + * + * @param locatorPath + * the path from which to instantiate the locator + * @return the immutable {@link Locator} instance + */ + public static Locator valueOf(String locatorPath) { + return new Locator(locatorPath); + } + /** * {@link LocatorBuilder} is used to build {@link Locator}s where a deep hierarchy is to be created. The * {@link #append(String)} method returns itself for chain building @@ -270,11 +284,13 @@ public class Locator { } /** - * Creates a {@link Locator} instance with the current elements + * Creates an immutable {@link Locator} instance with the current elements * * @return a new {@link Locator} instance */ public Locator build() { + if (this.pathElements.isEmpty()) + throw new StrolchException("The path elements must contain at least 1 item"); //$NON-NLS-1$ return new Locator(this.pathElements); } } diff --git a/src/main/java/li/strolch/model/ParameterizedElement.java b/src/main/java/li/strolch/model/ParameterizedElement.java index cf25546dd..3db4eab35 100644 --- a/src/main/java/li/strolch/model/ParameterizedElement.java +++ b/src/main/java/li/strolch/model/ParameterizedElement.java @@ -192,7 +192,7 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { @Override public void fillLocator(LocatorBuilder lb) { - lb.append(Tags.PARAMETERIZED_ELEMENT).append(this.id); + lb.append(this.id); } @Override diff --git a/src/main/java/li/strolch/model/parameter/AbstractParameter.java b/src/main/java/li/strolch/model/parameter/AbstractParameter.java index cdb6c558c..fc80bb6fa 100644 --- a/src/main/java/li/strolch/model/parameter/AbstractParameter.java +++ b/src/main/java/li/strolch/model/parameter/AbstractParameter.java @@ -166,7 +166,7 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem @Override protected void fillLocator(LocatorBuilder locatorBuilder) { - locatorBuilder.append(Tags.PARAMETER).append(this.id); + locatorBuilder.append(this.id); } @Override From 63fc60bdfd4aafd99bef7da61ed2ed5272ad0061 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 22 Jan 2014 20:19:10 +0100 Subject: [PATCH 42/88] [Bugfix] fixed a bug that tries to parse inexistant state on Order --- src/main/java/li/strolch/model/xml/XmlModelDefaultHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/li/strolch/model/xml/XmlModelDefaultHandler.java b/src/main/java/li/strolch/model/xml/XmlModelDefaultHandler.java index c47649f2a..9b8c72b7f 100644 --- a/src/main/java/li/strolch/model/xml/XmlModelDefaultHandler.java +++ b/src/main/java/li/strolch/model/xml/XmlModelDefaultHandler.java @@ -98,7 +98,7 @@ public class XmlModelDefaultHandler extends DefaultHandler { Date orderDate = ISO8601FormatFactory.getInstance().getDateFormat().parse(orderDateS); order.setDate(orderDate); } - if (orderDateS != null) { + if (orderStateS != null) { State orderState = State.valueOf(orderStateS); order.setState(orderState); } From 0f6f2183c984fbc15f6d8223fdfb3c38e97cf7ef Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 23 Jan 2014 22:00:34 +0100 Subject: [PATCH 43/88] [New] added version info metadata to agent --- pom.xml | 4 ++++ src/main/resources/componentVersion.properties | 6 ++++++ 2 files changed, 10 insertions(+) create mode 100644 src/main/resources/componentVersion.properties diff --git a/pom.xml b/pom.xml index eb1289eff..0d807046c 100644 --- a/pom.xml +++ b/pom.xml @@ -36,6 +36,10 @@ + + org.codehaus.mojo + buildnumber-maven-plugin + org.apache.maven.plugins maven-eclipse-plugin diff --git a/src/main/resources/componentVersion.properties b/src/main/resources/componentVersion.properties new file mode 100644 index 000000000..1f050160f --- /dev/null +++ b/src/main/resources/componentVersion.properties @@ -0,0 +1,6 @@ +groupId=${project.groupId} +artifactId=${project.artifactId} +artifactVersion=${project.version} +scmRevision=r${buildNumber} +scmBranch=${scmBranch} +buildTimestamp=${buildTimestamp} \ No newline at end of file From 84c75c8d32db5a983c622097351a645895796dc4 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 23 Jan 2014 22:52:38 +0100 Subject: [PATCH 44/88] [Project] added Jenkins build badge to README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 034f92fde..34313a285 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ li.strolch.model ================ +[![Build Status](http://jenkins.eitchnet.ch/buildStatus/icon?job=li.strolch.model)](http://jenkins.eitchnet.ch/view/strolch/job/li.strolch.model/) + Strolch is a generic framework for building parameterized models for modification at runtime written in Java \ No newline at end of file From 9fda3766974987dd8b2f93d8c976fffa3f6c7ba2 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sat, 25 Jan 2014 22:14:33 +0100 Subject: [PATCH 45/88] [Minor] code cleanup --- src/main/java/li/strolch/model/ModelGenerator.java | 2 +- src/main/java/li/strolch/model/Resource.java | 4 ++-- .../java/li/strolch/model/parameter/BooleanParameter.java | 5 +++-- src/test/java/li/strolch/model/timedstate/TimeStateTest.java | 2 -- .../li/strolch/model/timevalue/FloatTimeVariableTest.java | 3 --- .../li/strolch/model/timevalue/IntegerTimeVariableTest.java | 3 --- .../li/strolch/model/timevalue/StringTimeVariableTest.java | 3 --- src/test/java/li/strolch/model/timevalue/ValueTests.java | 1 - 8 files changed, 6 insertions(+), 17 deletions(-) diff --git a/src/main/java/li/strolch/model/ModelGenerator.java b/src/main/java/li/strolch/model/ModelGenerator.java index 5b42d828e..1091f2946 100644 --- a/src/main/java/li/strolch/model/ModelGenerator.java +++ b/src/main/java/li/strolch/model/ModelGenerator.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; -import ch.eitchnet.utils.helper.StringHelper; import li.strolch.model.parameter.BooleanParameter; import li.strolch.model.parameter.DateParameter; import li.strolch.model.parameter.FloatParameter; @@ -28,6 +27,7 @@ import li.strolch.model.parameter.LongParameter; import li.strolch.model.parameter.Parameter; import li.strolch.model.parameter.StringListParameter; import li.strolch.model.parameter.StringParameter; +import ch.eitchnet.utils.helper.StringHelper; /** * Class which can be used to generate objects which implement {@link StrolchElement}. These generated classes can then diff --git a/src/main/java/li/strolch/model/Resource.java b/src/main/java/li/strolch/model/Resource.java index 63b36e552..7a86483d8 100644 --- a/src/main/java/li/strolch/model/Resource.java +++ b/src/main/java/li/strolch/model/Resource.java @@ -15,11 +15,11 @@ */ package li.strolch.model; +import li.strolch.model.Locator.LocatorBuilder; + import org.w3c.dom.Document; import org.w3c.dom.Element; -import li.strolch.model.Locator.LocatorBuilder; - /** * @author Robert von Burg */ diff --git a/src/main/java/li/strolch/model/parameter/BooleanParameter.java b/src/main/java/li/strolch/model/parameter/BooleanParameter.java index 2ea3a0769..57b56117c 100644 --- a/src/main/java/li/strolch/model/parameter/BooleanParameter.java +++ b/src/main/java/li/strolch/model/parameter/BooleanParameter.java @@ -17,10 +17,11 @@ package li.strolch.model.parameter; import java.text.MessageFormat; -import org.w3c.dom.Element; - import li.strolch.exception.StrolchException; import li.strolch.model.Tags; + +import org.w3c.dom.Element; + import ch.eitchnet.utils.helper.StringHelper; /** diff --git a/src/test/java/li/strolch/model/timedstate/TimeStateTest.java b/src/test/java/li/strolch/model/timedstate/TimeStateTest.java index c21c9027f..d91d9efa0 100644 --- a/src/test/java/li/strolch/model/timedstate/TimeStateTest.java +++ b/src/test/java/li/strolch/model/timedstate/TimeStateTest.java @@ -18,8 +18,6 @@ package li.strolch.model.timedstate; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import li.strolch.model.timedstate.ITimedState; -import li.strolch.model.timedstate.TimedState; import li.strolch.model.timevalue.ITimeValue; import li.strolch.model.timevalue.IValueChange; import li.strolch.model.timevalue.impl.DoubleValue; diff --git a/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java b/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java index 8e16f85ac..0f788d2ca 100644 --- a/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java +++ b/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java @@ -22,9 +22,6 @@ import static org.junit.Assert.assertTrue; import java.util.Collection; import java.util.SortedSet; -import li.strolch.model.timevalue.ITimeValue; -import li.strolch.model.timevalue.IValue; -import li.strolch.model.timevalue.IValueChange; import li.strolch.model.timevalue.impl.DoubleValue; import li.strolch.model.timevalue.impl.TimeVariable; import li.strolch.model.timevalue.impl.ValueChange; diff --git a/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java b/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java index 5e2cad7cc..d1a5b346e 100644 --- a/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java +++ b/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java @@ -23,9 +23,6 @@ import java.util.HashMap; import java.util.Map; import java.util.SortedSet; -import li.strolch.model.timevalue.ITimeValue; -import li.strolch.model.timevalue.IValue; -import li.strolch.model.timevalue.IValueChange; import li.strolch.model.timevalue.impl.IntegerValue; import li.strolch.model.timevalue.impl.TimeVariable; import li.strolch.model.timevalue.impl.ValueChange; diff --git a/src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java b/src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java index e1b6ae38e..f8a8143ff 100644 --- a/src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java +++ b/src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java @@ -25,9 +25,6 @@ import java.util.Map; import java.util.Set; import java.util.SortedSet; -import li.strolch.model.timevalue.ITimeValue; -import li.strolch.model.timevalue.IValue; -import li.strolch.model.timevalue.IValueChange; import li.strolch.model.timevalue.impl.AString; import li.strolch.model.timevalue.impl.StringSetValue; import li.strolch.model.timevalue.impl.TimeVariable; diff --git a/src/test/java/li/strolch/model/timevalue/ValueTests.java b/src/test/java/li/strolch/model/timevalue/ValueTests.java index bab00c1ff..ed0991a3d 100644 --- a/src/test/java/li/strolch/model/timevalue/ValueTests.java +++ b/src/test/java/li/strolch/model/timevalue/ValueTests.java @@ -20,7 +20,6 @@ import static org.junit.Assert.assertEquals; import java.util.HashSet; import java.util.Set; -import li.strolch.model.timevalue.IValue; import li.strolch.model.timevalue.impl.AString; import li.strolch.model.timevalue.impl.DoubleValue; import li.strolch.model.timevalue.impl.IntegerValue; From 743e1c039bad8e7e0c1c30db7176cb1805d208d7 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 30 Jan 2014 00:21:13 +0100 Subject: [PATCH 46/88] [New] Implemented Export and Import model services and commands --- .../model/GroupedParameterizedElement.java | 11 ++- .../strolch/model/ParameterizedElement.java | 13 ++- .../model/xml/AbstractToSaxWriterVisitor.java | 96 +++++++++++++++++++ .../model/xml/OrderToSaxWriterVisitor.java | 47 +++++++++ .../model/xml/ResourceToSaxWriterVisitor.java | 47 +++++++++ ...andler.java => XmlModelSaxFileReader.java} | 6 +- ...ultHandler.java => XmlModelSaxReader.java} | 7 +- .../model/XmlModelDefaultHandlerTest.java | 6 +- 8 files changed, 220 insertions(+), 13 deletions(-) create mode 100644 src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java create mode 100644 src/main/java/li/strolch/model/xml/OrderToSaxWriterVisitor.java create mode 100644 src/main/java/li/strolch/model/xml/ResourceToSaxWriterVisitor.java rename src/main/java/li/strolch/model/xml/{XmlModelFileHandler.java => XmlModelSaxFileReader.java} (93%) rename src/main/java/li/strolch/model/xml/{XmlModelDefaultHandler.java => XmlModelSaxReader.java} (97%) diff --git a/src/main/java/li/strolch/model/GroupedParameterizedElement.java b/src/main/java/li/strolch/model/GroupedParameterizedElement.java index 4ed7f2ae3..16e7f04d6 100644 --- a/src/main/java/li/strolch/model/GroupedParameterizedElement.java +++ b/src/main/java/li/strolch/model/GroupedParameterizedElement.java @@ -186,6 +186,15 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement return this.parameterBagMap.remove(key); } + /** + * Returns true if this {@link GroupedParameterizedElement} has any {@link ParameterBag ParameterBag} + * + * @return true if this {@link GroupedParameterizedElement} has any {@link ParameterBag ParameterBag} + */ + public boolean hasParameterBags() { + return this.parameterBagMap != null && !this.parameterBagMap.isEmpty(); + } + /** * Returns true if the {@link ParameterBag} with the given key exists on this {@link GroupedParameterizedElement}. * @@ -194,7 +203,7 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement * @return true if the {@link ParameterBag} with the given key exists on this {@link GroupedParameterizedElement}. */ public boolean hasParameterBag(String bagKey) { - return this.parameterBagMap != null && this.parameterBagMap.containsKey(bagKey); + return this.parameterBagMap != null && this.parameterBagMap.containsKey(bagKey); } /** diff --git a/src/main/java/li/strolch/model/ParameterizedElement.java b/src/main/java/li/strolch/model/ParameterizedElement.java index 3db4eab35..aff782c3e 100644 --- a/src/main/java/li/strolch/model/ParameterizedElement.java +++ b/src/main/java/li/strolch/model/ParameterizedElement.java @@ -165,6 +165,15 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { return new ArrayList>(this.parameterMap.values()); } + /** + * Returns true, if the this {@link ParameterizedElement} has any {@link Parameter Parameters}, false otherwise + * + * @return true, if the this {@link ParameterizedElement} has any {@link Parameter Parameters}, false otherwise + */ + public boolean hasParameters() { + return this.parameterMap != null && !this.parameterMap.isEmpty(); + } + /** * Returns true, if the {@link Parameter} exists with the given key, false otherwise * @@ -261,8 +270,8 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { super.fillClone(clone); ParameterizedElement peClone = (ParameterizedElement) clone; peClone.setType(this.type); - if(this.parameterMap != null) { - for(Parameter param : this.parameterMap.values()) { + if (this.parameterMap != null) { + for (Parameter param : this.parameterMap.values()) { peClone.addParameter(param.getClone()); } } diff --git a/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java b/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java new file mode 100644 index 000000000..4ac7c3cc5 --- /dev/null +++ b/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java @@ -0,0 +1,96 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.xml; + +import java.util.Set; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; + +import li.strolch.model.GroupedParameterizedElement; +import li.strolch.model.ParameterBag; +import li.strolch.model.ParameterizedElement; +import li.strolch.model.StrolchElement; +import li.strolch.model.Tags; +import li.strolch.model.parameter.Parameter; +import ch.eitchnet.utils.helper.StringHelper; + +/** + * @author Robert von Burg + */ +public abstract class AbstractToSaxWriterVisitor { + + protected XMLStreamWriter writer; + + public AbstractToSaxWriterVisitor(XMLStreamWriter writer) { + this.writer = writer; + } + + protected void writeElement(String tag, GroupedParameterizedElement element) throws XMLStreamException { + boolean isEmpty = !element.hasParameterBags(); + writeStartStrolchElement(tag, isEmpty, element); + if (!isEmpty) { + writeParameterBags(element); + writer.writeEndElement(); + } + } + + protected void writeStartStrolchElement(String tag, boolean empty, StrolchElement element) + throws XMLStreamException { + if (empty) + writer.writeEmptyElement(tag); + else + writer.writeStartElement(tag); + + writer.writeAttribute(Tags.ID, element.getId()); + if (!StringHelper.isEmpty(element.getName())) + writer.writeAttribute(Tags.NAME, element.getName()); + writer.writeAttribute(Tags.TYPE, element.getType()); + } + + protected void writeParameters(ParameterizedElement element) throws XMLStreamException { + + Set parameterKeySet = element.getParameterKeySet(); + for (String paramKey : parameterKeySet) { + Parameter parameter = element.getParameter(paramKey); + + writeStartStrolchElement(Tags.PARAMETER, true, parameter); + + if (!Parameter.INTERPRETATION_NONE.equals(parameter.getInterpretation())) + writer.writeAttribute(Tags.INTERPRETATION, parameter.getInterpretation()); + if (!Parameter.UOM_NONE.equals(parameter.getUom())) + writer.writeAttribute(Tags.UOM, parameter.getUom()); + if (parameter.isHidden()) + writer.writeAttribute(Tags.HIDDEN, Boolean.toString(parameter.isHidden())); + + writer.writeAttribute(Tags.VALUE, parameter.getValueAsString()); + } + } + + protected void writeParameterBags(GroupedParameterizedElement element) throws XMLStreamException { + + Set bagKeySet = element.getParameterBagKeySet(); + for (String bagKey : bagKeySet) { + ParameterBag parameterBag = element.getParameterBag(bagKey); + boolean isEmpty = !parameterBag.hasParameters(); + writeStartStrolchElement(Tags.PARAMETER_BAG, isEmpty, parameterBag); + if (!isEmpty) { + writeParameters(parameterBag); + writer.writeEndElement(); + } + } + } +} diff --git a/src/main/java/li/strolch/model/xml/OrderToSaxWriterVisitor.java b/src/main/java/li/strolch/model/xml/OrderToSaxWriterVisitor.java new file mode 100644 index 000000000..8ac0200a0 --- /dev/null +++ b/src/main/java/li/strolch/model/xml/OrderToSaxWriterVisitor.java @@ -0,0 +1,47 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.xml; + +import java.text.MessageFormat; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; + +import li.strolch.exception.StrolchException; +import li.strolch.model.Order; +import li.strolch.model.OrderVisitor; +import li.strolch.model.Tags; + +/** + * @author Robert von Burg + */ +public class OrderToSaxWriterVisitor extends AbstractToSaxWriterVisitor implements OrderVisitor { + + public OrderToSaxWriterVisitor(XMLStreamWriter writer) { + super(writer); + } + + @Override + public void visit(Order order) { + try { + writeElement(Tags.ORDER, order); + } catch (XMLStreamException e) { + String msg = "Failed to write Order {0} due to {1}"; + msg = MessageFormat.format(msg, order.getLocator(), e.getMessage()); + throw new StrolchException(msg, e); + } + } +} diff --git a/src/main/java/li/strolch/model/xml/ResourceToSaxWriterVisitor.java b/src/main/java/li/strolch/model/xml/ResourceToSaxWriterVisitor.java new file mode 100644 index 000000000..f98098f29 --- /dev/null +++ b/src/main/java/li/strolch/model/xml/ResourceToSaxWriterVisitor.java @@ -0,0 +1,47 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.xml; + +import java.text.MessageFormat; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; + +import li.strolch.exception.StrolchException; +import li.strolch.model.Resource; +import li.strolch.model.ResourceVisitor; +import li.strolch.model.Tags; + +/** + * @author Robert von Burg + */ +public class ResourceToSaxWriterVisitor extends AbstractToSaxWriterVisitor implements ResourceVisitor { + + public ResourceToSaxWriterVisitor(XMLStreamWriter writer) { + super(writer); + } + + @Override + public void visit(Resource resource) { + try { + writeElement(Tags.RESOURCE, resource); + } catch (XMLStreamException e) { + String msg = "Failed to write Resource {0} due to {1}"; + msg = MessageFormat.format(msg, resource.getLocator(), e.getMessage()); + throw new StrolchException(msg, e); + } + } +} diff --git a/src/main/java/li/strolch/model/xml/XmlModelFileHandler.java b/src/main/java/li/strolch/model/xml/XmlModelSaxFileReader.java similarity index 93% rename from src/main/java/li/strolch/model/xml/XmlModelFileHandler.java rename to src/main/java/li/strolch/model/xml/XmlModelSaxFileReader.java index d75b1261f..81e9c0d47 100644 --- a/src/main/java/li/strolch/model/xml/XmlModelFileHandler.java +++ b/src/main/java/li/strolch/model/xml/XmlModelSaxFileReader.java @@ -36,7 +36,7 @@ import ch.eitchnet.utils.helper.StringHelper; * @author Robert von Burg * */ -public class XmlModelFileHandler extends XmlModelDefaultHandler { +public class XmlModelSaxFileReader extends XmlModelSaxReader { private File modelFile; @@ -44,7 +44,7 @@ public class XmlModelFileHandler extends XmlModelDefaultHandler { * @param listener * @param modelFile */ - public XmlModelFileHandler(StrolchElementListener listener, File modelFile) { + public XmlModelSaxFileReader(StrolchElementListener listener, File modelFile) { super(listener); this.modelFile = modelFile; } @@ -67,7 +67,7 @@ public class XmlModelFileHandler extends XmlModelDefaultHandler { throw new IllegalArgumentException(msg); } - XmlModelFileHandler handler = new XmlModelFileHandler(this.listener, includeFile); + XmlModelSaxFileReader handler = new XmlModelSaxFileReader(this.listener, includeFile); handler.parseFile(); this.statistics.nrOfOrders += handler.statistics.nrOfOrders; this.statistics.nrOfResources += handler.statistics.nrOfResources; diff --git a/src/main/java/li/strolch/model/xml/XmlModelDefaultHandler.java b/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java similarity index 97% rename from src/main/java/li/strolch/model/xml/XmlModelDefaultHandler.java rename to src/main/java/li/strolch/model/xml/XmlModelSaxReader.java index 9b8c72b7f..5b0b424d1 100644 --- a/src/main/java/li/strolch/model/xml/XmlModelDefaultHandler.java +++ b/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java @@ -44,11 +44,10 @@ import ch.eitchnet.utils.iso8601.ISO8601FormatFactory; /** * @author Robert von Burg - * */ -public class XmlModelDefaultHandler extends DefaultHandler { +public class XmlModelSaxReader extends DefaultHandler { - protected static final Logger logger = LoggerFactory.getLogger(XmlModelDefaultHandler.class); + protected static final Logger logger = LoggerFactory.getLogger(XmlModelSaxReader.class); protected StrolchElementListener listener; protected XmlModelStatistics statistics; @@ -56,7 +55,7 @@ public class XmlModelDefaultHandler extends DefaultHandler { private GroupedParameterizedElement parameterizedElement; private ParameterBag pBag; - public XmlModelDefaultHandler(StrolchElementListener listener) { + public XmlModelSaxReader(StrolchElementListener listener) { this.listener = listener; this.statistics = new XmlModelStatistics(); } diff --git a/src/test/java/li/strolch/model/XmlModelDefaultHandlerTest.java b/src/test/java/li/strolch/model/XmlModelDefaultHandlerTest.java index 2a0ecb803..1b7fedbae 100644 --- a/src/test/java/li/strolch/model/XmlModelDefaultHandlerTest.java +++ b/src/test/java/li/strolch/model/XmlModelDefaultHandlerTest.java @@ -22,8 +22,8 @@ import java.util.HashMap; import java.util.Map; import li.strolch.model.xml.StrolchElementListener; -import li.strolch.model.xml.XmlModelDefaultHandler.XmlModelStatistics; -import li.strolch.model.xml.XmlModelFileHandler; +import li.strolch.model.xml.XmlModelSaxReader.XmlModelStatistics; +import li.strolch.model.xml.XmlModelSaxFileReader; import org.junit.Test; import org.slf4j.Logger; @@ -58,7 +58,7 @@ public class XmlModelDefaultHandlerTest { orderMap.put(order.getId(), order); } }; - XmlModelFileHandler handler = new XmlModelFileHandler(listener, file); + XmlModelSaxFileReader handler = new XmlModelSaxFileReader(listener, file); handler.parseFile(); assertEquals(3, resourceMap.size()); From 368f8f14a4f1e12c437df8dc3d9d44ee0aeaafa7 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 31 Jan 2014 15:55:16 +0100 Subject: [PATCH 47/88] [New] modified the Selection to have a builder pattern Further modified the StringParameterSelection to allow for contains and case insensitive querying --- .../li/strolch/model/query/AndSelection.java | 19 +++++++++-- .../strolch/model/query/BooleanSelection.java | 24 ++++++++++--- .../li/strolch/model/query/OrSelection.java | 20 +++++++++-- .../model/query/ParameterSelection.java | 34 +++++++++++++++---- .../li/strolch/model/query/QueryVisitor.java | 5 ++- .../query/StrolchElementSelectionVisitor.java | 2 +- .../li/strolch/model/query/StrolchQuery.java | 2 +- .../model/xml/AbstractToSaxWriterVisitor.java | 22 ++++++------ .../model/xml/OrderToSaxWriterVisitor.java | 2 +- .../model/xml/ResourceToSaxWriterVisitor.java | 2 +- 10 files changed, 97 insertions(+), 35 deletions(-) diff --git a/src/main/java/li/strolch/model/query/AndSelection.java b/src/main/java/li/strolch/model/query/AndSelection.java index b0f643169..8f0c70bb6 100644 --- a/src/main/java/li/strolch/model/query/AndSelection.java +++ b/src/main/java/li/strolch/model/query/AndSelection.java @@ -20,15 +20,30 @@ import java.util.List; /** * @author Robert von Burg */ -public class AndSelection extends BooleanSelection { +public class AndSelection extends BooleanSelection { + + public AndSelection() { + super(); + } + + @SafeVarargs + public AndSelection(Selection... selections) { + super(selections); + } /** * @param selections */ - public AndSelection(List selections) { + public AndSelection(List selections) { super(selections); } + @Override + public AndSelection with(Selection selection) { + super.with(selection); + return this; + } + public void accept(QueryVisitor visitor) { visitor.visitAnd(this); } diff --git a/src/main/java/li/strolch/model/query/BooleanSelection.java b/src/main/java/li/strolch/model/query/BooleanSelection.java index 54881e8f9..bfd9318bc 100644 --- a/src/main/java/li/strolch/model/query/BooleanSelection.java +++ b/src/main/java/li/strolch/model/query/BooleanSelection.java @@ -15,23 +15,37 @@ */ package li.strolch.model.query; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** * @author Robert von Burg - * */ -public abstract class BooleanSelection implements Selection { +public abstract class BooleanSelection implements Selection { - protected List selections; + protected List selections; - public BooleanSelection(List selections) { + public BooleanSelection() { + this.selections = new ArrayList<>(); + } + + public BooleanSelection(List selections) { this.selections = selections; } - public List getSelections() { + public BooleanSelection(Selection... selections) { + this.selections = Arrays.asList(selections); + } + + public List getSelections() { return this.selections; } + public BooleanSelection with(Selection selection) { + this.selections.add(selection); + return this; + } + public abstract void accept(QueryVisitor visitor); } diff --git a/src/main/java/li/strolch/model/query/OrSelection.java b/src/main/java/li/strolch/model/query/OrSelection.java index 7a01dd725..697a25182 100644 --- a/src/main/java/li/strolch/model/query/OrSelection.java +++ b/src/main/java/li/strolch/model/query/OrSelection.java @@ -19,14 +19,28 @@ import java.util.List; /** * @author Robert von Burg - * */ -public class OrSelection extends BooleanSelection { +public class OrSelection extends BooleanSelection { - public OrSelection(List selections) { + public OrSelection() { + super(); + } + + public OrSelection(List selections) { super(selections); } + @SafeVarargs + public OrSelection(Selection... selections) { + super(selections); + } + + @Override + public OrSelection with(Selection selection) { + super.with(selection); + return this; + } + @Override public void accept(QueryVisitor visitor) { visitor.visitOr(this); diff --git a/src/main/java/li/strolch/model/query/ParameterSelection.java b/src/main/java/li/strolch/model/query/ParameterSelection.java index 5f1b53321..b57df7137 100644 --- a/src/main/java/li/strolch/model/query/ParameterSelection.java +++ b/src/main/java/li/strolch/model/query/ParameterSelection.java @@ -52,37 +52,39 @@ public abstract class ParameterSelection implements Selection { public abstract void accept(ParameterSelectionVisitor visitor); - public static ParameterSelection stringSelection(String bagKey, String paramKey, String value) { + public static StringParameterSelection stringSelection(String bagKey, String paramKey, String value) { return new StringParameterSelection(bagKey, paramKey, value); } - public static ParameterSelection integerSelection(String bagKey, String paramKey, int value) { + public static IntegerParameterSelection integerSelection(String bagKey, String paramKey, int value) { return new IntegerParameterSelection(bagKey, paramKey, value); } - public static ParameterSelection booleanSelection(String bagKey, String paramKey, boolean value) { + public static BooleanParameterSelection booleanSelection(String bagKey, String paramKey, boolean value) { return new BooleanParameterSelection(bagKey, paramKey, value); } - public static ParameterSelection floatSelection(String bagKey, String paramKey, double value) { + public static FloatParameterSelection floatSelection(String bagKey, String paramKey, double value) { return new FloatParameterSelection(bagKey, paramKey, value); } - public static ParameterSelection longSelection(String bagKey, String paramKey, long value) { + public static LongParameterSelection longSelection(String bagKey, String paramKey, long value) { return new LongParameterSelection(bagKey, paramKey, value); } - public static ParameterSelection dateSelection(String bagKey, String paramKey, Date value) { + public static DateParameterSelection dateSelection(String bagKey, String paramKey, Date value) { return new DateParameterSelection(bagKey, paramKey, value); } - public static ParameterSelection stringListSelection(String bagKey, String paramKey, List value) { + public static StringListParameterSelection stringListSelection(String bagKey, String paramKey, List value) { return new StringListParameterSelection(bagKey, paramKey, value); } public static class StringParameterSelection extends ParameterSelection { private String value; + private boolean contains; + private boolean caseInsensitive; public StringParameterSelection(String bagKey, String paramKey, String value) { super(bagKey, paramKey); @@ -93,6 +95,24 @@ public abstract class ParameterSelection implements Selection { return this.value; } + public boolean isContains() { + return this.contains; + } + + public boolean isCaseInsensitive() { + return this.caseInsensitive; + } + + public StringParameterSelection contains(boolean contains) { + this.contains = contains; + return this; + } + + public StringParameterSelection caseInsensitive(boolean caseInsensitive) { + this.caseInsensitive = true; + return this; + } + @Override public void accept(ParameterSelectionVisitor visitor) { visitor.visit(this); diff --git a/src/main/java/li/strolch/model/query/QueryVisitor.java b/src/main/java/li/strolch/model/query/QueryVisitor.java index d6efcec67..c5e9b128a 100644 --- a/src/main/java/li/strolch/model/query/QueryVisitor.java +++ b/src/main/java/li/strolch/model/query/QueryVisitor.java @@ -17,11 +17,10 @@ package li.strolch.model.query; /** * @author Robert von Burg - * */ public interface QueryVisitor { - public void visitAnd(AndSelection andSelection); + public void visitAnd(AndSelection andSelection); - public void visitOr(OrSelection orSelection); + public void visitOr(OrSelection orSelection); } diff --git a/src/main/java/li/strolch/model/query/StrolchElementSelectionVisitor.java b/src/main/java/li/strolch/model/query/StrolchElementSelectionVisitor.java index 4756beb3e..b7bf67fdb 100644 --- a/src/main/java/li/strolch/model/query/StrolchElementSelectionVisitor.java +++ b/src/main/java/li/strolch/model/query/StrolchElementSelectionVisitor.java @@ -18,7 +18,7 @@ package li.strolch.model.query; /** * @author Robert von Burg */ -public interface StrolchElementSelectionVisitor extends QueryVisitor{ +public interface StrolchElementSelectionVisitor extends QueryVisitor { public void visit(StrolchTypeNavigation navigation); diff --git a/src/main/java/li/strolch/model/query/StrolchQuery.java b/src/main/java/li/strolch/model/query/StrolchQuery.java index dff521c08..01e377347 100644 --- a/src/main/java/li/strolch/model/query/StrolchQuery.java +++ b/src/main/java/li/strolch/model/query/StrolchQuery.java @@ -31,7 +31,7 @@ public abstract class StrolchQuery { this.selections = new ArrayList<>(); } - public void addSelection(BooleanSelection selection) { + public void addSelection(BooleanSelection selection) { this.selections.add(selection); } diff --git a/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java b/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java index 4ac7c3cc5..a9bd73f74 100644 --- a/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java +++ b/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java @@ -44,21 +44,21 @@ public abstract class AbstractToSaxWriterVisitor { writeStartStrolchElement(tag, isEmpty, element); if (!isEmpty) { writeParameterBags(element); - writer.writeEndElement(); + this.writer.writeEndElement(); } } protected void writeStartStrolchElement(String tag, boolean empty, StrolchElement element) throws XMLStreamException { if (empty) - writer.writeEmptyElement(tag); + this.writer.writeEmptyElement(tag); else - writer.writeStartElement(tag); + this.writer.writeStartElement(tag); - writer.writeAttribute(Tags.ID, element.getId()); + this.writer.writeAttribute(Tags.ID, element.getId()); if (!StringHelper.isEmpty(element.getName())) - writer.writeAttribute(Tags.NAME, element.getName()); - writer.writeAttribute(Tags.TYPE, element.getType()); + this.writer.writeAttribute(Tags.NAME, element.getName()); + this.writer.writeAttribute(Tags.TYPE, element.getType()); } protected void writeParameters(ParameterizedElement element) throws XMLStreamException { @@ -70,13 +70,13 @@ public abstract class AbstractToSaxWriterVisitor { writeStartStrolchElement(Tags.PARAMETER, true, parameter); if (!Parameter.INTERPRETATION_NONE.equals(parameter.getInterpretation())) - writer.writeAttribute(Tags.INTERPRETATION, parameter.getInterpretation()); + this.writer.writeAttribute(Tags.INTERPRETATION, parameter.getInterpretation()); if (!Parameter.UOM_NONE.equals(parameter.getUom())) - writer.writeAttribute(Tags.UOM, parameter.getUom()); + this.writer.writeAttribute(Tags.UOM, parameter.getUom()); if (parameter.isHidden()) - writer.writeAttribute(Tags.HIDDEN, Boolean.toString(parameter.isHidden())); + this.writer.writeAttribute(Tags.HIDDEN, Boolean.toString(parameter.isHidden())); - writer.writeAttribute(Tags.VALUE, parameter.getValueAsString()); + this.writer.writeAttribute(Tags.VALUE, parameter.getValueAsString()); } } @@ -89,7 +89,7 @@ public abstract class AbstractToSaxWriterVisitor { writeStartStrolchElement(Tags.PARAMETER_BAG, isEmpty, parameterBag); if (!isEmpty) { writeParameters(parameterBag); - writer.writeEndElement(); + this.writer.writeEndElement(); } } } diff --git a/src/main/java/li/strolch/model/xml/OrderToSaxWriterVisitor.java b/src/main/java/li/strolch/model/xml/OrderToSaxWriterVisitor.java index 8ac0200a0..cf4f089d4 100644 --- a/src/main/java/li/strolch/model/xml/OrderToSaxWriterVisitor.java +++ b/src/main/java/li/strolch/model/xml/OrderToSaxWriterVisitor.java @@ -39,7 +39,7 @@ public class OrderToSaxWriterVisitor extends AbstractToSaxWriterVisitor implemen try { writeElement(Tags.ORDER, order); } catch (XMLStreamException e) { - String msg = "Failed to write Order {0} due to {1}"; + String msg = "Failed to write Order {0} due to {1}"; //$NON-NLS-1$ msg = MessageFormat.format(msg, order.getLocator(), e.getMessage()); throw new StrolchException(msg, e); } diff --git a/src/main/java/li/strolch/model/xml/ResourceToSaxWriterVisitor.java b/src/main/java/li/strolch/model/xml/ResourceToSaxWriterVisitor.java index f98098f29..8f6783802 100644 --- a/src/main/java/li/strolch/model/xml/ResourceToSaxWriterVisitor.java +++ b/src/main/java/li/strolch/model/xml/ResourceToSaxWriterVisitor.java @@ -39,7 +39,7 @@ public class ResourceToSaxWriterVisitor extends AbstractToSaxWriterVisitor imple try { writeElement(Tags.RESOURCE, resource); } catch (XMLStreamException e) { - String msg = "Failed to write Resource {0} due to {1}"; + String msg = "Failed to write Resource {0} due to {1}"; //$NON-NLS-1$ msg = MessageFormat.format(msg, resource.getLocator(), e.getMessage()); throw new StrolchException(msg, e); } From 49df0b54da45d08601b7d60ab3095be24a451a1a Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 31 Jan 2014 19:02:21 +0100 Subject: [PATCH 48/88] [Minor] switched to StringHelper.isNotEmpty() --- .../java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java b/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java index a9bd73f74..cbe28772a 100644 --- a/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java +++ b/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java @@ -56,7 +56,7 @@ public abstract class AbstractToSaxWriterVisitor { this.writer.writeStartElement(tag); this.writer.writeAttribute(Tags.ID, element.getId()); - if (!StringHelper.isEmpty(element.getName())) + if (StringHelper.isNotEmpty(element.getName())) this.writer.writeAttribute(Tags.NAME, element.getName()); this.writer.writeAttribute(Tags.TYPE, element.getType()); } From 5915fe086d92801abe420cf78dd36a55cc162a4c Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 31 Jan 2014 19:13:19 +0100 Subject: [PATCH 49/88] [New] added Parameter.getIndex() --- .../java/li/strolch/model/ModelGenerator.java | 7 +++++++ src/main/java/li/strolch/model/Tags.java | 1 + .../model/parameter/AbstractParameter.java | 21 +++++++++++++++++++ .../li/strolch/model/parameter/Parameter.java | 17 ++++++++++++++- .../StrolchElementDeepEqualsVisitor.java | 2 ++ .../model/xml/AbstractToSaxWriterVisitor.java | 2 ++ .../model/xml/StrolchElementToDomVisitor.java | 2 ++ .../strolch/model/xml/XmlModelSaxReader.java | 5 ++++- 8 files changed, 55 insertions(+), 2 deletions(-) diff --git a/src/main/java/li/strolch/model/ModelGenerator.java b/src/main/java/li/strolch/model/ModelGenerator.java index 1091f2946..3e6cf99f7 100644 --- a/src/main/java/li/strolch/model/ModelGenerator.java +++ b/src/main/java/li/strolch/model/ModelGenerator.java @@ -216,21 +216,27 @@ public class ModelGenerator { public static void addAllParameters(ParameterBag bag) { BooleanParameter boolParam = new BooleanParameter(PARAM_BOOLEAN_ID, PARAM_BOOLEAN_NAME, true); + boolParam.setIndex(1); bag.addParameter(boolParam); FloatParameter floatParam = new FloatParameter(PARAM_FLOAT_ID, PARAM_FLOAT_NAME, 44.3); + floatParam.setIndex(2); bag.addParameter(floatParam); IntegerParameter integerParam = new IntegerParameter(PARAM_INTEGER_ID, PARAM_INTEGER_NAME, 77); + integerParam.setIndex(3); bag.addParameter(integerParam); LongParameter longParam = new LongParameter(PARAM_LONG_ID, PARAM_LONG_NAME, 4453234566L); + longParam.setIndex(4); bag.addParameter(longParam); StringParameter stringParam = new StringParameter(PARAM_STRING_ID, PARAM_STRING_NAME, "Strolch"); + stringParam.setIndex(5); bag.addParameter(stringParam); DateParameter dateParam = new DateParameter(PARAM_DATE_ID, PARAM_DATE_NAME, new Date(1354295525628L)); + dateParam.setIndex(6); bag.addParameter(dateParam); ArrayList stringList = new ArrayList(); @@ -238,6 +244,7 @@ public class ModelGenerator { stringList.add("World"); StringListParameter stringListP = new StringListParameter(PARAM_LIST_STRING_ID, PARAM_LIST_STRING_NAME, stringList); + stringListP.setIndex(7); bag.addParameter(stringListP); } } diff --git a/src/main/java/li/strolch/model/Tags.java b/src/main/java/li/strolch/model/Tags.java index 5d0a3cd01..b68bdac9c 100644 --- a/src/main/java/li/strolch/model/Tags.java +++ b/src/main/java/li/strolch/model/Tags.java @@ -28,6 +28,7 @@ public class Tags { public static final String INTERPRETATION = "Interpretation"; public static final String UOM = "Uom"; public static final String HIDDEN = "Hidden"; + public static final String INDEX = "Index"; public static final String PARAMETER = "Parameter"; public static final String PARAMETERIZED_ELEMENT = "ParameterizedElement"; public static final String RESOURCE = "Resource"; diff --git a/src/main/java/li/strolch/model/parameter/AbstractParameter.java b/src/main/java/li/strolch/model/parameter/AbstractParameter.java index fc80bb6fa..9875dff0b 100644 --- a/src/main/java/li/strolch/model/parameter/AbstractParameter.java +++ b/src/main/java/li/strolch/model/parameter/AbstractParameter.java @@ -39,6 +39,7 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem private static final long serialVersionUID = 0L; protected boolean hidden = false; + protected int index; protected String interpretation = INTERPRETATION_NONE; protected String uom = UOM_NONE; @@ -99,6 +100,16 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem } } + @Override + public void setIndex(int index) { + this.index = index; + } + + @Override + public int getIndex() { + return this.index; + } + @Override public ParameterizedElement getParent() { return this.parent; @@ -122,6 +133,8 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem element.setAttribute(Tags.UOM, this.uom); if (this.hidden) element.setAttribute(Tags.HIDDEN, Boolean.toString(this.hidden)); + if (this.index != 0) + element.setAttribute(Tags.INDEX, Integer.toString(this.index)); return element; } @@ -145,10 +158,17 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem String interpretation = element.getAttribute(Tags.INTERPRETATION); String hidden = element.getAttribute(Tags.HIDDEN); String uom = element.getAttribute(Tags.UOM); + String index = element.getAttribute(Tags.INDEX); setInterpretation(interpretation); setUom(uom); + if(StringHelper.isEmpty(index)) { + this.index = 0; + } else { + this.index = Integer.valueOf(index); + } + if (StringHelper.isEmpty(hidden)) { setHidden(false); } else { @@ -205,6 +225,7 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem clone.setHidden(this.hidden); clone.setInterpretation(this.interpretation); clone.setUom(this.uom); + clone.setIndex(this.index); } @SuppressWarnings("nls") diff --git a/src/main/java/li/strolch/model/parameter/Parameter.java b/src/main/java/li/strolch/model/parameter/Parameter.java index 16ba482d2..2b8c37014 100644 --- a/src/main/java/li/strolch/model/parameter/Parameter.java +++ b/src/main/java/li/strolch/model/parameter/Parameter.java @@ -97,6 +97,21 @@ public interface Parameter extends StrolchElement { */ public void setUom(String uom); + /** + * Returns the index of this {@link Parameter}. This can be used to sort the parameters in a UI + * + * @return the index of this {@link Parameter}. This can be used to sort the parameters in a UI + */ + public int getIndex(); + + /** + * Set the index of this {@link Parameter}. This can be used to sort the parameters in a UI + * + * @param index + * the index to set + */ + public void setIndex(int index); + /** * The {@link ParameterizedElement} parent to which this {@link Parameter} belongs * @@ -140,7 +155,7 @@ public interface Parameter extends StrolchElement { @Override public boolean equals(Object obj); - + @Override public Parameter getClone(); } diff --git a/src/main/java/li/strolch/model/visitor/StrolchElementDeepEqualsVisitor.java b/src/main/java/li/strolch/model/visitor/StrolchElementDeepEqualsVisitor.java index 0b927fdcb..0c0c2c602 100644 --- a/src/main/java/li/strolch/model/visitor/StrolchElementDeepEqualsVisitor.java +++ b/src/main/java/li/strolch/model/visitor/StrolchElementDeepEqualsVisitor.java @@ -127,6 +127,8 @@ public class StrolchElementDeepEqualsVisitor { this.mismatchedLocators.add(dstParam.getLocator()); if (srcParam.isHidden() != dstParam.isHidden()) this.mismatchedLocators.add(dstParam.getLocator()); + if (srcParam.getIndex() != dstParam.getIndex()) + this.mismatchedLocators.add(dstParam.getLocator()); if (!srcParam.getValue().equals(dstParam.getValue())) this.mismatchedLocators.add(dstParam.getLocator()); diff --git a/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java b/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java index cbe28772a..ee3a27a53 100644 --- a/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java +++ b/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java @@ -75,6 +75,8 @@ public abstract class AbstractToSaxWriterVisitor { this.writer.writeAttribute(Tags.UOM, parameter.getUom()); if (parameter.isHidden()) this.writer.writeAttribute(Tags.HIDDEN, Boolean.toString(parameter.isHidden())); + if (parameter.getIndex() != 0) + this.writer.writeAttribute(Tags.INDEX, Integer.toString(parameter.getIndex())); this.writer.writeAttribute(Tags.VALUE, parameter.getValueAsString()); } diff --git a/src/main/java/li/strolch/model/xml/StrolchElementToDomVisitor.java b/src/main/java/li/strolch/model/xml/StrolchElementToDomVisitor.java index dfd939880..a13f921df 100644 --- a/src/main/java/li/strolch/model/xml/StrolchElementToDomVisitor.java +++ b/src/main/java/li/strolch/model/xml/StrolchElementToDomVisitor.java @@ -67,6 +67,8 @@ public abstract class StrolchElementToDomVisitor { attributes.addAttribute(null, null, Tags.INTERPRETATION, Tags.CDATA, parameter.getInterpretation()); if (parameter.isHidden()) attributes.addAttribute(null, null, Tags.HIDDEN, Tags.CDATA, Boolean.toString(parameter.isHidden())); + if (parameter.getIndex() != 0) + attributes.addAttribute(null, null, Tags.INDEX, Tags.CDATA, Integer.toString(parameter.getIndex())); return attributes; } diff --git a/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java b/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java index 5b0b424d1..ec4849e97 100644 --- a/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java +++ b/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java @@ -119,7 +119,9 @@ public class XmlModelSaxReader extends DefaultHandler { String paramType = attributes.getValue(Tags.TYPE); String paramValue = attributes.getValue(Tags.VALUE); String paramHiddenS = attributes.getValue(Tags.HIDDEN); - boolean paramHidden = paramHiddenS == null ? false : StringHelper.parseBoolean(paramHiddenS); + String paramIndexS = attributes.getValue(Tags.INDEX); + int index = StringHelper.isEmpty(paramIndexS) ? 0 : Integer.valueOf(paramIndexS); + boolean paramHidden = StringHelper.isEmpty(paramHiddenS) ? false : StringHelper.parseBoolean(paramHiddenS); String paramUom = attributes.getValue(Tags.UOM); String paramInterpretation = attributes.getValue(Tags.INTERPRETATION); Parameter param; @@ -152,6 +154,7 @@ public class XmlModelSaxReader extends DefaultHandler { param.setHidden(paramHidden); param.setUom(paramUom); param.setInterpretation(paramInterpretation); + param.setIndex(index); this.pBag.addParameter(param); break; From e023733cf04d6cff7e980062f46a4867d4cd721e Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sat, 1 Feb 2014 13:12:43 +0100 Subject: [PATCH 50/88] [New] Added NotSelection and further builder methods to StrolchQuery --- .../li/strolch/model/query/AndSelection.java | 1 + .../strolch/model/query/BooleanSelection.java | 12 ++++- .../li/strolch/model/query/IdSelection.java | 42 +++++++++++++++-- .../li/strolch/model/query/NotSelection.java | 47 +++++++++++++++++++ .../li/strolch/model/query/QueryVisitor.java | 2 + .../li/strolch/model/query/StrolchQuery.java | 23 +++++++++ 6 files changed, 120 insertions(+), 7 deletions(-) create mode 100644 src/main/java/li/strolch/model/query/NotSelection.java diff --git a/src/main/java/li/strolch/model/query/AndSelection.java b/src/main/java/li/strolch/model/query/AndSelection.java index 8f0c70bb6..77c480921 100644 --- a/src/main/java/li/strolch/model/query/AndSelection.java +++ b/src/main/java/li/strolch/model/query/AndSelection.java @@ -44,6 +44,7 @@ public class AndSelection extends BooleanSelection { return this; } + @Override public void accept(QueryVisitor visitor) { visitor.visitAnd(this); } diff --git a/src/main/java/li/strolch/model/query/BooleanSelection.java b/src/main/java/li/strolch/model/query/BooleanSelection.java index bfd9318bc..010d463d6 100644 --- a/src/main/java/li/strolch/model/query/BooleanSelection.java +++ b/src/main/java/li/strolch/model/query/BooleanSelection.java @@ -17,6 +17,7 @@ package li.strolch.model.query; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; /** @@ -27,19 +28,25 @@ public abstract class BooleanSelection implements Selection { protected List selections; public BooleanSelection() { - this.selections = new ArrayList<>(); + this.selections = new ArrayList<>(1); } public BooleanSelection(List selections) { this.selections = selections; } + public BooleanSelection(Selection leftHandSide, Selection rightHandSide) { + this.selections = new ArrayList<>(2); + this.selections.add(leftHandSide); + this.selections.add(rightHandSide); + } + public BooleanSelection(Selection... selections) { this.selections = Arrays.asList(selections); } public List getSelections() { - return this.selections; + return Collections.unmodifiableList(this.selections); } public BooleanSelection with(Selection selection) { @@ -47,5 +54,6 @@ public abstract class BooleanSelection implements Selection { return this; } + @Override public abstract void accept(QueryVisitor visitor); } diff --git a/src/main/java/li/strolch/model/query/IdSelection.java b/src/main/java/li/strolch/model/query/IdSelection.java index 9be311b08..1aea0f913 100644 --- a/src/main/java/li/strolch/model/query/IdSelection.java +++ b/src/main/java/li/strolch/model/query/IdSelection.java @@ -15,25 +15,57 @@ */ package li.strolch.model.query; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + /** * @author Robert von Burg */ public class IdSelection extends StrolchElementSelection { - private String id; + private List ids; + + public IdSelection() { + this.ids = new ArrayList<>(1); + } /** * @param id */ public IdSelection(String id) { - this.id = id; + this.ids = new ArrayList<>(1); + this.ids.add(id); } /** - * @return the id + * @param ids */ - public String getId() { - return this.id; + public IdSelection(String... ids) { + this.ids = Arrays.asList(ids); + } + + /** + * @param ids + */ + public IdSelection(List ids) { + this.ids = ids; + } + + /** + * @return the ids + */ + public List getIds() { + return this.ids; + } + + /** + * @param id + * @return + */ + public IdSelection with(String id) { + this.ids.add(id); + return this; } @Override diff --git a/src/main/java/li/strolch/model/query/NotSelection.java b/src/main/java/li/strolch/model/query/NotSelection.java new file mode 100644 index 000000000..a6ea2e0cf --- /dev/null +++ b/src/main/java/li/strolch/model/query/NotSelection.java @@ -0,0 +1,47 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.query; + +/** + * @author Robert von Burg + */ +public class NotSelection extends BooleanSelection { + + /** + * @param selection + */ + public NotSelection(Selection selection) { + super(selection); + } + + /** + * @throws UnsupportedOperationException + * because a {@link NotSelection} can only work on a single {@link Selection} + */ + @Override + public NotSelection with(Selection selection) { + throw new UnsupportedOperationException("NotSelection can only have a single selection"); //$NON-NLS-1$ + } + + public Selection getSelection() { + return this.selections.get(0); + } + + @Override + public void accept(QueryVisitor visitor) { + visitor.visitNot(this); + } +} diff --git a/src/main/java/li/strolch/model/query/QueryVisitor.java b/src/main/java/li/strolch/model/query/QueryVisitor.java index c5e9b128a..f1a9dbe55 100644 --- a/src/main/java/li/strolch/model/query/QueryVisitor.java +++ b/src/main/java/li/strolch/model/query/QueryVisitor.java @@ -23,4 +23,6 @@ public interface QueryVisitor { public void visitAnd(AndSelection andSelection); public void visitOr(OrSelection orSelection); + + public void visitNot(NotSelection notSelection); } diff --git a/src/main/java/li/strolch/model/query/StrolchQuery.java b/src/main/java/li/strolch/model/query/StrolchQuery.java index 01e377347..256abdc85 100644 --- a/src/main/java/li/strolch/model/query/StrolchQuery.java +++ b/src/main/java/li/strolch/model/query/StrolchQuery.java @@ -43,6 +43,29 @@ public abstract class StrolchQuery { this.selections.add(selection); } + public StrolchQuery select(Selection selection) { + this.selections.add(selection); + return this; + } + + public StrolchQuery and(Selection... selections) { + AndSelection and = new AndSelection(selections); + this.selections.add(and); + return this; + } + + public StrolchQuery or(Selection... selections) { + OrSelection or = new OrSelection(selections); + this.selections.add(or); + return this; + } + + public StrolchQuery not(Selection selection) { + NotSelection not = new NotSelection(selection); + this.selections.add(not); + return this; + } + public void accept(T visitor) { this.navigation.accept(visitor); for (Selection selection : this.selections) { From 8b76bf3d4bb2759efa63265d8188b14945ed7728 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 3 Feb 2014 08:03:10 +0100 Subject: [PATCH 51/88] [Major] refactoring use of BooleanSelection in StrolchQuery --- .../li/strolch/model/query/AndSelection.java | 12 ++++ .../strolch/model/query/BooleanSelection.java | 12 ++++ .../li/strolch/model/query/OrSelection.java | 12 ++++ .../li/strolch/model/query/OrderQuery.java | 4 -- .../li/strolch/model/query/StrolchQuery.java | 56 ++++++++----------- 5 files changed, 58 insertions(+), 38 deletions(-) diff --git a/src/main/java/li/strolch/model/query/AndSelection.java b/src/main/java/li/strolch/model/query/AndSelection.java index 77c480921..877ba4f50 100644 --- a/src/main/java/li/strolch/model/query/AndSelection.java +++ b/src/main/java/li/strolch/model/query/AndSelection.java @@ -44,6 +44,18 @@ public class AndSelection extends BooleanSelection { return this; } + @Override + public AndSelection with(List selections) { + super.with(selections); + return this; + } + + @Override + public AndSelection with(Selection... selections) { + super.with(selections); + return this; + } + @Override public void accept(QueryVisitor visitor) { visitor.visitAnd(this); diff --git a/src/main/java/li/strolch/model/query/BooleanSelection.java b/src/main/java/li/strolch/model/query/BooleanSelection.java index 010d463d6..76e2cee17 100644 --- a/src/main/java/li/strolch/model/query/BooleanSelection.java +++ b/src/main/java/li/strolch/model/query/BooleanSelection.java @@ -54,6 +54,18 @@ public abstract class BooleanSelection implements Selection { return this; } + public BooleanSelection with(Selection... selections) { + for (Selection selection : selections) { + this.selections.add(selection); + } + return this; + } + + public BooleanSelection with(List selections) { + this.selections.addAll(selections); + return this; + } + @Override public abstract void accept(QueryVisitor visitor); } diff --git a/src/main/java/li/strolch/model/query/OrSelection.java b/src/main/java/li/strolch/model/query/OrSelection.java index 697a25182..e2b0d582c 100644 --- a/src/main/java/li/strolch/model/query/OrSelection.java +++ b/src/main/java/li/strolch/model/query/OrSelection.java @@ -41,6 +41,18 @@ public class OrSelection extends BooleanSelection { return this; } + @Override + public OrSelection with(List selections) { + super.with(selections); + return this; + } + + @Override + public OrSelection with(Selection... selections) { + super.with(selections); + return this; + } + @Override public void accept(QueryVisitor visitor) { visitor.visitOr(this); diff --git a/src/main/java/li/strolch/model/query/OrderQuery.java b/src/main/java/li/strolch/model/query/OrderQuery.java index 23a598a7d..a98ca4f08 100644 --- a/src/main/java/li/strolch/model/query/OrderQuery.java +++ b/src/main/java/li/strolch/model/query/OrderQuery.java @@ -23,8 +23,4 @@ public class OrderQuery extends StrolchQuery { public OrderQuery(Navigation navigation) { super(navigation); } - - public void add(OrderSelection selection) { - this.selections.add(selection); - } } diff --git a/src/main/java/li/strolch/model/query/StrolchQuery.java b/src/main/java/li/strolch/model/query/StrolchQuery.java index 256abdc85..fa90f0385 100644 --- a/src/main/java/li/strolch/model/query/StrolchQuery.java +++ b/src/main/java/li/strolch/model/query/StrolchQuery.java @@ -15,8 +15,7 @@ */ package li.strolch.model.query; -import java.util.ArrayList; -import java.util.List; +import ch.eitchnet.utils.dbc.DBC; /** * @author Robert von Burg @@ -24,52 +23,41 @@ import java.util.List; public abstract class StrolchQuery { private Navigation navigation; - protected List selections; + private Selection selection; public StrolchQuery(Navigation navigation) { this.navigation = navigation; - this.selections = new ArrayList<>(); } - public void addSelection(BooleanSelection selection) { - this.selections.add(selection); + public void select(Selection selection) { + DBC.PRE.assertNull("A selection is already set! Use a boolean operator to perform multiple selections", + this.selection); + this.selection = selection; } - public void addSelection(StrolchElementSelection selection) { - this.selections.add(selection); + public AndSelection and() { + DBC.PRE.assertNull("A selection is already set! Create hierarchical boolean selections", this.selection); + AndSelection and = new AndSelection(); + this.selection = and; + return and; } - public void addSelection(ParameterSelection selection) { - this.selections.add(selection); + public OrSelection or() { + DBC.PRE.assertNull("A selection is already set! Create hierarchical boolean selections", this.selection); + OrSelection or = new OrSelection(); + this.selection = or; + return or; } - public StrolchQuery select(Selection selection) { - this.selections.add(selection); - return this; - } - - public StrolchQuery and(Selection... selections) { - AndSelection and = new AndSelection(selections); - this.selections.add(and); - return this; - } - - public StrolchQuery or(Selection... selections) { - OrSelection or = new OrSelection(selections); - this.selections.add(or); - return this; - } - - public StrolchQuery not(Selection selection) { - NotSelection not = new NotSelection(selection); - this.selections.add(not); - return this; + public void not(Selection selection) { + DBC.PRE.assertNull("A selection is already set! Create hierarchical boolean selections", this.selection); + this.selection = new NotSelection(selection); } public void accept(T visitor) { + DBC.PRE.assertNotNull("No navigation set!", this.navigation); + DBC.PRE.assertNotNull("No selection defined!", this.selection); this.navigation.accept(visitor); - for (Selection selection : this.selections) { - selection.accept(visitor); - } + this.selection.accept(visitor); } } From 14dd9ff73b7c53a5f5c696a6ff02748e23b824b8 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 7 Feb 2014 17:54:48 +0100 Subject: [PATCH 52/88] [New] added a ParameterVisitor interface with SetParameterValueVisitor --- .../java/li/strolch/model/OrderVisitor.java | 2 + .../li/strolch/model/ResourceVisitor.java | 2 + .../model/parameter/AbstractParameter.java | 10 +- .../model/parameter/BooleanParameter.java | 6 ++ .../model/parameter/DateParameter.java | 6 ++ .../model/parameter/FloatParameter.java | 8 +- .../model/parameter/IntegerParameter.java | 6 ++ .../model/parameter/LongParameter.java | 6 ++ .../li/strolch/model/parameter/Parameter.java | 3 + .../model/parameter/StringListParameter.java | 6 ++ .../model/parameter/StringParameter.java | 6 ++ .../model/visitor/ParameterVisitor.java | 50 ++++++++++ .../visitor/SetParameterValueVisitor.java | 96 +++++++++++++++++++ .../{ => visitor}/StrolchElementVisitor.java | 4 +- 14 files changed, 207 insertions(+), 4 deletions(-) create mode 100644 src/main/java/li/strolch/model/visitor/ParameterVisitor.java create mode 100644 src/main/java/li/strolch/model/visitor/SetParameterValueVisitor.java rename src/main/java/li/strolch/model/{ => visitor}/StrolchElementVisitor.java (91%) diff --git a/src/main/java/li/strolch/model/OrderVisitor.java b/src/main/java/li/strolch/model/OrderVisitor.java index c076175e3..2d3874c50 100644 --- a/src/main/java/li/strolch/model/OrderVisitor.java +++ b/src/main/java/li/strolch/model/OrderVisitor.java @@ -15,6 +15,8 @@ */ package li.strolch.model; +import li.strolch.model.visitor.StrolchElementVisitor; + /** * @author Robert von Burg */ diff --git a/src/main/java/li/strolch/model/ResourceVisitor.java b/src/main/java/li/strolch/model/ResourceVisitor.java index db8c78ba2..e96909b97 100644 --- a/src/main/java/li/strolch/model/ResourceVisitor.java +++ b/src/main/java/li/strolch/model/ResourceVisitor.java @@ -15,6 +15,8 @@ */ package li.strolch.model; +import li.strolch.model.visitor.StrolchElementVisitor; + /** * @author Robert von Burg */ diff --git a/src/main/java/li/strolch/model/parameter/AbstractParameter.java b/src/main/java/li/strolch/model/parameter/AbstractParameter.java index 9875dff0b..bec460d3c 100644 --- a/src/main/java/li/strolch/model/parameter/AbstractParameter.java +++ b/src/main/java/li/strolch/model/parameter/AbstractParameter.java @@ -21,6 +21,7 @@ import li.strolch.exception.StrolchException; import li.strolch.model.AbstractStrolchElement; import li.strolch.model.Locator; import li.strolch.model.Locator.LocatorBuilder; +import li.strolch.model.visitor.ParameterVisitor; import li.strolch.model.ParameterizedElement; import li.strolch.model.Tags; @@ -163,12 +164,12 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem setInterpretation(interpretation); setUom(uom); - if(StringHelper.isEmpty(index)) { + if (StringHelper.isEmpty(index)) { this.index = 0; } else { this.index = Integer.valueOf(index); } - + if (StringHelper.isEmpty(hidden)) { setHidden(false); } else { @@ -228,6 +229,11 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem clone.setIndex(this.index); } + @Override + public U accept(ParameterVisitor visitor) { + return visitor.visitParam(this); + } + @SuppressWarnings("nls") @Override public String toString() { diff --git a/src/main/java/li/strolch/model/parameter/BooleanParameter.java b/src/main/java/li/strolch/model/parameter/BooleanParameter.java index 57b56117c..ea380dc5e 100644 --- a/src/main/java/li/strolch/model/parameter/BooleanParameter.java +++ b/src/main/java/li/strolch/model/parameter/BooleanParameter.java @@ -19,6 +19,7 @@ import java.text.MessageFormat; import li.strolch.exception.StrolchException; import li.strolch.model.Tags; +import li.strolch.model.visitor.ParameterVisitor; import org.w3c.dom.Element; @@ -102,6 +103,11 @@ public class BooleanParameter extends AbstractParameter { return clone; } + @Override + public U accept(ParameterVisitor visitor) { + return visitor.visitBooleanParam(this); + } + public static Boolean parseFromString(String valueS) { return Boolean.valueOf(valueS); } diff --git a/src/main/java/li/strolch/model/parameter/DateParameter.java b/src/main/java/li/strolch/model/parameter/DateParameter.java index dcf3da983..86f19f2ad 100644 --- a/src/main/java/li/strolch/model/parameter/DateParameter.java +++ b/src/main/java/li/strolch/model/parameter/DateParameter.java @@ -20,6 +20,7 @@ import java.util.Date; import li.strolch.exception.StrolchException; import li.strolch.model.Tags; +import li.strolch.model.visitor.ParameterVisitor; import org.w3c.dom.Element; @@ -104,6 +105,11 @@ public class DateParameter extends AbstractParameter { return clone; } + @Override + public U accept(ParameterVisitor visitor) { + return visitor.visitDateParam(this); + } + public static Date parseFromString(String valueS) { return ISO8601FormatFactory.getInstance().getDateFormat().parse(valueS); } diff --git a/src/main/java/li/strolch/model/parameter/FloatParameter.java b/src/main/java/li/strolch/model/parameter/FloatParameter.java index f6dd5071f..7d322dc56 100644 --- a/src/main/java/li/strolch/model/parameter/FloatParameter.java +++ b/src/main/java/li/strolch/model/parameter/FloatParameter.java @@ -19,6 +19,7 @@ import java.text.MessageFormat; import li.strolch.exception.StrolchException; import li.strolch.model.Tags; +import li.strolch.model.visitor.ParameterVisitor; import org.w3c.dom.Element; @@ -103,7 +104,12 @@ public class FloatParameter extends AbstractParameter { return clone; } - + + @Override + public U accept(ParameterVisitor visitor) { + return visitor.visitFloatParam(this); + } + public static Double parseFromString(String valueS) { return Double.valueOf(valueS); } diff --git a/src/main/java/li/strolch/model/parameter/IntegerParameter.java b/src/main/java/li/strolch/model/parameter/IntegerParameter.java index 428e96dcb..a1db56027 100644 --- a/src/main/java/li/strolch/model/parameter/IntegerParameter.java +++ b/src/main/java/li/strolch/model/parameter/IntegerParameter.java @@ -19,6 +19,7 @@ import java.text.MessageFormat; import li.strolch.exception.StrolchException; import li.strolch.model.Tags; +import li.strolch.model.visitor.ParameterVisitor; import org.w3c.dom.Element; @@ -103,6 +104,11 @@ public class IntegerParameter extends AbstractParameter { return clone; } + @Override + public U accept(ParameterVisitor visitor) { + return visitor.visitIntegerParam(this); + } + public static Integer parseFromString(String valueS) { return Integer.valueOf(valueS); } diff --git a/src/main/java/li/strolch/model/parameter/LongParameter.java b/src/main/java/li/strolch/model/parameter/LongParameter.java index 9c445ccb1..42573a443 100644 --- a/src/main/java/li/strolch/model/parameter/LongParameter.java +++ b/src/main/java/li/strolch/model/parameter/LongParameter.java @@ -19,6 +19,7 @@ import java.text.MessageFormat; import li.strolch.exception.StrolchException; import li.strolch.model.Tags; +import li.strolch.model.visitor.ParameterVisitor; import org.w3c.dom.Element; @@ -103,6 +104,11 @@ public class LongParameter extends AbstractParameter { return clone; } + @Override + public U accept(ParameterVisitor visitor) { + return visitor.visitLongParam(this); + } + public static Long parseFromString(String valueS) { return Long.valueOf(valueS); } diff --git a/src/main/java/li/strolch/model/parameter/Parameter.java b/src/main/java/li/strolch/model/parameter/Parameter.java index 2b8c37014..71bb27f4e 100644 --- a/src/main/java/li/strolch/model/parameter/Parameter.java +++ b/src/main/java/li/strolch/model/parameter/Parameter.java @@ -19,6 +19,7 @@ import li.strolch.model.Order; import li.strolch.model.ParameterizedElement; import li.strolch.model.Resource; import li.strolch.model.StrolchElement; +import li.strolch.model.visitor.ParameterVisitor; /** * @author Robert von Burg @@ -158,4 +159,6 @@ public interface Parameter extends StrolchElement { @Override public Parameter getClone(); + + public U accept(ParameterVisitor visitor); } diff --git a/src/main/java/li/strolch/model/parameter/StringListParameter.java b/src/main/java/li/strolch/model/parameter/StringListParameter.java index 65fc6556e..0f7722076 100644 --- a/src/main/java/li/strolch/model/parameter/StringListParameter.java +++ b/src/main/java/li/strolch/model/parameter/StringListParameter.java @@ -24,6 +24,7 @@ import java.util.List; import li.strolch.exception.StrolchException; import li.strolch.model.Tags; +import li.strolch.model.visitor.ParameterVisitor; import org.w3c.dom.Element; @@ -134,6 +135,11 @@ public class StringListParameter extends AbstractParameter> impleme return clone; } + @Override + public U accept(ParameterVisitor visitor) { + return visitor.visitStringListParam(this); + } + public static List parseFromString(String value) { if (value.isEmpty()) return Collections.emptyList(); diff --git a/src/main/java/li/strolch/model/parameter/StringParameter.java b/src/main/java/li/strolch/model/parameter/StringParameter.java index 5a0db74fa..262a57a09 100644 --- a/src/main/java/li/strolch/model/parameter/StringParameter.java +++ b/src/main/java/li/strolch/model/parameter/StringParameter.java @@ -19,6 +19,7 @@ import java.text.MessageFormat; import li.strolch.exception.StrolchException; import li.strolch.model.Tags; +import li.strolch.model.visitor.ParameterVisitor; import org.w3c.dom.Element; @@ -104,4 +105,9 @@ public class StringParameter extends AbstractParameter { return clone; } + + @Override + public U accept(ParameterVisitor visitor) { + return visitor.visitStringParam(this); + } } diff --git a/src/main/java/li/strolch/model/visitor/ParameterVisitor.java b/src/main/java/li/strolch/model/visitor/ParameterVisitor.java new file mode 100644 index 000000000..a4a914849 --- /dev/null +++ b/src/main/java/li/strolch/model/visitor/ParameterVisitor.java @@ -0,0 +1,50 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.visitor; + +import li.strolch.model.parameter.BooleanParameter; +import li.strolch.model.parameter.DateParameter; +import li.strolch.model.parameter.FloatParameter; +import li.strolch.model.parameter.IntegerParameter; +import li.strolch.model.parameter.ListParameter; +import li.strolch.model.parameter.LongParameter; +import li.strolch.model.parameter.Parameter; +import li.strolch.model.parameter.StringListParameter; +import li.strolch.model.parameter.StringParameter; + +/** + * @author Robert von Burg + */ +public interface ParameterVisitor { + + public T visitParam(Parameter param); + + public T visitBooleanParam(BooleanParameter param); + + public T visitDateParam(DateParameter param); + + public T visitFloatParam(FloatParameter param); + + public T visitIntegerParam(IntegerParameter param); + + public T visitLongParam(LongParameter param); + + public T visitStringParam(StringParameter param); + + public T visitListParam(ListParameter param); + + public T visitStringListParam(StringListParameter param); +} diff --git a/src/main/java/li/strolch/model/visitor/SetParameterValueVisitor.java b/src/main/java/li/strolch/model/visitor/SetParameterValueVisitor.java new file mode 100644 index 000000000..c31bd6718 --- /dev/null +++ b/src/main/java/li/strolch/model/visitor/SetParameterValueVisitor.java @@ -0,0 +1,96 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.visitor; + +import li.strolch.model.parameter.BooleanParameter; +import li.strolch.model.parameter.DateParameter; +import li.strolch.model.parameter.FloatParameter; +import li.strolch.model.parameter.IntegerParameter; +import li.strolch.model.parameter.ListParameter; +import li.strolch.model.parameter.LongParameter; +import li.strolch.model.parameter.Parameter; +import li.strolch.model.parameter.StringListParameter; +import li.strolch.model.parameter.StringParameter; + +/** + * @author Robert von Burg + */ +public class SetParameterValueVisitor implements ParameterVisitor { + + private String value; + + public void setValue(Parameter parameter, String value) { + this.value = value; + try { + parameter.accept(this); + } finally { + this.value = null; + } + } + + @Override + public T visitParam(Parameter param) { + throw new UnsupportedOperationException("Not implemented on " + param.getClass()); + } + + @Override + public T visitListParam(ListParameter param) { + throw new UnsupportedOperationException("Not implemented on " + param.getClass()); + } + + @Override + public T visitBooleanParam(BooleanParameter param) { + param.setValue(BooleanParameter.parseFromString(this.value)); + return null; + } + + @Override + public T visitDateParam(DateParameter param) { + param.setValue(DateParameter.parseFromString(this.value)); + return null; + } + + @Override + public T visitFloatParam(FloatParameter param) { + param.setValue(FloatParameter.parseFromString(this.value)); + return null; + } + + @Override + public T visitIntegerParam(IntegerParameter param) { + param.setValue(IntegerParameter.parseFromString(this.value)); + return null; + } + + @Override + public T visitLongParam(LongParameter param) { + param.setValue(LongParameter.parseFromString(this.value)); + return null; + } + + @Override + public T visitStringParam(StringParameter param) { + param.setValue(this.value); + return null; + } + + @Override + public T visitStringListParam(StringListParameter param) { + param.setValue(StringListParameter.parseFromString(this.value)); + return null; + } + +} diff --git a/src/main/java/li/strolch/model/StrolchElementVisitor.java b/src/main/java/li/strolch/model/visitor/StrolchElementVisitor.java similarity index 91% rename from src/main/java/li/strolch/model/StrolchElementVisitor.java rename to src/main/java/li/strolch/model/visitor/StrolchElementVisitor.java index 605f3014f..93a9c5014 100644 --- a/src/main/java/li/strolch/model/StrolchElementVisitor.java +++ b/src/main/java/li/strolch/model/visitor/StrolchElementVisitor.java @@ -13,7 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package li.strolch.model; +package li.strolch.model.visitor; + +import li.strolch.model.StrolchElement; /** * @author Robert von Burg From 791f12eef3c8260d1e7802f01652485053613982 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 13 Feb 2014 22:17:02 +0100 Subject: [PATCH 53/88] [Bugfix] fixed bug where Locator was not complete for Parameters --- src/main/java/li/strolch/model/ParameterizedElement.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/li/strolch/model/ParameterizedElement.java b/src/main/java/li/strolch/model/ParameterizedElement.java index aff782c3e..ac8acde17 100644 --- a/src/main/java/li/strolch/model/ParameterizedElement.java +++ b/src/main/java/li/strolch/model/ParameterizedElement.java @@ -201,6 +201,7 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { @Override public void fillLocator(LocatorBuilder lb) { + this.parent.fillLocator(lb); lb.append(this.id); } From 205c4b967dde24ee620b0315dc7345c0fe24d9b4 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 13 Feb 2014 22:18:01 +0100 Subject: [PATCH 54/88] [Minor] added sorting of exports XML model - Parameters are sorted by Index - ParameterBags are sorted by Id --- .../model/xml/AbstractToSaxWriterVisitor.java | 20 +++++++++++++------ .../strolch/model/xml/XmlModelSaxReader.java | 18 +++++++++++++++++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java b/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java index ee3a27a53..36d5088da 100644 --- a/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java +++ b/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java @@ -15,7 +15,12 @@ */ package li.strolch.model.xml; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; import java.util.Set; +import java.util.TreeSet; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; @@ -63,10 +68,14 @@ public abstract class AbstractToSaxWriterVisitor { protected void writeParameters(ParameterizedElement element) throws XMLStreamException { - Set parameterKeySet = element.getParameterKeySet(); - for (String paramKey : parameterKeySet) { - Parameter parameter = element.getParameter(paramKey); - + List> parameters = new ArrayList<>(element.getParameters()); + Collections.sort(parameters, new Comparator>() { + @Override + public int compare(Parameter o1, Parameter o2) { + return Integer.valueOf(o1.getIndex()).compareTo(o2.getIndex()); + } + }); + for (Parameter parameter : parameters) { writeStartStrolchElement(Tags.PARAMETER, true, parameter); if (!Parameter.INTERPRETATION_NONE.equals(parameter.getInterpretation())) @@ -83,8 +92,7 @@ public abstract class AbstractToSaxWriterVisitor { } protected void writeParameterBags(GroupedParameterizedElement element) throws XMLStreamException { - - Set bagKeySet = element.getParameterBagKeySet(); + Set bagKeySet = new TreeSet<>(element.getParameterBagKeySet()); for (String bagKey : bagKeySet) { ParameterBag parameterBag = element.getParameterBag(bagKey); boolean isEmpty = !parameterBag.hasParameters(); diff --git a/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java b/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java index ec4849e97..cca74afa0 100644 --- a/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java +++ b/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java @@ -15,6 +15,8 @@ */ package li.strolch.model.xml; +import static ch.eitchnet.utils.helper.StringHelper.NULL; + import java.text.MessageFormat; import java.util.Date; @@ -196,5 +198,21 @@ public class XmlModelSaxReader extends DefaultHandler { public long durationNanos; public int nrOfResources; public int nrOfOrders; + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("XmlModelStatistics [startTime="); + builder.append(this.startTime == null ? NULL : ISO8601FormatFactory.getInstance() + .formatDate(this.startTime)); + builder.append(", durationNanos="); + builder.append(StringHelper.formatNanoDuration(this.durationNanos)); + builder.append(", nrOfResources="); + builder.append(this.nrOfResources); + builder.append(", nrOfOrders="); + builder.append(this.nrOfOrders); + builder.append("]"); + return builder.toString(); + } } } From 7147bc15709f718c9ab87d3f06498eb9cdfa3a6d Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 24 Feb 2014 21:48:53 +0100 Subject: [PATCH 55/88] [New] added a new StrolchRootElement interface for Resource and Order --- src/main/java/li/strolch/model/Order.java | 5 ++-- src/main/java/li/strolch/model/Resource.java | 2 +- .../li/strolch/model/StrolchRootElement.java | 27 +++++++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 src/main/java/li/strolch/model/StrolchRootElement.java diff --git a/src/main/java/li/strolch/model/Order.java b/src/main/java/li/strolch/model/Order.java index feec6abc5..51026960a 100644 --- a/src/main/java/li/strolch/model/Order.java +++ b/src/main/java/li/strolch/model/Order.java @@ -33,10 +33,9 @@ import ch.eitchnet.utils.iso8601.ISO8601FormatFactory; * In this sense, orders do not need to be verified, so all verifier chracteristics are disabled and the * getVerifier()-method will return the null reference * - * @author eitch - * + * @author Robert von Burg */ -public class Order extends GroupedParameterizedElement { +public class Order extends GroupedParameterizedElement implements StrolchRootElement { private static final long serialVersionUID = 0L; diff --git a/src/main/java/li/strolch/model/Resource.java b/src/main/java/li/strolch/model/Resource.java index 7a86483d8..f33964b49 100644 --- a/src/main/java/li/strolch/model/Resource.java +++ b/src/main/java/li/strolch/model/Resource.java @@ -23,7 +23,7 @@ import org.w3c.dom.Element; /** * @author Robert von Burg */ -public class Resource extends GroupedParameterizedElement { +public class Resource extends GroupedParameterizedElement implements StrolchRootElement { private static final long serialVersionUID = 0L; diff --git a/src/main/java/li/strolch/model/StrolchRootElement.java b/src/main/java/li/strolch/model/StrolchRootElement.java new file mode 100644 index 000000000..37699c783 --- /dev/null +++ b/src/main/java/li/strolch/model/StrolchRootElement.java @@ -0,0 +1,27 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model; + +/** + * Root element for all top level {@link StrolchElement}. These are elements which have no parent, e.g. {@link Resource + * Resources} and {@link Order Orders} + * + * @author Robert von Burg + */ +public interface StrolchRootElement extends StrolchElement { + + // marker interface +} From d15d163ebfd403caa861e45c9427baf65d17d638 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 26 Feb 2014 20:37:42 +0100 Subject: [PATCH 56/88] [New] Added New StrolchElementVisitor for StrolchRootElement Also added getParent() and getRootElement() on StrolchElement --- src/main/java/li/strolch/model/Order.java | 16 ++++++++ .../strolch/model/ParameterizedElement.java | 39 ++++++++++--------- src/main/java/li/strolch/model/Resource.java | 16 ++++++++ .../java/li/strolch/model/StrolchElement.java | 4 ++ .../li/strolch/model/StrolchRootElement.java | 4 +- .../model/parameter/AbstractParameter.java | 8 +++- .../model/visitor/StrolchElementVisitor.java | 2 +- .../visitor/StrolchRootElementVisitor.java | 29 ++++++++++++++ .../strolch/model/visitor/StrolchVisitor.java | 26 +++++++++++++ 9 files changed, 122 insertions(+), 22 deletions(-) create mode 100644 src/main/java/li/strolch/model/visitor/StrolchRootElementVisitor.java create mode 100644 src/main/java/li/strolch/model/visitor/StrolchVisitor.java diff --git a/src/main/java/li/strolch/model/Order.java b/src/main/java/li/strolch/model/Order.java index 51026960a..38bf665db 100644 --- a/src/main/java/li/strolch/model/Order.java +++ b/src/main/java/li/strolch/model/Order.java @@ -18,6 +18,7 @@ package li.strolch.model; import java.util.Date; import li.strolch.model.Locator.LocatorBuilder; +import li.strolch.model.visitor.StrolchRootElementVisitor; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -169,6 +170,21 @@ public class Order extends GroupedParameterizedElement implements StrolchRootEle return lb.build(); } + @Override + public StrolchElement getParent() { + return null; + } + + @Override + public Order getRootElement() { + return this; + } + + @Override + public T accept(StrolchRootElementVisitor visitor) { + return visitor.visitOrder(this); + } + @SuppressWarnings("nls") @Override public String toString() { diff --git a/src/main/java/li/strolch/model/ParameterizedElement.java b/src/main/java/li/strolch/model/ParameterizedElement.java index ac8acde17..5f1d6e72e 100644 --- a/src/main/java/li/strolch/model/ParameterizedElement.java +++ b/src/main/java/li/strolch/model/ParameterizedElement.java @@ -92,25 +92,6 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { this.type = type; } - /** - * Returns this {@link ParameterizedElement}'s parent - * - * @return the parent - */ - public GroupedParameterizedElement getParent() { - return this.parent; - } - - /** - * Set the parent for this {@link ParameterizedElement} - * - * @param parent - * the parent to set - */ - public void setParent(GroupedParameterizedElement parent) { - this.parent = parent; - } - /** * Returns the {@link Parameter} with the given id, or null if it does not exist * @@ -278,6 +259,26 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { } } + @Override + public GroupedParameterizedElement getParent() { + return this.parent; + } + + /** + * Set the parent for this {@link ParameterizedElement} + * + * @param parent + * the parent to set + */ + public void setParent(GroupedParameterizedElement parent) { + this.parent = parent; + } + + @Override + public StrolchRootElement getRootElement() { + return this.parent.getRootElement(); + } + @SuppressWarnings("nls") @Override public String toString() { diff --git a/src/main/java/li/strolch/model/Resource.java b/src/main/java/li/strolch/model/Resource.java index f33964b49..11fe1cb57 100644 --- a/src/main/java/li/strolch/model/Resource.java +++ b/src/main/java/li/strolch/model/Resource.java @@ -16,6 +16,7 @@ package li.strolch.model; import li.strolch.model.Locator.LocatorBuilder; +import li.strolch.model.visitor.StrolchRootElementVisitor; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -84,6 +85,21 @@ public class Resource extends GroupedParameterizedElement implements StrolchRoot return lb.build(); } + @Override + public StrolchElement getParent() { + return null; + } + + @Override + public Resource getRootElement() { + return this; + } + + @Override + public T accept(StrolchRootElementVisitor visitor) { + return visitor.visitResource(this); + } + @SuppressWarnings("nls") @Override public String toString() { diff --git a/src/main/java/li/strolch/model/StrolchElement.java b/src/main/java/li/strolch/model/StrolchElement.java index 261e7b4bd..e556f42e2 100644 --- a/src/main/java/li/strolch/model/StrolchElement.java +++ b/src/main/java/li/strolch/model/StrolchElement.java @@ -94,6 +94,10 @@ public interface StrolchElement extends Serializable, Comparable */ public String getType(); + public StrolchElement getParent(); + + public StrolchRootElement getRootElement(); + /** * Return a clone of this {@link StrolchElement} * diff --git a/src/main/java/li/strolch/model/StrolchRootElement.java b/src/main/java/li/strolch/model/StrolchRootElement.java index 37699c783..265cd185d 100644 --- a/src/main/java/li/strolch/model/StrolchRootElement.java +++ b/src/main/java/li/strolch/model/StrolchRootElement.java @@ -15,6 +15,8 @@ */ package li.strolch.model; +import li.strolch.model.visitor.StrolchRootElementVisitor; + /** * Root element for all top level {@link StrolchElement}. These are elements which have no parent, e.g. {@link Resource * Resources} and {@link Order Orders} @@ -23,5 +25,5 @@ package li.strolch.model; */ public interface StrolchRootElement extends StrolchElement { - // marker interface + public T accept(StrolchRootElementVisitor visitor); } diff --git a/src/main/java/li/strolch/model/parameter/AbstractParameter.java b/src/main/java/li/strolch/model/parameter/AbstractParameter.java index bec460d3c..7bcd7b324 100644 --- a/src/main/java/li/strolch/model/parameter/AbstractParameter.java +++ b/src/main/java/li/strolch/model/parameter/AbstractParameter.java @@ -21,9 +21,10 @@ import li.strolch.exception.StrolchException; import li.strolch.model.AbstractStrolchElement; import li.strolch.model.Locator; import li.strolch.model.Locator.LocatorBuilder; -import li.strolch.model.visitor.ParameterVisitor; import li.strolch.model.ParameterizedElement; +import li.strolch.model.StrolchRootElement; import li.strolch.model.Tags; +import li.strolch.model.visitor.ParameterVisitor; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -121,6 +122,11 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem this.parent = parent; } + @Override + public StrolchRootElement getRootElement() { + return this.parent.getRootElement(); + } + @Override public Element toDom(Document doc) { Element element = doc.createElement(Tags.PARAMETER); diff --git a/src/main/java/li/strolch/model/visitor/StrolchElementVisitor.java b/src/main/java/li/strolch/model/visitor/StrolchElementVisitor.java index 93a9c5014..9034a0c77 100644 --- a/src/main/java/li/strolch/model/visitor/StrolchElementVisitor.java +++ b/src/main/java/li/strolch/model/visitor/StrolchElementVisitor.java @@ -20,7 +20,7 @@ import li.strolch.model.StrolchElement; /** * @author Robert von Burg */ -public interface StrolchElementVisitor { +public interface StrolchElementVisitor extends StrolchVisitor { public void visit(T element); } diff --git a/src/main/java/li/strolch/model/visitor/StrolchRootElementVisitor.java b/src/main/java/li/strolch/model/visitor/StrolchRootElementVisitor.java new file mode 100644 index 000000000..c75f5a107 --- /dev/null +++ b/src/main/java/li/strolch/model/visitor/StrolchRootElementVisitor.java @@ -0,0 +1,29 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.visitor; + +import li.strolch.model.Order; +import li.strolch.model.Resource; + +/** + * @author Robert von Burg + */ +public interface StrolchRootElementVisitor extends StrolchVisitor { + + public T visitOrder(Order order); + + public T visitResource(Resource resource); +} diff --git a/src/main/java/li/strolch/model/visitor/StrolchVisitor.java b/src/main/java/li/strolch/model/visitor/StrolchVisitor.java new file mode 100644 index 000000000..aa58cfca9 --- /dev/null +++ b/src/main/java/li/strolch/model/visitor/StrolchVisitor.java @@ -0,0 +1,26 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.visitor; + +/** + * Marker interface to allow to quickly see the visitor implementations in Strolch + * + * @author Robert von Burg + */ +public interface StrolchVisitor { + + // marker interface +} From 0dae330e72260fe77964d270d50c13fdefb6ce41 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 3 Mar 2014 23:32:33 +0100 Subject: [PATCH 57/88] [Major] Multiple issues - setId() and setName() don't allow empty values - added Locator.newBuilder(String) - fixed wrong locator created by ParameterizedElement - Better exception handling when parsing from XML as Sax --- .../strolch/model/AbstractStrolchElement.java | 18 +++-- src/main/java/li/strolch/model/Locator.java | 12 +++ .../strolch/model/ParameterizedElement.java | 1 - .../model/xml/ResourceToSaxVisitor.java | 3 +- .../strolch/model/xml/XmlModelSaxReader.java | 77 ++++++++++--------- 5 files changed, 67 insertions(+), 44 deletions(-) diff --git a/src/main/java/li/strolch/model/AbstractStrolchElement.java b/src/main/java/li/strolch/model/AbstractStrolchElement.java index 0718f538d..a2d4c000a 100644 --- a/src/main/java/li/strolch/model/AbstractStrolchElement.java +++ b/src/main/java/li/strolch/model/AbstractStrolchElement.java @@ -22,6 +22,8 @@ import li.strolch.model.Locator.LocatorBuilder; import org.w3c.dom.Element; +import ch.eitchnet.utils.helper.StringHelper; + /** * @author Robert von Burg */ @@ -70,12 +72,11 @@ public abstract class AbstractStrolchElement implements StrolchElement { @Override public void setId(String id) { - if (id == null) - throw new StrolchException("The id may never be null"); //$NON-NLS-1$ - - if (id.isEmpty()) - throw new StrolchException("The id may never be empty"); //$NON-NLS-1$ - + if (StringHelper.isEmpty(id)) { + String msg = "The id may never be empty for {0}"; + msg = MessageFormat.format(msg, getClass().getSimpleName()); + throw new StrolchException(msg); + } this.id = id; } @@ -86,6 +87,11 @@ public abstract class AbstractStrolchElement implements StrolchElement { @Override public void setName(String name) { + if (StringHelper.isEmpty(name)) { + String msg = "The name may never be empty for {0} with id {1}"; + msg = MessageFormat.format(msg, getClass().getSimpleName(), id); + throw new StrolchException(msg); + } this.name = name; } diff --git a/src/main/java/li/strolch/model/Locator.java b/src/main/java/li/strolch/model/Locator.java index 31f50528c..9e4a5e3e9 100644 --- a/src/main/java/li/strolch/model/Locator.java +++ b/src/main/java/li/strolch/model/Locator.java @@ -243,6 +243,18 @@ public class Locator { return new Locator(locatorPath); } + /** + * Creates a new {@link LocatorBuilder} instance and appends the given root element tag to it + * + * @param rootElement + * the first element on the {@link Locator} + * + * @return a new {@link LocatorBuilder} instance with the given root element tag as the first element + */ + public static LocatorBuilder newBuilder(String rootElement) { + return new LocatorBuilder().append(rootElement); + } + /** * {@link LocatorBuilder} is used to build {@link Locator}s where a deep hierarchy is to be created. The * {@link #append(String)} method returns itself for chain building diff --git a/src/main/java/li/strolch/model/ParameterizedElement.java b/src/main/java/li/strolch/model/ParameterizedElement.java index 5f1d6e72e..30b2f4c20 100644 --- a/src/main/java/li/strolch/model/ParameterizedElement.java +++ b/src/main/java/li/strolch/model/ParameterizedElement.java @@ -189,7 +189,6 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { @Override public Locator getLocator() { LocatorBuilder lb = new LocatorBuilder(); - this.parent.fillLocator(lb); fillLocator(lb); return lb.build(); } diff --git a/src/main/java/li/strolch/model/xml/ResourceToSaxVisitor.java b/src/main/java/li/strolch/model/xml/ResourceToSaxVisitor.java index 3bafed894..5e10dab32 100644 --- a/src/main/java/li/strolch/model/xml/ResourceToSaxVisitor.java +++ b/src/main/java/li/strolch/model/xml/ResourceToSaxVisitor.java @@ -22,7 +22,6 @@ import li.strolch.model.ResourceVisitor; import li.strolch.model.Tags; import org.xml.sax.ContentHandler; -import org.xml.sax.SAXException; /** * @author Robert von Burg @@ -41,7 +40,7 @@ public class ResourceToSaxVisitor extends StrolchElementToDomVisitor implements toSax(res); this.contentHandler.endElement(null, null, Tags.RESOURCE); - } catch (SAXException e) { + } catch (Exception e) { String msg = "Failed to transform Resource {0} to XML due to {1}"; //$NON-NLS-1$ msg = MessageFormat.format(msg, res.getLocator(), e.getMessage()); throw new RuntimeException(msg, e); diff --git a/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java b/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java index cca74afa0..a1efba98b 100644 --- a/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java +++ b/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java @@ -20,6 +20,7 @@ import static ch.eitchnet.utils.helper.StringHelper.NULL; import java.text.MessageFormat; import java.util.Date; +import li.strolch.exception.StrolchException; import li.strolch.model.GroupedParameterizedElement; import li.strolch.model.Order; import li.strolch.model.ParameterBag; @@ -122,42 +123,48 @@ public class XmlModelSaxReader extends DefaultHandler { String paramValue = attributes.getValue(Tags.VALUE); String paramHiddenS = attributes.getValue(Tags.HIDDEN); String paramIndexS = attributes.getValue(Tags.INDEX); - int index = StringHelper.isEmpty(paramIndexS) ? 0 : Integer.valueOf(paramIndexS); - boolean paramHidden = StringHelper.isEmpty(paramHiddenS) ? false : StringHelper.parseBoolean(paramHiddenS); - String paramUom = attributes.getValue(Tags.UOM); - String paramInterpretation = attributes.getValue(Tags.INTERPRETATION); - Parameter param; - switch (paramType) { - case StringParameter.TYPE: - param = new StringParameter(paramId, paramName, paramValue); - break; - case IntegerParameter.TYPE: - param = new IntegerParameter(paramId, paramName, IntegerParameter.parseFromString(paramValue)); - break; - case BooleanParameter.TYPE: - param = new BooleanParameter(paramId, paramName, BooleanParameter.parseFromString(paramValue)); - break; - case LongParameter.TYPE: - param = new LongParameter(paramId, paramName, LongParameter.parseFromString(paramValue)); - break; - case DateParameter.TYPE: - param = new DateParameter(paramId, paramName, DateParameter.parseFromString(paramValue)); - break; - case StringListParameter.TYPE: - param = new StringListParameter(paramId, paramName, StringListParameter.parseFromString(paramValue)); - break; - case FloatParameter.TYPE: - param = new FloatParameter(paramId, paramName, FloatParameter.parseFromString(paramValue)); - break; - default: - throw new UnsupportedOperationException(MessageFormat.format( - "Parameters of type {0} are not supported!", paramType)); //$NON-NLS-1$ + try { + int index = StringHelper.isEmpty(paramIndexS) ? 0 : Integer.valueOf(paramIndexS); + boolean paramHidden = StringHelper.isEmpty(paramHiddenS) ? false : StringHelper + .parseBoolean(paramHiddenS); + String paramUom = attributes.getValue(Tags.UOM); + String paramInterpretation = attributes.getValue(Tags.INTERPRETATION); + Parameter param; + switch (paramType) { + case StringParameter.TYPE: + param = new StringParameter(paramId, paramName, paramValue); + break; + case IntegerParameter.TYPE: + param = new IntegerParameter(paramId, paramName, IntegerParameter.parseFromString(paramValue)); + break; + case BooleanParameter.TYPE: + param = new BooleanParameter(paramId, paramName, BooleanParameter.parseFromString(paramValue)); + break; + case LongParameter.TYPE: + param = new LongParameter(paramId, paramName, LongParameter.parseFromString(paramValue)); + break; + case DateParameter.TYPE: + param = new DateParameter(paramId, paramName, DateParameter.parseFromString(paramValue)); + break; + case StringListParameter.TYPE: + param = new StringListParameter(paramId, paramName, StringListParameter.parseFromString(paramValue)); + break; + case FloatParameter.TYPE: + param = new FloatParameter(paramId, paramName, FloatParameter.parseFromString(paramValue)); + break; + default: + throw new UnsupportedOperationException(MessageFormat.format( + "Parameters of type {0} are not supported!", paramType)); //$NON-NLS-1$ + } + param.setHidden(paramHidden); + param.setUom(paramUom); + param.setInterpretation(paramInterpretation); + param.setIndex(index); + this.pBag.addParameter(param); + } catch (Exception e) { + throw new StrolchException("Failed to instantiate parameter " + paramId + " for bag " + + this.pBag.getLocator() + " due to " + e.getMessage(), e); } - param.setHidden(paramHidden); - param.setUom(paramUom); - param.setInterpretation(paramInterpretation); - param.setIndex(index); - this.pBag.addParameter(param); break; default: From 66415dea5fc6af0a47ced641031ed047de14eebd Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 14 Mar 2014 14:36:39 +0100 Subject: [PATCH 58/88] [Project] fixed urls of projects --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 0d807046c..4ad96cef0 100644 --- a/pom.xml +++ b/pom.xml @@ -12,19 +12,19 @@ li.strolch.model jar li.strolch.model - https://github.com/eitch/li.strolch.model + https://github.com/eitchnet/li.strolch.model 2012 Github Issues - https://github.com/eitch/li.strolch.model/issues + https://github.com/eitchnet/li.strolch.model/issues - scm:git:https://github.com/eitch/li.strolch.model.git + scm:git:https://github.com/eitchnet/li.strolch.model.git scm:git:git@github.com:eitch/li.strolch.model.git - https://github.com/eitch/li.strolch.model + https://github.com/eitchnet/li.strolch.model From 7ca7bc7ca793473c145015a7519176265bc9e7f1 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 24 Mar 2014 15:02:58 +0100 Subject: [PATCH 59/88] [New] TimedStates are now properly incorporated into the Strolch Model The TimedStates have been added to Resources and can be added, removed and retrieved using the following methods: - addTimedState(StrolchTimedState):void - removeTimedState(String): - getTimedState(String): - getTimedStates():List> - hasTimedState(String):boolean Also created a new Boolean StateVariables type The TimedStates are added to Resources using the StrolchTimedState interface and there is a concrete implementation for each type: - BooleanTimedState - IntegerTimedState - FloatTimedState - StringSetTimedState Each timed state is tested in a unit test Each timed state is (de)serializable from/to XML --- .../java/li/strolch/model/ModelGenerator.java | 472 +++++++++++------- .../strolch/model/ParameterizedElement.java | 443 ++++++++-------- src/main/java/li/strolch/model/Resource.java | 243 ++++++--- src/main/java/li/strolch/model/Tags.java | 2 + .../model/parameter/AbstractParameter.java | 2 +- .../timedstate/AbstractStrolchTimedState.java | 127 +++++ .../model/timedstate/BooleanTimedState.java | 88 ++++ .../model/timedstate/FloatTimedState.java | 88 ++++ .../strolch/model/timedstate/ITimedState.java | 6 +- .../model/timedstate/IntegerTimedState.java | 88 ++++ .../model/timedstate/StringSetTimedState.java | 111 ++++ .../model/timedstate/StrolchTimedState.java | 42 ++ .../strolch/model/timedstate/TimedState.java | 10 +- .../strolch/model/timevalue/ITimeValue.java | 1 + .../model/timevalue/ITimeVariable.java | 28 +- .../li/strolch/model/timevalue/IValue.java | 2 - .../model/timevalue/impl/BooleanValue.java | 108 ++++ .../{DoubleValue.java => FloatValue.java} | 26 +- .../model/timevalue/impl/StringSetValue.java | 132 ++--- .../model/timevalue/impl/TimeValue.java | 7 +- .../model/timevalue/impl/TimeVariable.java | 18 +- .../StrolchElementDeepEqualsVisitor.java | 231 +++++---- src/test/java/li/strolch/model/ModelTest.java | 168 ++++--- .../java/li/strolch/model/XmlToDomTest.java | 56 ++- .../timedstate/StrolchTimedStateTest.java | 117 +++++ .../model/timedstate/TimeStateTest.java | 22 +- .../timevalue/FloatTimeVariableTest.java | 48 +- .../strolch/model/timevalue/ValueTests.java | 6 +- 28 files changed, 1876 insertions(+), 816 deletions(-) create mode 100644 src/main/java/li/strolch/model/timedstate/AbstractStrolchTimedState.java create mode 100644 src/main/java/li/strolch/model/timedstate/BooleanTimedState.java create mode 100644 src/main/java/li/strolch/model/timedstate/FloatTimedState.java create mode 100644 src/main/java/li/strolch/model/timedstate/IntegerTimedState.java create mode 100644 src/main/java/li/strolch/model/timedstate/StringSetTimedState.java create mode 100644 src/main/java/li/strolch/model/timedstate/StrolchTimedState.java create mode 100644 src/main/java/li/strolch/model/timevalue/impl/BooleanValue.java rename src/main/java/li/strolch/model/timevalue/impl/{DoubleValue.java => FloatValue.java} (79%) create mode 100644 src/test/java/li/strolch/model/timedstate/StrolchTimedStateTest.java diff --git a/src/main/java/li/strolch/model/ModelGenerator.java b/src/main/java/li/strolch/model/ModelGenerator.java index 3e6cf99f7..6808069cd 100644 --- a/src/main/java/li/strolch/model/ModelGenerator.java +++ b/src/main/java/li/strolch/model/ModelGenerator.java @@ -15,10 +15,13 @@ */ package li.strolch.model; +import ch.eitchnet.utils.helper.StringHelper; import java.util.ArrayList; import java.util.Date; +import java.util.HashSet; +import java.util.Iterator; import java.util.List; - +import java.util.Set; import li.strolch.model.parameter.BooleanParameter; import li.strolch.model.parameter.DateParameter; import li.strolch.model.parameter.FloatParameter; @@ -27,224 +30,319 @@ import li.strolch.model.parameter.LongParameter; import li.strolch.model.parameter.Parameter; import li.strolch.model.parameter.StringListParameter; import li.strolch.model.parameter.StringParameter; -import ch.eitchnet.utils.helper.StringHelper; +import li.strolch.model.timedstate.BooleanTimedState; +import li.strolch.model.timedstate.FloatTimedState; +import li.strolch.model.timedstate.IntegerTimedState; +import li.strolch.model.timedstate.StringSetTimedState; +import li.strolch.model.timedstate.StrolchTimedState; +import li.strolch.model.timevalue.impl.AString; +import li.strolch.model.timevalue.impl.BooleanValue; +import li.strolch.model.timevalue.impl.FloatValue; +import li.strolch.model.timevalue.impl.IntegerValue; +import li.strolch.model.timevalue.impl.StringSetValue; +import li.strolch.model.timevalue.impl.ValueChange; /** * Class which can be used to generate objects which implement {@link StrolchElement}. These generated classes can then * be used in test classes etc. - * + * * @author Robert von Burg */ @SuppressWarnings("nls") public class ModelGenerator { - public static final String PARAM_BOOLEAN_ID = "@param1"; - public static final String PARAM_BOOLEAN_NAME = "Boolean Param"; + public static final String PARAM_BOOLEAN_ID = "@param1"; + public static final String PARAM_BOOLEAN_NAME = "Boolean Param"; - public static final String PARAM_FLOAT_ID = "@param2"; - public static final String PARAM_FLOAT_NAME = "Float Param"; + public static final String PARAM_FLOAT_ID = "@param2"; + public static final String PARAM_FLOAT_NAME = "Float Param"; - public static final String PARAM_INTEGER_ID = "@param3"; - public static final String PARAM_INTEGER_NAME = "Integer Param"; + public static final String PARAM_INTEGER_ID = "@param3"; + public static final String PARAM_INTEGER_NAME = "Integer Param"; - public static final String PARAM_LONG_ID = "@param4"; - public static final String PARAM_LONG_NAME = "Long Param"; + public static final String PARAM_LONG_ID = "@param4"; + public static final String PARAM_LONG_NAME = "Long Param"; - public static final String PARAM_STRING_ID = "@param5"; - public static final String PARAM_STRING_NAME = "String Param"; + public static final String PARAM_STRING_ID = "@param5"; + public static final String PARAM_STRING_NAME = "String Param"; - public static final String PARAM_DATE_ID = "@param6"; - public static final String PARAM_DATE_NAME = "Date Param"; + public static final String PARAM_DATE_ID = "@param6"; + public static final String PARAM_DATE_NAME = "Date Param"; - public static final String PARAM_LIST_STRING_ID = "@param7"; - public static final String PARAM_LIST_STRING_NAME = "StringList Param"; + public static final String PARAM_LIST_STRING_ID = "@param7"; + public static final String PARAM_LIST_STRING_NAME = "StringList Param"; - public static final String BAG_ID = "@bag01"; - public static final String BAG_NAME = "Test Bag"; - public static final String BAG_TYPE = "TestBag"; + public static final String STATE_FLOAT_ID = "@state1"; + public static final String STATE_FLOAT_NAME = "Float State"; - /** - * Creates an {@link Resource} with the given values and adds a {@link ParameterBag} by calling - * {@link #createParameterBag(String, String, String)} - * - * @param id - * the id of the {@link Resource} - * @param name - * the name of the {@link Resource} - * @param type - * the type of the {@link Resource} - * - * @return the newly created {@link Resource} - */ - public static Resource createResource(String id, String name, String type) { - Resource resource = new Resource(id, name, type); - ParameterBag bag = createParameterBag(BAG_ID, BAG_NAME, BAG_TYPE); - resource.addParameterBag(bag); + public static final String STATE_INTEGER_ID = "@state2"; + public static final String STATE_INTEGER_NAME = "Float State"; - return resource; - } + public static final String STATE_STRING_ID = "@state3"; + public static final String STATE_STRING_NAME = "Float State"; - /** - * Creates a list of {@link Resource Resources} with the given values and adds a {@link ParameterBag} by calling - * {@link #createParameterBag(String, String, String)} - * - * @param idStart - * id range start - * @param count - * the number of elements to create - * @param idPrefix - * the prefix to generate IDs for the {@link Resource Resources} - * @param name - * the name of the {@link Resource} - * @param type - * the type of the {@link Resource} - * - * @return the list of newly created {@link Resource Resources} - */ - public static List createResources(int idStart, int count, String idPrefix, String name, String type) { - List resources = new ArrayList<>(); - for (int i = 0; i < count; i++) { - String id = StringHelper.normalizeLength(String.valueOf((i + idStart)), 8, true, '0'); - resources.add(createResource(idPrefix + "_" + id, name + " " + i, type)); - } - return resources; - } + public static final String STATE_BOOLEAN_ID = "@state4"; + public static final String STATE_BOOLEAN_NAME = "Float State"; - /** - * Creates an {@link Order} with the given values and adds a {@link ParameterBag} by calling - * {@link #createParameterBag(String, String, String)} - * - * @param id - * the id of the {@link Order} - * @param name - * the name of the {@link Order} - * @param type - * the type of the {@link Order} - * - * @return the newly created {@link Order} - */ - public static Order createOrder(String id, String name, String type) { - return createOrder(id, name, type, new Date(), State.CREATED); - } + public static final long STATE_TIME_0 = 0L; + public static final long STATE_TIME_10 = 10L; + public static final long STATE_TIME_20 = 20L; + public static final long STATE_TIME_30 = 30L; - /** - * Creates an {@link Order} with the given values and adds a {@link ParameterBag} by calling - * {@link #createParameterBag(String, String, String)} - * - * @param id - * the id of the {@link Order} - * @param name - * the name of the {@link Order} - * @param type - * the type of the {@link Order} - * @param date - * the date of the {@link Order} - * @param state - * the {@link State} of the {@link Order} - * - * @return the newly created {@link Order} - */ - public static Order createOrder(String id, String name, String type, Date date, State state) { + public static final Double STATE_FLOAT_TIME_0 = 0.0D; + public static final Double STATE_FLOAT_TIME_10 = 10.0D; + public static final Double STATE_FLOAT_TIME_20 = 20.0D; + public static final Double STATE_FLOAT_TIME_30 = 30.0D; - Order order = new Order(id, name, type, date, state); - ParameterBag bag = createParameterBag(BAG_ID, BAG_NAME, BAG_TYPE); - order.addParameterBag(bag); + public static final Integer STATE_INTEGER_TIME_0 = 0; + public static final Integer STATE_INTEGER_TIME_10 = 10; + public static final Integer STATE_INTEGER_TIME_20 = 20; + public static final Integer STATE_INTEGER_TIME_30 = 30; - return order; - } + public static final String STATE_STRING_TIME_0 = "empty"; + public static final String STATE_STRING_TIME_10 = "a"; + public static final String STATE_STRING_TIME_20 = "b"; + public static final String STATE_STRING_TIME_30 = "c"; - /** - * Creates a list of {@link Order Orders} with the given values and adds a {@link ParameterBag} by calling - * {@link #createParameterBag(String, String, String)} - * - * @param idStart - * id range start - * @param count - * the number of elements to create - * @param idPrefix - * the prefix to generate IDs for the {@link Order Orders} - * @param name - * the name of the {@link Order} - * @param type - * the type of the {@link Order} - * - * @return the list of newly created {@link Order Orders} - */ - public static List createOrders(int idStart, int count, String idPrefix, String name, String type) { - List orders = new ArrayList<>(); - for (int i = 0; i < count; i++) { - String id = StringHelper.normalizeLength(String.valueOf((i + idStart)), 8, true, '0'); - orders.add(createOrder(idPrefix + "_" + id, name + " " + i, type)); - } - return orders; - } + public static final Boolean STATE_BOOLEAN_TIME_0 = Boolean.FALSE; + public static final Boolean STATE_BOOLEAN_TIME_10 = Boolean.TRUE; + public static final Boolean STATE_BOOLEAN_TIME_20 = Boolean.FALSE; + public static final Boolean STATE_BOOLEAN_TIME_30 = Boolean.TRUE; - /** - * Creates a {@link ParameterBag} with the given values and calls {@link #addAllParameters(ParameterBag)} to add - * {@link Parameter}s - * - * @param id - * the id of the {@link ParameterBag} - * @param name - * the name of the {@link ParameterBag} - * @param type - * the type of the {@link ParameterBag} - * - * @return the newly created {@link ParameterBag} - */ - public static ParameterBag createParameterBag(String id, String name, String type) { + public static final String BAG_ID = "@bag01"; + public static final String BAG_NAME = "Test Bag"; + public static final String BAG_TYPE = "TestBag"; - ParameterBag bag = new ParameterBag(id, name, type); - addAllParameters(bag); - return bag; - } + /** + * Creates an {@link Resource} with the given values and adds a {@link ParameterBag} by calling + * {@link #createParameterBag(String, String, String)} + * + * @param id the id of the {@link Resource} + * @param name the name of the {@link Resource} + * @param type the type of the {@link Resource} + * + * @return the newly created {@link Resource} + */ + public static Resource createResource(String id, String name, String type) { + Resource resource = new Resource(id, name, type); + ParameterBag bag = createParameterBag(BAG_ID, BAG_NAME, BAG_TYPE); + resource.addParameterBag(bag); + addTimedStates(resource); - /** - * Adds the following {@link Parameter}s to the given {@link ParameterBag}: - *

    - *
  • BooleanParameter - true
  • - *
  • FloatParameter - 44.3
  • - *
  • IntegerParameter - 77
  • - *
  • LongParameter - 4453234566L
  • - *
  • StringParameter - "Strolch"
  • - *
  • DateParameter - 1354295525628L
  • - *
  • StringListParameter - Hello, World
  • - *
- * - * @param bag - */ - public static void addAllParameters(ParameterBag bag) { + return resource; + } - BooleanParameter boolParam = new BooleanParameter(PARAM_BOOLEAN_ID, PARAM_BOOLEAN_NAME, true); - boolParam.setIndex(1); - bag.addParameter(boolParam); + /** + * Creates {@link StrolchTimedState} instances and adds them to the {@link Resource} + * + * @param resource the resource to which to addd the newly created {@link StrolchTimedState} + */ + public static void addTimedStates(Resource resource) { - FloatParameter floatParam = new FloatParameter(PARAM_FLOAT_ID, PARAM_FLOAT_NAME, 44.3); - floatParam.setIndex(2); - bag.addParameter(floatParam); + // float state + FloatTimedState floatTimedState = new FloatTimedState(STATE_FLOAT_ID, STATE_FLOAT_NAME); + floatTimedState.applyChange(new ValueChange<>(STATE_TIME_0, new FloatValue(STATE_FLOAT_TIME_0))); + FloatValue floatValueChange = new FloatValue(STATE_FLOAT_TIME_10); + floatTimedState.applyChange(new ValueChange<>(STATE_TIME_10, floatValueChange)); + floatTimedState.applyChange(new ValueChange<>(STATE_TIME_20, floatValueChange)); + floatTimedState.applyChange(new ValueChange<>(STATE_TIME_30, floatValueChange)); + resource.addTimedState(floatTimedState); - IntegerParameter integerParam = new IntegerParameter(PARAM_INTEGER_ID, PARAM_INTEGER_NAME, 77); - integerParam.setIndex(3); - bag.addParameter(integerParam); + // integer state + IntegerTimedState integerTimedState = new IntegerTimedState(STATE_INTEGER_ID, STATE_INTEGER_NAME); + integerTimedState.applyChange(new ValueChange<>(STATE_TIME_0, + new IntegerValue(STATE_INTEGER_TIME_0))); + IntegerValue integerValueChange = new IntegerValue(STATE_INTEGER_TIME_10); + integerTimedState.applyChange(new ValueChange<>(STATE_TIME_10, integerValueChange)); + integerTimedState.applyChange(new ValueChange<>(STATE_TIME_20, integerValueChange)); + integerTimedState.applyChange(new ValueChange<>(STATE_TIME_30, integerValueChange)); + resource.addTimedState(integerTimedState); - LongParameter longParam = new LongParameter(PARAM_LONG_ID, PARAM_LONG_NAME, 4453234566L); - longParam.setIndex(4); - bag.addParameter(longParam); + // boolean state + BooleanTimedState booleanTimedState = new BooleanTimedState(STATE_BOOLEAN_ID, STATE_BOOLEAN_NAME); + booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_0, + new BooleanValue(STATE_BOOLEAN_TIME_0))); + BooleanValue booleanValueChange = new BooleanValue(STATE_BOOLEAN_TIME_10); + booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_10, booleanValueChange)); + booleanValueChange = booleanValueChange.getInverse(); + booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_20, booleanValueChange)); + booleanValueChange = booleanValueChange.getInverse(); + booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_30, booleanValueChange)); + resource.addTimedState(booleanTimedState); - StringParameter stringParam = new StringParameter(PARAM_STRING_ID, PARAM_STRING_NAME, "Strolch"); - stringParam.setIndex(5); - bag.addParameter(stringParam); + // string state + StringSetTimedState stringTimedState = new StringSetTimedState(STATE_STRING_ID, STATE_STRING_NAME); + StringSetValue change = new StringSetValue(asSet(STATE_STRING_TIME_0)); + stringTimedState.applyChange(new ValueChange<>(STATE_TIME_0, change)); + change = change.getInverse(); + change.add(asSet(STATE_STRING_TIME_10)); + stringTimedState.applyChange(new ValueChange<>(STATE_TIME_10, change)); + removeInverted(change.getValue()); + change = change.getInverse(); + change.add(asSet(STATE_STRING_TIME_20)); + stringTimedState.applyChange(new ValueChange<>(STATE_TIME_20, change)); + removeInverted(change.getValue()); + change = change.getInverse(); + change.add(asSet(STATE_STRING_TIME_30)); + stringTimedState.applyChange(new ValueChange<>(STATE_TIME_30, change)); + resource.addTimedState(stringTimedState); + } - DateParameter dateParam = new DateParameter(PARAM_DATE_ID, PARAM_DATE_NAME, new Date(1354295525628L)); - dateParam.setIndex(6); - bag.addParameter(dateParam); + private static Set asSet(String value) { + HashSet hashSet = new HashSet<>(); + hashSet.add(new AString(value)); + return hashSet; + } - ArrayList stringList = new ArrayList(); - stringList.add("Hello"); - stringList.add("World"); - StringListParameter stringListP = new StringListParameter(PARAM_LIST_STRING_ID, PARAM_LIST_STRING_NAME, - stringList); - stringListP.setIndex(7); - bag.addParameter(stringListP); - } + private static void removeInverted(Set set) { + for (Iterator iter = set.iterator(); iter.hasNext();) { + AString aString = iter.next(); + if (aString.isInverse()) { + iter.remove(); + } + } + } + + /** + * Creates a list of {@link Resource Resources} with the given values and adds a {@link ParameterBag} by calling + * {@link #createParameterBag(String, String, String)} + * + * @param idStart id range start + * @param count the number of elements to create + * @param idPrefix the prefix to generate IDs for the {@link Resource Resources} + * @param name the name of the {@link Resource} + * @param type the type of the {@link Resource} + * + * @return the list of newly created {@link Resource Resources} + */ + public static List createResources(int idStart, int count, String idPrefix, String name, String type) { + List resources = new ArrayList<>(); + for (int i = 0; i < count; i++) { + String id = StringHelper.normalizeLength(String.valueOf((i + idStart)), 8, true, '0'); + resources.add(createResource(idPrefix + "_" + id, name + " " + i, type)); + } + return resources; + } + + /** + * Creates an {@link Order} with the given values and adds a {@link ParameterBag} by calling + * {@link #createParameterBag(String, String, String)} + * + * @param id the id of the {@link Order} + * @param name the name of the {@link Order} + * @param type the type of the {@link Order} + * + * @return the newly created {@link Order} + */ + public static Order createOrder(String id, String name, String type) { + return createOrder(id, name, type, new Date(), State.CREATED); + } + + /** + * Creates an {@link Order} with the given values and adds a {@link ParameterBag} by calling + * {@link #createParameterBag(String, String, String)} + * + * @param id the id of the {@link Order} + * @param name the name of the {@link Order} + * @param type the type of the {@link Order} + * @param date the date of the {@link Order} + * @param state the {@link State} of the {@link Order} + * + * @return the newly created {@link Order} + */ + public static Order createOrder(String id, String name, String type, Date date, State state) { + + Order order = new Order(id, name, type, date, state); + ParameterBag bag = createParameterBag(BAG_ID, BAG_NAME, BAG_TYPE); + order.addParameterBag(bag); + + return order; + } + + /** + * Creates a list of {@link Order Orders} with the given values and adds a {@link ParameterBag} by calling + * {@link #createParameterBag(String, String, String)} + * + * @param idStart id range start + * @param count the number of elements to create + * @param idPrefix the prefix to generate IDs for the {@link Order Orders} + * @param name the name of the {@link Order} + * @param type the type of the {@link Order} + * + * @return the list of newly created {@link Order Orders} + */ + public static List createOrders(int idStart, int count, String idPrefix, String name, String type) { + List orders = new ArrayList<>(); + for (int i = 0; i < count; i++) { + String id = StringHelper.normalizeLength(String.valueOf((i + idStart)), 8, true, '0'); + orders.add(createOrder(idPrefix + "_" + id, name + " " + i, type)); + } + return orders; + } + + /** + * Creates a {@link ParameterBag} with the given values and calls {@link #addAllParameters(ParameterBag)} to add + * {@link Parameter}s + * + * @param id the id of the {@link ParameterBag} + * @param name the name of the {@link ParameterBag} + * @param type the type of the {@link ParameterBag} + * + * @return the newly created {@link ParameterBag} + */ + public static ParameterBag createParameterBag(String id, String name, String type) { + + ParameterBag bag = new ParameterBag(id, name, type); + addAllParameters(bag); + return bag; + } + + /** + * Adds the following {@link Parameter}s to the given {@link ParameterBag}: + *
    + *
  • BooleanParameter - true
  • + *
  • FloatParameter - 44.3
  • + *
  • IntegerParameter - 77
  • + *
  • LongParameter - 4453234566L
  • + *
  • StringParameter - "Strolch"
  • + *
  • DateParameter - 1354295525628L
  • + *
  • StringListParameter - Hello, World
  • + *
+ * + * @param bag + */ + public static void addAllParameters(ParameterBag bag) { + + BooleanParameter boolParam = new BooleanParameter(PARAM_BOOLEAN_ID, PARAM_BOOLEAN_NAME, true); + boolParam.setIndex(1); + bag.addParameter(boolParam); + + FloatParameter floatParam = new FloatParameter(PARAM_FLOAT_ID, PARAM_FLOAT_NAME, 44.3); + floatParam.setIndex(2); + bag.addParameter(floatParam); + + IntegerParameter integerParam = new IntegerParameter(PARAM_INTEGER_ID, PARAM_INTEGER_NAME, 77); + integerParam.setIndex(3); + bag.addParameter(integerParam); + + LongParameter longParam = new LongParameter(PARAM_LONG_ID, PARAM_LONG_NAME, 4453234566L); + longParam.setIndex(4); + bag.addParameter(longParam); + + StringParameter stringParam = new StringParameter(PARAM_STRING_ID, PARAM_STRING_NAME, "Strolch"); + stringParam.setIndex(5); + bag.addParameter(stringParam); + + DateParameter dateParam = new DateParameter(PARAM_DATE_ID, PARAM_DATE_NAME, new Date(1354295525628L)); + dateParam.setIndex(6); + bag.addParameter(dateParam); + + ArrayList stringList = new ArrayList(); + stringList.add("Hello"); + stringList.add("World"); + StringListParameter stringListP = new StringListParameter(PARAM_LIST_STRING_ID, PARAM_LIST_STRING_NAME, + stringList); + stringListP.setIndex(7); + bag.addParameter(stringListP); + } } diff --git a/src/main/java/li/strolch/model/ParameterizedElement.java b/src/main/java/li/strolch/model/ParameterizedElement.java index 30b2f4c20..2696399f7 100644 --- a/src/main/java/li/strolch/model/ParameterizedElement.java +++ b/src/main/java/li/strolch/model/ParameterizedElement.java @@ -15,6 +15,7 @@ */ package li.strolch.model; +import ch.eitchnet.utils.dbc.DBC; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collections; @@ -45,253 +46,255 @@ import ch.eitchnet.utils.helper.StringHelper; */ public abstract class ParameterizedElement extends AbstractStrolchElement { - private static final long serialVersionUID = 0L; + private static final long serialVersionUID = 0L; - protected GroupedParameterizedElement parent; - protected Map> parameterMap; - protected String type; + protected GroupedParameterizedElement parent; + protected Map> parameterMap; + protected String type; - /** - * Empty Constructor - */ - protected ParameterizedElement() { - // - } + /** + * Empty Constructor + */ + protected ParameterizedElement() { + // + } - /** - * Default Constructor - * - * @param id - * @param name - * @param type - */ - public ParameterizedElement(String id, String name, String type) { - setId(id); - setName(name); - setType(type); - } + /** + * Default Constructor + * + * @param id + * @param name + * @param type + */ + public ParameterizedElement(String id, String name, String type) { + setId(id); + setName(name); + setType(type); + } - @Override - public String getType() { - return this.type; - } + @Override + public String getType() { + return this.type; + } - /** - * Sets the type of this {@link ParameterizedElement} - * - * @param type - * the type to set - */ - public void setType(String type) { - if (StringHelper.isEmpty(type)) { - String msg = "Type may not be empty on element {0}"; //$NON-NLS-1$ - msg = MessageFormat.format(msg, getLocator()); - throw new StrolchException(msg); - } + /** + * Sets the type of this {@link ParameterizedElement} + * + * @param type the type to set + */ + public void setType(String type) { + if (StringHelper.isEmpty(type)) { + String msg = "Type may not be empty on element {0}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, getLocator()); + throw new StrolchException(msg); + } - this.type = type; - } + this.type = type; + } - /** - * Returns the {@link Parameter} with the given id, or null if it does not exist - * - * @param key - * the id of the parameter to return - * - * @return the {@link Parameter} with the given id, or null if it does not exist - */ - @SuppressWarnings("unchecked") - public T getParameter(String key) { - if (this.parameterMap == null) - return null; - return (T) this.parameterMap.get(key); - } + /** + * Returns the {@link Parameter} with the given id, or null if it does not exist + * + * @param key the id of the parameter to return + * + * @return the {@link Parameter} with the given id, or null if it does not exist + */ + @SuppressWarnings("unchecked") + public T getParameter(String key) { + if (this.parameterMap == null) { + return null; + } + return (T) this.parameterMap.get(key); + } - /** - * Adds the given {@link Parameter} to the {@link ParameterizedElement} - * - * @param parameter - * the {@link Parameter} to add - */ - public void addParameter(Parameter parameter) { - if (this.parameterMap == null) - this.parameterMap = new HashMap>(); - this.parameterMap.put(parameter.getId(), parameter); - parameter.setParent(this); - } + /** + * Adds the given {@link Parameter} to the {@link ParameterizedElement} + * + * @param parameter the {@link Parameter} to add + */ + public void addParameter(Parameter parameter) { + if (this.parameterMap == null) { + this.parameterMap = new HashMap>(); + } + this.parameterMap.put(parameter.getId(), parameter); + parameter.setParent(this); + } - /** - * Removes the {@link Parameter} with the given key - * - * @param key - * the key of the {@link Parameter} to remove - * - * @return the removed {@link Parameter}, or null if it does not exist - */ - @SuppressWarnings("unchecked") - public Parameter removeParameter(String key) { - if (this.parameterMap == null) - return null; - return (Parameter) this.parameterMap.remove(key); - } + /** + * Removes the {@link Parameter} with the given key + * + * @param key the key of the {@link Parameter} to remove + * + * @return the removed {@link Parameter}, or null if it does not exist + */ + @SuppressWarnings("unchecked") + public Parameter removeParameter(String key) { + if (this.parameterMap == null) { + return null; + } + return (Parameter) this.parameterMap.remove(key); + } - /** - * Returns a list of all the {@link Parameter}s in this {@link ParameterizedElement} - * - * @return a list of all the {@link Parameter}s in this {@link ParameterizedElement} - */ - public List> getParameters() { - if (this.parameterMap == null) - return Collections.emptyList(); - return new ArrayList>(this.parameterMap.values()); - } + /** + * Returns a list of all the {@link Parameter}s in this {@link ParameterizedElement} + * + * @return a list of all the {@link Parameter}s in this {@link ParameterizedElement} + */ + public List> getParameters() { + if (this.parameterMap == null) { + return Collections.emptyList(); + } + return new ArrayList>(this.parameterMap.values()); + } - /** - * Returns true, if the this {@link ParameterizedElement} has any {@link Parameter Parameters}, false otherwise - * - * @return true, if the this {@link ParameterizedElement} has any {@link Parameter Parameters}, false otherwise - */ - public boolean hasParameters() { - return this.parameterMap != null && !this.parameterMap.isEmpty(); - } + /** + * Returns true, if the this {@link ParameterizedElement} has any {@link Parameter Parameters}, false otherwise + * + * @return true, if the this {@link ParameterizedElement} has any {@link Parameter Parameters}, false otherwise + */ + public boolean hasParameters() { + return this.parameterMap != null && !this.parameterMap.isEmpty(); + } - /** - * Returns true, if the {@link Parameter} exists with the given key, false otherwise - * - * @param key - * the key of the {@link Parameter} to check for - * - * @return true, if the {@link Parameter} exists with the given key, false otherwise - */ - public boolean hasParameter(String key) { - if (this.parameterMap == null) - return false; - return this.parameterMap.containsKey(key); - } + /** + * Returns true, if the {@link Parameter} exists with the given key, false otherwise + * + * @param key the key of the {@link Parameter} to check for + * + * @return true, if the {@link Parameter} exists with the given key, false otherwise + */ + public boolean hasParameter(String key) { + if (this.parameterMap == null) { + return false; + } + return this.parameterMap.containsKey(key); + } - /** - * Returns a {@link Set} of all the {@link Parameter} keys in this {@link ParameterizedElement} - * - * @return a {@link Set} of all the {@link Parameter} keys in this {@link ParameterizedElement} - */ - public Set getParameterKeySet() { - if (this.parameterMap == null) - return Collections.emptySet(); - return new HashSet(this.parameterMap.keySet()); - } + /** + * Returns a {@link Set} of all the {@link Parameter} keys in this {@link ParameterizedElement} + * + * @return a {@link Set} of all the {@link Parameter} keys in this {@link ParameterizedElement} + */ + public Set getParameterKeySet() { + if (this.parameterMap == null) { + return Collections.emptySet(); + } + return new HashSet(this.parameterMap.keySet()); + } - @Override - public void fillLocator(LocatorBuilder lb) { - this.parent.fillLocator(lb); - lb.append(this.id); - } + @Override + public void fillLocator(LocatorBuilder lb) { + this.parent.fillLocator(lb); + lb.append(this.id); + } - @Override - public Locator getLocator() { - LocatorBuilder lb = new LocatorBuilder(); - fillLocator(lb); - return lb.build(); - } + @Override + public Locator getLocator() { + LocatorBuilder lb = new LocatorBuilder(); + fillLocator(lb); + return lb.build(); + } - @Override - protected void fromDom(Element element) { - super.fromDom(element); + @Override + protected void fromDom(Element element) { + super.fromDom(element); - String type = element.getAttribute(Tags.TYPE); - setType(type); + String type = element.getAttribute(Tags.TYPE); + setType(type); - // add all the parameters - NodeList parameterElements = element.getElementsByTagName(Tags.PARAMETER); - for (int i = 0; i < parameterElements.getLength(); i++) { - Element paramElement = (Element) parameterElements.item(i); - String paramtype = paramElement.getAttribute(Tags.TYPE); + // add all the parameters + NodeList parameterElements = element.getElementsByTagName(Tags.PARAMETER); + for (int i = 0; i < parameterElements.getLength(); i++) { + Element paramElement = (Element) parameterElements.item(i); + String paramtype = paramElement.getAttribute(Tags.TYPE); - if (paramtype.equals(StringParameter.TYPE)) { - StringParameter param = new StringParameter(paramElement); - addParameter(param); - } else if (paramtype.equals(IntegerParameter.TYPE)) { - IntegerParameter param = new IntegerParameter(paramElement); - addParameter(param); - } else if (paramtype.equals(FloatParameter.TYPE)) { - FloatParameter param = new FloatParameter(paramElement); - addParameter(param); - } else if (paramtype.equals(LongParameter.TYPE)) { - LongParameter param = new LongParameter(paramElement); - addParameter(param); - } else if (paramtype.equals(DateParameter.TYPE)) { - DateParameter param = new DateParameter(paramElement); - addParameter(param); - } else if (paramtype.equals(BooleanParameter.TYPE)) { - BooleanParameter param = new BooleanParameter(paramElement); - addParameter(param); - } else if (paramtype.equals(StringListParameter.TYPE)) { - StringListParameter param = new StringListParameter(paramElement); - addParameter(param); - } else { - String msg = "What kind of parameter is this: {0}"; //$NON-NLS-1$ - msg = MessageFormat.format(msg, paramtype); - throw new StrolchException(msg); - } - } - } + DBC.PRE.assertNotEmpty("Type must be set on Parameter for bag with id " + id, paramtype); - @Override - protected void fillElement(Element element) { - super.fillElement(element); + if (paramtype.equals(StringParameter.TYPE)) { + StringParameter param = new StringParameter(paramElement); + addParameter(param); + } else if (paramtype.equals(IntegerParameter.TYPE)) { + IntegerParameter param = new IntegerParameter(paramElement); + addParameter(param); + } else if (paramtype.equals(FloatParameter.TYPE)) { + FloatParameter param = new FloatParameter(paramElement); + addParameter(param); + } else if (paramtype.equals(LongParameter.TYPE)) { + LongParameter param = new LongParameter(paramElement); + addParameter(param); + } else if (paramtype.equals(DateParameter.TYPE)) { + DateParameter param = new DateParameter(paramElement); + addParameter(param); + } else if (paramtype.equals(BooleanParameter.TYPE)) { + BooleanParameter param = new BooleanParameter(paramElement); + addParameter(param); + } else if (paramtype.equals(StringListParameter.TYPE)) { + StringListParameter param = new StringListParameter(paramElement); + addParameter(param); + } else { + String msg = "What kind of parameter is this: {0}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, paramtype); + throw new StrolchException(msg); + } + } + } - if (this.parameterMap != null) { - for (Parameter parameter : this.parameterMap.values()) { - element.appendChild(parameter.toDom(element.getOwnerDocument())); - } - } - } + @Override + protected void fillElement(Element element) { + super.fillElement(element); - @Override - protected void fillClone(StrolchElement clone) { - super.fillClone(clone); - ParameterizedElement peClone = (ParameterizedElement) clone; - peClone.setType(this.type); - if (this.parameterMap != null) { - for (Parameter param : this.parameterMap.values()) { - peClone.addParameter(param.getClone()); - } - } - } + if (this.parameterMap != null) { + for (Parameter parameter : this.parameterMap.values()) { + element.appendChild(parameter.toDom(element.getOwnerDocument())); + } + } + } - @Override - public GroupedParameterizedElement getParent() { - return this.parent; - } + @Override + protected void fillClone(StrolchElement clone) { + super.fillClone(clone); + ParameterizedElement peClone = (ParameterizedElement) clone; + peClone.setType(this.type); + if (this.parameterMap != null) { + for (Parameter param : this.parameterMap.values()) { + peClone.addParameter(param.getClone()); + } + } + } - /** - * Set the parent for this {@link ParameterizedElement} - * - * @param parent - * the parent to set - */ - public void setParent(GroupedParameterizedElement parent) { - this.parent = parent; - } + @Override + public GroupedParameterizedElement getParent() { + return this.parent; + } - @Override - public StrolchRootElement getRootElement() { - return this.parent.getRootElement(); - } + /** + * Set the parent for this {@link ParameterizedElement} + * + * @param parent the parent to set + */ + public void setParent(GroupedParameterizedElement parent) { + this.parent = parent; + } - @SuppressWarnings("nls") - @Override - public String toString() { + @Override + public StrolchRootElement getRootElement() { + return this.parent.getRootElement(); + } - StringBuilder builder = new StringBuilder(); + @SuppressWarnings("nls") + @Override + public String toString() { - builder.append("ParameterizedElement [id="); - builder.append(this.id); - builder.append(", name="); - builder.append(this.name); - builder.append(", type="); - builder.append(this.type); - builder.append("]"); + StringBuilder builder = new StringBuilder(); - return builder.toString(); - } + builder.append("ParameterizedElement [id="); + builder.append(this.id); + builder.append(", name="); + builder.append(this.name); + builder.append(", type="); + builder.append(this.type); + builder.append("]"); + + return builder.toString(); + } } diff --git a/src/main/java/li/strolch/model/Resource.java b/src/main/java/li/strolch/model/Resource.java index 11fe1cb57..86b012e7e 100644 --- a/src/main/java/li/strolch/model/Resource.java +++ b/src/main/java/li/strolch/model/Resource.java @@ -15,105 +15,202 @@ */ package li.strolch.model; +import ch.eitchnet.utils.dbc.DBC; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import li.strolch.exception.StrolchException; import li.strolch.model.Locator.LocatorBuilder; +import li.strolch.model.timedstate.BooleanTimedState; +import li.strolch.model.timedstate.FloatTimedState; +import li.strolch.model.timedstate.IntegerTimedState; +import li.strolch.model.timedstate.StringSetTimedState; +import li.strolch.model.timedstate.StrolchTimedState; import li.strolch.model.visitor.StrolchRootElementVisitor; - import org.w3c.dom.Document; import org.w3c.dom.Element; +import org.w3c.dom.NodeList; /** * @author Robert von Burg */ public class Resource extends GroupedParameterizedElement implements StrolchRootElement { - private static final long serialVersionUID = 0L; + private static final long serialVersionUID = 0L; - /** - * Empty constructor - */ - public Resource() { - // - } + private Map> timedStateMap; - /** - * Default constructor - * - * @param id - * @param name - * @param type - */ - public Resource(String id, String name, String type) { - super(id, name, type); - } + /** + * Empty constructor + */ + public Resource() { + // + } - /** - * DOM Constructor - * - * @param element - */ - public Resource(Element element) { - super.fromDom(element); - } + /** + * Default constructor + * + * @param id + * @param name + * @param type + */ + public Resource(String id, String name, String type) { + super(id, name, type); + } - @Override - public Element toDom(Document doc) { + /** + * DOM Constructor + * + * @param element + */ + public Resource(Element element) { + super.fromDom(element); - Element element = doc.createElement(Tags.RESOURCE); - fillElement(element); + NodeList timedStateElems = element.getElementsByTagName(Tags.TIMED_STATE); + for (int i = 0; i < timedStateElems.getLength(); i++) { + Element timedStateElem = (Element) timedStateElems.item(i); + String typeS = timedStateElem.getAttribute(Tags.TYPE); - return element; - } + DBC.PRE.assertNotEmpty("Type must be set on TimedState for resource with id " + id, typeS); - @Override - public Resource getClone() { - Resource clone = new Resource(); + if (typeS.equals(FloatTimedState.TYPE)) { + StrolchTimedState timedState = new FloatTimedState(timedStateElem); + addTimedState(timedState); + } else if (typeS.equals(IntegerTimedState.TYPE)) { + StrolchTimedState timedState = new IntegerTimedState(timedStateElem); + addTimedState(timedState); + } else if (typeS.equals(BooleanTimedState.TYPE)) { + StrolchTimedState timedState = new BooleanTimedState(timedStateElem); + addTimedState(timedState); + } else if (typeS.equals(StringSetTimedState.TYPE)) { + StrolchTimedState timedState = new StringSetTimedState(timedStateElem); + addTimedState(timedState); + } else { + String msg = "What kind of TimedState is this: {0}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, typeS); + throw new StrolchException(msg); + } + } + } - super.fillClone(clone); + public void addTimedState(StrolchTimedState strolchTimedState) { + if (this.timedStateMap == null) { + this.timedStateMap = new HashMap<>(); + } - return clone; - } + this.timedStateMap.put(strolchTimedState.getId(), strolchTimedState); + strolchTimedState.setParent(this); + } - @Override - protected void fillLocator(LocatorBuilder lb) { - lb.append(Tags.RESOURCE).append(getType()).append(getId()); - } + @SuppressWarnings({"rawtypes", "unchecked"}) + public T getTimedState(String id) { + if (this.timedStateMap == null) { + return null; + } + return (T) this.timedStateMap.get(id); + } - @Override - public Locator getLocator() { - LocatorBuilder lb = new LocatorBuilder(); - fillLocator(lb); - return lb.build(); - } + @SuppressWarnings({"unchecked", "rawtypes"}) + public T removeTimedState(String id) { + if (this.timedStateMap == null) { + return null; + } + return (T) this.timedStateMap.remove(id); + } - @Override - public StrolchElement getParent() { - return null; - } + public Set getTimedStateKeySet() { + if (this.timedStateMap == null) { + return Collections.emptySet(); + } + return new HashSet<>(this.timedStateMap.keySet()); + } - @Override - public Resource getRootElement() { - return this; - } + public List> getTimedStates() { + if (this.timedStateMap == null) { + return Collections.emptyList(); + } + return new ArrayList<>(this.timedStateMap.values()); + } - @Override - public T accept(StrolchRootElementVisitor visitor) { - return visitor.visitResource(this); - } + public boolean hasTimedStates() { + return this.timedStateMap != null && !this.timedStateMap.isEmpty(); + } - @SuppressWarnings("nls") - @Override - public String toString() { + public boolean hasTimedState(String id) { + return this.timedStateMap != null && this.timedStateMap.containsKey(id); + } - StringBuilder builder = new StringBuilder(); + @Override + public Element toDom(Document doc) { - builder.append("Resource [id="); - builder.append(this.id); - builder.append(", name="); - builder.append(this.name); - builder.append(", type="); - builder.append(this.type); - builder.append("]"); + Element element = doc.createElement(Tags.RESOURCE); + fillElement(element); - return builder.toString(); - } + if (this.timedStateMap != null) { + for (StrolchTimedState state : this.timedStateMap.values()) { + Element timedStateElem = state.toDom(element.getOwnerDocument()); + element.appendChild(timedStateElem); + } + } + + return element; + } + + @Override + public Resource getClone() { + Resource clone = new Resource(); + + super.fillClone(clone); + + return clone; + } + + @Override + public void fillLocator(LocatorBuilder lb) { + lb.append(Tags.RESOURCE).append(getType()).append(getId()); + } + + @Override + public Locator getLocator() { + LocatorBuilder lb = new LocatorBuilder(); + fillLocator(lb); + return lb.build(); + } + + @Override + public StrolchElement getParent() { + return null; + } + + @Override + public Resource getRootElement() { + return this; + } + + @Override + public T accept(StrolchRootElementVisitor visitor) { + return visitor.visitResource(this); + } + + @SuppressWarnings("nls") + @Override + public String toString() { + + StringBuilder builder = new StringBuilder(); + + builder.append("Resource [id="); + builder.append(this.id); + builder.append(", name="); + builder.append(this.name); + builder.append(", type="); + builder.append(this.type); + builder.append("]"); + + return builder.toString(); + } } diff --git a/src/main/java/li/strolch/model/Tags.java b/src/main/java/li/strolch/model/Tags.java index b68bdac9c..52733c40f 100644 --- a/src/main/java/li/strolch/model/Tags.java +++ b/src/main/java/li/strolch/model/Tags.java @@ -25,11 +25,13 @@ public class Tags { public static final String DATE = "Date"; public static final String STATE = "State"; public static final String VALUE = "Value"; + public static final String TIME = "Time"; public static final String INTERPRETATION = "Interpretation"; public static final String UOM = "Uom"; public static final String HIDDEN = "Hidden"; public static final String INDEX = "Index"; public static final String PARAMETER = "Parameter"; + public static final String TIMED_STATE = "TimedState"; public static final String PARAMETERIZED_ELEMENT = "ParameterizedElement"; public static final String RESOURCE = "Resource"; public static final String ORDER = "Order"; diff --git a/src/main/java/li/strolch/model/parameter/AbstractParameter.java b/src/main/java/li/strolch/model/parameter/AbstractParameter.java index 7bcd7b324..a2895713a 100644 --- a/src/main/java/li/strolch/model/parameter/AbstractParameter.java +++ b/src/main/java/li/strolch/model/parameter/AbstractParameter.java @@ -200,7 +200,7 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem public Locator getLocator() { LocatorBuilder lb = new LocatorBuilder(); this.parent.fillLocator(lb); - this.fillLocator(lb); + fillLocator(lb); return lb.build(); } diff --git a/src/main/java/li/strolch/model/timedstate/AbstractStrolchTimedState.java b/src/main/java/li/strolch/model/timedstate/AbstractStrolchTimedState.java new file mode 100644 index 000000000..61f118599 --- /dev/null +++ b/src/main/java/li/strolch/model/timedstate/AbstractStrolchTimedState.java @@ -0,0 +1,127 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.timedstate; + +import li.strolch.model.AbstractStrolchElement; +import li.strolch.model.Locator; +import li.strolch.model.Locator.LocatorBuilder; +import li.strolch.model.Resource; +import li.strolch.model.StrolchElement; +import li.strolch.model.StrolchRootElement; +import li.strolch.model.Tags; +import li.strolch.model.timevalue.ITimeValue; +import li.strolch.model.timevalue.ITimeVariable; +import li.strolch.model.timevalue.IValue; +import li.strolch.model.timevalue.IValueChange; + +/** + * @author Robert von Burg + */ +@SuppressWarnings("rawtypes") +public abstract class AbstractStrolchTimedState extends AbstractStrolchElement implements + StrolchTimedState { + + private static final long serialVersionUID = 1L; + + protected Resource parent; + protected ITimedState state; + + public AbstractStrolchTimedState() { + this.state = new TimedState<>(); + } + + public AbstractStrolchTimedState(String id, String name) { + super(id, name); + this.state = new TimedState<>(); + } + + @Override + public ITimeValue getNextMatch(Long time, T value) { + return this.state.getNextMatch(time, value); + } + + @Override + public ITimeValue getPreviousMatch(Long time, T value) { + return this.state.getPreviousMatch(time, value); + } + + @Override + public > void applyChange(U change) { + this.state.applyChange(change); + } + + @Override + public ITimeValue getStateAt(Long time) { + return this.state.getStateAt(time); + } + + @Override + public ITimeVariable getTimeEvolution() { + return this.state.getTimeEvolution(); + } + + @Override + public StrolchElement getParent() { + return this.parent; + } + + @Override + public void setParent(Resource parent) { + this.parent = parent; + } + + @Override + public StrolchRootElement getRootElement() { + return this.parent; + } + + @Override + protected void fillLocator(LocatorBuilder locatorBuilder) { + locatorBuilder.append(Tags.TIMED_STATE); + locatorBuilder.append(getId()); + } + + @Override + public Locator getLocator() { + LocatorBuilder lb = new LocatorBuilder(); + this.parent.fillLocator(lb); + fillLocator(lb); + return lb.build(); + } + + protected void fillClone(AbstractStrolchTimedState clone) { + super.fillClone(clone); + clone.state = this.state.getCopy(); + } + + @SuppressWarnings("nls") + @Override + public String toString() { + + StringBuilder builder = new StringBuilder(); + + builder.append(getClass().getSimpleName()); + builder.append(" [id="); + builder.append(this.id); + builder.append(", name="); + builder.append(this.name); + builder.append(", valueNow="); + builder.append(this.state.getStateAt(System.currentTimeMillis())); + builder.append("]"); + + return builder.toString(); + } +} diff --git a/src/main/java/li/strolch/model/timedstate/BooleanTimedState.java b/src/main/java/li/strolch/model/timedstate/BooleanTimedState.java new file mode 100644 index 000000000..fce5aa0c1 --- /dev/null +++ b/src/main/java/li/strolch/model/timedstate/BooleanTimedState.java @@ -0,0 +1,88 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.timedstate; + +import java.util.SortedSet; +import li.strolch.model.StrolchElement; +import li.strolch.model.Tags; +import li.strolch.model.timevalue.ITimeValue; +import li.strolch.model.timevalue.impl.BooleanValue; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +/** + * @author Robert von Burg + */ +public class BooleanTimedState extends AbstractStrolchTimedState { + + private static final long serialVersionUID = 1L; + + public static final String TYPE = "BooleanState"; + + public BooleanTimedState() { + super(); + } + + public BooleanTimedState(String id, String name) { + super(id, name); + } + + public BooleanTimedState(Element element) { + super.fromDom(element); + + this.state = new TimedState<>(); + + NodeList timeValueElems = element.getElementsByTagName(Tags.VALUE); + for (int i = 0; i < timeValueElems.getLength(); i++) { + Element timeValueElem = (Element) timeValueElems.item(i); + Long time = Long.valueOf(timeValueElem.getAttribute(Tags.TIME)); + Boolean value = Boolean.valueOf(timeValueElem.getAttribute(Tags.VALUE)); + BooleanValue booleanValue = new BooleanValue(value); + this.state.getTimeEvolution().setValueAt(time, booleanValue); + } + } + + @Override + public Element toDom(Document doc) { + + Element stateElement = doc.createElement(Tags.TIMED_STATE); + super.fillElement(stateElement); + SortedSet> values = this.state.getTimeEvolution().getValues(); + for (ITimeValue timeValue : values) { + Long time = timeValue.getTime(); + BooleanValue value = timeValue.getValue(); + Element valueElem = doc.createElement(Tags.VALUE); + valueElem.setAttribute(Tags.TIME, time.toString()); + valueElem.setAttribute(Tags.VALUE, value.getValue().toString()); + stateElement.appendChild(valueElem); + } + + return stateElement; + } + + @Override + public String getType() { + return TYPE; + } + + @Override + public StrolchElement getClone() { + BooleanTimedState clone = new BooleanTimedState(); + fillClone(clone); + return clone; + } +} diff --git a/src/main/java/li/strolch/model/timedstate/FloatTimedState.java b/src/main/java/li/strolch/model/timedstate/FloatTimedState.java new file mode 100644 index 000000000..9c153af55 --- /dev/null +++ b/src/main/java/li/strolch/model/timedstate/FloatTimedState.java @@ -0,0 +1,88 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.timedstate; + +import java.util.SortedSet; +import li.strolch.model.StrolchElement; +import li.strolch.model.Tags; +import li.strolch.model.timevalue.ITimeValue; +import li.strolch.model.timevalue.impl.FloatValue; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +/** + * @author Robert von Burg + */ +public class FloatTimedState extends AbstractStrolchTimedState { + + private static final long serialVersionUID = 1L; + + public static final String TYPE = "FloatState"; + + public FloatTimedState() { + super(); + } + + public FloatTimedState(String id, String name) { + super(id, name); + } + + public FloatTimedState(Element element) { + super.fromDom(element); + + this.state = new TimedState<>(); + + NodeList timeValueElems = element.getElementsByTagName(Tags.VALUE); + for (int i = 0; i < timeValueElems.getLength(); i++) { + Element timeValueElem = (Element) timeValueElems.item(i); + Long time = Long.valueOf(timeValueElem.getAttribute(Tags.TIME)); + Double value = Double.valueOf(timeValueElem.getAttribute(Tags.VALUE)); + FloatValue floatValue = new FloatValue(value); + this.state.getTimeEvolution().setValueAt(time, floatValue); + } + } + + @Override + public Element toDom(Document doc) { + + Element stateElement = doc.createElement(Tags.TIMED_STATE); + super.fillElement(stateElement); + SortedSet> values = this.state.getTimeEvolution().getValues(); + for (ITimeValue timeValue : values) { + Long time = timeValue.getTime(); + FloatValue value = timeValue.getValue(); + Element valueElem = doc.createElement(Tags.VALUE); + valueElem.setAttribute(Tags.TIME, time.toString()); + valueElem.setAttribute(Tags.VALUE, value.getValue().toString()); + stateElement.appendChild(valueElem); + } + + return stateElement; + } + + @Override + public String getType() { + return TYPE; + } + + @Override + public StrolchElement getClone() { + FloatTimedState clone = new FloatTimedState(); + fillClone(clone); + return clone; + } +} diff --git a/src/main/java/li/strolch/model/timedstate/ITimedState.java b/src/main/java/li/strolch/model/timedstate/ITimedState.java index 27bfbb2ce..6115a5b1e 100644 --- a/src/main/java/li/strolch/model/timedstate/ITimedState.java +++ b/src/main/java/li/strolch/model/timedstate/ITimedState.java @@ -45,7 +45,7 @@ public interface ITimedState { * @param change * the state change to be applied */ - void applyChange(final IValueChange change); + > void applyChange(final U change); /** * @return the state at the given time @@ -57,4 +57,8 @@ public interface ITimedState { */ ITimeVariable getTimeEvolution(); + /** + * @return a copy of this timed state + */ + ITimedState getCopy(); } \ No newline at end of file diff --git a/src/main/java/li/strolch/model/timedstate/IntegerTimedState.java b/src/main/java/li/strolch/model/timedstate/IntegerTimedState.java new file mode 100644 index 000000000..31e7cec32 --- /dev/null +++ b/src/main/java/li/strolch/model/timedstate/IntegerTimedState.java @@ -0,0 +1,88 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.timedstate; + +import java.util.SortedSet; +import li.strolch.model.StrolchElement; +import li.strolch.model.Tags; +import li.strolch.model.timevalue.ITimeValue; +import li.strolch.model.timevalue.impl.IntegerValue; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +/** + * @author Robert von Burg + */ +public class IntegerTimedState extends AbstractStrolchTimedState { + + private static final long serialVersionUID = 1L; + + public static final String TYPE = "IntegerState"; + + public IntegerTimedState() { + super(); + } + + public IntegerTimedState(String id, String name) { + super(id, name); + } + + public IntegerTimedState(Element element) { + super.fromDom(element); + + this.state = new TimedState<>(); + + NodeList timeValueElems = element.getElementsByTagName(Tags.VALUE); + for (int i = 0; i < timeValueElems.getLength(); i++) { + Element timeValueElem = (Element) timeValueElems.item(i); + Long time = Long.valueOf(timeValueElem.getAttribute(Tags.TIME)); + Integer value = Integer.valueOf(timeValueElem.getAttribute(Tags.VALUE)); + IntegerValue integerValue = new IntegerValue(value); + this.state.getTimeEvolution().setValueAt(time, integerValue); + } + } + + @Override + public Element toDom(Document doc) { + + Element stateElement = doc.createElement(Tags.TIMED_STATE); + super.fillElement(stateElement); + SortedSet> values = this.state.getTimeEvolution().getValues(); + for (ITimeValue timeValue : values) { + Long time = timeValue.getTime(); + IntegerValue value = timeValue.getValue(); + Element valueElem = doc.createElement(Tags.VALUE); + valueElem.setAttribute(Tags.TIME, time.toString()); + valueElem.setAttribute(Tags.VALUE, value.getValue().toString()); + stateElement.appendChild(valueElem); + } + + return stateElement; + } + + @Override + public String getType() { + return TYPE; + } + + @Override + public StrolchElement getClone() { + IntegerTimedState clone = new IntegerTimedState(); + fillClone(clone); + return clone; + } +} diff --git a/src/main/java/li/strolch/model/timedstate/StringSetTimedState.java b/src/main/java/li/strolch/model/timedstate/StringSetTimedState.java new file mode 100644 index 000000000..13722527e --- /dev/null +++ b/src/main/java/li/strolch/model/timedstate/StringSetTimedState.java @@ -0,0 +1,111 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.timedstate; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import java.util.SortedSet; +import li.strolch.model.StrolchElement; +import li.strolch.model.Tags; +import li.strolch.model.timevalue.ITimeValue; +import li.strolch.model.timevalue.impl.AString; +import li.strolch.model.timevalue.impl.StringSetValue; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +/** + * @author Robert von Burg + */ +public class StringSetTimedState extends AbstractStrolchTimedState { + + private static final long serialVersionUID = 1L; + + public static final String TYPE = "StringSetState"; + + public StringSetTimedState() { + super(); + } + + public StringSetTimedState(String id, String name) { + super(id, name); + } + + public StringSetTimedState(Element element) { + super.fromDom(element); + + this.state = new TimedState<>(); + + NodeList timeValueElems = element.getElementsByTagName(Tags.VALUE); + for (int i = 0; i < timeValueElems.getLength(); i++) { + Element timeValueElem = (Element) timeValueElems.item(i); + Long time = Long.valueOf(timeValueElem.getAttribute(Tags.TIME)); + + String valueAsString = timeValueElem.getAttribute(Tags.VALUE); + Set value = new HashSet<>(); + String[] values = valueAsString.split(","); + for (String s : values) { + value.add(new AString(s.trim())); + } + + StringSetValue integerValue = new StringSetValue(value); + this.state.getTimeEvolution().setValueAt(time, integerValue); + } + } + + @Override + public Element toDom(Document doc) { + + Element stateElement = doc.createElement(Tags.TIMED_STATE); + super.fillElement(stateElement); + SortedSet> values = this.state.getTimeEvolution().getValues(); + for (ITimeValue timeValue : values) { + Long time = timeValue.getTime(); + StringSetValue stringSetValue = timeValue.getValue(); + + Set value = stringSetValue.getValue(); + StringBuilder sb = new StringBuilder(); + Iterator iter = value.iterator(); + while (iter.hasNext()) { + sb.append(iter.next().getString()); + if (iter.hasNext()) { + sb.append(", "); + } + } + String valueAsString = sb.toString(); + + Element valueElem = doc.createElement(Tags.VALUE); + valueElem.setAttribute(Tags.TIME, time.toString()); + valueElem.setAttribute(Tags.VALUE, valueAsString); + stateElement.appendChild(valueElem); + } + + return stateElement; + } + + @Override + public String getType() { + return TYPE; + } + + @Override + public StrolchElement getClone() { + StringSetTimedState clone = new StringSetTimedState(); + fillClone(clone); + return clone; + } +} diff --git a/src/main/java/li/strolch/model/timedstate/StrolchTimedState.java b/src/main/java/li/strolch/model/timedstate/StrolchTimedState.java new file mode 100644 index 000000000..f2ab09454 --- /dev/null +++ b/src/main/java/li/strolch/model/timedstate/StrolchTimedState.java @@ -0,0 +1,42 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.timedstate; + +import li.strolch.model.Resource; +import li.strolch.model.StrolchElement; +import li.strolch.model.timevalue.ITimeValue; +import li.strolch.model.timevalue.ITimeVariable; +import li.strolch.model.timevalue.IValue; +import li.strolch.model.timevalue.IValueChange; + +/** + * @author Robert von Burg + */ +@SuppressWarnings("rawtypes") +public interface StrolchTimedState extends StrolchElement { + + public ITimeValue getNextMatch(Long time, T value); + + public ITimeValue getPreviousMatch(Long time, T value); + + public > void applyChange(U change); + + public ITimeValue getStateAt(Long time); + + public ITimeVariable getTimeEvolution(); + + public void setParent(Resource aThis); +} diff --git a/src/main/java/li/strolch/model/timedstate/TimedState.java b/src/main/java/li/strolch/model/timedstate/TimedState.java index b4a6bb0f3..23f9fbdf8 100644 --- a/src/main/java/li/strolch/model/timedstate/TimedState.java +++ b/src/main/java/li/strolch/model/timedstate/TimedState.java @@ -34,7 +34,7 @@ import li.strolch.model.timevalue.impl.TimeVariable; public class TimedState implements ITimedState, Serializable { private static final long serialVersionUID = 1L; - + private ITimeVariable timeVariable = new TimeVariable(); @Override @@ -64,7 +64,7 @@ public class TimedState implements ITimedState, Serializabl } @Override - public void applyChange(final IValueChange change) { + public > void applyChange(U change) { this.timeVariable.applyChange(change); } @@ -78,4 +78,10 @@ public class TimedState implements ITimedState, Serializabl return this.timeVariable; } + @Override + public ITimedState getCopy() { + TimedState copy = new TimedState<>(); + copy.timeVariable = this.timeVariable.getCopy(); + return copy; + } } diff --git a/src/main/java/li/strolch/model/timevalue/ITimeValue.java b/src/main/java/li/strolch/model/timevalue/ITimeValue.java index fdc0090fa..de87f9190 100644 --- a/src/main/java/li/strolch/model/timevalue/ITimeValue.java +++ b/src/main/java/li/strolch/model/timevalue/ITimeValue.java @@ -36,4 +36,5 @@ public interface ITimeValue extends Comparable> ITimeValue add(final T change); + ITimeValue getCopy(); } diff --git a/src/main/java/li/strolch/model/timevalue/ITimeVariable.java b/src/main/java/li/strolch/model/timevalue/ITimeVariable.java index d453e8f55..0e7347f79 100644 --- a/src/main/java/li/strolch/model/timevalue/ITimeVariable.java +++ b/src/main/java/li/strolch/model/timevalue/ITimeVariable.java @@ -19,8 +19,7 @@ import java.util.Collection; import java.util.SortedSet; /** - * A timed variable storing a ordered sequence of {@link ITimeValue} objects - * modeling a time evolution of a quantity. + * A timed variable storing a ordered sequence of {@link ITimeValue} objects modeling a time evolution of a quantity. * * @author Martin Smock * @@ -41,14 +40,12 @@ public interface ITimeVariable { void setValueAt(final Long time, final T value); /** - * get the latest {@link ITimeValue} whose time field is less or equal to - * the time given + * get the latest {@link ITimeValue} whose time field is less or equal to the time given */ ITimeValue getValueAt(final Long time); /** - * Applies a {@link IValueChange} propagating the change to all future - * values starting from the time of the change. + * Applies a {@link IValueChange} propagating the change to all future values starting from the time of the change. * * @param change * the {@link IValueChange} to be applied @@ -56,8 +53,7 @@ public interface ITimeVariable { void applyChange(final IValueChange change); /** - * Get all {@link ITimeValue} objects whose time field is greater or equal - * to the given time + * Get all {@link ITimeValue} objects whose time field is greater or equal to the given time * * @param time * the time the sequence starts with @@ -66,8 +62,7 @@ public interface ITimeVariable { Collection> getFutureValues(final Long time); /** - * Get all {@link ITimeValue} objects whose time field is strictly smaller - * than the given time + * Get all {@link ITimeValue} objects whose time field is strictly smaller than the given time * * @param time * the time the sequence starts with @@ -81,13 +76,16 @@ public interface ITimeVariable { * @return a defensive copy of the {@link ITimeValue}s */ SortedSet> getValues(); - + /** - * removes {@link ITimeValue} objects from the sequence, where the successor - * matches value. I.e considering a pair of adjacent {@link ITimeValue} - * objects in the sequence which have the same {@link IValue}, the later one - * is removed, since it contains no additional information. + * removes {@link ITimeValue} objects from the sequence, where the successor matches value. I.e considering a pair + * of adjacent {@link ITimeValue} objects in the sequence which have the same {@link IValue}, the later one is + * removed, since it contains no additional information. */ void compact(); + /** + * @return a copy of this time variable + */ + ITimeVariable getCopy(); } diff --git a/src/main/java/li/strolch/model/timevalue/IValue.java b/src/main/java/li/strolch/model/timevalue/IValue.java index 5d8d73f56..83446b94a 100644 --- a/src/main/java/li/strolch/model/timevalue/IValue.java +++ b/src/main/java/li/strolch/model/timevalue/IValue.java @@ -23,7 +23,6 @@ package li.strolch.model.timevalue; * * @param * any object for which a (generalized) add operation can be defined. - * */ public interface IValue { @@ -52,5 +51,4 @@ public interface IValue { * @return a copy of this */ IValue getCopy(); - } diff --git a/src/main/java/li/strolch/model/timevalue/impl/BooleanValue.java b/src/main/java/li/strolch/model/timevalue/impl/BooleanValue.java new file mode 100644 index 000000000..bde39dab3 --- /dev/null +++ b/src/main/java/li/strolch/model/timevalue/impl/BooleanValue.java @@ -0,0 +1,108 @@ +/* + * Copyright 2013 Martin Smock + * + * 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 li.strolch.model.timevalue.impl; + +import java.io.Serializable; + +import li.strolch.model.timevalue.ITimeValue; +import li.strolch.model.timevalue.IValue; + +/** + * {@link IValue} implementation to work with Boolean valued {@link ITimeValue} objects + * + * @author Martin Smock + */ +public class BooleanValue implements IValue, Serializable { + + private static final long serialVersionUID = 1L; + + public static final BooleanValue NEUTRAL = new BooleanValue(false); + + private Boolean value; + + public BooleanValue(Boolean value) { + this.value = value; + } + + public BooleanValue(boolean value) { + this.value = Boolean.valueOf(value); + } + + public BooleanValue(String valueAsString) throws NumberFormatException { + this.value = Boolean.parseBoolean(valueAsString); + } + + @Override + public BooleanValue add(Boolean o) { + this.value = o; + return this; + } + + @Override + public boolean matches(IValue other) { + return this.value.equals(other.getValue()); + } + + @Override + public Boolean getValue() { + return this.value; + } + + @Override + public BooleanValue getInverse() { + return new BooleanValue(!getValue()); + } + + @SuppressWarnings("nls") + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("BooleanValue [value="); + sb.append(this.value); + sb.append("]"); + return sb.toString(); + } + + @Override + public BooleanValue getCopy() { + return new BooleanValue(this.value); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.value == null) ? 0 : this.value.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + BooleanValue other = (BooleanValue) obj; + if (this.value == null) { + if (other.value != null) + return false; + } else if (!this.value.equals(other.value)) + return false; + return true; + } +} diff --git a/src/main/java/li/strolch/model/timevalue/impl/DoubleValue.java b/src/main/java/li/strolch/model/timevalue/impl/FloatValue.java similarity index 79% rename from src/main/java/li/strolch/model/timevalue/impl/DoubleValue.java rename to src/main/java/li/strolch/model/timevalue/impl/FloatValue.java index 0b61f657c..98209b787 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/DoubleValue.java +++ b/src/main/java/li/strolch/model/timevalue/impl/FloatValue.java @@ -25,36 +25,36 @@ import li.strolch.model.timevalue.IValue; * * @author Martin Smock */ -public class DoubleValue implements IValue, Serializable { +public class FloatValue implements IValue, Serializable { private static final long serialVersionUID = 1L; - public static final DoubleValue NEUTRAL = new DoubleValue(0.0d); + public static final FloatValue NEUTRAL = new FloatValue(0.0d); private Double value; - public DoubleValue(Double value) { + public FloatValue(Double value) { this.value = value; } - public DoubleValue(double value) { + public FloatValue(double value) { this.value = Double.valueOf(value); } - public DoubleValue(Integer value) { + public FloatValue(Integer value) { this.value = this.value.doubleValue(); } - public DoubleValue(int value) { + public FloatValue(int value) { this.value = Integer.valueOf(value).doubleValue(); } - public DoubleValue(String valueAsString) throws NumberFormatException { + public FloatValue(String valueAsString) throws NumberFormatException { this.value = Double.parseDouble(valueAsString); } @Override - public DoubleValue add(Double o) { + public FloatValue add(Double o) { this.value += o; return this; } @@ -80,13 +80,13 @@ public class DoubleValue implements IValue, Serializable { } @Override - public DoubleValue getInverse() { - return new DoubleValue(-getValue()); + public FloatValue getInverse() { + return new FloatValue(-getValue()); } @Override - public DoubleValue getCopy(){ - return new DoubleValue(this.value); + public FloatValue getCopy(){ + return new FloatValue(this.value); } @Override @@ -105,7 +105,7 @@ public class DoubleValue implements IValue, Serializable { return false; if (getClass() != obj.getClass()) return false; - DoubleValue other = (DoubleValue) obj; + FloatValue other = (FloatValue) obj; if (this.value == null) { if (other.value != null) return false; diff --git a/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java b/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java index c99eacc26..b754b5c1e 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java +++ b/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java @@ -15,93 +15,103 @@ */ package li.strolch.model.timevalue.impl; +import ch.eitchnet.utils.helper.StringHelper; import java.io.Serializable; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.Set; - +import li.strolch.exception.StrolchException; import li.strolch.model.timevalue.ITimeValue; import li.strolch.model.timevalue.IValue; /** * {@link IValue} implementation to work with String valued {@link ITimeValue} objects. Since a java.util.String object * does not define a inverse, a algebraic {@link AString} wrapper is used. - * + * * @author Martin Smock */ public class StringSetValue implements IValue>, Serializable { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - private static Set neu = Collections.emptySet(); - public static final IValue> NEUTRAL = new StringSetValue(neu); + private static Set neu = Collections.emptySet(); + public static final IValue> NEUTRAL = new StringSetValue(neu); - private Set aStrings = new HashSet(); + private Set aStrings = new HashSet<>(); - public StringSetValue() { - } + public StringSetValue() { + } - public StringSetValue(final Set aStrings) { - this.aStrings = aStrings; - } + public StringSetValue(final Set aStrings) { + // assert no null values in set + for (AString aString : aStrings) { + if (StringHelper.isEmpty(aString.getString())) { + throw new StrolchException("StringSetValue may not contain null values in set!"); + } + } + this.aStrings = aStrings; + } - @Override - public Set getValue() { - return this.aStrings; - } + @Override + public Set getValue() { + return this.aStrings; + } - @Override - public IValue> add(Set o) { + @Override + public IValue> add(Set o) { - Set toBeAdded = new HashSet(o); + Set toBeAdded = new HashSet<>(o); - for (Iterator iter1 = toBeAdded.iterator(); iter1.hasNext();) { - AString toAdd = iter1.next(); - for (Iterator iter = this.aStrings.iterator(); iter.hasNext();) { - AString aString = iter.next(); - boolean valueMatch = aString.getString().equals(toAdd.getString()); - boolean compensate = (toAdd.isInverse() && !aString.isInverse()) - || (!toAdd.isInverse() && aString.isInverse()); - if (valueMatch && compensate) { - iter.remove(); - iter1.remove(); - } - } - } - this.aStrings.addAll(toBeAdded); - return this; - } + for (Iterator iter1 = toBeAdded.iterator(); iter1.hasNext();) { + AString toAdd = iter1.next(); + if (StringHelper.isEmpty(toAdd.getString())) { + throw new StrolchException("StringSetValue may not contain null values in set!"); + } - @Override - public boolean matches(IValue> other) { - return getValue().equals(other.getValue()); - } + for (Iterator iter = this.aStrings.iterator(); iter.hasNext();) { + AString aString = iter.next(); + boolean valueMatch = aString.getString().equals(toAdd.getString()); + boolean compensate = (toAdd.isInverse() && !aString.isInverse()) + || (!toAdd.isInverse() && aString.isInverse()); + if (valueMatch && compensate) { + iter.remove(); + iter1.remove(); + } + } + } + this.aStrings.addAll(toBeAdded); + return this; + } - @Override - public IValue> getInverse() { - Set inverseSet = new HashSet(); - for (AString as : this.aStrings) { - inverseSet.add(as.getInverse()); - } - StringSetValue inverse = new StringSetValue(); - inverse.aStrings = inverseSet; - return inverse; - } + @Override + public boolean matches(IValue> other) { + return getValue().equals(other.getValue()); + } - @Override - public StringSetValue getCopy() { - return new StringSetValue(this.aStrings); - } + @Override + public StringSetValue getInverse() { + Set inverseSet = new HashSet<>(); + for (AString as : this.aStrings) { + inverseSet.add(as.getInverse()); + } + StringSetValue inverse = new StringSetValue(); + inverse.aStrings = inverseSet; + return inverse; + } - @SuppressWarnings("nls") - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("StringSetValue [aStrings="); - sb.append(this.aStrings); - sb.append("]"); - return sb.toString(); - } + @Override + public StringSetValue getCopy() { + return new StringSetValue(new HashSet<>(this.aStrings)); + } + @SuppressWarnings("nls") + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("StringSetValue [aStrings="); + sb.append(this.aStrings); + sb.append("]"); + return sb.toString(); + } } diff --git a/src/main/java/li/strolch/model/timevalue/impl/TimeValue.java b/src/main/java/li/strolch/model/timevalue/impl/TimeValue.java index 091b5031e..c400c7ba4 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/TimeValue.java +++ b/src/main/java/li/strolch/model/timevalue/impl/TimeValue.java @@ -69,6 +69,12 @@ public class TimeValue implements ITimeValue, Serializable return this.getTime().compareTo(arg0.getTime()); } + @SuppressWarnings("unchecked") + @Override + public ITimeValue getCopy() { + return new TimeValue(time, (T) value.getCopy()); + } + @SuppressWarnings("nls") @Override public String toString() { @@ -112,5 +118,4 @@ public class TimeValue implements ITimeValue, Serializable return false; return true; } - } diff --git a/src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java b/src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java index 1e963eb1f..07cd0c2ad 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java +++ b/src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java @@ -26,7 +26,6 @@ import li.strolch.model.timevalue.ITimeVariable; import li.strolch.model.timevalue.IValue; import li.strolch.model.timevalue.IValueChange; - /** * @author Martin Smock */ @@ -34,7 +33,7 @@ import li.strolch.model.timevalue.IValueChange; public class TimeVariable implements ITimeVariable, Serializable { private static final long serialVersionUID = 1L; - + public SortedSet> container = new TreeSet>(); @Override @@ -71,7 +70,7 @@ public class TimeVariable implements ITimeVariable, Seriali TimeValue picker = new TimeValue(time, null); return new TreeSet>(this.container.headSet(picker)); } - + @Override public SortedSet> getValues() { return new TreeSet>(this.container); @@ -91,9 +90,10 @@ public class TimeVariable implements ITimeVariable, Seriali this.container.add(newValue); } else if (initialValue.getTime().longValue() < change.getTime().longValue()) { ITimeValue newValue = new TimeValue(change.getTime(), initialValue.getValue()); - newValue.add(change.getValue()); + newValue.add(change.getValue()); this.container.add(newValue); } + compact(); } @@ -115,7 +115,15 @@ public class TimeVariable implements ITimeVariable, Seriali predecessor = successor; } } - } + @Override + public ITimeVariable getCopy() { + TimeVariable clone = new TimeVariable<>(); + for (ITimeValue timeValue : this.container) { + clone.container.add(timeValue.getCopy()); + } + + return clone; + } } diff --git a/src/main/java/li/strolch/model/visitor/StrolchElementDeepEqualsVisitor.java b/src/main/java/li/strolch/model/visitor/StrolchElementDeepEqualsVisitor.java index 0c0c2c602..3ca79e0b1 100644 --- a/src/main/java/li/strolch/model/visitor/StrolchElementDeepEqualsVisitor.java +++ b/src/main/java/li/strolch/model/visitor/StrolchElementDeepEqualsVisitor.java @@ -18,7 +18,6 @@ package li.strolch.model.visitor; import java.util.ArrayList; import java.util.List; import java.util.Set; - import li.strolch.model.GroupedParameterizedElement; import li.strolch.model.Locator; import li.strolch.model.Order; @@ -26,123 +25,165 @@ import li.strolch.model.ParameterBag; import li.strolch.model.Resource; import li.strolch.model.StrolchElement; import li.strolch.model.parameter.Parameter; +import li.strolch.model.timedstate.StrolchTimedState; +import li.strolch.model.timevalue.ITimeVariable; /** * @author Robert von Burg - * + * */ public class StrolchElementDeepEqualsVisitor { - private List mismatchedLocators; + private List mismatchedLocators; - public StrolchElementDeepEqualsVisitor() { - this.mismatchedLocators = new ArrayList<>(); - } + public StrolchElementDeepEqualsVisitor() { + this.mismatchedLocators = new ArrayList<>(); + } - /** - * @return the mismatchedLocators - */ - public List getMismatchedLocators() { - return this.mismatchedLocators; - } + /** + * @return the mismatchedLocators + */ + public List getMismatchedLocators() { + return this.mismatchedLocators; + } - public boolean isEqual() { - return this.mismatchedLocators.isEmpty(); - } + public boolean isEqual() { + return this.mismatchedLocators.isEmpty(); + } - protected void deepEquals(StrolchElement srcElement, StrolchElement dstElement) { - if (!srcElement.getName().equals(dstElement.getName())) - this.mismatchedLocators.add(dstElement.getLocator()); - if (!srcElement.getType().equals(dstElement.getType())) - this.mismatchedLocators.add(dstElement.getLocator()); - } + protected void deepEquals(StrolchElement srcElement, StrolchElement dstElement) { + if (!srcElement.getName().equals(dstElement.getName())) { + this.mismatchedLocators.add(dstElement.getLocator()); + } + if (!srcElement.getType().equals(dstElement.getType())) { + this.mismatchedLocators.add(dstElement.getLocator()); + } + } - protected void deepEquals(Order srcOrder, Order dstOrder) { - deepEquals((StrolchElement) srcOrder, (StrolchElement) dstOrder); - if (!srcOrder.getState().equals(dstOrder.getState())) - this.mismatchedLocators.add(dstOrder.getLocator()); - if (!srcOrder.getDate().equals(dstOrder.getDate())) - this.mismatchedLocators.add(dstOrder.getLocator()); + protected void deepEquals(Order srcOrder, Order dstOrder) { + deepEquals((StrolchElement) srcOrder, (StrolchElement) dstOrder); + if (!srcOrder.getState().equals(dstOrder.getState())) { + this.mismatchedLocators.add(dstOrder.getLocator()); + } + if (!srcOrder.getDate().equals(dstOrder.getDate())) { + this.mismatchedLocators.add(dstOrder.getLocator()); + } - deepEquals((GroupedParameterizedElement) srcOrder, (GroupedParameterizedElement) dstOrder); - } + deepEquals((GroupedParameterizedElement) srcOrder, (GroupedParameterizedElement) dstOrder); + } - protected void deepEquals(Resource srcRes, Resource dstRes) { - deepEquals((StrolchElement) srcRes, (StrolchElement) dstRes); - deepEquals((GroupedParameterizedElement) srcRes, (GroupedParameterizedElement) dstRes); - } + protected void deepEquals(Resource srcRes, Resource dstRes) { + deepEquals((StrolchElement) srcRes, (StrolchElement) dstRes); + deepEquals((GroupedParameterizedElement) srcRes, (GroupedParameterizedElement) dstRes); + + Set srcTimedStateKeySet = srcRes.getTimedStateKeySet(); + for (String timedStateKey : srcTimedStateKeySet) { + StrolchTimedState srcTimedState = srcRes.getTimedState(timedStateKey); - protected void deepEquals(GroupedParameterizedElement srcElement, GroupedParameterizedElement dstElement) { - Set srcBagKeySet = srcElement.getParameterBagKeySet(); - for (String bagKey : srcBagKeySet) { - ParameterBag srcBag = srcElement.getParameterBag(bagKey); + if (!dstRes.hasTimedState(timedStateKey)) { + this.mismatchedLocators.add(srcTimedState.getLocator()); + continue; + } - if (!dstElement.hasParameterBag(bagKey)) { - this.mismatchedLocators.add(srcBag.getLocator()); - continue; - } + StrolchTimedState dstTimedState = dstRes.getTimedState(timedStateKey); + deepEquals(srcTimedState, dstTimedState); + } - ParameterBag dstBag = dstElement.getParameterBag(bagKey); - deepEquals(srcBag, dstBag); - } + Set dstTimedStateKeySet = dstRes.getTimedStateKeySet(); + for (String timedStateKey : dstTimedStateKeySet) { + if (!srcRes.hasTimedState(timedStateKey)) { + StrolchTimedState dstTimedState = dstRes.getTimedState(timedStateKey); + this.mismatchedLocators.add(dstTimedState.getLocator()); + } + } + } - Set dstBagKeySet = dstElement.getParameterBagKeySet(); - for (String bagKey : dstBagKeySet) { - if (!srcElement.hasParameterBag(bagKey)) { - ParameterBag dstBag = dstElement.getParameterBag(bagKey); - this.mismatchedLocators.add(dstBag.getLocator()); - } - } - } + protected void deepEquals(GroupedParameterizedElement srcElement, GroupedParameterizedElement dstElement) { + Set srcBagKeySet = srcElement.getParameterBagKeySet(); + for (String bagKey : srcBagKeySet) { + ParameterBag srcBag = srcElement.getParameterBag(bagKey); - protected void deepEquals(ParameterBag srcBag, ParameterBag dstBag) { - deepEquals((StrolchElement) srcBag, (StrolchElement) dstBag); + if (!dstElement.hasParameterBag(bagKey)) { + this.mismatchedLocators.add(srcBag.getLocator()); + continue; + } - Set srcParamKeySet = srcBag.getParameterKeySet(); - for (String paramKey : srcParamKeySet) { - Parameter srcParam = srcBag.getParameter(paramKey); - if (!dstBag.hasParameter(paramKey)) { - this.mismatchedLocators.add(srcParam.getLocator()); - continue; - } + ParameterBag dstBag = dstElement.getParameterBag(bagKey); + deepEquals(srcBag, dstBag); + } - Parameter dstParam = dstBag.getParameter(paramKey); - deepEquals(srcParam, dstParam); - } + Set dstBagKeySet = dstElement.getParameterBagKeySet(); + for (String bagKey : dstBagKeySet) { + if (!srcElement.hasParameterBag(bagKey)) { + ParameterBag dstBag = dstElement.getParameterBag(bagKey); + this.mismatchedLocators.add(dstBag.getLocator()); + } + } + } - Set dstParamKeySet = dstBag.getParameterKeySet(); - for (String paramKey : dstParamKeySet) { - if (!srcBag.hasParameter(paramKey)) { - Parameter dstParam = dstBag.getParameter(paramKey); - this.mismatchedLocators.add(dstParam.getLocator()); - } - } - } + protected void deepEquals(ParameterBag srcBag, ParameterBag dstBag) { + deepEquals((StrolchElement) srcBag, (StrolchElement) dstBag); - protected void deepEquals(Parameter srcParam, Parameter dstParam) { - deepEquals((StrolchElement) srcParam, (StrolchElement) dstParam); - if (!srcParam.getUom().equals(dstParam.getUom())) - this.mismatchedLocators.add(dstParam.getLocator()); - if (!srcParam.getInterpretation().equals(dstParam.getInterpretation())) - this.mismatchedLocators.add(dstParam.getLocator()); - if (srcParam.isHidden() != dstParam.isHidden()) - this.mismatchedLocators.add(dstParam.getLocator()); - if (srcParam.getIndex() != dstParam.getIndex()) - this.mismatchedLocators.add(dstParam.getLocator()); + Set srcParamKeySet = srcBag.getParameterKeySet(); + for (String paramKey : srcParamKeySet) { + Parameter srcParam = srcBag.getParameter(paramKey); + if (!dstBag.hasParameter(paramKey)) { + this.mismatchedLocators.add(srcParam.getLocator()); + continue; + } - if (!srcParam.getValue().equals(dstParam.getValue())) - this.mismatchedLocators.add(dstParam.getLocator()); - } + Parameter dstParam = dstBag.getParameter(paramKey); + deepEquals(srcParam, dstParam); + } - public static boolean isEqual(Order srcOrder, Order dstOrder) { - OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(srcOrder); - visitor.visit(srcOrder); - return visitor.isEqual(); - } + Set dstParamKeySet = dstBag.getParameterKeySet(); + for (String paramKey : dstParamKeySet) { + if (!srcBag.hasParameter(paramKey)) { + Parameter dstParam = dstBag.getParameter(paramKey); + this.mismatchedLocators.add(dstParam.getLocator()); + } + } + } - public static boolean isEqual(Resource srcRes, Resource dstRes) { - ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes); - visitor.visit(srcRes); - return visitor.isEqual(); - } + protected void deepEquals(Parameter srcParam, Parameter dstParam) { + deepEquals((StrolchElement) srcParam, (StrolchElement) dstParam); + if (!srcParam.getUom().equals(dstParam.getUom())) { + this.mismatchedLocators.add(dstParam.getLocator()); + } + if (!srcParam.getInterpretation().equals(dstParam.getInterpretation())) { + this.mismatchedLocators.add(dstParam.getLocator()); + } + if (srcParam.isHidden() != dstParam.isHidden()) { + this.mismatchedLocators.add(dstParam.getLocator()); + } + if (srcParam.getIndex() != dstParam.getIndex()) { + this.mismatchedLocators.add(dstParam.getLocator()); + } + + if (!srcParam.getValue().equals(dstParam.getValue())) { + this.mismatchedLocators.add(dstParam.getLocator()); + } + } + + protected void deepEquals(StrolchTimedState srcState, StrolchTimedState dstState) { + deepEquals((StrolchElement) srcState, (StrolchElement) dstState); + final ITimeVariable srcTimeEvolution = srcState.getTimeEvolution(); + final ITimeVariable dstTimeEvolution = dstState.getTimeEvolution(); + + if (!srcTimeEvolution.getValues().equals(dstTimeEvolution.getValues())) { + this.mismatchedLocators.add(dstState.getLocator()); + } + } + + public static boolean isEqual(Order srcOrder, Order dstOrder) { + OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(srcOrder); + visitor.visit(dstOrder); + return visitor.isEqual(); + } + + public static boolean isEqual(Resource srcRes, Resource dstRes) { + ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes); + visitor.visit(dstRes); + return visitor.isEqual(); + } } diff --git a/src/test/java/li/strolch/model/ModelTest.java b/src/test/java/li/strolch/model/ModelTest.java index c703c9aca..8046ce698 100644 --- a/src/test/java/li/strolch/model/ModelTest.java +++ b/src/test/java/li/strolch/model/ModelTest.java @@ -30,6 +30,9 @@ import li.strolch.model.parameter.IntegerParameter; import li.strolch.model.parameter.LongParameter; import li.strolch.model.parameter.StringListParameter; import li.strolch.model.parameter.StringParameter; +import li.strolch.model.timedstate.BooleanTimedState; +import li.strolch.model.timevalue.impl.BooleanValue; +import li.strolch.model.timevalue.impl.ValueChange; import li.strolch.model.visitor.OrderDeepEqualsVisitor; import li.strolch.model.visitor.ResourceDeepEqualsVisitor; @@ -38,99 +41,112 @@ import org.junit.Test; @SuppressWarnings("nls") public class ModelTest { - @Test - public void shouldCreateResource() { + @Test + public void shouldCreateResource() { - Resource resource = ModelGenerator.createResource("@res01", "Test resource", "MyType"); - ParameterBag bag = resource.getParameterBag(ModelGenerator.BAG_ID); - validateBag(bag); - } + Resource resource = ModelGenerator.createResource("@res01", "Test resource", "MyType"); + ParameterBag bag = resource.getParameterBag(ModelGenerator.BAG_ID); + validateBag(bag); + } - @Test - public void shouldCreateOrder() { + @Test + public void shouldCreateOrder() { - Order order = ModelGenerator.createOrder("@ord01", "Test Order", "MyType", new Date(), State.OPEN); - ParameterBag bag = order.getParameterBag(ModelGenerator.BAG_ID); - validateBag(bag); - } + Order order = ModelGenerator.createOrder("@ord01", "Test Order", "MyType", new Date(), State.OPEN); + ParameterBag bag = order.getParameterBag(ModelGenerator.BAG_ID); + validateBag(bag); + } - @Test - public void shouldPerformDeepResourceEquals() { - Resource srcRes = ModelGenerator.createResource("@res01", "Test resource", "MyType"); - Resource dstRes = ModelGenerator.createResource("@res01", "Test resource", "MyType"); - ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes); - visitor.visit(dstRes); - assertTrue("Same Resource should be deep equal!", visitor.isEqual()); - } + @Test + public void shouldPerformDeepResourceEquals() { + Resource srcRes = ModelGenerator.createResource("@res01", "Test resource", "MyType"); + Resource dstRes = ModelGenerator.createResource("@res01", "Test resource", "MyType"); + ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes); + visitor.visit(dstRes); + assertTrue("Same Resource should be deep equal!", visitor.isEqual()); + } - @Test - public void shouldFailDeepResourceEquals1() { - Resource srcRes = ModelGenerator.createResource("@res01", "Test resource", "MyType"); - Resource dstRes = ModelGenerator.createResource("@res01", "Test resource", "MyType"); - ParameterBag bag = dstRes.getParameterBag(ModelGenerator.BAG_ID); - bag.setName("Bla bla"); - FloatParameter fParam = bag.getParameter(ModelGenerator.PARAM_FLOAT_ID); - fParam.setValue(23434234.234); - fParam.setName("Ohla"); - ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes); - visitor.visit(dstRes); - assertFalse("Resource should not be same if param is changed!", visitor.isEqual()); - assertEquals("Three changes should be registered", 3, visitor.getMismatchedLocators().size()); - } + @Test + public void shouldFailDeepResourceEquals1() { + Resource srcRes = ModelGenerator.createResource("@res01", "Test resource", "MyType"); + Resource dstRes = ModelGenerator.createResource("@res01", "Test resource", "MyType"); + ParameterBag bag = dstRes.getParameterBag(ModelGenerator.BAG_ID); + bag.setName("Bla bla"); + FloatParameter fParam = bag.getParameter(ModelGenerator.PARAM_FLOAT_ID); + fParam.setValue(23434234.234); + fParam.setName("Ohla"); + ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes); + visitor.visit(dstRes); + assertFalse("Resource should not be same if param is changed!", visitor.isEqual()); + assertEquals("Three changes should be registered", 3, visitor.getMismatchedLocators().size()); + } - @Test - public void shouldPerformDeepOrderEquals() { - Date date = new Date(); - Order srcOrder = ModelGenerator.createOrder("@ord01", "Test Order", "MyType", date, State.OPEN); - Order dstOrder = ModelGenerator.createOrder("@ord01", "Test Order", "MyType", date, State.OPEN); - OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(srcOrder); - visitor.visit(dstOrder); - assertTrue("Same Order should be deep equal: " + visitor.getMismatchedLocators(), visitor.isEqual()); - } + @Test + public void shouldFailDeepResourceEquals2() { + Resource srcRes = ModelGenerator.createResource("@res01", "Test resource", "MyType"); + Resource dstRes = ModelGenerator.createResource("@res01", "Test resource", "MyType"); + BooleanTimedState timedState = dstRes.getTimedState(ModelGenerator.STATE_BOOLEAN_ID); + timedState.applyChange(new ValueChange<>(System.currentTimeMillis(), new BooleanValue(Boolean.TRUE))); + timedState.setName("Ohla"); + ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes); + visitor.visit(dstRes); + assertFalse("Resource should not be same if param is changed!", visitor.isEqual()); + assertEquals("One change should be registered!", 1, visitor.getMismatchedLocators().size()); + } - public static void validateBag(ParameterBag bag) { + @Test + public void shouldPerformDeepOrderEquals() { + Date date = new Date(); + Order srcOrder = ModelGenerator.createOrder("@ord01", "Test Order", "MyType", date, State.OPEN); + Order dstOrder = ModelGenerator.createOrder("@ord01", "Test Order", "MyType", date, State.OPEN); + OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(srcOrder); + visitor.visit(dstOrder); + assertTrue("Same Order should be deep equal: " + visitor.getMismatchedLocators(), visitor.isEqual()); + } - assertNotNull(bag); + public static void validateBag(ParameterBag bag) { - assertEquals(ModelGenerator.BAG_ID, bag.getId()); - assertEquals(ModelGenerator.BAG_NAME, bag.getName()); - assertEquals(ModelGenerator.BAG_TYPE, bag.getType()); + assertNotNull(bag); - validateParams(bag); - } + assertEquals(ModelGenerator.BAG_ID, bag.getId()); + assertEquals(ModelGenerator.BAG_NAME, bag.getName()); + assertEquals(ModelGenerator.BAG_TYPE, bag.getType()); - public static void validateParams(ParameterBag bag) { + validateParams(bag); + } - BooleanParameter boolParam = bag.getParameter(ModelGenerator.PARAM_BOOLEAN_ID); - assertNotNull("Boolean Param missing with id " + ModelGenerator.PARAM_BOOLEAN_ID, boolParam); - assertEquals(true, boolParam.getValue().booleanValue()); + public static void validateParams(ParameterBag bag) { - FloatParameter floatParam = bag.getParameter(ModelGenerator.PARAM_FLOAT_ID); - assertNotNull("Float Param missing with id " + ModelGenerator.PARAM_FLOAT_ID, floatParam); - assertEquals(44.3, floatParam.getValue().doubleValue(), 0.0001); + BooleanParameter boolParam = bag.getParameter(ModelGenerator.PARAM_BOOLEAN_ID); + assertNotNull("Boolean Param missing with id " + ModelGenerator.PARAM_BOOLEAN_ID, boolParam); + assertEquals(true, boolParam.getValue().booleanValue()); - IntegerParameter integerParam = bag.getParameter(ModelGenerator.PARAM_INTEGER_ID); - assertNotNull("Integer Param missing with id " + ModelGenerator.PARAM_INTEGER_ID, integerParam); - assertEquals(77, integerParam.getValue().intValue()); + FloatParameter floatParam = bag.getParameter(ModelGenerator.PARAM_FLOAT_ID); + assertNotNull("Float Param missing with id " + ModelGenerator.PARAM_FLOAT_ID, floatParam); + assertEquals(44.3, floatParam.getValue().doubleValue(), 0.0001); - LongParameter longParam = bag.getParameter(ModelGenerator.PARAM_LONG_ID); - assertNotNull("Long Param missing with id " + ModelGenerator.PARAM_LONG_ID, longParam); - assertEquals(4453234566L, longParam.getValue().longValue()); + IntegerParameter integerParam = bag.getParameter(ModelGenerator.PARAM_INTEGER_ID); + assertNotNull("Integer Param missing with id " + ModelGenerator.PARAM_INTEGER_ID, integerParam); + assertEquals(77, integerParam.getValue().intValue()); - StringParameter stringParam = bag.getParameter(ModelGenerator.PARAM_STRING_ID); - assertNotNull("String Param missing with id " + ModelGenerator.PARAM_STRING_ID, stringParam); - assertEquals("Strolch", stringParam.getValue()); + LongParameter longParam = bag.getParameter(ModelGenerator.PARAM_LONG_ID); + assertNotNull("Long Param missing with id " + ModelGenerator.PARAM_LONG_ID, longParam); + assertEquals(4453234566L, longParam.getValue().longValue()); - DateParameter dateParam = bag.getParameter(ModelGenerator.PARAM_DATE_ID); - assertNotNull("Date Param missing with id " + ModelGenerator.PARAM_DATE_ID, dateParam); - assertEquals(1354295525628L, dateParam.getValue().getTime()); + StringParameter stringParam = bag.getParameter(ModelGenerator.PARAM_STRING_ID); + assertNotNull("String Param missing with id " + ModelGenerator.PARAM_STRING_ID, stringParam); + assertEquals("Strolch", stringParam.getValue()); - StringListParameter stringListP = bag.getParameter(ModelGenerator.PARAM_LIST_STRING_ID); - assertNotNull("StringList Param missing with id " + ModelGenerator.PARAM_LIST_STRING_ID, stringListP); + DateParameter dateParam = bag.getParameter(ModelGenerator.PARAM_DATE_ID); + assertNotNull("Date Param missing with id " + ModelGenerator.PARAM_DATE_ID, dateParam); + assertEquals(1354295525628L, dateParam.getValue().getTime()); - ArrayList stringList = new ArrayList(); - stringList.add("Hello"); - stringList.add("World"); - assertEquals(stringList, stringListP.getValue()); - } + StringListParameter stringListP = bag.getParameter(ModelGenerator.PARAM_LIST_STRING_ID); + assertNotNull("StringList Param missing with id " + ModelGenerator.PARAM_LIST_STRING_ID, stringListP); + + ArrayList stringList = new ArrayList<>(); + stringList.add("Hello"); + stringList.add("World"); + assertEquals(stringList, stringListP.getValue()); + } } diff --git a/src/test/java/li/strolch/model/XmlToDomTest.java b/src/test/java/li/strolch/model/XmlToDomTest.java index 76e543665..315e17065 100644 --- a/src/test/java/li/strolch/model/XmlToDomTest.java +++ b/src/test/java/li/strolch/model/XmlToDomTest.java @@ -15,51 +15,55 @@ */ package li.strolch.model; -import static org.junit.Assert.assertTrue; -import li.strolch.model.visitor.StrolchElementDeepEqualsVisitor; +import li.strolch.model.visitor.OrderDeepEqualsVisitor; +import li.strolch.model.visitor.ResourceDeepEqualsVisitor; import li.strolch.model.xml.OrderToDomVisitor; import li.strolch.model.xml.ResourceToDomVisitor; - +import static org.junit.Assert.assertTrue; import org.junit.Test; import org.w3c.dom.Document; import org.w3c.dom.Element; /** * @author Robert von Burg - * + * */ @SuppressWarnings("nls") public class XmlToDomTest extends ModelTest { - @Test - public void shouldFormatAndParseOrder() { + @Test + public void shouldFormatAndParseOrder() { - Order order = ModelGenerator.createOrder("@1", "My Order 1", "MyOrder"); + Order order = ModelGenerator.createOrder("@1", "My Order 1", "MyOrder"); - OrderToDomVisitor domVisitor = new OrderToDomVisitor(); - domVisitor.visit(order); - Document document = domVisitor.getDocument(); + OrderToDomVisitor domVisitor = new OrderToDomVisitor(); + domVisitor.visit(order); + Document document = domVisitor.getDocument(); - Element rootElement = document.getDocumentElement(); - Order parsedOrder = new Order(rootElement); + Element rootElement = document.getDocumentElement(); + Order parsedOrder = new Order(rootElement); - assertTrue("To DOM and back should equal same Order!", - StrolchElementDeepEqualsVisitor.isEqual(order, parsedOrder)); - } + OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(order); + visitor.visit(parsedOrder); + assertTrue("To DOM and back should equal same Order:\n" + visitor.getMismatchedLocators(), + visitor.isEqual()); + } - @Test - public void shouldFormatAndParseResource() { + @Test + public void shouldFormatAndParseResource() { - Resource resource = ModelGenerator.createResource("@1", "My Resource 1", "MyResource"); + Resource resource = ModelGenerator.createResource("@1", "My Resource 1", "MyResource"); - ResourceToDomVisitor domVisitor = new ResourceToDomVisitor(); - domVisitor.visit(resource); - Document document = domVisitor.getDocument(); + ResourceToDomVisitor domVisitor = new ResourceToDomVisitor(); + domVisitor.visit(resource); + Document document = domVisitor.getDocument(); - Element rootElement = document.getDocumentElement(); - Resource parsedResource = new Resource(rootElement); + Element rootElement = document.getDocumentElement(); + Resource parsedResource = new Resource(rootElement); - assertTrue("To DOM and back should equal same Resource!", - StrolchElementDeepEqualsVisitor.isEqual(resource, parsedResource)); - } + ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(resource); + visitor.visit(parsedResource); + assertTrue("To DOM and back should equal same Resource:\n" + visitor.getMismatchedLocators(), + visitor.isEqual()); + } } diff --git a/src/test/java/li/strolch/model/timedstate/StrolchTimedStateTest.java b/src/test/java/li/strolch/model/timedstate/StrolchTimedStateTest.java new file mode 100644 index 000000000..6d10aa4cb --- /dev/null +++ b/src/test/java/li/strolch/model/timedstate/StrolchTimedStateTest.java @@ -0,0 +1,117 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.timedstate; + +import java.util.HashSet; +import java.util.Set; +import li.strolch.model.ModelGenerator; +import li.strolch.model.Resource; +import li.strolch.model.timevalue.ITimeValue; +import li.strolch.model.timevalue.impl.AString; +import li.strolch.model.timevalue.impl.BooleanValue; +import li.strolch.model.timevalue.impl.FloatValue; +import li.strolch.model.timevalue.impl.IntegerValue; +import li.strolch.model.timevalue.impl.StringSetValue; +import static org.junit.Assert.assertEquals; +import org.junit.Test; + +/** + * @author Robert von Burg + */ +public class StrolchTimedStateTest { + + @Test + public void testFloatState() { + + Resource myRes = ModelGenerator.createResource("@1", "Test With States", "Stated"); + + FloatTimedState floatState = myRes.getTimedState(ModelGenerator.STATE_FLOAT_ID); + ITimeValue valueAt0 = floatState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_0); + assertEquals(ModelGenerator.STATE_FLOAT_TIME_0, valueAt0.getValue().getValue()); + + ITimeValue valueAt10 = floatState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_10); + assertEquals(ModelGenerator.STATE_FLOAT_TIME_10, valueAt10.getValue().getValue()); + + ITimeValue valueAt20 = floatState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_20); + assertEquals(ModelGenerator.STATE_FLOAT_TIME_20, valueAt20.getValue().getValue()); + + ITimeValue valueAt30 = floatState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_30); + assertEquals(ModelGenerator.STATE_FLOAT_TIME_30, valueAt30.getValue().getValue()); + } + + @Test + public void testIntegerState() { + + Resource myRes = ModelGenerator.createResource("@1", "Test With States", "Stated"); + + IntegerTimedState integerState = myRes.getTimedState(ModelGenerator.STATE_INTEGER_ID); + ITimeValue valueAt0 = integerState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_0); + assertEquals(ModelGenerator.STATE_INTEGER_TIME_0, valueAt0.getValue().getValue()); + + ITimeValue valueAt10 = integerState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_10); + assertEquals(ModelGenerator.STATE_INTEGER_TIME_10, valueAt10.getValue().getValue()); + + ITimeValue valueAt20 = integerState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_20); + assertEquals(ModelGenerator.STATE_INTEGER_TIME_20, valueAt20.getValue().getValue()); + + ITimeValue valueAt30 = integerState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_30); + assertEquals(ModelGenerator.STATE_INTEGER_TIME_30, valueAt30.getValue().getValue()); + } + + @Test + public void testBooleanState() { + + Resource myRes = ModelGenerator.createResource("@1", "Test With States", "Stated"); + + BooleanTimedState booleanState = myRes.getTimedState(ModelGenerator.STATE_BOOLEAN_ID); + ITimeValue valueAt0 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_0); + assertEquals(ModelGenerator.STATE_BOOLEAN_TIME_0, valueAt0.getValue().getValue()); + + ITimeValue valueAt10 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_10); + assertEquals(ModelGenerator.STATE_BOOLEAN_TIME_10, valueAt10.getValue().getValue()); + + ITimeValue valueAt20 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_20); + assertEquals(ModelGenerator.STATE_BOOLEAN_TIME_20, valueAt20.getValue().getValue()); + + ITimeValue valueAt30 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_30); + assertEquals(ModelGenerator.STATE_BOOLEAN_TIME_30, valueAt30.getValue().getValue()); + } + + @Test + public void testStringSetState() { + + Resource myRes = ModelGenerator.createResource("@1", "Test With States", "Stated"); + + StringSetTimedState booleanState = myRes.getTimedState(ModelGenerator.STATE_STRING_ID); + ITimeValue valueAt0 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_0); + assertEquals(asSet(ModelGenerator.STATE_STRING_TIME_0), valueAt0.getValue().getValue()); + + ITimeValue valueAt10 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_10); + assertEquals(asSet(ModelGenerator.STATE_STRING_TIME_10), valueAt10.getValue().getValue()); + + ITimeValue valueAt20 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_20); + assertEquals(asSet(ModelGenerator.STATE_STRING_TIME_20), valueAt20.getValue().getValue()); + + ITimeValue valueAt30 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_30); + assertEquals(asSet(ModelGenerator.STATE_STRING_TIME_30), valueAt30.getValue().getValue()); + } + + private static Set asSet(String value) { + HashSet hashSet = new HashSet<>(); + hashSet.add(new AString(value)); + return hashSet; + } +} diff --git a/src/test/java/li/strolch/model/timedstate/TimeStateTest.java b/src/test/java/li/strolch/model/timedstate/TimeStateTest.java index d91d9efa0..2654fb216 100644 --- a/src/test/java/li/strolch/model/timedstate/TimeStateTest.java +++ b/src/test/java/li/strolch/model/timedstate/TimeStateTest.java @@ -20,7 +20,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import li.strolch.model.timevalue.ITimeValue; import li.strolch.model.timevalue.IValueChange; -import li.strolch.model.timevalue.impl.DoubleValue; +import li.strolch.model.timevalue.impl.FloatValue; import li.strolch.model.timevalue.impl.ValueChange; import org.junit.Before; @@ -28,10 +28,10 @@ import org.junit.Test; public class TimeStateTest { - private ITimedState state = new TimedState(); + private ITimedState state = new TimedState(); - final DoubleValue expectedValue1 = new DoubleValue(Double.valueOf(100D)); - final DoubleValue expectedValue2 = new DoubleValue(Double.valueOf(200D)); + final FloatValue expectedValue1 = new FloatValue(Double.valueOf(100D)); + final FloatValue expectedValue2 = new FloatValue(Double.valueOf(200D)); final Long t0 = Long.valueOf(0); final Long t10 = Long.valueOf(10); @@ -42,20 +42,20 @@ public class TimeStateTest { @Before public void before() { - final IValueChange change1 = new ValueChange(this.t10, this.expectedValue1); + final IValueChange change1 = new ValueChange(this.t10, this.expectedValue1); this.state.applyChange(change1); - final ITimeValue stateAt9 = this.state.getStateAt(9L); + final ITimeValue stateAt9 = this.state.getStateAt(9L); assertNull(stateAt9); - final ITimeValue stateAt11 = this.state.getStateAt(11L); + final ITimeValue stateAt11 = this.state.getStateAt(11L); assertNotNull(stateAt11); assertEquals(true, stateAt11.getValue().matches(this.expectedValue1)); - final IValueChange change2 = new ValueChange(this.t30, this.expectedValue1); + final IValueChange change2 = new ValueChange(this.t30, this.expectedValue1); this.state.applyChange(change2); - final ITimeValue stateAt31 = this.state.getStateAt(31L); + final ITimeValue stateAt31 = this.state.getStateAt(31L); assertNotNull(stateAt31); assertEquals(true, stateAt31.getValue().matches(this.expectedValue2)); } @@ -63,7 +63,7 @@ public class TimeStateTest { @Test public void testGetNextMatch() { - ITimeValue nextMatch = this.state.getNextMatch(this.t0, this.expectedValue1); + ITimeValue nextMatch = this.state.getNextMatch(this.t0, this.expectedValue1); assertNotNull(nextMatch); assertEquals(this.t10, nextMatch.getTime()); @@ -89,7 +89,7 @@ public class TimeStateTest { @Test public void testGetPreviousMatch() { - ITimeValue previousMatch = this.state.getPreviousMatch(this.t100, this.expectedValue2); + ITimeValue previousMatch = this.state.getPreviousMatch(this.t100, this.expectedValue2); assertNotNull(previousMatch); assertEquals(this.t30, previousMatch.getTime()); diff --git a/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java b/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java index 0f788d2ca..3b3f218a9 100644 --- a/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java +++ b/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java @@ -22,7 +22,7 @@ import static org.junit.Assert.assertTrue; import java.util.Collection; import java.util.SortedSet; -import li.strolch.model.timevalue.impl.DoubleValue; +import li.strolch.model.timevalue.impl.FloatValue; import li.strolch.model.timevalue.impl.TimeVariable; import li.strolch.model.timevalue.impl.ValueChange; @@ -35,22 +35,22 @@ public class FloatTimeVariableTest { private static final Long STEP = 10L; private static final Long PICK = 50L; - private TimeVariable timeVariable; + private TimeVariable timeVariable; /** * set the values ascending with a difference of STEP */ @Before public void init() { - this.timeVariable = new TimeVariable(); + this.timeVariable = new TimeVariable(); for (long i = 0; i < MAX; i += STEP) { - this.timeVariable.setValueAt(Long.valueOf(i), new DoubleValue(i)); + this.timeVariable.setValueAt(Long.valueOf(i), new FloatValue(i)); } } @Test public void testGetValueAt() { - ITimeValue valueAt = this.timeVariable.getValueAt(PICK); + ITimeValue valueAt = this.timeVariable.getValueAt(PICK); assertEquals(PICK.doubleValue(), valueAt.getValue().getValue(), 0.0001); } @@ -59,12 +59,12 @@ public class FloatTimeVariableTest { */ @Test public void testGetFutureValues() { - Collection> futureValues = this.timeVariable.getFutureValues(PICK); + Collection> futureValues = this.timeVariable.getFutureValues(PICK); Long expectedTime = PICK; Double expectedValue = PICK.doubleValue(); - for (ITimeValue value : futureValues) { + for (ITimeValue value : futureValues) { assertEquals(expectedTime, value.getTime()); - assertTrue(value.getValue().matches(new DoubleValue(expectedValue))); + assertTrue(value.getValue().matches(new FloatValue(expectedValue))); expectedTime += STEP; expectedValue += STEP.doubleValue(); } @@ -76,12 +76,12 @@ public class FloatTimeVariableTest { */ @Test public void testGetPastValues() { - Collection> pastValues = this.timeVariable.getPastValues(MAX); + Collection> pastValues = this.timeVariable.getPastValues(MAX); Long expectedTime = 0L; Double expectedValue = expectedTime.doubleValue(); - for (ITimeValue value : pastValues) { + for (ITimeValue value : pastValues) { assertEquals(expectedTime, value.getTime()); - assertTrue(value.getValue().matches(new DoubleValue(expectedValue))); + assertTrue(value.getValue().matches(new FloatValue(expectedValue))); expectedTime += STEP; expectedValue += STEP.doubleValue(); } @@ -93,17 +93,17 @@ public class FloatTimeVariableTest { @Test public void testApplyChange() { - DoubleValue doubleValue = new DoubleValue(STEP.doubleValue()); + FloatValue doubleValue = new FloatValue(STEP.doubleValue()); - IValueChange change = new ValueChange(PICK, doubleValue); + IValueChange change = new ValueChange(PICK, doubleValue); this.timeVariable.applyChange(change); - Collection> futureValues = this.timeVariable.getFutureValues(PICK); + Collection> futureValues = this.timeVariable.getFutureValues(PICK); Long expectedTime = PICK; - IValue expectedValue = new DoubleValue(PICK.doubleValue() + change.getValue().getValue()); + IValue expectedValue = new FloatValue(PICK.doubleValue() + change.getValue().getValue()); - for (ITimeValue value : futureValues) { + for (ITimeValue value : futureValues) { assertEquals(expectedTime, value.getTime()); assertTrue(expectedValue.matches(value.getValue())); expectedTime += STEP; @@ -117,17 +117,17 @@ public class FloatTimeVariableTest { @Test public void testApply2Change() { - this.timeVariable = new TimeVariable(); + this.timeVariable = new TimeVariable(); - DoubleValue doubleValue = new DoubleValue(STEP.doubleValue()); + FloatValue doubleValue = new FloatValue(STEP.doubleValue()); - IValueChange change = new ValueChange(PICK, doubleValue); + IValueChange change = new ValueChange(PICK, doubleValue); this.timeVariable.applyChange(change); - ITimeValue actual = this.timeVariable.getValueAt(PICK); + ITimeValue actual = this.timeVariable.getValueAt(PICK); assertNotNull(actual); - IValue expectedValue = new DoubleValue(STEP.doubleValue()); + IValue expectedValue = new FloatValue(STEP.doubleValue()); assertEquals(true, actual.getValue().matches(expectedValue)); } @@ -138,14 +138,14 @@ public class FloatTimeVariableTest { @Test public void testCompact() { - this.timeVariable = new TimeVariable(); + this.timeVariable = new TimeVariable(); for (Long i = 0L; i < MAX; i += STEP) { - this.timeVariable.setValueAt(i, new DoubleValue(STEP.doubleValue())); + this.timeVariable.setValueAt(i, new FloatValue(STEP.doubleValue())); } // call this.timeVariable.compact(); // check - SortedSet> futureValues = this.timeVariable.getFutureValues(0L); + SortedSet> futureValues = this.timeVariable.getFutureValues(0L); assertEquals(1, futureValues.size()); } diff --git a/src/test/java/li/strolch/model/timevalue/ValueTests.java b/src/test/java/li/strolch/model/timevalue/ValueTests.java index ed0991a3d..0be352166 100644 --- a/src/test/java/li/strolch/model/timevalue/ValueTests.java +++ b/src/test/java/li/strolch/model/timevalue/ValueTests.java @@ -21,7 +21,7 @@ import java.util.HashSet; import java.util.Set; import li.strolch.model.timevalue.impl.AString; -import li.strolch.model.timevalue.impl.DoubleValue; +import li.strolch.model.timevalue.impl.FloatValue; import li.strolch.model.timevalue.impl.IntegerValue; import li.strolch.model.timevalue.impl.StringSetValue; @@ -34,8 +34,8 @@ public class ValueTests { */ @Test public void testDoubleInverse() { - DoubleValue value = new DoubleValue(10.0d); - DoubleValue inverse = value.getInverse(); + FloatValue value = new FloatValue(10.0d); + FloatValue inverse = value.getInverse(); assertEquals(Double.valueOf(-10.0d), inverse.getValue()); assertEquals(Double.valueOf(0), value.add(inverse.getValue()).getValue()); } From 95117bdf8884e62395cb1d87907bcb6f24408f15 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 24 Mar 2014 15:35:13 +0100 Subject: [PATCH 60/88] [Minor] NetBeans didn't play nice... now using tabs, instead of spaces --- .../strolch/exception/StrolchException.java | 2 +- .../strolch/model/AbstractStrolchElement.java | 33 +- .../model/GroupedParameterizedElement.java | 117 ++-- src/main/java/li/strolch/model/Locator.java | 138 +++-- .../java/li/strolch/model/ModelGenerator.java | 506 +++++++++--------- src/main/java/li/strolch/model/Order.java | 16 +- .../java/li/strolch/model/ParameterBag.java | 5 +- .../strolch/model/ParameterizedElement.java | 442 +++++++-------- src/main/java/li/strolch/model/Resource.java | 282 +++++----- .../li/strolch/model/ResourceVisitor.java | 2 +- .../java/li/strolch/model/StrolchElement.java | 27 +- .../li/strolch/model/StrolchRootElement.java | 2 +- src/main/java/li/strolch/model/Tags.java | 2 +- .../model/parameter/AbstractParameter.java | 28 +- .../model/parameter/BooleanParameter.java | 4 +- .../model/parameter/DateParameter.java | 4 +- .../model/parameter/FloatParameter.java | 6 +- .../model/parameter/IntegerParameter.java | 6 +- .../model/parameter/ListParameter.java | 14 +- .../model/parameter/LongParameter.java | 6 +- .../li/strolch/model/parameter/Parameter.java | 29 +- .../model/parameter/StringListParameter.java | 16 +- .../model/parameter/StringParameter.java | 8 +- .../li/strolch/model/query/Navigation.java | 4 +- .../li/strolch/model/query/NotSelection.java | 3 +- .../model/query/OrderQueryVisitor.java | 2 +- .../strolch/model/query/OrderSelection.java | 4 +- .../model/query/OrderSelectionVisitor.java | 2 +- .../model/query/ParameterSelection.java | 5 + .../query/ParameterSelectionVisitor.java | 2 +- .../java/li/strolch/model/query/Query.java | 3 +- .../li/strolch/model/query/QueryVisitor.java | 2 +- .../model/query/ResourceQueryVisitor.java | 2 +- .../li/strolch/model/query/Selection.java | 1 - .../strolch/model/query/StateSelection.java | 2 +- .../model/query/StrolchTypeNavigation.java | 2 +- .../timedstate/AbstractStrolchTimedState.java | 146 ++--- .../model/timedstate/BooleanTimedState.java | 90 ++-- .../model/timedstate/FloatTimedState.java | 90 ++-- .../strolch/model/timedstate/ITimedState.java | 12 +- .../model/timedstate/IntegerTimedState.java | 90 ++-- .../model/timedstate/StringSetTimedState.java | 120 ++--- .../model/timedstate/StrolchTimedState.java | 2 +- .../strolch/model/timevalue/ITimeValue.java | 7 +- .../model/timevalue/ITimeVariable.java | 32 +- .../li/strolch/model/timevalue/IValue.java | 14 +- .../strolch/model/timevalue/IValueChange.java | 8 +- .../strolch/model/timevalue/impl/AString.java | 27 +- .../model/timevalue/impl/BooleanValue.java | 17 +- .../model/timevalue/impl/FloatValue.java | 22 +- .../model/timevalue/impl/IntegerValue.java | 17 +- .../model/timevalue/impl/StringSetValue.java | 136 ++--- .../model/timevalue/impl/TimeValue.java | 21 +- .../model/timevalue/impl/TimeVariable.java | 3 +- .../model/timevalue/impl/ValueChange.java | 21 +- .../StrolchElementDeepEqualsVisitor.java | 256 ++++----- .../strolch/model/visitor/StrolchVisitor.java | 2 +- .../model/xml/AbstractToSaxWriterVisitor.java | 20 +- .../xml/SimpleStrolchElementListener.java | 6 +- .../model/xml/StrolchElementListener.java | 2 +- .../model/xml/StrolchElementToDomVisitor.java | 12 +- .../model/xml/XmlModelSaxFileReader.java | 39 +- .../strolch/model/xml/XmlModelSaxReader.java | 218 ++++---- src/test/java/li/strolch/model/ModelTest.java | 174 +++--- .../model/XmlModelDefaultHandlerTest.java | 2 +- .../java/li/strolch/model/XmlToDomTest.java | 52 +- .../timedstate/StrolchTimedStateTest.java | 114 ++-- .../timevalue/FloatTimeVariableTest.java | 12 +- .../timevalue/IntegerTimeVariableTest.java | 2 +- 69 files changed, 1770 insertions(+), 1745 deletions(-) diff --git a/src/main/java/li/strolch/exception/StrolchException.java b/src/main/java/li/strolch/exception/StrolchException.java index cb5114bf7..67c43b706 100644 --- a/src/main/java/li/strolch/exception/StrolchException.java +++ b/src/main/java/li/strolch/exception/StrolchException.java @@ -17,7 +17,7 @@ package li.strolch.exception; /** * @author Robert von Burg - * + * */ public class StrolchException extends RuntimeException { diff --git a/src/main/java/li/strolch/model/AbstractStrolchElement.java b/src/main/java/li/strolch/model/AbstractStrolchElement.java index a2d4c000a..e554331ea 100644 --- a/src/main/java/li/strolch/model/AbstractStrolchElement.java +++ b/src/main/java/li/strolch/model/AbstractStrolchElement.java @@ -44,11 +44,9 @@ public abstract class AbstractStrolchElement implements StrolchElement { /** * Default constructor - * - * @param id - * id of this {@link StrolchElement} - * @param name - * name of this {@link StrolchElement} + * + * @param id id of this {@link StrolchElement} + * @param name name of this {@link StrolchElement} */ public AbstractStrolchElement(String id, String name) { setId(id); @@ -98,15 +96,15 @@ public abstract class AbstractStrolchElement implements StrolchElement { /** * Used to build a {@link Locator} for this {@link StrolchElement}. It must be implemented by the concrete * implemented as parents must first add their {@link Locator} information - * - * @param locatorBuilder - * the {@link LocatorBuilder} to which the {@link StrolchElement} must add its locator information + * + * @param locatorBuilder the {@link LocatorBuilder} to which the {@link StrolchElement} must add its locator + * information */ protected abstract void fillLocator(LocatorBuilder locatorBuilder); /** * fills the {@link StrolchElement} clone with the id, name and type - * + * * @param clone */ protected void fillClone(StrolchElement clone) { @@ -122,7 +120,7 @@ public abstract class AbstractStrolchElement implements StrolchElement { /** * Builds the fields of this {@link StrolchElement} from a {@link Element} - * + * * @param element */ protected void fromDom(Element element) { @@ -149,18 +147,23 @@ public abstract class AbstractStrolchElement implements StrolchElement { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } AbstractStrolchElement other = (AbstractStrolchElement) obj; if (this.id == null) { - if (other.id != null) + if (other.id != null) { return false; - } else if (!this.id.equals(other.id)) + } + } else if (!this.id.equals(other.id)) { return false; + } return true; } diff --git a/src/main/java/li/strolch/model/GroupedParameterizedElement.java b/src/main/java/li/strolch/model/GroupedParameterizedElement.java index 16e7f04d6..aef6552fd 100644 --- a/src/main/java/li/strolch/model/GroupedParameterizedElement.java +++ b/src/main/java/li/strolch/model/GroupedParameterizedElement.java @@ -49,7 +49,7 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement /** * Default Constructor - * + * * @param id * @param name * @param type @@ -66,9 +66,8 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement /** * Sets the type of this {@link GroupedParameterizedElement} - * - * @param type - * the type to set + * + * @param type the type to set */ public void setType(String type) { if (StringHelper.isEmpty(type)) { @@ -83,38 +82,36 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement /** * Returns the {@link Parameter} with the given key from the {@link ParameterBag} with the given bagKey, or null if * the {@link Parameter} or the {@link ParameterBag} does not exist - * - * @param bagKey - * the key of the {@link ParameterBag} from which the {@link Parameter} is to be returned - * @param paramKey - * the key of the {@link Parameter} which is to be returned - * + * + * @param bagKey the key of the {@link ParameterBag} from which the {@link Parameter} is to be returned + * @param paramKey the key of the {@link Parameter} which is to be returned + * * @return the found {@link Parameter} or null if it was not found */ public T getParameter(String bagKey, String paramKey) { - if (this.parameterBagMap == null) + if (this.parameterBagMap == null) { return null; + } ParameterBag bag = this.parameterBagMap.get(bagKey); - if (bag == null) + if (bag == null) { return null; + } return bag.getParameter(paramKey); } /** * Adds a new {@link Parameter} to the {@link ParameterBag} with the given key - * - * @param bagKey - * the key of the {@link ParameterBag} to which the {@link Parameter} should be added - * @param parameter - * the {@link Parameter} to be added to the {@link ParameterBag} - * - * @throws StrolchException - * if the {@link ParameterBag} does not exist + * + * @param bagKey the key of the {@link ParameterBag} to which the {@link Parameter} should be added + * @param parameter the {@link Parameter} to be added to the {@link ParameterBag} + * + * @throws StrolchException if the {@link ParameterBag} does not exist */ public void addParameter(String bagKey, Parameter parameter) throws StrolchException { - if (this.parameterBagMap == null) + if (this.parameterBagMap == null) { this.parameterBagMap = new HashMap(); + } ParameterBag bag = this.parameterBagMap.get(bagKey); if (bag == null) { String msg = "No parameter bag exists with key {0}"; //$NON-NLS-1$ @@ -127,68 +124,68 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement /** * Removes the {@link Parameter} with the given paramKey from the {@link ParameterBag} with the given bagKey - * - * @param bagKey - * the key of the {@link ParameterBag} from which the {@link Parameter} is to be removed - * @param paramKey - * the key of the {@link Parameter} which is to be removed - * + * + * @param bagKey the key of the {@link ParameterBag} from which the {@link Parameter} is to be removed + * @param paramKey the key of the {@link Parameter} which is to be removed + * * @return the removed {@link Parameter} or null if it did not exist */ public Parameter removeParameter(String bagKey, String paramKey) { - if (this.parameterBagMap == null) + if (this.parameterBagMap == null) { return null; + } ParameterBag bag = this.parameterBagMap.get(bagKey); - if (bag == null) + if (bag == null) { return null; + } return bag.removeParameter(paramKey); } /** * Returns the {@link ParameterBag} with the given key, or null if it does not exist - * - * @param key - * the key of the {@link ParameterBag} to return - * + * + * @param key the key of the {@link ParameterBag} to return + * * @return the {@link ParameterBag} with the given key, or null if it does not exist */ public ParameterBag getParameterBag(String key) { - if (this.parameterBagMap == null) + if (this.parameterBagMap == null) { return null; + } return this.parameterBagMap.get(key); } /** * Adds the given {@link ParameterBag} to this {@link GroupedParameterizedElement} - * - * @param bag - * the {@link ParameterBag} to add + * + * @param bag the {@link ParameterBag} to add */ public void addParameterBag(ParameterBag bag) { - if (this.parameterBagMap == null) + if (this.parameterBagMap == null) { this.parameterBagMap = new HashMap(); + } this.parameterBagMap.put(bag.getId(), bag); bag.setParent(this); } /** * Removes the {@link ParameterBag} with the given key - * - * @param key - * the key of the {@link ParameterBag} to remove - * + * + * @param key the key of the {@link ParameterBag} to remove + * * @return the removed {@link ParameterBag}, or null if it does not exist */ public ParameterBag removeParameterBag(String key) { - if (this.parameterBagMap == null) + if (this.parameterBagMap == null) { return null; + } return this.parameterBagMap.remove(key); } /** * Returns true if this {@link GroupedParameterizedElement} has any {@link ParameterBag ParameterBag} - * + * * @return true if this {@link GroupedParameterizedElement} has any {@link ParameterBag ParameterBag} */ public boolean hasParameterBags() { @@ -197,9 +194,8 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement /** * Returns true if the {@link ParameterBag} with the given key exists on this {@link GroupedParameterizedElement}. - * - * @param bagKey - * the key of the {@link ParameterBag} which is to be checked for existence + * + * @param bagKey the key of the {@link ParameterBag} which is to be checked for existence * @return true if the {@link ParameterBag} with the given key exists on this {@link GroupedParameterizedElement}. */ public boolean hasParameterBag(String bagKey) { @@ -209,34 +205,35 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement /** * Returns true if the {@link Parameter} with the given paramKey exists on the {@link ParameterBag} with the given * bagKey - * - * @param bagKey - * the key of the {@link ParameterBag} on which to find the {@link Parameter} - * @param paramKey - * the key of the {@link Parameter} to be found - * + * + * @param bagKey the key of the {@link ParameterBag} on which to find the {@link Parameter} + * @param paramKey the key of the {@link Parameter} to be found + * * @return true if the {@link Parameter} with the given paramKey exists on the {@link ParameterBag} with the given - * bagKey. False is returned if the {@link ParameterBag} does not exist, or the {@link Parameter} does not - * exist on the {@link ParameterBag} + * bagKey. False is returned if the {@link ParameterBag} does not exist, or the {@link Parameter} does not exist on + * the {@link ParameterBag} */ public boolean hasParameter(String bagKey, String paramKey) { - if (this.parameterBagMap == null) + if (this.parameterBagMap == null) { return false; + } ParameterBag bag = this.parameterBagMap.get(bagKey); - if (bag == null) + if (bag == null) { return false; + } return bag.hasParameter(paramKey); } /** * Returns the {@link Set} of keys for the {@link ParameterBag}s on this {@link GroupedParameterizedElement} - * + * * @return the {@link Set} of keys for the {@link ParameterBag}s on this {@link GroupedParameterizedElement} */ public Set getParameterBagKeySet() { - if (this.parameterBagMap == null) + if (this.parameterBagMap == null) { return Collections.emptySet(); + } return new HashSet(this.parameterBagMap.keySet()); } @@ -268,7 +265,7 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement /** * Fills {@link GroupedParameterizedElement} properties of this clone - * + * * @param clone */ protected void fillClone(GroupedParameterizedElement clone) { diff --git a/src/main/java/li/strolch/model/Locator.java b/src/main/java/li/strolch/model/Locator.java index 9e4a5e3e9..186bc6c0f 100644 --- a/src/main/java/li/strolch/model/Locator.java +++ b/src/main/java/li/strolch/model/Locator.java @@ -30,16 +30,16 @@ import ch.eitchnet.utils.helper.StringHelper; * consists of a {@link List} of Strings which starting from the first value, defining the root, with the last item * defining the objects id. *

- * + * *

* When the {@link Locator} is formatted to a String, it resembles the same format as is used in Unix based files * systems, with slashes (/), separating the different list values *

- * + * *

* A {@link Locator} is always immutable, modifications return a new instance *

- * + * * @author Robert von Burg */ public class Locator { @@ -56,27 +56,24 @@ public class Locator { /** * Constructs a new {@link Locator} with the given list of path elements - * - * @param pathElements - * the elements making up the {@link Locator} - * - * @throws StrolchException - * if the path is invalid, meaning has less than two elements in it + * + * @param pathElements the elements making up the {@link Locator} + * + * @throws StrolchException if the path is invalid, meaning has less than two elements in it */ public Locator(List pathElements) throws StrolchException { - if (pathElements == null || pathElements.isEmpty()) + if (pathElements == null || pathElements.isEmpty()) { throw new StrolchException("The path elements may not be null and must contain at least 1 item"); //$NON-NLS-1$ + } this.pathElements = Collections.unmodifiableList(new ArrayList(pathElements)); } /** * Constructs a new {@link Locator} by parsing the given string path. - * - * @param path - * the path to parse for instantiate this {@link Locator} with elements - * - * @throws StrolchException - * if the path is invalid, meaning has less than two elements in it + * + * @param path the path to parse for instantiate this {@link Locator} with elements + * + * @throws StrolchException if the path is invalid, meaning has less than two elements in it */ public Locator(String path) throws StrolchException { this.pathElements = Collections.unmodifiableList(parsePath(path)); @@ -84,11 +81,9 @@ public class Locator { /** * Internal constructor to append a sub path to a constructor - * - * @param path - * the base path of the locator - * @param subPath - * the additional path + * + * @param path the base path of the locator + * @param subPath the additional path */ private Locator(List path, List subPath) { List fullPath = new ArrayList(); @@ -99,11 +94,9 @@ public class Locator { /** * Internal constructor to append a element to a constructor - * - * @param path - * the base path of the locator - * @param element - * the additional element + * + * @param path the base path of the locator + * @param element the additional element */ private Locator(List path, String element) { List fullPath = new ArrayList(); @@ -114,7 +107,7 @@ public class Locator { /** * Returns the immutable list of path elements making up this locator - * + * * @return the pathElements */ public List getPathElements() { @@ -123,7 +116,7 @@ public class Locator { /** * Returns the number of elements which this {@link Locator} contains - * + * * @return the number of elements which this {@link Locator} contains */ public int getSize() { @@ -132,10 +125,9 @@ public class Locator { /** * Returns a new {@link Locator} where the given sub path is appended to the locator - * - * @param subPathElements - * the sub path to append - * + * + * @param subPathElements the sub path to append + * * @return the new locator */ public Locator append(List subPathElements) { @@ -144,10 +136,9 @@ public class Locator { /** * Returns a new {@link Locator} where the given element is appended to the locator - * - * @param element - * the element to append - * + * + * @param element the element to append + * * @return the new locator */ public Locator append(String element) { @@ -165,33 +156,30 @@ public class Locator { /** * Parses the given path to a {@link List} of path elements by splitting the string with the {@link #PATH_SEPARATOR} - * - * @param path - * the path to parse - * + * + * @param path the path to parse + * * @return the list of path elements for the list - * - * @throws StrolchException - * if the path is empty, or does not contain at least 2 elements separated by {@link #PATH_SEPARATOR} + * + * @throws StrolchException if the path is empty, or does not contain at least 2 elements separated by + * {@link #PATH_SEPARATOR} */ private List parsePath(String path) throws StrolchException { - if (StringHelper.isEmpty(path)) + if (StringHelper.isEmpty(path)) { throw new StrolchException("A path may not be empty!"); //$NON-NLS-1$ - + } String[] elements = path.split(Locator.PATH_SEPARATOR); return Arrays.asList(elements); } /** * Formats the given list of path elements to a String representation of the {@link Locator} - * - * @param pathElements - * the locator elements - * + * + * @param pathElements the locator elements + * * @return a string representation of the path elements - * - * @throws StrolchException - * if the path elements does not contain at least two items + * + * @throws StrolchException if the path elements does not contain at least two items */ private String formatPath(List pathElements) throws StrolchException { StringBuilder sb = new StringBuilder(); @@ -200,8 +188,9 @@ public class Locator { while (iter.hasNext()) { String element = iter.next(); sb.append(element); - if (iter.hasNext()) + if (iter.hasNext()) { sb.append(Locator.PATH_SEPARATOR); + } } return sb.toString(); @@ -217,26 +206,30 @@ public class Locator { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } Locator other = (Locator) obj; if (this.pathElements == null) { - if (other.pathElements != null) + if (other.pathElements != null) { return false; - } else if (!this.pathElements.equals(other.pathElements)) + } + } else if (!this.pathElements.equals(other.pathElements)) { return false; + } return true; } /** * Instantiates a new immutable {@link Locator} instance from the given string - * - * @param locatorPath - * the path from which to instantiate the locator + * + * @param locatorPath the path from which to instantiate the locator * @return the immutable {@link Locator} instance */ public static Locator valueOf(String locatorPath) { @@ -245,10 +238,9 @@ public class Locator { /** * Creates a new {@link LocatorBuilder} instance and appends the given root element tag to it - * - * @param rootElement - * the first element on the {@link Locator} - * + * + * @param rootElement the first element on the {@link Locator} + * * @return a new {@link LocatorBuilder} instance with the given root element tag as the first element */ public static LocatorBuilder newBuilder(String rootElement) { @@ -258,7 +250,7 @@ public class Locator { /** * {@link LocatorBuilder} is used to build {@link Locator}s where a deep hierarchy is to be created. The * {@link #append(String)} method returns itself for chain building - * + * * @author Robert von Burg */ public static class LocatorBuilder { @@ -274,10 +266,9 @@ public class Locator { /** * Append an element to the path - * - * @param element - * the element to add - * + * + * @param element the element to add + * * @return this instance for chaining */ public LocatorBuilder append(String element) { @@ -287,7 +278,7 @@ public class Locator { /** * Remove the last element from the path - * + * * @return this instance for chaining */ public LocatorBuilder removeLast() { @@ -297,12 +288,13 @@ public class Locator { /** * Creates an immutable {@link Locator} instance with the current elements - * + * * @return a new {@link Locator} instance */ public Locator build() { - if (this.pathElements.isEmpty()) + if (this.pathElements.isEmpty()) { throw new StrolchException("The path elements must contain at least 1 item"); //$NON-NLS-1$ + } return new Locator(this.pathElements); } } diff --git a/src/main/java/li/strolch/model/ModelGenerator.java b/src/main/java/li/strolch/model/ModelGenerator.java index 6808069cd..a7af23bac 100644 --- a/src/main/java/li/strolch/model/ModelGenerator.java +++ b/src/main/java/li/strolch/model/ModelGenerator.java @@ -51,298 +51,298 @@ import li.strolch.model.timevalue.impl.ValueChange; @SuppressWarnings("nls") public class ModelGenerator { - public static final String PARAM_BOOLEAN_ID = "@param1"; - public static final String PARAM_BOOLEAN_NAME = "Boolean Param"; + public static final String PARAM_BOOLEAN_ID = "@param1"; + public static final String PARAM_BOOLEAN_NAME = "Boolean Param"; - public static final String PARAM_FLOAT_ID = "@param2"; - public static final String PARAM_FLOAT_NAME = "Float Param"; + public static final String PARAM_FLOAT_ID = "@param2"; + public static final String PARAM_FLOAT_NAME = "Float Param"; - public static final String PARAM_INTEGER_ID = "@param3"; - public static final String PARAM_INTEGER_NAME = "Integer Param"; + public static final String PARAM_INTEGER_ID = "@param3"; + public static final String PARAM_INTEGER_NAME = "Integer Param"; - public static final String PARAM_LONG_ID = "@param4"; - public static final String PARAM_LONG_NAME = "Long Param"; + public static final String PARAM_LONG_ID = "@param4"; + public static final String PARAM_LONG_NAME = "Long Param"; - public static final String PARAM_STRING_ID = "@param5"; - public static final String PARAM_STRING_NAME = "String Param"; + public static final String PARAM_STRING_ID = "@param5"; + public static final String PARAM_STRING_NAME = "String Param"; - public static final String PARAM_DATE_ID = "@param6"; - public static final String PARAM_DATE_NAME = "Date Param"; + public static final String PARAM_DATE_ID = "@param6"; + public static final String PARAM_DATE_NAME = "Date Param"; - public static final String PARAM_LIST_STRING_ID = "@param7"; - public static final String PARAM_LIST_STRING_NAME = "StringList Param"; + public static final String PARAM_LIST_STRING_ID = "@param7"; + public static final String PARAM_LIST_STRING_NAME = "StringList Param"; - public static final String STATE_FLOAT_ID = "@state1"; - public static final String STATE_FLOAT_NAME = "Float State"; + public static final String STATE_FLOAT_ID = "@state1"; + public static final String STATE_FLOAT_NAME = "Float State"; - public static final String STATE_INTEGER_ID = "@state2"; - public static final String STATE_INTEGER_NAME = "Float State"; + public static final String STATE_INTEGER_ID = "@state2"; + public static final String STATE_INTEGER_NAME = "Float State"; - public static final String STATE_STRING_ID = "@state3"; - public static final String STATE_STRING_NAME = "Float State"; + public static final String STATE_STRING_ID = "@state3"; + public static final String STATE_STRING_NAME = "Float State"; - public static final String STATE_BOOLEAN_ID = "@state4"; - public static final String STATE_BOOLEAN_NAME = "Float State"; + public static final String STATE_BOOLEAN_ID = "@state4"; + public static final String STATE_BOOLEAN_NAME = "Float State"; - public static final long STATE_TIME_0 = 0L; - public static final long STATE_TIME_10 = 10L; - public static final long STATE_TIME_20 = 20L; - public static final long STATE_TIME_30 = 30L; + public static final long STATE_TIME_0 = 0L; + public static final long STATE_TIME_10 = 10L; + public static final long STATE_TIME_20 = 20L; + public static final long STATE_TIME_30 = 30L; - public static final Double STATE_FLOAT_TIME_0 = 0.0D; - public static final Double STATE_FLOAT_TIME_10 = 10.0D; - public static final Double STATE_FLOAT_TIME_20 = 20.0D; - public static final Double STATE_FLOAT_TIME_30 = 30.0D; + public static final Double STATE_FLOAT_TIME_0 = 0.0D; + public static final Double STATE_FLOAT_TIME_10 = 10.0D; + public static final Double STATE_FLOAT_TIME_20 = 20.0D; + public static final Double STATE_FLOAT_TIME_30 = 30.0D; - public static final Integer STATE_INTEGER_TIME_0 = 0; - public static final Integer STATE_INTEGER_TIME_10 = 10; - public static final Integer STATE_INTEGER_TIME_20 = 20; - public static final Integer STATE_INTEGER_TIME_30 = 30; + public static final Integer STATE_INTEGER_TIME_0 = 0; + public static final Integer STATE_INTEGER_TIME_10 = 10; + public static final Integer STATE_INTEGER_TIME_20 = 20; + public static final Integer STATE_INTEGER_TIME_30 = 30; - public static final String STATE_STRING_TIME_0 = "empty"; - public static final String STATE_STRING_TIME_10 = "a"; - public static final String STATE_STRING_TIME_20 = "b"; - public static final String STATE_STRING_TIME_30 = "c"; + public static final String STATE_STRING_TIME_0 = "empty"; + public static final String STATE_STRING_TIME_10 = "a"; + public static final String STATE_STRING_TIME_20 = "b"; + public static final String STATE_STRING_TIME_30 = "c"; - public static final Boolean STATE_BOOLEAN_TIME_0 = Boolean.FALSE; - public static final Boolean STATE_BOOLEAN_TIME_10 = Boolean.TRUE; - public static final Boolean STATE_BOOLEAN_TIME_20 = Boolean.FALSE; - public static final Boolean STATE_BOOLEAN_TIME_30 = Boolean.TRUE; + public static final Boolean STATE_BOOLEAN_TIME_0 = Boolean.FALSE; + public static final Boolean STATE_BOOLEAN_TIME_10 = Boolean.TRUE; + public static final Boolean STATE_BOOLEAN_TIME_20 = Boolean.FALSE; + public static final Boolean STATE_BOOLEAN_TIME_30 = Boolean.TRUE; - public static final String BAG_ID = "@bag01"; - public static final String BAG_NAME = "Test Bag"; - public static final String BAG_TYPE = "TestBag"; + public static final String BAG_ID = "@bag01"; + public static final String BAG_NAME = "Test Bag"; + public static final String BAG_TYPE = "TestBag"; - /** - * Creates an {@link Resource} with the given values and adds a {@link ParameterBag} by calling - * {@link #createParameterBag(String, String, String)} - * - * @param id the id of the {@link Resource} - * @param name the name of the {@link Resource} - * @param type the type of the {@link Resource} - * - * @return the newly created {@link Resource} - */ - public static Resource createResource(String id, String name, String type) { - Resource resource = new Resource(id, name, type); - ParameterBag bag = createParameterBag(BAG_ID, BAG_NAME, BAG_TYPE); - resource.addParameterBag(bag); - addTimedStates(resource); + /** + * Creates an {@link Resource} with the given values and adds a {@link ParameterBag} by calling + * {@link #createParameterBag(String, String, String)} + * + * @param id the id of the {@link Resource} + * @param name the name of the {@link Resource} + * @param type the type of the {@link Resource} + * + * @return the newly created {@link Resource} + */ + public static Resource createResource(String id, String name, String type) { + Resource resource = new Resource(id, name, type); + ParameterBag bag = createParameterBag(BAG_ID, BAG_NAME, BAG_TYPE); + resource.addParameterBag(bag); + addTimedStates(resource); - return resource; - } + return resource; + } - /** - * Creates {@link StrolchTimedState} instances and adds them to the {@link Resource} - * - * @param resource the resource to which to addd the newly created {@link StrolchTimedState} - */ - public static void addTimedStates(Resource resource) { + /** + * Creates {@link StrolchTimedState} instances and adds them to the {@link Resource} + * + * @param resource the resource to which to addd the newly created {@link StrolchTimedState} + */ + public static void addTimedStates(Resource resource) { - // float state - FloatTimedState floatTimedState = new FloatTimedState(STATE_FLOAT_ID, STATE_FLOAT_NAME); - floatTimedState.applyChange(new ValueChange<>(STATE_TIME_0, new FloatValue(STATE_FLOAT_TIME_0))); - FloatValue floatValueChange = new FloatValue(STATE_FLOAT_TIME_10); - floatTimedState.applyChange(new ValueChange<>(STATE_TIME_10, floatValueChange)); - floatTimedState.applyChange(new ValueChange<>(STATE_TIME_20, floatValueChange)); - floatTimedState.applyChange(new ValueChange<>(STATE_TIME_30, floatValueChange)); - resource.addTimedState(floatTimedState); + // float state + FloatTimedState floatTimedState = new FloatTimedState(STATE_FLOAT_ID, STATE_FLOAT_NAME); + floatTimedState.applyChange(new ValueChange<>(STATE_TIME_0, new FloatValue(STATE_FLOAT_TIME_0))); + FloatValue floatValueChange = new FloatValue(STATE_FLOAT_TIME_10); + floatTimedState.applyChange(new ValueChange<>(STATE_TIME_10, floatValueChange)); + floatTimedState.applyChange(new ValueChange<>(STATE_TIME_20, floatValueChange)); + floatTimedState.applyChange(new ValueChange<>(STATE_TIME_30, floatValueChange)); + resource.addTimedState(floatTimedState); - // integer state - IntegerTimedState integerTimedState = new IntegerTimedState(STATE_INTEGER_ID, STATE_INTEGER_NAME); - integerTimedState.applyChange(new ValueChange<>(STATE_TIME_0, - new IntegerValue(STATE_INTEGER_TIME_0))); - IntegerValue integerValueChange = new IntegerValue(STATE_INTEGER_TIME_10); - integerTimedState.applyChange(new ValueChange<>(STATE_TIME_10, integerValueChange)); - integerTimedState.applyChange(new ValueChange<>(STATE_TIME_20, integerValueChange)); - integerTimedState.applyChange(new ValueChange<>(STATE_TIME_30, integerValueChange)); - resource.addTimedState(integerTimedState); + // integer state + IntegerTimedState integerTimedState = new IntegerTimedState(STATE_INTEGER_ID, STATE_INTEGER_NAME); + integerTimedState.applyChange(new ValueChange<>(STATE_TIME_0, + new IntegerValue(STATE_INTEGER_TIME_0))); + IntegerValue integerValueChange = new IntegerValue(STATE_INTEGER_TIME_10); + integerTimedState.applyChange(new ValueChange<>(STATE_TIME_10, integerValueChange)); + integerTimedState.applyChange(new ValueChange<>(STATE_TIME_20, integerValueChange)); + integerTimedState.applyChange(new ValueChange<>(STATE_TIME_30, integerValueChange)); + resource.addTimedState(integerTimedState); - // boolean state - BooleanTimedState booleanTimedState = new BooleanTimedState(STATE_BOOLEAN_ID, STATE_BOOLEAN_NAME); - booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_0, - new BooleanValue(STATE_BOOLEAN_TIME_0))); - BooleanValue booleanValueChange = new BooleanValue(STATE_BOOLEAN_TIME_10); - booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_10, booleanValueChange)); - booleanValueChange = booleanValueChange.getInverse(); - booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_20, booleanValueChange)); - booleanValueChange = booleanValueChange.getInverse(); - booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_30, booleanValueChange)); - resource.addTimedState(booleanTimedState); + // boolean state + BooleanTimedState booleanTimedState = new BooleanTimedState(STATE_BOOLEAN_ID, STATE_BOOLEAN_NAME); + booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_0, + new BooleanValue(STATE_BOOLEAN_TIME_0))); + BooleanValue booleanValueChange = new BooleanValue(STATE_BOOLEAN_TIME_10); + booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_10, booleanValueChange)); + booleanValueChange = booleanValueChange.getInverse(); + booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_20, booleanValueChange)); + booleanValueChange = booleanValueChange.getInverse(); + booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_30, booleanValueChange)); + resource.addTimedState(booleanTimedState); - // string state - StringSetTimedState stringTimedState = new StringSetTimedState(STATE_STRING_ID, STATE_STRING_NAME); - StringSetValue change = new StringSetValue(asSet(STATE_STRING_TIME_0)); - stringTimedState.applyChange(new ValueChange<>(STATE_TIME_0, change)); - change = change.getInverse(); - change.add(asSet(STATE_STRING_TIME_10)); - stringTimedState.applyChange(new ValueChange<>(STATE_TIME_10, change)); - removeInverted(change.getValue()); - change = change.getInverse(); - change.add(asSet(STATE_STRING_TIME_20)); - stringTimedState.applyChange(new ValueChange<>(STATE_TIME_20, change)); - removeInverted(change.getValue()); - change = change.getInverse(); - change.add(asSet(STATE_STRING_TIME_30)); - stringTimedState.applyChange(new ValueChange<>(STATE_TIME_30, change)); - resource.addTimedState(stringTimedState); - } + // string state + StringSetTimedState stringTimedState = new StringSetTimedState(STATE_STRING_ID, STATE_STRING_NAME); + StringSetValue change = new StringSetValue(asSet(STATE_STRING_TIME_0)); + stringTimedState.applyChange(new ValueChange<>(STATE_TIME_0, change)); + change = change.getInverse(); + change.add(asSet(STATE_STRING_TIME_10)); + stringTimedState.applyChange(new ValueChange<>(STATE_TIME_10, change)); + removeInverted(change.getValue()); + change = change.getInverse(); + change.add(asSet(STATE_STRING_TIME_20)); + stringTimedState.applyChange(new ValueChange<>(STATE_TIME_20, change)); + removeInverted(change.getValue()); + change = change.getInverse(); + change.add(asSet(STATE_STRING_TIME_30)); + stringTimedState.applyChange(new ValueChange<>(STATE_TIME_30, change)); + resource.addTimedState(stringTimedState); + } - private static Set asSet(String value) { - HashSet hashSet = new HashSet<>(); - hashSet.add(new AString(value)); - return hashSet; - } + private static Set asSet(String value) { + HashSet hashSet = new HashSet<>(); + hashSet.add(new AString(value)); + return hashSet; + } - private static void removeInverted(Set set) { - for (Iterator iter = set.iterator(); iter.hasNext();) { - AString aString = iter.next(); - if (aString.isInverse()) { - iter.remove(); - } - } - } + private static void removeInverted(Set set) { + for (Iterator iter = set.iterator(); iter.hasNext();) { + AString aString = iter.next(); + if (aString.isInverse()) { + iter.remove(); + } + } + } - /** - * Creates a list of {@link Resource Resources} with the given values and adds a {@link ParameterBag} by calling - * {@link #createParameterBag(String, String, String)} - * - * @param idStart id range start - * @param count the number of elements to create - * @param idPrefix the prefix to generate IDs for the {@link Resource Resources} - * @param name the name of the {@link Resource} - * @param type the type of the {@link Resource} - * - * @return the list of newly created {@link Resource Resources} - */ - public static List createResources(int idStart, int count, String idPrefix, String name, String type) { - List resources = new ArrayList<>(); - for (int i = 0; i < count; i++) { - String id = StringHelper.normalizeLength(String.valueOf((i + idStart)), 8, true, '0'); - resources.add(createResource(idPrefix + "_" + id, name + " " + i, type)); - } - return resources; - } + /** + * Creates a list of {@link Resource Resources} with the given values and adds a {@link ParameterBag} by calling + * {@link #createParameterBag(String, String, String)} + * + * @param idStart id range start + * @param count the number of elements to create + * @param idPrefix the prefix to generate IDs for the {@link Resource Resources} + * @param name the name of the {@link Resource} + * @param type the type of the {@link Resource} + * + * @return the list of newly created {@link Resource Resources} + */ + public static List createResources(int idStart, int count, String idPrefix, String name, String type) { + List resources = new ArrayList<>(); + for (int i = 0; i < count; i++) { + String id = StringHelper.normalizeLength(String.valueOf((i + idStart)), 8, true, '0'); + resources.add(createResource(idPrefix + "_" + id, name + " " + i, type)); + } + return resources; + } - /** - * Creates an {@link Order} with the given values and adds a {@link ParameterBag} by calling - * {@link #createParameterBag(String, String, String)} - * - * @param id the id of the {@link Order} - * @param name the name of the {@link Order} - * @param type the type of the {@link Order} - * - * @return the newly created {@link Order} - */ - public static Order createOrder(String id, String name, String type) { - return createOrder(id, name, type, new Date(), State.CREATED); - } + /** + * Creates an {@link Order} with the given values and adds a {@link ParameterBag} by calling + * {@link #createParameterBag(String, String, String)} + * + * @param id the id of the {@link Order} + * @param name the name of the {@link Order} + * @param type the type of the {@link Order} + * + * @return the newly created {@link Order} + */ + public static Order createOrder(String id, String name, String type) { + return createOrder(id, name, type, new Date(), State.CREATED); + } - /** - * Creates an {@link Order} with the given values and adds a {@link ParameterBag} by calling - * {@link #createParameterBag(String, String, String)} - * - * @param id the id of the {@link Order} - * @param name the name of the {@link Order} - * @param type the type of the {@link Order} - * @param date the date of the {@link Order} - * @param state the {@link State} of the {@link Order} - * - * @return the newly created {@link Order} - */ - public static Order createOrder(String id, String name, String type, Date date, State state) { + /** + * Creates an {@link Order} with the given values and adds a {@link ParameterBag} by calling + * {@link #createParameterBag(String, String, String)} + * + * @param id the id of the {@link Order} + * @param name the name of the {@link Order} + * @param type the type of the {@link Order} + * @param date the date of the {@link Order} + * @param state the {@link State} of the {@link Order} + * + * @return the newly created {@link Order} + */ + public static Order createOrder(String id, String name, String type, Date date, State state) { - Order order = new Order(id, name, type, date, state); - ParameterBag bag = createParameterBag(BAG_ID, BAG_NAME, BAG_TYPE); - order.addParameterBag(bag); + Order order = new Order(id, name, type, date, state); + ParameterBag bag = createParameterBag(BAG_ID, BAG_NAME, BAG_TYPE); + order.addParameterBag(bag); - return order; - } + return order; + } - /** - * Creates a list of {@link Order Orders} with the given values and adds a {@link ParameterBag} by calling - * {@link #createParameterBag(String, String, String)} - * - * @param idStart id range start - * @param count the number of elements to create - * @param idPrefix the prefix to generate IDs for the {@link Order Orders} - * @param name the name of the {@link Order} - * @param type the type of the {@link Order} - * - * @return the list of newly created {@link Order Orders} - */ - public static List createOrders(int idStart, int count, String idPrefix, String name, String type) { - List orders = new ArrayList<>(); - for (int i = 0; i < count; i++) { - String id = StringHelper.normalizeLength(String.valueOf((i + idStart)), 8, true, '0'); - orders.add(createOrder(idPrefix + "_" + id, name + " " + i, type)); - } - return orders; - } + /** + * Creates a list of {@link Order Orders} with the given values and adds a {@link ParameterBag} by calling + * {@link #createParameterBag(String, String, String)} + * + * @param idStart id range start + * @param count the number of elements to create + * @param idPrefix the prefix to generate IDs for the {@link Order Orders} + * @param name the name of the {@link Order} + * @param type the type of the {@link Order} + * + * @return the list of newly created {@link Order Orders} + */ + public static List createOrders(int idStart, int count, String idPrefix, String name, String type) { + List orders = new ArrayList<>(); + for (int i = 0; i < count; i++) { + String id = StringHelper.normalizeLength(String.valueOf((i + idStart)), 8, true, '0'); + orders.add(createOrder(idPrefix + "_" + id, name + " " + i, type)); + } + return orders; + } - /** - * Creates a {@link ParameterBag} with the given values and calls {@link #addAllParameters(ParameterBag)} to add - * {@link Parameter}s - * - * @param id the id of the {@link ParameterBag} - * @param name the name of the {@link ParameterBag} - * @param type the type of the {@link ParameterBag} - * - * @return the newly created {@link ParameterBag} - */ - public static ParameterBag createParameterBag(String id, String name, String type) { + /** + * Creates a {@link ParameterBag} with the given values and calls {@link #addAllParameters(ParameterBag)} to add + * {@link Parameter}s + * + * @param id the id of the {@link ParameterBag} + * @param name the name of the {@link ParameterBag} + * @param type the type of the {@link ParameterBag} + * + * @return the newly created {@link ParameterBag} + */ + public static ParameterBag createParameterBag(String id, String name, String type) { - ParameterBag bag = new ParameterBag(id, name, type); - addAllParameters(bag); - return bag; - } + ParameterBag bag = new ParameterBag(id, name, type); + addAllParameters(bag); + return bag; + } - /** - * Adds the following {@link Parameter}s to the given {@link ParameterBag}: - *
    - *
  • BooleanParameter - true
  • - *
  • FloatParameter - 44.3
  • - *
  • IntegerParameter - 77
  • - *
  • LongParameter - 4453234566L
  • - *
  • StringParameter - "Strolch"
  • - *
  • DateParameter - 1354295525628L
  • - *
  • StringListParameter - Hello, World
  • - *
- * - * @param bag - */ - public static void addAllParameters(ParameterBag bag) { + /** + * Adds the following {@link Parameter}s to the given {@link ParameterBag}: + *
    + *
  • BooleanParameter - true
  • + *
  • FloatParameter - 44.3
  • + *
  • IntegerParameter - 77
  • + *
  • LongParameter - 4453234566L
  • + *
  • StringParameter - "Strolch"
  • + *
  • DateParameter - 1354295525628L
  • + *
  • StringListParameter - Hello, World
  • + *
+ * + * @param bag + */ + public static void addAllParameters(ParameterBag bag) { - BooleanParameter boolParam = new BooleanParameter(PARAM_BOOLEAN_ID, PARAM_BOOLEAN_NAME, true); - boolParam.setIndex(1); - bag.addParameter(boolParam); + BooleanParameter boolParam = new BooleanParameter(PARAM_BOOLEAN_ID, PARAM_BOOLEAN_NAME, true); + boolParam.setIndex(1); + bag.addParameter(boolParam); - FloatParameter floatParam = new FloatParameter(PARAM_FLOAT_ID, PARAM_FLOAT_NAME, 44.3); - floatParam.setIndex(2); - bag.addParameter(floatParam); + FloatParameter floatParam = new FloatParameter(PARAM_FLOAT_ID, PARAM_FLOAT_NAME, 44.3); + floatParam.setIndex(2); + bag.addParameter(floatParam); - IntegerParameter integerParam = new IntegerParameter(PARAM_INTEGER_ID, PARAM_INTEGER_NAME, 77); - integerParam.setIndex(3); - bag.addParameter(integerParam); + IntegerParameter integerParam = new IntegerParameter(PARAM_INTEGER_ID, PARAM_INTEGER_NAME, 77); + integerParam.setIndex(3); + bag.addParameter(integerParam); - LongParameter longParam = new LongParameter(PARAM_LONG_ID, PARAM_LONG_NAME, 4453234566L); - longParam.setIndex(4); - bag.addParameter(longParam); + LongParameter longParam = new LongParameter(PARAM_LONG_ID, PARAM_LONG_NAME, 4453234566L); + longParam.setIndex(4); + bag.addParameter(longParam); - StringParameter stringParam = new StringParameter(PARAM_STRING_ID, PARAM_STRING_NAME, "Strolch"); - stringParam.setIndex(5); - bag.addParameter(stringParam); + StringParameter stringParam = new StringParameter(PARAM_STRING_ID, PARAM_STRING_NAME, "Strolch"); + stringParam.setIndex(5); + bag.addParameter(stringParam); - DateParameter dateParam = new DateParameter(PARAM_DATE_ID, PARAM_DATE_NAME, new Date(1354295525628L)); - dateParam.setIndex(6); - bag.addParameter(dateParam); + DateParameter dateParam = new DateParameter(PARAM_DATE_ID, PARAM_DATE_NAME, new Date(1354295525628L)); + dateParam.setIndex(6); + bag.addParameter(dateParam); - ArrayList stringList = new ArrayList(); - stringList.add("Hello"); - stringList.add("World"); - StringListParameter stringListP = new StringListParameter(PARAM_LIST_STRING_ID, PARAM_LIST_STRING_NAME, - stringList); - stringListP.setIndex(7); - bag.addParameter(stringListP); - } + ArrayList stringList = new ArrayList(); + stringList.add("Hello"); + stringList.add("World"); + StringListParameter stringListP = new StringListParameter(PARAM_LIST_STRING_ID, PARAM_LIST_STRING_NAME, + stringList); + stringListP.setIndex(7); + bag.addParameter(stringListP); + } } diff --git a/src/main/java/li/strolch/model/Order.java b/src/main/java/li/strolch/model/Order.java index 38bf665db..8da752bb3 100644 --- a/src/main/java/li/strolch/model/Order.java +++ b/src/main/java/li/strolch/model/Order.java @@ -30,10 +30,10 @@ import ch.eitchnet.utils.iso8601.ISO8601FormatFactory; * The Order is an object used in the EDF to transfer data from one range to another. Orders are not to be thought of as * Resources. Resources are supposed to be thought of as things i.e. a table, a machine and so forth, where a order is * to be thought of as an object for doing something. - * + * * In this sense, orders do not need to be verified, so all verifier chracteristics are disabled and the * getVerifier()-method will return the null reference - * + * * @author Robert von Burg */ public class Order extends GroupedParameterizedElement implements StrolchRootElement { @@ -52,7 +52,7 @@ public class Order extends GroupedParameterizedElement implements StrolchRootEle /** * Default Constructor - * + * * @param id * @param name * @param type @@ -66,7 +66,7 @@ public class Order extends GroupedParameterizedElement implements StrolchRootEle /** * Extended Constructor for date and {@link State} - * + * * @param id * @param name * @param type @@ -82,7 +82,7 @@ public class Order extends GroupedParameterizedElement implements StrolchRootEle /** * DOM Constructor - * + * * @param element */ public Order(Element element) { @@ -112,8 +112,7 @@ public class Order extends GroupedParameterizedElement implements StrolchRootEle } /** - * @param date - * the date to set + * @param date the date to set */ public void setDate(Date date) { this.date = date; @@ -127,8 +126,7 @@ public class Order extends GroupedParameterizedElement implements StrolchRootEle } /** - * @param state - * the state to set + * @param state the state to set */ public void setState(State state) { this.state = state; diff --git a/src/main/java/li/strolch/model/ParameterBag.java b/src/main/java/li/strolch/model/ParameterBag.java index 6c2f53867..bd3fca218 100644 --- a/src/main/java/li/strolch/model/ParameterBag.java +++ b/src/main/java/li/strolch/model/ParameterBag.java @@ -22,6 +22,7 @@ import org.w3c.dom.Element; * @author Robert von Burg */ public class ParameterBag extends ParameterizedElement { + private static final long serialVersionUID = 1L; /** @@ -33,7 +34,7 @@ public class ParameterBag extends ParameterizedElement { /** * Default constructor - * + * * @param id * @param name * @param type @@ -44,7 +45,7 @@ public class ParameterBag extends ParameterizedElement { /** * DOM Constructor - * + * * @param bagElement */ public ParameterBag(Element bagElement) { diff --git a/src/main/java/li/strolch/model/ParameterizedElement.java b/src/main/java/li/strolch/model/ParameterizedElement.java index 2696399f7..14299ea50 100644 --- a/src/main/java/li/strolch/model/ParameterizedElement.java +++ b/src/main/java/li/strolch/model/ParameterizedElement.java @@ -46,255 +46,255 @@ import ch.eitchnet.utils.helper.StringHelper; */ public abstract class ParameterizedElement extends AbstractStrolchElement { - private static final long serialVersionUID = 0L; + private static final long serialVersionUID = 0L; - protected GroupedParameterizedElement parent; - protected Map> parameterMap; - protected String type; + protected GroupedParameterizedElement parent; + protected Map> parameterMap; + protected String type; - /** - * Empty Constructor - */ - protected ParameterizedElement() { - // - } + /** + * Empty Constructor + */ + protected ParameterizedElement() { + // + } - /** - * Default Constructor - * - * @param id - * @param name - * @param type - */ - public ParameterizedElement(String id, String name, String type) { - setId(id); - setName(name); - setType(type); - } + /** + * Default Constructor + * + * @param id + * @param name + * @param type + */ + public ParameterizedElement(String id, String name, String type) { + setId(id); + setName(name); + setType(type); + } - @Override - public String getType() { - return this.type; - } + @Override + public String getType() { + return this.type; + } - /** - * Sets the type of this {@link ParameterizedElement} - * - * @param type the type to set - */ - public void setType(String type) { - if (StringHelper.isEmpty(type)) { - String msg = "Type may not be empty on element {0}"; //$NON-NLS-1$ - msg = MessageFormat.format(msg, getLocator()); - throw new StrolchException(msg); - } + /** + * Sets the type of this {@link ParameterizedElement} + * + * @param type the type to set + */ + public void setType(String type) { + if (StringHelper.isEmpty(type)) { + String msg = "Type may not be empty on element {0}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, getLocator()); + throw new StrolchException(msg); + } - this.type = type; - } + this.type = type; + } - /** - * Returns the {@link Parameter} with the given id, or null if it does not exist - * - * @param key the id of the parameter to return - * - * @return the {@link Parameter} with the given id, or null if it does not exist - */ - @SuppressWarnings("unchecked") - public T getParameter(String key) { - if (this.parameterMap == null) { - return null; - } - return (T) this.parameterMap.get(key); - } + /** + * Returns the {@link Parameter} with the given id, or null if it does not exist + * + * @param key the id of the parameter to return + * + * @return the {@link Parameter} with the given id, or null if it does not exist + */ + @SuppressWarnings("unchecked") + public T getParameter(String key) { + if (this.parameterMap == null) { + return null; + } + return (T) this.parameterMap.get(key); + } - /** - * Adds the given {@link Parameter} to the {@link ParameterizedElement} - * - * @param parameter the {@link Parameter} to add - */ - public void addParameter(Parameter parameter) { - if (this.parameterMap == null) { - this.parameterMap = new HashMap>(); - } - this.parameterMap.put(parameter.getId(), parameter); - parameter.setParent(this); - } + /** + * Adds the given {@link Parameter} to the {@link ParameterizedElement} + * + * @param parameter the {@link Parameter} to add + */ + public void addParameter(Parameter parameter) { + if (this.parameterMap == null) { + this.parameterMap = new HashMap>(); + } + this.parameterMap.put(parameter.getId(), parameter); + parameter.setParent(this); + } - /** - * Removes the {@link Parameter} with the given key - * - * @param key the key of the {@link Parameter} to remove - * - * @return the removed {@link Parameter}, or null if it does not exist - */ - @SuppressWarnings("unchecked") - public Parameter removeParameter(String key) { - if (this.parameterMap == null) { - return null; - } - return (Parameter) this.parameterMap.remove(key); - } + /** + * Removes the {@link Parameter} with the given key + * + * @param key the key of the {@link Parameter} to remove + * + * @return the removed {@link Parameter}, or null if it does not exist + */ + @SuppressWarnings("unchecked") + public Parameter removeParameter(String key) { + if (this.parameterMap == null) { + return null; + } + return (Parameter) this.parameterMap.remove(key); + } - /** - * Returns a list of all the {@link Parameter}s in this {@link ParameterizedElement} - * - * @return a list of all the {@link Parameter}s in this {@link ParameterizedElement} - */ - public List> getParameters() { - if (this.parameterMap == null) { - return Collections.emptyList(); - } - return new ArrayList>(this.parameterMap.values()); - } + /** + * Returns a list of all the {@link Parameter}s in this {@link ParameterizedElement} + * + * @return a list of all the {@link Parameter}s in this {@link ParameterizedElement} + */ + public List> getParameters() { + if (this.parameterMap == null) { + return Collections.emptyList(); + } + return new ArrayList>(this.parameterMap.values()); + } - /** - * Returns true, if the this {@link ParameterizedElement} has any {@link Parameter Parameters}, false otherwise - * - * @return true, if the this {@link ParameterizedElement} has any {@link Parameter Parameters}, false otherwise - */ - public boolean hasParameters() { - return this.parameterMap != null && !this.parameterMap.isEmpty(); - } + /** + * Returns true, if the this {@link ParameterizedElement} has any {@link Parameter Parameters}, false otherwise + * + * @return true, if the this {@link ParameterizedElement} has any {@link Parameter Parameters}, false otherwise + */ + public boolean hasParameters() { + return this.parameterMap != null && !this.parameterMap.isEmpty(); + } - /** - * Returns true, if the {@link Parameter} exists with the given key, false otherwise - * - * @param key the key of the {@link Parameter} to check for - * - * @return true, if the {@link Parameter} exists with the given key, false otherwise - */ - public boolean hasParameter(String key) { - if (this.parameterMap == null) { - return false; - } - return this.parameterMap.containsKey(key); - } + /** + * Returns true, if the {@link Parameter} exists with the given key, false otherwise + * + * @param key the key of the {@link Parameter} to check for + * + * @return true, if the {@link Parameter} exists with the given key, false otherwise + */ + public boolean hasParameter(String key) { + if (this.parameterMap == null) { + return false; + } + return this.parameterMap.containsKey(key); + } - /** - * Returns a {@link Set} of all the {@link Parameter} keys in this {@link ParameterizedElement} - * - * @return a {@link Set} of all the {@link Parameter} keys in this {@link ParameterizedElement} - */ - public Set getParameterKeySet() { - if (this.parameterMap == null) { - return Collections.emptySet(); - } - return new HashSet(this.parameterMap.keySet()); - } + /** + * Returns a {@link Set} of all the {@link Parameter} keys in this {@link ParameterizedElement} + * + * @return a {@link Set} of all the {@link Parameter} keys in this {@link ParameterizedElement} + */ + public Set getParameterKeySet() { + if (this.parameterMap == null) { + return Collections.emptySet(); + } + return new HashSet(this.parameterMap.keySet()); + } - @Override - public void fillLocator(LocatorBuilder lb) { - this.parent.fillLocator(lb); - lb.append(this.id); - } + @Override + public void fillLocator(LocatorBuilder lb) { + this.parent.fillLocator(lb); + lb.append(this.id); + } - @Override - public Locator getLocator() { - LocatorBuilder lb = new LocatorBuilder(); - fillLocator(lb); - return lb.build(); - } + @Override + public Locator getLocator() { + LocatorBuilder lb = new LocatorBuilder(); + fillLocator(lb); + return lb.build(); + } - @Override - protected void fromDom(Element element) { - super.fromDom(element); + @Override + protected void fromDom(Element element) { + super.fromDom(element); - String type = element.getAttribute(Tags.TYPE); - setType(type); + String type = element.getAttribute(Tags.TYPE); + setType(type); - // add all the parameters - NodeList parameterElements = element.getElementsByTagName(Tags.PARAMETER); - for (int i = 0; i < parameterElements.getLength(); i++) { - Element paramElement = (Element) parameterElements.item(i); - String paramtype = paramElement.getAttribute(Tags.TYPE); + // add all the parameters + NodeList parameterElements = element.getElementsByTagName(Tags.PARAMETER); + for (int i = 0; i < parameterElements.getLength(); i++) { + Element paramElement = (Element) parameterElements.item(i); + String paramtype = paramElement.getAttribute(Tags.TYPE); - DBC.PRE.assertNotEmpty("Type must be set on Parameter for bag with id " + id, paramtype); + DBC.PRE.assertNotEmpty("Type must be set on Parameter for bag with id " + id, paramtype); - if (paramtype.equals(StringParameter.TYPE)) { - StringParameter param = new StringParameter(paramElement); - addParameter(param); - } else if (paramtype.equals(IntegerParameter.TYPE)) { - IntegerParameter param = new IntegerParameter(paramElement); - addParameter(param); - } else if (paramtype.equals(FloatParameter.TYPE)) { - FloatParameter param = new FloatParameter(paramElement); - addParameter(param); - } else if (paramtype.equals(LongParameter.TYPE)) { - LongParameter param = new LongParameter(paramElement); - addParameter(param); - } else if (paramtype.equals(DateParameter.TYPE)) { - DateParameter param = new DateParameter(paramElement); - addParameter(param); - } else if (paramtype.equals(BooleanParameter.TYPE)) { - BooleanParameter param = new BooleanParameter(paramElement); - addParameter(param); - } else if (paramtype.equals(StringListParameter.TYPE)) { - StringListParameter param = new StringListParameter(paramElement); - addParameter(param); - } else { - String msg = "What kind of parameter is this: {0}"; //$NON-NLS-1$ - msg = MessageFormat.format(msg, paramtype); - throw new StrolchException(msg); - } - } - } + if (paramtype.equals(StringParameter.TYPE)) { + StringParameter param = new StringParameter(paramElement); + addParameter(param); + } else if (paramtype.equals(IntegerParameter.TYPE)) { + IntegerParameter param = new IntegerParameter(paramElement); + addParameter(param); + } else if (paramtype.equals(FloatParameter.TYPE)) { + FloatParameter param = new FloatParameter(paramElement); + addParameter(param); + } else if (paramtype.equals(LongParameter.TYPE)) { + LongParameter param = new LongParameter(paramElement); + addParameter(param); + } else if (paramtype.equals(DateParameter.TYPE)) { + DateParameter param = new DateParameter(paramElement); + addParameter(param); + } else if (paramtype.equals(BooleanParameter.TYPE)) { + BooleanParameter param = new BooleanParameter(paramElement); + addParameter(param); + } else if (paramtype.equals(StringListParameter.TYPE)) { + StringListParameter param = new StringListParameter(paramElement); + addParameter(param); + } else { + String msg = "What kind of parameter is this: {0}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, paramtype); + throw new StrolchException(msg); + } + } + } - @Override - protected void fillElement(Element element) { - super.fillElement(element); + @Override + protected void fillElement(Element element) { + super.fillElement(element); - if (this.parameterMap != null) { - for (Parameter parameter : this.parameterMap.values()) { - element.appendChild(parameter.toDom(element.getOwnerDocument())); - } - } - } + if (this.parameterMap != null) { + for (Parameter parameter : this.parameterMap.values()) { + element.appendChild(parameter.toDom(element.getOwnerDocument())); + } + } + } - @Override - protected void fillClone(StrolchElement clone) { - super.fillClone(clone); - ParameterizedElement peClone = (ParameterizedElement) clone; - peClone.setType(this.type); - if (this.parameterMap != null) { - for (Parameter param : this.parameterMap.values()) { - peClone.addParameter(param.getClone()); - } - } - } + @Override + protected void fillClone(StrolchElement clone) { + super.fillClone(clone); + ParameterizedElement peClone = (ParameterizedElement) clone; + peClone.setType(this.type); + if (this.parameterMap != null) { + for (Parameter param : this.parameterMap.values()) { + peClone.addParameter(param.getClone()); + } + } + } - @Override - public GroupedParameterizedElement getParent() { - return this.parent; - } + @Override + public GroupedParameterizedElement getParent() { + return this.parent; + } - /** - * Set the parent for this {@link ParameterizedElement} - * - * @param parent the parent to set - */ - public void setParent(GroupedParameterizedElement parent) { - this.parent = parent; - } + /** + * Set the parent for this {@link ParameterizedElement} + * + * @param parent the parent to set + */ + public void setParent(GroupedParameterizedElement parent) { + this.parent = parent; + } - @Override - public StrolchRootElement getRootElement() { - return this.parent.getRootElement(); - } + @Override + public StrolchRootElement getRootElement() { + return this.parent.getRootElement(); + } - @SuppressWarnings("nls") - @Override - public String toString() { + @SuppressWarnings("nls") + @Override + public String toString() { - StringBuilder builder = new StringBuilder(); + StringBuilder builder = new StringBuilder(); - builder.append("ParameterizedElement [id="); - builder.append(this.id); - builder.append(", name="); - builder.append(this.name); - builder.append(", type="); - builder.append(this.type); - builder.append("]"); + builder.append("ParameterizedElement [id="); + builder.append(this.id); + builder.append(", name="); + builder.append(this.name); + builder.append(", type="); + builder.append(this.type); + builder.append("]"); - return builder.toString(); - } + return builder.toString(); + } } diff --git a/src/main/java/li/strolch/model/Resource.java b/src/main/java/li/strolch/model/Resource.java index 86b012e7e..54a3bd5dd 100644 --- a/src/main/java/li/strolch/model/Resource.java +++ b/src/main/java/li/strolch/model/Resource.java @@ -41,176 +41,176 @@ import org.w3c.dom.NodeList; */ public class Resource extends GroupedParameterizedElement implements StrolchRootElement { - private static final long serialVersionUID = 0L; + private static final long serialVersionUID = 0L; - private Map> timedStateMap; + private Map> timedStateMap; - /** - * Empty constructor - */ - public Resource() { - // - } + /** + * Empty constructor + */ + public Resource() { + // + } - /** - * Default constructor - * - * @param id - * @param name - * @param type - */ - public Resource(String id, String name, String type) { - super(id, name, type); - } + /** + * Default constructor + * + * @param id + * @param name + * @param type + */ + public Resource(String id, String name, String type) { + super(id, name, type); + } - /** - * DOM Constructor - * - * @param element - */ - public Resource(Element element) { - super.fromDom(element); + /** + * DOM Constructor + * + * @param element + */ + public Resource(Element element) { + super.fromDom(element); - NodeList timedStateElems = element.getElementsByTagName(Tags.TIMED_STATE); - for (int i = 0; i < timedStateElems.getLength(); i++) { - Element timedStateElem = (Element) timedStateElems.item(i); - String typeS = timedStateElem.getAttribute(Tags.TYPE); + NodeList timedStateElems = element.getElementsByTagName(Tags.TIMED_STATE); + for (int i = 0; i < timedStateElems.getLength(); i++) { + Element timedStateElem = (Element) timedStateElems.item(i); + String typeS = timedStateElem.getAttribute(Tags.TYPE); - DBC.PRE.assertNotEmpty("Type must be set on TimedState for resource with id " + id, typeS); + DBC.PRE.assertNotEmpty("Type must be set on TimedState for resource with id " + id, typeS); - if (typeS.equals(FloatTimedState.TYPE)) { - StrolchTimedState timedState = new FloatTimedState(timedStateElem); - addTimedState(timedState); - } else if (typeS.equals(IntegerTimedState.TYPE)) { - StrolchTimedState timedState = new IntegerTimedState(timedStateElem); - addTimedState(timedState); - } else if (typeS.equals(BooleanTimedState.TYPE)) { - StrolchTimedState timedState = new BooleanTimedState(timedStateElem); - addTimedState(timedState); - } else if (typeS.equals(StringSetTimedState.TYPE)) { - StrolchTimedState timedState = new StringSetTimedState(timedStateElem); - addTimedState(timedState); - } else { - String msg = "What kind of TimedState is this: {0}"; //$NON-NLS-1$ - msg = MessageFormat.format(msg, typeS); - throw new StrolchException(msg); - } - } - } + if (typeS.equals(FloatTimedState.TYPE)) { + StrolchTimedState timedState = new FloatTimedState(timedStateElem); + addTimedState(timedState); + } else if (typeS.equals(IntegerTimedState.TYPE)) { + StrolchTimedState timedState = new IntegerTimedState(timedStateElem); + addTimedState(timedState); + } else if (typeS.equals(BooleanTimedState.TYPE)) { + StrolchTimedState timedState = new BooleanTimedState(timedStateElem); + addTimedState(timedState); + } else if (typeS.equals(StringSetTimedState.TYPE)) { + StrolchTimedState timedState = new StringSetTimedState(timedStateElem); + addTimedState(timedState); + } else { + String msg = "What kind of TimedState is this: {0}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, typeS); + throw new StrolchException(msg); + } + } + } - public void addTimedState(StrolchTimedState strolchTimedState) { - if (this.timedStateMap == null) { - this.timedStateMap = new HashMap<>(); - } + public void addTimedState(StrolchTimedState strolchTimedState) { + if (this.timedStateMap == null) { + this.timedStateMap = new HashMap<>(); + } - this.timedStateMap.put(strolchTimedState.getId(), strolchTimedState); - strolchTimedState.setParent(this); - } + this.timedStateMap.put(strolchTimedState.getId(), strolchTimedState); + strolchTimedState.setParent(this); + } - @SuppressWarnings({"rawtypes", "unchecked"}) - public T getTimedState(String id) { - if (this.timedStateMap == null) { - return null; - } - return (T) this.timedStateMap.get(id); - } + @SuppressWarnings({"rawtypes", "unchecked"}) + public T getTimedState(String id) { + if (this.timedStateMap == null) { + return null; + } + return (T) this.timedStateMap.get(id); + } - @SuppressWarnings({"unchecked", "rawtypes"}) - public T removeTimedState(String id) { - if (this.timedStateMap == null) { - return null; - } - return (T) this.timedStateMap.remove(id); - } + @SuppressWarnings({"unchecked", "rawtypes"}) + public T removeTimedState(String id) { + if (this.timedStateMap == null) { + return null; + } + return (T) this.timedStateMap.remove(id); + } - public Set getTimedStateKeySet() { - if (this.timedStateMap == null) { - return Collections.emptySet(); - } - return new HashSet<>(this.timedStateMap.keySet()); - } + public Set getTimedStateKeySet() { + if (this.timedStateMap == null) { + return Collections.emptySet(); + } + return new HashSet<>(this.timedStateMap.keySet()); + } - public List> getTimedStates() { - if (this.timedStateMap == null) { - return Collections.emptyList(); - } - return new ArrayList<>(this.timedStateMap.values()); - } + public List> getTimedStates() { + if (this.timedStateMap == null) { + return Collections.emptyList(); + } + return new ArrayList<>(this.timedStateMap.values()); + } - public boolean hasTimedStates() { - return this.timedStateMap != null && !this.timedStateMap.isEmpty(); - } + public boolean hasTimedStates() { + return this.timedStateMap != null && !this.timedStateMap.isEmpty(); + } - public boolean hasTimedState(String id) { - return this.timedStateMap != null && this.timedStateMap.containsKey(id); - } + public boolean hasTimedState(String id) { + return this.timedStateMap != null && this.timedStateMap.containsKey(id); + } - @Override - public Element toDom(Document doc) { + @Override + public Element toDom(Document doc) { - Element element = doc.createElement(Tags.RESOURCE); - fillElement(element); + Element element = doc.createElement(Tags.RESOURCE); + fillElement(element); - if (this.timedStateMap != null) { - for (StrolchTimedState state : this.timedStateMap.values()) { - Element timedStateElem = state.toDom(element.getOwnerDocument()); - element.appendChild(timedStateElem); - } - } + if (this.timedStateMap != null) { + for (StrolchTimedState state : this.timedStateMap.values()) { + Element timedStateElem = state.toDom(element.getOwnerDocument()); + element.appendChild(timedStateElem); + } + } - return element; - } + return element; + } - @Override - public Resource getClone() { - Resource clone = new Resource(); + @Override + public Resource getClone() { + Resource clone = new Resource(); - super.fillClone(clone); + super.fillClone(clone); - return clone; - } + return clone; + } - @Override - public void fillLocator(LocatorBuilder lb) { - lb.append(Tags.RESOURCE).append(getType()).append(getId()); - } + @Override + public void fillLocator(LocatorBuilder lb) { + lb.append(Tags.RESOURCE).append(getType()).append(getId()); + } - @Override - public Locator getLocator() { - LocatorBuilder lb = new LocatorBuilder(); - fillLocator(lb); - return lb.build(); - } + @Override + public Locator getLocator() { + LocatorBuilder lb = new LocatorBuilder(); + fillLocator(lb); + return lb.build(); + } - @Override - public StrolchElement getParent() { - return null; - } + @Override + public StrolchElement getParent() { + return null; + } - @Override - public Resource getRootElement() { - return this; - } + @Override + public Resource getRootElement() { + return this; + } - @Override - public T accept(StrolchRootElementVisitor visitor) { - return visitor.visitResource(this); - } + @Override + public T accept(StrolchRootElementVisitor visitor) { + return visitor.visitResource(this); + } - @SuppressWarnings("nls") - @Override - public String toString() { + @SuppressWarnings("nls") + @Override + public String toString() { - StringBuilder builder = new StringBuilder(); + StringBuilder builder = new StringBuilder(); - builder.append("Resource [id="); - builder.append(this.id); - builder.append(", name="); - builder.append(this.name); - builder.append(", type="); - builder.append(this.type); - builder.append("]"); + builder.append("Resource [id="); + builder.append(this.id); + builder.append(", name="); + builder.append(this.name); + builder.append(", type="); + builder.append(this.type); + builder.append("]"); - return builder.toString(); - } + return builder.toString(); + } } diff --git a/src/main/java/li/strolch/model/ResourceVisitor.java b/src/main/java/li/strolch/model/ResourceVisitor.java index e96909b97..5d3816a63 100644 --- a/src/main/java/li/strolch/model/ResourceVisitor.java +++ b/src/main/java/li/strolch/model/ResourceVisitor.java @@ -20,7 +20,7 @@ import li.strolch.model.visitor.StrolchElementVisitor; /** * @author Robert von Burg */ -public interface ResourceVisitor extends StrolchElementVisitor{ +public interface ResourceVisitor extends StrolchElementVisitor { @Override public void visit(Resource element); diff --git a/src/main/java/li/strolch/model/StrolchElement.java b/src/main/java/li/strolch/model/StrolchElement.java index e556f42e2..85f171a21 100644 --- a/src/main/java/li/strolch/model/StrolchElement.java +++ b/src/main/java/li/strolch/model/StrolchElement.java @@ -27,7 +27,7 @@ public interface StrolchElement extends Serializable, Comparable /** * Return the {@link Locator} for this element - * + * * @return the {@link Locator} for this element */ public Locator getLocator(); @@ -35,7 +35,7 @@ public interface StrolchElement extends Serializable, Comparable /** * Set the semi unique id of this {@link StrolchElement}. This value should be unique under all concrete * implementations of this interface - * + * * @param id */ public void setId(String id); @@ -43,53 +43,52 @@ public interface StrolchElement extends Serializable, Comparable /** * Returns the semi unique id of this {@link StrolchElement}. This value should be unique under all concrete * implementations of this interface - * + * * @return */ public String getId(); /** * Set the name of this {@link StrolchElement} - * + * * @param name */ public void setName(String name); /** * Returns the name of this {@link StrolchElement} - * + * * @return */ public String getName(); /** * Set the currently set long value which defines the primary key for use in RDBM-Systems - * + * * @param dbid */ public void setDbid(long dbid); /** * Returns the currently set long value which defines the primary key for use in RDBM-Systems - * + * * @return */ public long getDbid(); /** * Returns an {@link Element} object which is an XML representation of this object - * - * @param doc - * the document to which this element is being written. The client must not append to the document, the - * caller will perform this as needed - * + * + * @param doc the document to which this element is being written. The client must not append to the document, the + * caller will perform this as needed + * * @return */ public Element toDom(Document doc); /** * Returns the type of this {@link StrolchElement} - * + * * @return */ public String getType(); @@ -100,7 +99,7 @@ public interface StrolchElement extends Serializable, Comparable /** * Return a clone of this {@link StrolchElement} - * + * * @return */ public StrolchElement getClone(); diff --git a/src/main/java/li/strolch/model/StrolchRootElement.java b/src/main/java/li/strolch/model/StrolchRootElement.java index 265cd185d..42ac8942c 100644 --- a/src/main/java/li/strolch/model/StrolchRootElement.java +++ b/src/main/java/li/strolch/model/StrolchRootElement.java @@ -20,7 +20,7 @@ import li.strolch.model.visitor.StrolchRootElementVisitor; /** * Root element for all top level {@link StrolchElement}. These are elements which have no parent, e.g. {@link Resource * Resources} and {@link Order Orders} - * + * * @author Robert von Burg */ public interface StrolchRootElement extends StrolchElement { diff --git a/src/main/java/li/strolch/model/Tags.java b/src/main/java/li/strolch/model/Tags.java index 52733c40f..879b36a56 100644 --- a/src/main/java/li/strolch/model/Tags.java +++ b/src/main/java/li/strolch/model/Tags.java @@ -25,7 +25,7 @@ public class Tags { public static final String DATE = "Date"; public static final String STATE = "State"; public static final String VALUE = "Value"; - public static final String TIME = "Time"; + public static final String TIME = "Time"; public static final String INTERPRETATION = "Interpretation"; public static final String UOM = "Uom"; public static final String HIDDEN = "Hidden"; diff --git a/src/main/java/li/strolch/model/parameter/AbstractParameter.java b/src/main/java/li/strolch/model/parameter/AbstractParameter.java index a2895713a..95ea81de5 100644 --- a/src/main/java/li/strolch/model/parameter/AbstractParameter.java +++ b/src/main/java/li/strolch/model/parameter/AbstractParameter.java @@ -33,7 +33,7 @@ import ch.eitchnet.utils.helper.StringHelper; /** * @author Robert von Burg - * + * * @param */ public abstract class AbstractParameter extends AbstractStrolchElement implements Parameter { @@ -56,7 +56,7 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem /** * Default constructor - * + * * @param id * @param name */ @@ -134,14 +134,18 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem element.setAttribute(Tags.VALUE, getValueAsString()); - if (!this.interpretation.equals(Parameter.INTERPRETATION_NONE)) + if (!this.interpretation.equals(Parameter.INTERPRETATION_NONE)) { element.setAttribute(Tags.INTERPRETATION, this.interpretation); - if (!this.uom.equals(Parameter.UOM_NONE)) + } + if (!this.uom.equals(Parameter.UOM_NONE)) { element.setAttribute(Tags.UOM, this.uom); - if (this.hidden) + } + if (this.hidden) { element.setAttribute(Tags.HIDDEN, Boolean.toString(this.hidden)); - if (this.index != 0) + } + if (this.index != 0) { element.setAttribute(Tags.INDEX, Integer.toString(this.index)); + } return element; } @@ -206,12 +210,10 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem /** * Validates that the value is legal. This is the case when it is not null in this implementation - * - * @param value - * the value to check for this parameter instance - * - * @throws StrolchException - * if the value is null + * + * @param value the value to check for this parameter instance + * + * @throws StrolchException if the value is null */ protected void validateValue(T value) throws StrolchException { if (value == null) { @@ -223,7 +225,7 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem /** * Fills the {@link Parameter} clone with the id, name, hidden, interpretation and uom - * + * * @param clone */ protected void fillClone(Parameter clone) { diff --git a/src/main/java/li/strolch/model/parameter/BooleanParameter.java b/src/main/java/li/strolch/model/parameter/BooleanParameter.java index ea380dc5e..2596dba0c 100644 --- a/src/main/java/li/strolch/model/parameter/BooleanParameter.java +++ b/src/main/java/li/strolch/model/parameter/BooleanParameter.java @@ -44,7 +44,7 @@ public class BooleanParameter extends AbstractParameter { /** * Default constructors - * + * * @param id * @param name * @param value @@ -56,7 +56,7 @@ public class BooleanParameter extends AbstractParameter { /** * DOM Constructor - * + * * @param element */ public BooleanParameter(Element element) { diff --git a/src/main/java/li/strolch/model/parameter/DateParameter.java b/src/main/java/li/strolch/model/parameter/DateParameter.java index 86f19f2ad..ffffb8462 100644 --- a/src/main/java/li/strolch/model/parameter/DateParameter.java +++ b/src/main/java/li/strolch/model/parameter/DateParameter.java @@ -46,7 +46,7 @@ public class DateParameter extends AbstractParameter { /** * Default Constructor - * + * * @param id * @param name * @param value @@ -58,7 +58,7 @@ public class DateParameter extends AbstractParameter { /** * DOM Constructor - * + * * @param element */ public DateParameter(Element element) { diff --git a/src/main/java/li/strolch/model/parameter/FloatParameter.java b/src/main/java/li/strolch/model/parameter/FloatParameter.java index 7d322dc56..565ce2738 100644 --- a/src/main/java/li/strolch/model/parameter/FloatParameter.java +++ b/src/main/java/li/strolch/model/parameter/FloatParameter.java @@ -27,7 +27,7 @@ import ch.eitchnet.utils.helper.StringHelper; /** * @author Robert von Burg - * + * */ public class FloatParameter extends AbstractParameter { @@ -45,7 +45,7 @@ public class FloatParameter extends AbstractParameter { /** * Default constructor - * + * * @param id * @param name * @param value @@ -58,7 +58,7 @@ public class FloatParameter extends AbstractParameter { /** * DOM Constructor - * + * * @param element */ public FloatParameter(Element element) { diff --git a/src/main/java/li/strolch/model/parameter/IntegerParameter.java b/src/main/java/li/strolch/model/parameter/IntegerParameter.java index a1db56027..cf29997d4 100644 --- a/src/main/java/li/strolch/model/parameter/IntegerParameter.java +++ b/src/main/java/li/strolch/model/parameter/IntegerParameter.java @@ -27,7 +27,7 @@ import ch.eitchnet.utils.helper.StringHelper; /** * @author Robert von Burg - * + * */ public class IntegerParameter extends AbstractParameter { @@ -45,7 +45,7 @@ public class IntegerParameter extends AbstractParameter { /** * Default constructor - * + * * @param id * @param name * @param value @@ -57,7 +57,7 @@ public class IntegerParameter extends AbstractParameter { /** * DOM Constructor - * + * * @param element */ public IntegerParameter(Element element) { diff --git a/src/main/java/li/strolch/model/parameter/ListParameter.java b/src/main/java/li/strolch/model/parameter/ListParameter.java index d7d46a6c1..149b91c8d 100644 --- a/src/main/java/li/strolch/model/parameter/ListParameter.java +++ b/src/main/java/li/strolch/model/parameter/ListParameter.java @@ -19,7 +19,7 @@ import java.util.List; /** * @author Robert von Burg - * + * */ public interface ListParameter extends Parameter> { @@ -27,18 +27,16 @@ public interface ListParameter extends Parameter> { /** * Adds a single value to the {@link List} of values - * - * @param value - * the value to add + * + * @param value the value to add */ public void addValue(E value); /** * Removes a single value from the {@link List} of values - * - * @param value - * the value to remove - * + * + * @param value the value to remove + * * @return true if the value was removed, false if it did not exist */ public boolean removeValue(E value); diff --git a/src/main/java/li/strolch/model/parameter/LongParameter.java b/src/main/java/li/strolch/model/parameter/LongParameter.java index 42573a443..0e47f51a9 100644 --- a/src/main/java/li/strolch/model/parameter/LongParameter.java +++ b/src/main/java/li/strolch/model/parameter/LongParameter.java @@ -27,7 +27,7 @@ import ch.eitchnet.utils.helper.StringHelper; /** * @author Robert von Burg - * + * */ public class LongParameter extends AbstractParameter { @@ -45,7 +45,7 @@ public class LongParameter extends AbstractParameter { /** * Default constructor - * + * * @param id * @param name * @param value @@ -57,7 +57,7 @@ public class LongParameter extends AbstractParameter { /** * DOM Constructor - * + * * @param element */ public LongParameter(Element element) { diff --git a/src/main/java/li/strolch/model/parameter/Parameter.java b/src/main/java/li/strolch/model/parameter/Parameter.java index 71bb27f4e..e9c46140e 100644 --- a/src/main/java/li/strolch/model/parameter/Parameter.java +++ b/src/main/java/li/strolch/model/parameter/Parameter.java @@ -23,7 +23,7 @@ import li.strolch.model.visitor.ParameterVisitor; /** * @author Robert von Burg - * + * */ public interface Parameter extends StrolchElement { @@ -51,71 +51,70 @@ public interface Parameter extends StrolchElement { /** * the value of the parameter as string - * + * * @return String */ public String getValueAsString(); /** * the value of the parameter - * + * * @return */ public T getValue(); /** * the value of the parameter - * + * * @param value */ public void setValue(T value); /** * get the hidden attribute - * + * * @return */ public boolean isHidden(); /** * set the hidden attribute - * + * * @param hidden */ public void setHidden(boolean hidden); /** * Get the UOM of this {@link Parameter} - * + * * @return */ public String getUom(); /** * Set the UOM of this {@link Parameter} - * + * * @param uom */ public void setUom(String uom); /** * Returns the index of this {@link Parameter}. This can be used to sort the parameters in a UI - * + * * @return the index of this {@link Parameter}. This can be used to sort the parameters in a UI */ public int getIndex(); /** * Set the index of this {@link Parameter}. This can be used to sort the parameters in a UI - * - * @param index - * the index to set + * + * @param index the index to set */ public void setIndex(int index); /** * The {@link ParameterizedElement} parent to which this {@link Parameter} belongs - * + * * @return */ public ParameterizedElement getParent(); @@ -133,7 +132,7 @@ public interface Parameter extends StrolchElement { *
  • {@link Parameter#INTERPRETATION_ORDER_REF}
  • *
  • {@link Parameter#INTERPRETATION_RESOURCE_REF}
  • * - * + * * @return string value */ public String getInterpretation(); @@ -146,7 +145,7 @@ public interface Parameter extends StrolchElement { *
  • {@link Parameter#INTERPRETATION_ORDER_REF}
  • *
  • {@link Parameter#INTERPRETATION_RESOURCE_REF}
  • * - * + * * @param interpretation */ public void setInterpretation(String interpretation); diff --git a/src/main/java/li/strolch/model/parameter/StringListParameter.java b/src/main/java/li/strolch/model/parameter/StringListParameter.java index 0f7722076..3068011f9 100644 --- a/src/main/java/li/strolch/model/parameter/StringListParameter.java +++ b/src/main/java/li/strolch/model/parameter/StringListParameter.java @@ -49,7 +49,7 @@ public class StringListParameter extends AbstractParameter> impleme /** * Default constructor - * + * * @param id * @param name * @param value @@ -62,7 +62,7 @@ public class StringListParameter extends AbstractParameter> impleme /** * DOM Constructor - * + * * @param element */ public StringListParameter(Element element) { @@ -79,8 +79,9 @@ public class StringListParameter extends AbstractParameter> impleme @Override public String getValueAsString() { - if (this.value.isEmpty()) + if (this.value.isEmpty()) { return StringHelper.EMPTY; + } StringBuilder sb = new StringBuilder(); Iterator iter = this.value.iterator(); @@ -88,8 +89,9 @@ public class StringListParameter extends AbstractParameter> impleme sb.append(iter.next()); - if (iter.hasNext()) + if (iter.hasNext()) { sb.append(VALUE_SEPARATOR); + } } return sb.toString(); @@ -103,8 +105,9 @@ public class StringListParameter extends AbstractParameter> impleme @Override public void setValue(List value) { validateValue(value); - if (this.value == null) + if (this.value == null) { this.value = new ArrayList(value.size()); + } this.value.clear(); this.value.addAll(value); } @@ -141,8 +144,9 @@ public class StringListParameter extends AbstractParameter> impleme } public static List parseFromString(String value) { - if (value.isEmpty()) + if (value.isEmpty()) { return Collections.emptyList(); + } String[] valueArr = value.split(VALUE_SEPARATOR); return Arrays.asList(valueArr); diff --git a/src/main/java/li/strolch/model/parameter/StringParameter.java b/src/main/java/li/strolch/model/parameter/StringParameter.java index 262a57a09..b7c65b897 100644 --- a/src/main/java/li/strolch/model/parameter/StringParameter.java +++ b/src/main/java/li/strolch/model/parameter/StringParameter.java @@ -27,7 +27,7 @@ import ch.eitchnet.utils.helper.StringHelper; /** * @author Robert von Burg - * + * */ public class StringParameter extends AbstractParameter { @@ -39,7 +39,7 @@ public class StringParameter extends AbstractParameter { /** * Empty constructor - * + * */ public StringParameter() { // @@ -47,7 +47,7 @@ public class StringParameter extends AbstractParameter { /** * Default constructor - * + * * @param id * @param name * @param value @@ -59,7 +59,7 @@ public class StringParameter extends AbstractParameter { /** * DOM Constructor - * + * * @param element */ public StringParameter(Element element) { diff --git a/src/main/java/li/strolch/model/query/Navigation.java b/src/main/java/li/strolch/model/query/Navigation.java index 9ff8d23f2..3ddb304fe 100644 --- a/src/main/java/li/strolch/model/query/Navigation.java +++ b/src/main/java/li/strolch/model/query/Navigation.java @@ -15,14 +15,12 @@ */ package li.strolch.model.query; - /** * @author Robert von Burg - * + * */ public interface Navigation { // marker interface - public void accept(QueryVisitor visitor); } diff --git a/src/main/java/li/strolch/model/query/NotSelection.java b/src/main/java/li/strolch/model/query/NotSelection.java index a6ea2e0cf..195ae6b86 100644 --- a/src/main/java/li/strolch/model/query/NotSelection.java +++ b/src/main/java/li/strolch/model/query/NotSelection.java @@ -28,8 +28,7 @@ public class NotSelection extends BooleanSelection { } /** - * @throws UnsupportedOperationException - * because a {@link NotSelection} can only work on a single {@link Selection} + * @throws UnsupportedOperationException because a {@link NotSelection} can only work on a single {@link Selection} */ @Override public NotSelection with(Selection selection) { diff --git a/src/main/java/li/strolch/model/query/OrderQueryVisitor.java b/src/main/java/li/strolch/model/query/OrderQueryVisitor.java index 5923efce8..91196a0f3 100644 --- a/src/main/java/li/strolch/model/query/OrderQueryVisitor.java +++ b/src/main/java/li/strolch/model/query/OrderQueryVisitor.java @@ -17,7 +17,7 @@ package li.strolch.model.query; /** * @author Robert von Burg - * + * */ public interface OrderQueryVisitor extends OrderSelectionVisitor, ParameterSelectionVisitor { diff --git a/src/main/java/li/strolch/model/query/OrderSelection.java b/src/main/java/li/strolch/model/query/OrderSelection.java index 9549ed8a3..ab6479c42 100644 --- a/src/main/java/li/strolch/model/query/OrderSelection.java +++ b/src/main/java/li/strolch/model/query/OrderSelection.java @@ -17,7 +17,7 @@ package li.strolch.model.query; /** * @author Robert von Burg - * + * */ public abstract class OrderSelection implements Selection { @@ -25,6 +25,6 @@ public abstract class OrderSelection implements Selection { public void accept(QueryVisitor visitor) { accept((OrderSelectionVisitor) visitor); } - + public abstract void accept(OrderSelectionVisitor visitor); } diff --git a/src/main/java/li/strolch/model/query/OrderSelectionVisitor.java b/src/main/java/li/strolch/model/query/OrderSelectionVisitor.java index 708bbce7a..700208027 100644 --- a/src/main/java/li/strolch/model/query/OrderSelectionVisitor.java +++ b/src/main/java/li/strolch/model/query/OrderSelectionVisitor.java @@ -17,7 +17,7 @@ package li.strolch.model.query; /** * @author Robert von Burg - * + * */ public interface OrderSelectionVisitor extends StrolchElementSelectionVisitor { diff --git a/src/main/java/li/strolch/model/query/ParameterSelection.java b/src/main/java/li/strolch/model/query/ParameterSelection.java index b57df7137..a3cc17bdf 100644 --- a/src/main/java/li/strolch/model/query/ParameterSelection.java +++ b/src/main/java/li/strolch/model/query/ParameterSelection.java @@ -139,6 +139,7 @@ public abstract class ParameterSelection implements Selection { } public static class BooleanParameterSelection extends ParameterSelection { + private Boolean value; public BooleanParameterSelection(String bagKey, String paramKey, Boolean value) { @@ -157,6 +158,7 @@ public abstract class ParameterSelection implements Selection { } public static class LongParameterSelection extends ParameterSelection { + private Long value; public LongParameterSelection(String bagKey, String paramKey, Long value) { @@ -175,6 +177,7 @@ public abstract class ParameterSelection implements Selection { } public static class FloatParameterSelection extends ParameterSelection { + private Double value; public FloatParameterSelection(String bagKey, String paramKey, Double value) { @@ -193,6 +196,7 @@ public abstract class ParameterSelection implements Selection { } public static class DateParameterSelection extends ParameterSelection { + private Date value; public DateParameterSelection(String bagKey, String paramKey, Date value) { @@ -211,6 +215,7 @@ public abstract class ParameterSelection implements Selection { } public static class StringListParameterSelection extends ParameterSelection { + private List value; public StringListParameterSelection(String bagKey, String paramKey, List value) { diff --git a/src/main/java/li/strolch/model/query/ParameterSelectionVisitor.java b/src/main/java/li/strolch/model/query/ParameterSelectionVisitor.java index 065e862be..b8b767474 100644 --- a/src/main/java/li/strolch/model/query/ParameterSelectionVisitor.java +++ b/src/main/java/li/strolch/model/query/ParameterSelectionVisitor.java @@ -25,7 +25,7 @@ import li.strolch.model.query.ParameterSelection.StringParameterSelection; /** * @author Robert von Burg - * + * */ public interface ParameterSelectionVisitor extends QueryVisitor { diff --git a/src/main/java/li/strolch/model/query/Query.java b/src/main/java/li/strolch/model/query/Query.java index 83dc7ef58..1f2b7057c 100644 --- a/src/main/java/li/strolch/model/query/Query.java +++ b/src/main/java/li/strolch/model/query/Query.java @@ -15,10 +15,9 @@ */ package li.strolch.model.query; - /** * @author Robert von Burg - * + * */ public interface Query { diff --git a/src/main/java/li/strolch/model/query/QueryVisitor.java b/src/main/java/li/strolch/model/query/QueryVisitor.java index f1a9dbe55..e14ccc566 100644 --- a/src/main/java/li/strolch/model/query/QueryVisitor.java +++ b/src/main/java/li/strolch/model/query/QueryVisitor.java @@ -23,6 +23,6 @@ public interface QueryVisitor { public void visitAnd(AndSelection andSelection); public void visitOr(OrSelection orSelection); - + public void visitNot(NotSelection notSelection); } diff --git a/src/main/java/li/strolch/model/query/ResourceQueryVisitor.java b/src/main/java/li/strolch/model/query/ResourceQueryVisitor.java index 8710a65f0..850b6950c 100644 --- a/src/main/java/li/strolch/model/query/ResourceQueryVisitor.java +++ b/src/main/java/li/strolch/model/query/ResourceQueryVisitor.java @@ -17,7 +17,7 @@ package li.strolch.model.query; /** * @author Robert von Burg - * + * */ public interface ResourceQueryVisitor extends StrolchElementSelectionVisitor, ParameterSelectionVisitor { diff --git a/src/main/java/li/strolch/model/query/Selection.java b/src/main/java/li/strolch/model/query/Selection.java index 3b658fe44..aeaded229 100644 --- a/src/main/java/li/strolch/model/query/Selection.java +++ b/src/main/java/li/strolch/model/query/Selection.java @@ -21,6 +21,5 @@ package li.strolch.model.query; public interface Selection { // marker interface - public void accept(QueryVisitor visitor); } diff --git a/src/main/java/li/strolch/model/query/StateSelection.java b/src/main/java/li/strolch/model/query/StateSelection.java index 393838f6c..542776e99 100644 --- a/src/main/java/li/strolch/model/query/StateSelection.java +++ b/src/main/java/li/strolch/model/query/StateSelection.java @@ -19,7 +19,7 @@ import li.strolch.model.State; /** * @author Robert von Burg - * + * */ public class StateSelection { diff --git a/src/main/java/li/strolch/model/query/StrolchTypeNavigation.java b/src/main/java/li/strolch/model/query/StrolchTypeNavigation.java index 82cc8760d..32b23f84a 100644 --- a/src/main/java/li/strolch/model/query/StrolchTypeNavigation.java +++ b/src/main/java/li/strolch/model/query/StrolchTypeNavigation.java @@ -17,7 +17,7 @@ package li.strolch.model.query; /** * @author Robert von Burg - * + * */ public class StrolchTypeNavigation implements Navigation { diff --git a/src/main/java/li/strolch/model/timedstate/AbstractStrolchTimedState.java b/src/main/java/li/strolch/model/timedstate/AbstractStrolchTimedState.java index 61f118599..30faffef5 100644 --- a/src/main/java/li/strolch/model/timedstate/AbstractStrolchTimedState.java +++ b/src/main/java/li/strolch/model/timedstate/AbstractStrolchTimedState.java @@ -32,96 +32,96 @@ import li.strolch.model.timevalue.IValueChange; */ @SuppressWarnings("rawtypes") public abstract class AbstractStrolchTimedState extends AbstractStrolchElement implements - StrolchTimedState { + StrolchTimedState { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - protected Resource parent; - protected ITimedState state; + protected Resource parent; + protected ITimedState state; - public AbstractStrolchTimedState() { - this.state = new TimedState<>(); - } + public AbstractStrolchTimedState() { + this.state = new TimedState<>(); + } - public AbstractStrolchTimedState(String id, String name) { - super(id, name); - this.state = new TimedState<>(); - } + public AbstractStrolchTimedState(String id, String name) { + super(id, name); + this.state = new TimedState<>(); + } - @Override - public ITimeValue getNextMatch(Long time, T value) { - return this.state.getNextMatch(time, value); - } + @Override + public ITimeValue getNextMatch(Long time, T value) { + return this.state.getNextMatch(time, value); + } - @Override - public ITimeValue getPreviousMatch(Long time, T value) { - return this.state.getPreviousMatch(time, value); - } + @Override + public ITimeValue getPreviousMatch(Long time, T value) { + return this.state.getPreviousMatch(time, value); + } - @Override - public > void applyChange(U change) { - this.state.applyChange(change); - } + @Override + public > void applyChange(U change) { + this.state.applyChange(change); + } - @Override - public ITimeValue getStateAt(Long time) { - return this.state.getStateAt(time); - } + @Override + public ITimeValue getStateAt(Long time) { + return this.state.getStateAt(time); + } - @Override - public ITimeVariable getTimeEvolution() { - return this.state.getTimeEvolution(); - } + @Override + public ITimeVariable getTimeEvolution() { + return this.state.getTimeEvolution(); + } - @Override - public StrolchElement getParent() { - return this.parent; - } + @Override + public StrolchElement getParent() { + return this.parent; + } - @Override - public void setParent(Resource parent) { - this.parent = parent; - } + @Override + public void setParent(Resource parent) { + this.parent = parent; + } - @Override - public StrolchRootElement getRootElement() { - return this.parent; - } + @Override + public StrolchRootElement getRootElement() { + return this.parent; + } - @Override - protected void fillLocator(LocatorBuilder locatorBuilder) { - locatorBuilder.append(Tags.TIMED_STATE); - locatorBuilder.append(getId()); - } + @Override + protected void fillLocator(LocatorBuilder locatorBuilder) { + locatorBuilder.append(Tags.TIMED_STATE); + locatorBuilder.append(getId()); + } - @Override - public Locator getLocator() { - LocatorBuilder lb = new LocatorBuilder(); - this.parent.fillLocator(lb); - fillLocator(lb); - return lb.build(); - } + @Override + public Locator getLocator() { + LocatorBuilder lb = new LocatorBuilder(); + this.parent.fillLocator(lb); + fillLocator(lb); + return lb.build(); + } - protected void fillClone(AbstractStrolchTimedState clone) { - super.fillClone(clone); - clone.state = this.state.getCopy(); - } + protected void fillClone(AbstractStrolchTimedState clone) { + super.fillClone(clone); + clone.state = this.state.getCopy(); + } - @SuppressWarnings("nls") - @Override - public String toString() { + @SuppressWarnings("nls") + @Override + public String toString() { - StringBuilder builder = new StringBuilder(); + StringBuilder builder = new StringBuilder(); - builder.append(getClass().getSimpleName()); - builder.append(" [id="); - builder.append(this.id); - builder.append(", name="); - builder.append(this.name); - builder.append(", valueNow="); - builder.append(this.state.getStateAt(System.currentTimeMillis())); - builder.append("]"); + builder.append(getClass().getSimpleName()); + builder.append(" [id="); + builder.append(this.id); + builder.append(", name="); + builder.append(this.name); + builder.append(", valueNow="); + builder.append(this.state.getStateAt(System.currentTimeMillis())); + builder.append("]"); - return builder.toString(); - } + return builder.toString(); + } } diff --git a/src/main/java/li/strolch/model/timedstate/BooleanTimedState.java b/src/main/java/li/strolch/model/timedstate/BooleanTimedState.java index fce5aa0c1..725570c51 100644 --- a/src/main/java/li/strolch/model/timedstate/BooleanTimedState.java +++ b/src/main/java/li/strolch/model/timedstate/BooleanTimedState.java @@ -29,60 +29,60 @@ import org.w3c.dom.NodeList; */ public class BooleanTimedState extends AbstractStrolchTimedState { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - public static final String TYPE = "BooleanState"; + public static final String TYPE = "BooleanState"; - public BooleanTimedState() { - super(); - } + public BooleanTimedState() { + super(); + } - public BooleanTimedState(String id, String name) { - super(id, name); - } + public BooleanTimedState(String id, String name) { + super(id, name); + } - public BooleanTimedState(Element element) { - super.fromDom(element); + public BooleanTimedState(Element element) { + super.fromDom(element); - this.state = new TimedState<>(); + this.state = new TimedState<>(); - NodeList timeValueElems = element.getElementsByTagName(Tags.VALUE); - for (int i = 0; i < timeValueElems.getLength(); i++) { - Element timeValueElem = (Element) timeValueElems.item(i); - Long time = Long.valueOf(timeValueElem.getAttribute(Tags.TIME)); - Boolean value = Boolean.valueOf(timeValueElem.getAttribute(Tags.VALUE)); - BooleanValue booleanValue = new BooleanValue(value); - this.state.getTimeEvolution().setValueAt(time, booleanValue); - } - } + NodeList timeValueElems = element.getElementsByTagName(Tags.VALUE); + for (int i = 0; i < timeValueElems.getLength(); i++) { + Element timeValueElem = (Element) timeValueElems.item(i); + Long time = Long.valueOf(timeValueElem.getAttribute(Tags.TIME)); + Boolean value = Boolean.valueOf(timeValueElem.getAttribute(Tags.VALUE)); + BooleanValue booleanValue = new BooleanValue(value); + this.state.getTimeEvolution().setValueAt(time, booleanValue); + } + } - @Override - public Element toDom(Document doc) { + @Override + public Element toDom(Document doc) { - Element stateElement = doc.createElement(Tags.TIMED_STATE); - super.fillElement(stateElement); - SortedSet> values = this.state.getTimeEvolution().getValues(); - for (ITimeValue timeValue : values) { - Long time = timeValue.getTime(); - BooleanValue value = timeValue.getValue(); - Element valueElem = doc.createElement(Tags.VALUE); - valueElem.setAttribute(Tags.TIME, time.toString()); - valueElem.setAttribute(Tags.VALUE, value.getValue().toString()); - stateElement.appendChild(valueElem); - } + Element stateElement = doc.createElement(Tags.TIMED_STATE); + super.fillElement(stateElement); + SortedSet> values = this.state.getTimeEvolution().getValues(); + for (ITimeValue timeValue : values) { + Long time = timeValue.getTime(); + BooleanValue value = timeValue.getValue(); + Element valueElem = doc.createElement(Tags.VALUE); + valueElem.setAttribute(Tags.TIME, time.toString()); + valueElem.setAttribute(Tags.VALUE, value.getValue().toString()); + stateElement.appendChild(valueElem); + } - return stateElement; - } + return stateElement; + } - @Override - public String getType() { - return TYPE; - } + @Override + public String getType() { + return TYPE; + } - @Override - public StrolchElement getClone() { - BooleanTimedState clone = new BooleanTimedState(); - fillClone(clone); - return clone; - } + @Override + public StrolchElement getClone() { + BooleanTimedState clone = new BooleanTimedState(); + fillClone(clone); + return clone; + } } diff --git a/src/main/java/li/strolch/model/timedstate/FloatTimedState.java b/src/main/java/li/strolch/model/timedstate/FloatTimedState.java index 9c153af55..4a6c90713 100644 --- a/src/main/java/li/strolch/model/timedstate/FloatTimedState.java +++ b/src/main/java/li/strolch/model/timedstate/FloatTimedState.java @@ -29,60 +29,60 @@ import org.w3c.dom.NodeList; */ public class FloatTimedState extends AbstractStrolchTimedState { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - public static final String TYPE = "FloatState"; + public static final String TYPE = "FloatState"; - public FloatTimedState() { - super(); - } + public FloatTimedState() { + super(); + } - public FloatTimedState(String id, String name) { - super(id, name); - } + public FloatTimedState(String id, String name) { + super(id, name); + } - public FloatTimedState(Element element) { - super.fromDom(element); + public FloatTimedState(Element element) { + super.fromDom(element); - this.state = new TimedState<>(); + this.state = new TimedState<>(); - NodeList timeValueElems = element.getElementsByTagName(Tags.VALUE); - for (int i = 0; i < timeValueElems.getLength(); i++) { - Element timeValueElem = (Element) timeValueElems.item(i); - Long time = Long.valueOf(timeValueElem.getAttribute(Tags.TIME)); - Double value = Double.valueOf(timeValueElem.getAttribute(Tags.VALUE)); - FloatValue floatValue = new FloatValue(value); - this.state.getTimeEvolution().setValueAt(time, floatValue); - } - } + NodeList timeValueElems = element.getElementsByTagName(Tags.VALUE); + for (int i = 0; i < timeValueElems.getLength(); i++) { + Element timeValueElem = (Element) timeValueElems.item(i); + Long time = Long.valueOf(timeValueElem.getAttribute(Tags.TIME)); + Double value = Double.valueOf(timeValueElem.getAttribute(Tags.VALUE)); + FloatValue floatValue = new FloatValue(value); + this.state.getTimeEvolution().setValueAt(time, floatValue); + } + } - @Override - public Element toDom(Document doc) { + @Override + public Element toDom(Document doc) { - Element stateElement = doc.createElement(Tags.TIMED_STATE); - super.fillElement(stateElement); - SortedSet> values = this.state.getTimeEvolution().getValues(); - for (ITimeValue timeValue : values) { - Long time = timeValue.getTime(); - FloatValue value = timeValue.getValue(); - Element valueElem = doc.createElement(Tags.VALUE); - valueElem.setAttribute(Tags.TIME, time.toString()); - valueElem.setAttribute(Tags.VALUE, value.getValue().toString()); - stateElement.appendChild(valueElem); - } + Element stateElement = doc.createElement(Tags.TIMED_STATE); + super.fillElement(stateElement); + SortedSet> values = this.state.getTimeEvolution().getValues(); + for (ITimeValue timeValue : values) { + Long time = timeValue.getTime(); + FloatValue value = timeValue.getValue(); + Element valueElem = doc.createElement(Tags.VALUE); + valueElem.setAttribute(Tags.TIME, time.toString()); + valueElem.setAttribute(Tags.VALUE, value.getValue().toString()); + stateElement.appendChild(valueElem); + } - return stateElement; - } + return stateElement; + } - @Override - public String getType() { - return TYPE; - } + @Override + public String getType() { + return TYPE; + } - @Override - public StrolchElement getClone() { - FloatTimedState clone = new FloatTimedState(); - fillClone(clone); - return clone; - } + @Override + public StrolchElement getClone() { + FloatTimedState clone = new FloatTimedState(); + fillClone(clone); + return clone; + } } diff --git a/src/main/java/li/strolch/model/timedstate/ITimedState.java b/src/main/java/li/strolch/model/timedstate/ITimedState.java index 6115a5b1e..42e765f17 100644 --- a/src/main/java/li/strolch/model/timedstate/ITimedState.java +++ b/src/main/java/li/strolch/model/timedstate/ITimedState.java @@ -22,11 +22,10 @@ import li.strolch.model.timevalue.IValueChange; /** * A time based state characterized by a {@link IValue} object implementation. - * + * * @author Martin Smock - * - * @param - * IValue implementation representing the state at a given time + * + * @param IValue implementation representing the state at a given time */ @SuppressWarnings("rawtypes") public interface ITimedState { @@ -42,8 +41,7 @@ public interface ITimedState { ITimeValue getPreviousMatch(final Long time, T value); /** - * @param change - * the state change to be applied + * @param change the state change to be applied */ > void applyChange(final U change); @@ -61,4 +59,4 @@ public interface ITimedState { * @return a copy of this timed state */ ITimedState getCopy(); -} \ No newline at end of file +} diff --git a/src/main/java/li/strolch/model/timedstate/IntegerTimedState.java b/src/main/java/li/strolch/model/timedstate/IntegerTimedState.java index 31e7cec32..220c53b0b 100644 --- a/src/main/java/li/strolch/model/timedstate/IntegerTimedState.java +++ b/src/main/java/li/strolch/model/timedstate/IntegerTimedState.java @@ -29,60 +29,60 @@ import org.w3c.dom.NodeList; */ public class IntegerTimedState extends AbstractStrolchTimedState { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - public static final String TYPE = "IntegerState"; + public static final String TYPE = "IntegerState"; - public IntegerTimedState() { - super(); - } + public IntegerTimedState() { + super(); + } - public IntegerTimedState(String id, String name) { - super(id, name); - } + public IntegerTimedState(String id, String name) { + super(id, name); + } - public IntegerTimedState(Element element) { - super.fromDom(element); + public IntegerTimedState(Element element) { + super.fromDom(element); - this.state = new TimedState<>(); + this.state = new TimedState<>(); - NodeList timeValueElems = element.getElementsByTagName(Tags.VALUE); - for (int i = 0; i < timeValueElems.getLength(); i++) { - Element timeValueElem = (Element) timeValueElems.item(i); - Long time = Long.valueOf(timeValueElem.getAttribute(Tags.TIME)); - Integer value = Integer.valueOf(timeValueElem.getAttribute(Tags.VALUE)); - IntegerValue integerValue = new IntegerValue(value); - this.state.getTimeEvolution().setValueAt(time, integerValue); - } - } + NodeList timeValueElems = element.getElementsByTagName(Tags.VALUE); + for (int i = 0; i < timeValueElems.getLength(); i++) { + Element timeValueElem = (Element) timeValueElems.item(i); + Long time = Long.valueOf(timeValueElem.getAttribute(Tags.TIME)); + Integer value = Integer.valueOf(timeValueElem.getAttribute(Tags.VALUE)); + IntegerValue integerValue = new IntegerValue(value); + this.state.getTimeEvolution().setValueAt(time, integerValue); + } + } - @Override - public Element toDom(Document doc) { + @Override + public Element toDom(Document doc) { - Element stateElement = doc.createElement(Tags.TIMED_STATE); - super.fillElement(stateElement); - SortedSet> values = this.state.getTimeEvolution().getValues(); - for (ITimeValue timeValue : values) { - Long time = timeValue.getTime(); - IntegerValue value = timeValue.getValue(); - Element valueElem = doc.createElement(Tags.VALUE); - valueElem.setAttribute(Tags.TIME, time.toString()); - valueElem.setAttribute(Tags.VALUE, value.getValue().toString()); - stateElement.appendChild(valueElem); - } + Element stateElement = doc.createElement(Tags.TIMED_STATE); + super.fillElement(stateElement); + SortedSet> values = this.state.getTimeEvolution().getValues(); + for (ITimeValue timeValue : values) { + Long time = timeValue.getTime(); + IntegerValue value = timeValue.getValue(); + Element valueElem = doc.createElement(Tags.VALUE); + valueElem.setAttribute(Tags.TIME, time.toString()); + valueElem.setAttribute(Tags.VALUE, value.getValue().toString()); + stateElement.appendChild(valueElem); + } - return stateElement; - } + return stateElement; + } - @Override - public String getType() { - return TYPE; - } + @Override + public String getType() { + return TYPE; + } - @Override - public StrolchElement getClone() { - IntegerTimedState clone = new IntegerTimedState(); - fillClone(clone); - return clone; - } + @Override + public StrolchElement getClone() { + IntegerTimedState clone = new IntegerTimedState(); + fillClone(clone); + return clone; + } } diff --git a/src/main/java/li/strolch/model/timedstate/StringSetTimedState.java b/src/main/java/li/strolch/model/timedstate/StringSetTimedState.java index 13722527e..99193c401 100644 --- a/src/main/java/li/strolch/model/timedstate/StringSetTimedState.java +++ b/src/main/java/li/strolch/model/timedstate/StringSetTimedState.java @@ -33,79 +33,79 @@ import org.w3c.dom.NodeList; */ public class StringSetTimedState extends AbstractStrolchTimedState { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - public static final String TYPE = "StringSetState"; + public static final String TYPE = "StringSetState"; - public StringSetTimedState() { - super(); - } + public StringSetTimedState() { + super(); + } - public StringSetTimedState(String id, String name) { - super(id, name); - } + public StringSetTimedState(String id, String name) { + super(id, name); + } - public StringSetTimedState(Element element) { - super.fromDom(element); + public StringSetTimedState(Element element) { + super.fromDom(element); - this.state = new TimedState<>(); + this.state = new TimedState<>(); - NodeList timeValueElems = element.getElementsByTagName(Tags.VALUE); - for (int i = 0; i < timeValueElems.getLength(); i++) { - Element timeValueElem = (Element) timeValueElems.item(i); - Long time = Long.valueOf(timeValueElem.getAttribute(Tags.TIME)); + NodeList timeValueElems = element.getElementsByTagName(Tags.VALUE); + for (int i = 0; i < timeValueElems.getLength(); i++) { + Element timeValueElem = (Element) timeValueElems.item(i); + Long time = Long.valueOf(timeValueElem.getAttribute(Tags.TIME)); - String valueAsString = timeValueElem.getAttribute(Tags.VALUE); - Set value = new HashSet<>(); - String[] values = valueAsString.split(","); - for (String s : values) { - value.add(new AString(s.trim())); - } + String valueAsString = timeValueElem.getAttribute(Tags.VALUE); + Set value = new HashSet<>(); + String[] values = valueAsString.split(","); + for (String s : values) { + value.add(new AString(s.trim())); + } - StringSetValue integerValue = new StringSetValue(value); - this.state.getTimeEvolution().setValueAt(time, integerValue); - } - } + StringSetValue integerValue = new StringSetValue(value); + this.state.getTimeEvolution().setValueAt(time, integerValue); + } + } - @Override - public Element toDom(Document doc) { + @Override + public Element toDom(Document doc) { - Element stateElement = doc.createElement(Tags.TIMED_STATE); - super.fillElement(stateElement); - SortedSet> values = this.state.getTimeEvolution().getValues(); - for (ITimeValue timeValue : values) { - Long time = timeValue.getTime(); - StringSetValue stringSetValue = timeValue.getValue(); + Element stateElement = doc.createElement(Tags.TIMED_STATE); + super.fillElement(stateElement); + SortedSet> values = this.state.getTimeEvolution().getValues(); + for (ITimeValue timeValue : values) { + Long time = timeValue.getTime(); + StringSetValue stringSetValue = timeValue.getValue(); - Set value = stringSetValue.getValue(); - StringBuilder sb = new StringBuilder(); - Iterator iter = value.iterator(); - while (iter.hasNext()) { - sb.append(iter.next().getString()); - if (iter.hasNext()) { - sb.append(", "); - } - } - String valueAsString = sb.toString(); + Set value = stringSetValue.getValue(); + StringBuilder sb = new StringBuilder(); + Iterator iter = value.iterator(); + while (iter.hasNext()) { + sb.append(iter.next().getString()); + if (iter.hasNext()) { + sb.append(", "); + } + } + String valueAsString = sb.toString(); - Element valueElem = doc.createElement(Tags.VALUE); - valueElem.setAttribute(Tags.TIME, time.toString()); - valueElem.setAttribute(Tags.VALUE, valueAsString); - stateElement.appendChild(valueElem); - } + Element valueElem = doc.createElement(Tags.VALUE); + valueElem.setAttribute(Tags.TIME, time.toString()); + valueElem.setAttribute(Tags.VALUE, valueAsString); + stateElement.appendChild(valueElem); + } - return stateElement; - } + return stateElement; + } - @Override - public String getType() { - return TYPE; - } + @Override + public String getType() { + return TYPE; + } - @Override - public StrolchElement getClone() { - StringSetTimedState clone = new StringSetTimedState(); - fillClone(clone); - return clone; - } + @Override + public StrolchElement getClone() { + StringSetTimedState clone = new StringSetTimedState(); + fillClone(clone); + return clone; + } } diff --git a/src/main/java/li/strolch/model/timedstate/StrolchTimedState.java b/src/main/java/li/strolch/model/timedstate/StrolchTimedState.java index f2ab09454..f70d406c3 100644 --- a/src/main/java/li/strolch/model/timedstate/StrolchTimedState.java +++ b/src/main/java/li/strolch/model/timedstate/StrolchTimedState.java @@ -38,5 +38,5 @@ public interface StrolchTimedState extends StrolchElement { public ITimeVariable getTimeEvolution(); - public void setParent(Resource aThis); + public void setParent(Resource aThis); } diff --git a/src/main/java/li/strolch/model/timevalue/ITimeValue.java b/src/main/java/li/strolch/model/timevalue/ITimeValue.java index de87f9190..97e9c9643 100644 --- a/src/main/java/li/strolch/model/timevalue/ITimeValue.java +++ b/src/main/java/li/strolch/model/timevalue/ITimeValue.java @@ -19,11 +19,10 @@ import li.strolch.model.timevalue.impl.TimeVariable; /** * Interface for timed value objects to be used with the {@link TimeVariable} - * + * * @author Martin Smock - * - * @param - * the backing value of the timed value object + * + * @param the backing value of the timed value object */ @SuppressWarnings("rawtypes") public interface ITimeValue extends Comparable> { diff --git a/src/main/java/li/strolch/model/timevalue/ITimeVariable.java b/src/main/java/li/strolch/model/timevalue/ITimeVariable.java index 0e7347f79..f16f9aeb8 100644 --- a/src/main/java/li/strolch/model/timevalue/ITimeVariable.java +++ b/src/main/java/li/strolch/model/timevalue/ITimeVariable.java @@ -20,22 +20,19 @@ import java.util.SortedSet; /** * A timed variable storing a ordered sequence of {@link ITimeValue} objects modeling a time evolution of a quantity. - * + * * @author Martin Smock - * - * @param - * the backing value of the timed value object + * + * @param the backing value of the timed value object */ @SuppressWarnings("rawtypes") public interface ITimeVariable { /** * set the value at a point in time to a given time value object - * - * @param time - * the time to set the {@link IValue} - * @param value - * the {@link IValue} to set + * + * @param time the time to set the {@link IValue} + * @param value the {@link IValue} to set */ void setValueAt(final Long time, final T value); @@ -46,33 +43,30 @@ public interface ITimeVariable { /** * Applies a {@link IValueChange} propagating the change to all future values starting from the time of the change. - * - * @param change - * the {@link IValueChange} to be applied + * + * @param change the {@link IValueChange} to be applied */ void applyChange(final IValueChange change); /** * Get all {@link ITimeValue} objects whose time field is greater or equal to the given time - * - * @param time - * the time the sequence starts with + * + * @param time the time the sequence starts with * @return the sequence of {@link ITimeValue} objects in the future */ Collection> getFutureValues(final Long time); /** * Get all {@link ITimeValue} objects whose time field is strictly smaller than the given time - * - * @param time - * the time the sequence starts with + * + * @param time the time the sequence starts with * @return the sequence of {@link ITimeValue} objects in the future */ Collection> getPastValues(final Long time); /** * Get all {@link ITimeValue} objects - * + * * @return a defensive copy of the {@link ITimeValue}s */ SortedSet> getValues(); diff --git a/src/main/java/li/strolch/model/timevalue/IValue.java b/src/main/java/li/strolch/model/timevalue/IValue.java index 83446b94a..94f1d6074 100644 --- a/src/main/java/li/strolch/model/timevalue/IValue.java +++ b/src/main/java/li/strolch/model/timevalue/IValue.java @@ -16,13 +16,12 @@ package li.strolch.model.timevalue; /** - * A value object defining some basic algebraic operations. Mathematically - * speaking {@link IValue} objects define a group with a addition operation. - * + * A value object defining some basic algebraic operations. Mathematically speaking {@link IValue} objects define a + * group with a addition operation. + * * @author Martin Smock - * - * @param - * any object for which a (generalized) add operation can be defined. + * + * @param any object for which a (generalized) add operation can be defined. */ public interface IValue { @@ -42,8 +41,7 @@ public interface IValue { boolean matches(IValue other); /** - * @return the inverse value, such that add(value.getInverse()) returns the - * neutral element of the group + * @return the inverse value, such that add(value.getInverse()) returns the neutral element of the group */ IValue getInverse(); diff --git a/src/main/java/li/strolch/model/timevalue/IValueChange.java b/src/main/java/li/strolch/model/timevalue/IValueChange.java index c4e391cd3..3821f7913 100644 --- a/src/main/java/li/strolch/model/timevalue/IValueChange.java +++ b/src/main/java/li/strolch/model/timevalue/IValueChange.java @@ -16,9 +16,8 @@ package li.strolch.model.timevalue; /** - * Interface for operators to be used to change the values of {@link ITimeValue} - * in a {@link ITimeVariable}. - * + * Interface for operators to be used to change the values of {@link ITimeValue} in a {@link ITimeVariable}. + * * @author Martin Smock */ @SuppressWarnings("rawtypes") @@ -35,8 +34,7 @@ public interface IValueChange { T getValue(); /** - * @return the inverse neutralizing a change. Very useful to undo changes - * applied. + * @return the inverse neutralizing a change. Very useful to undo changes applied. */ IValueChange getInverse(); diff --git a/src/main/java/li/strolch/model/timevalue/impl/AString.java b/src/main/java/li/strolch/model/timevalue/impl/AString.java index e66567552..5626bef3a 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/AString.java +++ b/src/main/java/li/strolch/model/timevalue/impl/AString.java @@ -18,15 +18,14 @@ package li.strolch.model.timevalue.impl; import java.io.Serializable; /** - * Wrapper for java.util.String object defining a inverse to support algebraic - * operations. - * + * Wrapper for java.util.String object defining a inverse to support algebraic operations. + * * @author Martin Smock */ public class AString implements Serializable { - + private static final long serialVersionUID = 1L; - + private final String string; private final boolean inverse; @@ -63,20 +62,26 @@ public class AString implements Serializable { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } AString other = (AString) obj; - if (this.inverse != other.inverse) + if (this.inverse != other.inverse) { return false; + } if (this.string == null) { - if (other.string != null) + if (other.string != null) { return false; - } else if (!this.string.equals(other.string)) + } + } else if (!this.string.equals(other.string)) { return false; + } return true; } diff --git a/src/main/java/li/strolch/model/timevalue/impl/BooleanValue.java b/src/main/java/li/strolch/model/timevalue/impl/BooleanValue.java index bde39dab3..10bc9cbe0 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/BooleanValue.java +++ b/src/main/java/li/strolch/model/timevalue/impl/BooleanValue.java @@ -22,7 +22,7 @@ import li.strolch.model.timevalue.IValue; /** * {@link IValue} implementation to work with Boolean valued {@link ITimeValue} objects - * + * * @author Martin Smock */ public class BooleanValue implements IValue, Serializable { @@ -91,18 +91,23 @@ public class BooleanValue implements IValue, Serializable { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } BooleanValue other = (BooleanValue) obj; if (this.value == null) { - if (other.value != null) + if (other.value != null) { return false; - } else if (!this.value.equals(other.value)) + } + } else if (!this.value.equals(other.value)) { return false; + } return true; } } diff --git a/src/main/java/li/strolch/model/timevalue/impl/FloatValue.java b/src/main/java/li/strolch/model/timevalue/impl/FloatValue.java index 98209b787..452686870 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/FloatValue.java +++ b/src/main/java/li/strolch/model/timevalue/impl/FloatValue.java @@ -22,7 +22,7 @@ import li.strolch.model.timevalue.IValue; /** * {@link IValue} implementation to work with Double valued {@link ITimeValue} objects - * + * * @author Martin Smock */ public class FloatValue implements IValue, Serializable { @@ -85,8 +85,8 @@ public class FloatValue implements IValue, Serializable { } @Override - public FloatValue getCopy(){ - return new FloatValue(this.value); + public FloatValue getCopy() { + return new FloatValue(this.value); } @Override @@ -99,20 +99,24 @@ public class FloatValue implements IValue, Serializable { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } FloatValue other = (FloatValue) obj; if (this.value == null) { - if (other.value != null) + if (other.value != null) { return false; - } else if (!this.value.equals(other.value)) + } + } else if (!this.value.equals(other.value)) { return false; + } return true; } - } diff --git a/src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java b/src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java index 50bb2abd2..da7936f64 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java +++ b/src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java @@ -22,7 +22,7 @@ import li.strolch.model.timevalue.IValue; /** * {@link IValue} implementation to work with Integer valued {@link ITimeValue} objects - * + * * @author Martin Smock */ public class IntegerValue implements IValue, Serializable { @@ -91,18 +91,23 @@ public class IntegerValue implements IValue, Serializable { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } IntegerValue other = (IntegerValue) obj; if (this.value == null) { - if (other.value != null) + if (other.value != null) { return false; - } else if (!this.value.equals(other.value)) + } + } else if (!this.value.equals(other.value)) { return false; + } return true; } diff --git a/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java b/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java index b754b5c1e..76bb82284 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java +++ b/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java @@ -33,85 +33,85 @@ import li.strolch.model.timevalue.IValue; */ public class StringSetValue implements IValue>, Serializable { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - private static Set neu = Collections.emptySet(); - public static final IValue> NEUTRAL = new StringSetValue(neu); + private static Set neu = Collections.emptySet(); + public static final IValue> NEUTRAL = new StringSetValue(neu); - private Set aStrings = new HashSet<>(); + private Set aStrings = new HashSet<>(); - public StringSetValue() { - } + public StringSetValue() { + } - public StringSetValue(final Set aStrings) { - // assert no null values in set - for (AString aString : aStrings) { - if (StringHelper.isEmpty(aString.getString())) { - throw new StrolchException("StringSetValue may not contain null values in set!"); - } - } - this.aStrings = aStrings; - } + public StringSetValue(final Set aStrings) { + // assert no null values in set + for (AString aString : aStrings) { + if (StringHelper.isEmpty(aString.getString())) { + throw new StrolchException("StringSetValue may not contain null values in set!"); + } + } + this.aStrings = aStrings; + } - @Override - public Set getValue() { - return this.aStrings; - } + @Override + public Set getValue() { + return this.aStrings; + } - @Override - public IValue> add(Set o) { + @Override + public IValue> add(Set o) { - Set toBeAdded = new HashSet<>(o); + Set toBeAdded = new HashSet<>(o); - for (Iterator iter1 = toBeAdded.iterator(); iter1.hasNext();) { - AString toAdd = iter1.next(); - if (StringHelper.isEmpty(toAdd.getString())) { - throw new StrolchException("StringSetValue may not contain null values in set!"); - } + for (Iterator iter1 = toBeAdded.iterator(); iter1.hasNext();) { + AString toAdd = iter1.next(); + if (StringHelper.isEmpty(toAdd.getString())) { + throw new StrolchException("StringSetValue may not contain null values in set!"); + } - for (Iterator iter = this.aStrings.iterator(); iter.hasNext();) { - AString aString = iter.next(); - boolean valueMatch = aString.getString().equals(toAdd.getString()); - boolean compensate = (toAdd.isInverse() && !aString.isInverse()) - || (!toAdd.isInverse() && aString.isInverse()); - if (valueMatch && compensate) { - iter.remove(); - iter1.remove(); - } - } - } - this.aStrings.addAll(toBeAdded); - return this; - } + for (Iterator iter = this.aStrings.iterator(); iter.hasNext();) { + AString aString = iter.next(); + boolean valueMatch = aString.getString().equals(toAdd.getString()); + boolean compensate = (toAdd.isInverse() && !aString.isInverse()) + || (!toAdd.isInverse() && aString.isInverse()); + if (valueMatch && compensate) { + iter.remove(); + iter1.remove(); + } + } + } + this.aStrings.addAll(toBeAdded); + return this; + } - @Override - public boolean matches(IValue> other) { - return getValue().equals(other.getValue()); - } + @Override + public boolean matches(IValue> other) { + return getValue().equals(other.getValue()); + } - @Override - public StringSetValue getInverse() { - Set inverseSet = new HashSet<>(); - for (AString as : this.aStrings) { - inverseSet.add(as.getInverse()); - } - StringSetValue inverse = new StringSetValue(); - inverse.aStrings = inverseSet; - return inverse; - } + @Override + public StringSetValue getInverse() { + Set inverseSet = new HashSet<>(); + for (AString as : this.aStrings) { + inverseSet.add(as.getInverse()); + } + StringSetValue inverse = new StringSetValue(); + inverse.aStrings = inverseSet; + return inverse; + } - @Override - public StringSetValue getCopy() { - return new StringSetValue(new HashSet<>(this.aStrings)); - } + @Override + public StringSetValue getCopy() { + return new StringSetValue(new HashSet<>(this.aStrings)); + } - @SuppressWarnings("nls") - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("StringSetValue [aStrings="); - sb.append(this.aStrings); - sb.append("]"); - return sb.toString(); - } + @SuppressWarnings("nls") + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("StringSetValue [aStrings="); + sb.append(this.aStrings); + sb.append("]"); + return sb.toString(); + } } diff --git a/src/main/java/li/strolch/model/timevalue/impl/TimeValue.java b/src/main/java/li/strolch/model/timevalue/impl/TimeValue.java index c400c7ba4..9af00ffe2 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/TimeValue.java +++ b/src/main/java/li/strolch/model/timevalue/impl/TimeValue.java @@ -98,24 +98,31 @@ public class TimeValue implements ITimeValue, Serializable @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } @SuppressWarnings("unchecked") TimeValue other = (TimeValue) obj; if (this.time == null) { - if (other.time != null) + if (other.time != null) { return false; - } else if (!this.time.equals(other.time)) + } + } else if (!this.time.equals(other.time)) { return false; + } if (this.value == null) { - if (other.value != null) + if (other.value != null) { return false; - } else if (!this.value.equals(other.value)) + } + } else if (!this.value.equals(other.value)) { return false; + } return true; } } diff --git a/src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java b/src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java index 07cd0c2ad..97c90cc97 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java +++ b/src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java @@ -101,8 +101,9 @@ public class TimeVariable implements ITimeVariable, Seriali @Override public void compact() { - if (this.container.size() < 2) + if (this.container.size() < 2) { return; + } Iterator> iterator = this.container.iterator(); ITimeValue predecessor = iterator.next(); diff --git a/src/main/java/li/strolch/model/timevalue/impl/ValueChange.java b/src/main/java/li/strolch/model/timevalue/impl/ValueChange.java index bef5eab70..c3e439df4 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/ValueChange.java +++ b/src/main/java/li/strolch/model/timevalue/impl/ValueChange.java @@ -59,23 +59,30 @@ public class ValueChange implements IValueChange, Serializa @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } ValueChange other = (ValueChange) obj; if (this.time == null) { - if (other.time != null) + if (other.time != null) { return false; - } else if (!this.time.equals(other.time)) + } + } else if (!this.time.equals(other.time)) { return false; + } if (this.value == null) { - if (other.value != null) + if (other.value != null) { return false; - } else if (!this.value.equals(other.value)) + } + } else if (!this.value.equals(other.value)) { return false; + } return true; } diff --git a/src/main/java/li/strolch/model/visitor/StrolchElementDeepEqualsVisitor.java b/src/main/java/li/strolch/model/visitor/StrolchElementDeepEqualsVisitor.java index 3ca79e0b1..b03d470b2 100644 --- a/src/main/java/li/strolch/model/visitor/StrolchElementDeepEqualsVisitor.java +++ b/src/main/java/li/strolch/model/visitor/StrolchElementDeepEqualsVisitor.java @@ -34,156 +34,156 @@ import li.strolch.model.timevalue.ITimeVariable; */ public class StrolchElementDeepEqualsVisitor { - private List mismatchedLocators; + private List mismatchedLocators; - public StrolchElementDeepEqualsVisitor() { - this.mismatchedLocators = new ArrayList<>(); - } + public StrolchElementDeepEqualsVisitor() { + this.mismatchedLocators = new ArrayList<>(); + } - /** - * @return the mismatchedLocators - */ - public List getMismatchedLocators() { - return this.mismatchedLocators; - } + /** + * @return the mismatchedLocators + */ + public List getMismatchedLocators() { + return this.mismatchedLocators; + } - public boolean isEqual() { - return this.mismatchedLocators.isEmpty(); - } + public boolean isEqual() { + return this.mismatchedLocators.isEmpty(); + } - protected void deepEquals(StrolchElement srcElement, StrolchElement dstElement) { - if (!srcElement.getName().equals(dstElement.getName())) { - this.mismatchedLocators.add(dstElement.getLocator()); - } - if (!srcElement.getType().equals(dstElement.getType())) { - this.mismatchedLocators.add(dstElement.getLocator()); - } - } + protected void deepEquals(StrolchElement srcElement, StrolchElement dstElement) { + if (!srcElement.getName().equals(dstElement.getName())) { + this.mismatchedLocators.add(dstElement.getLocator()); + } + if (!srcElement.getType().equals(dstElement.getType())) { + this.mismatchedLocators.add(dstElement.getLocator()); + } + } - protected void deepEquals(Order srcOrder, Order dstOrder) { - deepEquals((StrolchElement) srcOrder, (StrolchElement) dstOrder); - if (!srcOrder.getState().equals(dstOrder.getState())) { - this.mismatchedLocators.add(dstOrder.getLocator()); - } - if (!srcOrder.getDate().equals(dstOrder.getDate())) { - this.mismatchedLocators.add(dstOrder.getLocator()); - } + protected void deepEquals(Order srcOrder, Order dstOrder) { + deepEquals((StrolchElement) srcOrder, (StrolchElement) dstOrder); + if (!srcOrder.getState().equals(dstOrder.getState())) { + this.mismatchedLocators.add(dstOrder.getLocator()); + } + if (!srcOrder.getDate().equals(dstOrder.getDate())) { + this.mismatchedLocators.add(dstOrder.getLocator()); + } - deepEquals((GroupedParameterizedElement) srcOrder, (GroupedParameterizedElement) dstOrder); - } + deepEquals((GroupedParameterizedElement) srcOrder, (GroupedParameterizedElement) dstOrder); + } - protected void deepEquals(Resource srcRes, Resource dstRes) { - deepEquals((StrolchElement) srcRes, (StrolchElement) dstRes); - deepEquals((GroupedParameterizedElement) srcRes, (GroupedParameterizedElement) dstRes); - - Set srcTimedStateKeySet = srcRes.getTimedStateKeySet(); - for (String timedStateKey : srcTimedStateKeySet) { - StrolchTimedState srcTimedState = srcRes.getTimedState(timedStateKey); + protected void deepEquals(Resource srcRes, Resource dstRes) { + deepEquals((StrolchElement) srcRes, (StrolchElement) dstRes); + deepEquals((GroupedParameterizedElement) srcRes, (GroupedParameterizedElement) dstRes); - if (!dstRes.hasTimedState(timedStateKey)) { - this.mismatchedLocators.add(srcTimedState.getLocator()); - continue; - } + Set srcTimedStateKeySet = srcRes.getTimedStateKeySet(); + for (String timedStateKey : srcTimedStateKeySet) { + StrolchTimedState srcTimedState = srcRes.getTimedState(timedStateKey); - StrolchTimedState dstTimedState = dstRes.getTimedState(timedStateKey); - deepEquals(srcTimedState, dstTimedState); - } + if (!dstRes.hasTimedState(timedStateKey)) { + this.mismatchedLocators.add(srcTimedState.getLocator()); + continue; + } - Set dstTimedStateKeySet = dstRes.getTimedStateKeySet(); - for (String timedStateKey : dstTimedStateKeySet) { - if (!srcRes.hasTimedState(timedStateKey)) { - StrolchTimedState dstTimedState = dstRes.getTimedState(timedStateKey); - this.mismatchedLocators.add(dstTimedState.getLocator()); - } - } - } + StrolchTimedState dstTimedState = dstRes.getTimedState(timedStateKey); + deepEquals(srcTimedState, dstTimedState); + } - protected void deepEquals(GroupedParameterizedElement srcElement, GroupedParameterizedElement dstElement) { - Set srcBagKeySet = srcElement.getParameterBagKeySet(); - for (String bagKey : srcBagKeySet) { - ParameterBag srcBag = srcElement.getParameterBag(bagKey); + Set dstTimedStateKeySet = dstRes.getTimedStateKeySet(); + for (String timedStateKey : dstTimedStateKeySet) { + if (!srcRes.hasTimedState(timedStateKey)) { + StrolchTimedState dstTimedState = dstRes.getTimedState(timedStateKey); + this.mismatchedLocators.add(dstTimedState.getLocator()); + } + } + } - if (!dstElement.hasParameterBag(bagKey)) { - this.mismatchedLocators.add(srcBag.getLocator()); - continue; - } + protected void deepEquals(GroupedParameterizedElement srcElement, GroupedParameterizedElement dstElement) { + Set srcBagKeySet = srcElement.getParameterBagKeySet(); + for (String bagKey : srcBagKeySet) { + ParameterBag srcBag = srcElement.getParameterBag(bagKey); - ParameterBag dstBag = dstElement.getParameterBag(bagKey); - deepEquals(srcBag, dstBag); - } + if (!dstElement.hasParameterBag(bagKey)) { + this.mismatchedLocators.add(srcBag.getLocator()); + continue; + } - Set dstBagKeySet = dstElement.getParameterBagKeySet(); - for (String bagKey : dstBagKeySet) { - if (!srcElement.hasParameterBag(bagKey)) { - ParameterBag dstBag = dstElement.getParameterBag(bagKey); - this.mismatchedLocators.add(dstBag.getLocator()); - } - } - } + ParameterBag dstBag = dstElement.getParameterBag(bagKey); + deepEquals(srcBag, dstBag); + } - protected void deepEquals(ParameterBag srcBag, ParameterBag dstBag) { - deepEquals((StrolchElement) srcBag, (StrolchElement) dstBag); + Set dstBagKeySet = dstElement.getParameterBagKeySet(); + for (String bagKey : dstBagKeySet) { + if (!srcElement.hasParameterBag(bagKey)) { + ParameterBag dstBag = dstElement.getParameterBag(bagKey); + this.mismatchedLocators.add(dstBag.getLocator()); + } + } + } - Set srcParamKeySet = srcBag.getParameterKeySet(); - for (String paramKey : srcParamKeySet) { - Parameter srcParam = srcBag.getParameter(paramKey); - if (!dstBag.hasParameter(paramKey)) { - this.mismatchedLocators.add(srcParam.getLocator()); - continue; - } + protected void deepEquals(ParameterBag srcBag, ParameterBag dstBag) { + deepEquals((StrolchElement) srcBag, (StrolchElement) dstBag); - Parameter dstParam = dstBag.getParameter(paramKey); - deepEquals(srcParam, dstParam); - } + Set srcParamKeySet = srcBag.getParameterKeySet(); + for (String paramKey : srcParamKeySet) { + Parameter srcParam = srcBag.getParameter(paramKey); + if (!dstBag.hasParameter(paramKey)) { + this.mismatchedLocators.add(srcParam.getLocator()); + continue; + } - Set dstParamKeySet = dstBag.getParameterKeySet(); - for (String paramKey : dstParamKeySet) { - if (!srcBag.hasParameter(paramKey)) { - Parameter dstParam = dstBag.getParameter(paramKey); - this.mismatchedLocators.add(dstParam.getLocator()); - } - } - } + Parameter dstParam = dstBag.getParameter(paramKey); + deepEquals(srcParam, dstParam); + } - protected void deepEquals(Parameter srcParam, Parameter dstParam) { - deepEquals((StrolchElement) srcParam, (StrolchElement) dstParam); - if (!srcParam.getUom().equals(dstParam.getUom())) { - this.mismatchedLocators.add(dstParam.getLocator()); - } - if (!srcParam.getInterpretation().equals(dstParam.getInterpretation())) { - this.mismatchedLocators.add(dstParam.getLocator()); - } - if (srcParam.isHidden() != dstParam.isHidden()) { - this.mismatchedLocators.add(dstParam.getLocator()); - } - if (srcParam.getIndex() != dstParam.getIndex()) { - this.mismatchedLocators.add(dstParam.getLocator()); - } + Set dstParamKeySet = dstBag.getParameterKeySet(); + for (String paramKey : dstParamKeySet) { + if (!srcBag.hasParameter(paramKey)) { + Parameter dstParam = dstBag.getParameter(paramKey); + this.mismatchedLocators.add(dstParam.getLocator()); + } + } + } - if (!srcParam.getValue().equals(dstParam.getValue())) { - this.mismatchedLocators.add(dstParam.getLocator()); - } - } + protected void deepEquals(Parameter srcParam, Parameter dstParam) { + deepEquals((StrolchElement) srcParam, (StrolchElement) dstParam); + if (!srcParam.getUom().equals(dstParam.getUom())) { + this.mismatchedLocators.add(dstParam.getLocator()); + } + if (!srcParam.getInterpretation().equals(dstParam.getInterpretation())) { + this.mismatchedLocators.add(dstParam.getLocator()); + } + if (srcParam.isHidden() != dstParam.isHidden()) { + this.mismatchedLocators.add(dstParam.getLocator()); + } + if (srcParam.getIndex() != dstParam.getIndex()) { + this.mismatchedLocators.add(dstParam.getLocator()); + } - protected void deepEquals(StrolchTimedState srcState, StrolchTimedState dstState) { - deepEquals((StrolchElement) srcState, (StrolchElement) dstState); - final ITimeVariable srcTimeEvolution = srcState.getTimeEvolution(); - final ITimeVariable dstTimeEvolution = dstState.getTimeEvolution(); + if (!srcParam.getValue().equals(dstParam.getValue())) { + this.mismatchedLocators.add(dstParam.getLocator()); + } + } - if (!srcTimeEvolution.getValues().equals(dstTimeEvolution.getValues())) { - this.mismatchedLocators.add(dstState.getLocator()); - } - } + protected void deepEquals(StrolchTimedState srcState, StrolchTimedState dstState) { + deepEquals((StrolchElement) srcState, (StrolchElement) dstState); + final ITimeVariable srcTimeEvolution = srcState.getTimeEvolution(); + final ITimeVariable dstTimeEvolution = dstState.getTimeEvolution(); - public static boolean isEqual(Order srcOrder, Order dstOrder) { - OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(srcOrder); - visitor.visit(dstOrder); - return visitor.isEqual(); - } + if (!srcTimeEvolution.getValues().equals(dstTimeEvolution.getValues())) { + this.mismatchedLocators.add(dstState.getLocator()); + } + } - public static boolean isEqual(Resource srcRes, Resource dstRes) { - ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes); - visitor.visit(dstRes); - return visitor.isEqual(); - } + public static boolean isEqual(Order srcOrder, Order dstOrder) { + OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(srcOrder); + visitor.visit(dstOrder); + return visitor.isEqual(); + } + + public static boolean isEqual(Resource srcRes, Resource dstRes) { + ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes); + visitor.visit(dstRes); + return visitor.isEqual(); + } } diff --git a/src/main/java/li/strolch/model/visitor/StrolchVisitor.java b/src/main/java/li/strolch/model/visitor/StrolchVisitor.java index aa58cfca9..f3988cb16 100644 --- a/src/main/java/li/strolch/model/visitor/StrolchVisitor.java +++ b/src/main/java/li/strolch/model/visitor/StrolchVisitor.java @@ -17,7 +17,7 @@ package li.strolch.model.visitor; /** * Marker interface to allow to quickly see the visitor implementations in Strolch - * + * * @author Robert von Burg */ public interface StrolchVisitor { diff --git a/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java b/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java index 36d5088da..eae45ec9a 100644 --- a/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java +++ b/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java @@ -55,14 +55,16 @@ public abstract class AbstractToSaxWriterVisitor { protected void writeStartStrolchElement(String tag, boolean empty, StrolchElement element) throws XMLStreamException { - if (empty) + if (empty) { this.writer.writeEmptyElement(tag); - else + } else { this.writer.writeStartElement(tag); + } this.writer.writeAttribute(Tags.ID, element.getId()); - if (StringHelper.isNotEmpty(element.getName())) + if (StringHelper.isNotEmpty(element.getName())) { this.writer.writeAttribute(Tags.NAME, element.getName()); + } this.writer.writeAttribute(Tags.TYPE, element.getType()); } @@ -78,14 +80,18 @@ public abstract class AbstractToSaxWriterVisitor { for (Parameter parameter : parameters) { writeStartStrolchElement(Tags.PARAMETER, true, parameter); - if (!Parameter.INTERPRETATION_NONE.equals(parameter.getInterpretation())) + if (!Parameter.INTERPRETATION_NONE.equals(parameter.getInterpretation())) { this.writer.writeAttribute(Tags.INTERPRETATION, parameter.getInterpretation()); - if (!Parameter.UOM_NONE.equals(parameter.getUom())) + } + if (!Parameter.UOM_NONE.equals(parameter.getUom())) { this.writer.writeAttribute(Tags.UOM, parameter.getUom()); - if (parameter.isHidden()) + } + if (parameter.isHidden()) { this.writer.writeAttribute(Tags.HIDDEN, Boolean.toString(parameter.isHidden())); - if (parameter.getIndex() != 0) + } + if (parameter.getIndex() != 0) { this.writer.writeAttribute(Tags.INDEX, Integer.toString(parameter.getIndex())); + } this.writer.writeAttribute(Tags.VALUE, parameter.getValueAsString()); } diff --git a/src/main/java/li/strolch/model/xml/SimpleStrolchElementListener.java b/src/main/java/li/strolch/model/xml/SimpleStrolchElementListener.java index 79871b281..777fe2a57 100644 --- a/src/main/java/li/strolch/model/xml/SimpleStrolchElementListener.java +++ b/src/main/java/li/strolch/model/xml/SimpleStrolchElementListener.java @@ -31,15 +31,17 @@ public class SimpleStrolchElementListener implements StrolchElementListener { @Override public void notifyResource(Resource resource) { - if (this.resources == null) + if (this.resources == null) { this.resources = new ArrayList<>(); + } this.resources.add(resource); } @Override public void notifyOrder(Order order) { - if (this.orders == null) + if (this.orders == null) { this.orders = new ArrayList<>(); + } this.orders.add(order); } diff --git a/src/main/java/li/strolch/model/xml/StrolchElementListener.java b/src/main/java/li/strolch/model/xml/StrolchElementListener.java index 719ffd64b..58f1d419c 100644 --- a/src/main/java/li/strolch/model/xml/StrolchElementListener.java +++ b/src/main/java/li/strolch/model/xml/StrolchElementListener.java @@ -20,7 +20,7 @@ import li.strolch.model.Resource; /** * @author Robert von Burg - * + * */ public interface StrolchElementListener { diff --git a/src/main/java/li/strolch/model/xml/StrolchElementToDomVisitor.java b/src/main/java/li/strolch/model/xml/StrolchElementToDomVisitor.java index a13f921df..b26ecbe57 100644 --- a/src/main/java/li/strolch/model/xml/StrolchElementToDomVisitor.java +++ b/src/main/java/li/strolch/model/xml/StrolchElementToDomVisitor.java @@ -61,14 +61,18 @@ public abstract class StrolchElementToDomVisitor { AttributesImpl attributes = attributesFor((StrolchElement) parameter); attributes.addAttribute(null, null, Tags.VALUE, Tags.CDATA, parameter.getValueAsString()); - if (!Parameter.UOM_NONE.equals(parameter.getUom())) + if (!Parameter.UOM_NONE.equals(parameter.getUom())) { attributes.addAttribute(null, null, Tags.UOM, Tags.CDATA, parameter.getUom()); - if (!Parameter.INTERPRETATION_NONE.equals(parameter.getInterpretation())) + } + if (!Parameter.INTERPRETATION_NONE.equals(parameter.getInterpretation())) { attributes.addAttribute(null, null, Tags.INTERPRETATION, Tags.CDATA, parameter.getInterpretation()); - if (parameter.isHidden()) + } + if (parameter.isHidden()) { attributes.addAttribute(null, null, Tags.HIDDEN, Tags.CDATA, Boolean.toString(parameter.isHidden())); - if (parameter.getIndex() != 0) + } + if (parameter.getIndex() != 0) { attributes.addAttribute(null, null, Tags.INDEX, Tags.CDATA, Integer.toString(parameter.getIndex())); + } return attributes; } diff --git a/src/main/java/li/strolch/model/xml/XmlModelSaxFileReader.java b/src/main/java/li/strolch/model/xml/XmlModelSaxFileReader.java index 81e9c0d47..a515767b6 100644 --- a/src/main/java/li/strolch/model/xml/XmlModelSaxFileReader.java +++ b/src/main/java/li/strolch/model/xml/XmlModelSaxFileReader.java @@ -34,7 +34,7 @@ import ch.eitchnet.utils.helper.StringHelper; /** * @author Robert von Burg - * + * */ public class XmlModelSaxFileReader extends XmlModelSaxReader { @@ -54,27 +54,28 @@ public class XmlModelSaxFileReader extends XmlModelSaxReader { switch (qName) { - case Tags.INCLUDE_FILE: + case Tags.INCLUDE_FILE: - String includeFileS = attributes.getValue(Tags.FILE); - if (StringHelper.isEmpty(includeFileS)) - throw new IllegalArgumentException(MessageFormat.format( - "The attribute {0} is missing for IncludeFile!", Tags.FILE)); //$NON-NLS-1$ - File includeFile = new File(this.modelFile.getParentFile(), includeFileS); - if (!includeFile.exists() || !includeFile.canRead()) { - String msg = "The IncludeFile does not exist, or is not readable. Source model: {0} with IncludeFile: {1}"; //$NON-NLS-1$ - msg = MessageFormat.format(msg, this.modelFile.getName(), includeFileS); - throw new IllegalArgumentException(msg); - } + String includeFileS = attributes.getValue(Tags.FILE); + if (StringHelper.isEmpty(includeFileS)) { + throw new IllegalArgumentException(MessageFormat.format( + "The attribute {0} is missing for IncludeFile!", Tags.FILE)); //$NON-NLS-1$ + } + File includeFile = new File(this.modelFile.getParentFile(), includeFileS); + if (!includeFile.exists() || !includeFile.canRead()) { + String msg = "The IncludeFile does not exist, or is not readable. Source model: {0} with IncludeFile: {1}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, this.modelFile.getName(), includeFileS); + throw new IllegalArgumentException(msg); + } - XmlModelSaxFileReader handler = new XmlModelSaxFileReader(this.listener, includeFile); - handler.parseFile(); - this.statistics.nrOfOrders += handler.statistics.nrOfOrders; - this.statistics.nrOfResources += handler.statistics.nrOfResources; + XmlModelSaxFileReader handler = new XmlModelSaxFileReader(this.listener, includeFile); + handler.parseFile(); + this.statistics.nrOfOrders += handler.statistics.nrOfOrders; + this.statistics.nrOfResources += handler.statistics.nrOfResources; - break; - default: - super.startElement(uri, localName, qName, attributes); + break; + default: + super.startElement(uri, localName, qName, attributes); } } diff --git a/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java b/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java index a1efba98b..48cc6d6fa 100644 --- a/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java +++ b/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java @@ -74,101 +74,100 @@ public class XmlModelSaxReader extends DefaultHandler { public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { // TODO split each root object into its own file - switch (qName) { - case Tags.STROLCH_MODEL: - break; + case Tags.STROLCH_MODEL: + break; - case Tags.RESOURCE: + case Tags.RESOURCE: - String resId = attributes.getValue(Tags.ID); - String resName = attributes.getValue(Tags.NAME); - String resType = attributes.getValue(Tags.TYPE); - Resource resource = new Resource(resId, resName, resType); - this.parameterizedElement = resource; - break; + String resId = attributes.getValue(Tags.ID); + String resName = attributes.getValue(Tags.NAME); + String resType = attributes.getValue(Tags.TYPE); + Resource resource = new Resource(resId, resName, resType); + this.parameterizedElement = resource; + break; - case Tags.ORDER: - String orderId = attributes.getValue(Tags.ID); - String orderName = attributes.getValue(Tags.NAME); - String orderType = attributes.getValue(Tags.TYPE); - String orderDateS = attributes.getValue(Tags.DATE); - String orderStateS = attributes.getValue(Tags.STATE); - Order order = new Order(orderId, orderName, orderType); - if (orderDateS != null) { - Date orderDate = ISO8601FormatFactory.getInstance().getDateFormat().parse(orderDateS); - order.setDate(orderDate); - } - if (orderStateS != null) { - State orderState = State.valueOf(orderStateS); - order.setState(orderState); - } - this.parameterizedElement = order; - break; - - case Tags.PARAMETER_BAG: - String pBagId = attributes.getValue(Tags.ID); - String pBagName = attributes.getValue(Tags.NAME); - String pBagType = attributes.getValue(Tags.TYPE); - ParameterBag pBag = new ParameterBag(pBagId, pBagName, pBagType); - this.pBag = pBag; - this.parameterizedElement.addParameterBag(pBag); - break; - - case Tags.PARAMETER: - String paramId = attributes.getValue(Tags.ID); - String paramName = attributes.getValue(Tags.NAME); - String paramType = attributes.getValue(Tags.TYPE); - String paramValue = attributes.getValue(Tags.VALUE); - String paramHiddenS = attributes.getValue(Tags.HIDDEN); - String paramIndexS = attributes.getValue(Tags.INDEX); - try { - int index = StringHelper.isEmpty(paramIndexS) ? 0 : Integer.valueOf(paramIndexS); - boolean paramHidden = StringHelper.isEmpty(paramHiddenS) ? false : StringHelper - .parseBoolean(paramHiddenS); - String paramUom = attributes.getValue(Tags.UOM); - String paramInterpretation = attributes.getValue(Tags.INTERPRETATION); - Parameter param; - switch (paramType) { - case StringParameter.TYPE: - param = new StringParameter(paramId, paramName, paramValue); - break; - case IntegerParameter.TYPE: - param = new IntegerParameter(paramId, paramName, IntegerParameter.parseFromString(paramValue)); - break; - case BooleanParameter.TYPE: - param = new BooleanParameter(paramId, paramName, BooleanParameter.parseFromString(paramValue)); - break; - case LongParameter.TYPE: - param = new LongParameter(paramId, paramName, LongParameter.parseFromString(paramValue)); - break; - case DateParameter.TYPE: - param = new DateParameter(paramId, paramName, DateParameter.parseFromString(paramValue)); - break; - case StringListParameter.TYPE: - param = new StringListParameter(paramId, paramName, StringListParameter.parseFromString(paramValue)); - break; - case FloatParameter.TYPE: - param = new FloatParameter(paramId, paramName, FloatParameter.parseFromString(paramValue)); - break; - default: - throw new UnsupportedOperationException(MessageFormat.format( - "Parameters of type {0} are not supported!", paramType)); //$NON-NLS-1$ + case Tags.ORDER: + String orderId = attributes.getValue(Tags.ID); + String orderName = attributes.getValue(Tags.NAME); + String orderType = attributes.getValue(Tags.TYPE); + String orderDateS = attributes.getValue(Tags.DATE); + String orderStateS = attributes.getValue(Tags.STATE); + Order order = new Order(orderId, orderName, orderType); + if (orderDateS != null) { + Date orderDate = ISO8601FormatFactory.getInstance().getDateFormat().parse(orderDateS); + order.setDate(orderDate); } - param.setHidden(paramHidden); - param.setUom(paramUom); - param.setInterpretation(paramInterpretation); - param.setIndex(index); - this.pBag.addParameter(param); - } catch (Exception e) { - throw new StrolchException("Failed to instantiate parameter " + paramId + " for bag " - + this.pBag.getLocator() + " due to " + e.getMessage(), e); - } - break; + if (orderStateS != null) { + State orderState = State.valueOf(orderStateS); + order.setState(orderState); + } + this.parameterizedElement = order; + break; - default: - throw new IllegalArgumentException(MessageFormat.format("The element ''{0}'' is unhandled!", qName)); //$NON-NLS-1$ + case Tags.PARAMETER_BAG: + String pBagId = attributes.getValue(Tags.ID); + String pBagName = attributes.getValue(Tags.NAME); + String pBagType = attributes.getValue(Tags.TYPE); + ParameterBag pBag = new ParameterBag(pBagId, pBagName, pBagType); + this.pBag = pBag; + this.parameterizedElement.addParameterBag(pBag); + break; + + case Tags.PARAMETER: + String paramId = attributes.getValue(Tags.ID); + String paramName = attributes.getValue(Tags.NAME); + String paramType = attributes.getValue(Tags.TYPE); + String paramValue = attributes.getValue(Tags.VALUE); + String paramHiddenS = attributes.getValue(Tags.HIDDEN); + String paramIndexS = attributes.getValue(Tags.INDEX); + try { + int index = StringHelper.isEmpty(paramIndexS) ? 0 : Integer.valueOf(paramIndexS); + boolean paramHidden = StringHelper.isEmpty(paramHiddenS) ? false : StringHelper + .parseBoolean(paramHiddenS); + String paramUom = attributes.getValue(Tags.UOM); + String paramInterpretation = attributes.getValue(Tags.INTERPRETATION); + Parameter param; + switch (paramType) { + case StringParameter.TYPE: + param = new StringParameter(paramId, paramName, paramValue); + break; + case IntegerParameter.TYPE: + param = new IntegerParameter(paramId, paramName, IntegerParameter.parseFromString(paramValue)); + break; + case BooleanParameter.TYPE: + param = new BooleanParameter(paramId, paramName, BooleanParameter.parseFromString(paramValue)); + break; + case LongParameter.TYPE: + param = new LongParameter(paramId, paramName, LongParameter.parseFromString(paramValue)); + break; + case DateParameter.TYPE: + param = new DateParameter(paramId, paramName, DateParameter.parseFromString(paramValue)); + break; + case StringListParameter.TYPE: + param = new StringListParameter(paramId, paramName, StringListParameter.parseFromString(paramValue)); + break; + case FloatParameter.TYPE: + param = new FloatParameter(paramId, paramName, FloatParameter.parseFromString(paramValue)); + break; + default: + throw new UnsupportedOperationException(MessageFormat.format( + "Parameters of type {0} are not supported!", paramType)); //$NON-NLS-1$ + } + param.setHidden(paramHidden); + param.setUom(paramUom); + param.setInterpretation(paramInterpretation); + param.setIndex(index); + this.pBag.addParameter(param); + } catch (Exception e) { + throw new StrolchException("Failed to instantiate parameter " + paramId + " for bag " + + this.pBag.getLocator() + " due to " + e.getMessage(), e); + } + break; + + default: + throw new IllegalArgumentException(MessageFormat.format("The element ''{0}'' is unhandled!", qName)); //$NON-NLS-1$ } } @@ -176,31 +175,32 @@ public class XmlModelSaxReader extends DefaultHandler { public void endElement(String uri, String localName, String qName) throws SAXException { switch (qName) { - case Tags.STROLCH_MODEL: - break; - case Tags.RESOURCE: - this.listener.notifyResource((Resource) this.parameterizedElement); - this.statistics.nrOfResources++; - this.parameterizedElement = null; - break; - case Tags.ORDER: - this.listener.notifyOrder((Order) this.parameterizedElement); - this.statistics.nrOfOrders++; - this.parameterizedElement = null; - break; - case Tags.PARAMETER_BAG: - this.pBag = null; - break; - case Tags.PARAMETER: - break; - case Tags.INCLUDE_FILE: - break; - default: - throw new IllegalArgumentException(MessageFormat.format("The element ''{0}'' is unhandled!", qName)); //$NON-NLS-1$ + case Tags.STROLCH_MODEL: + break; + case Tags.RESOURCE: + this.listener.notifyResource((Resource) this.parameterizedElement); + this.statistics.nrOfResources++; + this.parameterizedElement = null; + break; + case Tags.ORDER: + this.listener.notifyOrder((Order) this.parameterizedElement); + this.statistics.nrOfOrders++; + this.parameterizedElement = null; + break; + case Tags.PARAMETER_BAG: + this.pBag = null; + break; + case Tags.PARAMETER: + break; + case Tags.INCLUDE_FILE: + break; + default: + throw new IllegalArgumentException(MessageFormat.format("The element ''{0}'' is unhandled!", qName)); //$NON-NLS-1$ } } public static class XmlModelStatistics { + public Date startTime; public long durationNanos; public int nrOfResources; diff --git a/src/test/java/li/strolch/model/ModelTest.java b/src/test/java/li/strolch/model/ModelTest.java index 8046ce698..391398e7a 100644 --- a/src/test/java/li/strolch/model/ModelTest.java +++ b/src/test/java/li/strolch/model/ModelTest.java @@ -41,112 +41,112 @@ import org.junit.Test; @SuppressWarnings("nls") public class ModelTest { - @Test - public void shouldCreateResource() { + @Test + public void shouldCreateResource() { - Resource resource = ModelGenerator.createResource("@res01", "Test resource", "MyType"); - ParameterBag bag = resource.getParameterBag(ModelGenerator.BAG_ID); - validateBag(bag); - } + Resource resource = ModelGenerator.createResource("@res01", "Test resource", "MyType"); + ParameterBag bag = resource.getParameterBag(ModelGenerator.BAG_ID); + validateBag(bag); + } - @Test - public void shouldCreateOrder() { + @Test + public void shouldCreateOrder() { - Order order = ModelGenerator.createOrder("@ord01", "Test Order", "MyType", new Date(), State.OPEN); - ParameterBag bag = order.getParameterBag(ModelGenerator.BAG_ID); - validateBag(bag); - } + Order order = ModelGenerator.createOrder("@ord01", "Test Order", "MyType", new Date(), State.OPEN); + ParameterBag bag = order.getParameterBag(ModelGenerator.BAG_ID); + validateBag(bag); + } - @Test - public void shouldPerformDeepResourceEquals() { - Resource srcRes = ModelGenerator.createResource("@res01", "Test resource", "MyType"); - Resource dstRes = ModelGenerator.createResource("@res01", "Test resource", "MyType"); - ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes); - visitor.visit(dstRes); - assertTrue("Same Resource should be deep equal!", visitor.isEqual()); - } + @Test + public void shouldPerformDeepResourceEquals() { + Resource srcRes = ModelGenerator.createResource("@res01", "Test resource", "MyType"); + Resource dstRes = ModelGenerator.createResource("@res01", "Test resource", "MyType"); + ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes); + visitor.visit(dstRes); + assertTrue("Same Resource should be deep equal!", visitor.isEqual()); + } - @Test - public void shouldFailDeepResourceEquals1() { - Resource srcRes = ModelGenerator.createResource("@res01", "Test resource", "MyType"); - Resource dstRes = ModelGenerator.createResource("@res01", "Test resource", "MyType"); - ParameterBag bag = dstRes.getParameterBag(ModelGenerator.BAG_ID); - bag.setName("Bla bla"); - FloatParameter fParam = bag.getParameter(ModelGenerator.PARAM_FLOAT_ID); - fParam.setValue(23434234.234); - fParam.setName("Ohla"); - ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes); - visitor.visit(dstRes); - assertFalse("Resource should not be same if param is changed!", visitor.isEqual()); - assertEquals("Three changes should be registered", 3, visitor.getMismatchedLocators().size()); - } + @Test + public void shouldFailDeepResourceEquals1() { + Resource srcRes = ModelGenerator.createResource("@res01", "Test resource", "MyType"); + Resource dstRes = ModelGenerator.createResource("@res01", "Test resource", "MyType"); + ParameterBag bag = dstRes.getParameterBag(ModelGenerator.BAG_ID); + bag.setName("Bla bla"); + FloatParameter fParam = bag.getParameter(ModelGenerator.PARAM_FLOAT_ID); + fParam.setValue(23434234.234); + fParam.setName("Ohla"); + ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes); + visitor.visit(dstRes); + assertFalse("Resource should not be same if param is changed!", visitor.isEqual()); + assertEquals("Three changes should be registered", 3, visitor.getMismatchedLocators().size()); + } - @Test - public void shouldFailDeepResourceEquals2() { - Resource srcRes = ModelGenerator.createResource("@res01", "Test resource", "MyType"); - Resource dstRes = ModelGenerator.createResource("@res01", "Test resource", "MyType"); - BooleanTimedState timedState = dstRes.getTimedState(ModelGenerator.STATE_BOOLEAN_ID); - timedState.applyChange(new ValueChange<>(System.currentTimeMillis(), new BooleanValue(Boolean.TRUE))); - timedState.setName("Ohla"); - ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes); - visitor.visit(dstRes); - assertFalse("Resource should not be same if param is changed!", visitor.isEqual()); - assertEquals("One change should be registered!", 1, visitor.getMismatchedLocators().size()); - } + @Test + public void shouldFailDeepResourceEquals2() { + Resource srcRes = ModelGenerator.createResource("@res01", "Test resource", "MyType"); + Resource dstRes = ModelGenerator.createResource("@res01", "Test resource", "MyType"); + BooleanTimedState timedState = dstRes.getTimedState(ModelGenerator.STATE_BOOLEAN_ID); + timedState.applyChange(new ValueChange<>(System.currentTimeMillis(), new BooleanValue(Boolean.TRUE))); + timedState.setName("Ohla"); + ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes); + visitor.visit(dstRes); + assertFalse("Resource should not be same if param is changed!", visitor.isEqual()); + assertEquals("One change should be registered!", 1, visitor.getMismatchedLocators().size()); + } - @Test - public void shouldPerformDeepOrderEquals() { - Date date = new Date(); - Order srcOrder = ModelGenerator.createOrder("@ord01", "Test Order", "MyType", date, State.OPEN); - Order dstOrder = ModelGenerator.createOrder("@ord01", "Test Order", "MyType", date, State.OPEN); - OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(srcOrder); - visitor.visit(dstOrder); - assertTrue("Same Order should be deep equal: " + visitor.getMismatchedLocators(), visitor.isEqual()); - } + @Test + public void shouldPerformDeepOrderEquals() { + Date date = new Date(); + Order srcOrder = ModelGenerator.createOrder("@ord01", "Test Order", "MyType", date, State.OPEN); + Order dstOrder = ModelGenerator.createOrder("@ord01", "Test Order", "MyType", date, State.OPEN); + OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(srcOrder); + visitor.visit(dstOrder); + assertTrue("Same Order should be deep equal: " + visitor.getMismatchedLocators(), visitor.isEqual()); + } - public static void validateBag(ParameterBag bag) { + public static void validateBag(ParameterBag bag) { - assertNotNull(bag); + assertNotNull(bag); - assertEquals(ModelGenerator.BAG_ID, bag.getId()); - assertEquals(ModelGenerator.BAG_NAME, bag.getName()); - assertEquals(ModelGenerator.BAG_TYPE, bag.getType()); + assertEquals(ModelGenerator.BAG_ID, bag.getId()); + assertEquals(ModelGenerator.BAG_NAME, bag.getName()); + assertEquals(ModelGenerator.BAG_TYPE, bag.getType()); - validateParams(bag); - } + validateParams(bag); + } - public static void validateParams(ParameterBag bag) { + public static void validateParams(ParameterBag bag) { - BooleanParameter boolParam = bag.getParameter(ModelGenerator.PARAM_BOOLEAN_ID); - assertNotNull("Boolean Param missing with id " + ModelGenerator.PARAM_BOOLEAN_ID, boolParam); - assertEquals(true, boolParam.getValue().booleanValue()); + BooleanParameter boolParam = bag.getParameter(ModelGenerator.PARAM_BOOLEAN_ID); + assertNotNull("Boolean Param missing with id " + ModelGenerator.PARAM_BOOLEAN_ID, boolParam); + assertEquals(true, boolParam.getValue().booleanValue()); - FloatParameter floatParam = bag.getParameter(ModelGenerator.PARAM_FLOAT_ID); - assertNotNull("Float Param missing with id " + ModelGenerator.PARAM_FLOAT_ID, floatParam); - assertEquals(44.3, floatParam.getValue().doubleValue(), 0.0001); + FloatParameter floatParam = bag.getParameter(ModelGenerator.PARAM_FLOAT_ID); + assertNotNull("Float Param missing with id " + ModelGenerator.PARAM_FLOAT_ID, floatParam); + assertEquals(44.3, floatParam.getValue().doubleValue(), 0.0001); - IntegerParameter integerParam = bag.getParameter(ModelGenerator.PARAM_INTEGER_ID); - assertNotNull("Integer Param missing with id " + ModelGenerator.PARAM_INTEGER_ID, integerParam); - assertEquals(77, integerParam.getValue().intValue()); + IntegerParameter integerParam = bag.getParameter(ModelGenerator.PARAM_INTEGER_ID); + assertNotNull("Integer Param missing with id " + ModelGenerator.PARAM_INTEGER_ID, integerParam); + assertEquals(77, integerParam.getValue().intValue()); - LongParameter longParam = bag.getParameter(ModelGenerator.PARAM_LONG_ID); - assertNotNull("Long Param missing with id " + ModelGenerator.PARAM_LONG_ID, longParam); - assertEquals(4453234566L, longParam.getValue().longValue()); + LongParameter longParam = bag.getParameter(ModelGenerator.PARAM_LONG_ID); + assertNotNull("Long Param missing with id " + ModelGenerator.PARAM_LONG_ID, longParam); + assertEquals(4453234566L, longParam.getValue().longValue()); - StringParameter stringParam = bag.getParameter(ModelGenerator.PARAM_STRING_ID); - assertNotNull("String Param missing with id " + ModelGenerator.PARAM_STRING_ID, stringParam); - assertEquals("Strolch", stringParam.getValue()); + StringParameter stringParam = bag.getParameter(ModelGenerator.PARAM_STRING_ID); + assertNotNull("String Param missing with id " + ModelGenerator.PARAM_STRING_ID, stringParam); + assertEquals("Strolch", stringParam.getValue()); - DateParameter dateParam = bag.getParameter(ModelGenerator.PARAM_DATE_ID); - assertNotNull("Date Param missing with id " + ModelGenerator.PARAM_DATE_ID, dateParam); - assertEquals(1354295525628L, dateParam.getValue().getTime()); + DateParameter dateParam = bag.getParameter(ModelGenerator.PARAM_DATE_ID); + assertNotNull("Date Param missing with id " + ModelGenerator.PARAM_DATE_ID, dateParam); + assertEquals(1354295525628L, dateParam.getValue().getTime()); - StringListParameter stringListP = bag.getParameter(ModelGenerator.PARAM_LIST_STRING_ID); - assertNotNull("StringList Param missing with id " + ModelGenerator.PARAM_LIST_STRING_ID, stringListP); + StringListParameter stringListP = bag.getParameter(ModelGenerator.PARAM_LIST_STRING_ID); + assertNotNull("StringList Param missing with id " + ModelGenerator.PARAM_LIST_STRING_ID, stringListP); ArrayList stringList = new ArrayList<>(); - stringList.add("Hello"); - stringList.add("World"); - assertEquals(stringList, stringListP.getValue()); - } + stringList.add("Hello"); + stringList.add("World"); + assertEquals(stringList, stringListP.getValue()); + } } diff --git a/src/test/java/li/strolch/model/XmlModelDefaultHandlerTest.java b/src/test/java/li/strolch/model/XmlModelDefaultHandlerTest.java index 1b7fedbae..f6948b6c2 100644 --- a/src/test/java/li/strolch/model/XmlModelDefaultHandlerTest.java +++ b/src/test/java/li/strolch/model/XmlModelDefaultHandlerTest.java @@ -33,7 +33,7 @@ import ch.eitchnet.utils.helper.StringHelper; /** * @author Robert von Burg - * + * */ @SuppressWarnings("nls") public class XmlModelDefaultHandlerTest { diff --git a/src/test/java/li/strolch/model/XmlToDomTest.java b/src/test/java/li/strolch/model/XmlToDomTest.java index 315e17065..e6417b494 100644 --- a/src/test/java/li/strolch/model/XmlToDomTest.java +++ b/src/test/java/li/strolch/model/XmlToDomTest.java @@ -31,39 +31,39 @@ import org.w3c.dom.Element; @SuppressWarnings("nls") public class XmlToDomTest extends ModelTest { - @Test - public void shouldFormatAndParseOrder() { + @Test + public void shouldFormatAndParseOrder() { - Order order = ModelGenerator.createOrder("@1", "My Order 1", "MyOrder"); + Order order = ModelGenerator.createOrder("@1", "My Order 1", "MyOrder"); - OrderToDomVisitor domVisitor = new OrderToDomVisitor(); - domVisitor.visit(order); - Document document = domVisitor.getDocument(); + OrderToDomVisitor domVisitor = new OrderToDomVisitor(); + domVisitor.visit(order); + Document document = domVisitor.getDocument(); - Element rootElement = document.getDocumentElement(); - Order parsedOrder = new Order(rootElement); + Element rootElement = document.getDocumentElement(); + Order parsedOrder = new Order(rootElement); - OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(order); - visitor.visit(parsedOrder); - assertTrue("To DOM and back should equal same Order:\n" + visitor.getMismatchedLocators(), - visitor.isEqual()); - } + OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(order); + visitor.visit(parsedOrder); + assertTrue("To DOM and back should equal same Order:\n" + visitor.getMismatchedLocators(), + visitor.isEqual()); + } - @Test - public void shouldFormatAndParseResource() { + @Test + public void shouldFormatAndParseResource() { - Resource resource = ModelGenerator.createResource("@1", "My Resource 1", "MyResource"); + Resource resource = ModelGenerator.createResource("@1", "My Resource 1", "MyResource"); - ResourceToDomVisitor domVisitor = new ResourceToDomVisitor(); - domVisitor.visit(resource); - Document document = domVisitor.getDocument(); + ResourceToDomVisitor domVisitor = new ResourceToDomVisitor(); + domVisitor.visit(resource); + Document document = domVisitor.getDocument(); - Element rootElement = document.getDocumentElement(); - Resource parsedResource = new Resource(rootElement); + Element rootElement = document.getDocumentElement(); + Resource parsedResource = new Resource(rootElement); - ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(resource); - visitor.visit(parsedResource); - assertTrue("To DOM and back should equal same Resource:\n" + visitor.getMismatchedLocators(), - visitor.isEqual()); - } + ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(resource); + visitor.visit(parsedResource); + assertTrue("To DOM and back should equal same Resource:\n" + visitor.getMismatchedLocators(), + visitor.isEqual()); + } } diff --git a/src/test/java/li/strolch/model/timedstate/StrolchTimedStateTest.java b/src/test/java/li/strolch/model/timedstate/StrolchTimedStateTest.java index 6d10aa4cb..b020b88c9 100644 --- a/src/test/java/li/strolch/model/timedstate/StrolchTimedStateTest.java +++ b/src/test/java/li/strolch/model/timedstate/StrolchTimedStateTest.java @@ -33,85 +33,85 @@ import org.junit.Test; */ public class StrolchTimedStateTest { - @Test - public void testFloatState() { + @Test + public void testFloatState() { - Resource myRes = ModelGenerator.createResource("@1", "Test With States", "Stated"); + Resource myRes = ModelGenerator.createResource("@1", "Test With States", "Stated"); - FloatTimedState floatState = myRes.getTimedState(ModelGenerator.STATE_FLOAT_ID); - ITimeValue valueAt0 = floatState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_0); - assertEquals(ModelGenerator.STATE_FLOAT_TIME_0, valueAt0.getValue().getValue()); + FloatTimedState floatState = myRes.getTimedState(ModelGenerator.STATE_FLOAT_ID); + ITimeValue valueAt0 = floatState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_0); + assertEquals(ModelGenerator.STATE_FLOAT_TIME_0, valueAt0.getValue().getValue()); - ITimeValue valueAt10 = floatState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_10); - assertEquals(ModelGenerator.STATE_FLOAT_TIME_10, valueAt10.getValue().getValue()); + ITimeValue valueAt10 = floatState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_10); + assertEquals(ModelGenerator.STATE_FLOAT_TIME_10, valueAt10.getValue().getValue()); - ITimeValue valueAt20 = floatState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_20); - assertEquals(ModelGenerator.STATE_FLOAT_TIME_20, valueAt20.getValue().getValue()); + ITimeValue valueAt20 = floatState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_20); + assertEquals(ModelGenerator.STATE_FLOAT_TIME_20, valueAt20.getValue().getValue()); - ITimeValue valueAt30 = floatState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_30); - assertEquals(ModelGenerator.STATE_FLOAT_TIME_30, valueAt30.getValue().getValue()); - } + ITimeValue valueAt30 = floatState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_30); + assertEquals(ModelGenerator.STATE_FLOAT_TIME_30, valueAt30.getValue().getValue()); + } - @Test - public void testIntegerState() { + @Test + public void testIntegerState() { - Resource myRes = ModelGenerator.createResource("@1", "Test With States", "Stated"); + Resource myRes = ModelGenerator.createResource("@1", "Test With States", "Stated"); - IntegerTimedState integerState = myRes.getTimedState(ModelGenerator.STATE_INTEGER_ID); - ITimeValue valueAt0 = integerState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_0); - assertEquals(ModelGenerator.STATE_INTEGER_TIME_0, valueAt0.getValue().getValue()); + IntegerTimedState integerState = myRes.getTimedState(ModelGenerator.STATE_INTEGER_ID); + ITimeValue valueAt0 = integerState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_0); + assertEquals(ModelGenerator.STATE_INTEGER_TIME_0, valueAt0.getValue().getValue()); - ITimeValue valueAt10 = integerState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_10); - assertEquals(ModelGenerator.STATE_INTEGER_TIME_10, valueAt10.getValue().getValue()); + ITimeValue valueAt10 = integerState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_10); + assertEquals(ModelGenerator.STATE_INTEGER_TIME_10, valueAt10.getValue().getValue()); - ITimeValue valueAt20 = integerState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_20); - assertEquals(ModelGenerator.STATE_INTEGER_TIME_20, valueAt20.getValue().getValue()); + ITimeValue valueAt20 = integerState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_20); + assertEquals(ModelGenerator.STATE_INTEGER_TIME_20, valueAt20.getValue().getValue()); - ITimeValue valueAt30 = integerState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_30); - assertEquals(ModelGenerator.STATE_INTEGER_TIME_30, valueAt30.getValue().getValue()); - } + ITimeValue valueAt30 = integerState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_30); + assertEquals(ModelGenerator.STATE_INTEGER_TIME_30, valueAt30.getValue().getValue()); + } - @Test - public void testBooleanState() { + @Test + public void testBooleanState() { - Resource myRes = ModelGenerator.createResource("@1", "Test With States", "Stated"); + Resource myRes = ModelGenerator.createResource("@1", "Test With States", "Stated"); - BooleanTimedState booleanState = myRes.getTimedState(ModelGenerator.STATE_BOOLEAN_ID); - ITimeValue valueAt0 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_0); - assertEquals(ModelGenerator.STATE_BOOLEAN_TIME_0, valueAt0.getValue().getValue()); + BooleanTimedState booleanState = myRes.getTimedState(ModelGenerator.STATE_BOOLEAN_ID); + ITimeValue valueAt0 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_0); + assertEquals(ModelGenerator.STATE_BOOLEAN_TIME_0, valueAt0.getValue().getValue()); - ITimeValue valueAt10 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_10); - assertEquals(ModelGenerator.STATE_BOOLEAN_TIME_10, valueAt10.getValue().getValue()); + ITimeValue valueAt10 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_10); + assertEquals(ModelGenerator.STATE_BOOLEAN_TIME_10, valueAt10.getValue().getValue()); - ITimeValue valueAt20 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_20); - assertEquals(ModelGenerator.STATE_BOOLEAN_TIME_20, valueAt20.getValue().getValue()); + ITimeValue valueAt20 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_20); + assertEquals(ModelGenerator.STATE_BOOLEAN_TIME_20, valueAt20.getValue().getValue()); - ITimeValue valueAt30 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_30); - assertEquals(ModelGenerator.STATE_BOOLEAN_TIME_30, valueAt30.getValue().getValue()); - } + ITimeValue valueAt30 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_30); + assertEquals(ModelGenerator.STATE_BOOLEAN_TIME_30, valueAt30.getValue().getValue()); + } - @Test - public void testStringSetState() { + @Test + public void testStringSetState() { - Resource myRes = ModelGenerator.createResource("@1", "Test With States", "Stated"); + Resource myRes = ModelGenerator.createResource("@1", "Test With States", "Stated"); - StringSetTimedState booleanState = myRes.getTimedState(ModelGenerator.STATE_STRING_ID); - ITimeValue valueAt0 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_0); - assertEquals(asSet(ModelGenerator.STATE_STRING_TIME_0), valueAt0.getValue().getValue()); + StringSetTimedState booleanState = myRes.getTimedState(ModelGenerator.STATE_STRING_ID); + ITimeValue valueAt0 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_0); + assertEquals(asSet(ModelGenerator.STATE_STRING_TIME_0), valueAt0.getValue().getValue()); - ITimeValue valueAt10 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_10); - assertEquals(asSet(ModelGenerator.STATE_STRING_TIME_10), valueAt10.getValue().getValue()); + ITimeValue valueAt10 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_10); + assertEquals(asSet(ModelGenerator.STATE_STRING_TIME_10), valueAt10.getValue().getValue()); - ITimeValue valueAt20 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_20); - assertEquals(asSet(ModelGenerator.STATE_STRING_TIME_20), valueAt20.getValue().getValue()); + ITimeValue valueAt20 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_20); + assertEquals(asSet(ModelGenerator.STATE_STRING_TIME_20), valueAt20.getValue().getValue()); - ITimeValue valueAt30 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_30); - assertEquals(asSet(ModelGenerator.STATE_STRING_TIME_30), valueAt30.getValue().getValue()); - } + ITimeValue valueAt30 = booleanState.getTimeEvolution().getValueAt(ModelGenerator.STATE_TIME_30); + assertEquals(asSet(ModelGenerator.STATE_STRING_TIME_30), valueAt30.getValue().getValue()); + } - private static Set asSet(String value) { - HashSet hashSet = new HashSet<>(); - hashSet.add(new AString(value)); - return hashSet; - } + private static Set asSet(String value) { + HashSet hashSet = new HashSet<>(); + hashSet.add(new AString(value)); + return hashSet; + } } diff --git a/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java b/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java index 3b3f218a9..0e07f940e 100644 --- a/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java +++ b/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java @@ -71,8 +71,7 @@ public class FloatTimeVariableTest { } /** - * test, that the past values time fields start with 0 and are strictly - * smaller than PICK + * test, that the past values time fields start with 0 and are strictly smaller than PICK */ @Test public void testGetPastValues() { @@ -124,16 +123,15 @@ public class FloatTimeVariableTest { IValueChange change = new ValueChange(PICK, doubleValue); this.timeVariable.applyChange(change); - ITimeValue actual = this.timeVariable.getValueAt(PICK); - assertNotNull(actual); - + ITimeValue actual = this.timeVariable.getValueAt(PICK); + assertNotNull(actual); + IValue expectedValue = new FloatValue(STEP.doubleValue()); assertEquals(true, actual.getValue().matches(expectedValue)); } /** - * test that successors matching the values of their predecessors are - * removed + * test that successors matching the values of their predecessors are removed */ @Test public void testCompact() { diff --git a/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java b/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java index d1a5b346e..323c7c38e 100644 --- a/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java +++ b/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java @@ -32,7 +32,7 @@ import org.junit.Test; /** * Basic tests for a {@link TimeVariable} with integer values. - * + * * @author martin_smock */ public class IntegerTimeVariableTest { From c24e01cdc8d074a5621791a4b7771281f6365d32 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 27 Mar 2014 18:52:13 +0100 Subject: [PATCH 61/88] [Minor] BooleanParameter is now more restrictive on parsing from string We only want the string literals true and false to parse --- .../java/li/strolch/model/parameter/BooleanParameter.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/li/strolch/model/parameter/BooleanParameter.java b/src/main/java/li/strolch/model/parameter/BooleanParameter.java index 2596dba0c..56c1aba28 100644 --- a/src/main/java/li/strolch/model/parameter/BooleanParameter.java +++ b/src/main/java/li/strolch/model/parameter/BooleanParameter.java @@ -44,7 +44,7 @@ public class BooleanParameter extends AbstractParameter { /** * Default constructors - * + * * @param id * @param name * @param value @@ -56,7 +56,7 @@ public class BooleanParameter extends AbstractParameter { /** * DOM Constructor - * + * * @param element */ public BooleanParameter(Element element) { @@ -109,6 +109,6 @@ public class BooleanParameter extends AbstractParameter { } public static Boolean parseFromString(String valueS) { - return Boolean.valueOf(valueS); + return StringHelper.parseBoolean(valueS); } } From 5cb0982b2f77abcdb388818b6310049ab37982c1 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 27 Mar 2014 18:52:57 +0100 Subject: [PATCH 62/88] [Minor] Added missing writing of Parameter attributes --- .../model/xml/OrderToSaxWriterVisitor.java | 1 + .../model/xml/ResourceToSaxWriterVisitor.java | 1 + .../strolch/model/xml/XmlModelSaxReader.java | 234 ++++++++++-------- 3 files changed, 128 insertions(+), 108 deletions(-) diff --git a/src/main/java/li/strolch/model/xml/OrderToSaxWriterVisitor.java b/src/main/java/li/strolch/model/xml/OrderToSaxWriterVisitor.java index cf4f089d4..f3e4c7cef 100644 --- a/src/main/java/li/strolch/model/xml/OrderToSaxWriterVisitor.java +++ b/src/main/java/li/strolch/model/xml/OrderToSaxWriterVisitor.java @@ -38,6 +38,7 @@ public class OrderToSaxWriterVisitor extends AbstractToSaxWriterVisitor implemen public void visit(Order order) { try { writeElement(Tags.ORDER, order); + this.writer.flush(); } catch (XMLStreamException e) { String msg = "Failed to write Order {0} due to {1}"; //$NON-NLS-1$ msg = MessageFormat.format(msg, order.getLocator(), e.getMessage()); diff --git a/src/main/java/li/strolch/model/xml/ResourceToSaxWriterVisitor.java b/src/main/java/li/strolch/model/xml/ResourceToSaxWriterVisitor.java index 8f6783802..c73f5c3f7 100644 --- a/src/main/java/li/strolch/model/xml/ResourceToSaxWriterVisitor.java +++ b/src/main/java/li/strolch/model/xml/ResourceToSaxWriterVisitor.java @@ -38,6 +38,7 @@ public class ResourceToSaxWriterVisitor extends AbstractToSaxWriterVisitor imple public void visit(Resource resource) { try { writeElement(Tags.RESOURCE, resource); + this.writer.flush(); } catch (XMLStreamException e) { String msg = "Failed to write Resource {0} due to {1}"; //$NON-NLS-1$ msg = MessageFormat.format(msg, resource.getLocator(), e.getMessage()); diff --git a/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java b/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java index 48cc6d6fa..e1acc9df9 100644 --- a/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java +++ b/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java @@ -76,98 +76,98 @@ public class XmlModelSaxReader extends DefaultHandler { // TODO split each root object into its own file switch (qName) { - case Tags.STROLCH_MODEL: - break; + case Tags.STROLCH_MODEL: + break; - case Tags.RESOURCE: + case Tags.RESOURCE: - String resId = attributes.getValue(Tags.ID); - String resName = attributes.getValue(Tags.NAME); - String resType = attributes.getValue(Tags.TYPE); - Resource resource = new Resource(resId, resName, resType); - this.parameterizedElement = resource; - break; + String resId = attributes.getValue(Tags.ID); + String resName = attributes.getValue(Tags.NAME); + String resType = attributes.getValue(Tags.TYPE); + Resource resource = new Resource(resId, resName, resType); + this.parameterizedElement = resource; + break; - case Tags.ORDER: - String orderId = attributes.getValue(Tags.ID); - String orderName = attributes.getValue(Tags.NAME); - String orderType = attributes.getValue(Tags.TYPE); - String orderDateS = attributes.getValue(Tags.DATE); - String orderStateS = attributes.getValue(Tags.STATE); - Order order = new Order(orderId, orderName, orderType); - if (orderDateS != null) { - Date orderDate = ISO8601FormatFactory.getInstance().getDateFormat().parse(orderDateS); - order.setDate(orderDate); + case Tags.ORDER: + String orderId = attributes.getValue(Tags.ID); + String orderName = attributes.getValue(Tags.NAME); + String orderType = attributes.getValue(Tags.TYPE); + String orderDateS = attributes.getValue(Tags.DATE); + String orderStateS = attributes.getValue(Tags.STATE); + Order order = new Order(orderId, orderName, orderType); + if (orderDateS != null) { + Date orderDate = ISO8601FormatFactory.getInstance().getDateFormat().parse(orderDateS); + order.setDate(orderDate); + } + if (orderStateS != null) { + State orderState = State.valueOf(orderStateS); + order.setState(orderState); + } + this.parameterizedElement = order; + break; + + case Tags.PARAMETER_BAG: + String pBagId = attributes.getValue(Tags.ID); + String pBagName = attributes.getValue(Tags.NAME); + String pBagType = attributes.getValue(Tags.TYPE); + ParameterBag pBag = new ParameterBag(pBagId, pBagName, pBagType); + this.pBag = pBag; + this.parameterizedElement.addParameterBag(pBag); + break; + + case Tags.PARAMETER: + String paramId = attributes.getValue(Tags.ID); + String paramName = attributes.getValue(Tags.NAME); + String paramType = attributes.getValue(Tags.TYPE); + String paramValue = attributes.getValue(Tags.VALUE); + String paramHiddenS = attributes.getValue(Tags.HIDDEN); + String paramIndexS = attributes.getValue(Tags.INDEX); + try { + int index = StringHelper.isEmpty(paramIndexS) ? 0 : Integer.valueOf(paramIndexS); + boolean paramHidden = StringHelper.isEmpty(paramHiddenS) ? false : StringHelper + .parseBoolean(paramHiddenS); + String paramUom = attributes.getValue(Tags.UOM); + String paramInterpretation = attributes.getValue(Tags.INTERPRETATION); + Parameter param; + switch (paramType) { + case StringParameter.TYPE: + param = new StringParameter(paramId, paramName, paramValue); + break; + case IntegerParameter.TYPE: + param = new IntegerParameter(paramId, paramName, IntegerParameter.parseFromString(paramValue)); + break; + case BooleanParameter.TYPE: + param = new BooleanParameter(paramId, paramName, BooleanParameter.parseFromString(paramValue)); + break; + case LongParameter.TYPE: + param = new LongParameter(paramId, paramName, LongParameter.parseFromString(paramValue)); + break; + case DateParameter.TYPE: + param = new DateParameter(paramId, paramName, DateParameter.parseFromString(paramValue)); + break; + case StringListParameter.TYPE: + param = new StringListParameter(paramId, paramName, StringListParameter.parseFromString(paramValue)); + break; + case FloatParameter.TYPE: + param = new FloatParameter(paramId, paramName, FloatParameter.parseFromString(paramValue)); + break; + default: + throw new UnsupportedOperationException(MessageFormat.format( + "Parameters of type {0} are not supported!", paramType)); //$NON-NLS-1$ } - if (orderStateS != null) { - State orderState = State.valueOf(orderStateS); - order.setState(orderState); - } - this.parameterizedElement = order; - break; + param.setHidden(paramHidden); + param.setUom(paramUom); + param.setInterpretation(paramInterpretation); + param.setIndex(index); + this.pBag.addParameter(param); + } catch (Exception e) { + throw new StrolchException("Failed to instantiate parameter " + paramId + " for bag " + + this.pBag.getLocator() + " due to " + e.getMessage(), e); + } + break; - case Tags.PARAMETER_BAG: - String pBagId = attributes.getValue(Tags.ID); - String pBagName = attributes.getValue(Tags.NAME); - String pBagType = attributes.getValue(Tags.TYPE); - ParameterBag pBag = new ParameterBag(pBagId, pBagName, pBagType); - this.pBag = pBag; - this.parameterizedElement.addParameterBag(pBag); - break; - - case Tags.PARAMETER: - String paramId = attributes.getValue(Tags.ID); - String paramName = attributes.getValue(Tags.NAME); - String paramType = attributes.getValue(Tags.TYPE); - String paramValue = attributes.getValue(Tags.VALUE); - String paramHiddenS = attributes.getValue(Tags.HIDDEN); - String paramIndexS = attributes.getValue(Tags.INDEX); - try { - int index = StringHelper.isEmpty(paramIndexS) ? 0 : Integer.valueOf(paramIndexS); - boolean paramHidden = StringHelper.isEmpty(paramHiddenS) ? false : StringHelper - .parseBoolean(paramHiddenS); - String paramUom = attributes.getValue(Tags.UOM); - String paramInterpretation = attributes.getValue(Tags.INTERPRETATION); - Parameter param; - switch (paramType) { - case StringParameter.TYPE: - param = new StringParameter(paramId, paramName, paramValue); - break; - case IntegerParameter.TYPE: - param = new IntegerParameter(paramId, paramName, IntegerParameter.parseFromString(paramValue)); - break; - case BooleanParameter.TYPE: - param = new BooleanParameter(paramId, paramName, BooleanParameter.parseFromString(paramValue)); - break; - case LongParameter.TYPE: - param = new LongParameter(paramId, paramName, LongParameter.parseFromString(paramValue)); - break; - case DateParameter.TYPE: - param = new DateParameter(paramId, paramName, DateParameter.parseFromString(paramValue)); - break; - case StringListParameter.TYPE: - param = new StringListParameter(paramId, paramName, StringListParameter.parseFromString(paramValue)); - break; - case FloatParameter.TYPE: - param = new FloatParameter(paramId, paramName, FloatParameter.parseFromString(paramValue)); - break; - default: - throw new UnsupportedOperationException(MessageFormat.format( - "Parameters of type {0} are not supported!", paramType)); //$NON-NLS-1$ - } - param.setHidden(paramHidden); - param.setUom(paramUom); - param.setInterpretation(paramInterpretation); - param.setIndex(index); - this.pBag.addParameter(param); - } catch (Exception e) { - throw new StrolchException("Failed to instantiate parameter " + paramId + " for bag " - + this.pBag.getLocator() + " due to " + e.getMessage(), e); - } - break; - - default: - throw new IllegalArgumentException(MessageFormat.format("The element ''{0}'' is unhandled!", qName)); //$NON-NLS-1$ + default: + throw new IllegalArgumentException(MessageFormat.format("The element ''{0}'' is unhandled!", qName)); //$NON-NLS-1$ } } @@ -175,27 +175,27 @@ public class XmlModelSaxReader extends DefaultHandler { public void endElement(String uri, String localName, String qName) throws SAXException { switch (qName) { - case Tags.STROLCH_MODEL: - break; - case Tags.RESOURCE: - this.listener.notifyResource((Resource) this.parameterizedElement); - this.statistics.nrOfResources++; - this.parameterizedElement = null; - break; - case Tags.ORDER: - this.listener.notifyOrder((Order) this.parameterizedElement); - this.statistics.nrOfOrders++; - this.parameterizedElement = null; - break; - case Tags.PARAMETER_BAG: - this.pBag = null; - break; - case Tags.PARAMETER: - break; - case Tags.INCLUDE_FILE: - break; - default: - throw new IllegalArgumentException(MessageFormat.format("The element ''{0}'' is unhandled!", qName)); //$NON-NLS-1$ + case Tags.STROLCH_MODEL: + break; + case Tags.RESOURCE: + this.listener.notifyResource((Resource) this.parameterizedElement); + this.statistics.nrOfResources++; + this.parameterizedElement = null; + break; + case Tags.ORDER: + this.listener.notifyOrder((Order) this.parameterizedElement); + this.statistics.nrOfOrders++; + this.parameterizedElement = null; + break; + case Tags.PARAMETER_BAG: + this.pBag = null; + break; + case Tags.PARAMETER: + break; + case Tags.INCLUDE_FILE: + break; + default: + throw new IllegalArgumentException(MessageFormat.format("The element ''{0}'' is unhandled!", qName)); //$NON-NLS-1$ } } @@ -206,6 +206,24 @@ public class XmlModelSaxReader extends DefaultHandler { public int nrOfResources; public int nrOfOrders; + /** + * @return the nrOfOrders + */ + public int getNrOfOrders() { + return this.nrOfOrders; + } + + /** + * @return the nrOfResources + */ + public int getNrOfResources() { + return this.nrOfResources; + } + + public long getNrOfElements() { + return this.nrOfOrders + this.nrOfResources; + } + @Override public String toString() { StringBuilder builder = new StringBuilder(); From 6ae9cbf866feb9a807e71d823a4bbcea0832f8e0 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 28 Mar 2014 18:43:04 +0100 Subject: [PATCH 63/88] [Minor] use locator when throwing exceptions --- src/main/java/li/strolch/model/AbstractStrolchElement.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/li/strolch/model/AbstractStrolchElement.java b/src/main/java/li/strolch/model/AbstractStrolchElement.java index e554331ea..110fa2803 100644 --- a/src/main/java/li/strolch/model/AbstractStrolchElement.java +++ b/src/main/java/li/strolch/model/AbstractStrolchElement.java @@ -86,8 +86,8 @@ public abstract class AbstractStrolchElement implements StrolchElement { @Override public void setName(String name) { if (StringHelper.isEmpty(name)) { - String msg = "The name may never be empty for {0} with id {1}"; - msg = MessageFormat.format(msg, getClass().getSimpleName(), id); + String msg = "The name may never be empty for {0} {1}"; + msg = MessageFormat.format(msg, getClass().getSimpleName(), getLocator()); throw new StrolchException(msg); } this.name = name; From c8cedae6474f2a3834296fb99368ed1f0c0776a0 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 31 Mar 2014 21:37:13 +0200 Subject: [PATCH 64/88] [Minor] Code formatting --- .../model/GroupedParameterizedElement.java | 89 +++++++++++-------- .../strolch/model/ParameterizedElement.java | 50 +++++++---- .../li/strolch/model/parameter/Parameter.java | 43 ++++----- 3 files changed, 100 insertions(+), 82 deletions(-) diff --git a/src/main/java/li/strolch/model/GroupedParameterizedElement.java b/src/main/java/li/strolch/model/GroupedParameterizedElement.java index aef6552fd..0bf081c05 100644 --- a/src/main/java/li/strolch/model/GroupedParameterizedElement.java +++ b/src/main/java/li/strolch/model/GroupedParameterizedElement.java @@ -49,7 +49,7 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement /** * Default Constructor - * + * * @param id * @param name * @param type @@ -66,8 +66,9 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement /** * Sets the type of this {@link GroupedParameterizedElement} - * - * @param type the type to set + * + * @param type + * the type to set */ public void setType(String type) { if (StringHelper.isEmpty(type)) { @@ -82,10 +83,12 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement /** * Returns the {@link Parameter} with the given key from the {@link ParameterBag} with the given bagKey, or null if * the {@link Parameter} or the {@link ParameterBag} does not exist - * - * @param bagKey the key of the {@link ParameterBag} from which the {@link Parameter} is to be returned - * @param paramKey the key of the {@link Parameter} which is to be returned - * + * + * @param bagKey + * the key of the {@link ParameterBag} from which the {@link Parameter} is to be returned + * @param paramKey + * the key of the {@link Parameter} which is to be returned + * * @return the found {@link Parameter} or null if it was not found */ public T getParameter(String bagKey, String paramKey) { @@ -102,11 +105,14 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement /** * Adds a new {@link Parameter} to the {@link ParameterBag} with the given key - * - * @param bagKey the key of the {@link ParameterBag} to which the {@link Parameter} should be added - * @param parameter the {@link Parameter} to be added to the {@link ParameterBag} - * - * @throws StrolchException if the {@link ParameterBag} does not exist + * + * @param bagKey + * the key of the {@link ParameterBag} to which the {@link Parameter} should be added + * @param parameter + * the {@link Parameter} to be added to the {@link ParameterBag} + * + * @throws StrolchException + * if the {@link ParameterBag} does not exist */ public void addParameter(String bagKey, Parameter parameter) throws StrolchException { if (this.parameterBagMap == null) { @@ -124,10 +130,12 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement /** * Removes the {@link Parameter} with the given paramKey from the {@link ParameterBag} with the given bagKey - * - * @param bagKey the key of the {@link ParameterBag} from which the {@link Parameter} is to be removed - * @param paramKey the key of the {@link Parameter} which is to be removed - * + * + * @param bagKey + * the key of the {@link ParameterBag} from which the {@link Parameter} is to be removed + * @param paramKey + * the key of the {@link Parameter} which is to be removed + * * @return the removed {@link Parameter} or null if it did not exist */ public Parameter removeParameter(String bagKey, String paramKey) { @@ -144,9 +152,10 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement /** * Returns the {@link ParameterBag} with the given key, or null if it does not exist - * - * @param key the key of the {@link ParameterBag} to return - * + * + * @param key + * the key of the {@link ParameterBag} to return + * * @return the {@link ParameterBag} with the given key, or null if it does not exist */ public ParameterBag getParameterBag(String key) { @@ -158,22 +167,29 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement /** * Adds the given {@link ParameterBag} to this {@link GroupedParameterizedElement} - * - * @param bag the {@link ParameterBag} to add + * + * @param bag + * the {@link ParameterBag} to add */ public void addParameterBag(ParameterBag bag) { if (this.parameterBagMap == null) { this.parameterBagMap = new HashMap(); } + + if (this.parameterBagMap.containsKey(bag.getId())) { + String msg = "A ParameterBag already exists with id {0} on {1}"; + throw new StrolchException(MessageFormat.format(msg, bag.getId(), getLocator())); + } this.parameterBagMap.put(bag.getId(), bag); bag.setParent(this); } /** * Removes the {@link ParameterBag} with the given key - * - * @param key the key of the {@link ParameterBag} to remove - * + * + * @param key + * the key of the {@link ParameterBag} to remove + * * @return the removed {@link ParameterBag}, or null if it does not exist */ public ParameterBag removeParameterBag(String key) { @@ -185,7 +201,7 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement /** * Returns true if this {@link GroupedParameterizedElement} has any {@link ParameterBag ParameterBag} - * + * * @return true if this {@link GroupedParameterizedElement} has any {@link ParameterBag ParameterBag} */ public boolean hasParameterBags() { @@ -194,8 +210,9 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement /** * Returns true if the {@link ParameterBag} with the given key exists on this {@link GroupedParameterizedElement}. - * - * @param bagKey the key of the {@link ParameterBag} which is to be checked for existence + * + * @param bagKey + * the key of the {@link ParameterBag} which is to be checked for existence * @return true if the {@link ParameterBag} with the given key exists on this {@link GroupedParameterizedElement}. */ public boolean hasParameterBag(String bagKey) { @@ -205,13 +222,15 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement /** * Returns true if the {@link Parameter} with the given paramKey exists on the {@link ParameterBag} with the given * bagKey - * - * @param bagKey the key of the {@link ParameterBag} on which to find the {@link Parameter} - * @param paramKey the key of the {@link Parameter} to be found - * + * + * @param bagKey + * the key of the {@link ParameterBag} on which to find the {@link Parameter} + * @param paramKey + * the key of the {@link Parameter} to be found + * * @return true if the {@link Parameter} with the given paramKey exists on the {@link ParameterBag} with the given - * bagKey. False is returned if the {@link ParameterBag} does not exist, or the {@link Parameter} does not exist on - * the {@link ParameterBag} + * bagKey. False is returned if the {@link ParameterBag} does not exist, or the {@link Parameter} does not + * exist on the {@link ParameterBag} */ public boolean hasParameter(String bagKey, String paramKey) { if (this.parameterBagMap == null) { @@ -227,7 +246,7 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement /** * Returns the {@link Set} of keys for the {@link ParameterBag}s on this {@link GroupedParameterizedElement} - * + * * @return the {@link Set} of keys for the {@link ParameterBag}s on this {@link GroupedParameterizedElement} */ public Set getParameterBagKeySet() { @@ -265,7 +284,7 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement /** * Fills {@link GroupedParameterizedElement} properties of this clone - * + * * @param clone */ protected void fillClone(GroupedParameterizedElement clone) { diff --git a/src/main/java/li/strolch/model/ParameterizedElement.java b/src/main/java/li/strolch/model/ParameterizedElement.java index 14299ea50..6a8e2b9cd 100644 --- a/src/main/java/li/strolch/model/ParameterizedElement.java +++ b/src/main/java/li/strolch/model/ParameterizedElement.java @@ -16,6 +16,7 @@ package li.strolch.model; import ch.eitchnet.utils.dbc.DBC; + import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collections; @@ -61,7 +62,7 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { /** * Default Constructor - * + * * @param id * @param name * @param type @@ -79,8 +80,9 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { /** * Sets the type of this {@link ParameterizedElement} - * - * @param type the type to set + * + * @param type + * the type to set */ public void setType(String type) { if (StringHelper.isEmpty(type)) { @@ -94,9 +96,10 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { /** * Returns the {@link Parameter} with the given id, or null if it does not exist - * - * @param key the id of the parameter to return - * + * + * @param key + * the id of the parameter to return + * * @return the {@link Parameter} with the given id, or null if it does not exist */ @SuppressWarnings("unchecked") @@ -109,22 +112,29 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { /** * Adds the given {@link Parameter} to the {@link ParameterizedElement} - * - * @param parameter the {@link Parameter} to add + * + * @param parameter + * the {@link Parameter} to add */ public void addParameter(Parameter parameter) { if (this.parameterMap == null) { this.parameterMap = new HashMap>(); } + + if (this.parameterMap.containsKey(parameter.getId())) { + String msg = "A Parameter already exists with id {0} on {1}"; + throw new StrolchException(MessageFormat.format(msg, parameter.getId(), getLocator())); + } this.parameterMap.put(parameter.getId(), parameter); parameter.setParent(this); } /** * Removes the {@link Parameter} with the given key - * - * @param key the key of the {@link Parameter} to remove - * + * + * @param key + * the key of the {@link Parameter} to remove + * * @return the removed {@link Parameter}, or null if it does not exist */ @SuppressWarnings("unchecked") @@ -137,7 +147,7 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { /** * Returns a list of all the {@link Parameter}s in this {@link ParameterizedElement} - * + * * @return a list of all the {@link Parameter}s in this {@link ParameterizedElement} */ public List> getParameters() { @@ -149,7 +159,7 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { /** * Returns true, if the this {@link ParameterizedElement} has any {@link Parameter Parameters}, false otherwise - * + * * @return true, if the this {@link ParameterizedElement} has any {@link Parameter Parameters}, false otherwise */ public boolean hasParameters() { @@ -158,9 +168,10 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { /** * Returns true, if the {@link Parameter} exists with the given key, false otherwise - * - * @param key the key of the {@link Parameter} to check for - * + * + * @param key + * the key of the {@link Parameter} to check for + * * @return true, if the {@link Parameter} exists with the given key, false otherwise */ public boolean hasParameter(String key) { @@ -172,7 +183,7 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { /** * Returns a {@link Set} of all the {@link Parameter} keys in this {@link ParameterizedElement} - * + * * @return a {@link Set} of all the {@link Parameter} keys in this {@link ParameterizedElement} */ public Set getParameterKeySet() { @@ -269,8 +280,9 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { /** * Set the parent for this {@link ParameterizedElement} - * - * @param parent the parent to set + * + * @param parent + * the parent to set */ public void setParent(GroupedParameterizedElement parent) { this.parent = parent; diff --git a/src/main/java/li/strolch/model/parameter/Parameter.java b/src/main/java/li/strolch/model/parameter/Parameter.java index e9c46140e..3eae2ef9f 100644 --- a/src/main/java/li/strolch/model/parameter/Parameter.java +++ b/src/main/java/li/strolch/model/parameter/Parameter.java @@ -15,15 +15,13 @@ */ package li.strolch.model.parameter; -import li.strolch.model.Order; import li.strolch.model.ParameterizedElement; -import li.strolch.model.Resource; import li.strolch.model.StrolchElement; import li.strolch.model.visitor.ParameterVisitor; /** * @author Robert von Burg - * + * */ public interface Parameter extends StrolchElement { @@ -37,84 +35,73 @@ public interface Parameter extends StrolchElement { */ public static final String UOM_NONE = "None"; //$NON-NLS-1$ - /** - * This interpretation value indicates that the value of the {@link Parameter} should be understood as a reference - * to a {@link Resource} - */ - public static final String INTERPRETATION_RESOURCE_REF = "Resource-Reference"; //$NON-NLS-1$ - - /** - * This interpretation value indicates that the value of the {@link Parameter} should be understood as a reference - * to a {@link Order} - */ - public static final String INTERPRETATION_ORDER_REF = "Order-Reference"; //$NON-NLS-1$ - /** * the value of the parameter as string - * + * * @return String */ public String getValueAsString(); /** * the value of the parameter - * + * * @return */ public T getValue(); /** * the value of the parameter - * + * * @param value */ public void setValue(T value); /** * get the hidden attribute - * + * * @return */ public boolean isHidden(); /** * set the hidden attribute - * + * * @param hidden */ public void setHidden(boolean hidden); /** * Get the UOM of this {@link Parameter} - * + * * @return */ public String getUom(); /** * Set the UOM of this {@link Parameter} - * + * * @param uom */ public void setUom(String uom); /** * Returns the index of this {@link Parameter}. This can be used to sort the parameters in a UI - * + * * @return the index of this {@link Parameter}. This can be used to sort the parameters in a UI */ public int getIndex(); /** * Set the index of this {@link Parameter}. This can be used to sort the parameters in a UI - * - * @param index the index to set + * + * @param index + * the index to set */ public void setIndex(int index); /** * The {@link ParameterizedElement} parent to which this {@link Parameter} belongs - * + * * @return */ public ParameterizedElement getParent(); @@ -132,7 +119,7 @@ public interface Parameter extends StrolchElement { *
  • {@link Parameter#INTERPRETATION_ORDER_REF}
  • *
  • {@link Parameter#INTERPRETATION_RESOURCE_REF}
  • * - * + * * @return string value */ public String getInterpretation(); @@ -145,7 +132,7 @@ public interface Parameter extends StrolchElement { *
  • {@link Parameter#INTERPRETATION_ORDER_REF}
  • *
  • {@link Parameter#INTERPRETATION_RESOURCE_REF}
  • * - * + * * @param interpretation */ public void setInterpretation(String interpretation); From c246c762366cec21e6fa1f7c58ddf7066dccec38 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Tue, 15 Jul 2014 18:50:45 +0200 Subject: [PATCH 65/88] [New] Added a StrolchQuery.hasSelection() and Selection.hasSelection() This allows for checking if a query really has a selection. --- .../li/strolch/model/query/BooleanSelection.java | 14 ++++++++++++++ .../li/strolch/model/query/OrderSelection.java | 7 ++++++- .../strolch/model/query/ParameterSelection.java | 16 ++++++++++++++++ .../java/li/strolch/model/query/Selection.java | 3 ++- .../model/query/StrolchElementSelection.java | 5 +++++ .../li/strolch/model/query/StrolchQuery.java | 8 ++++++++ 6 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/main/java/li/strolch/model/query/BooleanSelection.java b/src/main/java/li/strolch/model/query/BooleanSelection.java index 76e2cee17..afc7284b7 100644 --- a/src/main/java/li/strolch/model/query/BooleanSelection.java +++ b/src/main/java/li/strolch/model/query/BooleanSelection.java @@ -45,6 +45,20 @@ public abstract class BooleanSelection implements Selection { this.selections = Arrays.asList(selections); } + @Override + public boolean hasSelection() { + if (this.selections == null || this.selections.isEmpty()) + return false; + + for (Selection selection : this.selections) { + if (selection.hasSelection()) { + return true; + } + } + + return false; + } + public List getSelections() { return Collections.unmodifiableList(this.selections); } diff --git a/src/main/java/li/strolch/model/query/OrderSelection.java b/src/main/java/li/strolch/model/query/OrderSelection.java index ab6479c42..4a904d612 100644 --- a/src/main/java/li/strolch/model/query/OrderSelection.java +++ b/src/main/java/li/strolch/model/query/OrderSelection.java @@ -17,7 +17,7 @@ package li.strolch.model.query; /** * @author Robert von Burg - * + * */ public abstract class OrderSelection implements Selection { @@ -26,5 +26,10 @@ public abstract class OrderSelection implements Selection { accept((OrderSelectionVisitor) visitor); } + @Override + public boolean hasSelection() { + return true; + } + public abstract void accept(OrderSelectionVisitor visitor); } diff --git a/src/main/java/li/strolch/model/query/ParameterSelection.java b/src/main/java/li/strolch/model/query/ParameterSelection.java index a3cc17bdf..3ca5b1316 100644 --- a/src/main/java/li/strolch/model/query/ParameterSelection.java +++ b/src/main/java/li/strolch/model/query/ParameterSelection.java @@ -45,11 +45,27 @@ public abstract class ParameterSelection implements Selection { return this.paramKey; } + @Override + public boolean hasSelection() { + return true; + } + @Override public void accept(QueryVisitor visitor) { accept((ParameterSelectionVisitor) visitor); } + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append(getClass().getSimpleName() + " [bagKey="); + builder.append(this.bagKey); + builder.append(", paramKey="); + builder.append(this.paramKey); + builder.append("]"); + return builder.toString(); + } + public abstract void accept(ParameterSelectionVisitor visitor); public static StringParameterSelection stringSelection(String bagKey, String paramKey, String value) { diff --git a/src/main/java/li/strolch/model/query/Selection.java b/src/main/java/li/strolch/model/query/Selection.java index aeaded229..dd930ec6a 100644 --- a/src/main/java/li/strolch/model/query/Selection.java +++ b/src/main/java/li/strolch/model/query/Selection.java @@ -20,6 +20,7 @@ package li.strolch.model.query; */ public interface Selection { - // marker interface public void accept(QueryVisitor visitor); + + public boolean hasSelection(); } diff --git a/src/main/java/li/strolch/model/query/StrolchElementSelection.java b/src/main/java/li/strolch/model/query/StrolchElementSelection.java index bd4a5907b..0d33dc4bc 100644 --- a/src/main/java/li/strolch/model/query/StrolchElementSelection.java +++ b/src/main/java/li/strolch/model/query/StrolchElementSelection.java @@ -25,5 +25,10 @@ public abstract class StrolchElementSelection implements Selection { accept((StrolchElementSelectionVisitor) visitor); } + @Override + public boolean hasSelection() { + return true; + } + public abstract void accept(StrolchElementSelectionVisitor visitor); } diff --git a/src/main/java/li/strolch/model/query/StrolchQuery.java b/src/main/java/li/strolch/model/query/StrolchQuery.java index fa90f0385..daba941ed 100644 --- a/src/main/java/li/strolch/model/query/StrolchQuery.java +++ b/src/main/java/li/strolch/model/query/StrolchQuery.java @@ -28,6 +28,14 @@ public abstract class StrolchQuery { public StrolchQuery(Navigation navigation) { this.navigation = navigation; } + + public boolean hasNavigation() { + return navigation != null; + } + + public boolean hasSelection() { + return selection != null && selection.hasSelection(); + } public void select(Selection selection) { DBC.PRE.assertNull("A selection is already set! Use a boolean operator to perform multiple selections", From 16db0e357ebddfde7fbf29e4517b49c95f3a6114 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 31 Jul 2014 09:40:49 +0200 Subject: [PATCH 66/88] [New] Added a DataRange parameter selection --- .../model/query/ParameterSelection.java | 32 +++++++++++++++++++ .../query/ParameterSelectionVisitor.java | 4 ++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/main/java/li/strolch/model/query/ParameterSelection.java b/src/main/java/li/strolch/model/query/ParameterSelection.java index 3ca5b1316..f326ee62a 100644 --- a/src/main/java/li/strolch/model/query/ParameterSelection.java +++ b/src/main/java/li/strolch/model/query/ParameterSelection.java @@ -18,6 +18,8 @@ package li.strolch.model.query; import java.util.Date; import java.util.List; +import ch.eitchnet.utils.dbc.DBC; + /** * @author Robert von Burg */ @@ -92,6 +94,10 @@ public abstract class ParameterSelection implements Selection { return new DateParameterSelection(bagKey, paramKey, value); } + public static DateRangeParameterSelection dateRangeSelection(String bagKey, String paramKey, Date from, Date to) { + return new DateRangeParameterSelection(bagKey, paramKey, from, to); + } + public static StringListParameterSelection stringListSelection(String bagKey, String paramKey, List value) { return new StringListParameterSelection(bagKey, paramKey, value); } @@ -230,6 +236,32 @@ public abstract class ParameterSelection implements Selection { } } + public static class DateRangeParameterSelection extends ParameterSelection { + + private Date from; + private Date to; + + public DateRangeParameterSelection(String bagKey, String paramKey, Date from, Date to) { + super(bagKey, paramKey); + DBC.PRE.assertFalse("Either 'to' or 'from' must be set! Both can not be null!", from == null && to == null); + this.from = from; + this.to = to; + } + + public Date getFrom() { + return this.from; + } + + public Date getTo() { + return this.to; + } + + @Override + public void accept(ParameterSelectionVisitor visitor) { + visitor.visit(this); + } + } + public static class StringListParameterSelection extends ParameterSelection { private List value; diff --git a/src/main/java/li/strolch/model/query/ParameterSelectionVisitor.java b/src/main/java/li/strolch/model/query/ParameterSelectionVisitor.java index b8b767474..e6b5b2e8d 100644 --- a/src/main/java/li/strolch/model/query/ParameterSelectionVisitor.java +++ b/src/main/java/li/strolch/model/query/ParameterSelectionVisitor.java @@ -17,6 +17,7 @@ package li.strolch.model.query; import li.strolch.model.query.ParameterSelection.BooleanParameterSelection; import li.strolch.model.query.ParameterSelection.DateParameterSelection; +import li.strolch.model.query.ParameterSelection.DateRangeParameterSelection; import li.strolch.model.query.ParameterSelection.FloatParameterSelection; import li.strolch.model.query.ParameterSelection.IntegerParameterSelection; import li.strolch.model.query.ParameterSelection.LongParameterSelection; @@ -25,7 +26,6 @@ import li.strolch.model.query.ParameterSelection.StringParameterSelection; /** * @author Robert von Burg - * */ public interface ParameterSelectionVisitor extends QueryVisitor { @@ -40,6 +40,8 @@ public interface ParameterSelectionVisitor extends QueryVisitor { public void visit(FloatParameterSelection selection); public void visit(DateParameterSelection selection); + + public void visit(DateRangeParameterSelection selection); public void visit(StringListParameterSelection selection); } From d36267f640431e3cc8dc4a2076fb073c133108dd Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 31 Jul 2014 16:11:20 +0200 Subject: [PATCH 67/88] [Minor] extracted ModelStatistics --- .../li/strolch/model/ModelStatistics.java | 50 ++++++++++++++++++ .../strolch/model/xml/XmlModelSaxReader.java | 51 ++----------------- .../model/XmlModelDefaultHandlerTest.java | 3 +- 3 files changed, 55 insertions(+), 49 deletions(-) create mode 100644 src/main/java/li/strolch/model/ModelStatistics.java diff --git a/src/main/java/li/strolch/model/ModelStatistics.java b/src/main/java/li/strolch/model/ModelStatistics.java new file mode 100644 index 000000000..d3a04bd4c --- /dev/null +++ b/src/main/java/li/strolch/model/ModelStatistics.java @@ -0,0 +1,50 @@ +package li.strolch.model; + +import static ch.eitchnet.utils.helper.StringHelper.NULL; + +import java.util.Date; + +import ch.eitchnet.utils.helper.StringHelper; +import ch.eitchnet.utils.iso8601.ISO8601FormatFactory; + +public class ModelStatistics { + + public Date startTime; + public long durationNanos; + public long nrOfResources; + public long nrOfOrders; + + /** + * @return the nrOfOrders + */ + public long getNrOfOrders() { + return this.nrOfOrders; + } + + /** + * @return the nrOfResources + */ + public long getNrOfResources() { + return this.nrOfResources; + } + + public long getNrOfElements() { + return this.nrOfOrders + this.nrOfResources; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append(getClass().getSimpleName() + " [startTime="); + builder.append(this.startTime == null ? NULL : ISO8601FormatFactory.getInstance() + .formatDate(this.startTime)); + builder.append(", durationNanos="); + builder.append(StringHelper.formatNanoDuration(this.durationNanos)); + builder.append(", nrOfResources="); + builder.append(this.nrOfResources); + builder.append(", nrOfOrders="); + builder.append(this.nrOfOrders); + builder.append("]"); + return builder.toString(); + } +} \ No newline at end of file diff --git a/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java b/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java index e1acc9df9..06fe0901b 100644 --- a/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java +++ b/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java @@ -15,13 +15,12 @@ */ package li.strolch.model.xml; -import static ch.eitchnet.utils.helper.StringHelper.NULL; - import java.text.MessageFormat; import java.util.Date; import li.strolch.exception.StrolchException; import li.strolch.model.GroupedParameterizedElement; +import li.strolch.model.ModelStatistics; import li.strolch.model.Order; import li.strolch.model.ParameterBag; import li.strolch.model.Resource; @@ -53,20 +52,20 @@ public class XmlModelSaxReader extends DefaultHandler { protected static final Logger logger = LoggerFactory.getLogger(XmlModelSaxReader.class); protected StrolchElementListener listener; - protected XmlModelStatistics statistics; + protected ModelStatistics statistics; private GroupedParameterizedElement parameterizedElement; private ParameterBag pBag; public XmlModelSaxReader(StrolchElementListener listener) { this.listener = listener; - this.statistics = new XmlModelStatistics(); + this.statistics = new ModelStatistics(); } /** * @return the statistics */ - public XmlModelStatistics getStatistics() { + public ModelStatistics getStatistics() { return this.statistics; } @@ -198,46 +197,4 @@ public class XmlModelSaxReader extends DefaultHandler { throw new IllegalArgumentException(MessageFormat.format("The element ''{0}'' is unhandled!", qName)); //$NON-NLS-1$ } } - - public static class XmlModelStatistics { - - public Date startTime; - public long durationNanos; - public int nrOfResources; - public int nrOfOrders; - - /** - * @return the nrOfOrders - */ - public int getNrOfOrders() { - return this.nrOfOrders; - } - - /** - * @return the nrOfResources - */ - public int getNrOfResources() { - return this.nrOfResources; - } - - public long getNrOfElements() { - return this.nrOfOrders + this.nrOfResources; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("XmlModelStatistics [startTime="); - builder.append(this.startTime == null ? NULL : ISO8601FormatFactory.getInstance() - .formatDate(this.startTime)); - builder.append(", durationNanos="); - builder.append(StringHelper.formatNanoDuration(this.durationNanos)); - builder.append(", nrOfResources="); - builder.append(this.nrOfResources); - builder.append(", nrOfOrders="); - builder.append(this.nrOfOrders); - builder.append("]"); - return builder.toString(); - } - } } diff --git a/src/test/java/li/strolch/model/XmlModelDefaultHandlerTest.java b/src/test/java/li/strolch/model/XmlModelDefaultHandlerTest.java index f6948b6c2..35f299bb9 100644 --- a/src/test/java/li/strolch/model/XmlModelDefaultHandlerTest.java +++ b/src/test/java/li/strolch/model/XmlModelDefaultHandlerTest.java @@ -22,7 +22,6 @@ import java.util.HashMap; import java.util.Map; import li.strolch.model.xml.StrolchElementListener; -import li.strolch.model.xml.XmlModelSaxReader.XmlModelStatistics; import li.strolch.model.xml.XmlModelSaxFileReader; import org.junit.Test; @@ -64,7 +63,7 @@ public class XmlModelDefaultHandlerTest { assertEquals(3, resourceMap.size()); assertEquals(3, orderMap.size()); - XmlModelStatistics statistics = handler.getStatistics(); + ModelStatistics statistics = handler.getStatistics(); logger.info("Parsing took " + StringHelper.formatNanoDuration(statistics.durationNanos)); assertEquals(3, statistics.nrOfOrders); assertEquals(3, statistics.nrOfResources); From c21f96a5aee83eea9f3a89a76c306580bf689e31 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 4 Aug 2014 14:50:36 +0200 Subject: [PATCH 68/88] [New] added StrolchQuery.getSelection() and cleaned up some constants --- .../strolch/model/StrolchModelConstants.java | 23 +++++++++++ src/main/java/li/strolch/model/Tags.java | 1 - .../li/strolch/model/parameter/Parameter.java | 10 +++-- .../model/query/ParameterSelection.java | 3 +- .../li/strolch/model/query/StrolchQuery.java | 38 ++++++++++++------- 5 files changed, 56 insertions(+), 19 deletions(-) create mode 100644 src/main/java/li/strolch/model/StrolchModelConstants.java diff --git a/src/main/java/li/strolch/model/StrolchModelConstants.java b/src/main/java/li/strolch/model/StrolchModelConstants.java new file mode 100644 index 000000000..ae993ddfb --- /dev/null +++ b/src/main/java/li/strolch/model/StrolchModelConstants.java @@ -0,0 +1,23 @@ +package li.strolch.model; + +import li.strolch.model.parameter.Parameter; + +public class StrolchModelConstants { + + /** + * The type to set on {@link StrolchRootElement StrolchRootElements} when defining a template for a type of element + */ + public static final String TEMPLATE = "Template"; //$NON-NLS-1$ + + /** + * This interpretation value indicates that the value of the {@link Parameter} should be understood as a reference + * to a {@link Resource} + */ + public static final String INTERPRETATION_RESOURCE_REF = "Resource-Ref"; //$NON-NLS-1$ + + /** + * This interpretation value indicates that the value of the {@link Parameter} should be understood as a reference + * to an {@link Order} + */ + public static final String INTERPRETATION_ORDER_REF = "Order-Ref"; //$NON-NLS-1$ +} diff --git a/src/main/java/li/strolch/model/Tags.java b/src/main/java/li/strolch/model/Tags.java index 879b36a56..eb79a8fc2 100644 --- a/src/main/java/li/strolch/model/Tags.java +++ b/src/main/java/li/strolch/model/Tags.java @@ -40,5 +40,4 @@ public class Tags { public static final String INCLUDE_FILE = "IncludeFile"; public static final String FILE = "file"; - public static final String TEMPLATE = "Template"; } diff --git a/src/main/java/li/strolch/model/parameter/Parameter.java b/src/main/java/li/strolch/model/parameter/Parameter.java index 3eae2ef9f..00b55a53a 100644 --- a/src/main/java/li/strolch/model/parameter/Parameter.java +++ b/src/main/java/li/strolch/model/parameter/Parameter.java @@ -17,6 +17,7 @@ package li.strolch.model.parameter; import li.strolch.model.ParameterizedElement; import li.strolch.model.StrolchElement; +import li.strolch.model.StrolchModelConstants; import li.strolch.model.visitor.ParameterVisitor; /** @@ -104,6 +105,7 @@ public interface Parameter extends StrolchElement { * * @return */ + @Override public ParameterizedElement getParent(); /** @@ -116,8 +118,8 @@ public interface Parameter extends StrolchElement { * this {@link Parameter} means. Currently there are three definitions, but any String value can be used: *
      *
    • {@link Parameter#INTERPRETATION_NONE}
    • - *
    • {@link Parameter#INTERPRETATION_ORDER_REF}
    • - *
    • {@link Parameter#INTERPRETATION_RESOURCE_REF}
    • + *
    • {@link StrolchModelConstants#INTERPRETATION_ORDER_REF}
    • + *
    • {@link StrolchModelConstants#INTERPRETATION_RESOURCE_REF}
    • *
    * * @return string value @@ -129,8 +131,8 @@ public interface Parameter extends StrolchElement { * {@link Parameter} means. Currently there are three definitions, but any String value can be used: *
      *
    • {@link Parameter#INTERPRETATION_NONE}
    • - *
    • {@link Parameter#INTERPRETATION_ORDER_REF}
    • - *
    • {@link Parameter#INTERPRETATION_RESOURCE_REF}
    • + *
    • {@link StrolchModelConstants#INTERPRETATION_ORDER_REF}
    • + *
    • {@link StrolchModelConstants#INTERPRETATION_RESOURCE_REF}
    • *
    * * @param interpretation diff --git a/src/main/java/li/strolch/model/query/ParameterSelection.java b/src/main/java/li/strolch/model/query/ParameterSelection.java index f326ee62a..9829d51b9 100644 --- a/src/main/java/li/strolch/model/query/ParameterSelection.java +++ b/src/main/java/li/strolch/model/query/ParameterSelection.java @@ -57,6 +57,7 @@ public abstract class ParameterSelection implements Selection { accept((ParameterSelectionVisitor) visitor); } + @SuppressWarnings("nls") @Override public String toString() { StringBuilder builder = new StringBuilder(); @@ -243,7 +244,7 @@ public abstract class ParameterSelection implements Selection { public DateRangeParameterSelection(String bagKey, String paramKey, Date from, Date to) { super(bagKey, paramKey); - DBC.PRE.assertFalse("Either 'to' or 'from' must be set! Both can not be null!", from == null && to == null); + DBC.PRE.assertFalse("Either 'to' or 'from' must be set! Both can not be null!", from == null && to == null); //$NON-NLS-1$ this.from = from; this.to = to; } diff --git a/src/main/java/li/strolch/model/query/StrolchQuery.java b/src/main/java/li/strolch/model/query/StrolchQuery.java index daba941ed..ec0977d38 100644 --- a/src/main/java/li/strolch/model/query/StrolchQuery.java +++ b/src/main/java/li/strolch/model/query/StrolchQuery.java @@ -28,43 +28,55 @@ public abstract class StrolchQuery { public StrolchQuery(Navigation navigation) { this.navigation = navigation; } - + public boolean hasNavigation() { - return navigation != null; - } - - public boolean hasSelection() { - return selection != null && selection.hasSelection(); + return this.navigation != null; } - public void select(Selection selection) { - DBC.PRE.assertNull("A selection is already set! Use a boolean operator to perform multiple selections", + public boolean hasSelection() { + return this.selection != null && this.selection.hasSelection(); + } + + public Selection getSelection() { + return this.selection; + } + + public void with(Selection selection) { + DBC.PRE.assertNull("A selection is already set! Use a boolean operator to perform multiple selections", //$NON-NLS-1$ this.selection); this.selection = selection; } + /** + * @deprecated use {@link #with(Selection)} instead + */ + @Deprecated + public void select(Selection selection) { + with(selection); + } + public AndSelection and() { - DBC.PRE.assertNull("A selection is already set! Create hierarchical boolean selections", this.selection); + DBC.PRE.assertNull("A selection is already set! Create hierarchical boolean selections", this.selection); //$NON-NLS-1$ AndSelection and = new AndSelection(); this.selection = and; return and; } public OrSelection or() { - DBC.PRE.assertNull("A selection is already set! Create hierarchical boolean selections", this.selection); + DBC.PRE.assertNull("A selection is already set! Create hierarchical boolean selections", this.selection); //$NON-NLS-1$ OrSelection or = new OrSelection(); this.selection = or; return or; } public void not(Selection selection) { - DBC.PRE.assertNull("A selection is already set! Create hierarchical boolean selections", this.selection); + DBC.PRE.assertNull("A selection is already set! Create hierarchical boolean selections", this.selection); //$NON-NLS-1$ this.selection = new NotSelection(selection); } public void accept(T visitor) { - DBC.PRE.assertNotNull("No navigation set!", this.navigation); - DBC.PRE.assertNotNull("No selection defined!", this.selection); + DBC.PRE.assertNotNull("No navigation set!", this.navigation); //$NON-NLS-1$ + DBC.PRE.assertNotNull("No selection defined!", this.selection); //$NON-NLS-1$ this.navigation.accept(visitor); this.selection.accept(visitor); } From 64afcb02a6a3fbb3b7a899345dd44f19a106fb7c Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 4 Aug 2014 15:10:19 +0200 Subject: [PATCH 69/88] [New] Implemented NameSelection.contains() and caseInsensitive() --- .../li/strolch/model/query/NameSelection.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/li/strolch/model/query/NameSelection.java b/src/main/java/li/strolch/model/query/NameSelection.java index eb9d0cf66..9009655a7 100644 --- a/src/main/java/li/strolch/model/query/NameSelection.java +++ b/src/main/java/li/strolch/model/query/NameSelection.java @@ -21,6 +21,8 @@ package li.strolch.model.query; public class NameSelection extends StrolchElementSelection { private String name; + private boolean contains; + private boolean caseInsensitive; /** * @param name @@ -36,6 +38,24 @@ public class NameSelection extends StrolchElementSelection { return this.name; } + public boolean isContains() { + return this.contains; + } + + public boolean isCaseInsensitive() { + return this.caseInsensitive; + } + + public NameSelection contains(boolean contains) { + this.contains = contains; + return this; + } + + public NameSelection caseInsensitive(boolean caseInsensitive) { + this.caseInsensitive = true; + return this; + } + @Override public void accept(StrolchElementSelectionVisitor visitor) { visitor.visit(this); From 1ceedfc81827b73ad02e24abf6e211ff8e02b9f5 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 6 Aug 2014 12:46:31 +0200 Subject: [PATCH 70/88] [Major] refactored StrolchElementVisitor to return value Now instead of having visitors implement their own getters, the return type is defined as a template on the concrete implementation. To return nothing simply use the type Void and return null. --- src/main/java/li/strolch/model/OrderVisitor.java | 4 ++-- src/main/java/li/strolch/model/ResourceVisitor.java | 5 +++-- .../li/strolch/model/visitor/OrderDeepEqualsVisitor.java | 8 ++++++-- .../strolch/model/visitor/ResourceDeepEqualsVisitor.java | 9 +++++++-- .../li/strolch/model/visitor/StrolchElementVisitor.java | 4 ++-- .../java/li/strolch/model/xml/OrderToDomVisitor.java | 5 +++-- .../java/li/strolch/model/xml/OrderToSaxVisitor.java | 6 ++++-- .../li/strolch/model/xml/OrderToSaxWriterVisitor.java | 6 ++++-- .../java/li/strolch/model/xml/ResourceToDomVisitor.java | 5 +++-- .../java/li/strolch/model/xml/ResourceToSaxVisitor.java | 6 ++++-- .../li/strolch/model/xml/ResourceToSaxWriterVisitor.java | 6 ++++-- 11 files changed, 42 insertions(+), 22 deletions(-) diff --git a/src/main/java/li/strolch/model/OrderVisitor.java b/src/main/java/li/strolch/model/OrderVisitor.java index 2d3874c50..efcaf0684 100644 --- a/src/main/java/li/strolch/model/OrderVisitor.java +++ b/src/main/java/li/strolch/model/OrderVisitor.java @@ -20,8 +20,8 @@ import li.strolch.model.visitor.StrolchElementVisitor; /** * @author Robert von Burg */ -public interface OrderVisitor extends StrolchElementVisitor { +public interface OrderVisitor extends StrolchElementVisitor { @Override - public void visit(Order element); + public U visit(Order element); } diff --git a/src/main/java/li/strolch/model/ResourceVisitor.java b/src/main/java/li/strolch/model/ResourceVisitor.java index 5d3816a63..67c014fc1 100644 --- a/src/main/java/li/strolch/model/ResourceVisitor.java +++ b/src/main/java/li/strolch/model/ResourceVisitor.java @@ -19,9 +19,10 @@ import li.strolch.model.visitor.StrolchElementVisitor; /** * @author Robert von Burg + * @param */ -public interface ResourceVisitor extends StrolchElementVisitor { +public interface ResourceVisitor extends StrolchElementVisitor { @Override - public void visit(Resource element); + public U visit(Resource element); } diff --git a/src/main/java/li/strolch/model/visitor/OrderDeepEqualsVisitor.java b/src/main/java/li/strolch/model/visitor/OrderDeepEqualsVisitor.java index 497c46e29..f6c727c44 100644 --- a/src/main/java/li/strolch/model/visitor/OrderDeepEqualsVisitor.java +++ b/src/main/java/li/strolch/model/visitor/OrderDeepEqualsVisitor.java @@ -15,13 +15,16 @@ */ package li.strolch.model.visitor; +import java.util.List; + +import li.strolch.model.Locator; import li.strolch.model.Order; import li.strolch.model.OrderVisitor; /** * @author Robert von Burg */ -public class OrderDeepEqualsVisitor extends StrolchElementDeepEqualsVisitor implements OrderVisitor { +public class OrderDeepEqualsVisitor extends StrolchElementDeepEqualsVisitor implements OrderVisitor> { private Order srcOrder; @@ -30,7 +33,8 @@ public class OrderDeepEqualsVisitor extends StrolchElementDeepEqualsVisitor impl } @Override - public void visit(Order dstOrder) { + public List visit(Order dstOrder) { deepEquals(this.srcOrder, dstOrder); + return getMismatchedLocators(); } } diff --git a/src/main/java/li/strolch/model/visitor/ResourceDeepEqualsVisitor.java b/src/main/java/li/strolch/model/visitor/ResourceDeepEqualsVisitor.java index d74918a6f..de4213494 100644 --- a/src/main/java/li/strolch/model/visitor/ResourceDeepEqualsVisitor.java +++ b/src/main/java/li/strolch/model/visitor/ResourceDeepEqualsVisitor.java @@ -15,13 +15,17 @@ */ package li.strolch.model.visitor; +import java.util.List; + +import li.strolch.model.Locator; import li.strolch.model.Resource; import li.strolch.model.ResourceVisitor; /** * @author Robert von Burg */ -public class ResourceDeepEqualsVisitor extends StrolchElementDeepEqualsVisitor implements ResourceVisitor { +public class ResourceDeepEqualsVisitor extends StrolchElementDeepEqualsVisitor implements + ResourceVisitor> { private Resource srcRes; @@ -30,7 +34,8 @@ public class ResourceDeepEqualsVisitor extends StrolchElementDeepEqualsVisitor i } @Override - public void visit(Resource dstRes) { + public List visit(Resource dstRes) { deepEquals(this.srcRes, dstRes); + return getMismatchedLocators(); } } diff --git a/src/main/java/li/strolch/model/visitor/StrolchElementVisitor.java b/src/main/java/li/strolch/model/visitor/StrolchElementVisitor.java index 9034a0c77..30d23ba9b 100644 --- a/src/main/java/li/strolch/model/visitor/StrolchElementVisitor.java +++ b/src/main/java/li/strolch/model/visitor/StrolchElementVisitor.java @@ -20,7 +20,7 @@ import li.strolch.model.StrolchElement; /** * @author Robert von Burg */ -public interface StrolchElementVisitor extends StrolchVisitor { +public interface StrolchElementVisitor extends StrolchVisitor { - public void visit(T element); + public U visit(T element); } diff --git a/src/main/java/li/strolch/model/xml/OrderToDomVisitor.java b/src/main/java/li/strolch/model/xml/OrderToDomVisitor.java index 941f7d616..77c9995aa 100644 --- a/src/main/java/li/strolch/model/xml/OrderToDomVisitor.java +++ b/src/main/java/li/strolch/model/xml/OrderToDomVisitor.java @@ -28,7 +28,7 @@ import ch.eitchnet.utils.helper.DomUtil; /** * @author Robert von Burg */ -public class OrderToDomVisitor implements OrderVisitor { +public class OrderToDomVisitor implements OrderVisitor { private Document document; @@ -40,12 +40,13 @@ public class OrderToDomVisitor implements OrderVisitor { } @Override - public void visit(Order order) { + public Document visit(Order order) { DocumentBuilder documentBuilder = DomUtil.createDocumentBuilder(); Document document = documentBuilder.getDOMImplementation().createDocument(null, null, null); Element orderDom = order.toDom(document); document.appendChild(orderDom); this.document = document; + return this.document; } } diff --git a/src/main/java/li/strolch/model/xml/OrderToSaxVisitor.java b/src/main/java/li/strolch/model/xml/OrderToSaxVisitor.java index 428261ebe..12ea360f1 100644 --- a/src/main/java/li/strolch/model/xml/OrderToSaxVisitor.java +++ b/src/main/java/li/strolch/model/xml/OrderToSaxVisitor.java @@ -27,14 +27,14 @@ import org.xml.sax.SAXException; /** * @author Robert von Burg */ -public class OrderToSaxVisitor extends StrolchElementToDomVisitor implements OrderVisitor { +public class OrderToSaxVisitor extends StrolchElementToDomVisitor implements OrderVisitor { public OrderToSaxVisitor(ContentHandler contentHandler) { super(contentHandler); } @Override - public void visit(Order order) { + public Void visit(Order order) { try { this.contentHandler.startElement(null, null, Tags.ORDER, attributesFor(order)); @@ -46,5 +46,7 @@ public class OrderToSaxVisitor extends StrolchElementToDomVisitor implements Ord msg = MessageFormat.format(msg, order.getLocator(), e.getMessage()); throw new RuntimeException(msg, e); } + + return null; } } diff --git a/src/main/java/li/strolch/model/xml/OrderToSaxWriterVisitor.java b/src/main/java/li/strolch/model/xml/OrderToSaxWriterVisitor.java index f3e4c7cef..dc3b16d52 100644 --- a/src/main/java/li/strolch/model/xml/OrderToSaxWriterVisitor.java +++ b/src/main/java/li/strolch/model/xml/OrderToSaxWriterVisitor.java @@ -28,14 +28,14 @@ import li.strolch.model.Tags; /** * @author Robert von Burg */ -public class OrderToSaxWriterVisitor extends AbstractToSaxWriterVisitor implements OrderVisitor { +public class OrderToSaxWriterVisitor extends AbstractToSaxWriterVisitor implements OrderVisitor { public OrderToSaxWriterVisitor(XMLStreamWriter writer) { super(writer); } @Override - public void visit(Order order) { + public Void visit(Order order) { try { writeElement(Tags.ORDER, order); this.writer.flush(); @@ -44,5 +44,7 @@ public class OrderToSaxWriterVisitor extends AbstractToSaxWriterVisitor implemen msg = MessageFormat.format(msg, order.getLocator(), e.getMessage()); throw new StrolchException(msg, e); } + + return null; } } diff --git a/src/main/java/li/strolch/model/xml/ResourceToDomVisitor.java b/src/main/java/li/strolch/model/xml/ResourceToDomVisitor.java index 8585ecddf..2942d547c 100644 --- a/src/main/java/li/strolch/model/xml/ResourceToDomVisitor.java +++ b/src/main/java/li/strolch/model/xml/ResourceToDomVisitor.java @@ -28,7 +28,7 @@ import ch.eitchnet.utils.helper.DomUtil; /** * @author Robert von Burg */ -public class ResourceToDomVisitor implements ResourceVisitor { +public class ResourceToDomVisitor implements ResourceVisitor { private Document document; @@ -40,12 +40,13 @@ public class ResourceToDomVisitor implements ResourceVisitor { } @Override - public void visit(Resource resource) { + public Document visit(Resource resource) { DocumentBuilder documentBuilder = DomUtil.createDocumentBuilder(); Document document = documentBuilder.getDOMImplementation().createDocument(null, null, null); Element resourceDom = resource.toDom(document); document.appendChild(resourceDom); this.document = document; + return this.document; } } diff --git a/src/main/java/li/strolch/model/xml/ResourceToSaxVisitor.java b/src/main/java/li/strolch/model/xml/ResourceToSaxVisitor.java index 5e10dab32..73cadf82d 100644 --- a/src/main/java/li/strolch/model/xml/ResourceToSaxVisitor.java +++ b/src/main/java/li/strolch/model/xml/ResourceToSaxVisitor.java @@ -26,14 +26,14 @@ import org.xml.sax.ContentHandler; /** * @author Robert von Burg */ -public class ResourceToSaxVisitor extends StrolchElementToDomVisitor implements ResourceVisitor { +public class ResourceToSaxVisitor extends StrolchElementToDomVisitor implements ResourceVisitor { public ResourceToSaxVisitor(ContentHandler contentHandler) { super(contentHandler); } @Override - public void visit(Resource res) { + public Void visit(Resource res) { try { this.contentHandler.startElement(null, null, Tags.RESOURCE, attributesFor(res)); @@ -45,5 +45,7 @@ public class ResourceToSaxVisitor extends StrolchElementToDomVisitor implements msg = MessageFormat.format(msg, res.getLocator(), e.getMessage()); throw new RuntimeException(msg, e); } + + return null; } } diff --git a/src/main/java/li/strolch/model/xml/ResourceToSaxWriterVisitor.java b/src/main/java/li/strolch/model/xml/ResourceToSaxWriterVisitor.java index c73f5c3f7..764984a14 100644 --- a/src/main/java/li/strolch/model/xml/ResourceToSaxWriterVisitor.java +++ b/src/main/java/li/strolch/model/xml/ResourceToSaxWriterVisitor.java @@ -28,14 +28,14 @@ import li.strolch.model.Tags; /** * @author Robert von Burg */ -public class ResourceToSaxWriterVisitor extends AbstractToSaxWriterVisitor implements ResourceVisitor { +public class ResourceToSaxWriterVisitor extends AbstractToSaxWriterVisitor implements ResourceVisitor { public ResourceToSaxWriterVisitor(XMLStreamWriter writer) { super(writer); } @Override - public void visit(Resource resource) { + public Void visit(Resource resource) { try { writeElement(Tags.RESOURCE, resource); this.writer.flush(); @@ -44,5 +44,7 @@ public class ResourceToSaxWriterVisitor extends AbstractToSaxWriterVisitor imple msg = MessageFormat.format(msg, resource.getLocator(), e.getMessage()); throw new StrolchException(msg, e); } + + return null; } } From 1f986797d483184ea189e0f036e489ecc62db9fc Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 6 Aug 2014 16:33:10 +0200 Subject: [PATCH 71/88] [New] OrderQuery and ResourceQuery now require a visitor This visitor is used to transform the query result. In cases where transformation is not required, use the NoStrategyOrderVisitor or NoStrategyResourceVisitor. For convenience new static helper methods were: ResourceQuery.resourceQuery(Navigation) ResourceQuery.resourceQuery(String) ResourceQuery.resourceQuery(String, ResourceVisitor) OrderQuery.orderQuery(Navigation) OrderQuery.orderQuery(String) OrderQuery.orderQuery(String, ResourceVisitor) --- .../li/strolch/model/query/OrderQuery.java | 62 ++++++++++++++++- .../li/strolch/model/query/ResourceQuery.java | 68 ++++++++++++++++++- .../model/query/StrolchTypeNavigation.java | 1 - .../model/visitor/NoStrategyOrderVisitor.java | 30 ++++++++ .../visitor/NoStrategyResourceVisitor.java | 30 ++++++++ .../model/visitor/NoStrategyVisitor.java | 29 ++++++++ 6 files changed, 215 insertions(+), 5 deletions(-) create mode 100644 src/main/java/li/strolch/model/visitor/NoStrategyOrderVisitor.java create mode 100644 src/main/java/li/strolch/model/visitor/NoStrategyResourceVisitor.java create mode 100644 src/main/java/li/strolch/model/visitor/NoStrategyVisitor.java diff --git a/src/main/java/li/strolch/model/query/OrderQuery.java b/src/main/java/li/strolch/model/query/OrderQuery.java index a98ca4f08..0863781e9 100644 --- a/src/main/java/li/strolch/model/query/OrderQuery.java +++ b/src/main/java/li/strolch/model/query/OrderQuery.java @@ -15,12 +15,70 @@ */ package li.strolch.model.query; +import li.strolch.model.Order; +import li.strolch.model.OrderVisitor; +import li.strolch.model.parameter.Parameter; +import li.strolch.model.visitor.NoStrategyOrderVisitor; + /** + * {@link OrderQuery} is the user API to query {@link Order Orders} in Strolch. The {@link Navigation} is used to + * navigate to a type of order on which any further {@link Selection Selections} will be performed. The + * {@link OrderVisitor} is used to transform the returned object into a domain specific object (if required). This + * mechanism allows you to query only the values of a {@link Parameter} instead of having to return all the elements and + * then performing this transformation. + * * @author Robert von Burg */ -public class OrderQuery extends StrolchQuery { +public class OrderQuery extends StrolchQuery { - public OrderQuery(Navigation navigation) { + private OrderVisitor elementVisitor; + + public OrderQuery(Navigation navigation, OrderVisitor elementVisitor) { super(navigation); + this.elementVisitor = elementVisitor; + } + + /** + * @return the elementVisitor + */ + public OrderVisitor getElementVisitor() { + return this.elementVisitor; + } + + /** + * Returns an instance of {@link OrderQuery} where the visitor used is the {@link NoStrategyOrderVisitor} thus + * returning the actual Order, i.e. no transformation is performed + * + * @param navigation + * @return + */ + public static OrderQuery orderQuery(Navigation navigation) { + return new OrderQuery(navigation, new NoStrategyOrderVisitor()); + } + + /** + * Returns an instance of {@link OrderQuery} where the visitor used is the {@link NoStrategyOrderVisitor} thus + * returning the actual Order, i.e. no transformation is performed + * + * @param type + * the type of Order to navigate to + * @return + */ + public static OrderQuery orderQuery(String type) { + return new OrderQuery(new StrolchTypeNavigation(type), new NoStrategyOrderVisitor()); + } + + /** + * Returns an instance of {@link OrderQuery} using the given {@link OrderVisitor} thus performing the given + * transformation + * + * @param type + * the type of Order to navigate to + * @param orderVisitor + * the visitor to use for transformation + * @return + */ + public static OrderQuery orderQuery(String type, OrderVisitor orderVisitor) { + return new OrderQuery(new StrolchTypeNavigation(type), orderVisitor); } } diff --git a/src/main/java/li/strolch/model/query/ResourceQuery.java b/src/main/java/li/strolch/model/query/ResourceQuery.java index fbde73be5..5176fe08c 100644 --- a/src/main/java/li/strolch/model/query/ResourceQuery.java +++ b/src/main/java/li/strolch/model/query/ResourceQuery.java @@ -15,12 +15,76 @@ */ package li.strolch.model.query; +import li.strolch.model.Resource; +import li.strolch.model.ResourceVisitor; +import li.strolch.model.parameter.Parameter; +import li.strolch.model.visitor.NoStrategyResourceVisitor; + /** + * {@link ResourceQuery} is the user API to query {@link Resource Resources} in Strolch. The {@link Navigation} is used + * to navigate to a type of resource on which any further {@link Selection Selections} will be performed. The + * {@link ResourceVisitor} is used to transform the returned object into a domain specific object (if required). This + * mechanism allows you to query only the values of a {@link Parameter} instead of having to return all the elements and + * then performing this transformation. + * * @author Robert von Burg */ -public class ResourceQuery extends StrolchQuery { +public class ResourceQuery extends StrolchQuery { - public ResourceQuery(Navigation navigation) { + private ResourceVisitor elementVisitor; + + /** + * Create a new + * + * @param navigation + * @param elementVisitor + */ + public ResourceQuery(Navigation navigation, ResourceVisitor elementVisitor) { super(navigation); + this.elementVisitor = elementVisitor; + } + + /** + * @return the elementVisitor + */ + public ResourceVisitor getElementVisitor() { + return this.elementVisitor; + } + + /** + * Returns an instance of {@link ResourceQuery} where the visitor used is the {@link NoStrategyResourceVisitor} thus + * returning the actual Resource, i.e. no transformation is performed + * + * @param navigation + * @return + */ + public static ResourceQuery resourceQuery(Navigation navigation) { + return new ResourceQuery(navigation, new NoStrategyResourceVisitor()); + } + + /** + * Returns an instance of {@link ResourceQuery} where the visitor used is the {@link NoStrategyResourceVisitor} thus + * returning the actual Resource, i.e. no transformation is performed + * + * @param type + * the type of {@link Resource} to navigate to + * @return + */ + public static ResourceQuery resourceQuery(String type) { + return new ResourceQuery(new StrolchTypeNavigation(type), new NoStrategyResourceVisitor()); + } + + /** + * Returns an instance of {@link ResourceQuery} using the given {@link ResourceVisitor} thus performing the given + * transformation + * + * @param type + * the type of Order to navigate to + * @param resourceVisitor + * the visitor to use for transformation + * @return + */ + public static ResourceQuery resourceQuery(String type, ResourceVisitor resourceVisitor) { + return new ResourceQuery(new StrolchTypeNavigation(type), resourceVisitor); } } diff --git a/src/main/java/li/strolch/model/query/StrolchTypeNavigation.java b/src/main/java/li/strolch/model/query/StrolchTypeNavigation.java index 32b23f84a..a4f7c9fa2 100644 --- a/src/main/java/li/strolch/model/query/StrolchTypeNavigation.java +++ b/src/main/java/li/strolch/model/query/StrolchTypeNavigation.java @@ -17,7 +17,6 @@ package li.strolch.model.query; /** * @author Robert von Burg - * */ public class StrolchTypeNavigation implements Navigation { diff --git a/src/main/java/li/strolch/model/visitor/NoStrategyOrderVisitor.java b/src/main/java/li/strolch/model/visitor/NoStrategyOrderVisitor.java new file mode 100644 index 000000000..df168fb8b --- /dev/null +++ b/src/main/java/li/strolch/model/visitor/NoStrategyOrderVisitor.java @@ -0,0 +1,30 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.visitor; + +import li.strolch.model.Order; +import li.strolch.model.OrderVisitor; + +/** + * @author Robert von Burg + */ +public class NoStrategyOrderVisitor implements OrderVisitor { + + @Override + public Order visit(Order element) { + return element; + } +} diff --git a/src/main/java/li/strolch/model/visitor/NoStrategyResourceVisitor.java b/src/main/java/li/strolch/model/visitor/NoStrategyResourceVisitor.java new file mode 100644 index 000000000..d319aa7b9 --- /dev/null +++ b/src/main/java/li/strolch/model/visitor/NoStrategyResourceVisitor.java @@ -0,0 +1,30 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.visitor; + +import li.strolch.model.Resource; +import li.strolch.model.ResourceVisitor; + +/** + * @author Robert von Burg + */ +public class NoStrategyResourceVisitor implements ResourceVisitor { + + @Override + public Resource visit(Resource element) { + return element; + } +} diff --git a/src/main/java/li/strolch/model/visitor/NoStrategyVisitor.java b/src/main/java/li/strolch/model/visitor/NoStrategyVisitor.java new file mode 100644 index 000000000..050cf634a --- /dev/null +++ b/src/main/java/li/strolch/model/visitor/NoStrategyVisitor.java @@ -0,0 +1,29 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.visitor; + +import li.strolch.model.StrolchElement; + +/** + * @author Robert von Burg + */ +public class NoStrategyVisitor implements StrolchElementVisitor { + + @Override + public T visit(T element) { + return element; + } +} From e1dbb00ab7e4dd3f92807f984a2556ad52c7dec5 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 6 Aug 2014 16:35:41 +0200 Subject: [PATCH 72/88] [Major] renamed methods --- src/main/java/li/strolch/model/query/OrderQuery.java | 6 +++--- src/main/java/li/strolch/model/query/ResourceQuery.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/li/strolch/model/query/OrderQuery.java b/src/main/java/li/strolch/model/query/OrderQuery.java index 0863781e9..dac4c0d9f 100644 --- a/src/main/java/li/strolch/model/query/OrderQuery.java +++ b/src/main/java/li/strolch/model/query/OrderQuery.java @@ -52,7 +52,7 @@ public class OrderQuery extends StrolchQuery { * @param navigation * @return */ - public static OrderQuery orderQuery(Navigation navigation) { + public static OrderQuery query(Navigation navigation) { return new OrderQuery(navigation, new NoStrategyOrderVisitor()); } @@ -64,7 +64,7 @@ public class OrderQuery extends StrolchQuery { * the type of Order to navigate to * @return */ - public static OrderQuery orderQuery(String type) { + public static OrderQuery query(String type) { return new OrderQuery(new StrolchTypeNavigation(type), new NoStrategyOrderVisitor()); } @@ -78,7 +78,7 @@ public class OrderQuery extends StrolchQuery { * the visitor to use for transformation * @return */ - public static OrderQuery orderQuery(String type, OrderVisitor orderVisitor) { + public static OrderQuery query(String type, OrderVisitor orderVisitor) { return new OrderQuery(new StrolchTypeNavigation(type), orderVisitor); } } diff --git a/src/main/java/li/strolch/model/query/ResourceQuery.java b/src/main/java/li/strolch/model/query/ResourceQuery.java index 5176fe08c..6133b7c5b 100644 --- a/src/main/java/li/strolch/model/query/ResourceQuery.java +++ b/src/main/java/li/strolch/model/query/ResourceQuery.java @@ -58,7 +58,7 @@ public class ResourceQuery extends StrolchQuery { * @param navigation * @return */ - public static ResourceQuery resourceQuery(Navigation navigation) { + public static ResourceQuery query(Navigation navigation) { return new ResourceQuery(navigation, new NoStrategyResourceVisitor()); } @@ -70,7 +70,7 @@ public class ResourceQuery extends StrolchQuery { * the type of {@link Resource} to navigate to * @return */ - public static ResourceQuery resourceQuery(String type) { + public static ResourceQuery query(String type) { return new ResourceQuery(new StrolchTypeNavigation(type), new NoStrategyResourceVisitor()); } @@ -84,7 +84,7 @@ public class ResourceQuery extends StrolchQuery { * the visitor to use for transformation * @return */ - public static ResourceQuery resourceQuery(String type, ResourceVisitor resourceVisitor) { + public static ResourceQuery query(String type, ResourceVisitor resourceVisitor) { return new ResourceQuery(new StrolchTypeNavigation(type), resourceVisitor); } } From 41f0e72cc5f19e6ad7950661b690e84df045dee9 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 6 Aug 2014 18:42:44 +0200 Subject: [PATCH 73/88] [New] Moved *Visitor transformations in query into query method This is better than keeping the Visitor in the instance of the query, where it might be to early to instantiate it. --- .../li/strolch/model/query/OrderQuery.java | 52 +++--------------- .../li/strolch/model/query/ResourceQuery.java | 54 +++---------------- 2 files changed, 12 insertions(+), 94 deletions(-) diff --git a/src/main/java/li/strolch/model/query/OrderQuery.java b/src/main/java/li/strolch/model/query/OrderQuery.java index dac4c0d9f..0a5c1b63e 100644 --- a/src/main/java/li/strolch/model/query/OrderQuery.java +++ b/src/main/java/li/strolch/model/query/OrderQuery.java @@ -18,7 +18,6 @@ package li.strolch.model.query; import li.strolch.model.Order; import li.strolch.model.OrderVisitor; import li.strolch.model.parameter.Parameter; -import li.strolch.model.visitor.NoStrategyOrderVisitor; /** * {@link OrderQuery} is the user API to query {@link Order Orders} in Strolch. The {@link Navigation} is used to @@ -29,56 +28,17 @@ import li.strolch.model.visitor.NoStrategyOrderVisitor; * * @author Robert von Burg */ -public class OrderQuery extends StrolchQuery { +public class OrderQuery extends StrolchQuery { - private OrderVisitor elementVisitor; - - public OrderQuery(Navigation navigation, OrderVisitor elementVisitor) { + public OrderQuery(Navigation navigation) { super(navigation); - this.elementVisitor = elementVisitor; } - /** - * @return the elementVisitor - */ - public OrderVisitor getElementVisitor() { - return this.elementVisitor; + public static OrderQuery query(Navigation navigation) { + return new OrderQuery(navigation); } - /** - * Returns an instance of {@link OrderQuery} where the visitor used is the {@link NoStrategyOrderVisitor} thus - * returning the actual Order, i.e. no transformation is performed - * - * @param navigation - * @return - */ - public static OrderQuery query(Navigation navigation) { - return new OrderQuery(navigation, new NoStrategyOrderVisitor()); - } - - /** - * Returns an instance of {@link OrderQuery} where the visitor used is the {@link NoStrategyOrderVisitor} thus - * returning the actual Order, i.e. no transformation is performed - * - * @param type - * the type of Order to navigate to - * @return - */ - public static OrderQuery query(String type) { - return new OrderQuery(new StrolchTypeNavigation(type), new NoStrategyOrderVisitor()); - } - - /** - * Returns an instance of {@link OrderQuery} using the given {@link OrderVisitor} thus performing the given - * transformation - * - * @param type - * the type of Order to navigate to - * @param orderVisitor - * the visitor to use for transformation - * @return - */ - public static OrderQuery query(String type, OrderVisitor orderVisitor) { - return new OrderQuery(new StrolchTypeNavigation(type), orderVisitor); + public static OrderQuery query(String type) { + return new OrderQuery(new StrolchTypeNavigation(type)); } } diff --git a/src/main/java/li/strolch/model/query/ResourceQuery.java b/src/main/java/li/strolch/model/query/ResourceQuery.java index 6133b7c5b..7741c041b 100644 --- a/src/main/java/li/strolch/model/query/ResourceQuery.java +++ b/src/main/java/li/strolch/model/query/ResourceQuery.java @@ -18,7 +18,6 @@ package li.strolch.model.query; import li.strolch.model.Resource; import li.strolch.model.ResourceVisitor; import li.strolch.model.parameter.Parameter; -import li.strolch.model.visitor.NoStrategyResourceVisitor; /** * {@link ResourceQuery} is the user API to query {@link Resource Resources} in Strolch. The {@link Navigation} is used @@ -29,62 +28,21 @@ import li.strolch.model.visitor.NoStrategyResourceVisitor; * * @author Robert von Burg */ -public class ResourceQuery extends StrolchQuery { - - private ResourceVisitor elementVisitor; +public class ResourceQuery extends StrolchQuery { /** - * Create a new - * * @param navigation * @param elementVisitor */ - public ResourceQuery(Navigation navigation, ResourceVisitor elementVisitor) { + public ResourceQuery(Navigation navigation) { super(navigation); - this.elementVisitor = elementVisitor; } - /** - * @return the elementVisitor - */ - public ResourceVisitor getElementVisitor() { - return this.elementVisitor; + public static ResourceQuery query(Navigation navigation) { + return new ResourceQuery(navigation); } - /** - * Returns an instance of {@link ResourceQuery} where the visitor used is the {@link NoStrategyResourceVisitor} thus - * returning the actual Resource, i.e. no transformation is performed - * - * @param navigation - * @return - */ - public static ResourceQuery query(Navigation navigation) { - return new ResourceQuery(navigation, new NoStrategyResourceVisitor()); - } - - /** - * Returns an instance of {@link ResourceQuery} where the visitor used is the {@link NoStrategyResourceVisitor} thus - * returning the actual Resource, i.e. no transformation is performed - * - * @param type - * the type of {@link Resource} to navigate to - * @return - */ - public static ResourceQuery query(String type) { - return new ResourceQuery(new StrolchTypeNavigation(type), new NoStrategyResourceVisitor()); - } - - /** - * Returns an instance of {@link ResourceQuery} using the given {@link ResourceVisitor} thus performing the given - * transformation - * - * @param type - * the type of Order to navigate to - * @param resourceVisitor - * the visitor to use for transformation - * @return - */ - public static ResourceQuery query(String type, ResourceVisitor resourceVisitor) { - return new ResourceQuery(new StrolchTypeNavigation(type), resourceVisitor); + public static ResourceQuery query(String type) { + return new ResourceQuery(new StrolchTypeNavigation(type)); } } From 5e062f06301cc56cdccf4c89a1f037e4b1c8bec4 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 7 Aug 2014 01:00:25 +0200 Subject: [PATCH 74/88] [New] Implemented AnySelection --- .../li/strolch/model/query/AnySelection.java | 32 +++++++++++++++++++ .../li/strolch/model/query/OrderQuery.java | 18 +++++++++++ .../li/strolch/model/query/QueryVisitor.java | 2 ++ .../li/strolch/model/query/ResourceQuery.java | 18 +++++++++++ .../li/strolch/model/query/StrolchQuery.java | 30 +++++++++-------- 5 files changed, 87 insertions(+), 13 deletions(-) create mode 100644 src/main/java/li/strolch/model/query/AnySelection.java diff --git a/src/main/java/li/strolch/model/query/AnySelection.java b/src/main/java/li/strolch/model/query/AnySelection.java new file mode 100644 index 000000000..79762b54c --- /dev/null +++ b/src/main/java/li/strolch/model/query/AnySelection.java @@ -0,0 +1,32 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.query; + +/** + * @author Robert von Burg + */ +public class AnySelection implements Selection { + + @Override + public void accept(QueryVisitor visitor) { + visitor.visitAny(); + } + + @Override + public boolean hasSelection() { + return true; + } +} diff --git a/src/main/java/li/strolch/model/query/OrderQuery.java b/src/main/java/li/strolch/model/query/OrderQuery.java index 0a5c1b63e..68ff20094 100644 --- a/src/main/java/li/strolch/model/query/OrderQuery.java +++ b/src/main/java/li/strolch/model/query/OrderQuery.java @@ -34,6 +34,24 @@ public class OrderQuery extends StrolchQuery { super(navigation); } + @Override + public OrderQuery with(Selection selection) { + super.with(selection); + return this; + } + + @Override + public OrderQuery not(Selection selection) { + super.not(selection); + return this; + } + + @Override + public OrderQuery withAny() { + super.withAny(); + return this; + } + public static OrderQuery query(Navigation navigation) { return new OrderQuery(navigation); } diff --git a/src/main/java/li/strolch/model/query/QueryVisitor.java b/src/main/java/li/strolch/model/query/QueryVisitor.java index e14ccc566..3c92a0109 100644 --- a/src/main/java/li/strolch/model/query/QueryVisitor.java +++ b/src/main/java/li/strolch/model/query/QueryVisitor.java @@ -20,6 +20,8 @@ package li.strolch.model.query; */ public interface QueryVisitor { + public void visitAny(); + public void visitAnd(AndSelection andSelection); public void visitOr(OrSelection orSelection); diff --git a/src/main/java/li/strolch/model/query/ResourceQuery.java b/src/main/java/li/strolch/model/query/ResourceQuery.java index 7741c041b..dafe44eab 100644 --- a/src/main/java/li/strolch/model/query/ResourceQuery.java +++ b/src/main/java/li/strolch/model/query/ResourceQuery.java @@ -38,6 +38,24 @@ public class ResourceQuery extends StrolchQuery { super(navigation); } + @Override + public ResourceQuery with(Selection selection) { + super.with(selection); + return this; + } + + @Override + public ResourceQuery not(Selection selection) { + super.not(selection); + return this; + } + + @Override + public ResourceQuery withAny() { + super.withAny(); + return this; + } + public static ResourceQuery query(Navigation navigation) { return new ResourceQuery(navigation); } diff --git a/src/main/java/li/strolch/model/query/StrolchQuery.java b/src/main/java/li/strolch/model/query/StrolchQuery.java index ec0977d38..640c04f4d 100644 --- a/src/main/java/li/strolch/model/query/StrolchQuery.java +++ b/src/main/java/li/strolch/model/query/StrolchQuery.java @@ -41,37 +41,41 @@ public abstract class StrolchQuery { return this.selection; } - public void with(Selection selection) { - DBC.PRE.assertNull("A selection is already set! Use a boolean operator to perform multiple selections", //$NON-NLS-1$ - this.selection); + public StrolchQuery with(Selection selection) { + assertNoSelectionYetSet(); this.selection = selection; + return this; } - /** - * @deprecated use {@link #with(Selection)} instead - */ - @Deprecated - public void select(Selection selection) { - with(selection); + private void assertNoSelectionYetSet() { + String msg = "A selection is already set! Use a cascaded boolean operators to perform multiple selections"; //$NON-NLS-1$ + DBC.PRE.assertNull(msg, this.selection); + } + + public StrolchQuery withAny() { + assertNoSelectionYetSet(); + this.selection = new AnySelection(); + return this; } public AndSelection and() { - DBC.PRE.assertNull("A selection is already set! Create hierarchical boolean selections", this.selection); //$NON-NLS-1$ + assertNoSelectionYetSet(); AndSelection and = new AndSelection(); this.selection = and; return and; } public OrSelection or() { - DBC.PRE.assertNull("A selection is already set! Create hierarchical boolean selections", this.selection); //$NON-NLS-1$ + assertNoSelectionYetSet(); OrSelection or = new OrSelection(); this.selection = or; return or; } - public void not(Selection selection) { - DBC.PRE.assertNull("A selection is already set! Create hierarchical boolean selections", this.selection); //$NON-NLS-1$ + public StrolchQuery not(Selection selection) { + assertNoSelectionYetSet(); this.selection = new NotSelection(selection); + return this; } public void accept(T visitor) { From 208f8f0ec9aa2d93c3695f3c3307056121991bfb Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 13 Aug 2014 23:37:47 +0200 Subject: [PATCH 75/88] [Project] added resource filtering for componentVersion.properties --- pom.xml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pom.xml b/pom.xml index 4ad96cef0..381ccd4bf 100644 --- a/pom.xml +++ b/pom.xml @@ -35,6 +35,15 @@
    + + + src/main/resources + true + + **/componentVersion.properties + + + org.codehaus.mojo From 647de2b3926c2cd2bf061f462ebb86c9651ee440 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sun, 17 Aug 2014 14:09:29 +0200 Subject: [PATCH 76/88] [Minor] renamed StrolchElementToDomVisitor to StrolchElementToSaxVisitor --- src/main/java/li/strolch/model/xml/OrderToSaxVisitor.java | 2 +- src/main/java/li/strolch/model/xml/ResourceToSaxVisitor.java | 2 +- ...ementToDomVisitor.java => StrolchElementToSaxVisitor.java} | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) rename src/main/java/li/strolch/model/xml/{StrolchElementToDomVisitor.java => StrolchElementToSaxVisitor.java} (96%) diff --git a/src/main/java/li/strolch/model/xml/OrderToSaxVisitor.java b/src/main/java/li/strolch/model/xml/OrderToSaxVisitor.java index 12ea360f1..7911c16d8 100644 --- a/src/main/java/li/strolch/model/xml/OrderToSaxVisitor.java +++ b/src/main/java/li/strolch/model/xml/OrderToSaxVisitor.java @@ -27,7 +27,7 @@ import org.xml.sax.SAXException; /** * @author Robert von Burg */ -public class OrderToSaxVisitor extends StrolchElementToDomVisitor implements OrderVisitor { +public class OrderToSaxVisitor extends StrolchElementToSaxVisitor implements OrderVisitor { public OrderToSaxVisitor(ContentHandler contentHandler) { super(contentHandler); diff --git a/src/main/java/li/strolch/model/xml/ResourceToSaxVisitor.java b/src/main/java/li/strolch/model/xml/ResourceToSaxVisitor.java index 73cadf82d..676ce6a68 100644 --- a/src/main/java/li/strolch/model/xml/ResourceToSaxVisitor.java +++ b/src/main/java/li/strolch/model/xml/ResourceToSaxVisitor.java @@ -26,7 +26,7 @@ import org.xml.sax.ContentHandler; /** * @author Robert von Burg */ -public class ResourceToSaxVisitor extends StrolchElementToDomVisitor implements ResourceVisitor { +public class ResourceToSaxVisitor extends StrolchElementToSaxVisitor implements ResourceVisitor { public ResourceToSaxVisitor(ContentHandler contentHandler) { super(contentHandler); diff --git a/src/main/java/li/strolch/model/xml/StrolchElementToDomVisitor.java b/src/main/java/li/strolch/model/xml/StrolchElementToSaxVisitor.java similarity index 96% rename from src/main/java/li/strolch/model/xml/StrolchElementToDomVisitor.java rename to src/main/java/li/strolch/model/xml/StrolchElementToSaxVisitor.java index b26ecbe57..f777ce169 100644 --- a/src/main/java/li/strolch/model/xml/StrolchElementToDomVisitor.java +++ b/src/main/java/li/strolch/model/xml/StrolchElementToSaxVisitor.java @@ -33,11 +33,11 @@ import ch.eitchnet.utils.iso8601.ISO8601FormatFactory; /** * @author Robert von Burg */ -public abstract class StrolchElementToDomVisitor { +public abstract class StrolchElementToSaxVisitor { protected ContentHandler contentHandler; - protected StrolchElementToDomVisitor(ContentHandler contentHandler) { + protected StrolchElementToSaxVisitor(ContentHandler contentHandler) { this.contentHandler = contentHandler; } From 453b6b5bcbebadc38d556b8b51e58f7b8b900a43 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 21 Aug 2014 17:42:10 +0200 Subject: [PATCH 77/88] [Major] added missing parsing of StrolchTimedState and fixed locators Locators are now a bit different, to handle finding StrolchTimedState as well, the Locator has the form: Resource///State/ Resource///Bag// --- src/main/java/li/strolch/model/Locator.java | 76 +++++++--- .../java/li/strolch/model/ParameterBag.java | 9 ++ .../strolch/model/ParameterizedElement.java | 8 +- src/main/java/li/strolch/model/Resource.java | 25 +-- .../strolch/model/StrolchModelConstants.java | 11 ++ src/main/java/li/strolch/model/Tags.java | 1 + .../model/parameter/AbstractParameter.java | 21 ++- .../li/strolch/model/parameter/Parameter.java | 41 ++--- .../timedstate/AbstractStrolchTimedState.java | 142 +++++++++++++++++- .../model/timedstate/StrolchTimedState.java | 74 +++++++++ .../li/strolch/model/timevalue/IValue.java | 5 + .../strolch/model/timevalue/impl/AString.java | 6 + .../model/timevalue/impl/BooleanValue.java | 5 + .../model/timevalue/impl/FloatValue.java | 5 + .../model/timevalue/impl/IntegerValue.java | 5 + .../model/timevalue/impl/StringSetValue.java | 30 +++- .../StrolchElementDeepEqualsVisitor.java | 7 +- .../model/visitor/TimedStateVisitor.java | 39 +++++ .../model/xml/AbstractToSaxWriterVisitor.java | 118 ++++++++++----- .../model/xml/StrolchElementToSaxVisitor.java | 7 +- .../strolch/model/xml/XmlModelSaxReader.java | 77 ++++++++++ src/test/java/li/strolch/model/ModelTest.java | 124 +++++++++++---- 22 files changed, 685 insertions(+), 151 deletions(-) create mode 100644 src/main/java/li/strolch/model/visitor/TimedStateVisitor.java diff --git a/src/main/java/li/strolch/model/Locator.java b/src/main/java/li/strolch/model/Locator.java index 186bc6c0f..0dd9f093c 100644 --- a/src/main/java/li/strolch/model/Locator.java +++ b/src/main/java/li/strolch/model/Locator.java @@ -57,9 +57,11 @@ public class Locator { /** * Constructs a new {@link Locator} with the given list of path elements * - * @param pathElements the elements making up the {@link Locator} + * @param pathElements + * the elements making up the {@link Locator} * - * @throws StrolchException if the path is invalid, meaning has less than two elements in it + * @throws StrolchException + * if the path is invalid, meaning has less than two elements in it */ public Locator(List pathElements) throws StrolchException { if (pathElements == null || pathElements.isEmpty()) { @@ -68,12 +70,27 @@ public class Locator { this.pathElements = Collections.unmodifiableList(new ArrayList(pathElements)); } + /** + * Constructs a new {@link Locator} using the given path parts + * + * @param path + * the path to parse for instantiate this {@link Locator} with elements + * + * @throws StrolchException + * if the path is invalid, meaning has less than two elements in it + */ + public Locator(String... path) throws StrolchException { + this.pathElements = Collections.unmodifiableList(Arrays.asList(path)); + } + /** * Constructs a new {@link Locator} by parsing the given string path. * - * @param path the path to parse for instantiate this {@link Locator} with elements + * @param path + * the path to parse for instantiate this {@link Locator} with elements * - * @throws StrolchException if the path is invalid, meaning has less than two elements in it + * @throws StrolchException + * if the path is invalid, meaning has less than two elements in it */ public Locator(String path) throws StrolchException { this.pathElements = Collections.unmodifiableList(parsePath(path)); @@ -82,8 +99,10 @@ public class Locator { /** * Internal constructor to append a sub path to a constructor * - * @param path the base path of the locator - * @param subPath the additional path + * @param path + * the base path of the locator + * @param subPath + * the additional path */ private Locator(List path, List subPath) { List fullPath = new ArrayList(); @@ -95,8 +114,10 @@ public class Locator { /** * Internal constructor to append a element to a constructor * - * @param path the base path of the locator - * @param element the additional element + * @param path + * the base path of the locator + * @param element + * the additional element */ private Locator(List path, String element) { List fullPath = new ArrayList(); @@ -126,7 +147,8 @@ public class Locator { /** * Returns a new {@link Locator} where the given sub path is appended to the locator * - * @param subPathElements the sub path to append + * @param subPathElements + * the sub path to append * * @return the new locator */ @@ -137,7 +159,8 @@ public class Locator { /** * Returns a new {@link Locator} where the given element is appended to the locator * - * @param element the element to append + * @param element + * the element to append * * @return the new locator */ @@ -157,12 +180,13 @@ public class Locator { /** * Parses the given path to a {@link List} of path elements by splitting the string with the {@link #PATH_SEPARATOR} * - * @param path the path to parse + * @param path + * the path to parse * * @return the list of path elements for the list * - * @throws StrolchException if the path is empty, or does not contain at least 2 elements separated by - * {@link #PATH_SEPARATOR} + * @throws StrolchException + * if the path is empty, or does not contain at least 2 elements separated by {@link #PATH_SEPARATOR} */ private List parsePath(String path) throws StrolchException { if (StringHelper.isEmpty(path)) { @@ -175,11 +199,13 @@ public class Locator { /** * Formats the given list of path elements to a String representation of the {@link Locator} * - * @param pathElements the locator elements + * @param pathElements + * the locator elements * * @return a string representation of the path elements * - * @throws StrolchException if the path elements does not contain at least two items + * @throws StrolchException + * if the path elements does not contain at least two items */ private String formatPath(List pathElements) throws StrolchException { StringBuilder sb = new StringBuilder(); @@ -229,17 +255,30 @@ public class Locator { /** * Instantiates a new immutable {@link Locator} instance from the given string * - * @param locatorPath the path from which to instantiate the locator + * @param locatorPath + * the path from which to instantiate the locator * @return the immutable {@link Locator} instance */ public static Locator valueOf(String locatorPath) { return new Locator(locatorPath); } + /** + * Instantiates a new immutable {@link Locator} instance from the given path parts + * + * @param path + * the path from which to instantiate the locator + * @return the immutable {@link Locator} instance + */ + public static Locator valueOf(String... path) { + return new Locator(path); + } + /** * Creates a new {@link LocatorBuilder} instance and appends the given root element tag to it * - * @param rootElement the first element on the {@link Locator} + * @param rootElement + * the first element on the {@link Locator} * * @return a new {@link LocatorBuilder} instance with the given root element tag as the first element */ @@ -267,7 +306,8 @@ public class Locator { /** * Append an element to the path * - * @param element the element to add + * @param element + * the element to add * * @return this instance for chaining */ diff --git a/src/main/java/li/strolch/model/ParameterBag.java b/src/main/java/li/strolch/model/ParameterBag.java index bd3fca218..2baff9fda 100644 --- a/src/main/java/li/strolch/model/ParameterBag.java +++ b/src/main/java/li/strolch/model/ParameterBag.java @@ -15,6 +15,8 @@ */ package li.strolch.model; +import li.strolch.model.Locator.LocatorBuilder; + import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -59,6 +61,13 @@ public class ParameterBag extends ParameterizedElement { return clone; } + @Override + public void fillLocator(LocatorBuilder lb) { + this.parent.fillLocator(lb); + lb.append(Tags.BAG); + lb.append(this.id); + } + @Override public Element toDom(Document doc) { diff --git a/src/main/java/li/strolch/model/ParameterizedElement.java b/src/main/java/li/strolch/model/ParameterizedElement.java index 6a8e2b9cd..b73655b6c 100644 --- a/src/main/java/li/strolch/model/ParameterizedElement.java +++ b/src/main/java/li/strolch/model/ParameterizedElement.java @@ -15,8 +15,6 @@ */ package li.strolch.model; -import ch.eitchnet.utils.dbc.DBC; - import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collections; @@ -40,6 +38,7 @@ import li.strolch.model.parameter.StringParameter; import org.w3c.dom.Element; import org.w3c.dom.NodeList; +import ch.eitchnet.utils.dbc.DBC; import ch.eitchnet.utils.helper.StringHelper; /** @@ -194,10 +193,7 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { } @Override - public void fillLocator(LocatorBuilder lb) { - this.parent.fillLocator(lb); - lb.append(this.id); - } + public abstract void fillLocator(LocatorBuilder lb); @Override public Locator getLocator() { diff --git a/src/main/java/li/strolch/model/Resource.java b/src/main/java/li/strolch/model/Resource.java index 54a3bd5dd..2860e06df 100644 --- a/src/main/java/li/strolch/model/Resource.java +++ b/src/main/java/li/strolch/model/Resource.java @@ -15,7 +15,6 @@ */ package li.strolch.model; -import ch.eitchnet.utils.dbc.DBC; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collections; @@ -24,6 +23,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; + import li.strolch.exception.StrolchException; import li.strolch.model.Locator.LocatorBuilder; import li.strolch.model.timedstate.BooleanTimedState; @@ -31,11 +31,15 @@ import li.strolch.model.timedstate.FloatTimedState; import li.strolch.model.timedstate.IntegerTimedState; import li.strolch.model.timedstate.StringSetTimedState; import li.strolch.model.timedstate.StrolchTimedState; +import li.strolch.model.timevalue.IValue; import li.strolch.model.visitor.StrolchRootElementVisitor; + import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; +import ch.eitchnet.utils.dbc.DBC; + /** * @author Robert von Burg */ @@ -43,7 +47,7 @@ public class Resource extends GroupedParameterizedElement implements StrolchRoot private static final long serialVersionUID = 0L; - private Map> timedStateMap; + private Map>> timedStateMap; /** * Empty constructor @@ -79,16 +83,16 @@ public class Resource extends GroupedParameterizedElement implements StrolchRoot DBC.PRE.assertNotEmpty("Type must be set on TimedState for resource with id " + id, typeS); if (typeS.equals(FloatTimedState.TYPE)) { - StrolchTimedState timedState = new FloatTimedState(timedStateElem); + FloatTimedState timedState = new FloatTimedState(timedStateElem); addTimedState(timedState); } else if (typeS.equals(IntegerTimedState.TYPE)) { - StrolchTimedState timedState = new IntegerTimedState(timedStateElem); + IntegerTimedState timedState = new IntegerTimedState(timedStateElem); addTimedState(timedState); } else if (typeS.equals(BooleanTimedState.TYPE)) { - StrolchTimedState timedState = new BooleanTimedState(timedStateElem); + BooleanTimedState timedState = new BooleanTimedState(timedStateElem); addTimedState(timedState); } else if (typeS.equals(StringSetTimedState.TYPE)) { - StrolchTimedState timedState = new StringSetTimedState(timedStateElem); + StringSetTimedState timedState = new StringSetTimedState(timedStateElem); addTimedState(timedState); } else { String msg = "What kind of TimedState is this: {0}"; //$NON-NLS-1$ @@ -98,16 +102,17 @@ public class Resource extends GroupedParameterizedElement implements StrolchRoot } } + @SuppressWarnings("unchecked") public void addTimedState(StrolchTimedState strolchTimedState) { if (this.timedStateMap == null) { this.timedStateMap = new HashMap<>(); } - this.timedStateMap.put(strolchTimedState.getId(), strolchTimedState); + this.timedStateMap.put(strolchTimedState.getId(), (StrolchTimedState>) strolchTimedState); strolchTimedState.setParent(this); } - @SuppressWarnings({"rawtypes", "unchecked"}) + @SuppressWarnings({ "rawtypes", "unchecked" }) public T getTimedState(String id) { if (this.timedStateMap == null) { return null; @@ -115,7 +120,7 @@ public class Resource extends GroupedParameterizedElement implements StrolchRoot return (T) this.timedStateMap.get(id); } - @SuppressWarnings({"unchecked", "rawtypes"}) + @SuppressWarnings({ "unchecked", "rawtypes" }) public T removeTimedState(String id) { if (this.timedStateMap == null) { return null; @@ -130,7 +135,7 @@ public class Resource extends GroupedParameterizedElement implements StrolchRoot return new HashSet<>(this.timedStateMap.keySet()); } - public List> getTimedStates() { + public List>> getTimedStates() { if (this.timedStateMap == null) { return Collections.emptyList(); } diff --git a/src/main/java/li/strolch/model/StrolchModelConstants.java b/src/main/java/li/strolch/model/StrolchModelConstants.java index ae993ddfb..9db2dd829 100644 --- a/src/main/java/li/strolch/model/StrolchModelConstants.java +++ b/src/main/java/li/strolch/model/StrolchModelConstants.java @@ -20,4 +20,15 @@ public class StrolchModelConstants { * to an {@link Order} */ public static final String INTERPRETATION_ORDER_REF = "Order-Ref"; //$NON-NLS-1$ + + + /** + * This interpretation value indicates that the {@link Parameter} has no defined interpretation + */ + public static final String INTERPRETATION_NONE = "None"; //$NON-NLS-1$ + + /** + * This uom value indicates that the {@link Parameter} has no defined uom + */ + public static final String UOM_NONE = "None"; //$NON-NLS-1$ } diff --git a/src/main/java/li/strolch/model/Tags.java b/src/main/java/li/strolch/model/Tags.java index eb79a8fc2..c6b0d6e27 100644 --- a/src/main/java/li/strolch/model/Tags.java +++ b/src/main/java/li/strolch/model/Tags.java @@ -40,4 +40,5 @@ public class Tags { public static final String INCLUDE_FILE = "IncludeFile"; public static final String FILE = "file"; + public static final String BAG = "Bag"; } diff --git a/src/main/java/li/strolch/model/parameter/AbstractParameter.java b/src/main/java/li/strolch/model/parameter/AbstractParameter.java index 95ea81de5..18296b782 100644 --- a/src/main/java/li/strolch/model/parameter/AbstractParameter.java +++ b/src/main/java/li/strolch/model/parameter/AbstractParameter.java @@ -15,6 +15,9 @@ */ package li.strolch.model.parameter; +import static li.strolch.model.StrolchModelConstants.INTERPRETATION_NONE; +import static li.strolch.model.StrolchModelConstants.UOM_NONE; + import java.text.MessageFormat; import li.strolch.exception.StrolchException; @@ -82,7 +85,7 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem @Override public void setInterpretation(String interpretation) { if (StringHelper.isEmpty(interpretation)) { - this.interpretation = Parameter.INTERPRETATION_NONE; + this.interpretation = INTERPRETATION_NONE; } else { this.interpretation = interpretation; } @@ -96,7 +99,7 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem @Override public void setUom(String uom) { if (StringHelper.isEmpty(uom)) { - this.uom = Parameter.UOM_NONE; + this.uom = UOM_NONE; } else { this.uom = uom; } @@ -134,10 +137,10 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem element.setAttribute(Tags.VALUE, getValueAsString()); - if (!this.interpretation.equals(Parameter.INTERPRETATION_NONE)) { + if (!this.interpretation.equals(INTERPRETATION_NONE)) { element.setAttribute(Tags.INTERPRETATION, this.interpretation); } - if (!this.uom.equals(Parameter.UOM_NONE)) { + if (!this.uom.equals(UOM_NONE)) { element.setAttribute(Tags.UOM, this.uom); } if (this.hidden) { @@ -196,8 +199,8 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem } @Override - protected void fillLocator(LocatorBuilder locatorBuilder) { - locatorBuilder.append(this.id); + protected void fillLocator(LocatorBuilder lb) { + lb.append(this.id); } @Override @@ -211,9 +214,11 @@ public abstract class AbstractParameter extends AbstractStrolchElement implem /** * Validates that the value is legal. This is the case when it is not null in this implementation * - * @param value the value to check for this parameter instance + * @param value + * the value to check for this parameter instance * - * @throws StrolchException if the value is null + * @throws StrolchException + * if the value is null */ protected void validateValue(T value) throws StrolchException { if (value == null) { diff --git a/src/main/java/li/strolch/model/parameter/Parameter.java b/src/main/java/li/strolch/model/parameter/Parameter.java index 00b55a53a..f55b99594 100644 --- a/src/main/java/li/strolch/model/parameter/Parameter.java +++ b/src/main/java/li/strolch/model/parameter/Parameter.java @@ -22,20 +22,9 @@ import li.strolch.model.visitor.ParameterVisitor; /** * @author Robert von Burg - * */ public interface Parameter extends StrolchElement { - /** - * This interpretation value indicates that the {@link Parameter} has no defined interpretation - */ - public static final String INTERPRETATION_NONE = "None"; //$NON-NLS-1$ - - /** - * This uom value indicates that the {@link Parameter} has no defined uom - */ - public static final String UOM_NONE = "None"; //$NON-NLS-1$ - /** * the value of the parameter as string * @@ -100,24 +89,11 @@ public interface Parameter extends StrolchElement { */ public void setIndex(int index); - /** - * The {@link ParameterizedElement} parent to which this {@link Parameter} belongs - * - * @return - */ - @Override - public ParameterizedElement getParent(); - - /** - * Sets the parent for this {@link Parameter} - */ - public void setParent(ParameterizedElement parent); - /** * Returns the interpretation of this {@link Parameter}. The interpretation semantic describes what the value of * this {@link Parameter} means. Currently there are three definitions, but any String value can be used: *
      - *
    • {@link Parameter#INTERPRETATION_NONE}
    • + *
    • {@link StrolchModelConstants#INTERPRETATION_NONE}
    • *
    • {@link StrolchModelConstants#INTERPRETATION_ORDER_REF}
    • *
    • {@link StrolchModelConstants#INTERPRETATION_RESOURCE_REF}
    • *
    @@ -130,7 +106,7 @@ public interface Parameter extends StrolchElement { * Set the interpretation of this {@link Parameter}. The interpretation semantic describes what the value of this * {@link Parameter} means. Currently there are three definitions, but any String value can be used: *
      - *
    • {@link Parameter#INTERPRETATION_NONE}
    • + *
    • {@link StrolchModelConstants#INTERPRETATION_NONE}
    • *
    • {@link StrolchModelConstants#INTERPRETATION_ORDER_REF}
    • *
    • {@link StrolchModelConstants#INTERPRETATION_RESOURCE_REF}
    • *
    @@ -139,6 +115,19 @@ public interface Parameter extends StrolchElement { */ public void setInterpretation(String interpretation); + /** + * The {@link ParameterizedElement} parent to which this {@link Parameter} belongs + * + * @return + */ + @Override + public ParameterizedElement getParent(); + + /** + * Sets the parent for this {@link Parameter} + */ + public void setParent(ParameterizedElement parent); + @Override public int hashCode(); diff --git a/src/main/java/li/strolch/model/timedstate/AbstractStrolchTimedState.java b/src/main/java/li/strolch/model/timedstate/AbstractStrolchTimedState.java index 30faffef5..f79cff7b4 100644 --- a/src/main/java/li/strolch/model/timedstate/AbstractStrolchTimedState.java +++ b/src/main/java/li/strolch/model/timedstate/AbstractStrolchTimedState.java @@ -15,6 +15,12 @@ */ package li.strolch.model.timedstate; +import static li.strolch.model.StrolchModelConstants.INTERPRETATION_NONE; +import static li.strolch.model.StrolchModelConstants.UOM_NONE; + +import java.text.MessageFormat; + +import li.strolch.exception.StrolchException; import li.strolch.model.AbstractStrolchElement; import li.strolch.model.Locator; import li.strolch.model.Locator.LocatorBuilder; @@ -26,6 +32,12 @@ import li.strolch.model.timevalue.ITimeValue; import li.strolch.model.timevalue.ITimeVariable; import li.strolch.model.timevalue.IValue; import li.strolch.model.timevalue.IValueChange; +import li.strolch.model.visitor.TimedStateVisitor; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import ch.eitchnet.utils.helper.StringHelper; /** * @author Robert von Burg @@ -36,6 +48,11 @@ public abstract class AbstractStrolchTimedState extends Abstra private static final long serialVersionUID = 1L; + protected boolean hidden = false; + protected int index; + protected String interpretation = INTERPRETATION_NONE; + protected String uom = UOM_NONE; + protected Resource parent; protected ITimedState state; @@ -48,6 +65,54 @@ public abstract class AbstractStrolchTimedState extends Abstra this.state = new TimedState<>(); } + @Override + public boolean isHidden() { + return this.hidden; + } + + @Override + public void setHidden(boolean hidden) { + this.hidden = hidden; + } + + @Override + public String getInterpretation() { + return this.interpretation; + } + + @Override + public void setInterpretation(String interpretation) { + if (StringHelper.isEmpty(interpretation)) { + this.interpretation = INTERPRETATION_NONE; + } else { + this.interpretation = interpretation; + } + } + + @Override + public String getUom() { + return this.uom; + } + + @Override + public void setUom(String uom) { + if (StringHelper.isEmpty(uom)) { + this.uom = UOM_NONE; + } else { + this.uom = uom; + } + } + + @Override + public void setIndex(int index) { + this.index = index; + } + + @Override + public int getIndex() { + return this.index; + } + @Override public ITimeValue getNextMatch(Long time, T value) { return this.state.getNextMatch(time, value); @@ -89,9 +154,75 @@ public abstract class AbstractStrolchTimedState extends Abstra } @Override - protected void fillLocator(LocatorBuilder locatorBuilder) { - locatorBuilder.append(Tags.TIMED_STATE); - locatorBuilder.append(getId()); + public Element toDom(Document doc) { + Element element = doc.createElement(Tags.PARAMETER); + fillElement(element); + + if (!this.interpretation.equals(INTERPRETATION_NONE)) { + element.setAttribute(Tags.INTERPRETATION, this.interpretation); + } + if (!this.uom.equals(UOM_NONE)) { + element.setAttribute(Tags.UOM, this.uom); + } + if (this.hidden) { + element.setAttribute(Tags.HIDDEN, Boolean.toString(this.hidden)); + } + if (this.index != 0) { + element.setAttribute(Tags.INDEX, Integer.toString(this.index)); + } + + return element; + } + + @Override + public void fromDom(Element element) { + + super.fromDom(element); + + String typeS = element.getAttribute(Tags.TYPE); + if (StringHelper.isEmpty(typeS)) { + String msg = "Type must be set on element with id {0}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, this.id); + throw new StrolchException(msg); + } else if (!typeS.equals(getType())) { + String msg = "{0} must have type {1}, not: {2}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, getClass().getSimpleName(), getType(), typeS); + throw new StrolchException(msg); + } + + String interpretation = element.getAttribute(Tags.INTERPRETATION); + String hidden = element.getAttribute(Tags.HIDDEN); + String uom = element.getAttribute(Tags.UOM); + String index = element.getAttribute(Tags.INDEX); + + setInterpretation(interpretation); + setUom(uom); + + if (StringHelper.isEmpty(index)) { + this.index = 0; + } else { + this.index = Integer.valueOf(index); + } + + if (StringHelper.isEmpty(hidden)) { + setHidden(false); + } else { + if (hidden.equalsIgnoreCase(Boolean.TRUE.toString())) { + setHidden(true); + } else if (hidden.equalsIgnoreCase(Boolean.FALSE.toString())) { + setHidden(false); + } else { + String msg = "Boolean string must be either {0} or {1}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, Boolean.TRUE.toString(), Boolean.FALSE.toString()); + throw new StrolchException(msg); + } + } + } + + @Override + protected void fillLocator(LocatorBuilder lb) { + lb.append(Tags.STATE); + lb.append(this.id); } @Override @@ -107,6 +238,11 @@ public abstract class AbstractStrolchTimedState extends Abstra clone.state = this.state.getCopy(); } + @Override + public U accept(TimedStateVisitor visitor) { + return visitor.visitTimedState(this); + } + @SuppressWarnings("nls") @Override public String toString() { diff --git a/src/main/java/li/strolch/model/timedstate/StrolchTimedState.java b/src/main/java/li/strolch/model/timedstate/StrolchTimedState.java index f70d406c3..1b7942ddb 100644 --- a/src/main/java/li/strolch/model/timedstate/StrolchTimedState.java +++ b/src/main/java/li/strolch/model/timedstate/StrolchTimedState.java @@ -17,10 +17,13 @@ package li.strolch.model.timedstate; import li.strolch.model.Resource; import li.strolch.model.StrolchElement; +import li.strolch.model.StrolchModelConstants; +import li.strolch.model.parameter.Parameter; import li.strolch.model.timevalue.ITimeValue; import li.strolch.model.timevalue.ITimeVariable; import li.strolch.model.timevalue.IValue; import li.strolch.model.timevalue.IValueChange; +import li.strolch.model.visitor.TimedStateVisitor; /** * @author Robert von Burg @@ -28,6 +31,75 @@ import li.strolch.model.timevalue.IValueChange; @SuppressWarnings("rawtypes") public interface StrolchTimedState extends StrolchElement { + /** + * get the hidden attribute + * + * @return + */ + public boolean isHidden(); + + /** + * set the hidden attribute + * + * @param hidden + */ + public void setHidden(boolean hidden); + + /** + * Get the UOM of this {@link Parameter} + * + * @return + */ + public String getUom(); + + /** + * Set the UOM of this {@link Parameter} + * + * @param uom + */ + public void setUom(String uom); + + /** + * Returns the index of this {@link Parameter}. This can be used to sort the parameters in a UI + * + * @return the index of this {@link Parameter}. This can be used to sort the parameters in a UI + */ + public int getIndex(); + + /** + * Set the index of this {@link Parameter}. This can be used to sort the parameters in a UI + * + * @param index + * the index to set + */ + public void setIndex(int index); + + /** + * Returns the interpretation of this {@link Parameter}. The interpretation semantic describes what the value of + * this {@link Parameter} means. Currently there are three definitions, but any String value can be used: + *
      + *
    • {@link StrolchModelConstants#INTERPRETATION_NONE}
    • + *
    • {@link StrolchModelConstants#INTERPRETATION_ORDER_REF}
    • + *
    • {@link StrolchModelConstants#INTERPRETATION_RESOURCE_REF}
    • + *
    + * + * @return string value + */ + public String getInterpretation(); + + /** + * Set the interpretation of this {@link Parameter}. The interpretation semantic describes what the value of this + * {@link Parameter} means. Currently there are three definitions, but any String value can be used: + *
      + *
    • {@link StrolchModelConstants#INTERPRETATION_NONE}
    • + *
    • {@link StrolchModelConstants#INTERPRETATION_ORDER_REF}
    • + *
    • {@link StrolchModelConstants#INTERPRETATION_RESOURCE_REF}
    • + *
    + * + * @param interpretation + */ + public void setInterpretation(String interpretation); + public ITimeValue getNextMatch(Long time, T value); public ITimeValue getPreviousMatch(Long time, T value); @@ -39,4 +111,6 @@ public interface StrolchTimedState extends StrolchElement { public ITimeVariable getTimeEvolution(); public void setParent(Resource aThis); + + public U accept(TimedStateVisitor visitor); } diff --git a/src/main/java/li/strolch/model/timevalue/IValue.java b/src/main/java/li/strolch/model/timevalue/IValue.java index 94f1d6074..701d62d8d 100644 --- a/src/main/java/li/strolch/model/timevalue/IValue.java +++ b/src/main/java/li/strolch/model/timevalue/IValue.java @@ -49,4 +49,9 @@ public interface IValue { * @return a copy of this */ IValue getCopy(); + + /** + * @return this value in string representation + */ + String getValueAsString(); } diff --git a/src/main/java/li/strolch/model/timevalue/impl/AString.java b/src/main/java/li/strolch/model/timevalue/impl/AString.java index 5626bef3a..fc2835b74 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/AString.java +++ b/src/main/java/li/strolch/model/timevalue/impl/AString.java @@ -17,6 +17,8 @@ package li.strolch.model.timevalue.impl; import java.io.Serializable; +import ch.eitchnet.utils.dbc.DBC; + /** * Wrapper for java.util.String object defining a inverse to support algebraic operations. * @@ -30,11 +32,15 @@ public class AString implements Serializable { private final boolean inverse; public AString(final String string) { + DBC.PRE.assertNotNull("Value may not be null!", string); + DBC.PRE.assertFalse("Comma not allowed in value!", string.contains(",")); this.string = string; this.inverse = false; } public AString(final String string, final boolean inverse) { + DBC.PRE.assertNotNull("Value may not be null!", string); + DBC.PRE.assertFalse("Comma not allowed in value!", string.contains(",")); this.string = string; this.inverse = inverse; } diff --git a/src/main/java/li/strolch/model/timevalue/impl/BooleanValue.java b/src/main/java/li/strolch/model/timevalue/impl/BooleanValue.java index 10bc9cbe0..f52a1c794 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/BooleanValue.java +++ b/src/main/java/li/strolch/model/timevalue/impl/BooleanValue.java @@ -65,6 +65,11 @@ public class BooleanValue implements IValue, Serializable { public BooleanValue getInverse() { return new BooleanValue(!getValue()); } + + @Override + public String getValueAsString() { + return this.value.toString(); + } @SuppressWarnings("nls") @Override diff --git a/src/main/java/li/strolch/model/timevalue/impl/FloatValue.java b/src/main/java/li/strolch/model/timevalue/impl/FloatValue.java index 452686870..deaddc02d 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/FloatValue.java +++ b/src/main/java/li/strolch/model/timevalue/impl/FloatValue.java @@ -64,6 +64,11 @@ public class FloatValue implements IValue, Serializable { return this.value; } + @Override + public String getValueAsString() { + return this.value.toString(); + } + @SuppressWarnings("nls") @Override public String toString() { diff --git a/src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java b/src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java index da7936f64..4f90363e2 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java +++ b/src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java @@ -65,6 +65,11 @@ public class IntegerValue implements IValue, Serializable { public IntegerValue getInverse() { return new IntegerValue(-getValue()); } + + @Override + public String getValueAsString() { + return this.value.toString(); + } @SuppressWarnings("nls") @Override diff --git a/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java b/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java index 76bb82284..b6eb46df4 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java +++ b/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java @@ -15,15 +15,17 @@ */ package li.strolch.model.timevalue.impl; -import ch.eitchnet.utils.helper.StringHelper; import java.io.Serializable; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.Set; + import li.strolch.exception.StrolchException; import li.strolch.model.timevalue.ITimeValue; import li.strolch.model.timevalue.IValue; +import ch.eitchnet.utils.dbc.DBC; +import ch.eitchnet.utils.helper.StringHelper; /** * {@link IValue} implementation to work with String valued {@link ITimeValue} objects. Since a java.util.String object @@ -44,12 +46,7 @@ public class StringSetValue implements IValue>, Serializable { } public StringSetValue(final Set aStrings) { - // assert no null values in set - for (AString aString : aStrings) { - if (StringHelper.isEmpty(aString.getString())) { - throw new StrolchException("StringSetValue may not contain null values in set!"); - } - } + DBC.PRE.assertNotNull("Value may not be null!", aStrings); this.aStrings = aStrings; } @@ -105,12 +102,29 @@ public class StringSetValue implements IValue>, Serializable { return new StringSetValue(new HashSet<>(this.aStrings)); } + @Override + public String getValueAsString() { + if (this.aStrings.isEmpty()) + return StringHelper.EMPTY; + if (this.aStrings.size() == 1) + return this.aStrings.iterator().next().getString(); + + StringBuilder sb = new StringBuilder(); + Iterator iter = aStrings.iterator(); + while (iter.hasNext()) { + sb.append(iter.next()); + if (iter.hasNext()) + sb.append(", "); + } + return sb.toString(); + } + @SuppressWarnings("nls") @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("StringSetValue [aStrings="); - sb.append(this.aStrings); + sb.append(getValueAsString()); sb.append("]"); return sb.toString(); } diff --git a/src/main/java/li/strolch/model/visitor/StrolchElementDeepEqualsVisitor.java b/src/main/java/li/strolch/model/visitor/StrolchElementDeepEqualsVisitor.java index b03d470b2..2e8b1b038 100644 --- a/src/main/java/li/strolch/model/visitor/StrolchElementDeepEqualsVisitor.java +++ b/src/main/java/li/strolch/model/visitor/StrolchElementDeepEqualsVisitor.java @@ -18,6 +18,7 @@ package li.strolch.model.visitor; import java.util.ArrayList; import java.util.List; import java.util.Set; + import li.strolch.model.GroupedParameterizedElement; import li.strolch.model.Locator; import li.strolch.model.Order; @@ -78,21 +79,21 @@ public class StrolchElementDeepEqualsVisitor { Set srcTimedStateKeySet = srcRes.getTimedStateKeySet(); for (String timedStateKey : srcTimedStateKeySet) { - StrolchTimedState srcTimedState = srcRes.getTimedState(timedStateKey); + StrolchTimedState srcTimedState = srcRes.getTimedState(timedStateKey); if (!dstRes.hasTimedState(timedStateKey)) { this.mismatchedLocators.add(srcTimedState.getLocator()); continue; } - StrolchTimedState dstTimedState = dstRes.getTimedState(timedStateKey); + StrolchTimedState dstTimedState = dstRes.getTimedState(timedStateKey); deepEquals(srcTimedState, dstTimedState); } Set dstTimedStateKeySet = dstRes.getTimedStateKeySet(); for (String timedStateKey : dstTimedStateKeySet) { if (!srcRes.hasTimedState(timedStateKey)) { - StrolchTimedState dstTimedState = dstRes.getTimedState(timedStateKey); + StrolchTimedState dstTimedState = dstRes.getTimedState(timedStateKey); this.mismatchedLocators.add(dstTimedState.getLocator()); } } diff --git a/src/main/java/li/strolch/model/visitor/TimedStateVisitor.java b/src/main/java/li/strolch/model/visitor/TimedStateVisitor.java new file mode 100644 index 000000000..072afc482 --- /dev/null +++ b/src/main/java/li/strolch/model/visitor/TimedStateVisitor.java @@ -0,0 +1,39 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.visitor; + +import li.strolch.model.timedstate.BooleanTimedState; +import li.strolch.model.timedstate.FloatTimedState; +import li.strolch.model.timedstate.IntegerTimedState; +import li.strolch.model.timedstate.StringSetTimedState; +import li.strolch.model.timedstate.StrolchTimedState; + +/** + * @author Robert von Burg + */ +public interface TimedStateVisitor { + + public T visitTimedState(StrolchTimedState timedState); + + public T visitBooleanState(BooleanTimedState state); + + public T visitFloatState(FloatTimedState state); + + public T visitIntegerState(IntegerTimedState state); + + public T visitStringState(StringSetTimedState state); + +} diff --git a/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java b/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java index eae45ec9a..5a53a9497 100644 --- a/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java +++ b/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java @@ -15,22 +15,32 @@ */ package li.strolch.model.xml; +import static li.strolch.model.StrolchModelConstants.INTERPRETATION_NONE; +import static li.strolch.model.StrolchModelConstants.UOM_NONE; + import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Set; +import java.util.SortedSet; import java.util.TreeSet; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; import li.strolch.model.GroupedParameterizedElement; +import li.strolch.model.Order; import li.strolch.model.ParameterBag; import li.strolch.model.ParameterizedElement; +import li.strolch.model.Resource; import li.strolch.model.StrolchElement; import li.strolch.model.Tags; import li.strolch.model.parameter.Parameter; +import li.strolch.model.timedstate.StrolchTimedState; +import li.strolch.model.timevalue.ITimeValue; +import li.strolch.model.timevalue.ITimeVariable; +import li.strolch.model.timevalue.IValue; import ch.eitchnet.utils.helper.StringHelper; /** @@ -44,12 +54,52 @@ public abstract class AbstractToSaxWriterVisitor { this.writer = writer; } - protected void writeElement(String tag, GroupedParameterizedElement element) throws XMLStreamException { - boolean isEmpty = !element.hasParameterBags(); - writeStartStrolchElement(tag, isEmpty, element); - if (!isEmpty) { - writeParameterBags(element); + protected void writeElement(String tag, Order order) throws XMLStreamException { + boolean empty = !order.hasParameterBags(); + writeElement(tag, empty, (GroupedParameterizedElement) order); + if (!empty) this.writer.writeEndElement(); + } + + protected void writeElement(String tag, Resource resource) throws XMLStreamException { + boolean empty = !resource.hasParameterBags() && !resource.hasTimedStates(); + writeElement(tag, empty, (GroupedParameterizedElement) resource); + + if (resource.hasTimedStates()) + writeTimedStates(resource); + + if (!empty) + this.writer.writeEndElement(); + } + + /** + * @param resource + * @throws XMLStreamException + */ + private void writeTimedStates(Resource resource) throws XMLStreamException { + List>> timedStates = resource.getTimedStates(); + for (StrolchTimedState> timedState : timedStates) { + ITimeVariable> timeEvolution = timedState.getTimeEvolution(); + SortedSet>> values = timeEvolution.getValues(); + + writeStartStrolchElement(Tags.TIMED_STATE, !values.isEmpty(), timedState); + + for (ITimeValue> timeValue : values) { + writer.writeEmptyElement(Tags.VALUE); + writer.writeAttribute(Tags.TIME, timeValue.getTime().toString()); + writer.writeAttribute(Tags.VALUE, timeValue.getValue().getValueAsString()); + } + + if (!values.isEmpty()) + writer.writeEndElement(); + } + } + + protected void writeElement(String tag, boolean empty, GroupedParameterizedElement element) + throws XMLStreamException { + writeStartStrolchElement(tag, empty, element); + if (!empty) { + writeParameterBags(element); } } @@ -68,35 +118,6 @@ public abstract class AbstractToSaxWriterVisitor { this.writer.writeAttribute(Tags.TYPE, element.getType()); } - protected void writeParameters(ParameterizedElement element) throws XMLStreamException { - - List> parameters = new ArrayList<>(element.getParameters()); - Collections.sort(parameters, new Comparator>() { - @Override - public int compare(Parameter o1, Parameter o2) { - return Integer.valueOf(o1.getIndex()).compareTo(o2.getIndex()); - } - }); - for (Parameter parameter : parameters) { - writeStartStrolchElement(Tags.PARAMETER, true, parameter); - - if (!Parameter.INTERPRETATION_NONE.equals(parameter.getInterpretation())) { - this.writer.writeAttribute(Tags.INTERPRETATION, parameter.getInterpretation()); - } - if (!Parameter.UOM_NONE.equals(parameter.getUom())) { - this.writer.writeAttribute(Tags.UOM, parameter.getUom()); - } - if (parameter.isHidden()) { - this.writer.writeAttribute(Tags.HIDDEN, Boolean.toString(parameter.isHidden())); - } - if (parameter.getIndex() != 0) { - this.writer.writeAttribute(Tags.INDEX, Integer.toString(parameter.getIndex())); - } - - this.writer.writeAttribute(Tags.VALUE, parameter.getValueAsString()); - } - } - protected void writeParameterBags(GroupedParameterizedElement element) throws XMLStreamException { Set bagKeySet = new TreeSet<>(element.getParameterBagKeySet()); for (String bagKey : bagKeySet) { @@ -109,4 +130,33 @@ public abstract class AbstractToSaxWriterVisitor { } } } + + protected void writeParameters(ParameterizedElement element) throws XMLStreamException { + + List> parameters = new ArrayList<>(element.getParameters()); + Collections.sort(parameters, new Comparator>() { + @Override + public int compare(Parameter o1, Parameter o2) { + return Integer.valueOf(o1.getIndex()).compareTo(o2.getIndex()); + } + }); + for (Parameter parameter : parameters) { + writeStartStrolchElement(Tags.PARAMETER, true, parameter); + + if (!INTERPRETATION_NONE.equals(parameter.getInterpretation())) { + this.writer.writeAttribute(Tags.INTERPRETATION, parameter.getInterpretation()); + } + if (!UOM_NONE.equals(parameter.getUom())) { + this.writer.writeAttribute(Tags.UOM, parameter.getUom()); + } + if (parameter.isHidden()) { + this.writer.writeAttribute(Tags.HIDDEN, Boolean.toString(parameter.isHidden())); + } + if (parameter.getIndex() != 0) { + this.writer.writeAttribute(Tags.INDEX, Integer.toString(parameter.getIndex())); + } + + this.writer.writeAttribute(Tags.VALUE, parameter.getValueAsString()); + } + } } diff --git a/src/main/java/li/strolch/model/xml/StrolchElementToSaxVisitor.java b/src/main/java/li/strolch/model/xml/StrolchElementToSaxVisitor.java index f777ce169..6f14e598b 100644 --- a/src/main/java/li/strolch/model/xml/StrolchElementToSaxVisitor.java +++ b/src/main/java/li/strolch/model/xml/StrolchElementToSaxVisitor.java @@ -15,6 +15,9 @@ */ package li.strolch.model.xml; +import static li.strolch.model.StrolchModelConstants.INTERPRETATION_NONE; +import static li.strolch.model.StrolchModelConstants.UOM_NONE; + import java.util.Set; import li.strolch.model.GroupedParameterizedElement; @@ -61,10 +64,10 @@ public abstract class StrolchElementToSaxVisitor { AttributesImpl attributes = attributesFor((StrolchElement) parameter); attributes.addAttribute(null, null, Tags.VALUE, Tags.CDATA, parameter.getValueAsString()); - if (!Parameter.UOM_NONE.equals(parameter.getUom())) { + if (!UOM_NONE.equals(parameter.getUom())) { attributes.addAttribute(null, null, Tags.UOM, Tags.CDATA, parameter.getUom()); } - if (!Parameter.INTERPRETATION_NONE.equals(parameter.getInterpretation())) { + if (!INTERPRETATION_NONE.equals(parameter.getInterpretation())) { attributes.addAttribute(null, null, Tags.INTERPRETATION, Tags.CDATA, parameter.getInterpretation()); } if (parameter.isHidden()) { diff --git a/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java b/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java index 06fe0901b..70287df8f 100644 --- a/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java +++ b/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java @@ -17,6 +17,8 @@ package li.strolch.model.xml; import java.text.MessageFormat; import java.util.Date; +import java.util.HashSet; +import java.util.Set; import li.strolch.exception.StrolchException; import li.strolch.model.GroupedParameterizedElement; @@ -34,6 +36,17 @@ import li.strolch.model.parameter.LongParameter; import li.strolch.model.parameter.Parameter; import li.strolch.model.parameter.StringListParameter; import li.strolch.model.parameter.StringParameter; +import li.strolch.model.timedstate.BooleanTimedState; +import li.strolch.model.timedstate.FloatTimedState; +import li.strolch.model.timedstate.IntegerTimedState; +import li.strolch.model.timedstate.StringSetTimedState; +import li.strolch.model.timedstate.StrolchTimedState; +import li.strolch.model.timevalue.IValue; +import li.strolch.model.timevalue.impl.AString; +import li.strolch.model.timevalue.impl.BooleanValue; +import li.strolch.model.timevalue.impl.FloatValue; +import li.strolch.model.timevalue.impl.IntegerValue; +import li.strolch.model.timevalue.impl.StringSetValue; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -56,6 +69,8 @@ public class XmlModelSaxReader extends DefaultHandler { private GroupedParameterizedElement parameterizedElement; private ParameterBag pBag; + private StrolchTimedState> state; + private String stateType; public XmlModelSaxReader(StrolchElementListener listener) { this.listener = listener; @@ -165,6 +180,63 @@ public class XmlModelSaxReader extends DefaultHandler { } break; + case Tags.TIMED_STATE: + String stateId = attributes.getValue(Tags.ID); + String stateName = attributes.getValue(Tags.NAME); + this.stateType = attributes.getValue(Tags.TYPE); + + switch (this.stateType) { + case FloatTimedState.TYPE: + this.state = new FloatTimedState(stateId, stateName); + break; + case IntegerTimedState.TYPE: + this.state = new IntegerTimedState(stateId, stateName); + break; + case BooleanTimedState.TYPE: + this.state = new BooleanTimedState(stateId, stateName); + break; + case StringSetTimedState.TYPE: + this.state = new StringSetTimedState(stateId, stateName); + break; + default: + break; + } + + break; + + case Tags.VALUE: + String valueTime = attributes.getValue(Tags.TIME); + String valueValue = attributes.getValue(Tags.VALUE); + switch (this.stateType) { + case FloatTimedState.TYPE: + ((FloatTimedState) this.state).getTimeEvolution().setValueAt(Long.valueOf(valueTime), + new FloatValue(valueValue)); + break; + case IntegerTimedState.TYPE: + ((IntegerTimedState) this.state).getTimeEvolution().setValueAt(Long.valueOf(valueTime), + new IntegerValue(valueValue)); + break; + case BooleanTimedState.TYPE: + ((BooleanTimedState) this.state).getTimeEvolution().setValueAt(Long.valueOf(valueTime), + new BooleanValue(valueValue)); + break; + case StringSetTimedState.TYPE: + + Set value = new HashSet<>(); + String[] values = valueValue.split(","); + for (String s : values) { + value.add(new AString(s.trim())); + } + + StringSetValue stringSetValue = new StringSetValue(value); + ((StringSetTimedState) this.state).getTimeEvolution().setValueAt(Long.valueOf(valueTime), + stringSetValue); + break; + default: + break; + } + break; + default: throw new IllegalArgumentException(MessageFormat.format("The element ''{0}'' is unhandled!", qName)); //$NON-NLS-1$ } @@ -193,6 +265,11 @@ public class XmlModelSaxReader extends DefaultHandler { break; case Tags.INCLUDE_FILE: break; + case Tags.TIMED_STATE: + ((Resource) this.parameterizedElement).addTimedState(state); + break; + case Tags.VALUE: + break; default: throw new IllegalArgumentException(MessageFormat.format("The element ''{0}'' is unhandled!", qName)); //$NON-NLS-1$ } diff --git a/src/test/java/li/strolch/model/ModelTest.java b/src/test/java/li/strolch/model/ModelTest.java index 391398e7a..0a512ba56 100644 --- a/src/test/java/li/strolch/model/ModelTest.java +++ b/src/test/java/li/strolch/model/ModelTest.java @@ -15,6 +15,7 @@ */ package li.strolch.model; +import static li.strolch.model.ModelGenerator.*; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -22,7 +23,7 @@ import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.Date; - +import static li.strolch.model.Tags.*; import li.strolch.model.parameter.BooleanParameter; import li.strolch.model.parameter.DateParameter; import li.strolch.model.parameter.FloatParameter; @@ -31,6 +32,9 @@ import li.strolch.model.parameter.LongParameter; import li.strolch.model.parameter.StringListParameter; import li.strolch.model.parameter.StringParameter; import li.strolch.model.timedstate.BooleanTimedState; +import li.strolch.model.timedstate.FloatTimedState; +import li.strolch.model.timedstate.IntegerTimedState; +import li.strolch.model.timedstate.StringSetTimedState; import li.strolch.model.timevalue.impl.BooleanValue; import li.strolch.model.timevalue.impl.ValueChange; import li.strolch.model.visitor.OrderDeepEqualsVisitor; @@ -44,23 +48,44 @@ public class ModelTest { @Test public void shouldCreateResource() { - Resource resource = ModelGenerator.createResource("@res01", "Test resource", "MyType"); - ParameterBag bag = resource.getParameterBag(ModelGenerator.BAG_ID); + Resource resource = createResource("@res01", "Test resource", "MyType"); + ParameterBag bag = resource.getParameterBag(BAG_ID); validateBag(bag); + validateStates(resource); } @Test public void shouldCreateOrder() { - Order order = ModelGenerator.createOrder("@ord01", "Test Order", "MyType", new Date(), State.OPEN); - ParameterBag bag = order.getParameterBag(ModelGenerator.BAG_ID); + Order order = createOrder("@ord01", "Test Order", "MyType", new Date(), State.OPEN); + ParameterBag bag = order.getParameterBag(BAG_ID); validateBag(bag); } + @Test + public void shouldCreateLocators() { + + Resource resource = createResource("@res01", "Test resource", "MyType"); + assertEquals(Locator.valueOf(RESOURCE, "MyType", "@res01"), resource.getLocator()); + ParameterBag bag = resource.getParameterBag(BAG_ID); + assertEquals(Locator.valueOf(RESOURCE, "MyType", "@res01", BAG, BAG_ID), bag.getLocator()); + StringParameter sP = bag.getParameter(PARAM_STRING_ID); + assertEquals(Locator.valueOf(RESOURCE, "MyType", "@res01", BAG, BAG_ID, PARAM_STRING_ID), sP.getLocator()); + FloatTimedState floatS = resource.getTimedState(STATE_FLOAT_ID); + assertEquals(Locator.valueOf(RESOURCE, "MyType", "@res01", STATE, STATE_FLOAT_ID), floatS.getLocator()); + + Order order = createOrder("@ord01", "Test Order", "MyType", new Date(), State.OPEN); + assertEquals(Locator.valueOf(ORDER, "MyType", "@ord01"), order.getLocator()); + bag = order.getParameterBag(BAG_ID); + assertEquals(Locator.valueOf(ORDER, "MyType", "@ord01", BAG, BAG_ID), bag.getLocator()); + sP = bag.getParameter(PARAM_STRING_ID); + assertEquals(Locator.valueOf(ORDER, "MyType", "@ord01", BAG, BAG_ID, PARAM_STRING_ID), sP.getLocator()); + } + @Test public void shouldPerformDeepResourceEquals() { - Resource srcRes = ModelGenerator.createResource("@res01", "Test resource", "MyType"); - Resource dstRes = ModelGenerator.createResource("@res01", "Test resource", "MyType"); + Resource srcRes = createResource("@res01", "Test resource", "MyType"); + Resource dstRes = createResource("@res01", "Test resource", "MyType"); ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes); visitor.visit(dstRes); assertTrue("Same Resource should be deep equal!", visitor.isEqual()); @@ -68,11 +93,11 @@ public class ModelTest { @Test public void shouldFailDeepResourceEquals1() { - Resource srcRes = ModelGenerator.createResource("@res01", "Test resource", "MyType"); - Resource dstRes = ModelGenerator.createResource("@res01", "Test resource", "MyType"); - ParameterBag bag = dstRes.getParameterBag(ModelGenerator.BAG_ID); + Resource srcRes = createResource("@res01", "Test resource", "MyType"); + Resource dstRes = createResource("@res01", "Test resource", "MyType"); + ParameterBag bag = dstRes.getParameterBag(BAG_ID); bag.setName("Bla bla"); - FloatParameter fParam = bag.getParameter(ModelGenerator.PARAM_FLOAT_ID); + FloatParameter fParam = bag.getParameter(PARAM_FLOAT_ID); fParam.setValue(23434234.234); fParam.setName("Ohla"); ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes); @@ -83,9 +108,9 @@ public class ModelTest { @Test public void shouldFailDeepResourceEquals2() { - Resource srcRes = ModelGenerator.createResource("@res01", "Test resource", "MyType"); - Resource dstRes = ModelGenerator.createResource("@res01", "Test resource", "MyType"); - BooleanTimedState timedState = dstRes.getTimedState(ModelGenerator.STATE_BOOLEAN_ID); + Resource srcRes = createResource("@res01", "Test resource", "MyType"); + Resource dstRes = createResource("@res01", "Test resource", "MyType"); + BooleanTimedState timedState = dstRes.getTimedState(STATE_BOOLEAN_ID); timedState.applyChange(new ValueChange<>(System.currentTimeMillis(), new BooleanValue(Boolean.TRUE))); timedState.setName("Ohla"); ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes); @@ -97,8 +122,8 @@ public class ModelTest { @Test public void shouldPerformDeepOrderEquals() { Date date = new Date(); - Order srcOrder = ModelGenerator.createOrder("@ord01", "Test Order", "MyType", date, State.OPEN); - Order dstOrder = ModelGenerator.createOrder("@ord01", "Test Order", "MyType", date, State.OPEN); + Order srcOrder = createOrder("@ord01", "Test Order", "MyType", date, State.OPEN); + Order dstOrder = createOrder("@ord01", "Test Order", "MyType", date, State.OPEN); OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(srcOrder); visitor.visit(dstOrder); assertTrue("Same Order should be deep equal: " + visitor.getMismatchedLocators(), visitor.isEqual()); @@ -108,45 +133,78 @@ public class ModelTest { assertNotNull(bag); - assertEquals(ModelGenerator.BAG_ID, bag.getId()); - assertEquals(ModelGenerator.BAG_NAME, bag.getName()); - assertEquals(ModelGenerator.BAG_TYPE, bag.getType()); + assertEquals(BAG_ID, bag.getId()); + assertEquals(BAG_NAME, bag.getName()); + assertEquals(BAG_TYPE, bag.getType()); validateParams(bag); } public static void validateParams(ParameterBag bag) { - BooleanParameter boolParam = bag.getParameter(ModelGenerator.PARAM_BOOLEAN_ID); - assertNotNull("Boolean Param missing with id " + ModelGenerator.PARAM_BOOLEAN_ID, boolParam); + BooleanParameter boolParam = bag.getParameter(PARAM_BOOLEAN_ID); + assertNotNull("Boolean Param missing with id " + PARAM_BOOLEAN_ID, boolParam); assertEquals(true, boolParam.getValue().booleanValue()); - FloatParameter floatParam = bag.getParameter(ModelGenerator.PARAM_FLOAT_ID); - assertNotNull("Float Param missing with id " + ModelGenerator.PARAM_FLOAT_ID, floatParam); + FloatParameter floatParam = bag.getParameter(PARAM_FLOAT_ID); + assertNotNull("Float Param missing with id " + PARAM_FLOAT_ID, floatParam); assertEquals(44.3, floatParam.getValue().doubleValue(), 0.0001); - IntegerParameter integerParam = bag.getParameter(ModelGenerator.PARAM_INTEGER_ID); - assertNotNull("Integer Param missing with id " + ModelGenerator.PARAM_INTEGER_ID, integerParam); + IntegerParameter integerParam = bag.getParameter(PARAM_INTEGER_ID); + assertNotNull("Integer Param missing with id " + PARAM_INTEGER_ID, integerParam); assertEquals(77, integerParam.getValue().intValue()); - LongParameter longParam = bag.getParameter(ModelGenerator.PARAM_LONG_ID); - assertNotNull("Long Param missing with id " + ModelGenerator.PARAM_LONG_ID, longParam); + LongParameter longParam = bag.getParameter(PARAM_LONG_ID); + assertNotNull("Long Param missing with id " + PARAM_LONG_ID, longParam); assertEquals(4453234566L, longParam.getValue().longValue()); - StringParameter stringParam = bag.getParameter(ModelGenerator.PARAM_STRING_ID); - assertNotNull("String Param missing with id " + ModelGenerator.PARAM_STRING_ID, stringParam); + StringParameter stringParam = bag.getParameter(PARAM_STRING_ID); + assertNotNull("String Param missing with id " + PARAM_STRING_ID, stringParam); assertEquals("Strolch", stringParam.getValue()); - DateParameter dateParam = bag.getParameter(ModelGenerator.PARAM_DATE_ID); - assertNotNull("Date Param missing with id " + ModelGenerator.PARAM_DATE_ID, dateParam); + DateParameter dateParam = bag.getParameter(PARAM_DATE_ID); + assertNotNull("Date Param missing with id " + PARAM_DATE_ID, dateParam); assertEquals(1354295525628L, dateParam.getValue().getTime()); - StringListParameter stringListP = bag.getParameter(ModelGenerator.PARAM_LIST_STRING_ID); - assertNotNull("StringList Param missing with id " + ModelGenerator.PARAM_LIST_STRING_ID, stringListP); + StringListParameter stringListP = bag.getParameter(PARAM_LIST_STRING_ID); + assertNotNull("StringList Param missing with id " + PARAM_LIST_STRING_ID, stringListP); ArrayList stringList = new ArrayList<>(); stringList.add("Hello"); stringList.add("World"); assertEquals(stringList, stringListP.getValue()); } + + /** + * @param resource + */ + private void validateStates(Resource resource) { + BooleanTimedState booleanState = resource.getTimedState(STATE_BOOLEAN_ID); + assertNotNull("Boolean State missing with id " + STATE_BOOLEAN_ID, booleanState); + assertEquals(STATE_BOOLEAN_TIME_0, booleanState.getStateAt(STATE_TIME_0).getValue().getValue()); + assertEquals(STATE_BOOLEAN_TIME_10, booleanState.getStateAt(STATE_TIME_10).getValue().getValue()); + assertEquals(STATE_BOOLEAN_TIME_20, booleanState.getStateAt(STATE_TIME_20).getValue().getValue()); + assertEquals(STATE_BOOLEAN_TIME_30, booleanState.getStateAt(STATE_TIME_30).getValue().getValue()); + + FloatTimedState floatState = resource.getTimedState(STATE_FLOAT_ID); + assertNotNull("Float State missing with id " + STATE_FLOAT_ID, floatState); + assertEquals(STATE_FLOAT_TIME_0, floatState.getStateAt(STATE_TIME_0).getValue().getValue()); + assertEquals(STATE_FLOAT_TIME_10, floatState.getStateAt(STATE_TIME_10).getValue().getValue()); + assertEquals(STATE_FLOAT_TIME_20, floatState.getStateAt(STATE_TIME_20).getValue().getValue()); + assertEquals(STATE_FLOAT_TIME_30, floatState.getStateAt(STATE_TIME_30).getValue().getValue()); + + IntegerTimedState integerState = resource.getTimedState(STATE_INTEGER_ID); + assertNotNull("Integer State missing with id " + STATE_INTEGER_ID, integerState); + assertEquals(STATE_INTEGER_TIME_0, integerState.getStateAt(STATE_TIME_0).getValue().getValue()); + assertEquals(STATE_INTEGER_TIME_10, integerState.getStateAt(STATE_TIME_10).getValue().getValue()); + assertEquals(STATE_INTEGER_TIME_20, integerState.getStateAt(STATE_TIME_20).getValue().getValue()); + assertEquals(STATE_INTEGER_TIME_30, integerState.getStateAt(STATE_TIME_30).getValue().getValue()); + + StringSetTimedState stringState = resource.getTimedState(STATE_STRING_ID); + assertNotNull("String State missing with id " + STATE_STRING_ID, stringState); + assertEquals(STATE_STRING_TIME_0, stringState.getStateAt(STATE_TIME_0).getValue().getValueAsString()); + assertEquals(STATE_STRING_TIME_10, stringState.getStateAt(STATE_TIME_10).getValue().getValueAsString()); + assertEquals(STATE_STRING_TIME_20, stringState.getStateAt(STATE_TIME_20).getValue().getValueAsString()); + assertEquals(STATE_STRING_TIME_30, stringState.getStateAt(STATE_TIME_30).getValue().getValueAsString()); + } } From c7a69dbf88d6645ac854e2e2f722420e3ba8405e Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 21 Aug 2014 17:51:52 +0200 Subject: [PATCH 78/88] [New] Added convenience method Locator.newLocatorBuilder(String...) --- src/main/java/li/strolch/model/Locator.java | 27 +++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/main/java/li/strolch/model/Locator.java b/src/main/java/li/strolch/model/Locator.java index 0dd9f093c..5e60f9852 100644 --- a/src/main/java/li/strolch/model/Locator.java +++ b/src/main/java/li/strolch/model/Locator.java @@ -274,6 +274,18 @@ public class Locator { return new Locator(path); } + /** + * Creates a new {@link LocatorBuilder} instance and appends the given elements to it + * + * @param path + * the first element on the {@link Locator} + * + * @return a new {@link LocatorBuilder} instance with the given root element tag as the first element + */ + public static LocatorBuilder newBuilder(String... path) { + return new LocatorBuilder().append(path); + } + /** * Creates a new {@link LocatorBuilder} instance and appends the given root element tag to it * @@ -303,6 +315,21 @@ public class Locator { this.pathElements = new ArrayList(); } + /** + * Append the given elements to the path + * + * @param path + * the path elements to add + * + * @return this instance for chaining + */ + public LocatorBuilder append(String... path) { + for (String element : path) { + this.pathElements.add(element); + } + return this; + } + /** * Append an element to the path * From b0d921d720f7248154ee19ac49e64a78e51e87f2 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sat, 23 Aug 2014 20:49:43 +0200 Subject: [PATCH 79/88] [New] Implemented opt-in audit trail in Strolch The audit trail has its own map on the Realm and a trail is written by realm at the end of the transaction. You can write your own audit trail using tx.getAuditTrail(). Enable the audit trail by setting the realm configuration value 'enableAuditTrail'. --- .../java/li/strolch/model/ModelGenerator.java | 116 ++++++--- src/main/java/li/strolch/model/Order.java | 8 +- src/main/java/li/strolch/model/Resource.java | 2 +- .../li/strolch/model/StrolchRootElement.java | 2 +- src/main/java/li/strolch/model/Tags.java | 18 +- .../li/strolch/model/audit/AccessType.java | 27 ++ .../strolch/model/audit/ActionSelection.java | 59 +++++ .../java/li/strolch/model/audit/Audit.java | 233 ++++++++++++++++++ .../model/audit/AuditFromDomReader.java | 100 ++++++++ .../li/strolch/model/audit/AuditQuery.java | 79 ++++++ .../model/audit/AuditQueryVisitor.java | 33 +++ .../strolch/model/audit/AuditSaxReader.java | 25 ++ .../strolch/model/audit/AuditSelection.java | 35 +++ .../model/audit/AuditToDomVisitor.java | 66 +++++ .../li/strolch/model/audit/AuditVisitor.java | 24 ++ .../model/audit/DateRangeSelection.java | 73 ++++++ .../strolch/model/audit/ElementSelection.java | 63 +++++ .../model/audit/IdentitySelection.java | 86 +++++++ .../model/audit/NoStrategyAuditVisitor.java | 27 ++ .../strolch/model/query/StringMatchMode.java | 48 ++++ .../strolch/model/query/StringSelection.java | 75 ++++++ .../model/visitor/ElementTypeVisitor.java | 36 +++ .../visitor/StrolchRootElementVisitor.java | 6 +- 23 files changed, 1202 insertions(+), 39 deletions(-) create mode 100644 src/main/java/li/strolch/model/audit/AccessType.java create mode 100644 src/main/java/li/strolch/model/audit/ActionSelection.java create mode 100644 src/main/java/li/strolch/model/audit/Audit.java create mode 100644 src/main/java/li/strolch/model/audit/AuditFromDomReader.java create mode 100644 src/main/java/li/strolch/model/audit/AuditQuery.java create mode 100644 src/main/java/li/strolch/model/audit/AuditQueryVisitor.java create mode 100644 src/main/java/li/strolch/model/audit/AuditSaxReader.java create mode 100644 src/main/java/li/strolch/model/audit/AuditSelection.java create mode 100644 src/main/java/li/strolch/model/audit/AuditToDomVisitor.java create mode 100644 src/main/java/li/strolch/model/audit/AuditVisitor.java create mode 100644 src/main/java/li/strolch/model/audit/DateRangeSelection.java create mode 100644 src/main/java/li/strolch/model/audit/ElementSelection.java create mode 100644 src/main/java/li/strolch/model/audit/IdentitySelection.java create mode 100644 src/main/java/li/strolch/model/audit/NoStrategyAuditVisitor.java create mode 100644 src/main/java/li/strolch/model/query/StringMatchMode.java create mode 100644 src/main/java/li/strolch/model/query/StringSelection.java create mode 100644 src/main/java/li/strolch/model/visitor/ElementTypeVisitor.java diff --git a/src/main/java/li/strolch/model/ModelGenerator.java b/src/main/java/li/strolch/model/ModelGenerator.java index a7af23bac..56652c47d 100644 --- a/src/main/java/li/strolch/model/ModelGenerator.java +++ b/src/main/java/li/strolch/model/ModelGenerator.java @@ -15,13 +15,16 @@ */ package li.strolch.model; -import ch.eitchnet.utils.helper.StringHelper; import java.util.ArrayList; import java.util.Date; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Random; import java.util.Set; + +import li.strolch.model.audit.AccessType; +import li.strolch.model.audit.Audit; import li.strolch.model.parameter.BooleanParameter; import li.strolch.model.parameter.DateParameter; import li.strolch.model.parameter.FloatParameter; @@ -41,6 +44,7 @@ import li.strolch.model.timevalue.impl.FloatValue; import li.strolch.model.timevalue.impl.IntegerValue; import li.strolch.model.timevalue.impl.StringSetValue; import li.strolch.model.timevalue.impl.ValueChange; +import ch.eitchnet.utils.helper.StringHelper; /** * Class which can be used to generate objects which implement {@link StrolchElement}. These generated classes can then @@ -117,9 +121,12 @@ public class ModelGenerator { * Creates an {@link Resource} with the given values and adds a {@link ParameterBag} by calling * {@link #createParameterBag(String, String, String)} * - * @param id the id of the {@link Resource} - * @param name the name of the {@link Resource} - * @param type the type of the {@link Resource} + * @param id + * the id of the {@link Resource} + * @param name + * the name of the {@link Resource} + * @param type + * the type of the {@link Resource} * * @return the newly created {@link Resource} */ @@ -135,7 +142,8 @@ public class ModelGenerator { /** * Creates {@link StrolchTimedState} instances and adds them to the {@link Resource} * - * @param resource the resource to which to addd the newly created {@link StrolchTimedState} + * @param resource + * the resource to which to addd the newly created {@link StrolchTimedState} */ public static void addTimedStates(Resource resource) { @@ -150,8 +158,7 @@ public class ModelGenerator { // integer state IntegerTimedState integerTimedState = new IntegerTimedState(STATE_INTEGER_ID, STATE_INTEGER_NAME); - integerTimedState.applyChange(new ValueChange<>(STATE_TIME_0, - new IntegerValue(STATE_INTEGER_TIME_0))); + integerTimedState.applyChange(new ValueChange<>(STATE_TIME_0, new IntegerValue(STATE_INTEGER_TIME_0))); IntegerValue integerValueChange = new IntegerValue(STATE_INTEGER_TIME_10); integerTimedState.applyChange(new ValueChange<>(STATE_TIME_10, integerValueChange)); integerTimedState.applyChange(new ValueChange<>(STATE_TIME_20, integerValueChange)); @@ -160,8 +167,7 @@ public class ModelGenerator { // boolean state BooleanTimedState booleanTimedState = new BooleanTimedState(STATE_BOOLEAN_ID, STATE_BOOLEAN_NAME); - booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_0, - new BooleanValue(STATE_BOOLEAN_TIME_0))); + booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_0, new BooleanValue(STATE_BOOLEAN_TIME_0))); BooleanValue booleanValueChange = new BooleanValue(STATE_BOOLEAN_TIME_10); booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_10, booleanValueChange)); booleanValueChange = booleanValueChange.getInverse(); @@ -207,11 +213,16 @@ public class ModelGenerator { * Creates a list of {@link Resource Resources} with the given values and adds a {@link ParameterBag} by calling * {@link #createParameterBag(String, String, String)} * - * @param idStart id range start - * @param count the number of elements to create - * @param idPrefix the prefix to generate IDs for the {@link Resource Resources} - * @param name the name of the {@link Resource} - * @param type the type of the {@link Resource} + * @param idStart + * id range start + * @param count + * the number of elements to create + * @param idPrefix + * the prefix to generate IDs for the {@link Resource Resources} + * @param name + * the name of the {@link Resource} + * @param type + * the type of the {@link Resource} * * @return the list of newly created {@link Resource Resources} */ @@ -228,9 +239,12 @@ public class ModelGenerator { * Creates an {@link Order} with the given values and adds a {@link ParameterBag} by calling * {@link #createParameterBag(String, String, String)} * - * @param id the id of the {@link Order} - * @param name the name of the {@link Order} - * @param type the type of the {@link Order} + * @param id + * the id of the {@link Order} + * @param name + * the name of the {@link Order} + * @param type + * the type of the {@link Order} * * @return the newly created {@link Order} */ @@ -242,11 +256,16 @@ public class ModelGenerator { * Creates an {@link Order} with the given values and adds a {@link ParameterBag} by calling * {@link #createParameterBag(String, String, String)} * - * @param id the id of the {@link Order} - * @param name the name of the {@link Order} - * @param type the type of the {@link Order} - * @param date the date of the {@link Order} - * @param state the {@link State} of the {@link Order} + * @param id + * the id of the {@link Order} + * @param name + * the name of the {@link Order} + * @param type + * the type of the {@link Order} + * @param date + * the date of the {@link Order} + * @param state + * the {@link State} of the {@link Order} * * @return the newly created {@link Order} */ @@ -263,11 +282,16 @@ public class ModelGenerator { * Creates a list of {@link Order Orders} with the given values and adds a {@link ParameterBag} by calling * {@link #createParameterBag(String, String, String)} * - * @param idStart id range start - * @param count the number of elements to create - * @param idPrefix the prefix to generate IDs for the {@link Order Orders} - * @param name the name of the {@link Order} - * @param type the type of the {@link Order} + * @param idStart + * id range start + * @param count + * the number of elements to create + * @param idPrefix + * the prefix to generate IDs for the {@link Order Orders} + * @param name + * the name of the {@link Order} + * @param type + * the type of the {@link Order} * * @return the list of newly created {@link Order Orders} */ @@ -284,9 +308,12 @@ public class ModelGenerator { * Creates a {@link ParameterBag} with the given values and calls {@link #addAllParameters(ParameterBag)} to add * {@link Parameter}s * - * @param id the id of the {@link ParameterBag} - * @param name the name of the {@link ParameterBag} - * @param type the type of the {@link ParameterBag} + * @param id + * the id of the {@link ParameterBag} + * @param name + * the name of the {@link ParameterBag} + * @param type + * the type of the {@link ParameterBag} * * @return the newly created {@link ParameterBag} */ @@ -345,4 +372,33 @@ public class ModelGenerator { stringListP.setIndex(7); bag.addParameter(stringListP); } + + private static String randomValue(Random rand, String[] values) { + return values[rand.nextInt(values.length)]; + } + + public static Audit randomAudit() { + + Random rand = new Random(234234L); + String[] usernames = new String[] { "bob", "alice", "jenny" }; + String[] firstnames = new String[] { "Bob", "Alice", "Jenny" }; + String[] lastnames = new String[] { "Richards", "Kennedy", "Davids" }; + String[] types = new String[] { Tags.RESOURCE, Tags.ORDER, Tags.AUDIT }; + String[] actions = new String[] { "AddResourceService", "UpdateResourceService", "RemoveResourceService", + "AddOrderService", "UpdateOrderService", "RemoveOrderService" }; + + Audit audit = new Audit(); + audit.setId(StringHelper.getUniqueIdLong()); + audit.setUsername(randomValue(rand, usernames)); + audit.setFirstname(randomValue(rand, firstnames)); + audit.setLastname(randomValue(rand, lastnames)); + audit.setDate(new Date(rand.nextInt(5000))); + audit.setElementType(randomValue(rand, types)); + audit.setElementAccessed(StringHelper.getUniqueId()); + audit.setNewVersion(new Date(rand.nextInt(5000))); + audit.setAction(randomValue(rand, actions)); + audit.setAccessType(AccessType.values()[rand.nextInt(AccessType.values().length)]); + + return audit; + } } diff --git a/src/main/java/li/strolch/model/Order.java b/src/main/java/li/strolch/model/Order.java index 8da752bb3..3b8fb11eb 100644 --- a/src/main/java/li/strolch/model/Order.java +++ b/src/main/java/li/strolch/model/Order.java @@ -112,7 +112,8 @@ public class Order extends GroupedParameterizedElement implements StrolchRootEle } /** - * @param date the date to set + * @param date + * the date to set */ public void setDate(Date date) { this.date = date; @@ -126,7 +127,8 @@ public class Order extends GroupedParameterizedElement implements StrolchRootEle } /** - * @param state the state to set + * @param state + * the state to set */ public void setState(State state) { this.state = state; @@ -179,7 +181,7 @@ public class Order extends GroupedParameterizedElement implements StrolchRootEle } @Override - public T accept(StrolchRootElementVisitor visitor) { + public T accept(StrolchRootElementVisitor visitor) { return visitor.visitOrder(this); } diff --git a/src/main/java/li/strolch/model/Resource.java b/src/main/java/li/strolch/model/Resource.java index 2860e06df..3fe1d7597 100644 --- a/src/main/java/li/strolch/model/Resource.java +++ b/src/main/java/li/strolch/model/Resource.java @@ -198,7 +198,7 @@ public class Resource extends GroupedParameterizedElement implements StrolchRoot } @Override - public T accept(StrolchRootElementVisitor visitor) { + public T accept(StrolchRootElementVisitor visitor) { return visitor.visitResource(this); } diff --git a/src/main/java/li/strolch/model/StrolchRootElement.java b/src/main/java/li/strolch/model/StrolchRootElement.java index 42ac8942c..7b99b045d 100644 --- a/src/main/java/li/strolch/model/StrolchRootElement.java +++ b/src/main/java/li/strolch/model/StrolchRootElement.java @@ -25,5 +25,5 @@ import li.strolch.model.visitor.StrolchRootElementVisitor; */ public interface StrolchRootElement extends StrolchElement { - public T accept(StrolchRootElementVisitor visitor); + public T accept(StrolchRootElementVisitor visitor); } diff --git a/src/main/java/li/strolch/model/Tags.java b/src/main/java/li/strolch/model/Tags.java index c6b0d6e27..b4fb9d22c 100644 --- a/src/main/java/li/strolch/model/Tags.java +++ b/src/main/java/li/strolch/model/Tags.java @@ -39,6 +39,22 @@ public class Tags { public static final String STROLCH_MODEL = "StrolchModel"; public static final String INCLUDE_FILE = "IncludeFile"; public static final String FILE = "file"; - public static final String BAG = "Bag"; + public static final String AUDIT = "Audit"; + + public class Audit { + public static final String ID = Tags.ID; + + public static final String USERNAME = "Username"; + public static final String FIRSTNAME = "Firstname"; + public static final String LASTNAME = "Lastname"; + public static final String DATE = "Date"; + + public static final String ELEMENT_TYPE = "ElementType"; + public static final String ELEMENT_ACCESSED = "ElementAccessed"; + public static final String NEW_VERSION = "NewVersion"; + + public static final String ACTION = "Action"; + public static final String ACCESS_TYPE = "AccessType"; + } } diff --git a/src/main/java/li/strolch/model/audit/AccessType.java b/src/main/java/li/strolch/model/audit/AccessType.java new file mode 100644 index 000000000..9c26d7846 --- /dev/null +++ b/src/main/java/li/strolch/model/audit/AccessType.java @@ -0,0 +1,27 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.audit; + +import li.strolch.model.StrolchRootElement; + +/** + * Defines the type of access performed on a {@link StrolchRootElement} + * + * @author Robert von Burg + */ +public enum AccessType { + READ, CREATE, UPDATE, DELETE; +} \ No newline at end of file diff --git a/src/main/java/li/strolch/model/audit/ActionSelection.java b/src/main/java/li/strolch/model/audit/ActionSelection.java new file mode 100644 index 000000000..2f01ae89c --- /dev/null +++ b/src/main/java/li/strolch/model/audit/ActionSelection.java @@ -0,0 +1,59 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.audit; + +import li.strolch.model.query.StringMatchMode; +import li.strolch.model.query.StringSelection; + +/** + * @author Robert von Burg + */ +public class ActionSelection extends AuditSelection { + + private StringSelection actionSelection; + private AccessType[] accessTypes; + + public ActionSelection(AuditQuery query) { + super(query); + } + + public ActionSelection actions(StringMatchMode matchMode, String... actions) { + this.actionSelection = new StringSelection(matchMode, actions); + return this; + } + + public ActionSelection accessTypes(AccessType... accessTypes) { + this.accessTypes = accessTypes; + return this; + } + + public AccessType[] getAccessTypes() { + return this.accessTypes; + } + + public boolean isWildcardActionType() { + return this.accessTypes == null || this.accessTypes.length == 0; + } + + public boolean isWildcardAction() { + return this.actionSelection == null || this.actionSelection.isWildCard(); + } + + @Override + public void accept(AuditQueryVisitor visitor) { + visitor.visit(this); + } +} diff --git a/src/main/java/li/strolch/model/audit/Audit.java b/src/main/java/li/strolch/model/audit/Audit.java new file mode 100644 index 000000000..d07111fb4 --- /dev/null +++ b/src/main/java/li/strolch/model/audit/Audit.java @@ -0,0 +1,233 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.audit; + +import java.io.Serializable; +import java.util.Date; + +import li.strolch.model.StrolchRootElement; + +/** + * Used to log/audit access to {@link StrolchRootElement} + * + * @author Robert von Burg + */ +public class Audit implements Comparable, Serializable { + + private static final long serialVersionUID = 1L; + + private Long id; + private String username; + private String firstname; + private String lastname; + private Date date; + + private String elementType; + private String elementAccessed; + private Date newVersion; + + private String action; + private AccessType accessType; + + /** + * @return the id + */ + public Long getId() { + return this.id; + } + + /** + * @param id + * the id to set + */ + public void setId(long id) { + this.id = id; + } + + /** + * @return the username + */ + public String getUsername() { + return this.username; + } + + /** + * @param username + * the username to set + */ + public void setUsername(String username) { + this.username = username; + } + + /** + * @return the firstname + */ + public String getFirstname() { + return this.firstname; + } + + /** + * @param firstname + * the firstname to set + */ + public void setFirstname(String firstname) { + this.firstname = firstname; + } + + /** + * @return the lastname + */ + public String getLastname() { + return this.lastname; + } + + /** + * @param lastname + * the lastname to set + */ + public void setLastname(String lastname) { + this.lastname = lastname; + } + + /** + * @return the date + */ + public Date getDate() { + return this.date; + } + + /** + * @param date + * the date to set + */ + public void setDate(Date date) { + this.date = date; + } + + /** + * @return the elementType + */ + public String getElementType() { + return this.elementType; + } + + /** + * @param elementType + * the elementType to set + */ + public void setElementType(String elementType) { + this.elementType = elementType; + } + + /** + * @return the elementAccessed + */ + public String getElementAccessed() { + return this.elementAccessed; + } + + /** + * @param elementAccessed + * the elementAccessed to set + */ + public void setElementAccessed(String elementAccessed) { + this.elementAccessed = elementAccessed; + } + + /** + * @return the newVersion + */ + public Date getNewVersion() { + return this.newVersion; + } + + /** + * @param newVersion + * the newVersion to set + */ + public void setNewVersion(Date newVersion) { + this.newVersion = newVersion; + } + + /** + * @return the action + */ + public String getAction() { + return this.action; + } + + /** + * @param action + * the action to set + */ + public void setAction(String action) { + this.action = action; + } + + /** + * @return the accessType + */ + public AccessType getAccessType() { + return this.accessType; + } + + /** + * @param accessType + * the accessType to set + */ + public void setAccessType(AccessType accessType) { + this.accessType = accessType; + } + + public U accept(AuditVisitor visitor) { + return visitor.visitAudit(this); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.id == null) ? 0 : this.id.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + Audit other = (Audit) obj; + if (this.id == null) { + if (other.id != null) { + return false; + } + } else if (!this.id.equals(other.id)) { + return false; + } + return true; + } + + @Override + public int compareTo(Audit o) { + return getId().compareTo(o.getId()); + } +} diff --git a/src/main/java/li/strolch/model/audit/AuditFromDomReader.java b/src/main/java/li/strolch/model/audit/AuditFromDomReader.java new file mode 100644 index 000000000..123d5903c --- /dev/null +++ b/src/main/java/li/strolch/model/audit/AuditFromDomReader.java @@ -0,0 +1,100 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.audit; + +import java.text.MessageFormat; + +import li.strolch.model.Tags; + +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import ch.eitchnet.utils.dbc.DBC; +import ch.eitchnet.utils.iso8601.ISO8601FormatFactory; + +/** + * @author Robert von Burg + */ +public class AuditFromDomReader { + + public Audit from(Element rootElement) { + + Audit audit = new Audit(); + + String idS = rootElement.getAttribute(Tags.Audit.ID); + DBC.INTERIM.assertNotEmpty("Id must be set!", idS); + audit.setId(Long.valueOf(idS)); + + NodeList childNodes = rootElement.getChildNodes(); + for (int i = 0; i < childNodes.getLength(); i++) { + Node item = childNodes.item(i); + if (!(item instanceof Element)) + continue; + + Element element = (Element) item; + String nodeName = element.getNodeName(); + String txtContent = element.getTextContent(); + + switch (nodeName) { + case Tags.Audit.USERNAME: + audit.setUsername(txtContent); + break; + case Tags.Audit.FIRSTNAME: + audit.setFirstname(txtContent); + break; + case Tags.Audit.LASTNAME: + audit.setLastname(txtContent); + break; + case Tags.Audit.DATE: + audit.setDate(ISO8601FormatFactory.getInstance().getXmlDateFormat().parse(txtContent)); + break; + case Tags.Audit.ELEMENT_TYPE: + audit.setElementType(txtContent); + break; + case Tags.Audit.ELEMENT_ACCESSED: + audit.setElementAccessed(txtContent); + break; + case Tags.Audit.NEW_VERSION: + audit.setNewVersion(ISO8601FormatFactory.getInstance().getXmlDateFormat().parse(txtContent)); + break; + case Tags.Audit.ACTION: + audit.setAction(txtContent); + break; + case Tags.Audit.ACCESS_TYPE: + audit.setAccessType(AccessType.valueOf(txtContent)); + break; + + default: + throw new IllegalArgumentException(MessageFormat.format("Unhandled/Invalid tag {0} for Audit {1}", + nodeName, idS)); + } + } + + String msg = " missing for element with id " + audit.getId(); + DBC.INTERIM.assertNotEmpty("Username" + msg, audit.getUsername()); + DBC.INTERIM.assertNotEmpty("Firstname" + msg, audit.getFirstname()); + DBC.INTERIM.assertNotEmpty("Lastname" + msg, audit.getLastname()); + DBC.INTERIM.assertNotNull("Date" + msg, audit.getDate()); + DBC.INTERIM.assertNotEmpty("ElementType" + msg, audit.getElementType()); + DBC.INTERIM.assertNotEmpty("ElementAccessed" + msg, audit.getElementAccessed()); + //DBC.INTERIM.assertNotNull("NewVersion" + msg, audit.getNewVersion()); + DBC.INTERIM.assertNotEmpty("Action" + msg, audit.getAction()); + DBC.INTERIM.assertNotNull("AccessType" + msg, audit.getAccessType()); + + return audit; + } +} diff --git a/src/main/java/li/strolch/model/audit/AuditQuery.java b/src/main/java/li/strolch/model/audit/AuditQuery.java new file mode 100644 index 000000000..fa5daf1a2 --- /dev/null +++ b/src/main/java/li/strolch/model/audit/AuditQuery.java @@ -0,0 +1,79 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.audit; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Robert von Burg + */ +public class AuditQuery { + + private int maxResults; + + private List selections; + + public AuditQuery() { + this.selections = new ArrayList<>(); + } + + /** + * @return the maxResults + */ + public int getMaxResults() { + return this.maxResults; + } + + /** + * @param maxResults + * the maxResults to set + */ + public void setMaxResults(int maxResults) { + this.maxResults = maxResults; + } + + public ActionSelection action() { + ActionSelection selection = new ActionSelection(this); + this.selections.add(selection); + return selection; + } + + public DateRangeSelection dateRange() { + DateRangeSelection selection = new DateRangeSelection(this); + this.selections.add(selection); + return selection; + } + + public ElementSelection element() { + ElementSelection selection = new ElementSelection(this); + this.selections.add(selection); + return selection; + } + + public IdentitySelection identity() { + IdentitySelection selection = new IdentitySelection(this); + this.selections.add(selection); + return selection; + } + + public void accept(AuditQueryVisitor visitor) { + visitor.visit(this); + for (AuditSelection selection : selections) { + selection.accept(visitor); + } + } +} diff --git a/src/main/java/li/strolch/model/audit/AuditQueryVisitor.java b/src/main/java/li/strolch/model/audit/AuditQueryVisitor.java new file mode 100644 index 000000000..616f75f94 --- /dev/null +++ b/src/main/java/li/strolch/model/audit/AuditQueryVisitor.java @@ -0,0 +1,33 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.audit; + + +/** + * @author Robert von Burg + */ +public interface AuditQueryVisitor { + + public void visit(ElementSelection selection); + + public void visit(IdentitySelection selection); + + public void visit(DateRangeSelection selection); + + public void visit(ActionSelection selection); + + public void visit(AuditQuery auditQuery); +} diff --git a/src/main/java/li/strolch/model/audit/AuditSaxReader.java b/src/main/java/li/strolch/model/audit/AuditSaxReader.java new file mode 100644 index 000000000..5b585ed8d --- /dev/null +++ b/src/main/java/li/strolch/model/audit/AuditSaxReader.java @@ -0,0 +1,25 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.audit; + +import org.xml.sax.helpers.DefaultHandler; + +/** + * @author Robert von Burg + */ +public class AuditSaxReader extends DefaultHandler { + +} diff --git a/src/main/java/li/strolch/model/audit/AuditSelection.java b/src/main/java/li/strolch/model/audit/AuditSelection.java new file mode 100644 index 000000000..f2e1cae63 --- /dev/null +++ b/src/main/java/li/strolch/model/audit/AuditSelection.java @@ -0,0 +1,35 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.audit; + +/** + * @author Robert von Burg + */ +public abstract class AuditSelection { + + private AuditQuery query; + + public AuditSelection(AuditQuery query) { + super(); + this.query = query; + } + + public AuditQuery query() { + return this.query; + } + + public abstract void accept(AuditQueryVisitor visitor); +} diff --git a/src/main/java/li/strolch/model/audit/AuditToDomVisitor.java b/src/main/java/li/strolch/model/audit/AuditToDomVisitor.java new file mode 100644 index 000000000..f187cff84 --- /dev/null +++ b/src/main/java/li/strolch/model/audit/AuditToDomVisitor.java @@ -0,0 +1,66 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.audit; + +import javax.xml.parsers.DocumentBuilder; + +import li.strolch.model.Tags; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import ch.eitchnet.utils.helper.DomUtil; +import ch.eitchnet.utils.iso8601.ISO8601FormatFactory; + +/** + * @author Robert von Burg + */ +public class AuditToDomVisitor implements AuditVisitor { + + @Override + public Document visitAudit(Audit audit) { + DocumentBuilder documentBuilder = DomUtil.createDocumentBuilder(); + Document doc = documentBuilder.getDOMImplementation().createDocument(null, null, null); + + Element auditE = doc.createElement(Tags.AUDIT); + auditE.setAttribute(Tags.Audit.ID, audit.getId().toString()); + + auditE.appendChild(elem(doc, Tags.Audit.USERNAME, audit.getUsername())); + + auditE.appendChild(elem(doc, Tags.Audit.FIRSTNAME, audit.getUsername())); + auditE.appendChild(elem(doc, Tags.Audit.LASTNAME, audit.getUsername())); + auditE.appendChild(elem(doc, Tags.Audit.DATE, ISO8601FormatFactory.getInstance().formatDate(audit.getDate()))); + + auditE.appendChild(elem(doc, Tags.Audit.ELEMENT_TYPE, audit.getElementType())); + auditE.appendChild(elem(doc, Tags.Audit.ELEMENT_ACCESSED, audit.getElementAccessed())); + + if (audit.getNewVersion() != null) + auditE.appendChild(elem(doc, Tags.Audit.NEW_VERSION, + ISO8601FormatFactory.getInstance().formatDate(audit.getNewVersion()))); + + auditE.appendChild(elem(doc, Tags.Audit.ACTION, audit.getAction())); + auditE.appendChild(elem(doc, Tags.Audit.ACCESS_TYPE, audit.getAccessType().name())); + + doc.appendChild(auditE); + return doc; + } + + private Element elem(Document doc, String tag, String txtValue) { + Element element = doc.createElement(tag); + element.setTextContent(txtValue); + return element; + } +} diff --git a/src/main/java/li/strolch/model/audit/AuditVisitor.java b/src/main/java/li/strolch/model/audit/AuditVisitor.java new file mode 100644 index 000000000..002e4d922 --- /dev/null +++ b/src/main/java/li/strolch/model/audit/AuditVisitor.java @@ -0,0 +1,24 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.audit; + +/** + * @author Robert von Burg + */ +public interface AuditVisitor { + + public U visitAudit(Audit audit); +} diff --git a/src/main/java/li/strolch/model/audit/DateRangeSelection.java b/src/main/java/li/strolch/model/audit/DateRangeSelection.java new file mode 100644 index 000000000..18dc3b3cc --- /dev/null +++ b/src/main/java/li/strolch/model/audit/DateRangeSelection.java @@ -0,0 +1,73 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.audit; + +import java.util.Date; + +import ch.eitchnet.utils.collections.DateRange; + +/** + * @author Robert von Burg + */ +public class DateRangeSelection extends AuditSelection { + + private DateRange dateRange; + + public DateRangeSelection(AuditQuery query) { + super(query); + } + + public DateRange from(Date from, boolean inclusive) { + return this.dateRange.from(from, inclusive); + } + + public DateRange to(Date to, boolean inclusive) { + return this.dateRange.to(to, inclusive); + } + + public Date getFromDate() { + return this.dateRange.getFromDate(); + } + + public Date getToDate() { + return this.dateRange.getToDate(); + } + + public boolean isFromBounded() { + return this.dateRange.isFromBounded(); + } + + public boolean isToBounded() { + return this.dateRange.isToBounded(); + } + + public boolean isUnbounded() { + return this.dateRange.isUnbounded(); + } + + public boolean isBounded() { + return this.dateRange.isBounded(); + } + + public boolean contains(Date date) { + return this.dateRange.contains(date); + } + + @Override + public void accept(AuditQueryVisitor visitor) { + visitor.visit(this); + } +} diff --git a/src/main/java/li/strolch/model/audit/ElementSelection.java b/src/main/java/li/strolch/model/audit/ElementSelection.java new file mode 100644 index 000000000..f7f46403f --- /dev/null +++ b/src/main/java/li/strolch/model/audit/ElementSelection.java @@ -0,0 +1,63 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.audit; + +import li.strolch.model.query.StringMatchMode; +import li.strolch.model.query.StringSelection; + +/** + * @author Robert von Burg + */ +public class ElementSelection extends AuditSelection { + + private StringSelection elementTypeSelection; + private StringSelection elementAccessedSelection; + + public ElementSelection(AuditQuery query) { + super(query); + } + + public ElementSelection elementTypes(StringMatchMode matchMode, String... elementTypes) { + this.elementTypeSelection = new StringSelection(matchMode, elementTypes); + return this; + } + + public ElementSelection elementsAccessed(StringMatchMode matchMode, String... elementsAccessed) { + this.elementAccessedSelection = new StringSelection(matchMode, elementsAccessed); + return this; + } + + public StringSelection getElementAccessedSelection() { + return this.elementAccessedSelection; + } + + public StringSelection getElementTypeSelection() { + return this.elementTypeSelection; + } + + public boolean isElementTypesWildcard() { + return this.elementTypeSelection == null || this.elementTypeSelection.isWildCard(); + } + + public boolean isElementsAccessedWildcard() { + return this.elementAccessedSelection == null || this.elementAccessedSelection.isWildCard(); + } + + @Override + public void accept(AuditQueryVisitor visitor) { + visitor.visit(this); + } +} diff --git a/src/main/java/li/strolch/model/audit/IdentitySelection.java b/src/main/java/li/strolch/model/audit/IdentitySelection.java new file mode 100644 index 000000000..4f4728aad --- /dev/null +++ b/src/main/java/li/strolch/model/audit/IdentitySelection.java @@ -0,0 +1,86 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.audit; + +import li.strolch.model.query.StringMatchMode; +import li.strolch.model.query.StringSelection; + +/** + * @author Robert von Burg + */ +public class IdentitySelection extends AuditSelection { + + private StringSelection usernameSelection; + private StringSelection firstnameSelection; + private StringSelection lastnameSelection; + + public IdentitySelection(AuditQuery query) { + super(query); + } + + public IdentitySelection usernames(StringMatchMode matchMode, String... usernames) { + this.usernameSelection = new StringSelection(matchMode, usernames); + return this; + } + + public IdentitySelection firstnames(StringMatchMode matchMode, String... firstnames) { + this.firstnameSelection = new StringSelection(matchMode, firstnames); + return this; + } + + public IdentitySelection lastnames(StringMatchMode matchMode, String... lastnames) { + this.lastnameSelection = new StringSelection(matchMode, lastnames); + return this; + } + + /** + * @return the firstnameSelection + */ + public StringSelection getFirstnameSelection() { + return this.firstnameSelection; + } + + /** + * @return the lastnameSelection + */ + public StringSelection getLastnameSelection() { + return this.lastnameSelection; + } + + /** + * @return the usernameSelection + */ + public StringSelection getUsernameSelection() { + return this.usernameSelection; + } + + public boolean isFirstnameWildcard() { + return this.firstnameSelection == null || this.firstnameSelection.isWildCard(); + } + + public boolean isLastnameWildcard() { + return this.lastnameSelection == null || this.lastnameSelection.isWildCard(); + } + + public boolean isUsernameWildcard() { + return this.usernameSelection == null || this.usernameSelection.isWildCard(); + } + + @Override + public void accept(AuditQueryVisitor visitor) { + visitor.visit(this); + } +} diff --git a/src/main/java/li/strolch/model/audit/NoStrategyAuditVisitor.java b/src/main/java/li/strolch/model/audit/NoStrategyAuditVisitor.java new file mode 100644 index 000000000..5cede2cdb --- /dev/null +++ b/src/main/java/li/strolch/model/audit/NoStrategyAuditVisitor.java @@ -0,0 +1,27 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.audit; + +/** + * @author Robert von Burg + */ +public class NoStrategyAuditVisitor implements AuditVisitor { + + @Override + public Audit visitAudit(Audit audit) { + return audit; + } +} diff --git a/src/main/java/li/strolch/model/query/StringMatchMode.java b/src/main/java/li/strolch/model/query/StringMatchMode.java new file mode 100644 index 000000000..2a2ca25e8 --- /dev/null +++ b/src/main/java/li/strolch/model/query/StringMatchMode.java @@ -0,0 +1,48 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.query; + +/** + * @author Robert von Burg + */ +public enum StringMatchMode { + EQUALS_CASE_SENSITIVE(true, true), + EQUALS_CASE_INSENSITIVE(true, false), + CONTAINS_CASE_SENSITIVE(false, true), + CONTAINS_CASE_INSENSITIVE(false, false); + + private final boolean equals; + private final boolean caseSensitve; + + private StringMatchMode(boolean equals, boolean caseSensitive) { + this.equals = equals; + this.caseSensitve = caseSensitive; + } + + /** + * @return the caseSensitve + */ + public boolean isCaseSensitve() { + return this.caseSensitve; + } + + /** + * @return the equals + */ + public boolean isEquals() { + return this.equals; + } +} diff --git a/src/main/java/li/strolch/model/query/StringSelection.java b/src/main/java/li/strolch/model/query/StringSelection.java new file mode 100644 index 000000000..7077ce747 --- /dev/null +++ b/src/main/java/li/strolch/model/query/StringSelection.java @@ -0,0 +1,75 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.query; + +/** + * @author Robert von Burg + */ +public class StringSelection { + + private StringMatchMode matchMode; + private String[] values; + + public StringSelection() { + // + } + + /** + * @param matchMode + * @param values + */ + public StringSelection(StringMatchMode matchMode, String[] values) { + this.matchMode = matchMode; + this.values = values; + } + + /** + * @return the matchMode + */ + public StringMatchMode getMatchMode() { + return this.matchMode; + } + + /** + * @param matchMode + * the matchMode to set + */ + public void setMatchMode(StringMatchMode matchMode) { + this.matchMode = matchMode; + } + + /** + * @return the values + */ + public String[] getValues() { + return this.values; + } + + /** + * @param values + * the values to set + */ + public void setValues(String... values) { + this.values = values; + } + + /** + * @return + */ + public boolean isWildCard() { + return this.values == null || this.values.length == 0; + } +} diff --git a/src/main/java/li/strolch/model/visitor/ElementTypeVisitor.java b/src/main/java/li/strolch/model/visitor/ElementTypeVisitor.java new file mode 100644 index 000000000..74a8621e3 --- /dev/null +++ b/src/main/java/li/strolch/model/visitor/ElementTypeVisitor.java @@ -0,0 +1,36 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.visitor; + +import li.strolch.model.Order; +import li.strolch.model.Resource; +import li.strolch.model.Tags; + +/** + * @author Robert von Burg + */ +public class ElementTypeVisitor implements StrolchRootElementVisitor { + + @Override + public String visitOrder(Order order) { + return Tags.ORDER; + } + + @Override + public String visitResource(Resource resource) { + return Tags.RESOURCE; + } +} diff --git a/src/main/java/li/strolch/model/visitor/StrolchRootElementVisitor.java b/src/main/java/li/strolch/model/visitor/StrolchRootElementVisitor.java index c75f5a107..d24cbebd9 100644 --- a/src/main/java/li/strolch/model/visitor/StrolchRootElementVisitor.java +++ b/src/main/java/li/strolch/model/visitor/StrolchRootElementVisitor.java @@ -21,9 +21,9 @@ import li.strolch.model.Resource; /** * @author Robert von Burg */ -public interface StrolchRootElementVisitor extends StrolchVisitor { +public interface StrolchRootElementVisitor extends StrolchVisitor { - public T visitOrder(Order order); + public T visitOrder(Order order); - public T visitResource(Resource resource); + public T visitResource(Resource resource); } From c2fc8474f621bc2dce33a48dfd2ade298a09a221 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sun, 24 Aug 2014 17:23:38 +0200 Subject: [PATCH 80/88] [Project] set version to 1.0.0-SNAPSHOT --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 381ccd4bf..a07b6b593 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ li.strolch li.strolch.parent - 0.1.0-SNAPSHOT + 1.0.0-SNAPSHOT ../li.strolch.parent/pom.xml From e9fc3d7ac85f3b93b057d0ba42b83c6316885594 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 25 Aug 2014 22:52:18 +0200 Subject: [PATCH 81/88] [Major] moved StringMatchMode to ch.eitchnet.utils --- .../strolch/model/audit/ActionSelection.java | 2 +- .../strolch/model/audit/ElementSelection.java | 2 +- .../model/audit/IdentitySelection.java | 2 +- .../li/strolch/model/query/NameSelection.java | 30 +++++------- .../model/query/ParameterSelection.java | 30 ++++-------- .../strolch/model/query/StringMatchMode.java | 48 ------------------- .../strolch/model/query/StringSelection.java | 2 + 7 files changed, 25 insertions(+), 91 deletions(-) delete mode 100644 src/main/java/li/strolch/model/query/StringMatchMode.java diff --git a/src/main/java/li/strolch/model/audit/ActionSelection.java b/src/main/java/li/strolch/model/audit/ActionSelection.java index 2f01ae89c..aba3851fb 100644 --- a/src/main/java/li/strolch/model/audit/ActionSelection.java +++ b/src/main/java/li/strolch/model/audit/ActionSelection.java @@ -15,7 +15,7 @@ */ package li.strolch.model.audit; -import li.strolch.model.query.StringMatchMode; +import ch.eitchnet.utils.StringMatchMode; import li.strolch.model.query.StringSelection; /** diff --git a/src/main/java/li/strolch/model/audit/ElementSelection.java b/src/main/java/li/strolch/model/audit/ElementSelection.java index f7f46403f..a34535f81 100644 --- a/src/main/java/li/strolch/model/audit/ElementSelection.java +++ b/src/main/java/li/strolch/model/audit/ElementSelection.java @@ -15,7 +15,7 @@ */ package li.strolch.model.audit; -import li.strolch.model.query.StringMatchMode; +import ch.eitchnet.utils.StringMatchMode; import li.strolch.model.query.StringSelection; /** diff --git a/src/main/java/li/strolch/model/audit/IdentitySelection.java b/src/main/java/li/strolch/model/audit/IdentitySelection.java index 4f4728aad..ddca5bf7a 100644 --- a/src/main/java/li/strolch/model/audit/IdentitySelection.java +++ b/src/main/java/li/strolch/model/audit/IdentitySelection.java @@ -15,7 +15,7 @@ */ package li.strolch.model.audit; -import li.strolch.model.query.StringMatchMode; +import ch.eitchnet.utils.StringMatchMode; import li.strolch.model.query.StringSelection; /** diff --git a/src/main/java/li/strolch/model/query/NameSelection.java b/src/main/java/li/strolch/model/query/NameSelection.java index 9009655a7..9b618563d 100644 --- a/src/main/java/li/strolch/model/query/NameSelection.java +++ b/src/main/java/li/strolch/model/query/NameSelection.java @@ -15,20 +15,23 @@ */ package li.strolch.model.query; +import ch.eitchnet.utils.StringMatchMode; + /** * @author Robert von Burg */ public class NameSelection extends StrolchElementSelection { + private StringMatchMode matchMode; private String name; - private boolean contains; - private boolean caseInsensitive; /** * @param name + * @param matchMode */ - public NameSelection(String name) { + public NameSelection(String name, StringMatchMode matchMode) { this.name = name; + this.matchMode = matchMode; } /** @@ -38,22 +41,11 @@ public class NameSelection extends StrolchElementSelection { return this.name; } - public boolean isContains() { - return this.contains; - } - - public boolean isCaseInsensitive() { - return this.caseInsensitive; - } - - public NameSelection contains(boolean contains) { - this.contains = contains; - return this; - } - - public NameSelection caseInsensitive(boolean caseInsensitive) { - this.caseInsensitive = true; - return this; + /** + * @return the matchMode + */ + public StringMatchMode getMatchMode() { + return this.matchMode; } @Override diff --git a/src/main/java/li/strolch/model/query/ParameterSelection.java b/src/main/java/li/strolch/model/query/ParameterSelection.java index 9829d51b9..c1835b032 100644 --- a/src/main/java/li/strolch/model/query/ParameterSelection.java +++ b/src/main/java/li/strolch/model/query/ParameterSelection.java @@ -18,6 +18,7 @@ package li.strolch.model.query; import java.util.Date; import java.util.List; +import ch.eitchnet.utils.StringMatchMode; import ch.eitchnet.utils.dbc.DBC; /** @@ -71,8 +72,9 @@ public abstract class ParameterSelection implements Selection { public abstract void accept(ParameterSelectionVisitor visitor); - public static StringParameterSelection stringSelection(String bagKey, String paramKey, String value) { - return new StringParameterSelection(bagKey, paramKey, value); + public static StringParameterSelection stringSelection(String bagKey, String paramKey, String value, + StringMatchMode matchMode) { + return new StringParameterSelection(bagKey, paramKey, value, matchMode); } public static IntegerParameterSelection integerSelection(String bagKey, String paramKey, int value) { @@ -105,35 +107,21 @@ public abstract class ParameterSelection implements Selection { public static class StringParameterSelection extends ParameterSelection { + private StringMatchMode matchMode; private String value; - private boolean contains; - private boolean caseInsensitive; - public StringParameterSelection(String bagKey, String paramKey, String value) { + public StringParameterSelection(String bagKey, String paramKey, String value, StringMatchMode matchMode) { super(bagKey, paramKey); this.value = value; + this.matchMode = matchMode; } public String getValue() { return this.value; } - public boolean isContains() { - return this.contains; - } - - public boolean isCaseInsensitive() { - return this.caseInsensitive; - } - - public StringParameterSelection contains(boolean contains) { - this.contains = contains; - return this; - } - - public StringParameterSelection caseInsensitive(boolean caseInsensitive) { - this.caseInsensitive = true; - return this; + public StringMatchMode getMatchMode() { + return this.matchMode; } @Override diff --git a/src/main/java/li/strolch/model/query/StringMatchMode.java b/src/main/java/li/strolch/model/query/StringMatchMode.java deleted file mode 100644 index 2a2ca25e8..000000000 --- a/src/main/java/li/strolch/model/query/StringMatchMode.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2013 Robert von Burg - * - * 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 li.strolch.model.query; - -/** - * @author Robert von Burg - */ -public enum StringMatchMode { - EQUALS_CASE_SENSITIVE(true, true), - EQUALS_CASE_INSENSITIVE(true, false), - CONTAINS_CASE_SENSITIVE(false, true), - CONTAINS_CASE_INSENSITIVE(false, false); - - private final boolean equals; - private final boolean caseSensitve; - - private StringMatchMode(boolean equals, boolean caseSensitive) { - this.equals = equals; - this.caseSensitve = caseSensitive; - } - - /** - * @return the caseSensitve - */ - public boolean isCaseSensitve() { - return this.caseSensitve; - } - - /** - * @return the equals - */ - public boolean isEquals() { - return this.equals; - } -} diff --git a/src/main/java/li/strolch/model/query/StringSelection.java b/src/main/java/li/strolch/model/query/StringSelection.java index 7077ce747..b66734c48 100644 --- a/src/main/java/li/strolch/model/query/StringSelection.java +++ b/src/main/java/li/strolch/model/query/StringSelection.java @@ -15,6 +15,8 @@ */ package li.strolch.model.query; +import ch.eitchnet.utils.StringMatchMode; + /** * @author Robert von Burg */ From b8bfaf8408c46f866b77d552c9e7d5d04b8c5f5a Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Tue, 26 Aug 2014 22:02:20 +0200 Subject: [PATCH 82/88] [Major] Using DateRange in DateSelector --- .../strolch/model/audit/ActionSelection.java | 6 ++- .../model/audit/DateRangeSelection.java | 1 + .../strolch/model/audit/ElementSelection.java | 6 ++- .../model/audit/IdentitySelection.java | 6 ++- .../li/strolch/model/query/DateSelection.java | 50 +++++++++++++++++-- .../strolch/model/query/StateSelection.java | 11 ++-- 6 files changed, 67 insertions(+), 13 deletions(-) diff --git a/src/main/java/li/strolch/model/audit/ActionSelection.java b/src/main/java/li/strolch/model/audit/ActionSelection.java index aba3851fb..6a85a9627 100644 --- a/src/main/java/li/strolch/model/audit/ActionSelection.java +++ b/src/main/java/li/strolch/model/audit/ActionSelection.java @@ -15,8 +15,8 @@ */ package li.strolch.model.audit; -import ch.eitchnet.utils.StringMatchMode; import li.strolch.model.query.StringSelection; +import ch.eitchnet.utils.StringMatchMode; /** * @author Robert von Burg @@ -44,6 +44,10 @@ public class ActionSelection extends AuditSelection { return this.accessTypes; } + public StringSelection getActionSelection() { + return this.actionSelection; + } + public boolean isWildcardActionType() { return this.accessTypes == null || this.accessTypes.length == 0; } diff --git a/src/main/java/li/strolch/model/audit/DateRangeSelection.java b/src/main/java/li/strolch/model/audit/DateRangeSelection.java index 18dc3b3cc..558210fce 100644 --- a/src/main/java/li/strolch/model/audit/DateRangeSelection.java +++ b/src/main/java/li/strolch/model/audit/DateRangeSelection.java @@ -28,6 +28,7 @@ public class DateRangeSelection extends AuditSelection { public DateRangeSelection(AuditQuery query) { super(query); + this.dateRange = new DateRange(); } public DateRange from(Date from, boolean inclusive) { diff --git a/src/main/java/li/strolch/model/audit/ElementSelection.java b/src/main/java/li/strolch/model/audit/ElementSelection.java index a34535f81..226e4f96c 100644 --- a/src/main/java/li/strolch/model/audit/ElementSelection.java +++ b/src/main/java/li/strolch/model/audit/ElementSelection.java @@ -15,8 +15,8 @@ */ package li.strolch.model.audit; -import ch.eitchnet.utils.StringMatchMode; import li.strolch.model.query.StringSelection; +import ch.eitchnet.utils.StringMatchMode; /** * @author Robert von Burg @@ -56,6 +56,10 @@ public class ElementSelection extends AuditSelection { return this.elementAccessedSelection == null || this.elementAccessedSelection.isWildCard(); } + public boolean isWildcard() { + return this.isElementsAccessedWildcard() && this.isElementTypesWildcard(); + } + @Override public void accept(AuditQueryVisitor visitor) { visitor.visit(this); diff --git a/src/main/java/li/strolch/model/audit/IdentitySelection.java b/src/main/java/li/strolch/model/audit/IdentitySelection.java index ddca5bf7a..899442ff6 100644 --- a/src/main/java/li/strolch/model/audit/IdentitySelection.java +++ b/src/main/java/li/strolch/model/audit/IdentitySelection.java @@ -15,8 +15,8 @@ */ package li.strolch.model.audit; -import ch.eitchnet.utils.StringMatchMode; import li.strolch.model.query.StringSelection; +import ch.eitchnet.utils.StringMatchMode; /** * @author Robert von Burg @@ -79,6 +79,10 @@ public class IdentitySelection extends AuditSelection { return this.usernameSelection == null || this.usernameSelection.isWildCard(); } + public boolean isWildcard() { + return isFirstnameWildcard() && isLastnameWildcard() && isUsernameWildcard(); + } + @Override public void accept(AuditQueryVisitor visitor) { visitor.visit(this); diff --git a/src/main/java/li/strolch/model/query/DateSelection.java b/src/main/java/li/strolch/model/query/DateSelection.java index e6e6142a7..ea3ef2645 100644 --- a/src/main/java/li/strolch/model/query/DateSelection.java +++ b/src/main/java/li/strolch/model/query/DateSelection.java @@ -17,19 +17,59 @@ package li.strolch.model.query; import java.util.Date; +import ch.eitchnet.utils.collections.DateRange; + /** * @author Robert von Burg */ public class DateSelection extends OrderSelection { - private Date date; + private DateRange dateRange; - public DateSelection(Date date) { - this.date = date; + public DateSelection() { + this.dateRange = new DateRange(); } - public Date getDate() { - return this.date; + public DateSelection from(Date from, boolean inclusive) { + this.dateRange.from(from, inclusive); + return this; + } + + public DateSelection to(Date to, boolean inclusive) { + this.dateRange.to(to, inclusive); + return this; + } + + public Date getFromDate() { + return this.dateRange.getFromDate(); + } + + public Date getToDate() { + return this.dateRange.getToDate(); + } + + public boolean isFromBounded() { + return this.dateRange.isFromBounded(); + } + + public boolean isToBounded() { + return this.dateRange.isToBounded(); + } + + public boolean isUnbounded() { + return this.dateRange.isUnbounded(); + } + + public boolean isBounded() { + return this.dateRange.isBounded(); + } + + public boolean contains(Date date) { + return this.dateRange.contains(date); + } + + public DateRange getDateRange() { + return this.dateRange; } @Override diff --git a/src/main/java/li/strolch/model/query/StateSelection.java b/src/main/java/li/strolch/model/query/StateSelection.java index 542776e99..8c4aae742 100644 --- a/src/main/java/li/strolch/model/query/StateSelection.java +++ b/src/main/java/li/strolch/model/query/StateSelection.java @@ -19,9 +19,8 @@ import li.strolch.model.State; /** * @author Robert von Burg - * */ -public class StateSelection { +public class StateSelection extends OrderSelection { private State state; @@ -29,10 +28,12 @@ public class StateSelection { this.state = state; } - /** - * @return the state - */ public State getState() { return this.state; } + + @Override + public void accept(OrderSelectionVisitor visitor) { + visitor.visit(this); + } } From 7cb7c2749c53d882aa7f36c77fbe4645cf698b56 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 28 Aug 2014 21:45:03 +0200 Subject: [PATCH 83/88] [Major] Implemented AuditQuery --- .../li/strolch/model/audit/AuditQuery.java | 35 ++++----- .../model/audit/AuditQueryVisitor.java | 3 - .../model/audit/DateRangeSelection.java | 74 ------------------- .../strolch/model/audit/ElementSelection.java | 18 ----- .../li/strolch/model/query/Navigation.java | 2 - .../li/strolch/model/query/Selection.java | 2 +- .../strolch/model/query/StringSelection.java | 8 ++ 7 files changed, 24 insertions(+), 118 deletions(-) delete mode 100644 src/main/java/li/strolch/model/audit/DateRangeSelection.java diff --git a/src/main/java/li/strolch/model/audit/AuditQuery.java b/src/main/java/li/strolch/model/audit/AuditQuery.java index fa5daf1a2..d752c0c3d 100644 --- a/src/main/java/li/strolch/model/audit/AuditQuery.java +++ b/src/main/java/li/strolch/model/audit/AuditQuery.java @@ -18,32 +18,31 @@ package li.strolch.model.audit; import java.util.ArrayList; import java.util.List; +import ch.eitchnet.utils.collections.DateRange; +import ch.eitchnet.utils.dbc.DBC; + /** * @author Robert von Burg */ public class AuditQuery { - private int maxResults; - + private String elementTypeSelection; private List selections; + private DateRange dateRange; - public AuditQuery() { + public AuditQuery(String elementTypeSelection, DateRange dateRange) { + DBC.PRE.assertFalse("dateRange may not be unbounded!", dateRange.isUnbounded()); + this.elementTypeSelection = elementTypeSelection; + this.dateRange = dateRange; this.selections = new ArrayList<>(); } - /** - * @return the maxResults - */ - public int getMaxResults() { - return this.maxResults; + public String getElementTypeSelection() { + return this.elementTypeSelection; } - /** - * @param maxResults - * the maxResults to set - */ - public void setMaxResults(int maxResults) { - this.maxResults = maxResults; + public DateRange getDateRange() { + return this.dateRange; } public ActionSelection action() { @@ -52,12 +51,6 @@ public class AuditQuery { return selection; } - public DateRangeSelection dateRange() { - DateRangeSelection selection = new DateRangeSelection(this); - this.selections.add(selection); - return selection; - } - public ElementSelection element() { ElementSelection selection = new ElementSelection(this); this.selections.add(selection); @@ -71,6 +64,8 @@ public class AuditQuery { } public void accept(AuditQueryVisitor visitor) { + DBC.PRE.assertNotNull("No elementTypeSelection (navigation) set!", this.elementTypeSelection); //$NON-NLS-1$ + DBC.PRE.assertNotNull("No dateRange set!", this.dateRange); //$NON-NLS-1$ visitor.visit(this); for (AuditSelection selection : selections) { selection.accept(visitor); diff --git a/src/main/java/li/strolch/model/audit/AuditQueryVisitor.java b/src/main/java/li/strolch/model/audit/AuditQueryVisitor.java index 616f75f94..03fc601de 100644 --- a/src/main/java/li/strolch/model/audit/AuditQueryVisitor.java +++ b/src/main/java/li/strolch/model/audit/AuditQueryVisitor.java @@ -15,7 +15,6 @@ */ package li.strolch.model.audit; - /** * @author Robert von Burg */ @@ -25,8 +24,6 @@ public interface AuditQueryVisitor { public void visit(IdentitySelection selection); - public void visit(DateRangeSelection selection); - public void visit(ActionSelection selection); public void visit(AuditQuery auditQuery); diff --git a/src/main/java/li/strolch/model/audit/DateRangeSelection.java b/src/main/java/li/strolch/model/audit/DateRangeSelection.java deleted file mode 100644 index 558210fce..000000000 --- a/src/main/java/li/strolch/model/audit/DateRangeSelection.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2013 Robert von Burg - * - * 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 li.strolch.model.audit; - -import java.util.Date; - -import ch.eitchnet.utils.collections.DateRange; - -/** - * @author Robert von Burg - */ -public class DateRangeSelection extends AuditSelection { - - private DateRange dateRange; - - public DateRangeSelection(AuditQuery query) { - super(query); - this.dateRange = new DateRange(); - } - - public DateRange from(Date from, boolean inclusive) { - return this.dateRange.from(from, inclusive); - } - - public DateRange to(Date to, boolean inclusive) { - return this.dateRange.to(to, inclusive); - } - - public Date getFromDate() { - return this.dateRange.getFromDate(); - } - - public Date getToDate() { - return this.dateRange.getToDate(); - } - - public boolean isFromBounded() { - return this.dateRange.isFromBounded(); - } - - public boolean isToBounded() { - return this.dateRange.isToBounded(); - } - - public boolean isUnbounded() { - return this.dateRange.isUnbounded(); - } - - public boolean isBounded() { - return this.dateRange.isBounded(); - } - - public boolean contains(Date date) { - return this.dateRange.contains(date); - } - - @Override - public void accept(AuditQueryVisitor visitor) { - visitor.visit(this); - } -} diff --git a/src/main/java/li/strolch/model/audit/ElementSelection.java b/src/main/java/li/strolch/model/audit/ElementSelection.java index 226e4f96c..74b78975b 100644 --- a/src/main/java/li/strolch/model/audit/ElementSelection.java +++ b/src/main/java/li/strolch/model/audit/ElementSelection.java @@ -23,18 +23,12 @@ import ch.eitchnet.utils.StringMatchMode; */ public class ElementSelection extends AuditSelection { - private StringSelection elementTypeSelection; private StringSelection elementAccessedSelection; public ElementSelection(AuditQuery query) { super(query); } - public ElementSelection elementTypes(StringMatchMode matchMode, String... elementTypes) { - this.elementTypeSelection = new StringSelection(matchMode, elementTypes); - return this; - } - public ElementSelection elementsAccessed(StringMatchMode matchMode, String... elementsAccessed) { this.elementAccessedSelection = new StringSelection(matchMode, elementsAccessed); return this; @@ -44,22 +38,10 @@ public class ElementSelection extends AuditSelection { return this.elementAccessedSelection; } - public StringSelection getElementTypeSelection() { - return this.elementTypeSelection; - } - - public boolean isElementTypesWildcard() { - return this.elementTypeSelection == null || this.elementTypeSelection.isWildCard(); - } - public boolean isElementsAccessedWildcard() { return this.elementAccessedSelection == null || this.elementAccessedSelection.isWildCard(); } - public boolean isWildcard() { - return this.isElementsAccessedWildcard() && this.isElementTypesWildcard(); - } - @Override public void accept(AuditQueryVisitor visitor) { visitor.visit(this); diff --git a/src/main/java/li/strolch/model/query/Navigation.java b/src/main/java/li/strolch/model/query/Navigation.java index 3ddb304fe..b184bdd02 100644 --- a/src/main/java/li/strolch/model/query/Navigation.java +++ b/src/main/java/li/strolch/model/query/Navigation.java @@ -17,10 +17,8 @@ package li.strolch.model.query; /** * @author Robert von Burg - * */ public interface Navigation { - // marker interface public void accept(QueryVisitor visitor); } diff --git a/src/main/java/li/strolch/model/query/Selection.java b/src/main/java/li/strolch/model/query/Selection.java index dd930ec6a..7d720035e 100644 --- a/src/main/java/li/strolch/model/query/Selection.java +++ b/src/main/java/li/strolch/model/query/Selection.java @@ -21,6 +21,6 @@ package li.strolch.model.query; public interface Selection { public void accept(QueryVisitor visitor); - + public boolean hasSelection(); } diff --git a/src/main/java/li/strolch/model/query/StringSelection.java b/src/main/java/li/strolch/model/query/StringSelection.java index b66734c48..8fa00902a 100644 --- a/src/main/java/li/strolch/model/query/StringSelection.java +++ b/src/main/java/li/strolch/model/query/StringSelection.java @@ -74,4 +74,12 @@ public class StringSelection { public boolean isWildCard() { return this.values == null || this.values.length == 0; } + + public boolean matches(String value) { + for (String sel : values) { + if (this.matchMode.matches(value, sel)) + return true; + } + return false; + } } From 352a702c1514412653310247b100e8b007e3210d Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 4 Sep 2014 20:30:35 +0200 Subject: [PATCH 84/88] [New] Implemented param null selector and ParameterBagSelector --- .../model/query/OrderSelectionVisitor.java | 2 +- .../model/query/ParameterBagSelection.java | 70 +++++++++++++++++++ .../model/query/ParameterSelection.java | 16 +++++ .../query/ParameterSelectionVisitor.java | 5 +- .../model/query/ResourceQueryVisitor.java | 3 +- .../StrolchRootElementSelectionVisitor.java | 28 ++++++++ 6 files changed, 120 insertions(+), 4 deletions(-) create mode 100644 src/main/java/li/strolch/model/query/ParameterBagSelection.java create mode 100644 src/main/java/li/strolch/model/query/StrolchRootElementSelectionVisitor.java diff --git a/src/main/java/li/strolch/model/query/OrderSelectionVisitor.java b/src/main/java/li/strolch/model/query/OrderSelectionVisitor.java index 700208027..6f3c36349 100644 --- a/src/main/java/li/strolch/model/query/OrderSelectionVisitor.java +++ b/src/main/java/li/strolch/model/query/OrderSelectionVisitor.java @@ -19,7 +19,7 @@ package li.strolch.model.query; * @author Robert von Burg * */ -public interface OrderSelectionVisitor extends StrolchElementSelectionVisitor { +public interface OrderSelectionVisitor extends StrolchRootElementSelectionVisitor { public void visit(DateSelection selection); diff --git a/src/main/java/li/strolch/model/query/ParameterBagSelection.java b/src/main/java/li/strolch/model/query/ParameterBagSelection.java new file mode 100644 index 000000000..3ed626da0 --- /dev/null +++ b/src/main/java/li/strolch/model/query/ParameterBagSelection.java @@ -0,0 +1,70 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.query; + +/** + * @author Robert von Burg + */ +public class ParameterBagSelection implements Selection { + + private String bagKey; + + public ParameterBagSelection(String bagKey) { + this.bagKey = bagKey; + } + + /** + * @return the bagKey + */ + public String getBagKey() { + return this.bagKey; + } + + @Override + public boolean hasSelection() { + return true; + } + + @Override + public void accept(QueryVisitor visitor) { + accept((StrolchRootElementSelectionVisitor) visitor); + } + + public void accept(StrolchRootElementSelectionVisitor visitor) { + visitor.visit(this); + } + + @SuppressWarnings("nls") + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append(getClass().getSimpleName() + " [bagKey="); + builder.append(this.bagKey); + builder.append("]"); + return builder.toString(); + } + + public static class NullParameterBagSelection extends ParameterBagSelection { + + public NullParameterBagSelection(String bagKey) { + super(bagKey); + } + + public void accept(StrolchRootElementSelectionVisitor visitor) { + visitor.visit(this); + } + } +} diff --git a/src/main/java/li/strolch/model/query/ParameterSelection.java b/src/main/java/li/strolch/model/query/ParameterSelection.java index c1835b032..d6742d54c 100644 --- a/src/main/java/li/strolch/model/query/ParameterSelection.java +++ b/src/main/java/li/strolch/model/query/ParameterSelection.java @@ -105,6 +105,22 @@ public abstract class ParameterSelection implements Selection { return new StringListParameterSelection(bagKey, paramKey, value); } + public static NullParameterSelection nullSelection(String bagKey, String paramKey) { + return new NullParameterSelection(bagKey, paramKey); + } + + public static class NullParameterSelection extends ParameterSelection { + + public NullParameterSelection(String bagKey, String paramKey) { + super(bagKey, paramKey); + } + + @Override + public void accept(ParameterSelectionVisitor visitor) { + visitor.visit(this); + } + } + public static class StringParameterSelection extends ParameterSelection { private StringMatchMode matchMode; diff --git a/src/main/java/li/strolch/model/query/ParameterSelectionVisitor.java b/src/main/java/li/strolch/model/query/ParameterSelectionVisitor.java index e6b5b2e8d..3b53f54f6 100644 --- a/src/main/java/li/strolch/model/query/ParameterSelectionVisitor.java +++ b/src/main/java/li/strolch/model/query/ParameterSelectionVisitor.java @@ -21,6 +21,7 @@ import li.strolch.model.query.ParameterSelection.DateRangeParameterSelection; import li.strolch.model.query.ParameterSelection.FloatParameterSelection; import li.strolch.model.query.ParameterSelection.IntegerParameterSelection; import li.strolch.model.query.ParameterSelection.LongParameterSelection; +import li.strolch.model.query.ParameterSelection.NullParameterSelection; import li.strolch.model.query.ParameterSelection.StringListParameterSelection; import li.strolch.model.query.ParameterSelection.StringParameterSelection; @@ -40,8 +41,10 @@ public interface ParameterSelectionVisitor extends QueryVisitor { public void visit(FloatParameterSelection selection); public void visit(DateParameterSelection selection); - + public void visit(DateRangeParameterSelection selection); public void visit(StringListParameterSelection selection); + + public void visit(NullParameterSelection nullParameterSelection); } diff --git a/src/main/java/li/strolch/model/query/ResourceQueryVisitor.java b/src/main/java/li/strolch/model/query/ResourceQueryVisitor.java index 850b6950c..867e0b344 100644 --- a/src/main/java/li/strolch/model/query/ResourceQueryVisitor.java +++ b/src/main/java/li/strolch/model/query/ResourceQueryVisitor.java @@ -17,9 +17,8 @@ package li.strolch.model.query; /** * @author Robert von Burg - * */ -public interface ResourceQueryVisitor extends StrolchElementSelectionVisitor, ParameterSelectionVisitor { +public interface ResourceQueryVisitor extends StrolchRootElementSelectionVisitor, ParameterSelectionVisitor { // marker interface } diff --git a/src/main/java/li/strolch/model/query/StrolchRootElementSelectionVisitor.java b/src/main/java/li/strolch/model/query/StrolchRootElementSelectionVisitor.java new file mode 100644 index 000000000..3a2c3cace --- /dev/null +++ b/src/main/java/li/strolch/model/query/StrolchRootElementSelectionVisitor.java @@ -0,0 +1,28 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.query; + +import li.strolch.model.query.ParameterBagSelection.NullParameterBagSelection; + +/** + * @author Robert von Burg + */ +public interface StrolchRootElementSelectionVisitor extends StrolchElementSelectionVisitor { + + public void visit(ParameterBagSelection selection); + + public void visit(NullParameterBagSelection selection); +} From 523d44c41e8a0f8c129bc804da53fa6b2aa31ecd Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 8 Sep 2014 13:35:47 +0200 Subject: [PATCH 85/88] [New] Added privilege checking for StrolchQueries --- pom.xml | 4 + .../li/strolch/model/audit/AuditQuery.java | 19 +++- .../li/strolch/model/query/OrderQuery.java | 2 +- .../java/li/strolch/model/query/Query.java | 25 ----- .../li/strolch/model/query/ResourceQuery.java | 2 +- .../model/query/StrolchElementQuery.java | 103 ++++++++++++++++++ .../li/strolch/model/query/StrolchQuery.java | 67 +----------- 7 files changed, 130 insertions(+), 92 deletions(-) delete mode 100644 src/main/java/li/strolch/model/query/Query.java create mode 100644 src/main/java/li/strolch/model/query/StrolchElementQuery.java diff --git a/pom.xml b/pom.xml index a07b6b593..e34d5eefe 100644 --- a/pom.xml +++ b/pom.xml @@ -32,6 +32,10 @@ ch.eitchnet ch.eitchnet.utils
    + + ch.eitchnet + ch.eitchnet.privilege + diff --git a/src/main/java/li/strolch/model/audit/AuditQuery.java b/src/main/java/li/strolch/model/audit/AuditQuery.java index d752c0c3d..840d8f785 100644 --- a/src/main/java/li/strolch/model/audit/AuditQuery.java +++ b/src/main/java/li/strolch/model/audit/AuditQuery.java @@ -18,13 +18,14 @@ package li.strolch.model.audit; import java.util.ArrayList; import java.util.List; +import li.strolch.model.query.StrolchQuery; import ch.eitchnet.utils.collections.DateRange; import ch.eitchnet.utils.dbc.DBC; /** * @author Robert von Burg */ -public class AuditQuery { +public class AuditQuery implements StrolchQuery { private String elementTypeSelection; private List selections; @@ -71,4 +72,20 @@ public class AuditQuery { selection.accept(visitor); } } + + /** + * @see ch.eitchnet.privilege.model.Restrictable#getPrivilegeName() + */ + @Override + public String getPrivilegeName() { + return StrolchQuery.class.getName(); + } + + /** + * @see ch.eitchnet.privilege.model.Restrictable#getPrivilegeValue() + */ + @Override + public Object getPrivilegeValue() { + return getClass().getName(); + } } diff --git a/src/main/java/li/strolch/model/query/OrderQuery.java b/src/main/java/li/strolch/model/query/OrderQuery.java index 68ff20094..b7d3347c9 100644 --- a/src/main/java/li/strolch/model/query/OrderQuery.java +++ b/src/main/java/li/strolch/model/query/OrderQuery.java @@ -28,7 +28,7 @@ import li.strolch.model.parameter.Parameter; * * @author Robert von Burg */ -public class OrderQuery extends StrolchQuery { +public class OrderQuery extends StrolchElementQuery { public OrderQuery(Navigation navigation) { super(navigation); diff --git a/src/main/java/li/strolch/model/query/Query.java b/src/main/java/li/strolch/model/query/Query.java deleted file mode 100644 index 1f2b7057c..000000000 --- a/src/main/java/li/strolch/model/query/Query.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2013 Robert von Burg - * - * 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 li.strolch.model.query; - -/** - * @author Robert von Burg - * - */ -public interface Query { - - public void visit(T queryVisitor); -} diff --git a/src/main/java/li/strolch/model/query/ResourceQuery.java b/src/main/java/li/strolch/model/query/ResourceQuery.java index dafe44eab..900d2659a 100644 --- a/src/main/java/li/strolch/model/query/ResourceQuery.java +++ b/src/main/java/li/strolch/model/query/ResourceQuery.java @@ -28,7 +28,7 @@ import li.strolch.model.parameter.Parameter; * * @author Robert von Burg */ -public class ResourceQuery extends StrolchQuery { +public class ResourceQuery extends StrolchElementQuery { /** * @param navigation diff --git a/src/main/java/li/strolch/model/query/StrolchElementQuery.java b/src/main/java/li/strolch/model/query/StrolchElementQuery.java new file mode 100644 index 000000000..78c429815 --- /dev/null +++ b/src/main/java/li/strolch/model/query/StrolchElementQuery.java @@ -0,0 +1,103 @@ +/* + * Copyright 2013 Robert von Burg + * + * 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 li.strolch.model.query; + +import ch.eitchnet.utils.dbc.DBC; + +/** + * @author Robert von Burg + */ +public abstract class StrolchElementQuery implements StrolchQuery { + + private Navigation navigation; + private Selection selection; + + public StrolchElementQuery(Navigation navigation) { + this.navigation = navigation; + } + + public boolean hasNavigation() { + return this.navigation != null; + } + + public boolean hasSelection() { + return this.selection != null && this.selection.hasSelection(); + } + + public Selection getSelection() { + return this.selection; + } + + public StrolchElementQuery with(Selection selection) { + assertNoSelectionYetSet(); + this.selection = selection; + return this; + } + + private void assertNoSelectionYetSet() { + String msg = "A selection is already set! Use a cascaded boolean operators to perform multiple selections"; //$NON-NLS-1$ + DBC.PRE.assertNull(msg, this.selection); + } + + public StrolchElementQuery withAny() { + assertNoSelectionYetSet(); + this.selection = new AnySelection(); + return this; + } + + public AndSelection and() { + assertNoSelectionYetSet(); + AndSelection and = new AndSelection(); + this.selection = and; + return and; + } + + public OrSelection or() { + assertNoSelectionYetSet(); + OrSelection or = new OrSelection(); + this.selection = or; + return or; + } + + public StrolchElementQuery not(Selection selection) { + assertNoSelectionYetSet(); + this.selection = new NotSelection(selection); + return this; + } + + public void accept(T visitor) { + DBC.PRE.assertNotNull("No navigation set!", this.navigation); //$NON-NLS-1$ + DBC.PRE.assertNotNull("No selection defined!", this.selection); //$NON-NLS-1$ + this.navigation.accept(visitor); + this.selection.accept(visitor); + } + + /** + * @see ch.eitchnet.privilege.model.Restrictable#getPrivilegeName() + */ + @Override + public String getPrivilegeName() { + return StrolchQuery.class.getName(); + } + + /** + * @see ch.eitchnet.privilege.model.Restrictable#getPrivilegeValue() + */ + @Override + public Object getPrivilegeValue() { + return getClass().getName(); + } +} diff --git a/src/main/java/li/strolch/model/query/StrolchQuery.java b/src/main/java/li/strolch/model/query/StrolchQuery.java index 640c04f4d..018e3b9e4 100644 --- a/src/main/java/li/strolch/model/query/StrolchQuery.java +++ b/src/main/java/li/strolch/model/query/StrolchQuery.java @@ -15,73 +15,12 @@ */ package li.strolch.model.query; -import ch.eitchnet.utils.dbc.DBC; +import ch.eitchnet.privilege.model.Restrictable; /** * @author Robert von Burg */ -public abstract class StrolchQuery { +public interface StrolchQuery extends Restrictable { - private Navigation navigation; - private Selection selection; - - public StrolchQuery(Navigation navigation) { - this.navigation = navigation; - } - - public boolean hasNavigation() { - return this.navigation != null; - } - - public boolean hasSelection() { - return this.selection != null && this.selection.hasSelection(); - } - - public Selection getSelection() { - return this.selection; - } - - public StrolchQuery with(Selection selection) { - assertNoSelectionYetSet(); - this.selection = selection; - return this; - } - - private void assertNoSelectionYetSet() { - String msg = "A selection is already set! Use a cascaded boolean operators to perform multiple selections"; //$NON-NLS-1$ - DBC.PRE.assertNull(msg, this.selection); - } - - public StrolchQuery withAny() { - assertNoSelectionYetSet(); - this.selection = new AnySelection(); - return this; - } - - public AndSelection and() { - assertNoSelectionYetSet(); - AndSelection and = new AndSelection(); - this.selection = and; - return and; - } - - public OrSelection or() { - assertNoSelectionYetSet(); - OrSelection or = new OrSelection(); - this.selection = or; - return or; - } - - public StrolchQuery not(Selection selection) { - assertNoSelectionYetSet(); - this.selection = new NotSelection(selection); - return this; - } - - public void accept(T visitor) { - DBC.PRE.assertNotNull("No navigation set!", this.navigation); //$NON-NLS-1$ - DBC.PRE.assertNotNull("No selection defined!", this.selection); //$NON-NLS-1$ - this.navigation.accept(visitor); - this.selection.accept(visitor); - } + // marker interface } From 92286c9b13aa85b4eb7568ceb271239caca3fe59 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 8 Sep 2014 13:55:07 +0200 Subject: [PATCH 86/88] [Bugfix] fixed bug where type was not copied when cloned --- src/main/java/li/strolch/model/GroupedParameterizedElement.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/li/strolch/model/GroupedParameterizedElement.java b/src/main/java/li/strolch/model/GroupedParameterizedElement.java index 0bf081c05..44a70636b 100644 --- a/src/main/java/li/strolch/model/GroupedParameterizedElement.java +++ b/src/main/java/li/strolch/model/GroupedParameterizedElement.java @@ -289,6 +289,7 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement */ protected void fillClone(GroupedParameterizedElement clone) { super.fillClone(clone); + clone.setType(getType()); if (this.parameterBagMap != null) { for (ParameterBag bag : this.parameterBagMap.values()) { From 70d23188527157b6d54184241b31b560a6c3f5a5 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sun, 14 Sep 2014 12:20:44 +0200 Subject: [PATCH 87/88] [Minor] code cleanup --- .../strolch/model/AbstractStrolchElement.java | 10 +++-- .../java/li/strolch/model/ModelGenerator.java | 4 +- .../li/strolch/model/ModelStatistics.java | 3 +- .../strolch/model/ParameterizedElement.java | 2 +- src/main/java/li/strolch/model/Resource.java | 2 +- .../java/li/strolch/model/StrolchElement.java | 5 ++- .../strolch/model/StrolchModelConstants.java | 1 - .../li/strolch/model/audit/AuditQuery.java | 2 +- .../model/parameter/ListParameter.java | 6 ++- .../li/strolch/model/query/NotSelection.java | 3 +- .../model/query/ParameterBagSelection.java | 1 + .../li/strolch/model/query/QueryVisitor.java | 2 +- .../strolch/model/query/StringSelection.java | 2 +- .../model/timedstate/BooleanTimedState.java | 2 + .../model/timedstate/FloatTimedState.java | 2 + .../strolch/model/timedstate/ITimedState.java | 6 ++- .../model/timedstate/IntegerTimedState.java | 2 + .../model/timedstate/StringSetTimedState.java | 2 + .../strolch/model/timevalue/ITimeValue.java | 3 +- .../model/timevalue/ITimeVariable.java | 18 +++++--- .../li/strolch/model/timevalue/IValue.java | 5 ++- .../model/timevalue/impl/BooleanValue.java | 2 +- .../model/timevalue/impl/IntegerValue.java | 2 +- .../model/timevalue/impl/StringSetValue.java | 2 +- .../model/timevalue/impl/TimeValue.java | 2 +- .../model/xml/AbstractToSaxWriterVisitor.java | 12 +++--- .../model/xml/XmlModelSaxFileReader.java | 38 ++++++++-------- .../strolch/model/xml/XmlModelSaxReader.java | 2 +- src/test/java/li/strolch/model/ModelTest.java | 43 ++++++++++++++++++- .../java/li/strolch/model/XmlToDomTest.java | 9 ++-- .../timedstate/StrolchTimedStateTest.java | 5 ++- 31 files changed, 132 insertions(+), 68 deletions(-) diff --git a/src/main/java/li/strolch/model/AbstractStrolchElement.java b/src/main/java/li/strolch/model/AbstractStrolchElement.java index 110fa2803..44783903d 100644 --- a/src/main/java/li/strolch/model/AbstractStrolchElement.java +++ b/src/main/java/li/strolch/model/AbstractStrolchElement.java @@ -45,8 +45,10 @@ public abstract class AbstractStrolchElement implements StrolchElement { /** * Default constructor * - * @param id id of this {@link StrolchElement} - * @param name name of this {@link StrolchElement} + * @param id + * id of this {@link StrolchElement} + * @param name + * name of this {@link StrolchElement} */ public AbstractStrolchElement(String id, String name) { setId(id); @@ -97,8 +99,8 @@ public abstract class AbstractStrolchElement implements StrolchElement { * Used to build a {@link Locator} for this {@link StrolchElement}. It must be implemented by the concrete * implemented as parents must first add their {@link Locator} information * - * @param locatorBuilder the {@link LocatorBuilder} to which the {@link StrolchElement} must add its locator - * information + * @param locatorBuilder + * the {@link LocatorBuilder} to which the {@link StrolchElement} must add its locator information */ protected abstract void fillLocator(LocatorBuilder locatorBuilder); diff --git a/src/main/java/li/strolch/model/ModelGenerator.java b/src/main/java/li/strolch/model/ModelGenerator.java index 56652c47d..701b9a248 100644 --- a/src/main/java/li/strolch/model/ModelGenerator.java +++ b/src/main/java/li/strolch/model/ModelGenerator.java @@ -230,7 +230,7 @@ public class ModelGenerator { List resources = new ArrayList<>(); for (int i = 0; i < count; i++) { String id = StringHelper.normalizeLength(String.valueOf((i + idStart)), 8, true, '0'); - resources.add(createResource(idPrefix + "_" + id, name + " " + i, type)); + resources.add(createResource(idPrefix + id, name + " " + i, type)); } return resources; } @@ -299,7 +299,7 @@ public class ModelGenerator { List orders = new ArrayList<>(); for (int i = 0; i < count; i++) { String id = StringHelper.normalizeLength(String.valueOf((i + idStart)), 8, true, '0'); - orders.add(createOrder(idPrefix + "_" + id, name + " " + i, type)); + orders.add(createOrder(idPrefix + id, name + " " + i, type)); } return orders; } diff --git a/src/main/java/li/strolch/model/ModelStatistics.java b/src/main/java/li/strolch/model/ModelStatistics.java index d3a04bd4c..32315e47e 100644 --- a/src/main/java/li/strolch/model/ModelStatistics.java +++ b/src/main/java/li/strolch/model/ModelStatistics.java @@ -36,8 +36,7 @@ public class ModelStatistics { public String toString() { StringBuilder builder = new StringBuilder(); builder.append(getClass().getSimpleName() + " [startTime="); - builder.append(this.startTime == null ? NULL : ISO8601FormatFactory.getInstance() - .formatDate(this.startTime)); + builder.append(this.startTime == null ? NULL : ISO8601FormatFactory.getInstance().formatDate(this.startTime)); builder.append(", durationNanos="); builder.append(StringHelper.formatNanoDuration(this.durationNanos)); builder.append(", nrOfResources="); diff --git a/src/main/java/li/strolch/model/ParameterizedElement.java b/src/main/java/li/strolch/model/ParameterizedElement.java index b73655b6c..ac6270fbe 100644 --- a/src/main/java/li/strolch/model/ParameterizedElement.java +++ b/src/main/java/li/strolch/model/ParameterizedElement.java @@ -215,7 +215,7 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { Element paramElement = (Element) parameterElements.item(i); String paramtype = paramElement.getAttribute(Tags.TYPE); - DBC.PRE.assertNotEmpty("Type must be set on Parameter for bag with id " + id, paramtype); + DBC.PRE.assertNotEmpty("Type must be set on Parameter for bag with id " + this.id, paramtype); if (paramtype.equals(StringParameter.TYPE)) { StringParameter param = new StringParameter(paramElement); diff --git a/src/main/java/li/strolch/model/Resource.java b/src/main/java/li/strolch/model/Resource.java index 3fe1d7597..1a535a4b6 100644 --- a/src/main/java/li/strolch/model/Resource.java +++ b/src/main/java/li/strolch/model/Resource.java @@ -80,7 +80,7 @@ public class Resource extends GroupedParameterizedElement implements StrolchRoot Element timedStateElem = (Element) timedStateElems.item(i); String typeS = timedStateElem.getAttribute(Tags.TYPE); - DBC.PRE.assertNotEmpty("Type must be set on TimedState for resource with id " + id, typeS); + DBC.PRE.assertNotEmpty("Type must be set on TimedState for resource with id " + this.id, typeS); if (typeS.equals(FloatTimedState.TYPE)) { FloatTimedState timedState = new FloatTimedState(timedStateElem); diff --git a/src/main/java/li/strolch/model/StrolchElement.java b/src/main/java/li/strolch/model/StrolchElement.java index 85f171a21..1fb148ffc 100644 --- a/src/main/java/li/strolch/model/StrolchElement.java +++ b/src/main/java/li/strolch/model/StrolchElement.java @@ -79,8 +79,9 @@ public interface StrolchElement extends Serializable, Comparable /** * Returns an {@link Element} object which is an XML representation of this object * - * @param doc the document to which this element is being written. The client must not append to the document, the - * caller will perform this as needed + * @param doc + * the document to which this element is being written. The client must not append to the document, the + * caller will perform this as needed * * @return */ diff --git a/src/main/java/li/strolch/model/StrolchModelConstants.java b/src/main/java/li/strolch/model/StrolchModelConstants.java index 9db2dd829..5b9caedf2 100644 --- a/src/main/java/li/strolch/model/StrolchModelConstants.java +++ b/src/main/java/li/strolch/model/StrolchModelConstants.java @@ -20,7 +20,6 @@ public class StrolchModelConstants { * to an {@link Order} */ public static final String INTERPRETATION_ORDER_REF = "Order-Ref"; //$NON-NLS-1$ - /** * This interpretation value indicates that the {@link Parameter} has no defined interpretation diff --git a/src/main/java/li/strolch/model/audit/AuditQuery.java b/src/main/java/li/strolch/model/audit/AuditQuery.java index 840d8f785..54dcf4914 100644 --- a/src/main/java/li/strolch/model/audit/AuditQuery.java +++ b/src/main/java/li/strolch/model/audit/AuditQuery.java @@ -68,7 +68,7 @@ public class AuditQuery implements StrolchQuery { DBC.PRE.assertNotNull("No elementTypeSelection (navigation) set!", this.elementTypeSelection); //$NON-NLS-1$ DBC.PRE.assertNotNull("No dateRange set!", this.dateRange); //$NON-NLS-1$ visitor.visit(this); - for (AuditSelection selection : selections) { + for (AuditSelection selection : this.selections) { selection.accept(visitor); } } diff --git a/src/main/java/li/strolch/model/parameter/ListParameter.java b/src/main/java/li/strolch/model/parameter/ListParameter.java index 149b91c8d..d599bb29b 100644 --- a/src/main/java/li/strolch/model/parameter/ListParameter.java +++ b/src/main/java/li/strolch/model/parameter/ListParameter.java @@ -28,14 +28,16 @@ public interface ListParameter extends Parameter> { /** * Adds a single value to the {@link List} of values * - * @param value the value to add + * @param value + * the value to add */ public void addValue(E value); /** * Removes a single value from the {@link List} of values * - * @param value the value to remove + * @param value + * the value to remove * * @return true if the value was removed, false if it did not exist */ diff --git a/src/main/java/li/strolch/model/query/NotSelection.java b/src/main/java/li/strolch/model/query/NotSelection.java index 195ae6b86..a6ea2e0cf 100644 --- a/src/main/java/li/strolch/model/query/NotSelection.java +++ b/src/main/java/li/strolch/model/query/NotSelection.java @@ -28,7 +28,8 @@ public class NotSelection extends BooleanSelection { } /** - * @throws UnsupportedOperationException because a {@link NotSelection} can only work on a single {@link Selection} + * @throws UnsupportedOperationException + * because a {@link NotSelection} can only work on a single {@link Selection} */ @Override public NotSelection with(Selection selection) { diff --git a/src/main/java/li/strolch/model/query/ParameterBagSelection.java b/src/main/java/li/strolch/model/query/ParameterBagSelection.java index 3ed626da0..c1910d2ea 100644 --- a/src/main/java/li/strolch/model/query/ParameterBagSelection.java +++ b/src/main/java/li/strolch/model/query/ParameterBagSelection.java @@ -63,6 +63,7 @@ public class ParameterBagSelection implements Selection { super(bagKey); } + @Override public void accept(StrolchRootElementSelectionVisitor visitor) { visitor.visit(this); } diff --git a/src/main/java/li/strolch/model/query/QueryVisitor.java b/src/main/java/li/strolch/model/query/QueryVisitor.java index 3c92a0109..0209ae2bc 100644 --- a/src/main/java/li/strolch/model/query/QueryVisitor.java +++ b/src/main/java/li/strolch/model/query/QueryVisitor.java @@ -21,7 +21,7 @@ package li.strolch.model.query; public interface QueryVisitor { public void visitAny(); - + public void visitAnd(AndSelection andSelection); public void visitOr(OrSelection orSelection); diff --git a/src/main/java/li/strolch/model/query/StringSelection.java b/src/main/java/li/strolch/model/query/StringSelection.java index 8fa00902a..f5fa5d39a 100644 --- a/src/main/java/li/strolch/model/query/StringSelection.java +++ b/src/main/java/li/strolch/model/query/StringSelection.java @@ -76,7 +76,7 @@ public class StringSelection { } public boolean matches(String value) { - for (String sel : values) { + for (String sel : this.values) { if (this.matchMode.matches(value, sel)) return true; } diff --git a/src/main/java/li/strolch/model/timedstate/BooleanTimedState.java b/src/main/java/li/strolch/model/timedstate/BooleanTimedState.java index 725570c51..13f3474a7 100644 --- a/src/main/java/li/strolch/model/timedstate/BooleanTimedState.java +++ b/src/main/java/li/strolch/model/timedstate/BooleanTimedState.java @@ -16,10 +16,12 @@ package li.strolch.model.timedstate; import java.util.SortedSet; + import li.strolch.model.StrolchElement; import li.strolch.model.Tags; import li.strolch.model.timevalue.ITimeValue; import li.strolch.model.timevalue.impl.BooleanValue; + import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; diff --git a/src/main/java/li/strolch/model/timedstate/FloatTimedState.java b/src/main/java/li/strolch/model/timedstate/FloatTimedState.java index 4a6c90713..a82960ba3 100644 --- a/src/main/java/li/strolch/model/timedstate/FloatTimedState.java +++ b/src/main/java/li/strolch/model/timedstate/FloatTimedState.java @@ -16,10 +16,12 @@ package li.strolch.model.timedstate; import java.util.SortedSet; + import li.strolch.model.StrolchElement; import li.strolch.model.Tags; import li.strolch.model.timevalue.ITimeValue; import li.strolch.model.timevalue.impl.FloatValue; + import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; diff --git a/src/main/java/li/strolch/model/timedstate/ITimedState.java b/src/main/java/li/strolch/model/timedstate/ITimedState.java index 42e765f17..e1e60a2be 100644 --- a/src/main/java/li/strolch/model/timedstate/ITimedState.java +++ b/src/main/java/li/strolch/model/timedstate/ITimedState.java @@ -25,7 +25,8 @@ import li.strolch.model.timevalue.IValueChange; * * @author Martin Smock * - * @param IValue implementation representing the state at a given time + * @param + * IValue implementation representing the state at a given time */ @SuppressWarnings("rawtypes") public interface ITimedState { @@ -41,7 +42,8 @@ public interface ITimedState { ITimeValue getPreviousMatch(final Long time, T value); /** - * @param change the state change to be applied + * @param change + * the state change to be applied */ > void applyChange(final U change); diff --git a/src/main/java/li/strolch/model/timedstate/IntegerTimedState.java b/src/main/java/li/strolch/model/timedstate/IntegerTimedState.java index 220c53b0b..8cd771412 100644 --- a/src/main/java/li/strolch/model/timedstate/IntegerTimedState.java +++ b/src/main/java/li/strolch/model/timedstate/IntegerTimedState.java @@ -16,10 +16,12 @@ package li.strolch.model.timedstate; import java.util.SortedSet; + import li.strolch.model.StrolchElement; import li.strolch.model.Tags; import li.strolch.model.timevalue.ITimeValue; import li.strolch.model.timevalue.impl.IntegerValue; + import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; diff --git a/src/main/java/li/strolch/model/timedstate/StringSetTimedState.java b/src/main/java/li/strolch/model/timedstate/StringSetTimedState.java index 99193c401..76c202e56 100644 --- a/src/main/java/li/strolch/model/timedstate/StringSetTimedState.java +++ b/src/main/java/li/strolch/model/timedstate/StringSetTimedState.java @@ -19,11 +19,13 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Set; import java.util.SortedSet; + import li.strolch.model.StrolchElement; import li.strolch.model.Tags; import li.strolch.model.timevalue.ITimeValue; import li.strolch.model.timevalue.impl.AString; import li.strolch.model.timevalue.impl.StringSetValue; + import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; diff --git a/src/main/java/li/strolch/model/timevalue/ITimeValue.java b/src/main/java/li/strolch/model/timevalue/ITimeValue.java index 97e9c9643..32f0478e7 100644 --- a/src/main/java/li/strolch/model/timevalue/ITimeValue.java +++ b/src/main/java/li/strolch/model/timevalue/ITimeValue.java @@ -22,7 +22,8 @@ import li.strolch.model.timevalue.impl.TimeVariable; * * @author Martin Smock * - * @param the backing value of the timed value object + * @param + * the backing value of the timed value object */ @SuppressWarnings("rawtypes") public interface ITimeValue extends Comparable> { diff --git a/src/main/java/li/strolch/model/timevalue/ITimeVariable.java b/src/main/java/li/strolch/model/timevalue/ITimeVariable.java index f16f9aeb8..d3e68b804 100644 --- a/src/main/java/li/strolch/model/timevalue/ITimeVariable.java +++ b/src/main/java/li/strolch/model/timevalue/ITimeVariable.java @@ -23,7 +23,8 @@ import java.util.SortedSet; * * @author Martin Smock * - * @param the backing value of the timed value object + * @param + * the backing value of the timed value object */ @SuppressWarnings("rawtypes") public interface ITimeVariable { @@ -31,8 +32,10 @@ public interface ITimeVariable { /** * set the value at a point in time to a given time value object * - * @param time the time to set the {@link IValue} - * @param value the {@link IValue} to set + * @param time + * the time to set the {@link IValue} + * @param value + * the {@link IValue} to set */ void setValueAt(final Long time, final T value); @@ -44,14 +47,16 @@ public interface ITimeVariable { /** * Applies a {@link IValueChange} propagating the change to all future values starting from the time of the change. * - * @param change the {@link IValueChange} to be applied + * @param change + * the {@link IValueChange} to be applied */ void applyChange(final IValueChange change); /** * Get all {@link ITimeValue} objects whose time field is greater or equal to the given time * - * @param time the time the sequence starts with + * @param time + * the time the sequence starts with * @return the sequence of {@link ITimeValue} objects in the future */ Collection> getFutureValues(final Long time); @@ -59,7 +64,8 @@ public interface ITimeVariable { /** * Get all {@link ITimeValue} objects whose time field is strictly smaller than the given time * - * @param time the time the sequence starts with + * @param time + * the time the sequence starts with * @return the sequence of {@link ITimeValue} objects in the future */ Collection> getPastValues(final Long time); diff --git a/src/main/java/li/strolch/model/timevalue/IValue.java b/src/main/java/li/strolch/model/timevalue/IValue.java index 701d62d8d..2c33a262d 100644 --- a/src/main/java/li/strolch/model/timevalue/IValue.java +++ b/src/main/java/li/strolch/model/timevalue/IValue.java @@ -21,7 +21,8 @@ package li.strolch.model.timevalue; * * @author Martin Smock * - * @param any object for which a (generalized) add operation can be defined. + * @param + * any object for which a (generalized) add operation can be defined. */ public interface IValue { @@ -49,7 +50,7 @@ public interface IValue { * @return a copy of this */ IValue getCopy(); - + /** * @return this value in string representation */ diff --git a/src/main/java/li/strolch/model/timevalue/impl/BooleanValue.java b/src/main/java/li/strolch/model/timevalue/impl/BooleanValue.java index f52a1c794..4e00f603c 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/BooleanValue.java +++ b/src/main/java/li/strolch/model/timevalue/impl/BooleanValue.java @@ -65,7 +65,7 @@ public class BooleanValue implements IValue, Serializable { public BooleanValue getInverse() { return new BooleanValue(!getValue()); } - + @Override public String getValueAsString() { return this.value.toString(); diff --git a/src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java b/src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java index 4f90363e2..c1476273f 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java +++ b/src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java @@ -65,7 +65,7 @@ public class IntegerValue implements IValue, Serializable { public IntegerValue getInverse() { return new IntegerValue(-getValue()); } - + @Override public String getValueAsString() { return this.value.toString(); diff --git a/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java b/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java index b6eb46df4..e17c590c7 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java +++ b/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java @@ -110,7 +110,7 @@ public class StringSetValue implements IValue>, Serializable { return this.aStrings.iterator().next().getString(); StringBuilder sb = new StringBuilder(); - Iterator iter = aStrings.iterator(); + Iterator iter = this.aStrings.iterator(); while (iter.hasNext()) { sb.append(iter.next()); if (iter.hasNext()) diff --git a/src/main/java/li/strolch/model/timevalue/impl/TimeValue.java b/src/main/java/li/strolch/model/timevalue/impl/TimeValue.java index 9af00ffe2..3ffec7a36 100644 --- a/src/main/java/li/strolch/model/timevalue/impl/TimeValue.java +++ b/src/main/java/li/strolch/model/timevalue/impl/TimeValue.java @@ -72,7 +72,7 @@ public class TimeValue implements ITimeValue, Serializable @SuppressWarnings("unchecked") @Override public ITimeValue getCopy() { - return new TimeValue(time, (T) value.getCopy()); + return new TimeValue(this.time, (T) this.value.getCopy()); } @SuppressWarnings("nls") diff --git a/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java b/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java index 5a53a9497..9f50deaf4 100644 --- a/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java +++ b/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java @@ -56,14 +56,14 @@ public abstract class AbstractToSaxWriterVisitor { protected void writeElement(String tag, Order order) throws XMLStreamException { boolean empty = !order.hasParameterBags(); - writeElement(tag, empty, (GroupedParameterizedElement) order); + writeElement(tag, empty, order); if (!empty) this.writer.writeEndElement(); } protected void writeElement(String tag, Resource resource) throws XMLStreamException { boolean empty = !resource.hasParameterBags() && !resource.hasTimedStates(); - writeElement(tag, empty, (GroupedParameterizedElement) resource); + writeElement(tag, empty, resource); if (resource.hasTimedStates()) writeTimedStates(resource); @@ -85,13 +85,13 @@ public abstract class AbstractToSaxWriterVisitor { writeStartStrolchElement(Tags.TIMED_STATE, !values.isEmpty(), timedState); for (ITimeValue> timeValue : values) { - writer.writeEmptyElement(Tags.VALUE); - writer.writeAttribute(Tags.TIME, timeValue.getTime().toString()); - writer.writeAttribute(Tags.VALUE, timeValue.getValue().getValueAsString()); + this.writer.writeEmptyElement(Tags.VALUE); + this.writer.writeAttribute(Tags.TIME, timeValue.getTime().toString()); + this.writer.writeAttribute(Tags.VALUE, timeValue.getValue().getValueAsString()); } if (!values.isEmpty()) - writer.writeEndElement(); + this.writer.writeEndElement(); } } diff --git a/src/main/java/li/strolch/model/xml/XmlModelSaxFileReader.java b/src/main/java/li/strolch/model/xml/XmlModelSaxFileReader.java index a515767b6..e87059b6f 100644 --- a/src/main/java/li/strolch/model/xml/XmlModelSaxFileReader.java +++ b/src/main/java/li/strolch/model/xml/XmlModelSaxFileReader.java @@ -54,28 +54,28 @@ public class XmlModelSaxFileReader extends XmlModelSaxReader { switch (qName) { - case Tags.INCLUDE_FILE: + case Tags.INCLUDE_FILE: - String includeFileS = attributes.getValue(Tags.FILE); - if (StringHelper.isEmpty(includeFileS)) { - throw new IllegalArgumentException(MessageFormat.format( - "The attribute {0} is missing for IncludeFile!", Tags.FILE)); //$NON-NLS-1$ - } - File includeFile = new File(this.modelFile.getParentFile(), includeFileS); - if (!includeFile.exists() || !includeFile.canRead()) { - String msg = "The IncludeFile does not exist, or is not readable. Source model: {0} with IncludeFile: {1}"; //$NON-NLS-1$ - msg = MessageFormat.format(msg, this.modelFile.getName(), includeFileS); - throw new IllegalArgumentException(msg); - } + String includeFileS = attributes.getValue(Tags.FILE); + if (StringHelper.isEmpty(includeFileS)) { + throw new IllegalArgumentException(MessageFormat.format( + "The attribute {0} is missing for IncludeFile!", Tags.FILE)); //$NON-NLS-1$ + } + File includeFile = new File(this.modelFile.getParentFile(), includeFileS); + if (!includeFile.exists() || !includeFile.canRead()) { + String msg = "The IncludeFile does not exist, or is not readable. Source model: {0} with IncludeFile: {1}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, this.modelFile.getName(), includeFileS); + throw new IllegalArgumentException(msg); + } - XmlModelSaxFileReader handler = new XmlModelSaxFileReader(this.listener, includeFile); - handler.parseFile(); - this.statistics.nrOfOrders += handler.statistics.nrOfOrders; - this.statistics.nrOfResources += handler.statistics.nrOfResources; + XmlModelSaxFileReader handler = new XmlModelSaxFileReader(this.listener, includeFile); + handler.parseFile(); + this.statistics.nrOfOrders += handler.statistics.nrOfOrders; + this.statistics.nrOfResources += handler.statistics.nrOfResources; - break; - default: - super.startElement(uri, localName, qName, attributes); + break; + default: + super.startElement(uri, localName, qName, attributes); } } diff --git a/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java b/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java index 70287df8f..61ea31067 100644 --- a/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java +++ b/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java @@ -266,7 +266,7 @@ public class XmlModelSaxReader extends DefaultHandler { case Tags.INCLUDE_FILE: break; case Tags.TIMED_STATE: - ((Resource) this.parameterizedElement).addTimedState(state); + ((Resource) this.parameterizedElement).addTimedState(this.state); break; case Tags.VALUE: break; diff --git a/src/test/java/li/strolch/model/ModelTest.java b/src/test/java/li/strolch/model/ModelTest.java index 0a512ba56..ce2fd43f0 100644 --- a/src/test/java/li/strolch/model/ModelTest.java +++ b/src/test/java/li/strolch/model/ModelTest.java @@ -15,7 +15,46 @@ */ package li.strolch.model; -import static li.strolch.model.ModelGenerator.*; +import static li.strolch.model.ModelGenerator.BAG_ID; +import static li.strolch.model.ModelGenerator.BAG_NAME; +import static li.strolch.model.ModelGenerator.BAG_TYPE; +import static li.strolch.model.ModelGenerator.PARAM_BOOLEAN_ID; +import static li.strolch.model.ModelGenerator.PARAM_DATE_ID; +import static li.strolch.model.ModelGenerator.PARAM_FLOAT_ID; +import static li.strolch.model.ModelGenerator.PARAM_INTEGER_ID; +import static li.strolch.model.ModelGenerator.PARAM_LIST_STRING_ID; +import static li.strolch.model.ModelGenerator.PARAM_LONG_ID; +import static li.strolch.model.ModelGenerator.PARAM_STRING_ID; +import static li.strolch.model.ModelGenerator.STATE_BOOLEAN_ID; +import static li.strolch.model.ModelGenerator.STATE_BOOLEAN_TIME_0; +import static li.strolch.model.ModelGenerator.STATE_BOOLEAN_TIME_10; +import static li.strolch.model.ModelGenerator.STATE_BOOLEAN_TIME_20; +import static li.strolch.model.ModelGenerator.STATE_BOOLEAN_TIME_30; +import static li.strolch.model.ModelGenerator.STATE_FLOAT_ID; +import static li.strolch.model.ModelGenerator.STATE_FLOAT_TIME_0; +import static li.strolch.model.ModelGenerator.STATE_FLOAT_TIME_10; +import static li.strolch.model.ModelGenerator.STATE_FLOAT_TIME_20; +import static li.strolch.model.ModelGenerator.STATE_FLOAT_TIME_30; +import static li.strolch.model.ModelGenerator.STATE_INTEGER_ID; +import static li.strolch.model.ModelGenerator.STATE_INTEGER_TIME_0; +import static li.strolch.model.ModelGenerator.STATE_INTEGER_TIME_10; +import static li.strolch.model.ModelGenerator.STATE_INTEGER_TIME_20; +import static li.strolch.model.ModelGenerator.STATE_INTEGER_TIME_30; +import static li.strolch.model.ModelGenerator.STATE_STRING_ID; +import static li.strolch.model.ModelGenerator.STATE_STRING_TIME_0; +import static li.strolch.model.ModelGenerator.STATE_STRING_TIME_10; +import static li.strolch.model.ModelGenerator.STATE_STRING_TIME_20; +import static li.strolch.model.ModelGenerator.STATE_STRING_TIME_30; +import static li.strolch.model.ModelGenerator.STATE_TIME_0; +import static li.strolch.model.ModelGenerator.STATE_TIME_10; +import static li.strolch.model.ModelGenerator.STATE_TIME_20; +import static li.strolch.model.ModelGenerator.STATE_TIME_30; +import static li.strolch.model.ModelGenerator.createOrder; +import static li.strolch.model.ModelGenerator.createResource; +import static li.strolch.model.Tags.BAG; +import static li.strolch.model.Tags.ORDER; +import static li.strolch.model.Tags.RESOURCE; +import static li.strolch.model.Tags.STATE; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -23,7 +62,7 @@ import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.Date; -import static li.strolch.model.Tags.*; + import li.strolch.model.parameter.BooleanParameter; import li.strolch.model.parameter.DateParameter; import li.strolch.model.parameter.FloatParameter; diff --git a/src/test/java/li/strolch/model/XmlToDomTest.java b/src/test/java/li/strolch/model/XmlToDomTest.java index e6417b494..ecbd00fa8 100644 --- a/src/test/java/li/strolch/model/XmlToDomTest.java +++ b/src/test/java/li/strolch/model/XmlToDomTest.java @@ -15,11 +15,12 @@ */ package li.strolch.model; +import static org.junit.Assert.assertTrue; import li.strolch.model.visitor.OrderDeepEqualsVisitor; import li.strolch.model.visitor.ResourceDeepEqualsVisitor; import li.strolch.model.xml.OrderToDomVisitor; import li.strolch.model.xml.ResourceToDomVisitor; -import static org.junit.Assert.assertTrue; + import org.junit.Test; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -45,8 +46,7 @@ public class XmlToDomTest extends ModelTest { OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(order); visitor.visit(parsedOrder); - assertTrue("To DOM and back should equal same Order:\n" + visitor.getMismatchedLocators(), - visitor.isEqual()); + assertTrue("To DOM and back should equal same Order:\n" + visitor.getMismatchedLocators(), visitor.isEqual()); } @Test @@ -63,7 +63,6 @@ public class XmlToDomTest extends ModelTest { ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(resource); visitor.visit(parsedResource); - assertTrue("To DOM and back should equal same Resource:\n" + visitor.getMismatchedLocators(), - visitor.isEqual()); + assertTrue("To DOM and back should equal same Resource:\n" + visitor.getMismatchedLocators(), visitor.isEqual()); } } diff --git a/src/test/java/li/strolch/model/timedstate/StrolchTimedStateTest.java b/src/test/java/li/strolch/model/timedstate/StrolchTimedStateTest.java index b020b88c9..1cbd914b3 100644 --- a/src/test/java/li/strolch/model/timedstate/StrolchTimedStateTest.java +++ b/src/test/java/li/strolch/model/timedstate/StrolchTimedStateTest.java @@ -15,8 +15,11 @@ */ package li.strolch.model.timedstate; +import static org.junit.Assert.assertEquals; + import java.util.HashSet; import java.util.Set; + import li.strolch.model.ModelGenerator; import li.strolch.model.Resource; import li.strolch.model.timevalue.ITimeValue; @@ -25,7 +28,7 @@ import li.strolch.model.timevalue.impl.BooleanValue; import li.strolch.model.timevalue.impl.FloatValue; import li.strolch.model.timevalue.impl.IntegerValue; import li.strolch.model.timevalue.impl.StringSetValue; -import static org.junit.Assert.assertEquals; + import org.junit.Test; /** From 0882274198e9ab789b230d4a5226b81f941edbd0 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Tue, 16 Sep 2014 08:50:59 +0200 Subject: [PATCH 88/88] moved everything to a subdirectory for repo merge --- .gitignore => li.strolch.model/.gitignore | 0 LICENSE => li.strolch.model/LICENSE | 0 README.md => li.strolch.model/README.md | 0 pom.xml => li.strolch.model/pom.xml | 0 .../src}/main/java/li/strolch/exception/StrolchException.java | 0 .../src}/main/java/li/strolch/model/AbstractStrolchElement.java | 0 .../main/java/li/strolch/model/GroupedParameterizedElement.java | 0 .../src}/main/java/li/strolch/model/Locator.java | 0 .../src}/main/java/li/strolch/model/ModelGenerator.java | 0 .../src}/main/java/li/strolch/model/ModelStatistics.java | 0 .../src}/main/java/li/strolch/model/Order.java | 0 .../src}/main/java/li/strolch/model/OrderVisitor.java | 0 .../src}/main/java/li/strolch/model/ParameterBag.java | 0 .../src}/main/java/li/strolch/model/ParameterizedElement.java | 0 .../src}/main/java/li/strolch/model/Resource.java | 0 .../src}/main/java/li/strolch/model/ResourceVisitor.java | 0 .../src}/main/java/li/strolch/model/State.java | 0 .../src}/main/java/li/strolch/model/StrolchElement.java | 0 .../src}/main/java/li/strolch/model/StrolchModelConstants.java | 0 .../src}/main/java/li/strolch/model/StrolchRootElement.java | 0 .../src}/main/java/li/strolch/model/Tags.java | 0 .../src}/main/java/li/strolch/model/audit/AccessType.java | 0 .../src}/main/java/li/strolch/model/audit/ActionSelection.java | 0 .../src}/main/java/li/strolch/model/audit/Audit.java | 0 .../src}/main/java/li/strolch/model/audit/AuditFromDomReader.java | 0 .../src}/main/java/li/strolch/model/audit/AuditQuery.java | 0 .../src}/main/java/li/strolch/model/audit/AuditQueryVisitor.java | 0 .../src}/main/java/li/strolch/model/audit/AuditSaxReader.java | 0 .../src}/main/java/li/strolch/model/audit/AuditSelection.java | 0 .../src}/main/java/li/strolch/model/audit/AuditToDomVisitor.java | 0 .../src}/main/java/li/strolch/model/audit/AuditVisitor.java | 0 .../src}/main/java/li/strolch/model/audit/ElementSelection.java | 0 .../src}/main/java/li/strolch/model/audit/IdentitySelection.java | 0 .../main/java/li/strolch/model/audit/NoStrategyAuditVisitor.java | 0 .../main/java/li/strolch/model/parameter/AbstractParameter.java | 0 .../main/java/li/strolch/model/parameter/BooleanParameter.java | 0 .../src}/main/java/li/strolch/model/parameter/DateParameter.java | 0 .../src}/main/java/li/strolch/model/parameter/FloatParameter.java | 0 .../main/java/li/strolch/model/parameter/IntegerParameter.java | 0 .../src}/main/java/li/strolch/model/parameter/ListParameter.java | 0 .../src}/main/java/li/strolch/model/parameter/LongParameter.java | 0 .../src}/main/java/li/strolch/model/parameter/Parameter.java | 0 .../main/java/li/strolch/model/parameter/StringListParameter.java | 0 .../main/java/li/strolch/model/parameter/StringParameter.java | 0 .../src}/main/java/li/strolch/model/query/AndSelection.java | 0 .../src}/main/java/li/strolch/model/query/AnySelection.java | 0 .../src}/main/java/li/strolch/model/query/BooleanSelection.java | 0 .../src}/main/java/li/strolch/model/query/DateSelection.java | 0 .../src}/main/java/li/strolch/model/query/IdSelection.java | 0 .../src}/main/java/li/strolch/model/query/NameSelection.java | 0 .../src}/main/java/li/strolch/model/query/Navigation.java | 0 .../src}/main/java/li/strolch/model/query/NotSelection.java | 0 .../src}/main/java/li/strolch/model/query/OrSelection.java | 0 .../src}/main/java/li/strolch/model/query/OrderQuery.java | 0 .../src}/main/java/li/strolch/model/query/OrderQueryVisitor.java | 0 .../src}/main/java/li/strolch/model/query/OrderSelection.java | 0 .../main/java/li/strolch/model/query/OrderSelectionVisitor.java | 0 .../main/java/li/strolch/model/query/ParameterBagSelection.java | 0 .../src}/main/java/li/strolch/model/query/ParameterSelection.java | 0 .../java/li/strolch/model/query/ParameterSelectionVisitor.java | 0 .../src}/main/java/li/strolch/model/query/QueryVisitor.java | 0 .../src}/main/java/li/strolch/model/query/ResourceQuery.java | 0 .../main/java/li/strolch/model/query/ResourceQueryVisitor.java | 0 .../src}/main/java/li/strolch/model/query/Selection.java | 0 .../src}/main/java/li/strolch/model/query/StateSelection.java | 0 .../src}/main/java/li/strolch/model/query/StringSelection.java | 0 .../main/java/li/strolch/model/query/StrolchElementQuery.java | 0 .../main/java/li/strolch/model/query/StrolchElementSelection.java | 0 .../li/strolch/model/query/StrolchElementSelectionVisitor.java | 0 .../src}/main/java/li/strolch/model/query/StrolchQuery.java | 0 .../strolch/model/query/StrolchRootElementSelectionVisitor.java | 0 .../main/java/li/strolch/model/query/StrolchTypeNavigation.java | 0 .../li/strolch/model/timedstate/AbstractStrolchTimedState.java | 0 .../main/java/li/strolch/model/timedstate/BooleanTimedState.java | 0 .../main/java/li/strolch/model/timedstate/FloatTimedState.java | 0 .../src}/main/java/li/strolch/model/timedstate/ITimedState.java | 0 .../main/java/li/strolch/model/timedstate/IntegerTimedState.java | 0 .../java/li/strolch/model/timedstate/StringSetTimedState.java | 0 .../main/java/li/strolch/model/timedstate/StrolchTimedState.java | 0 .../src}/main/java/li/strolch/model/timedstate/TimedState.java | 0 .../src}/main/java/li/strolch/model/timevalue/ITimeValue.java | 0 .../src}/main/java/li/strolch/model/timevalue/ITimeVariable.java | 0 .../src}/main/java/li/strolch/model/timevalue/IValue.java | 0 .../src}/main/java/li/strolch/model/timevalue/IValueChange.java | 0 .../src}/main/java/li/strolch/model/timevalue/impl/AString.java | 0 .../main/java/li/strolch/model/timevalue/impl/BooleanValue.java | 0 .../main/java/li/strolch/model/timevalue/impl/FloatValue.java | 0 .../main/java/li/strolch/model/timevalue/impl/IntegerValue.java | 0 .../main/java/li/strolch/model/timevalue/impl/StringSetValue.java | 0 .../src}/main/java/li/strolch/model/timevalue/impl/TimeValue.java | 0 .../main/java/li/strolch/model/timevalue/impl/TimeVariable.java | 0 .../main/java/li/strolch/model/timevalue/impl/ValueChange.java | 0 .../main/java/li/strolch/model/visitor/ElementTypeVisitor.java | 0 .../java/li/strolch/model/visitor/NoStrategyOrderVisitor.java | 0 .../java/li/strolch/model/visitor/NoStrategyResourceVisitor.java | 0 .../main/java/li/strolch/model/visitor/NoStrategyVisitor.java | 0 .../java/li/strolch/model/visitor/OrderDeepEqualsVisitor.java | 0 .../src}/main/java/li/strolch/model/visitor/ParameterVisitor.java | 0 .../java/li/strolch/model/visitor/ResourceDeepEqualsVisitor.java | 0 .../java/li/strolch/model/visitor/SetParameterValueVisitor.java | 0 .../li/strolch/model/visitor/StrolchElementDeepEqualsVisitor.java | 0 .../main/java/li/strolch/model/visitor/StrolchElementVisitor.java | 0 .../java/li/strolch/model/visitor/StrolchRootElementVisitor.java | 0 .../src}/main/java/li/strolch/model/visitor/StrolchVisitor.java | 0 .../main/java/li/strolch/model/visitor/TimedStateVisitor.java | 0 .../java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java | 0 .../src}/main/java/li/strolch/model/xml/OrderToDomVisitor.java | 0 .../src}/main/java/li/strolch/model/xml/OrderToSaxVisitor.java | 0 .../main/java/li/strolch/model/xml/OrderToSaxWriterVisitor.java | 0 .../src}/main/java/li/strolch/model/xml/ResourceToDomVisitor.java | 0 .../src}/main/java/li/strolch/model/xml/ResourceToSaxVisitor.java | 0 .../java/li/strolch/model/xml/ResourceToSaxWriterVisitor.java | 0 .../java/li/strolch/model/xml/SimpleStrolchElementListener.java | 0 .../main/java/li/strolch/model/xml/StrolchElementListener.java | 0 .../java/li/strolch/model/xml/StrolchElementToSaxVisitor.java | 0 .../main/java/li/strolch/model/xml/XmlModelSaxFileReader.java | 0 .../src}/main/java/li/strolch/model/xml/XmlModelSaxReader.java | 0 .../src}/main/resources/componentVersion.properties | 0 .../src}/test/java/li/strolch/model/ModelTest.java | 0 .../test/java/li/strolch/model/XmlModelDefaultHandlerTest.java | 0 .../src}/test/java/li/strolch/model/XmlToDomTest.java | 0 .../java/li/strolch/model/timedstate/StrolchTimedStateTest.java | 0 .../src}/test/java/li/strolch/model/timedstate/TimeStateTest.java | 0 .../java/li/strolch/model/timevalue/FloatTimeVariableTest.java | 0 .../java/li/strolch/model/timevalue/IntegerTimeVariableTest.java | 0 .../java/li/strolch/model/timevalue/StringTimeVariableTest.java | 0 .../src}/test/java/li/strolch/model/timevalue/ValueTests.java | 0 .../src}/test/resources/data/StrolchModel.xml | 0 .../src}/test/resources/data/orders/Orders.xml | 0 .../src}/test/resources/data/orders/Templates.xml | 0 .../src}/test/resources/data/resources/Resources.xml | 0 .../src}/test/resources/data/resources/Templates.xml | 0 {src => li.strolch.model/src}/test/resources/log4j.xml | 0 133 files changed, 0 insertions(+), 0 deletions(-) rename .gitignore => li.strolch.model/.gitignore (100%) rename LICENSE => li.strolch.model/LICENSE (100%) rename README.md => li.strolch.model/README.md (100%) rename pom.xml => li.strolch.model/pom.xml (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/exception/StrolchException.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/AbstractStrolchElement.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/GroupedParameterizedElement.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/Locator.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/ModelGenerator.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/ModelStatistics.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/Order.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/OrderVisitor.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/ParameterBag.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/ParameterizedElement.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/Resource.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/ResourceVisitor.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/State.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/StrolchElement.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/StrolchModelConstants.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/StrolchRootElement.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/Tags.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/audit/AccessType.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/audit/ActionSelection.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/audit/Audit.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/audit/AuditFromDomReader.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/audit/AuditQuery.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/audit/AuditQueryVisitor.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/audit/AuditSaxReader.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/audit/AuditSelection.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/audit/AuditToDomVisitor.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/audit/AuditVisitor.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/audit/ElementSelection.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/audit/IdentitySelection.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/audit/NoStrategyAuditVisitor.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/parameter/AbstractParameter.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/parameter/BooleanParameter.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/parameter/DateParameter.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/parameter/FloatParameter.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/parameter/IntegerParameter.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/parameter/ListParameter.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/parameter/LongParameter.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/parameter/Parameter.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/parameter/StringListParameter.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/parameter/StringParameter.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/query/AndSelection.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/query/AnySelection.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/query/BooleanSelection.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/query/DateSelection.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/query/IdSelection.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/query/NameSelection.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/query/Navigation.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/query/NotSelection.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/query/OrSelection.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/query/OrderQuery.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/query/OrderQueryVisitor.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/query/OrderSelection.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/query/OrderSelectionVisitor.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/query/ParameterBagSelection.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/query/ParameterSelection.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/query/ParameterSelectionVisitor.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/query/QueryVisitor.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/query/ResourceQuery.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/query/ResourceQueryVisitor.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/query/Selection.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/query/StateSelection.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/query/StringSelection.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/query/StrolchElementQuery.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/query/StrolchElementSelection.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/query/StrolchElementSelectionVisitor.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/query/StrolchQuery.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/query/StrolchRootElementSelectionVisitor.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/query/StrolchTypeNavigation.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/timedstate/AbstractStrolchTimedState.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/timedstate/BooleanTimedState.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/timedstate/FloatTimedState.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/timedstate/ITimedState.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/timedstate/IntegerTimedState.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/timedstate/StringSetTimedState.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/timedstate/StrolchTimedState.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/timedstate/TimedState.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/timevalue/ITimeValue.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/timevalue/ITimeVariable.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/timevalue/IValue.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/timevalue/IValueChange.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/timevalue/impl/AString.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/timevalue/impl/BooleanValue.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/timevalue/impl/FloatValue.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/timevalue/impl/IntegerValue.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/timevalue/impl/StringSetValue.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/timevalue/impl/TimeValue.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/timevalue/impl/TimeVariable.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/timevalue/impl/ValueChange.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/visitor/ElementTypeVisitor.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/visitor/NoStrategyOrderVisitor.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/visitor/NoStrategyResourceVisitor.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/visitor/NoStrategyVisitor.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/visitor/OrderDeepEqualsVisitor.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/visitor/ParameterVisitor.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/visitor/ResourceDeepEqualsVisitor.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/visitor/SetParameterValueVisitor.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/visitor/StrolchElementDeepEqualsVisitor.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/visitor/StrolchElementVisitor.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/visitor/StrolchRootElementVisitor.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/visitor/StrolchVisitor.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/visitor/TimedStateVisitor.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/xml/OrderToDomVisitor.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/xml/OrderToSaxVisitor.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/xml/OrderToSaxWriterVisitor.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/xml/ResourceToDomVisitor.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/xml/ResourceToSaxVisitor.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/xml/ResourceToSaxWriterVisitor.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/xml/SimpleStrolchElementListener.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/xml/StrolchElementListener.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/xml/StrolchElementToSaxVisitor.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/xml/XmlModelSaxFileReader.java (100%) rename {src => li.strolch.model/src}/main/java/li/strolch/model/xml/XmlModelSaxReader.java (100%) rename {src => li.strolch.model/src}/main/resources/componentVersion.properties (100%) rename {src => li.strolch.model/src}/test/java/li/strolch/model/ModelTest.java (100%) rename {src => li.strolch.model/src}/test/java/li/strolch/model/XmlModelDefaultHandlerTest.java (100%) rename {src => li.strolch.model/src}/test/java/li/strolch/model/XmlToDomTest.java (100%) rename {src => li.strolch.model/src}/test/java/li/strolch/model/timedstate/StrolchTimedStateTest.java (100%) rename {src => li.strolch.model/src}/test/java/li/strolch/model/timedstate/TimeStateTest.java (100%) rename {src => li.strolch.model/src}/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java (100%) rename {src => li.strolch.model/src}/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java (100%) rename {src => li.strolch.model/src}/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java (100%) rename {src => li.strolch.model/src}/test/java/li/strolch/model/timevalue/ValueTests.java (100%) rename {src => li.strolch.model/src}/test/resources/data/StrolchModel.xml (100%) rename {src => li.strolch.model/src}/test/resources/data/orders/Orders.xml (100%) rename {src => li.strolch.model/src}/test/resources/data/orders/Templates.xml (100%) rename {src => li.strolch.model/src}/test/resources/data/resources/Resources.xml (100%) rename {src => li.strolch.model/src}/test/resources/data/resources/Templates.xml (100%) rename {src => li.strolch.model/src}/test/resources/log4j.xml (100%) diff --git a/.gitignore b/li.strolch.model/.gitignore similarity index 100% rename from .gitignore rename to li.strolch.model/.gitignore diff --git a/LICENSE b/li.strolch.model/LICENSE similarity index 100% rename from LICENSE rename to li.strolch.model/LICENSE diff --git a/README.md b/li.strolch.model/README.md similarity index 100% rename from README.md rename to li.strolch.model/README.md diff --git a/pom.xml b/li.strolch.model/pom.xml similarity index 100% rename from pom.xml rename to li.strolch.model/pom.xml diff --git a/src/main/java/li/strolch/exception/StrolchException.java b/li.strolch.model/src/main/java/li/strolch/exception/StrolchException.java similarity index 100% rename from src/main/java/li/strolch/exception/StrolchException.java rename to li.strolch.model/src/main/java/li/strolch/exception/StrolchException.java diff --git a/src/main/java/li/strolch/model/AbstractStrolchElement.java b/li.strolch.model/src/main/java/li/strolch/model/AbstractStrolchElement.java similarity index 100% rename from src/main/java/li/strolch/model/AbstractStrolchElement.java rename to li.strolch.model/src/main/java/li/strolch/model/AbstractStrolchElement.java diff --git a/src/main/java/li/strolch/model/GroupedParameterizedElement.java b/li.strolch.model/src/main/java/li/strolch/model/GroupedParameterizedElement.java similarity index 100% rename from src/main/java/li/strolch/model/GroupedParameterizedElement.java rename to li.strolch.model/src/main/java/li/strolch/model/GroupedParameterizedElement.java diff --git a/src/main/java/li/strolch/model/Locator.java b/li.strolch.model/src/main/java/li/strolch/model/Locator.java similarity index 100% rename from src/main/java/li/strolch/model/Locator.java rename to li.strolch.model/src/main/java/li/strolch/model/Locator.java diff --git a/src/main/java/li/strolch/model/ModelGenerator.java b/li.strolch.model/src/main/java/li/strolch/model/ModelGenerator.java similarity index 100% rename from src/main/java/li/strolch/model/ModelGenerator.java rename to li.strolch.model/src/main/java/li/strolch/model/ModelGenerator.java diff --git a/src/main/java/li/strolch/model/ModelStatistics.java b/li.strolch.model/src/main/java/li/strolch/model/ModelStatistics.java similarity index 100% rename from src/main/java/li/strolch/model/ModelStatistics.java rename to li.strolch.model/src/main/java/li/strolch/model/ModelStatistics.java diff --git a/src/main/java/li/strolch/model/Order.java b/li.strolch.model/src/main/java/li/strolch/model/Order.java similarity index 100% rename from src/main/java/li/strolch/model/Order.java rename to li.strolch.model/src/main/java/li/strolch/model/Order.java diff --git a/src/main/java/li/strolch/model/OrderVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/OrderVisitor.java similarity index 100% rename from src/main/java/li/strolch/model/OrderVisitor.java rename to li.strolch.model/src/main/java/li/strolch/model/OrderVisitor.java diff --git a/src/main/java/li/strolch/model/ParameterBag.java b/li.strolch.model/src/main/java/li/strolch/model/ParameterBag.java similarity index 100% rename from src/main/java/li/strolch/model/ParameterBag.java rename to li.strolch.model/src/main/java/li/strolch/model/ParameterBag.java diff --git a/src/main/java/li/strolch/model/ParameterizedElement.java b/li.strolch.model/src/main/java/li/strolch/model/ParameterizedElement.java similarity index 100% rename from src/main/java/li/strolch/model/ParameterizedElement.java rename to li.strolch.model/src/main/java/li/strolch/model/ParameterizedElement.java diff --git a/src/main/java/li/strolch/model/Resource.java b/li.strolch.model/src/main/java/li/strolch/model/Resource.java similarity index 100% rename from src/main/java/li/strolch/model/Resource.java rename to li.strolch.model/src/main/java/li/strolch/model/Resource.java diff --git a/src/main/java/li/strolch/model/ResourceVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/ResourceVisitor.java similarity index 100% rename from src/main/java/li/strolch/model/ResourceVisitor.java rename to li.strolch.model/src/main/java/li/strolch/model/ResourceVisitor.java diff --git a/src/main/java/li/strolch/model/State.java b/li.strolch.model/src/main/java/li/strolch/model/State.java similarity index 100% rename from src/main/java/li/strolch/model/State.java rename to li.strolch.model/src/main/java/li/strolch/model/State.java diff --git a/src/main/java/li/strolch/model/StrolchElement.java b/li.strolch.model/src/main/java/li/strolch/model/StrolchElement.java similarity index 100% rename from src/main/java/li/strolch/model/StrolchElement.java rename to li.strolch.model/src/main/java/li/strolch/model/StrolchElement.java diff --git a/src/main/java/li/strolch/model/StrolchModelConstants.java b/li.strolch.model/src/main/java/li/strolch/model/StrolchModelConstants.java similarity index 100% rename from src/main/java/li/strolch/model/StrolchModelConstants.java rename to li.strolch.model/src/main/java/li/strolch/model/StrolchModelConstants.java diff --git a/src/main/java/li/strolch/model/StrolchRootElement.java b/li.strolch.model/src/main/java/li/strolch/model/StrolchRootElement.java similarity index 100% rename from src/main/java/li/strolch/model/StrolchRootElement.java rename to li.strolch.model/src/main/java/li/strolch/model/StrolchRootElement.java diff --git a/src/main/java/li/strolch/model/Tags.java b/li.strolch.model/src/main/java/li/strolch/model/Tags.java similarity index 100% rename from src/main/java/li/strolch/model/Tags.java rename to li.strolch.model/src/main/java/li/strolch/model/Tags.java diff --git a/src/main/java/li/strolch/model/audit/AccessType.java b/li.strolch.model/src/main/java/li/strolch/model/audit/AccessType.java similarity index 100% rename from src/main/java/li/strolch/model/audit/AccessType.java rename to li.strolch.model/src/main/java/li/strolch/model/audit/AccessType.java diff --git a/src/main/java/li/strolch/model/audit/ActionSelection.java b/li.strolch.model/src/main/java/li/strolch/model/audit/ActionSelection.java similarity index 100% rename from src/main/java/li/strolch/model/audit/ActionSelection.java rename to li.strolch.model/src/main/java/li/strolch/model/audit/ActionSelection.java diff --git a/src/main/java/li/strolch/model/audit/Audit.java b/li.strolch.model/src/main/java/li/strolch/model/audit/Audit.java similarity index 100% rename from src/main/java/li/strolch/model/audit/Audit.java rename to li.strolch.model/src/main/java/li/strolch/model/audit/Audit.java diff --git a/src/main/java/li/strolch/model/audit/AuditFromDomReader.java b/li.strolch.model/src/main/java/li/strolch/model/audit/AuditFromDomReader.java similarity index 100% rename from src/main/java/li/strolch/model/audit/AuditFromDomReader.java rename to li.strolch.model/src/main/java/li/strolch/model/audit/AuditFromDomReader.java diff --git a/src/main/java/li/strolch/model/audit/AuditQuery.java b/li.strolch.model/src/main/java/li/strolch/model/audit/AuditQuery.java similarity index 100% rename from src/main/java/li/strolch/model/audit/AuditQuery.java rename to li.strolch.model/src/main/java/li/strolch/model/audit/AuditQuery.java diff --git a/src/main/java/li/strolch/model/audit/AuditQueryVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/audit/AuditQueryVisitor.java similarity index 100% rename from src/main/java/li/strolch/model/audit/AuditQueryVisitor.java rename to li.strolch.model/src/main/java/li/strolch/model/audit/AuditQueryVisitor.java diff --git a/src/main/java/li/strolch/model/audit/AuditSaxReader.java b/li.strolch.model/src/main/java/li/strolch/model/audit/AuditSaxReader.java similarity index 100% rename from src/main/java/li/strolch/model/audit/AuditSaxReader.java rename to li.strolch.model/src/main/java/li/strolch/model/audit/AuditSaxReader.java diff --git a/src/main/java/li/strolch/model/audit/AuditSelection.java b/li.strolch.model/src/main/java/li/strolch/model/audit/AuditSelection.java similarity index 100% rename from src/main/java/li/strolch/model/audit/AuditSelection.java rename to li.strolch.model/src/main/java/li/strolch/model/audit/AuditSelection.java diff --git a/src/main/java/li/strolch/model/audit/AuditToDomVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/audit/AuditToDomVisitor.java similarity index 100% rename from src/main/java/li/strolch/model/audit/AuditToDomVisitor.java rename to li.strolch.model/src/main/java/li/strolch/model/audit/AuditToDomVisitor.java diff --git a/src/main/java/li/strolch/model/audit/AuditVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/audit/AuditVisitor.java similarity index 100% rename from src/main/java/li/strolch/model/audit/AuditVisitor.java rename to li.strolch.model/src/main/java/li/strolch/model/audit/AuditVisitor.java diff --git a/src/main/java/li/strolch/model/audit/ElementSelection.java b/li.strolch.model/src/main/java/li/strolch/model/audit/ElementSelection.java similarity index 100% rename from src/main/java/li/strolch/model/audit/ElementSelection.java rename to li.strolch.model/src/main/java/li/strolch/model/audit/ElementSelection.java diff --git a/src/main/java/li/strolch/model/audit/IdentitySelection.java b/li.strolch.model/src/main/java/li/strolch/model/audit/IdentitySelection.java similarity index 100% rename from src/main/java/li/strolch/model/audit/IdentitySelection.java rename to li.strolch.model/src/main/java/li/strolch/model/audit/IdentitySelection.java diff --git a/src/main/java/li/strolch/model/audit/NoStrategyAuditVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/audit/NoStrategyAuditVisitor.java similarity index 100% rename from src/main/java/li/strolch/model/audit/NoStrategyAuditVisitor.java rename to li.strolch.model/src/main/java/li/strolch/model/audit/NoStrategyAuditVisitor.java diff --git a/src/main/java/li/strolch/model/parameter/AbstractParameter.java b/li.strolch.model/src/main/java/li/strolch/model/parameter/AbstractParameter.java similarity index 100% rename from src/main/java/li/strolch/model/parameter/AbstractParameter.java rename to li.strolch.model/src/main/java/li/strolch/model/parameter/AbstractParameter.java diff --git a/src/main/java/li/strolch/model/parameter/BooleanParameter.java b/li.strolch.model/src/main/java/li/strolch/model/parameter/BooleanParameter.java similarity index 100% rename from src/main/java/li/strolch/model/parameter/BooleanParameter.java rename to li.strolch.model/src/main/java/li/strolch/model/parameter/BooleanParameter.java diff --git a/src/main/java/li/strolch/model/parameter/DateParameter.java b/li.strolch.model/src/main/java/li/strolch/model/parameter/DateParameter.java similarity index 100% rename from src/main/java/li/strolch/model/parameter/DateParameter.java rename to li.strolch.model/src/main/java/li/strolch/model/parameter/DateParameter.java diff --git a/src/main/java/li/strolch/model/parameter/FloatParameter.java b/li.strolch.model/src/main/java/li/strolch/model/parameter/FloatParameter.java similarity index 100% rename from src/main/java/li/strolch/model/parameter/FloatParameter.java rename to li.strolch.model/src/main/java/li/strolch/model/parameter/FloatParameter.java diff --git a/src/main/java/li/strolch/model/parameter/IntegerParameter.java b/li.strolch.model/src/main/java/li/strolch/model/parameter/IntegerParameter.java similarity index 100% rename from src/main/java/li/strolch/model/parameter/IntegerParameter.java rename to li.strolch.model/src/main/java/li/strolch/model/parameter/IntegerParameter.java diff --git a/src/main/java/li/strolch/model/parameter/ListParameter.java b/li.strolch.model/src/main/java/li/strolch/model/parameter/ListParameter.java similarity index 100% rename from src/main/java/li/strolch/model/parameter/ListParameter.java rename to li.strolch.model/src/main/java/li/strolch/model/parameter/ListParameter.java diff --git a/src/main/java/li/strolch/model/parameter/LongParameter.java b/li.strolch.model/src/main/java/li/strolch/model/parameter/LongParameter.java similarity index 100% rename from src/main/java/li/strolch/model/parameter/LongParameter.java rename to li.strolch.model/src/main/java/li/strolch/model/parameter/LongParameter.java diff --git a/src/main/java/li/strolch/model/parameter/Parameter.java b/li.strolch.model/src/main/java/li/strolch/model/parameter/Parameter.java similarity index 100% rename from src/main/java/li/strolch/model/parameter/Parameter.java rename to li.strolch.model/src/main/java/li/strolch/model/parameter/Parameter.java diff --git a/src/main/java/li/strolch/model/parameter/StringListParameter.java b/li.strolch.model/src/main/java/li/strolch/model/parameter/StringListParameter.java similarity index 100% rename from src/main/java/li/strolch/model/parameter/StringListParameter.java rename to li.strolch.model/src/main/java/li/strolch/model/parameter/StringListParameter.java diff --git a/src/main/java/li/strolch/model/parameter/StringParameter.java b/li.strolch.model/src/main/java/li/strolch/model/parameter/StringParameter.java similarity index 100% rename from src/main/java/li/strolch/model/parameter/StringParameter.java rename to li.strolch.model/src/main/java/li/strolch/model/parameter/StringParameter.java diff --git a/src/main/java/li/strolch/model/query/AndSelection.java b/li.strolch.model/src/main/java/li/strolch/model/query/AndSelection.java similarity index 100% rename from src/main/java/li/strolch/model/query/AndSelection.java rename to li.strolch.model/src/main/java/li/strolch/model/query/AndSelection.java diff --git a/src/main/java/li/strolch/model/query/AnySelection.java b/li.strolch.model/src/main/java/li/strolch/model/query/AnySelection.java similarity index 100% rename from src/main/java/li/strolch/model/query/AnySelection.java rename to li.strolch.model/src/main/java/li/strolch/model/query/AnySelection.java diff --git a/src/main/java/li/strolch/model/query/BooleanSelection.java b/li.strolch.model/src/main/java/li/strolch/model/query/BooleanSelection.java similarity index 100% rename from src/main/java/li/strolch/model/query/BooleanSelection.java rename to li.strolch.model/src/main/java/li/strolch/model/query/BooleanSelection.java diff --git a/src/main/java/li/strolch/model/query/DateSelection.java b/li.strolch.model/src/main/java/li/strolch/model/query/DateSelection.java similarity index 100% rename from src/main/java/li/strolch/model/query/DateSelection.java rename to li.strolch.model/src/main/java/li/strolch/model/query/DateSelection.java diff --git a/src/main/java/li/strolch/model/query/IdSelection.java b/li.strolch.model/src/main/java/li/strolch/model/query/IdSelection.java similarity index 100% rename from src/main/java/li/strolch/model/query/IdSelection.java rename to li.strolch.model/src/main/java/li/strolch/model/query/IdSelection.java diff --git a/src/main/java/li/strolch/model/query/NameSelection.java b/li.strolch.model/src/main/java/li/strolch/model/query/NameSelection.java similarity index 100% rename from src/main/java/li/strolch/model/query/NameSelection.java rename to li.strolch.model/src/main/java/li/strolch/model/query/NameSelection.java diff --git a/src/main/java/li/strolch/model/query/Navigation.java b/li.strolch.model/src/main/java/li/strolch/model/query/Navigation.java similarity index 100% rename from src/main/java/li/strolch/model/query/Navigation.java rename to li.strolch.model/src/main/java/li/strolch/model/query/Navigation.java diff --git a/src/main/java/li/strolch/model/query/NotSelection.java b/li.strolch.model/src/main/java/li/strolch/model/query/NotSelection.java similarity index 100% rename from src/main/java/li/strolch/model/query/NotSelection.java rename to li.strolch.model/src/main/java/li/strolch/model/query/NotSelection.java diff --git a/src/main/java/li/strolch/model/query/OrSelection.java b/li.strolch.model/src/main/java/li/strolch/model/query/OrSelection.java similarity index 100% rename from src/main/java/li/strolch/model/query/OrSelection.java rename to li.strolch.model/src/main/java/li/strolch/model/query/OrSelection.java diff --git a/src/main/java/li/strolch/model/query/OrderQuery.java b/li.strolch.model/src/main/java/li/strolch/model/query/OrderQuery.java similarity index 100% rename from src/main/java/li/strolch/model/query/OrderQuery.java rename to li.strolch.model/src/main/java/li/strolch/model/query/OrderQuery.java diff --git a/src/main/java/li/strolch/model/query/OrderQueryVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/query/OrderQueryVisitor.java similarity index 100% rename from src/main/java/li/strolch/model/query/OrderQueryVisitor.java rename to li.strolch.model/src/main/java/li/strolch/model/query/OrderQueryVisitor.java diff --git a/src/main/java/li/strolch/model/query/OrderSelection.java b/li.strolch.model/src/main/java/li/strolch/model/query/OrderSelection.java similarity index 100% rename from src/main/java/li/strolch/model/query/OrderSelection.java rename to li.strolch.model/src/main/java/li/strolch/model/query/OrderSelection.java diff --git a/src/main/java/li/strolch/model/query/OrderSelectionVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/query/OrderSelectionVisitor.java similarity index 100% rename from src/main/java/li/strolch/model/query/OrderSelectionVisitor.java rename to li.strolch.model/src/main/java/li/strolch/model/query/OrderSelectionVisitor.java diff --git a/src/main/java/li/strolch/model/query/ParameterBagSelection.java b/li.strolch.model/src/main/java/li/strolch/model/query/ParameterBagSelection.java similarity index 100% rename from src/main/java/li/strolch/model/query/ParameterBagSelection.java rename to li.strolch.model/src/main/java/li/strolch/model/query/ParameterBagSelection.java diff --git a/src/main/java/li/strolch/model/query/ParameterSelection.java b/li.strolch.model/src/main/java/li/strolch/model/query/ParameterSelection.java similarity index 100% rename from src/main/java/li/strolch/model/query/ParameterSelection.java rename to li.strolch.model/src/main/java/li/strolch/model/query/ParameterSelection.java diff --git a/src/main/java/li/strolch/model/query/ParameterSelectionVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/query/ParameterSelectionVisitor.java similarity index 100% rename from src/main/java/li/strolch/model/query/ParameterSelectionVisitor.java rename to li.strolch.model/src/main/java/li/strolch/model/query/ParameterSelectionVisitor.java diff --git a/src/main/java/li/strolch/model/query/QueryVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/query/QueryVisitor.java similarity index 100% rename from src/main/java/li/strolch/model/query/QueryVisitor.java rename to li.strolch.model/src/main/java/li/strolch/model/query/QueryVisitor.java diff --git a/src/main/java/li/strolch/model/query/ResourceQuery.java b/li.strolch.model/src/main/java/li/strolch/model/query/ResourceQuery.java similarity index 100% rename from src/main/java/li/strolch/model/query/ResourceQuery.java rename to li.strolch.model/src/main/java/li/strolch/model/query/ResourceQuery.java diff --git a/src/main/java/li/strolch/model/query/ResourceQueryVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/query/ResourceQueryVisitor.java similarity index 100% rename from src/main/java/li/strolch/model/query/ResourceQueryVisitor.java rename to li.strolch.model/src/main/java/li/strolch/model/query/ResourceQueryVisitor.java diff --git a/src/main/java/li/strolch/model/query/Selection.java b/li.strolch.model/src/main/java/li/strolch/model/query/Selection.java similarity index 100% rename from src/main/java/li/strolch/model/query/Selection.java rename to li.strolch.model/src/main/java/li/strolch/model/query/Selection.java diff --git a/src/main/java/li/strolch/model/query/StateSelection.java b/li.strolch.model/src/main/java/li/strolch/model/query/StateSelection.java similarity index 100% rename from src/main/java/li/strolch/model/query/StateSelection.java rename to li.strolch.model/src/main/java/li/strolch/model/query/StateSelection.java diff --git a/src/main/java/li/strolch/model/query/StringSelection.java b/li.strolch.model/src/main/java/li/strolch/model/query/StringSelection.java similarity index 100% rename from src/main/java/li/strolch/model/query/StringSelection.java rename to li.strolch.model/src/main/java/li/strolch/model/query/StringSelection.java diff --git a/src/main/java/li/strolch/model/query/StrolchElementQuery.java b/li.strolch.model/src/main/java/li/strolch/model/query/StrolchElementQuery.java similarity index 100% rename from src/main/java/li/strolch/model/query/StrolchElementQuery.java rename to li.strolch.model/src/main/java/li/strolch/model/query/StrolchElementQuery.java diff --git a/src/main/java/li/strolch/model/query/StrolchElementSelection.java b/li.strolch.model/src/main/java/li/strolch/model/query/StrolchElementSelection.java similarity index 100% rename from src/main/java/li/strolch/model/query/StrolchElementSelection.java rename to li.strolch.model/src/main/java/li/strolch/model/query/StrolchElementSelection.java diff --git a/src/main/java/li/strolch/model/query/StrolchElementSelectionVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/query/StrolchElementSelectionVisitor.java similarity index 100% rename from src/main/java/li/strolch/model/query/StrolchElementSelectionVisitor.java rename to li.strolch.model/src/main/java/li/strolch/model/query/StrolchElementSelectionVisitor.java diff --git a/src/main/java/li/strolch/model/query/StrolchQuery.java b/li.strolch.model/src/main/java/li/strolch/model/query/StrolchQuery.java similarity index 100% rename from src/main/java/li/strolch/model/query/StrolchQuery.java rename to li.strolch.model/src/main/java/li/strolch/model/query/StrolchQuery.java diff --git a/src/main/java/li/strolch/model/query/StrolchRootElementSelectionVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/query/StrolchRootElementSelectionVisitor.java similarity index 100% rename from src/main/java/li/strolch/model/query/StrolchRootElementSelectionVisitor.java rename to li.strolch.model/src/main/java/li/strolch/model/query/StrolchRootElementSelectionVisitor.java diff --git a/src/main/java/li/strolch/model/query/StrolchTypeNavigation.java b/li.strolch.model/src/main/java/li/strolch/model/query/StrolchTypeNavigation.java similarity index 100% rename from src/main/java/li/strolch/model/query/StrolchTypeNavigation.java rename to li.strolch.model/src/main/java/li/strolch/model/query/StrolchTypeNavigation.java diff --git a/src/main/java/li/strolch/model/timedstate/AbstractStrolchTimedState.java b/li.strolch.model/src/main/java/li/strolch/model/timedstate/AbstractStrolchTimedState.java similarity index 100% rename from src/main/java/li/strolch/model/timedstate/AbstractStrolchTimedState.java rename to li.strolch.model/src/main/java/li/strolch/model/timedstate/AbstractStrolchTimedState.java diff --git a/src/main/java/li/strolch/model/timedstate/BooleanTimedState.java b/li.strolch.model/src/main/java/li/strolch/model/timedstate/BooleanTimedState.java similarity index 100% rename from src/main/java/li/strolch/model/timedstate/BooleanTimedState.java rename to li.strolch.model/src/main/java/li/strolch/model/timedstate/BooleanTimedState.java diff --git a/src/main/java/li/strolch/model/timedstate/FloatTimedState.java b/li.strolch.model/src/main/java/li/strolch/model/timedstate/FloatTimedState.java similarity index 100% rename from src/main/java/li/strolch/model/timedstate/FloatTimedState.java rename to li.strolch.model/src/main/java/li/strolch/model/timedstate/FloatTimedState.java diff --git a/src/main/java/li/strolch/model/timedstate/ITimedState.java b/li.strolch.model/src/main/java/li/strolch/model/timedstate/ITimedState.java similarity index 100% rename from src/main/java/li/strolch/model/timedstate/ITimedState.java rename to li.strolch.model/src/main/java/li/strolch/model/timedstate/ITimedState.java diff --git a/src/main/java/li/strolch/model/timedstate/IntegerTimedState.java b/li.strolch.model/src/main/java/li/strolch/model/timedstate/IntegerTimedState.java similarity index 100% rename from src/main/java/li/strolch/model/timedstate/IntegerTimedState.java rename to li.strolch.model/src/main/java/li/strolch/model/timedstate/IntegerTimedState.java diff --git a/src/main/java/li/strolch/model/timedstate/StringSetTimedState.java b/li.strolch.model/src/main/java/li/strolch/model/timedstate/StringSetTimedState.java similarity index 100% rename from src/main/java/li/strolch/model/timedstate/StringSetTimedState.java rename to li.strolch.model/src/main/java/li/strolch/model/timedstate/StringSetTimedState.java diff --git a/src/main/java/li/strolch/model/timedstate/StrolchTimedState.java b/li.strolch.model/src/main/java/li/strolch/model/timedstate/StrolchTimedState.java similarity index 100% rename from src/main/java/li/strolch/model/timedstate/StrolchTimedState.java rename to li.strolch.model/src/main/java/li/strolch/model/timedstate/StrolchTimedState.java diff --git a/src/main/java/li/strolch/model/timedstate/TimedState.java b/li.strolch.model/src/main/java/li/strolch/model/timedstate/TimedState.java similarity index 100% rename from src/main/java/li/strolch/model/timedstate/TimedState.java rename to li.strolch.model/src/main/java/li/strolch/model/timedstate/TimedState.java diff --git a/src/main/java/li/strolch/model/timevalue/ITimeValue.java b/li.strolch.model/src/main/java/li/strolch/model/timevalue/ITimeValue.java similarity index 100% rename from src/main/java/li/strolch/model/timevalue/ITimeValue.java rename to li.strolch.model/src/main/java/li/strolch/model/timevalue/ITimeValue.java diff --git a/src/main/java/li/strolch/model/timevalue/ITimeVariable.java b/li.strolch.model/src/main/java/li/strolch/model/timevalue/ITimeVariable.java similarity index 100% rename from src/main/java/li/strolch/model/timevalue/ITimeVariable.java rename to li.strolch.model/src/main/java/li/strolch/model/timevalue/ITimeVariable.java diff --git a/src/main/java/li/strolch/model/timevalue/IValue.java b/li.strolch.model/src/main/java/li/strolch/model/timevalue/IValue.java similarity index 100% rename from src/main/java/li/strolch/model/timevalue/IValue.java rename to li.strolch.model/src/main/java/li/strolch/model/timevalue/IValue.java diff --git a/src/main/java/li/strolch/model/timevalue/IValueChange.java b/li.strolch.model/src/main/java/li/strolch/model/timevalue/IValueChange.java similarity index 100% rename from src/main/java/li/strolch/model/timevalue/IValueChange.java rename to li.strolch.model/src/main/java/li/strolch/model/timevalue/IValueChange.java diff --git a/src/main/java/li/strolch/model/timevalue/impl/AString.java b/li.strolch.model/src/main/java/li/strolch/model/timevalue/impl/AString.java similarity index 100% rename from src/main/java/li/strolch/model/timevalue/impl/AString.java rename to li.strolch.model/src/main/java/li/strolch/model/timevalue/impl/AString.java diff --git a/src/main/java/li/strolch/model/timevalue/impl/BooleanValue.java b/li.strolch.model/src/main/java/li/strolch/model/timevalue/impl/BooleanValue.java similarity index 100% rename from src/main/java/li/strolch/model/timevalue/impl/BooleanValue.java rename to li.strolch.model/src/main/java/li/strolch/model/timevalue/impl/BooleanValue.java diff --git a/src/main/java/li/strolch/model/timevalue/impl/FloatValue.java b/li.strolch.model/src/main/java/li/strolch/model/timevalue/impl/FloatValue.java similarity index 100% rename from src/main/java/li/strolch/model/timevalue/impl/FloatValue.java rename to li.strolch.model/src/main/java/li/strolch/model/timevalue/impl/FloatValue.java diff --git a/src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java b/li.strolch.model/src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java similarity index 100% rename from src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java rename to li.strolch.model/src/main/java/li/strolch/model/timevalue/impl/IntegerValue.java diff --git a/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java b/li.strolch.model/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java similarity index 100% rename from src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java rename to li.strolch.model/src/main/java/li/strolch/model/timevalue/impl/StringSetValue.java diff --git a/src/main/java/li/strolch/model/timevalue/impl/TimeValue.java b/li.strolch.model/src/main/java/li/strolch/model/timevalue/impl/TimeValue.java similarity index 100% rename from src/main/java/li/strolch/model/timevalue/impl/TimeValue.java rename to li.strolch.model/src/main/java/li/strolch/model/timevalue/impl/TimeValue.java diff --git a/src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java b/li.strolch.model/src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java similarity index 100% rename from src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java rename to li.strolch.model/src/main/java/li/strolch/model/timevalue/impl/TimeVariable.java diff --git a/src/main/java/li/strolch/model/timevalue/impl/ValueChange.java b/li.strolch.model/src/main/java/li/strolch/model/timevalue/impl/ValueChange.java similarity index 100% rename from src/main/java/li/strolch/model/timevalue/impl/ValueChange.java rename to li.strolch.model/src/main/java/li/strolch/model/timevalue/impl/ValueChange.java diff --git a/src/main/java/li/strolch/model/visitor/ElementTypeVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/visitor/ElementTypeVisitor.java similarity index 100% rename from src/main/java/li/strolch/model/visitor/ElementTypeVisitor.java rename to li.strolch.model/src/main/java/li/strolch/model/visitor/ElementTypeVisitor.java diff --git a/src/main/java/li/strolch/model/visitor/NoStrategyOrderVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/visitor/NoStrategyOrderVisitor.java similarity index 100% rename from src/main/java/li/strolch/model/visitor/NoStrategyOrderVisitor.java rename to li.strolch.model/src/main/java/li/strolch/model/visitor/NoStrategyOrderVisitor.java diff --git a/src/main/java/li/strolch/model/visitor/NoStrategyResourceVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/visitor/NoStrategyResourceVisitor.java similarity index 100% rename from src/main/java/li/strolch/model/visitor/NoStrategyResourceVisitor.java rename to li.strolch.model/src/main/java/li/strolch/model/visitor/NoStrategyResourceVisitor.java diff --git a/src/main/java/li/strolch/model/visitor/NoStrategyVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/visitor/NoStrategyVisitor.java similarity index 100% rename from src/main/java/li/strolch/model/visitor/NoStrategyVisitor.java rename to li.strolch.model/src/main/java/li/strolch/model/visitor/NoStrategyVisitor.java diff --git a/src/main/java/li/strolch/model/visitor/OrderDeepEqualsVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/visitor/OrderDeepEqualsVisitor.java similarity index 100% rename from src/main/java/li/strolch/model/visitor/OrderDeepEqualsVisitor.java rename to li.strolch.model/src/main/java/li/strolch/model/visitor/OrderDeepEqualsVisitor.java diff --git a/src/main/java/li/strolch/model/visitor/ParameterVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/visitor/ParameterVisitor.java similarity index 100% rename from src/main/java/li/strolch/model/visitor/ParameterVisitor.java rename to li.strolch.model/src/main/java/li/strolch/model/visitor/ParameterVisitor.java diff --git a/src/main/java/li/strolch/model/visitor/ResourceDeepEqualsVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/visitor/ResourceDeepEqualsVisitor.java similarity index 100% rename from src/main/java/li/strolch/model/visitor/ResourceDeepEqualsVisitor.java rename to li.strolch.model/src/main/java/li/strolch/model/visitor/ResourceDeepEqualsVisitor.java diff --git a/src/main/java/li/strolch/model/visitor/SetParameterValueVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/visitor/SetParameterValueVisitor.java similarity index 100% rename from src/main/java/li/strolch/model/visitor/SetParameterValueVisitor.java rename to li.strolch.model/src/main/java/li/strolch/model/visitor/SetParameterValueVisitor.java diff --git a/src/main/java/li/strolch/model/visitor/StrolchElementDeepEqualsVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/visitor/StrolchElementDeepEqualsVisitor.java similarity index 100% rename from src/main/java/li/strolch/model/visitor/StrolchElementDeepEqualsVisitor.java rename to li.strolch.model/src/main/java/li/strolch/model/visitor/StrolchElementDeepEqualsVisitor.java diff --git a/src/main/java/li/strolch/model/visitor/StrolchElementVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/visitor/StrolchElementVisitor.java similarity index 100% rename from src/main/java/li/strolch/model/visitor/StrolchElementVisitor.java rename to li.strolch.model/src/main/java/li/strolch/model/visitor/StrolchElementVisitor.java diff --git a/src/main/java/li/strolch/model/visitor/StrolchRootElementVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/visitor/StrolchRootElementVisitor.java similarity index 100% rename from src/main/java/li/strolch/model/visitor/StrolchRootElementVisitor.java rename to li.strolch.model/src/main/java/li/strolch/model/visitor/StrolchRootElementVisitor.java diff --git a/src/main/java/li/strolch/model/visitor/StrolchVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/visitor/StrolchVisitor.java similarity index 100% rename from src/main/java/li/strolch/model/visitor/StrolchVisitor.java rename to li.strolch.model/src/main/java/li/strolch/model/visitor/StrolchVisitor.java diff --git a/src/main/java/li/strolch/model/visitor/TimedStateVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/visitor/TimedStateVisitor.java similarity index 100% rename from src/main/java/li/strolch/model/visitor/TimedStateVisitor.java rename to li.strolch.model/src/main/java/li/strolch/model/visitor/TimedStateVisitor.java diff --git a/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java similarity index 100% rename from src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java rename to li.strolch.model/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java diff --git a/src/main/java/li/strolch/model/xml/OrderToDomVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/xml/OrderToDomVisitor.java similarity index 100% rename from src/main/java/li/strolch/model/xml/OrderToDomVisitor.java rename to li.strolch.model/src/main/java/li/strolch/model/xml/OrderToDomVisitor.java diff --git a/src/main/java/li/strolch/model/xml/OrderToSaxVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/xml/OrderToSaxVisitor.java similarity index 100% rename from src/main/java/li/strolch/model/xml/OrderToSaxVisitor.java rename to li.strolch.model/src/main/java/li/strolch/model/xml/OrderToSaxVisitor.java diff --git a/src/main/java/li/strolch/model/xml/OrderToSaxWriterVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/xml/OrderToSaxWriterVisitor.java similarity index 100% rename from src/main/java/li/strolch/model/xml/OrderToSaxWriterVisitor.java rename to li.strolch.model/src/main/java/li/strolch/model/xml/OrderToSaxWriterVisitor.java diff --git a/src/main/java/li/strolch/model/xml/ResourceToDomVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/xml/ResourceToDomVisitor.java similarity index 100% rename from src/main/java/li/strolch/model/xml/ResourceToDomVisitor.java rename to li.strolch.model/src/main/java/li/strolch/model/xml/ResourceToDomVisitor.java diff --git a/src/main/java/li/strolch/model/xml/ResourceToSaxVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/xml/ResourceToSaxVisitor.java similarity index 100% rename from src/main/java/li/strolch/model/xml/ResourceToSaxVisitor.java rename to li.strolch.model/src/main/java/li/strolch/model/xml/ResourceToSaxVisitor.java diff --git a/src/main/java/li/strolch/model/xml/ResourceToSaxWriterVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/xml/ResourceToSaxWriterVisitor.java similarity index 100% rename from src/main/java/li/strolch/model/xml/ResourceToSaxWriterVisitor.java rename to li.strolch.model/src/main/java/li/strolch/model/xml/ResourceToSaxWriterVisitor.java diff --git a/src/main/java/li/strolch/model/xml/SimpleStrolchElementListener.java b/li.strolch.model/src/main/java/li/strolch/model/xml/SimpleStrolchElementListener.java similarity index 100% rename from src/main/java/li/strolch/model/xml/SimpleStrolchElementListener.java rename to li.strolch.model/src/main/java/li/strolch/model/xml/SimpleStrolchElementListener.java diff --git a/src/main/java/li/strolch/model/xml/StrolchElementListener.java b/li.strolch.model/src/main/java/li/strolch/model/xml/StrolchElementListener.java similarity index 100% rename from src/main/java/li/strolch/model/xml/StrolchElementListener.java rename to li.strolch.model/src/main/java/li/strolch/model/xml/StrolchElementListener.java diff --git a/src/main/java/li/strolch/model/xml/StrolchElementToSaxVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/xml/StrolchElementToSaxVisitor.java similarity index 100% rename from src/main/java/li/strolch/model/xml/StrolchElementToSaxVisitor.java rename to li.strolch.model/src/main/java/li/strolch/model/xml/StrolchElementToSaxVisitor.java diff --git a/src/main/java/li/strolch/model/xml/XmlModelSaxFileReader.java b/li.strolch.model/src/main/java/li/strolch/model/xml/XmlModelSaxFileReader.java similarity index 100% rename from src/main/java/li/strolch/model/xml/XmlModelSaxFileReader.java rename to li.strolch.model/src/main/java/li/strolch/model/xml/XmlModelSaxFileReader.java diff --git a/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java b/li.strolch.model/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java similarity index 100% rename from src/main/java/li/strolch/model/xml/XmlModelSaxReader.java rename to li.strolch.model/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java diff --git a/src/main/resources/componentVersion.properties b/li.strolch.model/src/main/resources/componentVersion.properties similarity index 100% rename from src/main/resources/componentVersion.properties rename to li.strolch.model/src/main/resources/componentVersion.properties diff --git a/src/test/java/li/strolch/model/ModelTest.java b/li.strolch.model/src/test/java/li/strolch/model/ModelTest.java similarity index 100% rename from src/test/java/li/strolch/model/ModelTest.java rename to li.strolch.model/src/test/java/li/strolch/model/ModelTest.java diff --git a/src/test/java/li/strolch/model/XmlModelDefaultHandlerTest.java b/li.strolch.model/src/test/java/li/strolch/model/XmlModelDefaultHandlerTest.java similarity index 100% rename from src/test/java/li/strolch/model/XmlModelDefaultHandlerTest.java rename to li.strolch.model/src/test/java/li/strolch/model/XmlModelDefaultHandlerTest.java diff --git a/src/test/java/li/strolch/model/XmlToDomTest.java b/li.strolch.model/src/test/java/li/strolch/model/XmlToDomTest.java similarity index 100% rename from src/test/java/li/strolch/model/XmlToDomTest.java rename to li.strolch.model/src/test/java/li/strolch/model/XmlToDomTest.java diff --git a/src/test/java/li/strolch/model/timedstate/StrolchTimedStateTest.java b/li.strolch.model/src/test/java/li/strolch/model/timedstate/StrolchTimedStateTest.java similarity index 100% rename from src/test/java/li/strolch/model/timedstate/StrolchTimedStateTest.java rename to li.strolch.model/src/test/java/li/strolch/model/timedstate/StrolchTimedStateTest.java diff --git a/src/test/java/li/strolch/model/timedstate/TimeStateTest.java b/li.strolch.model/src/test/java/li/strolch/model/timedstate/TimeStateTest.java similarity index 100% rename from src/test/java/li/strolch/model/timedstate/TimeStateTest.java rename to li.strolch.model/src/test/java/li/strolch/model/timedstate/TimeStateTest.java diff --git a/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java b/li.strolch.model/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java similarity index 100% rename from src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java rename to li.strolch.model/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java diff --git a/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java b/li.strolch.model/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java similarity index 100% rename from src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java rename to li.strolch.model/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java diff --git a/src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java b/li.strolch.model/src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java similarity index 100% rename from src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java rename to li.strolch.model/src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java diff --git a/src/test/java/li/strolch/model/timevalue/ValueTests.java b/li.strolch.model/src/test/java/li/strolch/model/timevalue/ValueTests.java similarity index 100% rename from src/test/java/li/strolch/model/timevalue/ValueTests.java rename to li.strolch.model/src/test/java/li/strolch/model/timevalue/ValueTests.java diff --git a/src/test/resources/data/StrolchModel.xml b/li.strolch.model/src/test/resources/data/StrolchModel.xml similarity index 100% rename from src/test/resources/data/StrolchModel.xml rename to li.strolch.model/src/test/resources/data/StrolchModel.xml diff --git a/src/test/resources/data/orders/Orders.xml b/li.strolch.model/src/test/resources/data/orders/Orders.xml similarity index 100% rename from src/test/resources/data/orders/Orders.xml rename to li.strolch.model/src/test/resources/data/orders/Orders.xml diff --git a/src/test/resources/data/orders/Templates.xml b/li.strolch.model/src/test/resources/data/orders/Templates.xml similarity index 100% rename from src/test/resources/data/orders/Templates.xml rename to li.strolch.model/src/test/resources/data/orders/Templates.xml diff --git a/src/test/resources/data/resources/Resources.xml b/li.strolch.model/src/test/resources/data/resources/Resources.xml similarity index 100% rename from src/test/resources/data/resources/Resources.xml rename to li.strolch.model/src/test/resources/data/resources/Resources.xml diff --git a/src/test/resources/data/resources/Templates.xml b/li.strolch.model/src/test/resources/data/resources/Templates.xml similarity index 100% rename from src/test/resources/data/resources/Templates.xml rename to li.strolch.model/src/test/resources/data/resources/Templates.xml diff --git a/src/test/resources/log4j.xml b/li.strolch.model/src/test/resources/log4j.xml similarity index 100% rename from src/test/resources/log4j.xml rename to li.strolch.model/src/test/resources/log4j.xml