Author: chatellier Date: 2008-09-23 10:30:37 +0000 (Tue, 23 Sep 2008) New Revision: 90 Modified: lutinmatrix/trunk/LICENSE.txt lutinmatrix/trunk/changelog lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/BasicMatrix.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/BasicMatrixIterator.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DimensionHelper.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DoubleBigVector.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DoubleVector.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/FloatBigVector.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/FloatVector.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MapFunction.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixEncoder.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixException.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixHelper.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixIterator.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixIteratorImpl.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixNDImpl.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SemanticList.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SubMatrix.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/Vector.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEditor.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEvent.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelListener.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPopupMenu.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModel.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModelLinear.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModelND.java lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/BasicMatrixBigTest.java lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/BasicMatrixTest.java lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/FloatVectorTest.java lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/ImportExportMatrixTest.java lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixEncoderDecoderTest.java lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixHelperTest.java lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/PerfTest.java lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/SubMatrixTest.java lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/gui/MatrixTableModelTest.java Log: Switch to LGPL v3, format code (eclipse), organise import Modified: lutinmatrix/trunk/LICENSE.txt =================================================================== --- lutinmatrix/trunk/LICENSE.txt 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/LICENSE.txt 2008-09-23 10:30:37 UTC (rev 90) @@ -1,280 +1,674 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. - Preamble + Preamble - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to + 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 -this service 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. +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 make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. + 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 give the recipients all the rights that -you have. 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. +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. - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. + 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. - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. + 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. - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. + 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. - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + TERMS AND CONDITIONS - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". + 0. Definitions. -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. + "This License" refers to version 3 of the GNU General Public License. - 1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. + "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. - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: + 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) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. + A "covered work" means either the unmodified Program or a work based +on the Program. - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. + 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. - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) + 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. -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. + 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. -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. + 1. Source Code. -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. + 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. - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: + 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. - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, + 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. - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, + 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. - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. + The Corresponding Source for a work in source code form is that +same work. -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. + 2. Basic Permissions. - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. + 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. - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. + 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. - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to + 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. - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or + 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 -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. +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. -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. + 13. Use with the GNU Affero General Public License. -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. + 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. -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. + 14. Revised Versions of this License. - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will + 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 a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. + 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. - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. + 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. - NO WARRANTY + 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. - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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. + 15. Disclaimer of Warranty. - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE 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. + 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. - END OF TERMS AND CONDITIONS + 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. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + 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 <http://www.gnu.org/licenses/>. + +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: + + <program> Copyright (C) <year> <name of author> + 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 +<http://www.gnu.org/licenses/>. + + 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 +<http://www.gnu.org/philosophy/why-not-lgpl.html>. Modified: lutinmatrix/trunk/changelog =================================================================== --- lutinmatrix/trunk/changelog 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/changelog 2008-09-23 10:30:37 UTC (rev 90) @@ -1,4 +1,5 @@ ver-1.1 + * Switch to LGPL v3 * Update site on maven2 * Comment lutinxml dependent tests * Remove unnecessary files Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,21 +1,19 @@ -/* *##% - * Copyright (C) 2002, 2003, 2004 Code Lutin, Cédric Pineau, - * Benjamin Poussin +/* *##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin * - * 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 2 - * of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Lesser Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * * AbstractMatrixND.java @@ -53,19 +51,21 @@ static private Log log = LogFactory.getLog(AbstractMatrixND.class); abstract public MatrixIterator iterator(); - abstract public double getValue(int [] coordinates); - abstract public void setValue(int [] coordinates, double d); + abstract public double getValue(int[] coordinates); + + abstract public void setValue(int[] coordinates, double d); + transient protected DimensionHelper dimHelper = new DimensionHelper(); transient protected MatrixFactory factory = null; protected String name = ""; - protected String [] dimNames = null; - protected int [] dim = null; + protected String[] dimNames = null; + protected int[] dim = null; protected List[] semantics = null; protected double defaultValue = 0; - protected void init(int [] dim){ + protected void init(int[] dim) { this.dim = new int[dim.length]; System.arraycopy(dim, 0, this.dim, 0, dim.length); semantics = new List[dim.length]; @@ -74,22 +74,23 @@ Arrays.fill(dimNames, ""); } - protected AbstractMatrixND(MatrixFactory factory){ + protected AbstractMatrixND(MatrixFactory factory) { this.factory = factory; } - public AbstractMatrixND(MatrixFactory factory, int [] dim){ + public AbstractMatrixND(MatrixFactory factory, int[] dim) { this(factory); init(dim); - for(int i=0; i<getNbDim(); i++){ + for (int i = 0; i < getNbDim(); i++) { // par defaut les listes des semantiques contiennent des nulls semantics[i] = Collections.nCopies(dim[i], null); } } - public AbstractMatrixND(MatrixFactory factory, List[] semantics){ + + public AbstractMatrixND(MatrixFactory factory, List[] semantics) { this(factory); - int [] dim = new int[semantics.length]; - for(int i=0; i<dim.length; i++){ + int[] dim = new int[semantics.length]; + for (int i = 0; i < dim.length; i++) { if (semantics[i] == null) { dim[i] = 0; } else { @@ -97,225 +98,271 @@ } } init(dim); - for(int i=0; i<getNbDim(); i++){ + for (int i = 0; i < getNbDim(); i++) { setSemantics(i, semantics[i]); } } - public AbstractMatrixND(MatrixFactory factory, String name, int [] dim){ + public AbstractMatrixND(MatrixFactory factory, String name, int[] dim) { this(factory, dim); setName(name); } - public AbstractMatrixND(MatrixFactory factory, String name, int [] dim, String [] dimNames){ + + public AbstractMatrixND(MatrixFactory factory, String name, int[] dim, + String[] dimNames) { this(factory, dim); setName(name); - for(int i=0; dimNames != null && i<dimNames.length; i++){ + for (int i = 0; dimNames != null && i < dimNames.length; i++) { setDimensionName(i, dimNames[i]); } } - public AbstractMatrixND(MatrixFactory factory, String name, List[] semantics){ + + public AbstractMatrixND(MatrixFactory factory, String name, List[] semantics) { this(factory, semantics); setName(name); } - public AbstractMatrixND(MatrixFactory factory, String name, List[] semantics, String [] dimNames){ + public AbstractMatrixND(MatrixFactory factory, String name, + List[] semantics, String[] dimNames) { this(factory, name, semantics); - for(int i=0; dimNames != null && i<dimNames.length; i++){ + for (int i = 0; dimNames != null && i < dimNames.length; i++) { setDimensionName(i, dimNames[i]); } } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.codelutin.math.matrix.MatrixND#copy() */ public MatrixND copy() { MatrixND result = getFactory().create(this); return result; - } + } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see java.lang.Object#clone() */ @Override protected Object clone() throws CloneNotSupportedException { return copy(); } - + /** - * Retourne la factory utilisée pour créer cette matrice, la factory - * peut-être réutilisé pour créer d'autre matrice si besoin. - */ + * Retourne la factory utilisée pour créer cette matrice, la factory + * peut-être réutilisé pour créer d'autre matrice si besoin. + */ public MatrixFactory getFactory() { return factory; } - public List[] getSemantics(){ + public List[] getSemantics() { return semantics; } - public List getSemantics(int dim){ + + public List getSemantics(int dim) { return semantics[dim]; } - public void setSemantics(int dim, List sem){ + + public void setSemantics(int dim, List sem) { if (!(sem instanceof SemanticList)) { sem = new SemanticList(sem); - } + } // else SemanticList is immutable and can be used in many matrix in // same time this permit to used same indexOf optimization semantics[dim] = sem; } - public void setName(String name){ + + public void setName(String name) { this.name = name; } - public String getName(){ + + public String getName() { return name; } - public void setDimensionName(String[] names){ - for(int i=0; names != null && i<names.length; i++){ + + public void setDimensionName(String[] names) { + for (int i = 0; names != null && i < names.length; i++) { setDimensionName(i, names[i]); } } - public void setDimensionName(int dim, String name){ + + public void setDimensionName(int dim, String name) { dimNames[dim] = name; } - public String getDimensionName(int dim){ + + public String getDimensionName(int dim) { return dimNames[dim]; } - public String [] getDimensionName(){ + + public String[] getDimensionName() { return dimNames; } - public double getMaxOccurence(){ + + public double getMaxOccurence() { // on creer un tableau dans cette classe, car on ne sait pas sur quelle // implantation on s'appuie. Mais dans les sous classes, si on a deja // un tableau il ne faut pas le recréer, on peut le passer directement int nbelem = 1; - for(int i=0; i<getNbDim(); i++){ - nbelem *=getDim(i); + for (int i = 0; i < getNbDim(); i++) { + nbelem *= getDim(i); } - double [] data = new double[nbelem]; - int i =0; - for(MatrixIterator mi=iterator(); mi.next();){ + double[] data = new double[nbelem]; + int i = 0; + for (MatrixIterator mi = iterator(); mi.next();) { data[i++] = mi.getValue(); } return MatrixHelper.maxOccurence(data); } - public int getNbDim(){ + + public int getNbDim() { return dim.length; } - public int[] getDim(){ + + public int[] getDim() { return dim; } - public int getDim(int d){ + + public int getDim(int d) { return dim[d]; } + /** - * Retourne la matrice elle meme. Les modifications sont faites directement - * dessus - */ - public MatrixND map(MapFunction f){ - for(MatrixIterator i=iterator(); i.next();){ + * Retourne la matrice elle meme. Les modifications sont faites directement + * dessus + */ + public MatrixND map(MapFunction f) { + for (MatrixIterator i = iterator(); i.next();) { i.setValue(f.apply(i.getValue())); } return this; } - public double getValue(Object [] coordinates){ - return getValue(MatrixHelper.semanticsToDimension(getSemantics(), coordinates)); + + public double getValue(Object[] coordinates) { + return getValue(MatrixHelper.semanticsToDimension(getSemantics(), + coordinates)); } - public double getValue(Object x){ - // on peut utiliser dimHelper car le get ne le reutilisera pas en interne + + public double getValue(Object x) { + // on peut utiliser dimHelper car le get ne le reutilisera pas en + // interne return getValue(dimHelper.get(x)); } - public double getValue(Object x, Object y){ + + public double getValue(Object x, Object y) { return getValue(dimHelper.get(x, y)); } - public double getValue(Object x, Object y, Object z){ + + public double getValue(Object x, Object y, Object z) { return getValue(dimHelper.get(x, y, z)); } - public double getValue(Object x, Object y, Object z, Object t){ + + public double getValue(Object x, Object y, Object z, Object t) { return getValue(dimHelper.get(x, y, z, t)); }; - public double getValue(int x){ - // on peut utiliser dimHelper car le get ne le reutilisera pas en interne + + public double getValue(int x) { + // on peut utiliser dimHelper car le get ne le reutilisera pas en + // interne return getValue(dimHelper.get(x)); } - public double getValue(int x, int y){ + + public double getValue(int x, int y) { return getValue(dimHelper.get(x, y)); } - public double getValue(int x, int y, int z){ + + public double getValue(int x, int y, int z) { return getValue(dimHelper.get(x, y, z)); } - public double getValue(int x, int y, int z, int t){ + + public double getValue(int x, int y, int z, int t) { return getValue(dimHelper.get(x, y, z, t)); }; - public void setValue(Object [] coordinates, double d){ - setValue(MatrixHelper.semanticsToDimension(getSemantics(), coordinates), d); + + public void setValue(Object[] coordinates, double d) { + setValue( + MatrixHelper.semanticsToDimension(getSemantics(), coordinates), + d); } - public void setValue(Object x, double d){ + + public void setValue(Object x, double d) { setValue(dimHelper.get(x), d); } - public void setValue(Object x, Object y, double d){ + + public void setValue(Object x, Object y, double d) { setValue(dimHelper.get(x, y), d); } - public void setValue(Object x, Object y, Object z, double d){ + + public void setValue(Object x, Object y, Object z, double d) { setValue(dimHelper.get(x, y, z), d); } - public void setValue(Object x, Object y, Object z, Object t, double d){ + + public void setValue(Object x, Object y, Object z, Object t, double d) { setValue(dimHelper.get(x, y, z, t), d); } - public void setValue(int x, double d){ + + public void setValue(int x, double d) { setValue(dimHelper.get(x), d); } - public void setValue(int x, int y, double d){ + + public void setValue(int x, int y, double d) { setValue(dimHelper.get(x, y), d); } - public void setValue(int x, int y, int z, double d){ + + public void setValue(int x, int y, int z, double d) { setValue(dimHelper.get(x, y, z), d); } - public void setValue(int x, int y, int z, int t, double d){ + + public void setValue(int x, int y, int z, int t, double d) { setValue(dimHelper.get(x, y, z, t), d); } - - // TODO peut-etre faire une variante de equals qui regarde par rapport au coordonnées sémantique - public boolean equals(Object o){ - return o instanceof MatrixND && equals((MatrixND)o); + // TODO peut-etre faire une variante de equals qui regarde par rapport au + // coordonnées sémantique + public boolean equals(Object o) { + return o instanceof MatrixND && equals((MatrixND) o); } - public boolean equals(MatrixND mat){ + public boolean equals(MatrixND mat) { boolean result = true; // le nom doit être le même result = result && getName().equals(mat.getName()); result = result && equalsValues(mat); - + // les sémantiques doivent-être identique - for(int i=0; result && i<getNbDim(); i++){ + for (int i = 0; result && i < getNbDim(); i++) { String dimName1 = getDimensionName(i); String dimName2 = mat.getDimensionName(i); - result = ObjectUtils.equals(dimName1,dimName2); + result = ObjectUtils.equals(dimName1, dimName2); if (log.isDebugEnabled()) { - log.debug("dimName1("+dimName1+")==dimName2("+dimName2+ ")="+result); + log.debug("dimName1(" + dimName1 + ")==dimName2(" + dimName2 + + ")=" + result); } -// System.out.println("dimName1("+dimName1+")==dimName2("+dimName2+ ")="+result); - + // System.out.println("dimName1("+dimName1+")==dimName2("+dimName2+ + // ")="+result); + List sem1 = getSemantics(i); List sem2 = mat.getSemantics(i); result = result && ObjectUtils.equals(sem1, sem2); if (log.isDebugEnabled()) { - log.debug("sem1("+sem1+")==sem2("+sem2+ ")="+result); + log.debug("sem1(" + sem1 + ")==sem2(" + sem2 + ")=" + result); } -// System.out.println("sem1("+sem1+")==sem1("+sem2+ ")="+result); + // System.out.println("sem1("+sem1+")==sem1("+sem2+ ")="+result); } - + if (log.isDebugEnabled()) { - log.debug("result="+result); + log.debug("result=" + result); } -// System.out.println("result="+result); + // System.out.println("result="+result); return result; } - - /** - * Verifie si les matrices sont egales en ne regardant que les valeurs - * et pas les semantiques + + /** + * Verifie si les matrices sont egales en ne regardant que les valeurs et + * pas les semantiques * * @param mat * @return @@ -326,56 +373,56 @@ result = result && MatrixHelper.sameDimension(getDim(), mat.getDim()); // toutes les données doivent être identique - for(MatrixIterator i=mat.iterator(); result && i.next();){ + for (MatrixIterator i = mat.iterator(); result && i.next();) { double v1 = i.getValue(); double v2 = getValue(i.getCoordinates()); result = v1 == v2; if (log.isDebugEnabled()) { - log.debug("v1("+v1+")==v2("+v2+ ")="+result); + log.debug("v1(" + v1 + ")==v2(" + v2 + ")=" + result); } -// System.out.println("v1("+v1+")==v2("+v2+ ")="+result); + // System.out.println("v1("+v1+")==v2("+v2+ ")="+result); } - + return result; } - - public String toString(){ + + public String toString() { StringBuffer result = new StringBuffer(); result.append("dimensions = [\n"); - for(int i=0; i<getDim().length; i++){ + for (int i = 0; i < getDim().length; i++) { result.append(getDim()[i] + ","); } result.append("\n]\nmatrice = [\n"); - for(MatrixIterator i=this.iterator(); i.next();){ + for (MatrixIterator i = this.iterator(); i.next();) { result.append(i.getValue() + ","); } result.append("\n]\n"); return result.toString(); } - + public List toList() { List result = new ArrayList(); // [3,2,5,4] - for(MatrixIterator i=iterator(); i.next();){ - int [] coord = i.getCoordinates(); + for (MatrixIterator i = iterator(); i.next();) { + int[] coord = i.getCoordinates(); double value = i.getValue(); List tmp = result; - for(int dim=0; dim<coord.length - 1; dim++) { + for (int dim = 0; dim < coord.length - 1; dim++) { while (tmp.size() <= coord[dim]) { tmp.add(new ArrayList()); } - tmp = (List)tmp.get(coord[dim]); + tmp = (List) tmp.get(coord[dim]); } while (tmp.size() <= coord[coord.length - 1]) { tmp.add(NumberUtils.DOUBLE_ZERO); } - + tmp.set(coord[coord.length - 1], value); } return result; } - + public void fromList(List list) { // on suppose que les listes sont bien formé, c-a-d qu'elles sont // toutes de la meme dimension pour une dimension donnée. @@ -383,59 +430,61 @@ List tmp = list; while (tmp.get(tmp.size() - 1) instanceof List) { dim.add(tmp.size()); - tmp = (List)tmp.get(tmp.size() - 1); + tmp = (List) tmp.get(tmp.size() - 1); } dim.add(tmp.size()); MatrixND mat = getFactory().create(dim.toArray()); - - for(MatrixIterator i=mat.iterator(); i.next();){ - int [] coord = i.getCoordinates(); + + for (MatrixIterator i = mat.iterator(); i.next();) { + int[] coord = i.getCoordinates(); tmp = list; - for(int d=0; d<coord.length - 1; d++) { - tmp = (List)tmp.get(coord[d]); + for (int d = 0; d < coord.length - 1; d++) { + tmp = (List) tmp.get(coord[d]); } - - Double value = (Double)tmp.get(coord[coord.length - 1]); + + Double value = (Double) tmp.get(coord[coord.length - 1]); i.setValue(value); } paste(mat); - } + } - public boolean isValidCoordinates(int [] dim){ + public boolean isValidCoordinates(int[] dim) { boolean result = getNbDim() == dim.length; - for(int i=0; result && i<dim.length; i++){ + for (int i = 0; result && i < dim.length; i++) { result = 0 <= dim[i] && dim[i] < getDim(i); } return result; } - public boolean isValidCoordinates(Object [] semantics){ + public boolean isValidCoordinates(Object[] semantics) { boolean result = getNbDim() == semantics.length; - for(int i=0; result && i<semantics.length; i++){ + for (int i = 0; result && i < semantics.length; i++) { result = getSemantics(i).contains(semantics[i]); } return result; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.codelutin.math.matrix.MatrixND#sumAll() */ public double sumAll() { double result = 0; - for(MatrixIterator i=iterator(); i.next();){ + for (MatrixIterator i = iterator(); i.next();) { result += i.getValue(); } return result; } - - public MatrixND sumOverDim(int dim){ + + public MatrixND sumOverDim(int dim) { return sumOverDim(dim, getDim(dim)); } - public MatrixND sumOverDim(int dim, int step){ - if(step < 0){ + public MatrixND sumOverDim(int dim, int step) { + if (step < 0) { step = getDim(dim); - }else if(step <= 1){ + } else if (step <= 1) { // il n'y a rien a faire, on fait une copie et on la retrourne return getFactory().create(this); } @@ -443,45 +492,48 @@ // le nombre d'element qu'il y aura dans la dim pour le resultat int nbDim = getDim(dim) / step; - List [] semantics = new List[getNbDim()]; + List[] semantics = new List[getNbDim()]; System.arraycopy(getSemantics(), 0, semantics, 0, getNbDim()); semantics[dim] = semantics[dim].subList(0, nbDim); // creation du resultat - MatrixND result = getFactory().create(getName(), semantics, getDimensionName()); + MatrixND result = getFactory().create(getName(), semantics, + getDimensionName()); - for(int i=0; i<result.getDim(dim); i++){ - MatrixND temp = getSubMatrix(dim, i*step, step); + for (int i = 0; i < result.getDim(dim); i++) { + MatrixND temp = getSubMatrix(dim, i * step, step); MatrixND sum = result.getSubMatrix(dim, i, 1); - for(int s=0; s<temp.getDim(dim); s++){ + for (int s = 0; s < temp.getDim(dim); s++) { sum.add(temp.getSubMatrix(dim, s, 1)); } } return result; } - public MatrixND sumOverDim(int dim, int start, int nb ) { + public MatrixND sumOverDim(int dim, int start, int nb) { // copie de l'ancienne semantique - List [] semantics = new List[getNbDim()]; + List[] semantics = new List[getNbDim()]; System.arraycopy(getSemantics(), 0, semantics, 0, getNbDim()); semantics[dim] = new ArrayList<Object>(semantics[dim]); - + // creation d'un liste qui agrege les elements sommés List<Object> newElem = new ArrayList<Object>(); - for(int i=0; i<nb; i++) { + for (int i = 0; i < nb; i++) { newElem.add(semantics[dim].remove(start)); } // on ajout la liste comme nouvel element de la semantique semantics[dim].add(start, newElem); - + // creation du resultat - MatrixND result = getFactory().create(getName(), semantics, getDimensionName()); + MatrixND result = getFactory().create(getName(), semantics, + getDimensionName()); MatrixND sub1 = this.getSubMatrix(dim, 0, start); MatrixND sub2 = this.getSubMatrix(dim, start, nb).sumOverDim(dim); - MatrixND sub3 = this.getSubMatrix(dim, start+nb, getDim(dim)-(start+nb)); - - int [] origin = new int[getNbDim()]; + MatrixND sub3 = this.getSubMatrix(dim, start + nb, getDim(dim) + - (start + nb)); + + int[] origin = new int[getNbDim()]; result.paste(origin, sub1); origin[dim] = start; result.paste(origin, sub2); @@ -490,36 +542,37 @@ result.paste(origin, sub3); } - return result; + return result; } - - public MatrixND cut(int dim, int[] toCut){ + + public MatrixND cut(int dim, int[] toCut) { throw new UnsupportedOperationException("Méthode non implantée"); } /** - * Modifie la matrice actuel en metant les valeurs de mat passé en parametre - */ - public MatrixND paste(MatrixND mat){ + * Modifie la matrice actuel en metant les valeurs de mat passé en parametre + */ + public MatrixND paste(MatrixND mat) { return paste(new int[getNbDim()], mat); } /** - * Modifie la matrice actuel en metant les valeurs de mat passé en parametre - * @param origin le point d'origine a partir duquel on colle la matrice - * @param mat une matrice avec le meme nombre de dimension, si la matrice - * que l'on colle est trop grande, les valeurs qui depasse ne sont pas prises - * en compte - */ - public MatrixND paste(int [] origin, MatrixND mat){ + * Modifie la matrice actuel en metant les valeurs de mat passé en parametre + * + * @param origin le point d'origine a partir duquel on colle la matrice + * @param mat une matrice avec le meme nombre de dimension, si la matrice + * que l'on colle est trop grande, les valeurs qui depasse ne + * sont pas prises en compte + */ + public MatrixND paste(int[] origin, MatrixND mat) { // TODO, si les matrice mat et this on les memes dimensions // et que origin est 0 // on doit pouvoir optimiser en appeler une methode paste // sur BasicMatrix qui l'appel sur le vector if (mat != null) { - for(MatrixIterator mi=mat.iterator(); mi.next();){ - int [] coordinates = ArrayUtil.sum(origin, mi.getCoordinates()); - if(isValidCoordinates(coordinates)){ + for (MatrixIterator mi = mat.iterator(); mi.next();) { + int[] coordinates = ArrayUtil.sum(origin, mi.getCoordinates()); + if (isValidCoordinates(coordinates)) { setValue(coordinates, mi.getValue()); } } @@ -530,134 +583,146 @@ /** * Modifie la matrice actuel en metant les valeurs de mat passé en parametre * La copie se fait en fonction de la semantique, si un element dans une - * dimension n'est pas trouvé, alors il est passé + * dimension n'est pas trouvé, alors il est passé */ - public MatrixND pasteSemantics(MatrixND mat){ - if (mat != null) { - for(MatrixIterator mi=mat.iterator(); mi.next();){ - Object [] sems = mi.getSemanticsCoordinates(); - if(isValidCoordinates(sems)){ - setValue(sems, mi.getValue()); - } - } - } - return this; - } + public MatrixND pasteSemantics(MatrixND mat) { + if (mat != null) { + for (MatrixIterator mi = mat.iterator(); mi.next();) { + Object[] sems = mi.getSemanticsCoordinates(); + if (isValidCoordinates(sems)) { + setValue(sems, mi.getValue()); + } + } + } + return this; + } - public MatrixND getSubMatrix(int dim, int start, int nb){ - if(dim < 0){ + public MatrixND getSubMatrix(int dim, int start, int nb) { + if (dim < 0) { dim = getNbDim() + dim; } - if(start < 0){ + if (start < 0) { start = getDim(dim) + start; } - if(nb <= 0){ + if (nb <= 0) { nb = getDim(dim) - start; } return new SubMatrix(this, dim, start, nb); } - public MatrixND getSubMatrix(int dim, Object start, int nb){ + public MatrixND getSubMatrix(int dim, Object start, int nb) { int begin = MatrixHelper.indexOf(getSemantics(), dim, start); return getSubMatrix(dim, begin, nb); } /** - * Add to desambiguas some call with xpath engine, but do the same - * thing {@link #getSubMatrix(int, Object[])} + * Add to desambiguas some call with xpath engine, but do the same thing + * {@link #getSubMatrix(int, Object[])} + * * @param dim * @param elem * @return */ - public MatrixND getSubMatrixOnSemantic(int dim, Object ... elem){ + public MatrixND getSubMatrixOnSemantic(int dim, Object... elem) { MatrixND result = getSubMatrix(dim, elem); return result; } - public MatrixND getSubMatrix(int dim, Object ... elem){ - int [] ielem = new int[elem.length]; - for(int i=0; i<ielem.length; i++){ + + public MatrixND getSubMatrix(int dim, Object... elem) { + int[] ielem = new int[elem.length]; + for (int i = 0; i < ielem.length; i++) { ielem[i] = MatrixHelper.indexOf(getSemantics(), dim, elem[i]); } return getSubMatrix(dim, ielem); } - public MatrixND getSubMatrix(int dim, int [] elem){ + public MatrixND getSubMatrix(int dim, int[] elem) { return new SubMatrix(this, dim, elem); } /** - * Modifie la matrice actuelle en lui ajoutant les valeurs de la matrice - * passé en parametre. La matrice passé en parametre doit avoir le meme - * nombre de dimension, et chacune de ses dimensions doit avoir un nombre - * d'element au moins egal a cette matrice. - */ - public MatrixND add(MatrixND m){ + * Modifie la matrice actuelle en lui ajoutant les valeurs de la matrice + * passé en parametre. La matrice passé en parametre doit avoir le meme + * nombre de dimension, et chacune de ses dimensions doit avoir un nombre + * d'element au moins egal a cette matrice. + */ + public MatrixND add(MatrixND m) { // TODO si les dimensions sont exactment les memes, on doit pouvoir // gagner du temps en travaillant directement au niveau du vector - for(MatrixIterator i=iterator(); i.next();){ + for (MatrixIterator i = iterator(); i.next();) { i.setValue(i.getValue() + m.getValue(i.getCoordinates())); // TODO faire une variante de add avec les semantiques } return this; } + /** - * Modifie la matrice actuelle en lui soustrayant les valeurs de la matrice - * passé en parametre. La matrice passé en parametre doit avoir le meme - * nombre de dimension, et chacune de ses dimensions doit avoir un nombre - * d'element au moins egal a cette matrice. - */ - public MatrixND minus(MatrixND m){ + * Modifie la matrice actuelle en lui soustrayant les valeurs de la matrice + * passé en parametre. La matrice passé en parametre doit avoir le meme + * nombre de dimension, et chacune de ses dimensions doit avoir un nombre + * d'element au moins egal a cette matrice. + */ + public MatrixND minus(MatrixND m) { // TODO si les dimensions sont exactment les memes, on doit pouvoir // gagner du temps en travaillant directement au niveau du vector - for(MatrixIterator i=iterator(); i.next();){ + for (MatrixIterator i = iterator(); i.next();) { i.setValue(i.getValue() - m.getValue(i.getSemanticsCoordinates())); } return this; } - public MatrixND transpose(){ - if(getNbDim() > 2){ - throw new MatrixException("La transpose ne peut-être fait que sur une matrice ayant 2 dimensions ou moins"); + public MatrixND transpose() { + if (getNbDim() > 2) { + throw new MatrixException( + "La transpose ne peut-être fait que sur une matrice ayant 2 dimensions ou moins"); } - if(getNbDim() == 1){ - MatrixND result = getFactory().create(getName(), new List[]{Collections.nCopies(1, null), getSemantics(0)}, new String[]{"Dimension 0", getDimensionName(0)}); - for (int x=0; x<getDim(0); x++){ - result.setValue(0,x, getValue(x)); + if (getNbDim() == 1) { + MatrixND result = getFactory() + .create( + getName(), + new List[] { Collections.nCopies(1, null), + getSemantics(0) }, + new String[] { "Dimension 0", getDimensionName(0) }); + for (int x = 0; x < getDim(0); x++) { + result.setValue(0, x, getValue(x)); } return result; - }else{ - MatrixND result = getFactory().create(getName(), new List[]{getSemantics(1), getSemantics(0)}, new String[]{getDimensionName(1), getDimensionName(0)}); - for (int x=0; x<getDim(0); x++){ - for (int y=0; y<getDim(1); y++){ - result.setValue(y,x, getValue(x,y)); + } else { + MatrixND result = getFactory().create(getName(), + new List[] { getSemantics(1), getSemantics(0) }, + new String[] { getDimensionName(1), getDimensionName(0) }); + for (int x = 0; x < getDim(0); x++) { + for (int y = 0; y < getDim(1); y++) { + result.setValue(y, x, getValue(x, y)); } } return result; } } - public MatrixND reduce(){ + public MatrixND reduce() { return reduce(1); } - public MatrixND reduceDims(int ... dims) { + public MatrixND reduceDims(int... dims) { Arrays.sort(dims); // tableau permettant de faire la correspondance entre les dimensions // de la matrice actuelle et les dimentsions de la nouvelle matrice // l'element i du tableau qui correcpond à la dimensions i de la // nouvelle matrice contient la dimension equivalente dans // la matrice actuelle - int [] correspondance = new int[getNbDim()]; + int[] correspondance = new int[getNbDim()]; // les nouvelles semantiques List sem = new ArrayList(); // les nouveaux noms de dimensions List dimName = new ArrayList(); // il faut au moins une dimension pour la matrice int minNbDim = 1; - for (int j=getNbDim()-1; j>=0 ; j--){ + for (int j = getNbDim() - 1; j >= 0; j--) { // si la dimension à plus d'un élément ou qu'il n'est pas dans dims // on garde la dimension - if (getDim(j) > 1 || Arrays.binarySearch(dims, j) < 0 || j < minNbDim){ + if (getDim(j) > 1 || Arrays.binarySearch(dims, j) < 0 + || j < minNbDim) { // on ne conserve que les dimensions supérieure à 1 correspondance[sem.size()] = j; sem.add(getSemantics(j)); @@ -668,27 +733,28 @@ MatrixND result = reduce(dimName, sem, correspondance); return result; } - - public MatrixND reduce(int minNbDim){ + + public MatrixND reduce(int minNbDim) { // tableau permettant de faire la correspondance entre les dimensions // de la matrice actuelle et les dimentsions de la nouvelle matrice // l'element i du tableau qui correcpond à la dimensions i de la // nouvelle matrice contient la dimension equivalente dans // la matrice actuelle - int [] correspondance = new int[getNbDim()]; + int[] correspondance = new int[getNbDim()]; // les nouvelles semantiques List sem = new ArrayList(); // les nouveaux noms de dimensions List dimName = new ArrayList(); - for (int j=getNbDim()-1; j>=0 ; j--){ + for (int j = getNbDim() - 1; j >= 0; j--) { // si la dimension à plus d'un élément ou si on a pas assez de // dimension pour avoir le minimum demandé on prend la dimension - if (getDim(j) > 1 || j < minNbDim){ + if (getDim(j) > 1 || j < minNbDim) { // on ne conserve que les dimensions supérieure à 1 correspondance[sem.size()] = j; sem.add(getSemantics(j)); dimName.add(getDimensionName(j)); - // on vient de prendre une dimension il nous en faut une de moins + // on vient de prendre une dimension il nous en faut une de + // moins minNbDim--; } } @@ -698,76 +764,80 @@ } /** - * Create new matrice from the current matrix. + * Create new matrice from the current matrix. + * * @param dimName dimension name for new matrix * @param sem semantic for new matrix * @param correspondance array to do the link between current matrix and - * returned matrix + * returned matrix * @return new matrix */ - protected MatrixND reduce(List dimName, List sem, int [] correspondance) { + protected MatrixND reduce(List dimName, List sem, int[] correspondance) { // on converti les listes en tableau en inversant l'ordre car on // a fait un parcours en sens inverse int nbDim = sem.size(); - List [] newSemantics = new List[nbDim]; - String [] newDimNames = new String[nbDim]; - int [] tmpcorrespondance = new int[nbDim]; - for(int i=0; i<nbDim; i++){ - newSemantics[i] = (List)sem.get(nbDim-1-i); - newDimNames[i] = (String)dimName.get(nbDim-1-i); - tmpcorrespondance[i] = correspondance[nbDim-1-i]; + List[] newSemantics = new List[nbDim]; + String[] newDimNames = new String[nbDim]; + int[] tmpcorrespondance = new int[nbDim]; + for (int i = 0; i < nbDim; i++) { + newSemantics[i] = (List) sem.get(nbDim - 1 - i); + newDimNames[i] = (String) dimName.get(nbDim - 1 - i); + tmpcorrespondance[i] = correspondance[nbDim - 1 - i]; } correspondance = tmpcorrespondance; - MatrixND result = getFactory().create(getName(), newSemantics, newDimNames); + MatrixND result = getFactory().create(getName(), newSemantics, + newDimNames); // on reprend les valeurs - int [] newCoordinates = new int[result.getNbDim()]; - for(MatrixIterator mi=iterator(); mi.next();){ - int [] oldCoordinates = mi.getCoordinates(); - for(int i=0; i<newCoordinates.length; i++){ + int[] newCoordinates = new int[result.getNbDim()]; + for (MatrixIterator mi = iterator(); mi.next();) { + int[] oldCoordinates = mi.getCoordinates(); + for (int i = 0; i < newCoordinates.length; i++) { newCoordinates[i] = oldCoordinates[correspondance[i]]; } result.setValue(newCoordinates, mi.getValue()); } return result; } - - public MatrixND mult(MatrixND m)throws MatrixException{ - if(this.getNbDim()>2 || m.getNbDim()>2){ - throw new MatrixException("La multiplication de matrice n'est pas applicable aux matrices de plus de 2 dimensions"); + + public MatrixND mult(MatrixND m) throws MatrixException { + if (this.getNbDim() > 2 || m.getNbDim() > 2) { + throw new MatrixException( + "La multiplication de matrice n'est pas applicable aux matrices de plus de 2 dimensions"); } - if (!((this.getDim(1) == m.getDim(0)))){ - throw new MatrixException("Le nombre de colonnes de la matrice m1 doit etre egal au nombre de lignes de la matrice m2"); + if (!((this.getDim(1) == m.getDim(0)))) { + throw new MatrixException( + "Le nombre de colonnes de la matrice m1 doit etre egal au nombre de lignes de la matrice m2"); } - MatrixND result = getFactory().create(new int[]{this.getDim(0), - m.getDim(1)}); + MatrixND result = getFactory().create( + new int[] { this.getDim(0), m.getDim(1) }); double d; - for (int x=0; x<this.getDim(0); x++){ - for (int y=0; y<m.getDim(1); y++){ + for (int x = 0; x < this.getDim(0); x++) { + for (int y = 0; y < m.getDim(1); y++) { d = this.getValue(x, 0) * m.getValue(0, y); - for (int k=1; k<this.getDim(1); k++){ + for (int k = 1; k < this.getDim(1); k++) { d += this.getValue(x, k) * m.getValue(k, y); } - result.setValue(x,y, d); + result.setValue(x, y, d); } } return result; } - public MatrixND mults(final double d){ - map(new MapFunction(){ - public double apply(double val){ + public MatrixND mults(final double d) { + map(new MapFunction() { + public double apply(double val) { return val * d; } }); return this; } - public MatrixND divs(final double d){ - map(new MapFunction(){ - public double apply(double val){ + public MatrixND divs(final double d) { + map(new MapFunction() { + public double apply(double val) { return val / d; } }); @@ -778,44 +848,49 @@ * Separateur CSV par défaut la virgule */ public static char CSV_SEPARATOR = ';'; - + /** * Determine si la matrice supporte l'import et l'export CSV + * * @return support du CSV */ public boolean isSupportedCSV() { return getNbDim() <= 2; } - - Pattern NUMBER = Pattern.compile(" *[+-]?[0-9]*\\.?[0-9]+([eE][+-]?[0-9]+)? *"); - + + Pattern NUMBER = Pattern + .compile(" *[+-]?[0-9]*\\.?[0-9]+([eE][+-]?[0-9]+)? *"); + /** * Import depuis un reader au format CSV des données dans la matrice + * * @param reader le reader à importer - * @param origin le point à partir duquel il faut faire l'importation int[]{x,y} + * @param origin le point à partir duquel il faut faire l'importation + * int[]{x,y} */ public void importCSV(Reader reader, int[] origin) throws IOException { int rowsCount = 0; List<Double> row = new ArrayList<Double>(); StringBuffer number = new StringBuffer(20); boolean stop = false; - - for (int c=reader.read(); !stop; c=reader.read()){ + + for (int c = reader.read(); !stop; c = reader.read()) { if (c == -1) { stop = true; } if (c == ' ') { // skip space - } else if (c == CSV_SEPARATOR) { + } else if (c == CSV_SEPARATOR) { if (NUMBER.matcher(number.toString()).matches()) { Double val = Double.valueOf(number.toString()); row.add(val); } number.setLength(0); } else if (c == -1 || c == '\n' || c == '\r') { - // is line return or equivalent char because space is already skiped + // is line return or equivalent char because space is already + // skiped // or end of stream - + // at end of line, we must see if the leave number if (NUMBER.matcher(number.toString()).matches()) { Double val = Double.valueOf(number.toString()); @@ -823,93 +898,100 @@ } number.setLength(0); - if(!row.isEmpty()) { + if (!row.isEmpty()) { if (getDim().length == 1) { int columnNumber = origin[0]; for (Double value : row) { if (columnNumber < getDim(0)) { - setValue(new int[]{columnNumber}, value); + setValue(new int[] { columnNumber }, value); columnNumber++; } - } + } } else if (getDim().length == 2) { - MatrixND matrix = getFactory().create(new int[]{1, row.size()}); + MatrixND matrix = getFactory().create( + new int[] { 1, row.size() }); int columnNumber = 0; for (Double value : row) { - matrix.setValue(new int[]{0, columnNumber}, value); + matrix.setValue(new int[] { 0, columnNumber }, + value); columnNumber++; } - paste(new int[]{origin[0] + rowsCount, origin[1]}, matrix); - rowsCount ++; + paste(new int[] { origin[0] + rowsCount, origin[1] }, + matrix); + rowsCount++; row.clear(); } else { - throw new MatrixException("Can't import matrix with more than 2 dimensions."); + throw new MatrixException( + "Can't import matrix with more than 2 dimensions."); } - } + } } else { - number.append((char)c); + number.append((char) c); } } // cette implatation avec StreamTokenizer ne fonctionne pas // car il ne sait pas reconnaitre tous les nombres: 5.0E-7 -// int rowsCount = 0; -// StreamTokenizer tokenizer; -// List<Double> row = new ArrayList<Double>(); -// boolean stop = false; -// -// tokenizer = new StreamTokenizer(reader); -// tokenizer.eolIsSignificant(true); -// -// while(!stop) { -// tokenizer.nextToken(); -// -// switch (tokenizer.ttype) { -// case StreamTokenizer.TT_EOF: -// stop = true; // no break we do next case too -// case StreamTokenizer.TT_EOL: -// if(!row.isEmpty()) { -// MatrixND matrix = getFactory().create(new int[]{1, row.size()}); -// int columnNumber = 0; -// for (Double value : row) { -// matrix.setValue(new int[]{0, columnNumber}, value); -// columnNumber++; -// } -// paste(new int[]{origin[0] + rowsCount, origin[1]}, matrix); -// rowsCount ++; -// row.clear(); -// } -// break; -// case StreamTokenizer.TT_NUMBER: -// System.out.println("+++++++++ " + tokenizer.nval); -// row.add(tokenizer.nval); -// break; -// case StreamTokenizer.TT_WORD: -// System.out.println("--------- " + tokenizer.nval); -// break; -// default: -// break; -// } -// } + // int rowsCount = 0; + // StreamTokenizer tokenizer; + // List<Double> row = new ArrayList<Double>(); + // boolean stop = false; + // + // tokenizer = new StreamTokenizer(reader); + // tokenizer.eolIsSignificant(true); + // + // while(!stop) { + // tokenizer.nextToken(); + // + // switch (tokenizer.ttype) { + // case StreamTokenizer.TT_EOF: + // stop = true; // no break we do next case too + // case StreamTokenizer.TT_EOL: + // if(!row.isEmpty()) { + // MatrixND matrix = getFactory().create(new int[]{1, row.size()}); + // int columnNumber = 0; + // for (Double value : row) { + // matrix.setValue(new int[]{0, columnNumber}, value); + // columnNumber++; + // } + // paste(new int[]{origin[0] + rowsCount, origin[1]}, matrix); + // rowsCount ++; + // row.clear(); + // } + // break; + // case StreamTokenizer.TT_NUMBER: + // System.out.println("+++++++++ " + tokenizer.nval); + // row.add(tokenizer.nval); + // break; + // case StreamTokenizer.TT_WORD: + // System.out.println("--------- " + tokenizer.nval); + // break; + // default: + // break; + // } + // } } - + /** * Export dans un writer au format CSV de la matrice + * * @param writer le writer ou copier la matrice - * @param withSemantics export ou pas des semantiques de la matrice dans le writer + * @param withSemantics export ou pas des semantiques de la matrice dans le + * writer */ - public void exportCSV(Writer writer, boolean withSemantics) throws IOException { + public void exportCSV(Writer writer, boolean withSemantics) + throws IOException { int dimsCount = getNbDim(); int rowsCount = dimsCount == 1 ? 1 : getDim(0); int columnsCount = dimsCount == 1 ? getDim(0) : getDim(1); int[] coordinates; - - if(!isSupportedCSV()) { + + if (!isSupportedCSV()) { throw new UnsupportedOperationException(); } /* Création de l'entete */ - if(withSemantics) { + if (withSemantics) { /* Recuperation de la liste sur la bonne dimenssion */ List listSemantics = getSemantics(dimsCount - 1); /* Ajout d'un décalage de l'entete pour la dimenssion 2 */ @@ -919,18 +1001,18 @@ } writer.append("\n"); } - + for (int rowNb = 0; rowNb < rowsCount; rowNb++) { /* Ajout de la semantic devant la ligne pour la dimenssion 2 */ - if(withSemantics && dimsCount == 2) { + if (withSemantics && dimsCount == 2) { Object semantic = getSemantics(0).get(rowNb); writer.append("\"" + semantic + "\"" + CSV_SEPARATOR); } - + for (int columnNb = 0; columnNb < columnsCount; columnNb++) { /* Calcul des coordonnees */ - coordinates = dimsCount == 1 ? - new int[]{columnNb} : new int[]{rowNb, columnNb}; + coordinates = dimsCount == 1 ? new int[] { columnNb } + : new int[] { rowNb, columnNb }; writer.append(getValue(coordinates) + "" + CSV_SEPARATOR); } writer.append("\n"); Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/BasicMatrix.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/BasicMatrix.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/BasicMatrix.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,21 +1,19 @@ -/* *##% - * Copyright (C) 2002, 2003, 2004 Code Lutin, Cédric Pineau, - Benjamin Poussin +/* *##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin * - * 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 2 - * of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Lesser Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * * BasicMatrix.java @@ -33,28 +31,31 @@ import java.util.Arrays; import java.util.NoSuchElementException; + import org.codelutin.i18n.I18n; /** -* Objet matrice qui ne permet que le stockage de double dans un matrice à -* autant de dimension que l'on souhaite. -*/ + * Objet matrice qui ne permet que le stockage de double dans un matrice à + * autant de dimension que l'on souhaite. + */ public class BasicMatrix { // BasicMatrix /** La factory */ protected MatrixFactory factory = null; /** Les dimensions de la matrice */ - protected int [] dimensions = null; + protected int[] dimensions = null; /** La matrice en représentation linéaire */ protected Vector data = null; - /** tableau de facteur permettant de convertir les coordonnées dans la - * matrice en un indice dans la représentation linéaire de la matrice */ - protected int [] linearFactor = null; + /** + * tableau de facteur permettant de convertir les coordonnées dans la + * matrice en un indice dans la représentation linéaire de la matrice + */ + protected int[] linearFactor = null; /** - * Crée une nouvelle matrice ayant les dimensions demandées - */ - public BasicMatrix(MatrixFactory factory, int [] dimensions){ + * Crée une nouvelle matrice ayant les dimensions demandées + */ + public BasicMatrix(MatrixFactory factory, int[] dimensions) { this.factory = factory; checkDim(dimensions); @@ -65,9 +66,9 @@ // calcul du linearFactor linearFactor = new int[dimensions.length]; - linearFactor[linearFactor.length-1] = 1; - for(int i=linearFactor.length - 2; i>=0; i--){ - linearFactor[i] = linearFactor[i+1] * dimensions[i+1]; + linearFactor[linearFactor.length - 1] = 1; + for (int i = linearFactor.length - 2; i >= 0; i--) { + linearFactor[i] = linearFactor[i + 1] * dimensions[i + 1]; } // creation de la matrice lineaire @@ -75,113 +76,123 @@ } /** - * Retourne la valeur la plus courrement rencontrer dans la matrice. - * si plusieurs valeurs ont le même nombre d'occurence la plus petite - * valeur est retourné. - * @return la valeur la plus nombreuse dans la matrice, ou la plus petite - * si plusieurs valeur se retourve le même nombre de fois - */ - public double getMaxOccurence(){ + * Retourne la valeur la plus courrement rencontrer dans la matrice. si + * plusieurs valeurs ont le même nombre d'occurence la plus petite valeur + * est retourné. + * + * @return la valeur la plus nombreuse dans la matrice, ou la plus petite si + * plusieurs valeur se retourve le même nombre de fois + */ + public double getMaxOccurence() { return data.getMaxOccurence(); } /** - * Retourne le nombre de dimension de la matrice - * @return le nombre de dimension de la matrice; - */ - public int getNbDim(){ + * Retourne le nombre de dimension de la matrice + * + * @return le nombre de dimension de la matrice; + */ + public int getNbDim() { return dimensions.length; } /** - * Retourne la taille d'une dimension - * @param dim la dimension dont on souhaite la taille - * @return la taille d'une dimension - * @throws - */ - public int getDim(int dim){ + * Retourne la taille d'une dimension + * + * @param dim la dimension dont on souhaite la taille + * @return la taille d'une dimension + * @throws + */ + public int getDim(int dim) { checkDim(dim); return dimensions[dim]; } /** - * Retourne un tableau representant les dimensions de la matrice. - * Le tableau retourné n'est pas une copie, il ne faut donc pas le modifier - * @return le tableau des dimensions. - */ - public int [] getDim(){ + * Retourne un tableau representant les dimensions de la matrice. Le tableau + * retourné n'est pas une copie, il ne faut donc pas le modifier + * + * @return le tableau des dimensions. + */ + public int[] getDim() { return dimensions; } /** - * Retourne un element de la matrice - * @param pos la position de l'element à retourner - */ - public double getValue(int [] pos){ + * Retourne un element de la matrice + * + * @param pos la position de l'element à retourner + */ + public double getValue(int[] pos) { int indice = coordonatesToLinear(pos); return data.getValue(indice); } /** - * Modifie un élement de la matrice - * @param pos la position de l'element à modifier - * @param value la nouvelle valeur à mettre dans la matrice - */ - public void setValue(int [] pos, double value){ + * Modifie un élement de la matrice + * + * @param pos la position de l'element à modifier + * @param value la nouvelle valeur à mettre dans la matrice + */ + public void setValue(int[] pos, double value) { int indice = coordonatesToLinear(pos); data.setValue(indice, value); } /** - * Retourne un objet Inc pret a etre utilisé pour boucler sur tous les - * element de la matrice. - * @return un objet Inc pret à être utilisé - */ - public BasicMatrixIterator iterator(){ + * Retourne un objet Inc pret a etre utilisé pour boucler sur tous les + * element de la matrice. + * + * @return un objet Inc pret à être utilisé + */ + public BasicMatrixIterator iterator() { return new BasicMatrixIteratorImpl(this); } /** - * Permet de faire un traitement sur chaque valeur de la matrice - * @param f la fonction a appliquer à chaque élement de la matrice - */ - public void map(MapFunction f){ + * Permet de faire un traitement sur chaque valeur de la matrice + * + * @param f la fonction a appliquer à chaque élement de la matrice + */ + public void map(MapFunction f) { if (data.isImplementedMap()) { data.map(f); } else { - for(int i=0; i<data.size(); i++){ + for (int i = 0; i < data.size(); i++) { double result = f.apply(data.getValue(i)); - data.setValue(i,result); + data.setValue(i, result); } } } /** - * Permet de convertir les coordonnées d'un élément en un indice dans la - * représentation linéraire de la matrice. - * @param coordonates les coordonnées à lineariser - * @return un indice réprésentant les coordonnées de façon linéaire - */ - protected int coordonatesToLinear(int [] coordonates){ + * Permet de convertir les coordonnées d'un élément en un indice dans la + * représentation linéraire de la matrice. + * + * @param coordonates les coordonnées à lineariser + * @return un indice réprésentant les coordonnées de façon linéaire + */ + protected int coordonatesToLinear(int[] coordonates) { checkPos(coordonates); - int result=0; - for(int i=0; i<linearFactor.length; i++){ + int result = 0; + for (int i = 0; i < linearFactor.length; i++) { result += coordonates[i] * linearFactor[i]; } return result; } /** - * Convertie une coordonnée lineaire en coordonnées spaciales - * @param pos la coordonnée linéaire - * @param linearFactor le tableau permettant la conversion - * @return les coordonnées spaciales de l'élément - */ - protected int [] linearToCoordinates(int pos){ - int [] result = new int[linearFactor.length]; + * Convertie une coordonnée lineaire en coordonnées spaciales + * + * @param pos la coordonnée linéaire + * @param linearFactor le tableau permettant la conversion + * @return les coordonnées spaciales de l'élément + */ + protected int[] linearToCoordinates(int pos) { + int[] result = new int[linearFactor.length]; - for(int i=0; i<result.length; i++){ + for (int i = 0; i < result.length; i++) { result[i] = pos / linearFactor[i]; pos -= result[i] * linearFactor[i]; } @@ -189,76 +200,84 @@ } /** - * Permet de vérifier que les dimensions de la nouvelle matrice sont - * corrects - * @param dim les dimensions de la nouvelle matrice - * @throws IllegalArgumentException si une dimension n'est pas valide - */ - protected void checkDim(int [] dim){ - for(int i=0; i<dim.length; i++){ - if(dim[i] <= 0){ - throw new IllegalArgumentException(I18n._("lutinmatrix.invalid.size", new Integer(i), new Integer(dim[i]))); + * Permet de vérifier que les dimensions de la nouvelle matrice sont + * corrects + * + * @param dim les dimensions de la nouvelle matrice + * @throws IllegalArgumentException si une dimension n'est pas valide + */ + protected void checkDim(int[] dim) { + for (int i = 0; i < dim.length; i++) { + if (dim[i] <= 0) { + throw new IllegalArgumentException(I18n._( + "lutinmatrix.invalid.size", new Integer(i), + new Integer(dim[i]))); } } } /** - * Permet de vérifier qu'une dimension demandé existe bien dans la matrice - * @param dim la position de la dimension que l'on souhaite - * @throws IndexOutOfBoundsException si la dimension demandée n'existe pas - */ - protected void checkDim(int dim){ - if(dim < 0 || dim >= getNbDim()){ - throw new IndexOutOfBoundsException(I18n._("lutinmatrix.invalid.size", dim, getNbDim())); + * Permet de vérifier qu'une dimension demandé existe bien dans la matrice + * + * @param dim la position de la dimension que l'on souhaite + * @throws IndexOutOfBoundsException si la dimension demandée n'existe pas + */ + protected void checkDim(int dim) { + if (dim < 0 || dim >= getNbDim()) { + throw new IndexOutOfBoundsException(I18n._( + "lutinmatrix.invalid.size", dim, getNbDim())); } } /** - * Verifie que les coordonnées demandé appartiennent bien à la matrice - * @param pos les coordonnées souhaitées dans la matrice - * @throws NoSuchElementException si les coordonnées ne correspondent pas - * à un élement de la matrice - */ - protected void checkPos(int [] pos){ - int [] dim = getDim(); + * Verifie que les coordonnées demandé appartiennent bien à la matrice + * + * @param pos les coordonnées souhaitées dans la matrice + * @throws NoSuchElementException si les coordonnées ne correspondent pas à + * un élement de la matrice + */ + protected void checkPos(int[] pos) { + int[] dim = getDim(); boolean result = dim.length == pos.length; - for(int i=0; result && i<dim.length; i++){ + for (int i = 0; result && i < dim.length; i++) { result = (0 <= pos[i]) && (pos[i] < dim[i]); } - if(! result){ - throw new NoSuchElementException(I18n._("lutinmatrix.invalid.element", Arrays.toString(pos), Arrays.toString(dim))); + if (!result) { + throw new NoSuchElementException(I18n._( + "lutinmatrix.invalid.element", Arrays.toString(pos), Arrays + .toString(dim))); } } - public String toString(){ + public String toString() { StringBuffer result = new StringBuffer(); - if(getNbDim() == 1){ + if (getNbDim() == 1) { result.append("matrix1D ["); - for(int i=0; i<data.size(); i++){ + for (int i = 0; i < data.size(); i++) { result.append(data.getValue(i) + ","); } result.append("]"); - }else if(getNbDim() == 2){ + } else if (getNbDim() == 2) { DimensionHelper dimHelper = new DimensionHelper(); result.append("matrix2D ["); - for(int y=0; y<getDim(1); y++){ + for (int y = 0; y < getDim(1); y++) { result.append("\n"); - for(int x=0; x<getDim(0); x++){ - result.append(getValue(dimHelper.get(x,y)) + ","); + for (int x = 0; x < getDim(0); x++) { + result.append(getValue(dimHelper.get(x, y)) + ","); } } result.append("]"); - }else{ + } else { result.append("dimensions = [\n"); - for(int i=0; i<dimensions.length; i++){ + for (int i = 0; i < dimensions.length; i++) { result.append(dimensions[i] + ","); } result.append("\n]\nmatrice = [\n"); - for(int i=0; i<data.size(); i++){ + for (int i = 0; i < data.size(); i++) { result.append(data.getValue(i) + ","); } result.append("\n]\nlinearFactor = [\n"); - for(int i=0; i<linearFactor.length; i++){ + for (int i = 0; i < linearFactor.length; i++) { result.append(linearFactor[i] + ","); } result.append("\n]\n"); @@ -266,54 +285,51 @@ return result.toString(); } - public boolean equals(Object o){ - if(o instanceof BasicMatrix){ - BasicMatrix other = (BasicMatrix)o; - return this == o || - (Arrays.equals(this.dimensions, other.dimensions) && - this.data.equals(other.data)); + public boolean equals(Object o) { + if (o instanceof BasicMatrix) { + BasicMatrix other = (BasicMatrix) o; + return this == o + || (Arrays.equals(this.dimensions, other.dimensions) && this.data + .equals(other.data)); } return false; } - - - protected class BasicMatrixIteratorImpl implements BasicMatrixIterator { // MatrixIteratorImpl protected BasicMatrix matrix = null; protected int pos = -1; /** - * @param matrix la matrice sur lequel l'iterator doit travailler - */ - public BasicMatrixIteratorImpl(BasicMatrix matrix){ + * @param matrix la matrice sur lequel l'iterator doit travailler + */ + public BasicMatrixIteratorImpl(BasicMatrix matrix) { this.matrix = matrix; pos = -1; } - public boolean hasNext(){ + public boolean hasNext() { return pos + 1 < matrix.data.size(); } - public boolean next(){ - if(hasNext()){ + public boolean next() { + if (hasNext()) { pos++; return true; - }else{ + } else { return false; } } - public double getValue(){ + public double getValue() { return matrix.data.getValue(pos); } - public void setValue(double value){ + public void setValue(double value) { matrix.data.setValue(pos, value); } - public int [] getCoordinates(){ + public int[] getCoordinates() { return matrix.linearToCoordinates(pos); } Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/BasicMatrixIterator.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/BasicMatrixIterator.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/BasicMatrixIterator.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,21 +1,19 @@ -/* *##% - * Copyright (C) 2002, 2003, 2004 Code Lutin, Cédric Pineau, - * Benjamin Poussin +/* *##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin * - * 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 2 - * of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Lesser Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * * BasicMatrixIterator.java @@ -34,29 +32,30 @@ public interface BasicMatrixIterator { // BasicMatrixIterator /** - * Retourne vrai s'il existe un suivant - * @return vrai s'il y a un suivant, faux sinon - */ + * Retourne vrai s'il existe un suivant + * + * @return vrai s'il y a un suivant, faux sinon + */ public boolean hasNext(); /** - * Passe à l'élément suivant - */ + * Passe à l'élément suivant + */ public boolean next(); /** - * Retourne les coordonnés de l'élément - */ - public int [] getCoordinates(); + * Retourne les coordonnés de l'élément + */ + public int[] getCoordinates(); /** - * Retourne la valeur courant pointé par l'iterator - */ + * Retourne la valeur courant pointé par l'iterator + */ public double getValue(); /** - * Modifie la valeur courant pointé par l'iterator - */ + * Modifie la valeur courant pointé par l'iterator + */ public void setValue(double value); } // BasicMatrixIterator Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DimensionHelper.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DimensionHelper.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DimensionHelper.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,21 +1,19 @@ -/* *##% - * Copyright (C) 2002, 2003, 2004 Code Lutin, Cédric Pineau, - * Benjamin Poussin +/* *##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin * - * 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 2 - * of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Lesser Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * * DimensionHelper.java @@ -32,46 +30,47 @@ package org.codelutin.math.matrix; /** -* Classe permettant de diminuer au maximum l'allocation de tableau de int -* pour les dimensions. Cette classe n'est pas multithread, il faut créer une -* instance par thread. Il faut bien réfléchir lorsque l'on souhaite utiliser -* cette classe, par exemple il ne faut pas l'utiliser dans une méthode qui -* appelle une autre methode réutilisant le meme objet, car il sera alors -* modifier alors qu'il ne le faut pas pour la premiere methode appelée. -*/ + * Classe permettant de diminuer au maximum l'allocation de tableau de int pour + * les dimensions. Cette classe n'est pas multithread, il faut créer une + * instance par thread. Il faut bien réfléchir lorsque l'on souhaite utiliser + * cette classe, par exemple il ne faut pas l'utiliser dans une méthode qui + * appelle une autre methode réutilisant le meme objet, car il sera alors + * modifier alors qu'il ne le faut pas pour la premiere methode appelée. + */ public class DimensionHelper { // DimensionHelper - protected int [] d1 = new int[1]; - protected int [] d2 = new int[2]; - protected int [] d3 = new int[3]; - protected int [] d4 = new int[4]; + protected int[] d1 = new int[1]; + protected int[] d2 = new int[2]; + protected int[] d3 = new int[3]; + protected int[] d4 = new int[4]; - protected Object [] o1 = new Object[1]; - protected Object [] o2 = new Object[2]; - protected Object [] o3 = new Object[3]; - protected Object [] o4 = new Object[4]; + protected Object[] o1 = new Object[1]; + protected Object[] o2 = new Object[2]; + protected Object[] o3 = new Object[3]; + protected Object[] o4 = new Object[4]; - public DimensionHelper(){} + public DimensionHelper() { + } - public int [] get(int x){ + public int[] get(int x) { d1[0] = x; return d1; } - public int [] get(int x, int y){ + public int[] get(int x, int y) { d2[0] = x; d2[1] = y; return d2; } - public int [] get(int x, int y, int z){ + public int[] get(int x, int y, int z) { d3[0] = x; d3[1] = y; d3[2] = z; return d3; } - public int [] get(int x, int y, int z, int t){ + public int[] get(int x, int y, int z, int t) { d4[0] = x; d4[1] = y; d4[2] = z; @@ -79,25 +78,25 @@ return d4; } - public Object [] get(Object x){ + public Object[] get(Object x) { o1[0] = x; return o1; } - public Object [] get(Object x, Object y){ + public Object[] get(Object x, Object y) { o2[0] = x; o2[1] = y; return o2; } - public Object [] get(Object x, Object y, Object z){ + public Object[] get(Object x, Object y, Object z) { o3[0] = x; o3[1] = y; o3[2] = z; return o3; } - public Object [] get(Object x, Object y, Object z, Object t){ + public Object[] get(Object x, Object y, Object z, Object t) { o4[0] = x; o4[1] = y; o4[2] = z; Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DoubleBigVector.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DoubleBigVector.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DoubleBigVector.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,21 +1,19 @@ -/* *##% - * Copyright (C) 2005 - * Code Lutin, Cédric Pineau, Benjamin Poussin +/* *##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin * - * 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 2 - * of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Lesser Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * * DoubleBigVector.java @@ -37,7 +35,7 @@ protected double data[] = null; - public DoubleBigVector(int capacity){ + public DoubleBigVector(int capacity) { data = new double[capacity]; } @@ -60,12 +58,12 @@ public boolean equals(Object o) { boolean result = false; if (o instanceof DoubleBigVector) { - DoubleBigVector other = (DoubleBigVector)o; + DoubleBigVector other = (DoubleBigVector) o; result = Arrays.equals(this.data, other.data); } else if (o instanceof Vector) { - Vector other = (Vector)o; + Vector other = (Vector) o; result = true; - for(int i=0; i<size() && result; i++){ + for (int i = 0; i < size() && result; i++) { result = getValue(i) == other.getValue(i); } } @@ -75,36 +73,40 @@ public boolean isImplementedPaste(Vector v) { return v instanceof DoubleBigVector; } + public boolean isImplementedAdd(Vector v) { return v instanceof DoubleBigVector; } + public boolean isImplementedMinus(Vector v) { return v instanceof DoubleBigVector; } + public boolean isImplementedMap() { return true; } public void paste(Vector v) { - DoubleBigVector fbv = (DoubleBigVector)v; + DoubleBigVector fbv = (DoubleBigVector) v; System.arraycopy(fbv.data, 0, this.data, 0, this.size()); } + public void add(Vector v) { - DoubleBigVector fbv = (DoubleBigVector)v; - for(int i=0; i<data.length; i++) { + DoubleBigVector fbv = (DoubleBigVector) v; + for (int i = 0; i < data.length; i++) { data[i] += fbv.data[i]; } } public void minus(Vector v) { - DoubleBigVector fbv = (DoubleBigVector)v; - for(int i=0; i<data.length; i++) { + DoubleBigVector fbv = (DoubleBigVector) v; + for (int i = 0; i < data.length; i++) { data[i] -= fbv.data[i]; } } public void map(MapFunction f) { - for(int i=0; i<data.length; i++) { + for (int i = 0; i < data.length; i++) { data[i] = f.apply(data[i]); } } Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DoubleVector.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DoubleVector.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DoubleVector.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,21 +1,19 @@ -/* *##% - * Copyright (C) 2005 - * Code Lutin, Cédric Pineau, Benjamin Poussin +/* *##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin * - * 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 2 - * of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Lesser Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * * FloatVector.java @@ -34,15 +32,13 @@ import java.util.Arrays; import org.apache.commons.collections.primitives.ArrayDoubleList; -import org.apache.commons.collections.primitives.ArrayFloatList; /** -* Permet de stocker des données à une position lineair et de la redemander -* Cette classe ne gére que les données lineaire. -* L'avantage de cette classe est de ne conserver que les elements differents -* de la valeur par defaut, ce qui minimize la taille du tableau necessaire -* a conserver les données. -*/ + * Permet de stocker des données à une position lineair et de la redemander + * Cette classe ne gére que les données lineaire. L'avantage de cette classe est + * de ne conserver que les elements differents de la valeur par defaut, ce qui + * minimize la taille du tableau necessaire a conserver les données. + */ public class DoubleVector implements Vector { // FloatVector /** maximum number of element, maximum pos value */ @@ -52,7 +48,7 @@ protected double defaultValue = 0; /** contient la position de l'element, le tableau est trie */ - protected int [] position; + protected int[] position; protected int positionSize = 0; /** contient la valeur de l'element */ @@ -64,7 +60,7 @@ Arrays.fill(position, Integer.MAX_VALUE); } - public DoubleVector(int capacity, double defaultValue){ + public DoubleVector(int capacity, double defaultValue) { this(capacity); this.defaultValue = defaultValue; } @@ -73,18 +69,20 @@ return capacity; } - // poussin 20060827 TODO: verifier l'implantation, il semble quelle soit fausse et ne puisse pas recherche le nombre max correctement + // poussin 20060827 TODO: verifier l'implantation, il semble quelle soit + // fausse et ne puisse pas recherche le nombre max correctement public double getMaxOccurence() { double result = defaultValue; - double [] tmp = data.toArray(); + double[] tmp = data.toArray(); // si potentiellement il y a plus d'element identique dans data // que de valeur par defaut, on recherche la valeur possible - if (this.capacity < 2*tmp.length) { + if (this.capacity < 2 * tmp.length) { Arrays.sort(tmp); - // le nombre de fois que l'on a rencontrer la valeur la plus nombreuse + // le nombre de fois que l'on a rencontrer la valeur la plus + // nombreuse int max = 1; // le nombre de fois que l'on a rencontrer la valeur courante int count = 1; @@ -96,13 +94,13 @@ double current = tmp[0]; // tant que l'on peut encore trouve un element plus nombreux dans le // tableau on le parcours - for(int i=1; max<tmp.length-i+count && i<tmp.length; i++){ + for (int i = 1; max < tmp.length - i + count && i < tmp.length; i++) { current = tmp[i]; - if(current == old){ + if (current == old) { count++; - }else{ - if(count > max){ + } else { + if (count > max) { max = count; result = old; } @@ -110,12 +108,12 @@ old = current; } } - if(count > max){ + if (count > max) { max = count; result = current; } - if(max <= capacity - tmp.length) { + if (max <= capacity - tmp.length) { // en fin de compte, il n'y a pas plus d'element identique // dans data que de defaultValue result = defaultValue; @@ -125,9 +123,10 @@ return result; } - protected void checkPos(int pos){ - if(pos < 0 || pos >= capacity) { - throw new IllegalArgumentException("pos " + pos + " is not in [0, "+capacity+"]"); + protected void checkPos(int pos) { + if (pos < 0 || pos >= capacity) { + throw new IllegalArgumentException("pos " + pos + " is not in [0, " + + capacity + "]"); } } @@ -143,8 +142,8 @@ } /** - * On ajoute dans l'o - */ + * On ajoute dans l'o + */ public void setValue(int pos, double value) { checkPos(pos); @@ -162,7 +161,7 @@ // il n'etait pas present if (value != defaultValue) { // il faut ajouter dans position et dans data - index = -index -1; + index = -index - 1; addElementAt(index, pos); data.add(index, value); @@ -173,35 +172,36 @@ public boolean equals(Object o) { boolean result = false; if (o instanceof DoubleVector) { - DoubleVector other = (DoubleVector)o; - result = Arrays.equals(this.position, other.position) && data.equals(other.data); + DoubleVector other = (DoubleVector) o; + result = Arrays.equals(this.position, other.position) + && data.equals(other.data); } else if (o instanceof Vector) { - Vector other = (Vector)o; + Vector other = (Vector) o; result = true; - for(int i=0; i<size() && result; i++){ + for (int i = 0; i < size() && result; i++) { result = getValue(i) == other.getValue(i); } } return result; } - /** - * retourne la position dans le tableau position de la position lineaire - * @return la position ou < 0 donnant la position de l'element s'il etait - * present - */ + * retourne la position dans le tableau position de la position lineaire + * + * @return la position ou < 0 donnant la position de l'element s'il etait + * present + */ protected int findIndex(int pos) { return Arrays.binarySearch(position, pos); } protected void ensureCapacity(int mincap) { - if(mincap > position.length) { + if (mincap > position.length) { int newcap = (position.length * 3) / 2 + 1; int olddata[] = position; position = new int[newcap >= mincap ? newcap : mincap]; System.arraycopy(olddata, 0, position, 0, positionSize); - for(int i=positionSize; i<position.length; i++){ + for (int i = positionSize; i < position.length; i++) { position[i] = Integer.MAX_VALUE; } } @@ -218,7 +218,7 @@ protected int removeElementAt(int index) { int oldval = position[index]; int numtomove = positionSize - index - 1; - if(numtomove > 0) { + if (numtomove > 0) { System.arraycopy(position, index + 1, position, index, numtomove); } positionSize--; @@ -226,65 +226,70 @@ return oldval; } - public boolean isImplementedPaste(Vector v) { return v instanceof DoubleVector; } + public boolean isImplementedAdd(Vector v) { // FIXME une fois la methode implanter supprimer le false return false && v instanceof DoubleVector; } + public boolean isImplementedMinus(Vector v) { // FIXME une fois la methode implanter supprimer le false return false && v instanceof DoubleVector; } + public boolean isImplementedMap() { return true; } /** - * On recopie tous les attributs pour que le vector ressemble exactement - * a celui passé en argument - */ + * On recopie tous les attributs pour que le vector ressemble exactement a + * celui passé en argument + */ public void paste(Vector v) { - DoubleVector fbv = (DoubleVector)v; + DoubleVector fbv = (DoubleVector) v; this.capacity = fbv.capacity; this.defaultValue = fbv.defaultValue; this.positionSize = fbv.positionSize; this.position = new int[fbv.position.length]; - System.arraycopy(fbv.position, 0, this.position, 0, this.position.length); + System.arraycopy(fbv.position, 0, this.position, 0, + this.position.length); this.data.clear(); this.data.addAll(fbv.data); } - // poussin 20060827 FIXME a refaire car v.data et date n'ont pas forcement leur element qui se correspondent, cette implatation est donc fausse + // poussin 20060827 FIXME a refaire car v.data et date n'ont pas forcement + // leur element qui se correspondent, cette implatation est donc fausse public void add(Vector v) { - DoubleVector fbv = (DoubleVector)v; - for(int i=0; i<data.size(); i++) { + DoubleVector fbv = (DoubleVector) v; + for (int i = 0; i < data.size(); i++) { double newValue = data.get(i) + fbv.data.get(i); data.set(i, newValue); } } - // poussin 20060827 FIXME a refaire car v.data et date n'ont pas forcement leur element qui se correspondent, cette implatation est donc fausse + // poussin 20060827 FIXME a refaire car v.data et date n'ont pas forcement + // leur element qui se correspondent, cette implatation est donc fausse public void minus(Vector v) { - DoubleVector fbv = (DoubleVector)v; - for(int i=0; i<data.size(); i++) { + DoubleVector fbv = (DoubleVector) v; + for (int i = 0; i < data.size(); i++) { double newValue = data.get(i) - fbv.data.get(i); data.set(i, newValue); } } /** - * on applique sur chaque donnée existante et sur default - */ + * on applique sur chaque donnée existante et sur default + */ public void map(MapFunction f) { // on commence toujours par modifier la valeur par defaut // car les valeurs suivante pourrait prendre cette valeur // et donc disparaitre des tableaux si besoin defaultValue = f.apply(defaultValue); // on fait la boucle a l'envers au cas ou on supprime des valeurs - for(int i=data.size()-1; i>=0; i--) { + for (int i = data.size() - 1; i >= 0; i--) { double value = f.apply(data.get(i)); if (value == defaultValue) { // il etait present, on supprime l'element Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/FloatBigVector.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/FloatBigVector.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/FloatBigVector.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,21 +1,19 @@ -/* *##% - * Copyright (C) 2005 - * Code Lutin, Cédric Pineau, Benjamin Poussin +/* *##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin * - * 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 2 - * of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Lesser Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * * FloatBigVector.java @@ -37,7 +35,7 @@ protected float data[] = null; - public FloatBigVector(int capacity){ + public FloatBigVector(int capacity) { data = new float[capacity]; } @@ -54,18 +52,18 @@ } public void setValue(int pos, double value) { - data[pos] = (float)value; + data[pos] = (float) value; } public boolean equals(Object o) { boolean result = false; if (o instanceof FloatBigVector) { - FloatBigVector other = (FloatBigVector)o; + FloatBigVector other = (FloatBigVector) o; result = Arrays.equals(this.data, other.data); } else if (o instanceof Vector) { - Vector other = (Vector)o; + Vector other = (Vector) o; result = true; - for(int i=0; i<size() && result; i++){ + for (int i = 0; i < size() && result; i++) { result = getValue(i) == other.getValue(i); } } @@ -75,37 +73,41 @@ public boolean isImplementedPaste(Vector v) { return v instanceof FloatBigVector; } + public boolean isImplementedAdd(Vector v) { return v instanceof FloatBigVector; } + public boolean isImplementedMinus(Vector v) { return v instanceof FloatBigVector; } + public boolean isImplementedMap() { return true; } public void paste(Vector v) { - FloatBigVector fbv = (FloatBigVector)v; + FloatBigVector fbv = (FloatBigVector) v; System.arraycopy(fbv.data, 0, this.data, 0, this.size()); } + public void add(Vector v) { - FloatBigVector fbv = (FloatBigVector)v; - for(int i=0; i<data.length; i++) { + FloatBigVector fbv = (FloatBigVector) v; + for (int i = 0; i < data.length; i++) { data[i] += fbv.data[i]; } } public void minus(Vector v) { - FloatBigVector fbv = (FloatBigVector)v; - for(int i=0; i<data.length; i++) { + FloatBigVector fbv = (FloatBigVector) v; + for (int i = 0; i < data.length; i++) { data[i] -= fbv.data[i]; } } public void map(MapFunction f) { - for(int i=0; i<data.length; i++) { - data[i] = (float)f.apply(data[i]); + for (int i = 0; i < data.length; i++) { + data[i] = (float) f.apply(data[i]); } } Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/FloatVector.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/FloatVector.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/FloatVector.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,21 +1,19 @@ -/* *##% - * Copyright (C) 2005 - * Code Lutin, Cédric Pineau, Benjamin Poussin +/* *##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin * - * 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 2 - * of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Lesser Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * * FloatVector.java @@ -36,12 +34,11 @@ import org.apache.commons.collections.primitives.ArrayFloatList; /** -* Permet de stocker des données à une position lineair et de la redemander -* Cette classe ne gére que les données lineaire. -* L'avantage de cette classe est de ne conserver que les elements differents -* de la valeur par defaut, ce qui minimize la taille du tableau necessaire -* a conserver les données. -*/ + * Permet de stocker des données à une position lineair et de la redemander + * Cette classe ne gére que les données lineaire. L'avantage de cette classe est + * de ne conserver que les elements differents de la valeur par defaut, ce qui + * minimize la taille du tableau necessaire a conserver les données. + */ public class FloatVector implements Vector { // FloatVector /** maximum number of element, maximum pos value */ @@ -51,7 +48,7 @@ protected float defaultValue = 0; /** contient la position de l'element, le tableau est trie */ - protected int [] position; + protected int[] position; protected int positionSize = 0; /** contient la valeur de l'element */ @@ -63,7 +60,7 @@ Arrays.fill(position, Integer.MAX_VALUE); } - public FloatVector(int capacity, float defaultValue){ + public FloatVector(int capacity, float defaultValue) { this(capacity); this.defaultValue = defaultValue; } @@ -75,14 +72,15 @@ public double getMaxOccurence() { float result = defaultValue; - float [] tmp = data.toArray(); + float[] tmp = data.toArray(); // si potentiellement il y a plus d'element identique dans data // que de valeur par defaut, on recherche la valeur possible - if (this.capacity < 2*tmp.length) { + if (this.capacity < 2 * tmp.length) { Arrays.sort(tmp); - // le nombre de fois que l'on a rencontrer la valeur la plus nombreuse + // le nombre de fois que l'on a rencontrer la valeur la plus + // nombreuse int max = 1; // le nombre de fois que l'on a rencontrer la valeur courante int count = 1; @@ -94,13 +92,13 @@ float current = tmp[0]; // tant que l'on peut encore trouve un element plus nombreux dans le // tableau on le parcours - for(int i=1; max<tmp.length-i+count && i<tmp.length; i++){ + for (int i = 1; max < tmp.length - i + count && i < tmp.length; i++) { current = tmp[i]; - if(current == old){ + if (current == old) { count++; - }else{ - if(count > max){ + } else { + if (count > max) { max = count; result = old; } @@ -108,12 +106,12 @@ old = current; } } - if(count > max){ + if (count > max) { max = count; result = current; } - if(max <= capacity - tmp.length) { + if (max <= capacity - tmp.length) { // en fin de compte, il n'y a pas plus d'element identique // dans data que de defaultValue result = defaultValue; @@ -123,9 +121,10 @@ return result; } - protected void checkPos(int pos){ - if(pos < 0 || pos >= capacity) { - throw new IllegalArgumentException("pos " + pos + " is not in [0, "+capacity+"]"); + protected void checkPos(int pos) { + if (pos < 0 || pos >= capacity) { + throw new IllegalArgumentException("pos " + pos + " is not in [0, " + + capacity + "]"); } } @@ -141,12 +140,12 @@ } /** - * On ajoute dans l'o - */ + * On ajoute dans l'o + */ public void setValue(int pos, double dValue) { checkPos(pos); - float value = (float)dValue; + float value = (float) dValue; int index = findIndex(pos); if (index >= 0) { if (value == defaultValue) { @@ -161,7 +160,7 @@ // il n'etait pas present if (value != defaultValue) { // il faut ajouter dans position et dans data - index = -index -1; + index = -index - 1; addElementAt(index, pos); data.add(index, value); @@ -172,35 +171,36 @@ public boolean equals(Object o) { boolean result = false; if (o instanceof FloatVector) { - FloatVector other = (FloatVector)o; - result = Arrays.equals(this.position, other.position) && data.equals(other.data); + FloatVector other = (FloatVector) o; + result = Arrays.equals(this.position, other.position) + && data.equals(other.data); } else if (o instanceof Vector) { - Vector other = (Vector)o; + Vector other = (Vector) o; result = true; - for(int i=0; i<size() && result; i++){ + for (int i = 0; i < size() && result; i++) { result = getValue(i) == other.getValue(i); } } return result; } - /** - * retourne la position dans le tableau position de la position lineaire - * @return la position ou < 0 donnant la position de l'element s'il etait - * present - */ + * retourne la position dans le tableau position de la position lineaire + * + * @return la position ou < 0 donnant la position de l'element s'il etait + * present + */ protected int findIndex(int pos) { return Arrays.binarySearch(position, pos); } protected void ensureCapacity(int mincap) { - if(mincap > position.length) { + if (mincap > position.length) { int newcap = (position.length * 3) / 2 + 1; int olddata[] = position; position = new int[newcap >= mincap ? newcap : mincap]; System.arraycopy(olddata, 0, position, 0, positionSize); - for(int i=positionSize; i<position.length; i++){ + for (int i = positionSize; i < position.length; i++) { position[i] = Integer.MAX_VALUE; } } @@ -217,7 +217,7 @@ protected int removeElementAt(int index) { int oldval = position[index]; int numtomove = positionSize - index - 1; - if(numtomove > 0) { + if (numtomove > 0) { System.arraycopy(position, index + 1, position, index, numtomove); } positionSize--; @@ -225,63 +225,66 @@ return oldval; } - public boolean isImplementedPaste(Vector v) { return v instanceof FloatVector; } + public boolean isImplementedAdd(Vector v) { // FIXME une fois la methode implanter supprimer le false return false && v instanceof FloatVector; } + public boolean isImplementedMinus(Vector v) { // FIXME une fois la methode implanter supprimer le false return false && v instanceof FloatVector; } + public boolean isImplementedMap() { return true; } /** - * On recopie tous les attributs pour que le vector ressemble exactement - * a celui passé en argument - */ + * On recopie tous les attributs pour que le vector ressemble exactement a + * celui passé en argument + */ public void paste(Vector v) { - FloatVector fbv = (FloatVector)v; + FloatVector fbv = (FloatVector) v; this.capacity = fbv.capacity; this.defaultValue = fbv.defaultValue; this.positionSize = fbv.positionSize; this.position = new int[fbv.position.length]; - System.arraycopy(fbv.position, 0, this.position, 0, this.position.length); + System.arraycopy(fbv.position, 0, this.position, 0, + this.position.length); this.data.clear(); this.data.addAll(fbv.data); } // FIXME a faire public void add(Vector v) { - FloatVector fbv = (FloatVector)v; - for(int i=0; i<data.size(); i++) { - data.set(i, (float)(data.get(i) + fbv.data.get(i))); + FloatVector fbv = (FloatVector) v; + for (int i = 0; i < data.size(); i++) { + data.set(i, (float) (data.get(i) + fbv.data.get(i))); } } // FIXME a faire public void minus(Vector v) { - FloatVector fbv = (FloatVector)v; - for(int i=0; i<data.size(); i++) { - data.set(i, (float)(data.get(i) - fbv.data.get(i))); + FloatVector fbv = (FloatVector) v; + for (int i = 0; i < data.size(); i++) { + data.set(i, (float) (data.get(i) - fbv.data.get(i))); } } /** - * on applique sur chaque donnée existante et sur default - */ + * on applique sur chaque donnée existante et sur default + */ public void map(MapFunction f) { // on commence toujours par modifier la valeur par defaut // car les valeurs suivante pourrait prendre cette valeur // et donc disparaitre des tableaux si besoin - defaultValue = (float)f.apply(defaultValue); + defaultValue = (float) f.apply(defaultValue); // on fait la boucle a l'envers au cas ou on supprime des valeurs - for(int i=data.size()-1; i>=0; i--) { + for (int i = data.size() - 1; i >= 0; i--) { double value = f.apply(data.get(i)); if (value == defaultValue) { // il etait present, on supprime l'element @@ -289,7 +292,7 @@ data.removeElementAt(i); } else { // il etait deja present, on modifie la valeur - data.set(i, (float)value); + data.set(i, (float) value); } } } Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MapFunction.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MapFunction.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MapFunction.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,21 +1,19 @@ -/* *##% - * Copyright (C) 2002, 2003 Code Lutin, Cédric Pineau, - Benjamin Poussin +/* *##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin * - * 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 2 - * of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Lesser Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * * MapFunction.java @@ -34,12 +32,13 @@ public interface MapFunction { // MapFunction /** - * Permet de faire un traitement sur value et de retourne une nouvelle - * valeur. - * @param la valeur courante sur lequel il faut faire le traitement - * @return la nouvelle valeur à mettre dans la matrice à la place de - * l'ancienne. - */ + * Permet de faire un traitement sur value et de retourne une nouvelle + * valeur. + * + * @param la valeur courante sur lequel il faut faire le traitement + * @return la nouvelle valeur à mettre dans la matrice à la place de + * l'ancienne. + */ public double apply(double value); } // MapFunction Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixEncoder.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixEncoder.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixEncoder.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,21 +1,19 @@ -/* *##% - * Copyright (C) 2002, 2003 Code Lutin, Cédric Pineau, - Benjamin Poussin +/* *##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin * - * 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 2 - * of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Lesser Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * * MatriceEncoder.java @@ -41,34 +39,34 @@ protected Writer out = null; - public MatrixEncoder(Writer out){ + public MatrixEncoder(Writer out) { this.out = out; } /** - * Methode qui peut etre surcharge par les enfants - * Elle sert a mettre sous forme XML les objets de semantiques - * Par defaut cette méthode converti en représentation chaine les objets - * Un objet deviendra donc une chaine de caractere lors de la lecture de - * la matrice à partir du XML si cette méthode n'est pas surchargée. - * Le seul objet convenablement supporté sont les représentation objet - * des types primitifs - */ + * Methode qui peut etre surcharge par les enfants Elle sert a mettre sous + * forme XML les objets de semantiques Par defaut cette méthode converti en + * représentation chaine les objets Un objet deviendra donc une chaine de + * caractere lors de la lecture de la matrice à partir du XML si cette + * méthode n'est pas surchargée. Le seul objet convenablement supporté sont + * les représentation objet des types primitifs + */ protected String getSemanticsAsXml(Object o) throws IOException { - if(o == null){ + if (o == null) { // on ne fait rien car la valeur par defaut lorsqu'on relit // la matrice est null return null; - }else{ + } else { // par defaut si on ne sait pas comment mettre en XML un objet // on dit qu'il est de type String et on appelle la methode // toString sur l'objet // A la relecture l'objet sera donc une string String type = String.class.getName(); - if(o instanceof Number || o instanceof Boolean){ + if (o instanceof Number || o instanceof Boolean) { type = o.getClass().getName(); } - return "<object type=\"" + type + "\">" + o.toString() + "</object>"; + return "<object type=\"" + type + "\">" + o.toString() + + "</object>"; } } @@ -77,17 +75,18 @@ // que l'on retrouve le plus souvent double defaultValue = mat.getMaxOccurence(); - out.write("<matrix defaultValue=\"" + defaultValue + "\" name=\""+mat.getName()+"\" dimensions=\""); + out.write("<matrix defaultValue=\"" + defaultValue + "\" name=\"" + + mat.getName() + "\" dimensions=\""); out.write(MatrixHelper.coordinatesToString(mat.getDim())); - out.write("\" type=\""+mat.getClass().getName()+"\">\n"); + out.write("\" type=\"" + mat.getClass().getName() + "\">\n"); // ecriture des noms des dimensions - for(int i=0; i<mat.getNbDim(); i++){ + for (int i = 0; i < mat.getNbDim(); i++) { String dimName = mat.getDimensionName(i); // si le nom est non null et non vide on l'ecrit, // sinon c la valeur par defaut lorsqu'on relit la matrice // donc ca ne sert a rien de le mettre dans le XML - if(dimName != null && !"".equals(dimName)){ + if (dimName != null && !"".equals(dimName)) { out.write(" <dimensionName dim=\"" + i + "\">"); out.write(mat.getDimensionName(i)); out.write("</dimensionName>\n"); @@ -95,21 +94,22 @@ } // ecriture de la semantique - for(int i=0; i<mat.getNbDim(); i++){ + for (int i = 0; i < mat.getNbDim(); i++) { List sem = mat.getSemantics(i); List semAsXml = new ArrayList(); boolean haveNotNull = false; - for(Iterator e=sem.iterator(); e.hasNext();){ + for (Iterator e = sem.iterator(); e.hasNext();) { String xml = getSemanticsAsXml(e.next()); semAsXml.add(xml); haveNotNull = haveNotNull || xml != null; } - if(haveNotNull){ + if (haveNotNull) { out.write(" <semantics dim=\"" + i + "\">\n"); - for(int index=0; index<semAsXml.size(); index++){ - String xml = (String)semAsXml.get(index); - if(xml != null){ - out.write(" <sem index=\""+index+"\">"+xml+"</sem>\n"); + for (int index = 0; index < semAsXml.size(); index++) { + String xml = (String) semAsXml.get(index); + if (xml != null) { + out.write(" <sem index=\"" + index + "\">" + xml + + "</sem>\n"); } } out.write(" </semantics>\n"); @@ -117,11 +117,13 @@ } // ecriture des valeur de la matrice - for(MatrixIterator i=mat.iterator(); i.next();){ + for (MatrixIterator i = mat.iterator(); i.next();) { double val = i.getValue(); - if(val != defaultValue){ - String path = MatrixHelper.coordinatesToString(i.getCoordinates()); - out.write("\t<element path=\""+path+"\" value=\""+val+"\"/>\n"); + if (val != defaultValue) { + String path = MatrixHelper.coordinatesToString(i + .getCoordinates()); + out.write("\t<element path=\"" + path + "\" value=\"" + val + + "\"/>\n"); } } Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixException.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixException.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixException.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,40 +1,36 @@ -/**##%% -* Copyright (C) 2002, 2003 Code Lutin -* -* 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 2 -* 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, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*##%%**/ +/*##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ - /** -* MatriceException.java -* -* -* Created: Tue Jun 29 11:46:39 1999 -* -* @author -* @version $Revision$ -* -* Mise a jour: $Date$ -* par : $Author$ -*/ - + * MatriceException.java + * + * Created: Tue Jun 29 11:46:39 1999 + * + * @author + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ package org.codelutin.math.matrix; public class MatrixException extends RuntimeException { - /** */ + /** serialVersionUID */ private static final long serialVersionUID = 1917420713781767581L; public MatrixException(String s) { @@ -45,4 +41,4 @@ super(s, e); } -} // MatriceException +} // MatriceException \ No newline at end of file Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,21 +1,19 @@ -/* *##% - * Copyright (C) 2005 - * Code Lutin, Cédric Pineau, Benjamin Poussin +/* *##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin * - * 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 2 - * of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Lesser Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * * MatrixFactory.java @@ -34,17 +32,17 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.util.List; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** -* Cette classe permet de creer des matrices, toutes les creations de matrice -* doivent etre faite a travers cette classe. -* Cette classe permet de modifier la representation interne des matrices -* de facon simple. -* <p> -* -*/ + * Cette classe permet de creer des matrices, toutes les creations de matrice + * doivent etre faite a travers cette classe. Cette classe permet de modifier la + * representation interne des matrices de facon simple. + * <p> + * + */ public class MatrixFactory { // MatrixFactory /** to use log facility, just put in your code: log.info(\"...\"); */ @@ -56,44 +54,57 @@ // Il faut le faire par pur introspection sinon l'exception // NoClassDefFoundError est levé avant d'entrer dans le constructeur // static :( - Class converterClass = Class.forName("org.codelutin.math.matrix.MatrixNDXMLConverter"); + Class converterClass = Class + .forName("org.codelutin.math.matrix.MatrixNDXMLConverter"); Object converter = converterClass.newInstance(); - Class converterFactoryClass = Class.forName("org.codelutin.xml.XMLConverterFactory"); - Method m = converterFactoryClass.getMethod("addConverter", Class.class, Class.forName("org.codelutin.xml.XMLConverter")); + Class converterFactoryClass = Class + .forName("org.codelutin.xml.XMLConverterFactory"); + Method m = converterFactoryClass.getMethod("addConverter", + Class.class, Class + .forName("org.codelutin.xml.XMLConverter")); m.invoke(null, MatrixND.class, converter); - // org.codelutin.xml.XMLConverterFactory.addConverter(MatrixND.class, + //org.codelutin.xml.XMLConverterFactory.addConverter(MatrixND.class, // new MatrixNDXMLConverter()); log.info("Converter XML pour MatrixND ajoute"); // on essai d'enregistrer le converter JDBC // le JDBC depend du XML try { - converterClass = Class.forName("org.codelutin.math.matrix.MatrixNDJDBCConverter"); + converterClass = Class + .forName("org.codelutin.math.matrix.MatrixNDJDBCConverter"); converter = converterClass.newInstance(); - converterFactoryClass = Class.forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformerFactory"); - m = converterFactoryClass.getMethod("addConverter", Class.class, Class.forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformer")); + converterFactoryClass = Class + .forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformerFactory"); + m = converterFactoryClass + .getMethod( + "addConverter", + Class.class, + Class + .forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformer")); m.invoke(null, MatrixND.class, converter); - // Class converterClass = org.codelutin.math.matrix.MatrixNDJDBCConverter(); + // Class converterClass = + // org.codelutin.math.matrix.MatrixNDJDBCConverter(); // JDBCTransformerFactory // .addConverter(MatrixND.class, new MatrixNDJDBCConverter()); log.info("Converter JDBC pour MatrixND ajoute"); } catch (Throwable eee) { - log.info("librairie topia non presente. Import/Export JDBC impossible"); + log + .info("librairie topia non presente. Import/Export JDBC impossible"); log.debug("L'exception etait", eee); } } catch (Throwable eee) { - log.info("librairie lutinxml non presente. Import/Export XML impossible"); + log + .info("librairie lutinxml non presente. Import/Export XML impossible"); log.debug("L'exception etait", eee); } } - /** Valeur par defaut si aucun type de Vector n'est donné */ static protected Class defaultVectorClass = DoubleBigVector.class; @@ -112,66 +123,69 @@ } /** - * Retourne une factory utilisant vectorClass comme classe de base - * a l'implantation des matrices - */ + * Retourne une factory utilisant vectorClass comme classe de base a + * l'implantation des matrices + */ static public MatrixFactory getInstance(Class vectorClass) { return new MatrixFactory(vectorClass); } /** - * Utilise par defaut {@link FloatBigVector} - */ + * Utilise par defaut {@link FloatBigVector} + */ static public MatrixFactory getInstance() { return getInstance(defaultVectorClass); } - public MatrixND create(int [] dim){ + public MatrixND create(int[] dim) { return new MatrixNDImpl(this, dim); } - public MatrixND create(List[] semantics){ + + public MatrixND create(List[] semantics) { return new MatrixNDImpl(this, semantics); } - public MatrixND create(String name, int [] dim){ + public MatrixND create(String name, int[] dim) { return new MatrixNDImpl(this, name, dim); - } + } - public MatrixND create(String name, int [] dim, String [] dimNames){ + public MatrixND create(String name, int[] dim, String[] dimNames) { return new MatrixNDImpl(this, name, dim, dimNames); - } + } - public MatrixND create(String name, List[] semantics){ + public MatrixND create(String name, List[] semantics) { return new MatrixNDImpl(this, name, semantics); } - public MatrixND create(String name, List[] semantics, String [] dimNames){ + public MatrixND create(String name, List[] semantics, String[] dimNames) { return new MatrixNDImpl(this, name, semantics, dimNames); } - public MatrixND create(MatrixND matrix){ + public MatrixND create(MatrixND matrix) { return new MatrixNDImpl(this, matrix); } /** - * Crée une nouvelle matrice identité. Une matrice identité est une matrice - * à 2 dimensions dont tous les éléments de la diagonal vaut 1 - * @param size la taille de la matrice - * @return une nouvelle matrice identité - */ - public MatrixND matrixId(int size){ - MatrixND result = create(new int[]{size, size}); - for(int i=0; i<size; i++){ - result.setValue(i, i , 1); + * Crée une nouvelle matrice identité. Une matrice identité est une matrice + * à 2 dimensions dont tous les éléments de la diagonal vaut 1 + * + * @param size la taille de la matrice + * @return une nouvelle matrice identité + */ + public MatrixND matrixId(int size) { + MatrixND result = create(new int[] { size, size }); + for (int i = 0; i < size; i++) { + result.setValue(i, i, 1); } return result; } protected Vector createVector(int length) { try { - Constructor c = vectorClass.getConstructor(new Class[]{Integer.TYPE}); - return (Vector)c.newInstance(new Object[]{length}); - } catch (Exception eee){ + Constructor c = vectorClass + .getConstructor(new Class[] { Integer.TYPE }); + return (Vector) c.newInstance(new Object[] { length }); + } catch (Exception eee) { throw new RuntimeException("Can't create vector", eee); } } Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixHelper.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixHelper.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixHelper.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,21 +1,19 @@ -/* *##% - * Copyright (C) 2002, 2003, 2004 Code Lutin, C�dric Pineau, - Benjamin Poussin +/* *##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin * - * 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 2 - * of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Lesser Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * * MatrixHelper.java @@ -31,10 +29,7 @@ package org.codelutin.math.matrix; -import java.io.IOException; import java.io.StreamTokenizer; -import java.io.StringReader; -import java.io.StringWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -50,11 +45,13 @@ * Logger for this class */ private static final Log log = LogFactory.getLog(MatrixHelper.class); - // MatrixHelper + // MatrixHelper + /** * Convert Matrix to identity matrix must have 2 dimensions. If dimension * haven't same length, then the small dimension is used. + * * @param mat * @return */ @@ -63,11 +60,11 @@ if (size > mat.getDim(1)) { size = mat.getDim(1); } - + fill(mat, 0); - - for(int i=0; i<size; i++){ - mat.setValue(i, i , 1); + + for (int i = 0; i < size; i++) { + mat.setValue(i, i, 1); } return mat; } @@ -76,27 +73,28 @@ * Permet de relire une chaine du type [[[1, 2], [3, 4]],[[3, 5], [1, 4]]] * <p> * Remarque: une premiere implatantion avait ete faite en utilisant - * {@link StreamTokenizer} mais en fait il y a un bug dedans, il ne - * sait pas parser les chiffres avec un exposant: 5.0E-7 par exemple - * est lu comme 5.0 :( + * {@link StreamTokenizer} mais en fait il y a un bug dedans, il ne sait pas + * parser les chiffres avec un exposant: 5.0E-7 par exemple est lu comme 5.0 + * :( * <p> - * Remarque: une autre implantation de remplacement a ete faite en - * utilisant le {@link org.codelutin.util.StrintUtil#split(String, String)} - * mais elle etait moins performante (x2) + * Remarque: une autre implantation de remplacement a ete faite en utilisant + * le {@link org.codelutin.util.StrintUtil#split(String, String)} mais elle + * etait moins performante (x2) * * @param s la chaine representant les listes de liste * @return une liste de liste ... de Double - */ + */ static public List convertStringToList(String s) { List result = null; Stack<List> stack = new Stack<List>(); - StringBuffer number = new StringBuffer(20); // initial to 20 char - - for (int i=0; i<s.length(); i++) { + StringBuffer number = new StringBuffer(20); // initial to 20 char + + for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c == ' ') { // skip space - }if (c == '[') { + } + if (c == '[') { stack.push(new ArrayList()); } else if (c == ',') { if (number.length() != 0) { @@ -106,7 +104,7 @@ stack.peek().add(value); } number.setLength(0); - } else if (c == ']'){ + } else if (c == ']') { // fin d'une liste, il doit rester un nombre dans number // a mois que la liste etait vide if (number.length() != 0) { @@ -122,7 +120,7 @@ stack.peek().add(current); } } else { - // pas un '[' ou ']', pas une ',' devrait etre + // pas un '[' ou ']', pas une ',' devrait etre // un bout du nombre, si c un espace qui traine n'importe ou // c pas grace car Double.valueOf gere les espaces number.append(c); @@ -132,15 +130,16 @@ } /** - * permet de donner une repr�sentation String d'un tableau de coordonn�es - * @param coordinates les coordonn�es - * @return la chaine demand�e de la forme 1,3,34,23 - */ - static public String coordinatesToString(int [] coordinates){ + * permet de donner une repr�sentation String d'un tableau de coordonn�es + * + * @param coordinates les coordonn�es + * @return la chaine demand�e de la forme 1,3,34,23 + */ + static public String coordinatesToString(int[] coordinates) { StringBuffer sb = new StringBuffer(); - for(int i=0; i<coordinates.length; i++){ + for (int i = 0; i < coordinates.length; i++) { sb.append(coordinates[i]); - if(i+1 < coordinates.length){ + if (i + 1 < coordinates.length) { sb.append(','); } } @@ -148,43 +147,46 @@ } /** - * permet de donner une repr�sentation String d'un tableau de coordonn�es - * @param coordinates les coordonn�es - * @return la chaine demand�e de la forme "Ob1","Ob2,"Ob3", ... - * la chaine prise pour l'objet est celle retourn�e par la m�thode - * toString de l'objet - */ - static public String coordinatesToString(Object [] coordinates){ + * permet de donner une repr�sentation String d'un tableau de coordonn�es + * + * @param coordinates les coordonn�es + * @return la chaine demand�e de la forme "Ob1","Ob2,"Ob3", ... la chaine + * prise pour l'objet est celle retourn�e par la m�thode toString de + * l'objet + */ + static public String coordinatesToString(Object[] coordinates) { StringBuffer sb = new StringBuffer(); - for(int i=0; i<coordinates.length; i++){ + for (int i = 0; i < coordinates.length; i++) { sb.append(coordinates[i]); - if(i+1 < coordinates.length) + if (i + 1 < coordinates.length) sb.append(','); } return sb.toString(); } /** - * Permet de savoir si deux dimension sont identique - */ - static public boolean sameDimension(int [] dim1, int [] dim2){ + * Permet de savoir si deux dimension sont identique + */ + static public boolean sameDimension(int[] dim1, int[] dim2) { return Arrays.equals(dim1, dim2); } /** - * Permet de convertir des coordonn�es d�fini par des entiers en coordonn�e - * semantique par des objets - * @param semantics la semantique � utilis� pour la conversion - * @param coordinates les coordonn�es � convertir - * @return un tableau donnant les coordonn�es sous forme semantique - * s'il n'y a pas de semantique (liste pleine de null) alors un objet - * Integer est cr�er pour repr�senter la semantique de la dimension. - */ - static public Object [] dimensionToSemantics(List [] semantics, int [] coordinates){ - Object [] result = new Object[coordinates.length]; - for(int i=0; i<result.length; i++){ + * Permet de convertir des coordonn�es d�fini par des entiers en coordonn�e + * semantique par des objets + * + * @param semantics la semantique � utilis� pour la conversion + * @param coordinates les coordonn�es � convertir + * @return un tableau donnant les coordonn�es sous forme semantique s'il n'y + * a pas de semantique (liste pleine de null) alors un objet Integer + * est cr�er pour repr�senter la semantique de la dimension. + */ + static public Object[] dimensionToSemantics(List[] semantics, + int[] coordinates) { + Object[] result = new Object[coordinates.length]; + for (int i = 0; i < result.length; i++) { result[i] = semantics[i].get(coordinates[i]); - if(result[i] == null){ + if (result[i] == null) { result[i] = new Integer(coordinates[i]); } } @@ -192,20 +194,23 @@ } /** - * Permet de convertir des coordonn�es s�mantiques en coordonn�es d�fini - * par des entiers. Cette fonction est l'inverse de - * {@link #dimensionToSemantics}. - * @param semantics la semantique � utilis� pour la conversion - * @param coordonn�es les coordonn�es s�mantique - * @return les coordonn�es en entier. Si la s�mantique est repr�sent� par un - * Integer alors la valeur de l'interger est utilis� pour la conversion. - */ - static public int [] semanticsToDimension(List [] semantics, Object [] coordinates){ - int [] result = new int[coordinates.length]; - for(int i=0; i<coordinates.length; i++){ - if(coordinates[i] == null){ + * Permet de convertir des coordonn�es s�mantiques en coordonn�es d�fini par + * des entiers. Cette fonction est l'inverse de + * {@link #dimensionToSemantics}. + * + * @param semantics la semantique � utilis� pour la conversion + * @param coordonn�es les coordonn�es s�mantique + * @return les coordonn�es en entier. Si la s�mantique est repr�sent� par un + * Integer alors la valeur de l'interger est utilis� pour la + * conversion. + */ + static public int[] semanticsToDimension(List[] semantics, + Object[] coordinates) { + int[] result = new int[coordinates.length]; + for (int i = 0; i < coordinates.length; i++) { + if (coordinates[i] == null) { result[i] = -1; - }else{ + } else { result[i] = indexOf(semantics, i, coordinates[i]); } } @@ -213,35 +218,40 @@ } /** - * Permet de retrouver la position d'un objet dans une liste - * @param semantics la semantique � utilis� pour la recherche - * @param dim la dimension dans lequel il faut faire la recherche - * @param o l'objet � rechercher - * @return la position de l'objet dans la dimension demand�e - */ - static public int indexOf(List [] semantics, int dim, Object o) throws NoSuchElementException{ - if(o instanceof Integer){ - return ((Integer)o).intValue(); + * Permet de retrouver la position d'un objet dans une liste + * + * @param semantics la semantique � utilis� pour la recherche + * @param dim la dimension dans lequel il faut faire la recherche + * @param o l'objet � rechercher + * @return la position de l'objet dans la dimension demand�e + */ + static public int indexOf(List[] semantics, int dim, Object o) + throws NoSuchElementException { + if (o instanceof Integer) { + return ((Integer) o).intValue(); } int result = -1; - if((0 <= dim) && (dim < semantics.length)){ + if ((0 <= dim) && (dim < semantics.length)) { result = semantics[dim].indexOf(o); } - if(result == -1){ - throw new NoSuchElementException("L'objet pass� en argument n'a pas �t� retrouve ou la dimension donn�e ne convient pas:" + o + " in " + semantics[dim]); + if (result == -1) { + throw new NoSuchElementException( + "L'objet pass� en argument n'a pas �t� retrouve ou la dimension donn�e ne convient pas:" + + o + " in " + semantics[dim]); } return result; } /** - * Permet de remplir toute la matrice avec la m�me donn�e - * @param mat la matrice � remplir - * @param value la valeur de remplissage - * @return la matrice pass� en param�tre - */ - static public MatrixND fill(MatrixND mat, final double value){ - mat.map(new MapFunction(){ - public double apply(double v){ + * Permet de remplir toute la matrice avec la m�me donn�e + * + * @param mat la matrice � remplir + * @param value la valeur de remplissage + * @return la matrice pass� en param�tre + */ + static public MatrixND fill(MatrixND mat, final double value) { + mat.map(new MapFunction() { + public double apply(double v) { return value; } }); @@ -249,46 +259,48 @@ } // /** - // * Cr�e une nouvelle matrice identit�. Une matrice identit� est une matrice + // * Cr�e une nouvelle matrice identit�. Une matrice identit� est une + // matrice // * � 2 dimensions dont tous les �l�ments de la diagonal vaut 1 // * @param size la taille de la matrice // * @return une nouvelle matrice identit� // */ // static public MatrixND matrixId(int size){ - // MatrixND result = new MatrixNDImpl(new int[]{size, size}); - // for(int i=0; i<size; i++){ - // result.setValue(i, i , 1); - // } - // return result; + // MatrixND result = new MatrixNDImpl(new int[]{size, size}); + // for(int i=0; i<size; i++){ + // result.setValue(i, i , 1); // } + // return result; + // } /** - * Retourne la valeur la plus courrement rencontrer dans un tableau. - * si plusieurs valeurs ont le m�me nombre d'occurence la plus petite - * valeur est retourn�. - * @param tab le tableau de valeur - * @return la valeur la plus nombreuse dans le tableau - */ - static public double maxOccurence(double [] tab){ - double [] tmp = new double[tab.length]; + * Retourne la valeur la plus courrement rencontrer dans un tableau. si + * plusieurs valeurs ont le m�me nombre d'occurence la plus petite valeur + * est retourn�. + * + * @param tab le tableau de valeur + * @return la valeur la plus nombreuse dans le tableau + */ + static public double maxOccurence(double[] tab) { + double[] tmp = new double[tab.length]; System.arraycopy(tab, 0, tmp, 0, tab.length); return maxOccurence1(tmp); } - static public double maxOccurence(float [] tab){ - double [] tmp = new double[tab.length]; - for(int i=0; i<tab.length; i++){ + static public double maxOccurence(float[] tab) { + double[] tmp = new double[tab.length]; + for (int i = 0; i < tab.length; i++) { tmp[i] = tab[i]; } return maxOccurence1(tmp); } /** - * le tableau en entre est trie durant l'execution de la methode, il est - * donc modifi� - */ - static protected double maxOccurence1(double [] tmp){ - if(tmp.length == 0){ + * le tableau en entre est trie durant l'execution de la methode, il est + * donc modifi� + */ + static protected double maxOccurence1(double[] tmp) { + if (tmp.length == 0) { throw new IllegalArgumentException("Array must be not empty"); } // double [] tmp = new double[tab.length]; @@ -307,13 +319,13 @@ double current = tmp[0]; // tant que l'on peut encore trouve un element plus nombreux dans le // tableau on le parcours - for(int i=1; max<tmp.length-i+count && i<tmp.length; i++){ + for (int i = 1; max < tmp.length - i + count && i < tmp.length; i++) { current = tmp[i]; - if(current == old){ + if (current == old) { count++; - }else{ - if(count > max){ + } else { + if (count > max) { max = count; result = old; } @@ -321,26 +333,28 @@ old = current; } } - if(count > max){ + if (count > max) { max = count; result = current; } return result; } -// static public String encodeToXML(MatrixND mat){ -// StringWriter out = new StringWriter(); -// XMLEncoderDecoder.getInstance().encode(out, mat); -// return out.toString(); -// } -// -// static public MatrixND decodeFromXML(String xml){ -// try{ -// return (MatrixND)XMLEncoderDecoder.getInstance().decode(new StringReader(xml)); -// }catch(Exception eee){ -// throw new MatrixException("Erreur durant le decodage de la matrice", eee); -// } -// } + // static public String encodeToXML(MatrixND mat){ + // StringWriter out = new StringWriter(); + // XMLEncoderDecoder.getInstance().encode(out, mat); + // return out.toString(); + // } + // + // static public MatrixND decodeFromXML(String xml){ + // try{ + // return (MatrixND)XMLEncoderDecoder.getInstance().decode(new + // StringReader(xml)); + // }catch(Exception eee){ + // throw new MatrixException("Erreur durant le decodage de la matrice", + // eee); + // } + // } } // MatrixHelper Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixIterator.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixIterator.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixIterator.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,21 +1,19 @@ -/* *##% - * Copyright (C) 2002, 2003, 2004 Code Lutin, Cédric Pineau, - * Benjamin Poussin +/* *##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin * - * 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 2 - * of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Lesser Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * * MatrixIterator.java @@ -34,10 +32,10 @@ public interface MatrixIterator extends BasicMatrixIterator { // MatrixIterator /** - * Retourne les coordonnés de l'élément, en sémantique. - * Si la matrice n'a pas de sémantique alors retourne null - */ - public Object [] getSemanticsCoordinates(); + * Retourne les coordonnés de l'élément, en sémantique. Si la matrice n'a + * pas de sémantique alors retourne null + */ + public Object[] getSemanticsCoordinates(); } // MatrixIterator Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixIteratorImpl.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixIteratorImpl.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixIteratorImpl.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,21 +1,19 @@ -/* *##% - * Copyright (C) 2002, 2003, 2004 Code Lutin, Cédric Pineau, - * Benjamin Poussin +/* *##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin * - * 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 2 - * of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Lesser Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * * MatrixIteratorImpl.java @@ -36,46 +34,47 @@ public class MatrixIteratorImpl implements MatrixIterator { // MatrixIteratorImpl protected BasicMatrixIterator iterator = null; - protected List [] semantics = null; + protected List[] semantics = null; protected int pos = 0; /** - * @param matrix la matrice sur lequel l'iterator doit travailler - * @param semantics la semantique de matrix, si matrix n'a pas de semantique - * alors il faut passer null - */ - public MatrixIteratorImpl(BasicMatrixIterator iterator, List [] semantics){ + * @param matrix la matrice sur lequel l'iterator doit travailler + * @param semantics la semantique de matrix, si matrix n'a pas de semantique + * alors il faut passer null + */ + public MatrixIteratorImpl(BasicMatrixIterator iterator, List[] semantics) { this.iterator = iterator; this.semantics = semantics; pos = 0; } - public boolean hasNext(){ + public boolean hasNext() { return iterator.hasNext(); } - public boolean next(){ + public boolean next() { return iterator.next(); } - public int [] getCoordinates(){ + public int[] getCoordinates() { return iterator.getCoordinates(); } - public double getValue(){ + public double getValue() { return iterator.getValue(); } - public void setValue(double value){ + public void setValue(double value) { iterator.setValue(value); } - public Object [] getSemanticsCoordinates(){ - if(semantics == null){ + public Object[] getSemanticsCoordinates() { + if (semantics == null) { return null; - }else{ - int [] coordinates = getCoordinates(); - Object [] result = MatrixHelper.dimensionToSemantics(semantics, coordinates); + } else { + int[] coordinates = getCoordinates(); + Object[] result = MatrixHelper.dimensionToSemantics(semantics, + coordinates); return result; } } Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,33 +1,31 @@ -/* *##% -* Copyright (C) 2002, 2003, 2004 Code Lutin, Cédric Pineau, -* Benjamin Poussin -* -* 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 2 -* 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, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*##%*/ +/* *##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * -* MatrixND.java -* -* Created: 29 oct. 2004 -* -* @author Benjamin Poussin <poussin@codelutin.com> -* @version $Revision$ -* -* Mise a jour: $Date$ -* par : $Author$ -*/ + * MatrixND.java + * + * Created: 29 oct. 2004 + * + * @author Benjamin Poussin <poussin@codelutin.com> + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ package org.codelutin.math.matrix; @@ -40,489 +38,534 @@ public interface MatrixND extends Serializable, Cloneable { // MatrixND /** - * Retourne la factory qui a permit de creer la matrice - */ + * Retourne la factory qui a permit de creer la matrice + */ public MatrixFactory getFactory(); /** - * Donne toutes les semantiques de la matrice - * Si la matrice n'a pas de semantique retourne null - */ + * Donne toutes les semantiques de la matrice Si la matrice n'a pas de + * semantique retourne null + */ public List[] getSemantics(); /** - * Retourne la semantique pour une dimension - * @param dim la dimension pour lequel on veut la semantique - * @return la semantique de la dimension on null s'il n'y a pas de semantique - */ + * Retourne la semantique pour une dimension + * + * @param dim la dimension pour lequel on veut la semantique + * @return la semantique de la dimension on null s'il n'y a pas de + * semantique + */ public List getSemantics(int dim); /** - * Modifie la semantique d'une dimension - */ + * Modifie la semantique d'une dimension + */ public void setSemantics(int dim, List sem); /** - * Permet de donner un nom à la matrice. - */ + * Permet de donner un nom à la matrice. + */ public void setName(String name); /** - * Retourne le nom de la matrice - * @return le nom de la matrice ou la chaine vide si pas de nom. - */ + * Retourne le nom de la matrice + * + * @return le nom de la matrice ou la chaine vide si pas de nom. + */ public String getName(); /** - * Permet de mettre des noms aux différentes dimension. - */ + * Permet de mettre des noms aux différentes dimension. + */ public void setDimensionName(String[] names); /** - * Permet de mettre un nom à une dimension. - * @param dim la dimension dont on veut changer le nom - * @param name le nom à donner à la dimension - */ + * Permet de mettre un nom à une dimension. + * + * @param dim la dimension dont on veut changer le nom + * @param name le nom à donner à la dimension + */ public void setDimensionName(int dim, String name); /** - * Retourne le nom de la dimension demandé. - * @param dim la dimension dont on veut le nom - * @return le nom de la dimension ou la chaine vide si la dimension n'a - * pas de nom - * @ si la dimension demandé n'est pas valide - */ + * Retourne le nom de la dimension demandé. + * + * @param dim la dimension dont on veut le nom + * @return le nom de la dimension ou la chaine vide si la dimension n'a pas + * de nom @ si la dimension demandé n'est pas valide + */ public String getDimensionName(int dim); - public String [] getDimensionName(); + public String[] getDimensionName(); + /** - * Retourne la valeur la plus courrement rencontrer dans un tableau. - * si plusieurs valeurs ont le même nombre d'occurence la plus petite - * valeur est retourné. - * @param tab le tableau de valeur - * @return la valeur la plus nombreuse dans le tableau - */ + * Retourne la valeur la plus courrement rencontrer dans un tableau. si + * plusieurs valeurs ont le même nombre d'occurence la plus petite valeur + * est retourné. + * + * @param tab le tableau de valeur + * @return la valeur la plus nombreuse dans le tableau + */ public double getMaxOccurence(); /** - * Retourne le nombre de dimensions de la matrice. - */ + * Retourne le nombre de dimensions de la matrice. + */ public int getNbDim(); /** - * Retourne les dimensions de la matrice. - */ + * Retourne les dimensions de la matrice. + */ public int[] getDim(); /** - * Retourne la dimension de la matrice dans la dimension d - */ + * Retourne la dimension de la matrice dans la dimension d + */ public int getDim(int d); /** - * Retourne un iterator sur toute la matrice - */ + * Retourne un iterator sur toute la matrice + */ public MatrixIterator iterator(); /** - * Applique une fonction sur chaque valeur de la matrice - */ + * Applique une fonction sur chaque valeur de la matrice + */ public MatrixND map(MapFunction f); -// /** -// * Retourne la sous matrice demandée en fonction des dimensions -// * passé en paramètre.<br> -// * -// * Exemple: Si on a un matrice 3D.<br> -// * get([1,1,1]) retourne un element de la matrice.<br> -// * get([0,0]) retourne une matrice 1D.<br> -// * get([3]) retourne une matrice 2D.<br> -// * get([-1,1]) retourne une matrice 2D.<br> -// * get([-1,-1,1]) retourne une matrice 2D.<br> -// * -// * @param dimensions les différentes dimension à extraire. -// * -// * @return une MatrixND. -// */ -// public MatrixND get(int [] dimensions); -// public MatrixND get(int x); -// public MatrixND get(int x, int y); -// public MatrixND get(int x, int y, int z); -// public MatrixND get(int x, int y, int z, int t); + // /** + // * Retourne la sous matrice demandée en fonction des dimensions + // * passé en paramètre.<br> + // * + // * Exemple: Si on a un matrice 3D.<br> + // * get([1,1,1]) retourne un element de la matrice.<br> + // * get([0,0]) retourne une matrice 1D.<br> + // * get([3]) retourne une matrice 2D.<br> + // * get([-1,1]) retourne une matrice 2D.<br> + // * get([-1,-1,1]) retourne une matrice 2D.<br> + // * + // * @param dimensions les différentes dimension à extraire. + // * + // * @return une MatrixND. + // */ + // public MatrixND get(int [] dimensions); + // public MatrixND get(int x); + // public MatrixND get(int x, int y); + // public MatrixND get(int x, int y, int z); + // public MatrixND get(int x, int y, int z, int t); /** - * Renvoie un element de la matrice demandée en fonction des dimensions - * passé en paramètre.<br> - * - * Exemple: Si on a un matrice 3D.<br> - * getValue(1,1,1) retourne un element de la matrice.<br> - * - * @param dimensions les différentes dimension à extraire. Le - * tableau doit contenir toutes les dimensions de la matrice, et - * seulement des nombres positif - * - * @return un entier double. - */ - public double getValue(int [] dim); + * Renvoie un element de la matrice demandée en fonction des dimensions + * passé en paramètre.<br> + * + * Exemple: Si on a un matrice 3D.<br> + * getValue(1,1,1) retourne un element de la matrice.<br> + * + * @param dimensions les différentes dimension à extraire. Le tableau doit + * contenir toutes les dimensions de la matrice, et seulement des + * nombres positif + * + * @return un entier double. + */ + public double getValue(int[] dim); + public double getValue(int x); + public double getValue(int x, int y); + public double getValue(int x, int y, int z); + public double getValue(int x, int y, int z, int t); - public double getValue(Object [] coordinates); + public double getValue(Object[] coordinates); + public double getValue(Object x); + public double getValue(Object x, Object y); + public double getValue(Object x, Object y, Object z); + public double getValue(Object x, Object y, Object z, Object t); -// /** -// * Modifie la sous matrice demandée en fonction des dimensions -// * passé en paramètre.<br> -// * -// * Exemple: Si on a un matrice 3D.<br> -// * set([1,1,1], m) modifie un element de la matrice.<br> -// * set([0,0], m) modifie une matrice 1D.<br> -// * set([3], m) modifie une matrice 2D.<br> -// * set([-1,1], m) modifie une matrice 2D.<br> -// * set([-1,-1,1], m) modifie une matrice 2D.<br> -// * -// * @param dimensions les différentes dimension à extraire. -// * -// * @param m la matrice qui doit remplacer la sous matrice spécifié -// * par l'argument dimensions -// */ -// public void set(int [] dimensions, MatrixND m); -// public void set(int x, MatrixND m); -// public void set(int x, int y, MatrixND m); -// public void set(int x, int y, int z, MatrixND m); -// public void set(int x, int y, int z, int t, MatrixND m); + // /** + // * Modifie la sous matrice demandée en fonction des dimensions + // * passé en paramètre.<br> + // * + // * Exemple: Si on a un matrice 3D.<br> + // * set([1,1,1], m) modifie un element de la matrice.<br> + // * set([0,0], m) modifie une matrice 1D.<br> + // * set([3], m) modifie une matrice 2D.<br> + // * set([-1,1], m) modifie une matrice 2D.<br> + // * set([-1,-1,1], m) modifie une matrice 2D.<br> + // * + // * @param dimensions les différentes dimension à extraire. + // * + // * @param m la matrice qui doit remplacer la sous matrice spécifié + // * par l'argument dimensions + // */ + // public void set(int [] dimensions, MatrixND m); + // public void set(int x, MatrixND m); + // public void set(int x, int y, MatrixND m); + // public void set(int x, int y, int z, MatrixND m); + // public void set(int x, int y, int z, int t, MatrixND m); + /** + * Modifie un element de la matrice en fonction des dimensions passé en + * paramètre.<br> + * + * Exemple: Si on a un matrice 3D.<br> + * set([1,1,1], m) modifie un element de la matrice.<br> + * + * @param dimensions les différentes dimension à extraire. + * + * @param d l'entier double qui doit remplacer l'entier double spécifié par + * l'argument dimensions + */ + public void setValue(int[] dimensions, double d); - /** - * Modifie un element de la matrice en fonction des dimensions - * passé en paramètre.<br> - * - * Exemple: Si on a un matrice 3D.<br> - * set([1,1,1], m) modifie un element de la matrice.<br> - * - * @param dimensions les différentes dimension à extraire. - * - * @param d l'entier double qui doit remplacer l'entier double spécifié - * par l'argument dimensions - */ - public void setValue(int [] dimensions, double d); public void setValue(int x, double d); + public void setValue(int x, int y, double d); + public void setValue(int x, int y, int z, double d); + public void setValue(int x, int y, int z, int t, double d); - public void setValue(Object [] coordinates, double d); + public void setValue(Object[] coordinates, double d); + public void setValue(Object x, double d); + public void setValue(Object x, Object y, double d); + public void setValue(Object x, Object y, Object z, double d); + public void setValue(Object x, Object y, Object z, Object t, double d); /** - * Copy la matrice pour pouvoir la modifier sans perdre les - * donnees initiales. - */ + * Copy la matrice pour pouvoir la modifier sans perdre les donnees + * initiales. + */ public MatrixND copy(); - -// public String toString(); -// /** -// * Verifie si les 2 matrices sont egal -// */ -// public boolean equals(Object o); + // public String toString(); -// /** -// * Verifie si les dimensions sont valide pour cette matrice -// * @return vrai si dim a la même taille que le tableau de dimensions de la -// * matrice et si chaque valeur de dim est comprise entre 0 (inclus) et -// * la taille de la dimension (exclus). -// */ -// public boolean dimValid(int [] dim); + // /** + // * Verifie si les 2 matrices sont egal + // */ + // public boolean equals(Object o); + // /** + // * Verifie si les dimensions sont valide pour cette matrice + // * @return vrai si dim a la même taille que le tableau de dimensions de la + // * matrice et si chaque valeur de dim est comprise entre 0 (inclus) et + // * la taille de la dimension (exclus). + // */ + // public boolean dimValid(int [] dim); + /** * Somme toutes les valeurs de la matrice */ public double sumAll(); /** - * Somme la matrice sur une dimension donnée. La matrice résultat à le - * même nombre de dimension, pas la dimension sommer, ne contient qu'une - * ligne. - * <p> - * par exemple pour la matrice suivante si on somme sur la dimension 1 - * cela donnera - * <pre> - * 1 2 3 - * 2 3 4 - * 3 4 5 - * </pre> - * <pre> - * 6 9 12 - * </pre> - * @param dim la dimension sur lequel il faut faire la somme - */ + * Somme la matrice sur une dimension donnée. La matrice résultat à le même + * nombre de dimension, pas la dimension sommer, ne contient qu'une ligne. + * <p> + * par exemple pour la matrice suivante si on somme sur la dimension 1 cela + * donnera + * + * <pre> + * 1 2 3 + * 2 3 4 + * 3 4 5 + * </pre> + * + * <pre> + * 6 9 12 + * </pre> + * + * @param dim la dimension sur lequel il faut faire la somme + */ public MatrixND sumOverDim(int dim); /** - * Somme la matrice mais la matrice reste de la même dimension. - * la somme permet juste de regrouper dans une dimension un certain - * nombre de valeur. - * <p> - * pour la matrice suivant - * <pre> - * 1 2 3 4 - * 2 3 4 5 - * 3 4 5 6 - * 4 5 6 7 - * </pre> - * la somme sur la dimension 1 avec un pas de 2 donnera - * <pre> - * 4 6 8 10 - * 6 8 10 12 - * </pre> - * c'est à dire que la ligne 0 et la ligne 2 sont sommées. - * ainsi que la ligne 1 avec la ligne 3. - * @param dim la dimension sur lequel il faut faire les sommes - * @param step le pas qu'il faut utiliser pour regrouper les elements. - * Si le pas est inférieur à 0, le pas se comporte comme si on avait - * passé en argument la taille de la dimension. Un pas de 0 ou 1, retourne - * juste une copie de la matrice actuelle. - * si la division du pas avec la taille de la dimension ne donne pas un - * nombre entier, les elements restants ne sont pas pris en compte. Par - * exemple si la dimension a 10 élements et que l'on donne un pas de 3, - * dans la matrice resultat la dimension aura 3 elements qui seront la - * somme par 3 des 9 premiers element de la matrice courante. Le 10eme - * element sera perdu. - * @return une nouvelle matrice avec le meme nombre de dimension mais - * dont la dimension passé en paramètre aura comme taille, le resultat - * de la division entier de la taille actuelle par le step - */ + * Somme la matrice mais la matrice reste de la même dimension. la somme + * permet juste de regrouper dans une dimension un certain nombre de valeur. + * <p> + * pour la matrice suivant + * + * <pre> + * 1 2 3 4 + * 2 3 4 5 + * 3 4 5 6 + * 4 5 6 7 + * </pre> + * + * la somme sur la dimension 1 avec un pas de 2 donnera + * + * <pre> + * 4 6 8 10 + * 6 8 10 12 + * </pre> + * + * c'est à dire que la ligne 0 et la ligne 2 sont sommées. ainsi que la + * ligne 1 avec la ligne 3. + * + * @param dim la dimension sur lequel il faut faire les sommes + * @param step le pas qu'il faut utiliser pour regrouper les elements. Si le + * pas est inférieur à 0, le pas se comporte comme si on avait + * passé en argument la taille de la dimension. Un pas de 0 ou 1, + * retourne juste une copie de la matrice actuelle. si la + * division du pas avec la taille de la dimension ne donne pas un + * nombre entier, les elements restants ne sont pas pris en + * compte. Par exemple si la dimension a 10 élements et que l'on + * donne un pas de 3, dans la matrice resultat la dimension aura + * 3 elements qui seront la somme par 3 des 9 premiers element de + * la matrice courante. Le 10eme element sera perdu. + * @return une nouvelle matrice avec le meme nombre de dimension mais dont + * la dimension passé en paramètre aura comme taille, le resultat de + * la division entier de la taille actuelle par le step + */ public MatrixND sumOverDim(int dim, int step); - public MatrixND sumOverDim(int dim, int start, int nb ); + public MatrixND sumOverDim(int dim, int start, int nb); /** - * Permet de supprimer des éléments de la matrice. - * par exemple pour la matrice - * <pre> - * 1 2 3 4 - * 2 3 4 5 - * 3 4 5 6 - * 4 5 6 7 - * </pre> - * un cut(1, [0,2]) donnera - * <pre> - * 2 4 - * 3 5 - * 4 6 - * 5 7 - * </pre> - * @param dim la dimension dans lequel il faut supprimer des éléments - * @param toCut les éléments à supprimer - * @return une nouvelle matrice, la matrice actuelle n'est pas modifiée - */ + * Permet de supprimer des éléments de la matrice. par exemple pour la + * matrice + * + * <pre> + * 1 2 3 4 + * 2 3 4 5 + * 3 4 5 6 + * 4 5 6 7 + * </pre> + * + * un cut(1, [0,2]) donnera + * + * <pre> + * 2 4 + * 3 5 + * 4 6 + * 5 7 + * </pre> + * + * @param dim la dimension dans lequel il faut supprimer des éléments + * @param toCut les éléments à supprimer + * @return une nouvelle matrice, la matrice actuelle n'est pas modifiée + */ public MatrixND cut(int dim, int[] toCut); /** - * Copie une matrice dans la matrice actuelle. La matrice à copier à le - * même nombre de dimension. Si la matrice à copier est trop grande - * seul les éléments pouvant être copier le seront. - * @param mat la matrice à copier - * @return return la matrice courante. - */ + * Copie une matrice dans la matrice actuelle. La matrice à copier à le même + * nombre de dimension. Si la matrice à copier est trop grande seul les + * éléments pouvant être copier le seront. + * + * @param mat la matrice à copier + * @return return la matrice courante. + */ public MatrixND paste(MatrixND mat); /** - * Copie une matrice dans la matrice actuelle. La matrice à copier à le - * même nombre de dimension. Si la matrice à copier est trop grande - * seul les éléments pouvant être copier le seront. - * @param origin le point à partir duquel il faut faire la copie - * @param mat la matrice à copier - * @return return la matrice courante. - */ - public MatrixND paste(int [] origin, MatrixND mat); + * Copie une matrice dans la matrice actuelle. La matrice à copier à le même + * nombre de dimension. Si la matrice à copier est trop grande seul les + * éléments pouvant être copier le seront. + * + * @param origin le point à partir duquel il faut faire la copie + * @param mat la matrice à copier + * @return return la matrice courante. + */ + public MatrixND paste(int[] origin, MatrixND mat); /** * Modifie la matrice actuel en metant les valeurs de mat passé en parametre * La copie se fait en fonction de la semantique, si un element dans une - * dimension n'est pas trouvé, alors il est passé + * dimension n'est pas trouvé, alors il est passé */ public MatrixND pasteSemantics(MatrixND mat); - -// /** -// * Permet de prendre une sous matrice dans la matrice. -// * par exemple pour la matrice suivante -// * <pre> -// * 1 2 3 4 5 -// * 2 3 4 5 6 -// * 3 4 5 6 7 -// * 4 5 6 7 8 -// * 5 6 7 8 9 -// * </pre> -// * un getSubMatrix([1,2], [-1, -1], [2,-1]) donnera -// * <pre> -// * 4 5 -// * 5 6 -// * 6 7 -// * </pre> -// * @param origine point à partir duquel on souhaite extraire la matrice -// * toutes les valeurs de ce tableau doivent être renseigné par des nombres -// * positif et inferieur au maximum de chaque dimension respective -// * @param toExtract permet d'indiquer les dimensions que l'on souhaite -// * extraire. Les dimensions que l'on souhaite sont marqué par un -1. Si -// * une dimension n'a pas de -1 alors on ne prend qu'une ligne dans cette -// * dimension. Le nombre de -1 indique la taille de la matrice resultante -// * S'il y a 3 -1 dans le tableau, la matrice aura 3 dimensions -// * @param nbToExtract permet de limite le nombre d'élément à prendre dans -// * une dimension. Si le tableau contient -1 alors toutes les valeurs de -// * origin à la fin seront prise, si le tableau contient une valeur positive -// * alors seul le nombre indique sera pris à partir d'origin. Une valeur -// * différente de -1 n'a de sens que pour les dimensions qui ont une valeur -// * -1 dans le paramètre toExtract -// * @return une sous matrice de la matrice -// */ -// public MatrixND getSubMatrix(int [] origin, int [] toExtract, int [] nbToExtract); + // /** + // * Permet de prendre une sous matrice dans la matrice. + // * par exemple pour la matrice suivante + // * <pre> + // * 1 2 3 4 5 + // * 2 3 4 5 6 + // * 3 4 5 6 7 + // * 4 5 6 7 8 + // * 5 6 7 8 9 + // * </pre> + // * un getSubMatrix([1,2], [-1, -1], [2,-1]) donnera + // * <pre> + // * 4 5 + // * 5 6 + // * 6 7 + // * </pre> + // * @param origine point à partir duquel on souhaite extraire la matrice + // * toutes les valeurs de ce tableau doivent être renseigné par des nombres + // * positif et inferieur au maximum de chaque dimension respective + // * @param toExtract permet d'indiquer les dimensions que l'on souhaite + // * extraire. Les dimensions que l'on souhaite sont marqué par un -1. Si + // * une dimension n'a pas de -1 alors on ne prend qu'une ligne dans cette + // * dimension. Le nombre de -1 indique la taille de la matrice resultante + // * S'il y a 3 -1 dans le tableau, la matrice aura 3 dimensions + // * @param nbToExtract permet de limite le nombre d'élément à prendre dans + // * une dimension. Si le tableau contient -1 alors toutes les valeurs de + // * origin à la fin seront prise, si le tableau contient une valeur + // positive + // * alors seul le nombre indique sera pris à partir d'origin. Une valeur + // * différente de -1 n'a de sens que pour les dimensions qui ont une valeur + // * -1 dans le paramètre toExtract + // * @return une sous matrice de la matrice + // */ + // public MatrixND getSubMatrix(int [] origin, int [] toExtract, int [] + // nbToExtract); /** - * Permet de prendre une sous matrice dans la matrice courante. La sous - * matrice a le même nombre de dimensions mais sur une des dimensions - * on ne prend que certain élément. - * @param dim la dimension dans lequel on veut une sous matrice - * si dim est négatif alors la dimension est prise à partir de la fin - * par exemple si l'on veut la derniere dimension il faut passer -1 pour - * dim - * @param start la position dans dim d'ou il faut partir pour prendre - * la sous matrice. - * @param nb le nombre d'élément à prendre dans la dimension. si nb est - * inférieur ou égal à 0 alors cela indique qu'il faut prendre tous les - * éléments jusqu'à la fin de la dimension. - */ + * Permet de prendre une sous matrice dans la matrice courante. La sous + * matrice a le même nombre de dimensions mais sur une des dimensions on ne + * prend que certain élément. + * + * @param dim la dimension dans lequel on veut une sous matrice si dim est + * négatif alors la dimension est prise à partir de la fin par + * exemple si l'on veut la derniere dimension il faut passer -1 + * pour dim + * @param start la position dans dim d'ou il faut partir pour prendre la + * sous matrice. + * @param nb le nombre d'élément à prendre dans la dimension. si nb est + * inférieur ou égal à 0 alors cela indique qu'il faut prendre + * tous les éléments jusqu'à la fin de la dimension. + */ public MatrixND getSubMatrix(int dim, Object start, int nb); /** - * Permet de prendre une sous matrice dans la matrice courante. La sous - * matrice a le même nombre de dimensions mais sur une des dimensions - * on ne prend que certain élément. - * @param dim la dimension dans lequel on veut une sous matrice - * @param start la position dans dim d'ou il faut partir pour prendre - * la sous matrice. 0 <= start < dim.size - * si start est négatif alors la position de départ est calculé par rapport - * à la fin de la dimension, pour avoir le dernier élément il faut passer - * -1 - * @param nb le nombre d'élément à prendre dans la dimension si nb est - * inférieur ou égal à 0 alors cela indique qu'il faut prendre tous les - * éléments jusqu'à la fin de la dimension. - */ + * Permet de prendre une sous matrice dans la matrice courante. La sous + * matrice a le même nombre de dimensions mais sur une des dimensions on ne + * prend que certain élément. + * + * @param dim la dimension dans lequel on veut une sous matrice + * @param start la position dans dim d'ou il faut partir pour prendre la + * sous matrice. 0 <= start < dim.size si start est négatif alors + * la position de départ est calculé par rapport à la fin de la + * dimension, pour avoir le dernier élément il faut passer -1 + * @param nb le nombre d'élément à prendre dans la dimension si nb est + * inférieur ou égal à 0 alors cela indique qu'il faut prendre + * tous les éléments jusqu'à la fin de la dimension. + */ public MatrixND getSubMatrix(int dim, int start, int nb); /** - * Permet de prendre une sous matrice dans la matrice courante. La sous - * matrice a le même nombre de dimensions mais sur une des dimensions - * on ne prend que certain élément. - * @param dim la dimension dans lequel on veut une sous matrice - * @param elem les éléments dans la dimension à conserver - */ - public MatrixND getSubMatrix(int dim, Object ... elem); + * Permet de prendre une sous matrice dans la matrice courante. La sous + * matrice a le même nombre de dimensions mais sur une des dimensions on ne + * prend que certain élément. + * + * @param dim la dimension dans lequel on veut une sous matrice + * @param elem les éléments dans la dimension à conserver + */ + public MatrixND getSubMatrix(int dim, Object... elem); /** - * Permet de prendre une sous matrice dans la matrice courante. La sous - * matrice a le même nombre de dimensions mais sur une des dimensions - * on ne prend que certain élément. - * @param dim la dimension dans lequel on veut une sous matrice - * @param elem les éléments dans la dimension à conserver - */ - public MatrixND getSubMatrix(int dim, int [] elem); + * Permet de prendre une sous matrice dans la matrice courante. La sous + * matrice a le même nombre de dimensions mais sur une des dimensions on ne + * prend que certain élément. + * + * @param dim la dimension dans lequel on veut une sous matrice + * @param elem les éléments dans la dimension à conserver + */ + public MatrixND getSubMatrix(int dim, int[] elem); - /** - * Addition la matrice courante avec la matrice passe en parametre et - * ce retourne elle meme - */ + * Addition la matrice courante avec la matrice passe en parametre et ce + * retourne elle meme + */ public MatrixND add(MatrixND m); + /** - * Soustrai la matrice courante avec la matrice passe en parametre et - * ce retourne elle meme - */ + * Soustrai la matrice courante avec la matrice passe en parametre et ce + * retourne elle meme + */ public MatrixND minus(MatrixND m); /** - * retourne le transpose de la matrice - */ + * retourne le transpose de la matrice + */ public MatrixND transpose(); /** - * Reduit la matrice de sorte que toutes les dimensions qui n'ont qu'un - * élement soit supprimée. Au pire cette méthode retourne une matrice - * à une seule dimension à un seul élément. - * @return une nouvelle matrice plus petite que la matrice actuelle - * ou egal s'il n'y a aucune dimension à supprimer - */ + * Reduit la matrice de sorte que toutes les dimensions qui n'ont qu'un + * élement soit supprimée. Au pire cette méthode retourne une matrice à une + * seule dimension à un seul élément. + * + * @return une nouvelle matrice plus petite que la matrice actuelle ou egal + * s'il n'y a aucune dimension à supprimer + */ public MatrixND reduce(); /** - * Reduit la matrice de sorte que toutes les dimensions qui n'ont qu'un - * élement soit supprimée. Au pire cette méthode retourne une matrice - * à une seule dimension à un seul élément. - * @param minNbDim le nombre minimum de dimension que l'on souhaite pour - * la matrice résultat - * @return une nouvelle matrice plus petite que la matrice actuelle - * ou egal s'il n'y a aucune dimension à supprimer - */ + * Reduit la matrice de sorte que toutes les dimensions qui n'ont qu'un + * élement soit supprimée. Au pire cette méthode retourne une matrice à une + * seule dimension à un seul élément. + * + * @param minNbDim le nombre minimum de dimension que l'on souhaite pour la + * matrice résultat + * @return une nouvelle matrice plus petite que la matrice actuelle ou egal + * s'il n'y a aucune dimension à supprimer + */ public MatrixND reduce(int minNbDim); /** * Reduit le matrice seulement sur les dimensions passées en argument. Si * une des dimensions passées en arguement n'a pas un seul élément, cette * dimension n'est pas prise en compte. + * * @param dims les dimensions sur lequel il faut faire la reduction * @return une nouvelle matrice */ - public MatrixND reduceDims(int ... dims); + public MatrixND reduceDims(int... dims); /** - * Multiplication normal de 2 matrices 2D. Retourne une nouvelle matrice - */ + * Multiplication normal de 2 matrices 2D. Retourne une nouvelle matrice + */ public MatrixND mult(MatrixND m); -// /** -// * multiplication terme a terme de la matrice courante avec la -// * matrice passe en parametre et ce retourne elle meme -// */ -// public MatrixND multm(MatrixND m); + // /** + // * multiplication terme a terme de la matrice courante avec la + // * matrice passe en parametre et ce retourne elle meme + // */ + // public MatrixND multm(MatrixND m); /** - * Multiplication d'une matrice par un scalaire - */ + * Multiplication d'une matrice par un scalaire + */ public MatrixND mults(final double d); + /** - * Multiplication d'une matrice par un scalaire - */ + * Multiplication d'une matrice par un scalaire + */ public MatrixND divs(final double d); - + /** * Donne la matrice sous forme de List de list ... de double + * * @return */ public List toList(); - + /** * Permet de charger une matrice a partir d'une representation List + * * @param list la matrice sous forme de List de list ... de double */ public void fromList(List list); - + /** * Determine si la matrice supporte l'import et l'export CSV + * * @return support du CSV */ public boolean isSupportedCSV(); - + /** * Import depuis un reader au format CSV des données dans la matrice + * * @param reader le reader à importer * @param origin le point à partir duquel il faut faire l'importation */ @@ -530,41 +573,47 @@ /** * Export dans un writer au format CSV de la matrice + * * @param writer le writer ou copier la matrice - * @param withSemantics export ou pas des semantiques de la matrice dans le writer + * @param withSemantics export ou pas des semantiques de la matrice dans le + * writer */ - public void exportCSV(Writer writer, boolean withSemantics) throws IOException; - - /** - * Verifie si les matrices sont egales en ne regardant que les valeurs - * et pas les semantiques + public void exportCSV(Writer writer, boolean withSemantics) + throws IOException; + + /** + * Verifie si les matrices sont egales en ne regardant que les valeurs et + * pas les semantiques * * @param mat * @return */ public boolean equalsValues(MatrixND mat); -// /** -// * Multiplication d'une vecteur [i] avec une matrice [i,j], -// * le resultat est result[i,j]=matrice[i,j]*vecteur[i] -// */ -// public MatrixND multv(MatrixND v); -// /** -// * Multiplication d'une vecteur [i] avec une matrice [g,h,i,j,k,..], -// * le resultat est result[g,h,i,j,k,..]=matrice[g,h,i,j,k,l,...]*vecteur[i] -// * @param v le vecteur -// * @param dim la position de la dimension avec lequel il faut multiplier -// * le vecteur. -// */ -// public MatrixND multv(MatrixND v, int dim); -// /** -// * Addition d'un vecteur [i] avec une matrice [g,h,i,j,k,..], -// * le resultat est result[g,h,i,j,k,..]=matrice[g,h,i,j,k,l,...]+vecteur[i] -// * @param v le vecteur -// * @param dim la dimension ou on doit mettre le vecteur doit etre egal a -1 -// * [0, -1, 3 ] ajoutera le vecteur dans la dimension 2 -// */ -// public MatrixND addv(MatrixND v, int [] dim); + // /** + // * Multiplication d'une vecteur [i] avec une matrice [i,j], + // * le resultat est result[i,j]=matrice[i,j]*vecteur[i] + // */ + // public MatrixND multv(MatrixND v); + // /** + // * Multiplication d'une vecteur [i] avec une matrice [g,h,i,j,k,..], + // * le resultat est + // result[g,h,i,j,k,..]=matrice[g,h,i,j,k,l,...]*vecteur[i] + // * @param v le vecteur + // * @param dim la position de la dimension avec lequel il faut multiplier + // * le vecteur. + // */ + // public MatrixND multv(MatrixND v, int dim); + // /** + // * Addition d'un vecteur [i] avec une matrice [g,h,i,j,k,..], + // * le resultat est + // result[g,h,i,j,k,..]=matrice[g,h,i,j,k,l,...]+vecteur[i] + // * @param v le vecteur + // * @param dim la dimension ou on doit mettre le vecteur doit etre egal a + // -1 + // * [0, -1, 3 ] ajoutera le vecteur dans la dimension 2 + // */ + // public MatrixND addv(MatrixND v, int [] dim); } // MatrixND Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixNDImpl.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixNDImpl.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixNDImpl.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,33 +1,31 @@ -/* *##% -* Copyright (C) 2002, 2003, 2004 Code Lutin, Cédric Pineau, -* Benjamin Poussin -* -* 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 2 -* 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, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*##%*/ +/* *##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * -* MatrixNDImpl.java -* -* Created: 29 oct. 2004 -* -* @author Benjamin Poussin <poussin@codelutin.com> -* @version $Revision$ -* -* Mise a jour: $Date$ -* par : $Author$ -*/ + * MatrixNDImpl.java + * + * Created: 29 oct. 2004 + * + * @author Benjamin Poussin <poussin@codelutin.com> + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ package org.codelutin.math.matrix; @@ -38,69 +36,75 @@ /** */ private static final long serialVersionUID = 1L; - + protected BasicMatrix matrix = null; - protected MatrixNDImpl(MatrixFactory factory, int [] dim){ + protected MatrixNDImpl(MatrixFactory factory, int[] dim) { super(factory, dim); matrix = new BasicMatrix(factory, dim); } - protected MatrixNDImpl(MatrixFactory factory, List[] semantics){ + + protected MatrixNDImpl(MatrixFactory factory, List[] semantics) { super(factory, semantics); matrix = new BasicMatrix(factory, dim); } - protected MatrixNDImpl(MatrixFactory factory, String name, int [] dim){ + protected MatrixNDImpl(MatrixFactory factory, String name, int[] dim) { super(factory, name, dim); matrix = new BasicMatrix(factory, dim); } - protected MatrixNDImpl(MatrixFactory factory, String name, int [] dim, String [] dimNames){ + protected MatrixNDImpl(MatrixFactory factory, String name, int[] dim, + String[] dimNames) { super(factory, name, dim, dimNames); matrix = new BasicMatrix(factory, dim); } - protected MatrixNDImpl(MatrixFactory factory, String name, List[] semantics){ + protected MatrixNDImpl(MatrixFactory factory, String name, List[] semantics) { super(factory, name, semantics); matrix = new BasicMatrix(factory, dim); } - protected MatrixNDImpl(MatrixFactory factory, String name, List[] semantics, String [] dimNames){ + protected MatrixNDImpl(MatrixFactory factory, String name, + List[] semantics, String[] dimNames) { super(factory, name, semantics, dimNames); matrix = new BasicMatrix(factory, dim); } - protected MatrixNDImpl(MatrixFactory factory, MatrixND matrix){ - super(factory, matrix.getName(), matrix.getSemantics(), matrix.getDimensionName()); + protected MatrixNDImpl(MatrixFactory factory, MatrixND matrix) { + super(factory, matrix.getName(), matrix.getSemantics(), matrix + .getDimensionName()); this.matrix = new BasicMatrix(factory, dim); this.paste(matrix); } - public MatrixIterator iterator(){ + public MatrixIterator iterator() { return new MatrixIteratorImpl(matrix.iterator(), getSemantics()); } - public double getValue(int [] coordinates){ + + public double getValue(int[] coordinates) { return matrix.getValue(coordinates); } - public void setValue(int [] coordinates, double d){ + + public void setValue(int[] coordinates, double d) { matrix.setValue(coordinates, d); } - public double getMaxOccurence(){ + public double getMaxOccurence() { return matrix.getMaxOccurence(); } - public String toString(){ + public String toString() { return getName() + " " + matrix.toString(); } // Un peu d'optimisation pour les matrices entieres (pas de sub matrix) /** - * Si le vector utilise par la BasicMatix supporte la method map, - * on l'utilise pour gagner du temps - */ + * Si le vector utilise par la BasicMatix supporte la method map, on + * l'utilise pour gagner du temps + */ @Override - public MatrixND map(MapFunction f){ + public MatrixND map(MapFunction f) { if (matrix.data.isImplementedMap()) { matrix.data.map(f); } else { @@ -110,29 +114,31 @@ } /** - * Si on peut on utilise le paste du vector de BasicMatix, sinon - * on utilise la methode de AbstractMatrixND. - */ - public MatrixND paste(int [] origin, MatrixND mat){ + * Si on peut on utilise le paste du vector de BasicMatix, sinon on utilise + * la methode de AbstractMatrixND. + */ + public MatrixND paste(int[] origin, MatrixND mat) { // permet de savoir si l'origin est bien le point 0 de la matrice boolean origin0 = true; - for (int i=0; i<origin.length && origin0; i++) { + for (int i = 0; i < origin.length && origin0; i++) { origin0 = origin0 && origin[i] == 0; } - if (origin0 && mat instanceof MatrixNDImpl && - Arrays.equals(mat.getDim(), this.getDim()) && - matrix.data.isImplementedPaste(((MatrixNDImpl)mat).matrix.data)){ - matrix.data.paste(((MatrixNDImpl)mat).matrix.data); + if (origin0 + && mat instanceof MatrixNDImpl + && Arrays.equals(mat.getDim(), this.getDim()) + && matrix.data + .isImplementedPaste(((MatrixNDImpl) mat).matrix.data)) { + matrix.data.paste(((MatrixNDImpl) mat).matrix.data); } else { super.paste(origin, mat); } return this; } - public MatrixND add(MatrixND m){ - if (m instanceof MatrixNDImpl && - matrix.data.isImplementedAdd(((MatrixNDImpl)m).matrix.data)){ - matrix.data.add(((MatrixNDImpl)m).matrix.data); + public MatrixND add(MatrixND m) { + if (m instanceof MatrixNDImpl + && matrix.data.isImplementedAdd(((MatrixNDImpl) m).matrix.data)) { + matrix.data.add(((MatrixNDImpl) m).matrix.data); } else { super.add(m); } @@ -140,15 +146,16 @@ } /** - * Modifie la matrice actuelle en lui soustrayant les valeurs de la matrice - * passé en parametre. La matrice passé en parametre doit avoir le meme - * nombre de dimension, et chacune de ses dimensions doit avoir un nombre - * d'element au moins egal a cette matrice. - */ - public MatrixND minus(MatrixND m){ - if (m instanceof MatrixNDImpl && - matrix.data.isImplementedMinus(((MatrixNDImpl)m).matrix.data)){ - matrix.data.minus(((MatrixNDImpl)m).matrix.data); + * Modifie la matrice actuelle en lui soustrayant les valeurs de la matrice + * passé en parametre. La matrice passé en parametre doit avoir le meme + * nombre de dimension, et chacune de ses dimensions doit avoir un nombre + * d'element au moins egal a cette matrice. + */ + public MatrixND minus(MatrixND m) { + if (m instanceof MatrixNDImpl + && matrix.data + .isImplementedMinus(((MatrixNDImpl) m).matrix.data)) { + matrix.data.minus(((MatrixNDImpl) m).matrix.data); } else { super.minus(m); } Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SemanticList.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SemanticList.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SemanticList.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,21 +1,19 @@ -/* *##% - * Copyright (C) 2006 - * Code Lutin, Cédric Pineau, Benjamin Poussin +/* *##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin * - * 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 2 - * of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Lesser Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * * SemanticList.java @@ -38,22 +36,21 @@ import java.util.Map; import java.util.RandomAccess; - /** * @author poussin - * */ - public class SemanticList<T> extends AbstractList<T> implements RandomAccess { protected ArrayList<T> datas = null; - protected Map<Object, Integer> index = null; - + protected Map<Object, Integer> index = null; + public SemanticList(Collection<T> c) { datas = new ArrayList<T>(c); } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see java.util.AbstractList#get(int) */ @Override @@ -62,7 +59,9 @@ return result; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see java.util.AbstractCollection#size() */ @Override @@ -71,16 +70,18 @@ return result; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see java.util.AbstractList#indexOf(java.lang.Object) */ @Override public int indexOf(Object o) { Map index = getIndex(); - Integer result = (Integer)index.get(o); + Integer result = (Integer) index.get(o); if (result == null) { return -1; - } else { + } else { return result.intValue(); } } @@ -91,12 +92,10 @@ private Map getIndex() { if (index == null) { index = new HashMap<Object, Integer>(); - for (int i=0; i<datas.size(); i++) { + for (int i = 0; i < datas.size(); i++) { index.put(datas.get(i), Integer.valueOf(i)); } } return index; } } - - Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SubMatrix.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SubMatrix.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SubMatrix.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,21 +1,19 @@ -/* *##% - * Copyright (C) 2002, 2003, 2004 Code Lutin, Cédric Pineau, - * Benjamin Poussin +/*##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin * - * 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 2 - * of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Lesser Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * * SubMatrix.java @@ -38,20 +36,21 @@ import java.util.NoSuchElementException; /** -* Pour l'instant une sous matrice a obligatoirement le meme nombre -* de dimension que la matrice qu'elle contient. -* Elle permet juste de reduire le nombre d'element d'une dimension. -*/ + * Pour l'instant une sous matrice a obligatoirement le meme nombre de dimension + * que la matrice qu'elle contient. Elle permet juste de reduire le nombre + * d'element d'une dimension. + */ public class SubMatrix extends AbstractMatrixND { // SubMatrix /** */ private static final long serialVersionUID = 1L; - + protected MatrixND matrix = null; protected DimensionConverter converter = null; - public SubMatrix(MatrixND matrix, int dim, int start, int nb){ - super(matrix.getFactory(), matrix.getName(), matrix.getSemantics(), matrix.getDimensionName()); + public SubMatrix(MatrixND matrix, int dim, int start, int nb) { + super(matrix.getFactory(), matrix.getName(), matrix.getSemantics(), + matrix.getDimensionName()); this.matrix = matrix; converter = new ShiftConverter(dim, start, nb); @@ -59,60 +58,61 @@ getDim()[dim] = nb; } - public SubMatrix(MatrixND matrix, int dim, int [] elem){ - super(matrix.getFactory(), matrix.getName(), matrix.getSemantics(), matrix.getDimensionName()); + public SubMatrix(MatrixND matrix, int dim, int[] elem) { + super(matrix.getFactory(), matrix.getName(), matrix.getSemantics(), + matrix.getDimensionName()); this.matrix = matrix; converter = new MappingConverter(dim, elem); List oldSemantic = getSemantics(dim); List newSemantic = new LinkedList(); - for(int i=0; i<elem.length; i++){ + for (int i = 0; i < elem.length; i++) { newSemantic.add(oldSemantic.get(elem[i])); } setSemantics(dim, newSemantic); getDim()[dim] = elem.length; } - public MatrixIterator iterator(){ + public MatrixIterator iterator() { return new SubMatrixIteratorImpl(this); } - public double getValue(int [] coordinates){ + public double getValue(int[] coordinates) { return matrix.getValue(converter.convertCoordinates(coordinates)); } - public void setValue(int [] coordinates, double d){ + public void setValue(int[] coordinates, double d) { matrix.setValue(converter.convertCoordinates(coordinates), d); } protected class SubMatrixIteratorImpl implements MatrixIterator { protected SubMatrix subMatrix = null; - protected int [] cpt = null; - protected int [] last = null; + protected int[] cpt = null; + protected int[] last = null; - public SubMatrixIteratorImpl(SubMatrix subMatrix){ + public SubMatrixIteratorImpl(SubMatrix subMatrix) { this.subMatrix = subMatrix; cpt = new int[subMatrix.getNbDim()]; - cpt[cpt.length-1] = -1; + cpt[cpt.length - 1] = -1; last = new int[subMatrix.getNbDim()]; - for(int i=0; i<last.length; i++){ + for (int i = 0; i < last.length; i++) { last[i] = subMatrix.getDim(i) - 1; } } - public boolean hasNext(){ + public boolean hasNext() { return !Arrays.equals(cpt, last); } - public boolean next(){ + public boolean next() { boolean result = hasNext(); int ret = 1; - int [] dim = getDim(); - for(int i=cpt.length-1; i>=0; i--){ + int[] dim = getDim(); + for (int i = cpt.length - 1; i >= 0; i--) { cpt[i] = cpt[i] + ret; ret = cpt[i] / dim[i]; cpt[i] = cpt[i] % dim[i]; @@ -120,84 +120,90 @@ return result; } - public int [] getCoordinates(){ + public int[] getCoordinates() { return cpt; } - public Object [] getSemanticsCoordinates(){ - int [] coordinates = getCoordinates(); - Object [] result = MatrixHelper.dimensionToSemantics(subMatrix.getSemantics(), coordinates); + public Object[] getSemanticsCoordinates() { + int[] coordinates = getCoordinates(); + Object[] result = MatrixHelper.dimensionToSemantics(subMatrix + .getSemantics(), coordinates); return result; } - public double getValue(){ + public double getValue() { return subMatrix.getValue(getCoordinates()); } - public void setValue(double value){ + public void setValue(double value) { subMatrix.setValue(getCoordinates(), value); } } - /** - * Permet de faire une conversion de la dimension demandé dans la sous - * matrice avec la position reel de la matrice sous jacente. - */ + * Permet de faire une conversion de la dimension demandé dans la sous + * matrice avec la position reel de la matrice sous jacente. + */ protected interface DimensionConverter extends Serializable { - public int [] convertCoordinates(int [] coordinates); + public int[] convertCoordinates(int[] coordinates); } /** - * La conversion est juste un decalage d'indice - */ + * La conversion est juste un decalage d'indice + */ protected class ShiftConverter implements DimensionConverter { /** */ private static final long serialVersionUID = 1L; - + protected int dim; protected int start; protected int nb; - public ShiftConverter(int dim, int start, int nb){ + + public ShiftConverter(int dim, int start, int nb) { this.dim = dim; this.start = start; this.nb = nb; } - public int [] convertCoordinates(int [] coordinates){ - if(coordinates[dim] < nb){ - int [] result = new int[coordinates.length]; + + public int[] convertCoordinates(int[] coordinates) { + if (coordinates[dim] < nb) { + int[] result = new int[coordinates.length]; System.arraycopy(coordinates, 0, result, 0, result.length); result[dim] = result[dim] + start; return result; - }else{ - throw new NoSuchElementException("L'indice est supérieur au nombre d'élement de la sous matrice pour cette dimension."); + } else { + throw new NoSuchElementException( + "L'indice est supérieur au nombre d'élement de la sous matrice pour cette dimension."); } } } /** - * La conversion est le mapping d'un element vers un autre element - */ + * La conversion est le mapping d'un element vers un autre element + */ protected class MappingConverter implements DimensionConverter { /** */ private static final long serialVersionUID = 1L; - + protected int dim; - protected int [] elem = null; - public MappingConverter(int dim, int [] elem){ + protected int[] elem = null; + + public MappingConverter(int dim, int[] elem) { this.dim = dim; this.elem = new int[elem.length]; System.arraycopy(elem, 0, this.elem, 0, elem.length); } - public int [] convertCoordinates(int [] coordinates){ - if(coordinates[dim] < elem.length){ - int [] result = new int[coordinates.length]; + + public int[] convertCoordinates(int[] coordinates) { + if (coordinates[dim] < elem.length) { + int[] result = new int[coordinates.length]; System.arraycopy(coordinates, 0, result, 0, result.length); result[dim] = elem[coordinates[dim]]; return result; - }else{ - throw new NoSuchElementException("L'indice est supérieur au nombre d'élement de la sous matrice pour cette dimension."); + } else { + throw new NoSuchElementException( + "L'indice est supérieur au nombre d'élement de la sous matrice pour cette dimension."); } } } Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/Vector.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/Vector.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/Vector.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,21 +1,19 @@ -/* *##% - * Copyright (C) 2005 - * Code Lutin, Cédric Pineau, Benjamin Poussin +/* *##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin * - * 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 2 - * of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Lesser Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * * Vector.java @@ -34,42 +32,51 @@ public interface Vector { // Vector public double getMaxOccurence(); + public double getValue(int pos); + public void setValue(int pos, double value); + public int size(); /** - * Permet de savoir si paste est implanté par ce vector - */ + * Permet de savoir si paste est implanté par ce vector + */ public boolean isImplementedPaste(Vector v); + /** - * Permet de savoir si add est implanté par ce vector - */ + * Permet de savoir si add est implanté par ce vector + */ public boolean isImplementedAdd(Vector v); + /** - * Permet de savoir si minus est implanté par ce vector - */ + * Permet de savoir si minus est implanté par ce vector + */ public boolean isImplementedMinus(Vector v); + /** - * Permet de savoir si map est implanté par ce vector - */ + * Permet de savoir si map est implanté par ce vector + */ public boolean isImplementedMap(); /** - * Copie les valeurs du vector passé en argument dans ce vector - */ + * Copie les valeurs du vector passé en argument dans ce vector + */ public void paste(Vector v); + /** - * Ajoute les valeurs du vector passé en argument a ce vector - */ + * Ajoute les valeurs du vector passé en argument a ce vector + */ public void add(Vector v); + /** - * soustrai les valeurs du vector passé en argument a ce vector - */ + * soustrai les valeurs du vector passé en argument a ce vector + */ public void minus(Vector v); + /** - * applique a chaque valeur du vector la MapFunction - */ + * applique a chaque valeur du vector la MapFunction + */ public void map(MapFunction f); } // Vector Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEditor.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEditor.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEditor.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,34 +1,21 @@ /* - * *##% Copyright (C) 2002, 2003, 2004 Code Lutin, Cédric Pineau, Benjamin - * Poussin - * - * 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 2 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, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307, USA. ##% - */ + * *##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/******************************************************************************* - * MatrixPanelEditor.java - * - * Created: 4 nov. 2004 - * - * @author Benjamin Poussin <poussin@codelutin.com> - * - * @version $Revision$ - * - * Mise a jour: $Date$ par : $Author$ - */ - package org.codelutin.math.matrix.gui; import java.awt.BorderLayout; @@ -65,9 +52,9 @@ * JPanel contenant une JTable pour afficher une Matrice a une ou deux * dimension. * - * TODO: Une methode permettant de retourne la sous matrice de la selection - * que la matrice soit reprensentée en lineaire ou non. (avoir un mapping - * cellule de table vers element de matrice + * TODO: Une methode permettant de retourne la sous matrice de la selection que + * la matrice soit reprensentée en lineaire ou non. (avoir un mapping cellule de + * table vers element de matrice */ public class MatrixPanelEditor extends JPanel implements TableModelListener { // MatrixPanelEditor @@ -79,7 +66,7 @@ private final static int DEFAULT_HEIGHT = 150; protected ListenerSet listeners = new ListenerSet(); - + protected JTable table; protected MatrixND m; @@ -89,8 +76,8 @@ protected JScrollPane editArea; protected MatrixPopupMenu popupMenu; -// protected JTextArea text; - + // protected JTextArea text; + /** if true, use linear representation of matrix */ protected boolean linearModel = false; /** if false don't show default value in matrix (ex: 0) */ @@ -145,15 +132,15 @@ protected MatrixFactory getFactory() { return MatrixFactory.getInstance(); } - + public void addMatrixListener(MatrixPanelListener l) { listeners.add(l); } - + public void removeMatrixPanelListener(MatrixPanelListener l) { listeners.remove(l); } - + protected void initObjet() { setLayout(new BorderLayout()); editArea = new JScrollPane(); @@ -170,9 +157,10 @@ public void actionPerformed(ActionEvent e) { String dim; - dim = JOptionPane.showInputDialog(null, - I18n._("lutinmatrix.create.matrix.message"), - I18n._("lutinmatrix.create.matrix.title"), JOptionPane.DEFAULT_OPTION); + dim = JOptionPane.showInputDialog(null, I18n + ._("lutinmatrix.create.matrix.message"), I18n + ._("lutinmatrix.create.matrix.title"), + JOptionPane.DEFAULT_OPTION); if (dim != null) { String[] sdim = dim.split(";"); @@ -189,14 +177,13 @@ return bEdit; } - /** * @return Returns the linearModel. */ public boolean isLinearModel() { return this.linearModel; } - + /** * @param linearModel The linearModel to set. */ @@ -204,14 +191,14 @@ this.linearModel = linearModel; initObject(m); } - + /** * @return Returns the linearModelShowDefault. */ public boolean isLinearModelShowDefault() { return this.linearModelShowDefault; } - + /** * @param linearModelShowDefault The linearModelShowDefault to set. */ @@ -219,7 +206,7 @@ this.linearModelShowDefault = linearModelShowDefault; initObject(m); } - + /** * Get the value of dimensionEdit. * @@ -250,31 +237,33 @@ // pour les matrices 1D et 2D JTable table = getTable(); if (isLinearModel()) { - tableModel = new MatrixTableModelLinear(m, isLinearModelShowDefault()); + tableModel = new MatrixTableModelLinear(m, + isLinearModelShowDefault()); } else { tableModel = new MatrixTableModelND(m); - } + } table.getModel().removeTableModelListener(this); tableModel.addTableModelListener(this); table.setModel(tableModel); - table.setDefaultRenderer(String.class, tableModel.getMatrixCellRenderer()); + table.setDefaultRenderer(String.class, tableModel + .getMatrixCellRenderer()); editArea.setViewportView(table); // next line is needed otherwize matrix doesn't appear add(editArea, BorderLayout.CENTER); -// if (table.getColumnCount() > 0 && m.getNbDim() > 1) { -// table.getColumnModel().getColumn(0).setCellRenderer( -// tableModel.getMatrixCellRenderer()); -// } -// text = null; + // if (table.getColumnCount() > 0 && m.getNbDim() > 1) { + // table.getColumnModel().getColumn(0).setCellRenderer( + // tableModel.getMatrixCellRenderer()); + // } + // text = null; } -// else { -// // pour les matrices 3D et plus -// text = new JTextArea(); -// editArea.setViewportView(text); -// text.setText(MatrixHelper.encodeToXML(m)); -// table = null; -// editArea.setColumnHeaderView(null); -// } + // else { + // // pour les matrices 3D et plus + // text = new JTextArea(); + // editArea.setViewportView(text); + // text.setText(MatrixHelper.encodeToXML(m)); + // table = null; + // editArea.setColumnHeaderView(null); + // } setEnabled(enabled); repaint(); } @@ -282,61 +271,71 @@ public JTable getTable() { if (table == null) { popupMenu = new MatrixPopupMenu(this); - table = new JTable(){ + table = new JTable() { public void processMouseEvent(MouseEvent event) { - if(event.isPopupTrigger()) { - popupMenu.show(event.getComponent(), - event.getX(), event.getY()); + if (event.isPopupTrigger()) { + popupMenu.show(event.getComponent(), event.getX(), + event.getY()); } super.processMouseEvent(event); } }; - - table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_C, Event.CTRL_MASK), "copy"); - table.getActionMap().put("copy", popupMenu.getSendToClipBoardSelectionCopyAction()); - - table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_V, Event.CTRL_MASK), "paste"); - table.getActionMap().put("paste", popupMenu.getSendToClipBoardCurrentPasteAction()); - /*table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_A, Event.CTRL_MASK), "selectAll"); - table.getActionMap().put("selectAll", new AbstractAction(){ - public void actionPerformed(ActionEvent e) { - table.selectAll(); - }});*/ + table.getInputMap().put( + KeyStroke.getKeyStroke(KeyEvent.VK_C, Event.CTRL_MASK), + "copy"); + table.getActionMap().put("copy", + popupMenu.getSendToClipBoardSelectionCopyAction()); + table.getInputMap().put( + KeyStroke.getKeyStroke(KeyEvent.VK_V, Event.CTRL_MASK), + "paste"); + table.getActionMap().put("paste", + popupMenu.getSendToClipBoardCurrentPasteAction()); + + /* + * table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_A, + * Event.CTRL_MASK), "selectAll"); + * table.getActionMap().put("selectAll", new AbstractAction(){ + * public void actionPerformed(ActionEvent e) { table.selectAll(); + * }}); + */ + table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); - table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); + table + .setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); table.setCellSelectionEnabled(true); - + } return table; } - + public void setMatrix(MatrixND m) throws MatrixException { initObject(m); this.m = m; fireEvent(); } - + /** - * @deprecated use setMatrix - */ + * @deprecated use setMatrix + */ public void setMatrice(MatrixND m) throws MatrixException { setMatrix(m); } public MatrixND getMatrix() { -// if (m == null) { - return m; -// } else if (m.getNbDim() <= 2) { -// return m; -// } else { -// return MatrixHelper.decodeFromXML(text.getText()); -// } + // if (m == null) { + return m; + // } else if (m.getNbDim() <= 2) { + // return m; + // } else { + // return MatrixHelper.decodeFromXML(text.getText()); + // } } + /** - * @deprecated use setMatrix - */ + * @deprecated use setMatrix + */ public MatrixND getMatrice() { return getMatrix(); } @@ -348,9 +347,9 @@ if (tableModel != null) { tableModel.setEnabled(enabled); } -// if (text != null) { -// text.setEditable(enabled); -// } + // if (text != null) { + // text.setEditable(enabled); + // } // si la table n'est pas editable, inutile de laisser le bouton // de creation de matrice. if (!enabled && dimensionEdit) { @@ -367,31 +366,34 @@ return enabled; } - /* (non-Javadoc) - * @see javax.swing.event.TableModelListener#tableChanged(javax.swing.event.TableModelEvent) + /* + * (non-Javadoc) + * + * @seejavax.swing.event.TableModelListener#tableChanged(javax.swing.event. + * TableModelEvent) */ public void tableChanged(TableModelEvent e) { fireEvent(); } - + protected void fireEvent() { MatrixPanelEvent e = new MatrixPanelEvent(this); - for(Iterator i=listeners.iterator(); i.hasNext();) { - MatrixPanelListener l = (MatrixPanelListener)i.next(); + for (Iterator i = listeners.iterator(); i.hasNext();) { + MatrixPanelListener l = (MatrixPanelListener) i.next(); l.matrixChanged(e); } } - + /** * Une petite fonction main pour le test... */ public static void main(String[] args) { - I18n.init("fr","FR"); -// I18n.init("en","EN"); + I18n.init("fr", "FR"); + // I18n.init("en","EN"); JFrame frame = new JFrame(); MatrixPanelEditor ed = null; - + try { ed = new MatrixPanelEditor(true); ed.setLinearModel(false); @@ -407,23 +409,28 @@ List sem1 = Arrays.asList(new String[] { "toto", "titi", "tutu" }); List sem2 = Arrays.asList(new String[] { "tata", "tete", "tyty" }); - List sem3 = Arrays.asList(new String[] { "riri", "fifi", "loulou" }); - - /*MatrixND m = MatrixFactory.getInstance().create(new int[]{100,100});*/ + List sem3 = Arrays + .asList(new String[] { "riri", "fifi", "loulou" }); - /*MatrixND m = MatrixFactory.getInstance().create("name", - new List[] { sem1, sem2 }, new String[]{"dim1", "dim2"}); - m.setValue(0, 0, 1); - m.setValue(0, 1, 2); - m.setValue(0, 2, 3);*/ - + /* + * MatrixND m = MatrixFactory.getInstance().create(new + * int[]{100,100}); + */ + + /* + * MatrixND m = MatrixFactory.getInstance().create("name", new + * List[] { sem1, sem2 }, new String[]{"dim1", "dim2"}); + * m.setValue(0, 0, 1); m.setValue(0, 1, 2); m.setValue(0, 2, 3); + */ + MatrixND m = MatrixFactory.getInstance().create("name", - new List[] { sem1, sem2, sem3 }, new String[]{"dim1", "dim2", "dim3"}); + new List[] { sem1, sem2, sem3 }, + new String[] { "dim1", "dim2", "dim3" }); m.setValue(0, 0, 0, 1); m.setValue(0, 1, 0, 2); m.setValue(0, 0, 1, 3); - + ed.setMatrix(m); // ed.setEnabled(false); } catch (MatrixException e) { @@ -431,7 +438,7 @@ System.exit(0); } -// final MatrixPanelEditor mp = ed; + // final MatrixPanelEditor mp = ed; frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { @@ -443,4 +450,3 @@ } } // MatrixPanelEditor - Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEvent.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEvent.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEvent.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,21 +1,19 @@ -/* *##% - * Copyright (C) 2006 - * Code Lutin, Cédric Pineau, Benjamin Poussin +/* *##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin * - * 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 2 - * of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Lesser Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * * MatrixPanelEvent.java @@ -35,10 +33,9 @@ import org.codelutin.math.matrix.MatrixND; - /** * @author poussin - * + * */ public class MatrixPanelEvent extends EventObject { @@ -51,9 +48,7 @@ } public MatrixND getMatrix() { - MatrixND result = ((MatrixPanelEditor)getSource()).getMatrix(); + MatrixND result = ((MatrixPanelEditor) getSource()).getMatrix(); return result; } } - - Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelListener.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelListener.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelListener.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,21 +1,19 @@ -/* *##% - * Copyright (C) 2006 - * Code Lutin, Cédric Pineau, Benjamin Poussin +/* *##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin * - * 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 2 - * of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Lesser Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * * MatrixPanelListener.java @@ -31,10 +29,9 @@ package org.codelutin.math.matrix.gui; - /** * @author poussin - * + * */ public interface MatrixPanelListener { @@ -47,5 +44,3 @@ public void matrixChanged(MatrixPanelEvent e); } - - Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPopupMenu.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPopupMenu.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPopupMenu.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,21 +1,19 @@ -/* *##% - * Copyright (C) 2006 - * Code Lutin, Cédric Pineau, Benjamin Poussin +/* *##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin * - * 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 2 - * of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Lesser Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * * MatrixPopupMenu.java @@ -64,79 +62,92 @@ * Ajout d'un menu contextuel sur la matrice dans l'editeur * * @author ruchaud - * + * */ public class MatrixPopupMenu extends JPopupMenu { - + private MatrixPanelEditor matrixEditor; private JFileChooser fileChooser; - + private JMenu sendToClipBoard; private JMenu sendToFile; - + private JCheckBoxMenuItem withSemantics; - + private Action sendToClipBoardAllCopyAction; private Action sendToClipBoardAllPasteAction; private Action sendToClipBoardSelectionCopyAction; private Action sendToClipBoardCurrentPasteAction; - + private Action sendToFileAllCopyAction; private Action sendToFileAllPasteAction; private Action sendToFileSelectionCopyAction; private Action sendToFileCurrentPasteAction; - + public MatrixPopupMenu(MatrixPanelEditor matrixEditor) { super(); this.matrixEditor = matrixEditor; - + sendToClipBoard = getSendToClipBoard(); sendToFile = getSendToFile(); - - withSemantics = new JCheckBoxMenuItem(_("lutinmatrix.menu.option.semantics"), false); - + + withSemantics = new JCheckBoxMenuItem( + _("lutinmatrix.menu.option.semantics"), false); + add(sendToClipBoard); add(sendToFile); add(new JSeparator()); add(withSemantics); } - + /** * @return retourne le menu d'action pour le bloc note */ public JMenu getSendToClipBoard() { if (sendToClipBoard == null) { sendToClipBoard = new JMenu(_("lutinmatrix.menu.action")); - JMenuItem sendToClipBoardAllCopy = new JMenuItem(_("lutinmatrix.menu.action.copy")); - JMenuItem sendToClipBoardAllPaste = new JMenuItem(_("lutinmatrix.menu.action.paste")); - JMenuItem sendToClipBoardSelectionCopy = new JMenuItem(_("lutinmatrix.menu.action.copy.selection")); - JMenuItem sendToClipBoardCurrentPaste = new JMenuItem(_("lutinmatrix.menu.action.paste.position")); + JMenuItem sendToClipBoardAllCopy = new JMenuItem( + _("lutinmatrix.menu.action.copy")); + JMenuItem sendToClipBoardAllPaste = new JMenuItem( + _("lutinmatrix.menu.action.paste")); + JMenuItem sendToClipBoardSelectionCopy = new JMenuItem( + _("lutinmatrix.menu.action.copy.selection")); + JMenuItem sendToClipBoardCurrentPaste = new JMenuItem( + _("lutinmatrix.menu.action.paste.position")); sendToClipBoard.add(sendToClipBoardAllCopy); sendToClipBoard.add(sendToClipBoardAllPaste); sendToClipBoard.add(new JSeparator()); sendToClipBoard.add(sendToClipBoardSelectionCopy); sendToClipBoard.add(sendToClipBoardCurrentPaste); - - sendToClipBoardAllCopy.addActionListener(getSendToClipBoardAllCopyAction()); - sendToClipBoardAllPaste.addActionListener(getSendToClipBoardAllPasteAction()); - sendToClipBoardSelectionCopy.addActionListener(getSendToClipBoardSelectionCopyAction()); - sendToClipBoardCurrentPaste.addActionListener(getSendToClipBoardCurrentPasteAction()); + + sendToClipBoardAllCopy + .addActionListener(getSendToClipBoardAllCopyAction()); + sendToClipBoardAllPaste + .addActionListener(getSendToClipBoardAllPasteAction()); + sendToClipBoardSelectionCopy + .addActionListener(getSendToClipBoardSelectionCopyAction()); + sendToClipBoardCurrentPaste + .addActionListener(getSendToClipBoardCurrentPasteAction()); } return sendToClipBoard; } - + /** * @return retourne le menu d'action pour les fichiers CSV */ public JMenu getSendToFile() { if (sendToFile == null) { sendToFile = new JMenu(_("lutinmatrix.menu.csv")); - JMenuItem sendToFileAllCopy = new JMenuItem(_("lutinmatrix.menu.csv.export.file")); - JMenuItem sendToFileAllPaste = new JMenuItem(_("lutinmatrix.menu.csv.import.file")); - JMenuItem sendToFileSelectionCopy = new JMenuItem(_("lutinmatrix.menu.csv.export.selection")); - JMenuItem sendToFileCurrentPaste = new JMenuItem(_("lutinmatrix.menu.csv.import.position")); + JMenuItem sendToFileAllCopy = new JMenuItem( + _("lutinmatrix.menu.csv.export.file")); + JMenuItem sendToFileAllPaste = new JMenuItem( + _("lutinmatrix.menu.csv.import.file")); + JMenuItem sendToFileSelectionCopy = new JMenuItem( + _("lutinmatrix.menu.csv.export.selection")); + JMenuItem sendToFileCurrentPaste = new JMenuItem( + _("lutinmatrix.menu.csv.import.position")); sendToFile.add(sendToFileAllCopy); sendToFile.add(sendToFileAllPaste); @@ -146,40 +157,42 @@ sendToFileAllCopy.addActionListener(getSendToFileAllCopyAction()); sendToFileAllPaste.addActionListener(getSendToFileAllPasteAction()); - sendToFileSelectionCopy.addActionListener(getSendToFileSelectionCopyAction()); - sendToFileCurrentPaste.addActionListener(getSendToFileCurrentPasteAction()); + sendToFileSelectionCopy + .addActionListener(getSendToFileSelectionCopyAction()); + sendToFileCurrentPaste + .addActionListener(getSendToFileCurrentPasteAction()); } return sendToFile; } - + /** * @return retourne un writer du fichier choisi dans le selecteur de fichier * @throws IOException */ private Writer getFileChooserWriter() throws IOException { int returnVal = getFileChooser().showOpenDialog(matrixEditor); - if(returnVal == JFileChooser.APPROVE_OPTION) { + if (returnVal == JFileChooser.APPROVE_OPTION) { File selectedFile = getFileChooser().getSelectedFile(); return FileUtil.getWriter(selectedFile); } return null; } - + /** * @return retourne un writer pour le bloc note */ private Writer getClipBoardWriter() { return new StringWriter(); } - + /** * @return retourne un reader du fichier choisi dans le selecteur de fichier * @throws IOException */ private Reader getFileChooserReader() throws IOException { int returnVal = getFileChooser().showOpenDialog(matrixEditor); - if(returnVal == JFileChooser.APPROVE_OPTION) { + if (returnVal == JFileChooser.APPROVE_OPTION) { File selectedFile = getFileChooser().getSelectedFile(); return FileUtil.getReader(selectedFile); } @@ -194,7 +207,8 @@ Transferable contents = clipboard.getContents(clipboard); if (contents != null) { try { - String data = (String) contents.getTransferData(DataFlavor.stringFlavor); + String data = (String) contents + .getTransferData(DataFlavor.stringFlavor); return new StringReader(data); } catch (Exception e) { JOptionPane.showMessageDialog(matrixEditor, @@ -205,12 +219,12 @@ } return null; } - + /** * Desactive le menu si la matrice ne supporte pas le mode CSV */ protected void firePopupMenuWillBecomeVisible() { - if(!getMatrix().isSupportedCSV()) { + if (!getMatrix().isSupportedCSV()) { sendToClipBoard.setEnabled(false); sendToFile.setEnabled(false); } else { @@ -226,30 +240,33 @@ private MatrixND getMatrix() { return matrixEditor.getMatrix(); } - + /** - * @return la sous matrice en cours de saisie dans l'editeur c'est a dire la partie selectionnee + * @return la sous matrice en cours de saisie dans l'editeur c'est a dire la + * partie selectionnee */ private MatrixND getSelectedMatrix() { int beginSelectedColumn = matrixEditor.getTable().getSelectedColumn(); int nbSelectedColumn = matrixEditor.getTable().getSelectedColumnCount(); - + /* Prend en compte le décalage des lignes par rapport aux dimenssions */ int nbColumnDimRow = matrixEditor.getMatrix().getNbDim() - 1; beginSelectedColumn -= nbColumnDimRow; - if(beginSelectedColumn < 0) { + if (beginSelectedColumn < 0) { beginSelectedColumn = 0; nbSelectedColumn -= nbColumnDimRow; } - + int beginSelectedRow = matrixEditor.getTable().getSelectedRow() - 1; int nbSelectedRow = matrixEditor.getTable().getSelectedRowCount(); - if(getMatrix().getNbDim() == 1) { - return matrixEditor.getMatrix().getSubMatrix(0, beginSelectedColumn, nbSelectedColumn); + if (getMatrix().getNbDim() == 1) { + return matrixEditor.getMatrix().getSubMatrix(0, + beginSelectedColumn, nbSelectedColumn); } else { - return matrixEditor.getMatrix().getSubMatrix(0, beginSelectedRow, nbSelectedRow) - .getSubMatrix(1, beginSelectedColumn, nbSelectedColumn); + return matrixEditor.getMatrix().getSubMatrix(0, beginSelectedRow, + nbSelectedRow).getSubMatrix(1, beginSelectedColumn, + nbSelectedColumn); } } @@ -258,26 +275,26 @@ */ private int[] getCoordinatesFirstCellSelectedMatrix() { int selectedColumn = matrixEditor.getTable().getSelectedColumn(); - + /* Prend en compte le décalage des lignes par rapport aux dimenssions */ int nbColumnDimRow = matrixEditor.getMatrix().getNbDim() - 1; selectedColumn -= nbColumnDimRow; - if(selectedColumn < 0) { + if (selectedColumn < 0) { selectedColumn = 0; } - + int selectedRow = matrixEditor.getTable().getSelectedRow() - 1; - return new int[]{selectedRow, selectedColumn}; + return new int[] { selectedRow, selectedColumn }; } /** * @return Selecteur de fichier CSV */ private JFileChooser getFileChooser() { - if(fileChooser == null) { + if (fileChooser == null) { fileChooser = new JFileChooser(); - FileFilter filter = new FileFilter(){ + FileFilter filter = new FileFilter() { public boolean accept(File pathname) { if (pathname.isDirectory()) { return true; @@ -291,9 +308,10 @@ return false; } } - + return false; } + public String getDescription() { return "Texte CSV (*.csv)"; } @@ -304,7 +322,8 @@ } /** - * @return retourne l'action du bloc note permettant la copie entere de la matrice + * @return retourne l'action du bloc note permettant la copie entere de la + * matrice */ public Action getSendToClipBoardAllCopyAction() { if (sendToClipBoardAllCopyAction == null) { @@ -318,8 +337,8 @@ } /** - * @return retourne l'action du bloc note permettant la recopie entere - * de la matrice depuis le bloc note + * @return retourne l'action du bloc note permettant la recopie entere de la + * matrice depuis le bloc note */ public Action getSendToClipBoardAllPasteAction() { if (sendToClipBoardAllPasteAction == null) { @@ -333,7 +352,8 @@ } /** - * @return retourne l'action du bloc note permettant la copie de la partie selectionnee + * @return retourne l'action du bloc note permettant la copie de la partie + * selectionnee */ public Action getSendToClipBoardSelectionCopyAction() { if (sendToClipBoardSelectionCopyAction == null) { @@ -347,8 +367,8 @@ } /** - * @return retourne l'action du bloc note permettant la recopie de la partie selectionnee - * de la matrice depuis le bloc note + * @return retourne l'action du bloc note permettant la recopie de la partie + * selectionnee de la matrice depuis le bloc note */ public Action getSendToClipBoardCurrentPasteAction() { if (sendToClipBoardCurrentPasteAction == null) { @@ -366,14 +386,15 @@ Writer writer = getClipBoardWriter(); getMatrix().exportCSV(writer, withSemantics.getState()); StringSelection contents = new StringSelection(writer.toString()); - Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + Clipboard clipboard = Toolkit.getDefaultToolkit() + .getSystemClipboard(); clipboard.setContents(contents, contents); writer.close(); matrixEditor.repaint(); } catch (Exception e) { JOptionPane.showMessageDialog(matrixEditor, - _("lutinmatrix.error.clipboard.write"), _("lutinmatrix.error"), - JOptionPane.ERROR_MESSAGE); + _("lutinmatrix.error.clipboard.write"), + _("lutinmatrix.error"), JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } } @@ -381,14 +402,14 @@ private void sendToClipBoardAllPastePerformed() { try { Reader reader = getClipBoardReader(); - getMatrix().importCSV(reader, new int[]{0,0}); + getMatrix().importCSV(reader, new int[] { 0, 0 }); reader.close(); matrixEditor.fireEvent(); matrixEditor.repaint(); } catch (Exception e) { JOptionPane.showMessageDialog(matrixEditor, - _("lutinmatrix.error.clipboard.read"), _("lutinmatrix.error"), - JOptionPane.ERROR_MESSAGE); + _("lutinmatrix.error.clipboard.read"), + _("lutinmatrix.error"), JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } } @@ -398,14 +419,15 @@ Writer writer = getClipBoardWriter(); getSelectedMatrix().exportCSV(writer, withSemantics.getState()); StringSelection contents = new StringSelection(writer.toString()); - Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + Clipboard clipboard = Toolkit.getDefaultToolkit() + .getSystemClipboard(); clipboard.setContents(contents, contents); writer.close(); matrixEditor.repaint(); } catch (Exception e) { JOptionPane.showMessageDialog(matrixEditor, - _("lutinmatrix.error.clipboard.write"), _("lutinmatrix.error"), - JOptionPane.ERROR_MESSAGE); + _("lutinmatrix.error.clipboard.write"), + _("lutinmatrix.error"), JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } } @@ -413,20 +435,22 @@ private void sendToClipBoardCurrentPastePerformed() { try { Reader reader = getClipBoardReader(); - getMatrix().importCSV(reader, getCoordinatesFirstCellSelectedMatrix()); + getMatrix().importCSV(reader, + getCoordinatesFirstCellSelectedMatrix()); reader.close(); matrixEditor.fireEvent(); matrixEditor.repaint(); } catch (Exception e) { JOptionPane.showMessageDialog(matrixEditor, - _("lutinmatrix.error.clipboard.read"), _("lutinmatrix.error"), - JOptionPane.ERROR_MESSAGE); + _("lutinmatrix.error.clipboard.read"), + _("lutinmatrix.error"), JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } } /** - * @return retourne l'action du fichier permettant la copie entere de la matrice + * @return retourne l'action du fichier permettant la copie entere de la + * matrice */ public Action getSendToFileAllCopyAction() { if (sendToFileAllCopyAction == null) { @@ -440,8 +464,8 @@ } /** - * @return retourne l'action du fichier permettant la recopie entere - * de la matrice depuis le fichier + * @return retourne l'action du fichier permettant la recopie entere de la + * matrice depuis le fichier */ public Action getSendToFileAllPasteAction() { if (sendToFileAllPasteAction == null) { @@ -455,7 +479,8 @@ } /** - * @return retourne l'action du fichier permettant la copie de la partie selectionnee + * @return retourne l'action du fichier permettant la copie de la partie + * selectionnee */ public Action getSendToFileSelectionCopyAction() { if (sendToFileSelectionCopyAction == null) { @@ -469,8 +494,8 @@ } /** - * @return retourne l'action du fichier permettant la recopie de la partie selectionnee - * de la matrice depuis le fichier + * @return retourne l'action du fichier permettant la recopie de la partie + * selectionnee de la matrice depuis le fichier */ public Action getSendToFileCurrentPasteAction() { if (sendToFileCurrentPasteAction == null) { @@ -482,7 +507,7 @@ } return sendToFileCurrentPasteAction; } - + private void sendToFileAllCopyPerformed() { try { Writer writer = getFileChooserWriter(); @@ -500,7 +525,7 @@ private void sendToFileAllPastePerformed() { try { Reader reader = getFileChooserReader(); - getMatrix().importCSV(reader, new int[]{0,0}); + getMatrix().importCSV(reader, new int[] { 0, 0 }); reader.close(); matrixEditor.fireEvent(); matrixEditor.repaint(); @@ -529,7 +554,8 @@ private void sendToFileCurrentPastePerformed() { try { Reader reader = getFileChooserReader(); - getMatrix().importCSV(reader, getCoordinatesFirstCellSelectedMatrix()); + getMatrix().importCSV(reader, + getCoordinatesFirstCellSelectedMatrix()); reader.close(); matrixEditor.fireEvent(); matrixEditor.repaint(); Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModel.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModel.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModel.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,21 +1,19 @@ -/* *##% - * Copyright (C) 2006 - * Code Lutin, Cédric Pineau, Benjamin Poussin +/* *##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin * - * 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 2 - * of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Lesser Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * * MatrixTableModel.java @@ -36,18 +34,17 @@ import org.codelutin.math.matrix.MatrixND; - /** * @author poussin - * + * */ public interface MatrixTableModel extends TableModel { - + public void setMatrix(MatrixND m); + public void setEnabled(boolean enabled); + public TableCellRenderer getMatrixCellRenderer(); } - - Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModelLinear.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModelLinear.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModelLinear.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,21 +1,19 @@ -/* *##% - * Copyright (C) 2006 - * Code Lutin, Cédric Pineau, Benjamin Poussin +/* *##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin * - * 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 2 - * of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Lesser Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * * MatrixTableModelLinear.java @@ -50,20 +48,20 @@ import org.codelutin.math.matrix.MatrixIterator; import org.codelutin.math.matrix.MatrixND; - /** * @author poussin - * + * */ -public class MatrixTableModelLinear extends AbstractTableModel implements MatrixTableModel { +public class MatrixTableModelLinear extends AbstractTableModel implements + MatrixTableModel { /** * Logger for this class */ private static final Log log = LogFactory .getLog(MatrixTableModelLinear.class); - + protected boolean enabled = true; protected MatrixND m = null; protected boolean showDefault = false; @@ -75,45 +73,45 @@ this.showDefault = showDefault; setMatrix(m); } - + public void setMatrix(MatrixND m) { this.m = m; computeMapping(); fireTableStructureChanged(); } - + protected void computeMapping() { mappingRowSems.clear(); - for (MatrixIterator i=m.iterator(); i.next();) { - Object [] sems = i.getSemanticsCoordinates(); + for (MatrixIterator i = m.iterator(); i.next();) { + Object[] sems = i.getSemanticsCoordinates(); double value = i.getValue(); if (showDefault || value != defaultValue) { mappingRowSems.add(sems); } - } + } } - + /** * @return Returns the enabled. */ public boolean isEnabled() { return this.enabled; } - + /** * @param enabled The enabled to set. */ public void setEnabled(boolean enabled) { this.enabled = enabled; } - + /** * @return Returns the showDefault. */ public boolean isShowDefault() { return this.showDefault; } - + /** * @param showDefault The showDefault to set. */ @@ -122,14 +120,14 @@ computeMapping(); fireTableDataChanged(); } - + /** * @return Returns the defaultValue. */ public double getDefaultValue() { return this.defaultValue; } - + /** * @param defaultValue The defaultValue to set. */ @@ -138,22 +136,28 @@ computeMapping(); fireTableDataChanged(); } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see javax.swing.table.TableModel#getRowCount() */ - public int getRowCount() { + public int getRowCount() { return mappingRowSems.size(); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see javax.swing.table.TableModel#getColumnCount() */ - public int getColumnCount() { + public int getColumnCount() { return m.getNbDim() + 1; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see javax.swing.table.TableModel#getValueAt(int, int) */ public Object getValueAt(int rowIndex, int columnIndex) { @@ -165,33 +169,40 @@ } return result; } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see javax.swing.table.AbstractTableModel#isCellEditable(int, int) */ @Override public boolean isCellEditable(int rowIndex, int columnIndex) { return isEnabled() && columnIndex == m.getNbDim(); } - - /* (non-Javadoc) - * @see javax.swing.table.AbstractTableModel#setValueAt(java.lang.Object, int, int) + + /* + * (non-Javadoc) + * + * @see javax.swing.table.AbstractTableModel#setValueAt(java.lang.Object, + * int, int) */ @Override public void setValueAt(Object aValue, int rowIndex, int columnIndex) { try { double val = Double.parseDouble((String) aValue); - Object [] sems = mappingRowSems.get(rowIndex); + Object[] sems = mappingRowSems.get(rowIndex); m.setValue(sems, val); fireTableDataChanged(); } catch (Exception eee) { log.debug("La nouvelle valeur n'est pas convertible en double: " - + aValue, eee); - } - + + aValue, eee); + } + } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see javax.swing.table.AbstractTableModel#getColumnName(int) */ @Override @@ -204,7 +215,7 @@ } return result; } - + /** * Par defaut, la classe de la colonne est du type Function.class */ @@ -216,13 +227,12 @@ * @return */ public TableCellRenderer getMatrixCellRenderer() { - if (renderer == null) { + if (renderer == null) { renderer = new MatrixCellRenderer(this); } return renderer; } - - + class MatrixCellRenderer extends DefaultTableCellRenderer { protected MatrixTableModelLinear model = null; @@ -230,7 +240,7 @@ protected Color fg = null; protected Font font = null; protected Border border = null; - + public MatrixCellRenderer(MatrixTableModelLinear model) { this.model = model; bg = getBackground(); @@ -238,16 +248,17 @@ font = getFont(); border = getBorder(); } - + /** */ private static final long serialVersionUID = 6537813058357761914L; - public Component getTableCellRendererComponent(JTable table, Object value, - boolean isSelected, boolean hasFocus, int row, int column) { - super.getTableCellRendererComponent(table, value, isSelected, hasFocus, - row, column); + public Component getTableCellRendererComponent(JTable table, + Object value, boolean isSelected, boolean hasFocus, int row, + int column) { + super.getTableCellRendererComponent(table, value, isSelected, + hasFocus, row, column); setToolTipText(getText()); - + if (column < model.m.getNbDim()) { if (table != null) { JTableHeader header = table.getTableHeader(); @@ -257,7 +268,7 @@ setFont(header.getFont()); } } - + setBorder(UIManager.getBorder("TableHeader.cellBorder")); } else { setBackground(bg); @@ -265,11 +276,9 @@ setFont(font); setBorder(border); } - + return this; } } } - - Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModelND.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModelND.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModelND.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,21 +1,19 @@ -/* *##% - * Copyright (C) 2006 - * Code Lutin, Cédric Pineau, Benjamin Poussin +/*##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin * - * 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 2 - * of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Lesser Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * * MatrixTableModel.java @@ -48,19 +46,18 @@ import org.codelutin.math.matrix.MatrixException; import org.codelutin.math.matrix.MatrixND; - /** * @author poussin - * + * */ -public /** - * Extension de AbstractTableModel pour definir un TableModel avec une MatrixND - * comme support d'information. - * - * @todo changer les 'matrice' en 'matrix', s'il y a des methodes public avec - * les nom 'matice' les laisser mais les mettres depreciées - */ +public/* + * Extension de AbstractTableModel pour definir un TableModel avec une + * MatrixND comme support d'information. + * + * @todo changer les 'matrice' en 'matrix', s'il y a des methodes public + * avec les nom 'matice' les laisser mais les mettres depreciées + */ class MatrixTableModelND extends AbstractTableModel implements MatrixTableModel { /** */ @@ -72,9 +69,9 @@ protected int addRow = 0; /** nombre de colone ajouté */ protected int addCol = 0; - - protected int [] multRowCol = null; - + + protected int[] multRowCol = null; + /** par defaut, la matrice est editable. */ protected boolean enabled = true; @@ -107,23 +104,24 @@ public MatrixTableModelND(MatrixND m) throws MatrixException { setMatrix(m); } - + public void setMatrix(MatrixND m) { this.m = m; addRow = m.getNbDim() / 2; addCol = (m.getNbDim() + 1) / 2; - - // calcule les coefficients multiplicateur pour la correspondance table/matrice - multRowCol = new int[m.getNbDim()]; - for (int i=multRowCol.length-1; i>=0; i--) { + + // calcule les coefficients multiplicateur pour la correspondance + // table/matrice + multRowCol = new int[m.getNbDim()]; + for (int i = multRowCol.length - 1; i >= 0; i--) { if (i >= multRowCol.length - 2) { multRowCol[i] = 1; } else { - multRowCol[i] = multRowCol[i+2] * m.getDim(i+2); + multRowCol[i] = multRowCol[i + 2] * m.getDim(i + 2); } } } - + /** * converti les coordonnées de la table en coordonnées pour la matrice * @@ -131,23 +129,23 @@ * @param col la colonne dans la table * @return les coordonnées equivalentes dans la matrice */ - protected int [] tableToMatrix(int row, int col) { - int [] result = new int[m.getNbDim()]; - for (int i=0; i<result.length; i++) { + protected int[] tableToMatrix(int row, int col) { + int[] result = new int[m.getNbDim()]; + for (int i = 0; i < result.length; i++) { int val = row; - if (i%2 == 1) { // si impaire alors la valeur vient de la colonne + if (i % 2 == 1) { // si impaire alors la valeur vient de la colonne val = col; } result[i] = tableToMatrixCell(i, val); } return result; } - + protected int tableToMatrixCell(int dim, int tableValue) { int b = 0; int val = tableValue; if (dim % 2 == 1) { // si impaire alors la valeur vient de la colonne - b = 1; // les colonnes represente toutes les dim impaires + b = 1; // les colonnes represente toutes les dim impaires } while (b < dim) { val = val % multRowCol[b]; @@ -156,12 +154,13 @@ int result = val / multRowCol[b]; return result; } - + protected Object getValue(int row, int col) { Object result = null; if (row < addRow && col < addCol) { if (row == addRow - 1 && col == addCol - 1) { - result = m.getDimensionName(col * 2) + "\\" + m.getDimensionName(row * 2 + 1); + result = m.getDimensionName(col * 2) + "\\" + + m.getDimensionName(row * 2 + 1); } else if (row == addRow - 1) { result = m.getDimensionName(col * 2); } else if (col == addCol - 1) { @@ -170,9 +169,11 @@ result = ""; } } else if (row < addRow) { - result = getSemantic(row * 2 + 1, tableToMatrixCell(row * 2 + 1, col - addCol)); + result = getSemantic(row * 2 + 1, tableToMatrixCell(row * 2 + 1, + col - addCol)); } else if (col < addCol) { - result = getSemantic(col * 2, tableToMatrixCell(col * 2, row - addRow)); + result = getSemantic(col * 2, tableToMatrixCell(col * 2, row + - addRow)); } else { result = m.getValue(tableToMatrix(row - addRow, col - addCol)); } @@ -189,20 +190,20 @@ * chaine vide est retourné */ protected String getSemantic(int dim, int elem) { - + Object o = m.getSemantics(dim).get(elem); return (o == null) ? "" : o.toString(); } public String getColumnName(int column) { return null; -// String result = null; -// if (m.getNbDim() != 1) { -// result = getValue(0, column).toString(); -// } else { -// result = getValue(column, 0).toString(); -// } -// return result; + // String result = null; + // if (m.getNbDim() != 1) { + // result = getValue(0, column).toString(); + // } else { + // result = getValue(column, 0).toString(); + // } + // return result; } /** @@ -211,7 +212,8 @@ public int getRowCount() { int result = 0; if (m.getNbDim() != 1) { -// result = multRowCol[0] * m.getDim(0) + addRow - 1; // -1 pour le header + // result = multRowCol[0] * m.getDim(0) + addRow - 1; // -1 pour le + // header result = multRowCol[0] * m.getDim(0) + addRow; } else { result = 2; @@ -240,8 +242,8 @@ public Object getValueAt(int row, int column) { Object result = null; if (m.getNbDim() != 1) { -// // on fait row + 1 a cause du header -// result = getValue(row + 1, column); + // // on fait row + 1 a cause du header + // result = getValue(row + 1, column); result = getValue(row, column); } else { result = getValue(column, row); @@ -255,25 +257,26 @@ * @param column La colonnes */ public void setValueAt(Object obj, int row, int column) { - if ((m.getNbDim() != 1 && row >= addRow && column >= addCol) - || (m.getNbDim() == 1 && row >= 1) ) { + if ((m.getNbDim() != 1 && row >= addRow && column >= addCol) + || (m.getNbDim() == 1 && row >= 1)) { try { double val = Double.parseDouble((String) obj); - int [] coord = null; + int[] coord = null; if (m.getNbDim() != 1) { -// coord = tableToMatrix(row - addRow + 1, column - addCol); // +1 pour le header + // coord = tableToMatrix(row - addRow + 1, column - addCol); + // // +1 pour le header coord = tableToMatrix(row - addRow, column - addCol); } else { - coord = new int[]{column}; + coord = new int[] { column }; } m.setValue(coord, val); fireTableDataChanged(); } catch (Exception eee) { Logger.getLogger(getClass().getName() + ".setValueAt").log( - Level.FINE, - "La nouvelle valeur n'est pas convertible en double: " - + obj, eee); - } + Level.FINE, + "La nouvelle valeur n'est pas convertible en double: " + + obj, eee); + } } } @@ -307,13 +310,12 @@ * @return */ public TableCellRenderer getMatrixCellRenderer() { - if (renderer == null) { + if (renderer == null) { renderer = new MatrixCellRenderer(this); } return renderer; } - - + class MatrixCellRenderer extends DefaultTableCellRenderer { protected MatrixTableModelND model = null; @@ -321,7 +323,7 @@ protected Color fg = null; protected Font font = null; protected Border border = null; - + public MatrixCellRenderer(MatrixTableModelND model) { this.model = model; bg = getBackground(); @@ -329,16 +331,17 @@ font = getFont(); border = getBorder(); } - + /** */ private static final long serialVersionUID = 6537813058357761914L; - public Component getTableCellRendererComponent(JTable table, Object value, - boolean isSelected, boolean hasFocus, int row, int column) { - super.getTableCellRendererComponent(table, value, isSelected, hasFocus, - row, column); + public Component getTableCellRendererComponent(JTable table, + Object value, boolean isSelected, boolean hasFocus, int row, + int column) { + super.getTableCellRendererComponent(table, value, isSelected, + hasFocus, row, column); setToolTipText(getText()); - + if ((model.m.getNbDim() != 1 && (row < model.addRow || column < model.addCol)) || (model.m.getNbDim() == 1 && row < 1)) { if (table != null) { @@ -349,21 +352,19 @@ setFont(header.getFont()); } } - + setBorder(UIManager.getBorder("TableHeader.cellBorder")); } else { setBackground(bg); setForeground(fg); setFont(font); setBorder(border); - return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, - row, column); + return super.getTableCellRendererComponent(table, value, + isSelected, hasFocus, row, column); } - + return this; } } } - - Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/BasicMatrixBigTest.java =================================================================== --- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/BasicMatrixBigTest.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/BasicMatrixBigTest.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,21 +1,19 @@ -/* *##% - * Copyright (C) 2002, 2003 Code Lutin, Cédric Pineau, - Benjamin Poussin +/* *##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin * - * 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 2 - * of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Lesser Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * * MatriceTest.java @@ -31,7 +29,6 @@ package org.codelutin.math.matrix; - public class BasicMatrixBigTest extends BasicMatrixTest { // BasicMatrixTest public MatrixFactory getFactory() throws Exception { Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/BasicMatrixTest.java =================================================================== --- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/BasicMatrixTest.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/BasicMatrixTest.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,21 +1,19 @@ -/* *##% - * Copyright (C) 2002, 2003 Code Lutin, Cédric Pineau, - Benjamin Poussin +/* *##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin * - * 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 2 - * of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Lesser Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * * MatriceTest.java @@ -34,10 +32,10 @@ import java.util.Arrays; import java.util.NoSuchElementException; -import org.apache.commons.lang.time.DurationFormatUtils; - import junit.framework.TestCase; +import org.apache.commons.lang.time.DurationFormatUtils; + public class BasicMatrixTest extends TestCase { // BasicMatrixTest public MatrixFactory getFactory() throws Exception { @@ -46,41 +44,41 @@ public void testNew() throws Exception { BasicMatrix mat = null; - try{ + try { mat = new BasicMatrix(getFactory(), null); assertFalse(true); // on ne doit pas etre ici - }catch(NullPointerException eee){ + } catch (NullPointerException eee) { assertTrue(true); // mais on doit etre la } - try{ - mat = new BasicMatrix(getFactory(), new int[]{0}); + try { + mat = new BasicMatrix(getFactory(), new int[] { 0 }); assertFalse(true); // on ne doit pas etre ici - }catch(IllegalArgumentException eee){ - assertTrue(true); // mais on doit etre la + } catch (IllegalArgumentException eee) { + assertTrue(true); // mais on doit etre la } - mat = new BasicMatrix(getFactory(), new int[]{100}); - mat = new BasicMatrix(getFactory(), new int[]{10,1}); + mat = new BasicMatrix(getFactory(), new int[] { 100 }); + mat = new BasicMatrix(getFactory(), new int[] { 10, 1 }); assertEquals(0.0, mat.getMaxOccurence()); - mat = new BasicMatrix(getFactory(), new int[]{10,10,10,10}); - try{ - mat = new BasicMatrix(getFactory(), new int[]{-10}); + mat = new BasicMatrix(getFactory(), new int[] { 10, 10, 10, 10 }); + try { + mat = new BasicMatrix(getFactory(), new int[] { -10 }); assertFalse(true); // on ne doit pas etre ici - }catch(IllegalArgumentException eee){ - assertTrue(true); // mais on doit etre la + } catch (IllegalArgumentException eee) { + assertTrue(true); // mais on doit etre la } - try{ - mat = new BasicMatrix(getFactory(), new int[]{10, 20, -10, 20}); + try { + mat = new BasicMatrix(getFactory(), new int[] { 10, 20, -10, 20 }); assertFalse(true); // on ne doit pas etre ici - }catch(IllegalArgumentException eee){ - assertTrue(true); // mais on doit etre la + } catch (IllegalArgumentException eee) { + assertTrue(true); // mais on doit etre la } } - public void testDimension()throws Exception { + public void testDimension() throws Exception { BasicMatrix mat = null; - mat = new BasicMatrix(getFactory(), new int[]{1,10,30,5}); + mat = new BasicMatrix(getFactory(), new int[] { 1, 10, 30, 5 }); assertEquals(4, mat.getNbDim()); assertEquals(1, mat.getDim(0)); @@ -88,17 +86,17 @@ assertEquals(30, mat.getDim(2)); assertEquals(5, mat.getDim(3)); - try{ + try { mat.getDim(-3); assertFalse(true); // on ne doit pas etre ici - }catch(IndexOutOfBoundsException eee){ - assertTrue(true); // mais on doit etre la + } catch (IndexOutOfBoundsException eee) { + assertTrue(true); // mais on doit etre la } - try{ + try { mat.getDim(4); assertFalse(true); // on ne doit pas etre ici - }catch(IndexOutOfBoundsException eee){ - assertTrue(true); // mais on doit etre la + } catch (IndexOutOfBoundsException eee) { + assertTrue(true); // mais on doit etre la } } @@ -106,206 +104,206 @@ BasicMatrix mat = null; // test avec la plus petit BasicMatrix possible - mat = new BasicMatrix(getFactory(), new int[]{1}); + mat = new BasicMatrix(getFactory(), new int[] { 1 }); // test la valeur par defaut doit etre 0 - assertEquals(0, mat.getValue(new int[]{0}), 0); - mat.setValue(new int[]{0}, 30); - assertEquals(30, mat.getValue(new int[]{0}), 0); + assertEquals(0, mat.getValue(new int[] { 0 }), 0); + mat.setValue(new int[] { 0 }, 30); + assertEquals(30, mat.getValue(new int[] { 0 }), 0); // acces a un element qui n'existe pas - try{ - mat.getValue(new int[]{1}); + try { + mat.getValue(new int[] { 1 }); assertFalse(true); // on ne doit pas etre ici - }catch(NoSuchElementException eee){ - assertTrue(true); // mais on doit etre la - } + } catch (NoSuchElementException eee) { + assertTrue(true); // mais on doit etre la + } - mat = new BasicMatrix(getFactory(), new int[]{1, 10, 5}); - mat.setValue(new int[]{0, 0, 0}, 0); - mat.setValue(new int[]{0, 0, 1}, 1); - mat.setValue(new int[]{0, 0, 2}, 2); - mat.setValue(new int[]{0, 0, 3}, 3); - mat.setValue(new int[]{0, 0, 4}, 4); - mat.setValue(new int[]{0, 1, 0}, 10); - mat.setValue(new int[]{0, 1, 1}, 11); - mat.setValue(new int[]{0, 1, 2}, 12); - mat.setValue(new int[]{0, 1, 3}, 13); - mat.setValue(new int[]{0, 1, 4}, 14); - mat.setValue(new int[]{0, 2, 0}, 20); - mat.setValue(new int[]{0, 2, 1}, 21); - mat.setValue(new int[]{0, 2, 2}, 22); - mat.setValue(new int[]{0, 9, 4}, 98); - mat.setValue(new int[]{0, 4, 2}, 97); - assertEquals(0, mat.getValue(new int[]{0, 0, 0}), 0); - assertEquals(98, mat.getValue(new int[]{0, 9, 4}), 0); - assertEquals(97, mat.getValue(new int[]{0, 4, 2}), 0); + mat = new BasicMatrix(getFactory(), new int[] { 1, 10, 5 }); + mat.setValue(new int[] { 0, 0, 0 }, 0); + mat.setValue(new int[] { 0, 0, 1 }, 1); + mat.setValue(new int[] { 0, 0, 2 }, 2); + mat.setValue(new int[] { 0, 0, 3 }, 3); + mat.setValue(new int[] { 0, 0, 4 }, 4); + mat.setValue(new int[] { 0, 1, 0 }, 10); + mat.setValue(new int[] { 0, 1, 1 }, 11); + mat.setValue(new int[] { 0, 1, 2 }, 12); + mat.setValue(new int[] { 0, 1, 3 }, 13); + mat.setValue(new int[] { 0, 1, 4 }, 14); + mat.setValue(new int[] { 0, 2, 0 }, 20); + mat.setValue(new int[] { 0, 2, 1 }, 21); + mat.setValue(new int[] { 0, 2, 2 }, 22); + mat.setValue(new int[] { 0, 9, 4 }, 98); + mat.setValue(new int[] { 0, 4, 2 }, 97); + assertEquals(0, mat.getValue(new int[] { 0, 0, 0 }), 0); + assertEquals(98, mat.getValue(new int[] { 0, 9, 4 }), 0); + assertEquals(97, mat.getValue(new int[] { 0, 4, 2 }), 0); - //System.out.println(mat.toString()); + // System.out.println(mat.toString()); - // acces a un element qui n'existe pas - try{ - mat.setValue(new int[]{0, 9, 5}, 44); - assertFalse(true); // on ne doit pas etre ici - }catch(NoSuchElementException eee){ - assertTrue(true); // mais on doit etre la - } + // acces a un element qui n'existe pas + try { + mat.setValue(new int[] { 0, 9, 5 }, 44); + assertFalse(true); // on ne doit pas etre ici + } catch (NoSuchElementException eee) { + assertTrue(true); // mais on doit etre la + } } public void testEquals() throws Exception { - BasicMatrix m1 = new BasicMatrix(getFactory(), new int[]{3,3,3,3}); - BasicMatrix m2 = new BasicMatrix(getFactory(), new int[]{3,3,3,3}); + BasicMatrix m1 = new BasicMatrix(getFactory(), new int[] { 3, 3, 3, 3 }); + BasicMatrix m2 = new BasicMatrix(getFactory(), new int[] { 3, 3, 3, 3 }); assertEquals(m1, m2); - m1.setValue(new int[]{1,2,1,2}, 123); - m2.setValue(new int[]{1,2,1,2}, 123); + m1.setValue(new int[] { 1, 2, 1, 2 }, 123); + m2.setValue(new int[] { 1, 2, 1, 2 }, 123); assertEquals(m1, m2); - m1.setValue(new int[]{1,0,1,0}, 321); + m1.setValue(new int[] { 1, 0, 1, 0 }, 321); assertFalse(m1.equals(m2)); } public void testIterator() throws Exception { - int [][] val27 = new int[][]{ - {0,0,0}, - {0,0,1}, - {0,0,2}, - {0,1,0}, - {0,1,1}, - {0,1,2}, - {0,2,0}, - {0,2,1}, - {0,2,2}, - {1,0,0}, - {1,0,1}, - {1,0,2}, - {1,1,0}, - {1,1,1}, - {1,1,2}, - {1,2,0}, - {1,2,1}, - {1,2,2}, - {2,0,0}, - {2,0,1}, - {2,0,2}, - {2,1,0}, - {2,1,1}, - {2,1,2}, - {2,2,0}, - {2,2,1}, - {2,2,2}, - }; - int [][] val1 = new int[][]{{0}}; + int[][] val27 = new int[][] { { 0, 0, 0 }, { 0, 0, 1 }, { 0, 0, 2 }, + { 0, 1, 0 }, { 0, 1, 1 }, { 0, 1, 2 }, { 0, 2, 0 }, + { 0, 2, 1 }, { 0, 2, 2 }, { 1, 0, 0 }, { 1, 0, 1 }, + { 1, 0, 2 }, { 1, 1, 0 }, { 1, 1, 1 }, { 1, 1, 2 }, + { 1, 2, 0 }, { 1, 2, 1 }, { 1, 2, 2 }, { 2, 0, 0 }, + { 2, 0, 1 }, { 2, 0, 2 }, { 2, 1, 0 }, { 2, 1, 1 }, + { 2, 1, 2 }, { 2, 2, 0 }, { 2, 2, 1 }, { 2, 2, 2 }, }; + int[][] val1 = new int[][] { { 0 } }; - BasicMatrix m1 = new BasicMatrix(getFactory(), new int[]{3,3,3}); -// System.out.println("Matrice a 27 valeurs"); + BasicMatrix m1 = new BasicMatrix(getFactory(), new int[] { 3, 3, 3 }); + // System.out.println("Matrice a 27 valeurs"); int cpt = 0; - for(BasicMatrixIterator iter = m1.iterator(); iter.next();){ + for (BasicMatrixIterator iter = m1.iterator(); iter.next();) { Arrays.equals(val27[cpt], iter.getCoordinates()); - cpt ++; + cpt++; } assertEquals(27, cpt); cpt = 0; - BasicMatrix m2 = new BasicMatrix(getFactory(), new int[]{1}); -// System.out.println("Matrice a 1 valeurs"); - for(BasicMatrixIterator iter = m2.iterator(); iter.next();){ - Arrays.equals(val1[cpt], iter.getCoordinates()); - cpt ++; + BasicMatrix m2 = new BasicMatrix(getFactory(), new int[] { 1 }); + // System.out.println("Matrice a 1 valeurs"); + for (BasicMatrixIterator iter = m2.iterator(); iter.next();) { + Arrays.equals(val1[cpt], iter.getCoordinates()); + cpt++; } assertEquals(1, cpt); } - MapFunction f = new MapFunction(){ - public double apply(double value){ + MapFunction f = new MapFunction() { + public double apply(double value) { return value + 2; } }; public void testPerfLineaire() throws Exception { long time = System.nanoTime(); - BasicMatrix m1 = new BasicMatrix(getFactory(), new int[]{30,30,30,30}); + BasicMatrix m1 = new BasicMatrix(getFactory(), new int[] { 30, 30, 30, + 30 }); m1.map(f); long time1 = System.nanoTime(); - System.out.println("testPerfLineaire: " + DurationFormatUtils.formatDuration((time1 - time)/1000000, "s'.'S")); + System.out.println("testPerfLineaire: " + + DurationFormatUtils.formatDuration((time1 - time) / 1000000, + "s'.'S")); } public void testPerfCoordonnee() throws Exception { long time = System.nanoTime(); - BasicMatrix m2 = new BasicMatrix(getFactory(), new int[]{30,30,30,30}); + BasicMatrix m2 = new BasicMatrix(getFactory(), new int[] { 30, 30, 30, + 30 }); BasicMatrixIterator inc = m2.iterator(); - while(inc.next()){ + while (inc.next()) { inc.setValue(inc.getValue() + 2); } long time1 = System.nanoTime(); - System.out.println("testPerfCoordonnee iter: " + DurationFormatUtils.formatDuration((time1 - time)/1000000, "s'.'S")); + System.out.println("testPerfCoordonnee iter: " + + DurationFormatUtils.formatDuration((time1 - time) / 1000000, + "s'.'S")); inc = m2.iterator(); - while(inc.next()){ + while (inc.next()) { inc.setValue(inc.getValue() + 2); } long time2 = System.nanoTime(); - System.out.println("testPerfCoordonnee iter: " + DurationFormatUtils.formatDuration((time2 - time1)/1000000, "s'.'S")); + System.out.println("testPerfCoordonnee iter: " + + DurationFormatUtils.formatDuration((time2 - time1) / 1000000, + "s'.'S")); m2.map(f); long time3 = System.nanoTime(); - System.out.println("testPerfLineaire map: " + DurationFormatUtils.formatDuration((time3 - time2)/1000000, "s'.'S")); + System.out.println("testPerfLineaire map: " + + DurationFormatUtils.formatDuration((time3 - time2) / 1000000, + "s'.'S")); } public void testPerfCoordonnee2() throws Exception { long time = System.nanoTime(); - BasicMatrix m2 = new BasicMatrix(getFactory(), new int[]{30,30,30,30}); + BasicMatrix m2 = new BasicMatrix(getFactory(), new int[] { 30, 30, 30, + 30 }); BasicMatrixIterator inc = m2.iterator(); - while(inc.next() && inc.next()){ + while (inc.next() && inc.next()) { inc.setValue(inc.getValue() + 2); } long time1 = System.nanoTime(); - System.out.println("testPerfCoordonnee2: " + DurationFormatUtils.formatDuration((time1 - time)/1000000, "s'.'S")); + System.out.println("testPerfCoordonnee2: " + + DurationFormatUtils.formatDuration((time1 - time) / 1000000, + "s'.'S")); inc = m2.iterator(); - while(inc.next() && inc.next()){ + while (inc.next() && inc.next()) { inc.setValue(inc.getValue() + 2); } long time2 = System.nanoTime(); - System.out.println("testPerfCoordonnee2 re: " + DurationFormatUtils.formatDuration((time2 - time1)/1000000, "s'.'S")); + System.out.println("testPerfCoordonnee2 re: " + + DurationFormatUtils.formatDuration((time2 - time1) / 1000000, + "s'.'S")); - m2.map(f); long time3 = System.nanoTime(); - System.out.println("testPerfLineaire2: " + DurationFormatUtils.formatDuration((time3 - time2)/1000000, "s'.'S")); + System.out.println("testPerfLineaire2: " + + DurationFormatUtils.formatDuration((time3 - time2) / 1000000, + "s'.'S")); } public void testPerfCoordonnee4() throws Exception { long time = System.nanoTime(); - BasicMatrix m2 = new BasicMatrix(getFactory(), new int[]{30,30,30,30}); + BasicMatrix m2 = new BasicMatrix(getFactory(), new int[] { 30, 30, 30, + 30 }); BasicMatrixIterator inc = m2.iterator(); - while(inc.next() && inc.next() && inc.next() && inc.next()){ + while (inc.next() && inc.next() && inc.next() && inc.next()) { inc.setValue(inc.getValue() + 2); } long time1 = System.nanoTime(); - System.out.println("testPerfCoordonnee4: " + DurationFormatUtils.formatDuration((time1 - time)/1000000, "s'.'S")); + System.out.println("testPerfCoordonnee4: " + + DurationFormatUtils.formatDuration((time1 - time) / 1000000, + "s'.'S")); inc = m2.iterator(); - while(inc.next() && inc.next() && inc.next() && inc.next()){ + while (inc.next() && inc.next() && inc.next() && inc.next()) { inc.setValue(inc.getValue() + 2); } long time2 = System.nanoTime(); - System.out.println("testPerfCoordonnee4 re: " + DurationFormatUtils.formatDuration((time2 - time1)/1000000, "s'.'S")); + System.out.println("testPerfCoordonnee4 re: " + + DurationFormatUtils.formatDuration((time2 - time1) / 1000000, + "s'.'S")); - m2.map(f); long time3 = System.nanoTime(); - System.out.println("testPerfLineaire4: " + DurationFormatUtils.formatDuration((time3 - time2)/1000000, "s'.'S")); + System.out.println("testPerfLineaire4: " + + DurationFormatUtils.formatDuration((time3 - time2) / 1000000, + "s'.'S")); } Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/FloatVectorTest.java =================================================================== --- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/FloatVectorTest.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/FloatVectorTest.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,21 +1,19 @@ -/* *##% - * Copyright (C) 2005 - * Code Lutin, Cédric Pineau, Benjamin Poussin +/* *##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin * - * 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 2 - * of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Lesser Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * * FloatVectorTest.java Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/ImportExportMatrixTest.java =================================================================== --- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/ImportExportMatrixTest.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/ImportExportMatrixTest.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,21 +1,21 @@ /* - * *##% Copyright (C) 2002, 2003, 2004 Code Lutin, Cédric Pineau, Benjamin - * Poussin - * - * 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 2 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, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307, USA. ##% - */ + * *##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ + package org.codelutin.math.matrix; import java.io.IOException; @@ -30,92 +30,97 @@ * Test de l'import et export CSV * * @author ruchaud - * + * */ public class ImportExportMatrixTest extends TestCase { - + private MatrixND mat1D; private MatrixND mat2D; private MatrixND mat2DSemantics; - + public MatrixFactory getFactory() throws Exception { return MatrixFactory.getInstance(DoubleVector.class); } @Override protected void setUp() throws Exception { - mat1D = new MatrixNDImpl(getFactory(), new int[]{10}); - mat1D.setValue(new int[]{0}, 0); - mat1D.setValue(new int[]{1}, 1); - mat1D.setValue(new int[]{2}, 2); - mat1D.setValue(new int[]{3}, 3); - mat1D.setValue(new int[]{4}, -4.0E-7); + mat1D = new MatrixNDImpl(getFactory(), new int[] { 10 }); + mat1D.setValue(new int[] { 0 }, 0); + mat1D.setValue(new int[] { 1 }, 1); + mat1D.setValue(new int[] { 2 }, 2); + mat1D.setValue(new int[] { 3 }, 3); + mat1D.setValue(new int[] { 4 }, -4.0E-7); - mat2D = new MatrixNDImpl(getFactory(), new int[]{20,10}); - mat2D.setValue(new int[]{0, 0}, 0); - mat2D.setValue(new int[]{0, 1}, 1); - mat2D.setValue(new int[]{0, 2}, 2); - mat2D.setValue(new int[]{0, 3}, 3); - mat2D.setValue(new int[]{0, 4}, 4); - mat2D.setValue(new int[]{0, 5}, 4); - mat2D.setValue(new int[]{0, 6}, 4); - mat2D.setValue(new int[]{0, 7}, 4); - mat2D.setValue(new int[]{1, 8}, 4); - mat2D.setValue(new int[]{2, 9}, -4.0E-7); + mat2D = new MatrixNDImpl(getFactory(), new int[] { 20, 10 }); + mat2D.setValue(new int[] { 0, 0 }, 0); + mat2D.setValue(new int[] { 0, 1 }, 1); + mat2D.setValue(new int[] { 0, 2 }, 2); + mat2D.setValue(new int[] { 0, 3 }, 3); + mat2D.setValue(new int[] { 0, 4 }, 4); + mat2D.setValue(new int[] { 0, 5 }, 4); + mat2D.setValue(new int[] { 0, 6 }, 4); + mat2D.setValue(new int[] { 0, 7 }, 4); + mat2D.setValue(new int[] { 1, 8 }, 4); + mat2D.setValue(new int[] { 2, 9 }, -4.0E-7); - List sem1 = Arrays.asList(new String[] { "toto", "titi", "tutu", "trtr" }); + List sem1 = Arrays + .asList(new String[] { "toto", "titi", "tutu", "trtr" }); List sem2 = Arrays.asList(new String[] { "tata", "tete", "tyty" }); - mat2DSemantics = new MatrixNDImpl(getFactory(), "name", - new List[] { sem1, sem2 }, new String[]{"dim1", "dim2"}); + mat2DSemantics = new MatrixNDImpl(getFactory(), "name", new List[] { + sem1, sem2 }, new String[] { "dim1", "dim2" }); } public void testImport() throws IOException { - String test = "5.0E-7;1.0;2.0;3.0;4.0;4.0;4.0;4.0;0.3;0.0\n" + - "0.0;0.0;7.0;0.0;0.0;2.0;0.0;0.0;4.0;0.0\n" + - "0.0;0.0;8.0;1.0;0.0;0.0;0.0;0.0;0.0;4.0\n"; + String test = "5.0E-7;1.0;2.0;3.0;4.0;4.0;4.0;4.0;0.3;0.0\n" + + "0.0;0.0;7.0;0.0;0.0;2.0;0.0;0.0;4.0;0.0\n" + + "0.0;0.0;8.0;1.0;0.0;0.0;0.0;0.0;0.0;4.0\n"; StringReader reader = new StringReader(test); - - mat2D.importCSV(reader, new int[]{0,0}); - assertEquals(mat2D.getValue(0,0), 5.0E-7); - assertEquals(mat2D.getValue(1,2), 7.0); - assertEquals(mat2D.getValue(2,2), 8.0); - assertEquals(mat2D.getValue(1,8), 4.0); + mat2D.importCSV(reader, new int[] { 0, 0 }); + assertEquals(mat2D.getValue(0, 0), 5.0E-7); + assertEquals(mat2D.getValue(1, 2), 7.0); + assertEquals(mat2D.getValue(2, 2), 8.0); + assertEquals(mat2D.getValue(1, 8), 4.0); + reader = new StringReader(test); - mat2D.importCSV(reader, new int[]{1,1}); - assertEquals(mat2D.getValue(1,1), 5.0E-7); - assertEquals(mat2D.getValue(2,3), 7.0); - assertEquals(mat2D.getValue(3,3), 8.0); - assertEquals(mat2D.getValue(2,9), 4.0); + mat2D.importCSV(reader, new int[] { 1, 1 }); + assertEquals(mat2D.getValue(1, 1), 5.0E-7); + assertEquals(mat2D.getValue(2, 3), 7.0); + assertEquals(mat2D.getValue(3, 3), 8.0); + assertEquals(mat2D.getValue(2, 9), 4.0); } - + public void testExport() throws IOException { testExport(mat1D, false); testExport(mat2D, false); testExport(mat1D, true); testExport(mat2D, true); - + testExport(mat2DSemantics, false); testExport(mat2DSemantics, true); } - private void testExport(MatrixND matrixND, boolean withSemantics) throws IOException { + private void testExport(MatrixND matrixND, boolean withSemantics) + throws IOException { StringWriter writer = new StringWriter(); matrixND.exportCSV(writer, withSemantics); - + StringReader writerToReader = new StringReader(writer.toString()); - matrixND.importCSV(writerToReader, new int[]{0,0}); - + matrixND.importCSV(writerToReader, new int[] { 0, 0 }); + StringWriter readerToWriter = new StringWriter(); matrixND.exportCSV(readerToWriter, withSemantics); - + assertEquals(writer.toString(), readerToWriter.toString()); } - + public void testSupport() throws Exception { - assertEquals(true, new MatrixNDImpl(getFactory(), new int[]{1}).isSupportedCSV()); - assertEquals(true, new MatrixNDImpl(getFactory(), new int[]{2,2}).isSupportedCSV()); - assertEquals(false, new MatrixNDImpl(getFactory(), new int[]{3,3,3}).isSupportedCSV()); + assertEquals(true, new MatrixNDImpl(getFactory(), new int[] { 1 }) + .isSupportedCSV()); + assertEquals(true, new MatrixNDImpl(getFactory(), new int[] { 2, 2 }) + .isSupportedCSV()); + assertEquals(false, new MatrixNDImpl(getFactory(), + new int[] { 3, 3, 3 }).isSupportedCSV()); } } Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixEncoderDecoderTest.java =================================================================== --- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixEncoderDecoderTest.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixEncoderDecoderTest.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,21 +1,19 @@ -/* *##% - * Copyright (C) 2002, 2003, 2004 Code Lutin, Cédric Pineau, - * Benjamin Poussin +/* *##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin * - * 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 2 - * of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Lesser Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * * MatrixEncoderDecoderTest.java @@ -39,47 +37,41 @@ * @author poussin * @version $Revision$ * - * Last update : $Date$ - * By : $Author$ + * Last update : $Date$ + * By : $Author$ */ public class MatrixEncoderDecoderTest extends TestCase { // MatrixEncoderDecoderTest - /*public MatrixFactory getFactory() throws Exception { - return MatrixFactory.getInstance(); - } + /* + * public MatrixFactory getFactory() throws Exception { return + * MatrixFactory.getInstance(); } + * + * protected void subtestEncoderDecoder(MatrixND mat) throws Exception { // + * encodage en XML String xml = MatrixHelper.encodeToXML(mat); // decodage + * depuis le XML MatrixND mat2 = MatrixHelper.decodeFromXML(xml); // + * reencodage de la matrice resultat String xml2 = + * MatrixHelper.encodeToXML(mat2); // on verifie que les 2 matrices sont + * egals et leur representation // XML aussi assertEquals(mat, mat2); + * assertEquals(xml, xml2); } + * + * public void testEncoderDecoder() throws Exception { List s1 = + * Arrays.asList(new String[]{"a", "b", "c"}); List s2 = Arrays.asList(new + * String[]{"e", "f", "g"}); List s3 = Arrays.asList(new String[]{"k", "l", + * "m"}); + * + * MatrixND mat = null; + * + * mat = getFactory().create("Ma mat", new int[]{3,3,3}); + * subtestEncoderDecoder(mat); + * + * mat = getFactory().create("Ma mat", new List[]{s1, s2, s3}); + * subtestEncoderDecoder(mat); + * + * // on modifie S1 pour avoir un null au milieu s1.set(1, null); mat = + * getFactory().create("Ma mat", new List[]{s1, s2, s3}, new + * String[]{"dim abc", "dim efg", "dim klm"}); mat.setSemantics(1, + * Collections.nCopies(3, null)); subtestEncoderDecoder(mat); } + */ - protected void subtestEncoderDecoder(MatrixND mat) throws Exception { - // encodage en XML - String xml = MatrixHelper.encodeToXML(mat); - // decodage depuis le XML - MatrixND mat2 = MatrixHelper.decodeFromXML(xml); - // reencodage de la matrice resultat - String xml2 = MatrixHelper.encodeToXML(mat2); - // on verifie que les 2 matrices sont egals et leur representation - // XML aussi - assertEquals(mat, mat2); - assertEquals(xml, xml2); - } - - public void testEncoderDecoder() throws Exception { - List s1 = Arrays.asList(new String[]{"a", "b", "c"}); - List s2 = Arrays.asList(new String[]{"e", "f", "g"}); - List s3 = Arrays.asList(new String[]{"k", "l", "m"}); - - MatrixND mat = null; - - mat = getFactory().create("Ma mat", new int[]{3,3,3}); - subtestEncoderDecoder(mat); - - mat = getFactory().create("Ma mat", new List[]{s1, s2, s3}); - subtestEncoderDecoder(mat); - - // on modifie S1 pour avoir un null au milieu - s1.set(1, null); - mat = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); - mat.setSemantics(1, Collections.nCopies(3, null)); - subtestEncoderDecoder(mat); - }*/ - } // MatrixEncoderDecoderTest Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixHelperTest.java =================================================================== --- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixHelperTest.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixHelperTest.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,21 +1,19 @@ -/* *##% - * Copyright (C) 2002, 2003, 2004 Code Lutin, Cédric Pineau, - * Benjamin Poussin +/* *##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin * - * 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 2 - * of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Lesser Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * * MatrixHelperTest.java @@ -42,65 +40,73 @@ } public void testCoordinatesToString() throws Exception { - assertEquals("1", MatrixHelper.coordinatesToString(new int[]{1})); - assertEquals("2,3,4,5", MatrixHelper.coordinatesToString(new int[]{2,3,4,5})); - assertEquals("2,3,4,5,234", MatrixHelper.coordinatesToString(new int[]{2,3,4,5,234})); + assertEquals("1", MatrixHelper.coordinatesToString(new int[] { 1 })); + assertEquals("2,3,4,5", MatrixHelper.coordinatesToString(new int[] { 2, + 3, 4, 5 })); + assertEquals("2,3,4,5,234", MatrixHelper.coordinatesToString(new int[] { + 2, 3, 4, 5, 234 })); - assertEquals("a", MatrixHelper.coordinatesToString(new String[]{"a"})); - assertEquals("a,b,n,m", MatrixHelper.coordinatesToString(new String[]{"a","b","n","m"})); - assertEquals("a,b,f,e,aze", MatrixHelper.coordinatesToString(new String[]{"a","b","f","e","aze"})); + assertEquals("a", MatrixHelper + .coordinatesToString(new String[] { "a" })); + assertEquals("a,b,n,m", MatrixHelper.coordinatesToString(new String[] { + "a", "b", "n", "m" })); + assertEquals("a,b,f,e,aze", + MatrixHelper.coordinatesToString(new String[] { "a", "b", "f", + "e", "aze" })); } - public void testSameDimension()throws Exception { - assertTrue(MatrixHelper.sameDimension(new int[]{1}, new int[]{1})); - assertTrue(MatrixHelper.sameDimension(new int[]{1,2}, new int[]{1,2})); - assertTrue(MatrixHelper.sameDimension(new int[]{1,324,3}, new int[]{1,324,3})); + public void testSameDimension() throws Exception { + assertTrue(MatrixHelper.sameDimension(new int[] { 1 }, new int[] { 1 })); + assertTrue(MatrixHelper.sameDimension(new int[] { 1, 2 }, new int[] { + 1, 2 })); + assertTrue(MatrixHelper.sameDimension(new int[] { 1, 324, 3 }, + new int[] { 1, 324, 3 })); } - public void testDimensionToSemantics()throws Exception { + public void testDimensionToSemantics() throws Exception { // TODO faire un test pour dimensionToSemantics } - public void testSemanticsToDimension()throws Exception { + public void testSemanticsToDimension() throws Exception { // TODO faire un test pour semanticsToDimension } public void testFill() throws Exception { - MatrixND mat = getFactory().create(new int[]{3, 3}); + MatrixND mat = getFactory().create(new int[] { 3, 3 }); MatrixHelper.fill(mat, 4); - assertEquals(4, mat.getValue(1,1), 0); + assertEquals(4, mat.getValue(1, 1), 0); } public void testMatrixId() throws Exception { MatrixND mat = getFactory().matrixId(4); - assertTrue(MatrixHelper.sameDimension(new int[]{4,4}, mat.getDim())); - assertEquals(0, mat.getValue(1,2), 0); - assertEquals(1, mat.getValue(0,0), 0); - assertEquals(1, mat.getValue(1,1), 0); - assertEquals(1, mat.getValue(2,2), 0); - assertEquals(1, mat.getValue(3,3), 0); + assertTrue(MatrixHelper.sameDimension(new int[] { 4, 4 }, mat.getDim())); + assertEquals(0, mat.getValue(1, 2), 0); + assertEquals(1, mat.getValue(0, 0), 0); + assertEquals(1, mat.getValue(1, 1), 0); + assertEquals(1, mat.getValue(2, 2), 0); + assertEquals(1, mat.getValue(3, 3), 0); } public void testToList() throws Exception { - MatrixND mat1 = getFactory().create(new int[]{3, 2, 1}); + MatrixND mat1 = getFactory().create(new int[] { 3, 2, 1 }); mat1.setValue(0, 0, 0, -1.0E-7); mat1.setValue(1, 1, 0, 2); mat1.setValue(2, 1, 0, 5.0E-7); - List l = mat1.toList(); + List l = mat1.toList(); String s = String.valueOf(l); List l2 = MatrixHelper.convertStringToList(s); - + System.out.println(l); System.out.println(l2); - + assertEquals(l, l2); } - + public void testMaxOccurence() throws Exception { - double [] val = new double[5]; + double[] val = new double[5]; assertEquals(0, MatrixHelper.maxOccurence(val), 0); @@ -132,12 +138,11 @@ val[5] = -3; assertEquals(-3, MatrixHelper.maxOccurence(val), 0); - val = new double[0]; - try{ + try { MatrixHelper.maxOccurence(val); assertFalse(true); // on ne passe pas ici - }catch(IllegalArgumentException eee){ + } catch (IllegalArgumentException eee) { assertTrue(true); // on passe ici } Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java =================================================================== --- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,31 +1,30 @@ -/* *##% -* Copyright (C) 2002, 2003 Code Lutin -* -* 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 2 -* 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, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*##%*/ +/* *##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * -* AppTestCase.java -* -* Created: 10 mai 2004 -* -* @version $Revision$ -* -* Mise a jour: $Date$ -* par : $Author$ -*/ + * AppTestCase.java + * + * Created: 10 mai 2004 + * + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ package org.codelutin.math.matrix; @@ -37,11 +36,11 @@ import java.util.List; import java.util.Stack; +import junit.framework.TestCase; + import org.apache.commons.lang.time.DurationFormatUtils; import org.codelutin.util.StringUtil; -import junit.framework.TestCase; - public class MatrixNDTest extends TestCase { public MatrixFactory getFactory() throws Exception { @@ -49,33 +48,34 @@ } public void testNew() throws Exception { - List s1 = Arrays.asList(new String[]{"a", "b", "c"}); - List s2 = Arrays.asList(new String[]{"e", "f", "g"}); - List s3 = Arrays.asList(new String[]{"k", "l", "m"}); + List s1 = Arrays.asList(new String[] { "a", "b", "c" }); + List s2 = Arrays.asList(new String[] { "e", "f", "g" }); + List s3 = Arrays.asList(new String[] { "k", "l", "m" }); MatrixND mat = null; - mat = getFactory().create("Ma mat", new int[]{3,3,3}); + mat = getFactory().create("Ma mat", new int[] { 3, 3, 3 }); - mat = getFactory().create("Ma mat", new List[]{s1, s2, s3}); + mat = getFactory().create("Ma mat", new List[] { s1, s2, s3 }); - mat = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + mat = getFactory().create("Ma mat", new List[] { s1, s2, s3 }, + new String[] { "dim abc", "dim efg", "dim klm" }); assertEquals(0.0, mat.getMaxOccurence()); } public void testSemantique() throws Exception { - List s1 = Arrays.asList(new String[]{"a", "b", "c"}); - List s2 = Arrays.asList(new String[]{"e", "f", "g"}); - List s3 = Arrays.asList(new String[]{"k", "l", "m"}); + List s1 = Arrays.asList(new String[] { "a", "b", "c" }); + List s2 = Arrays.asList(new String[] { "e", "f", "g" }); + List s3 = Arrays.asList(new String[] { "k", "l", "m" }); MatrixND mat = null; - mat = getFactory().create(new int[]{3,3,3}); + mat = getFactory().create(new int[] { 3, 3, 3 }); assertTrue(null == mat.getSemantics(1).get(1)); - mat = getFactory().create("Ma mat", new List[]{s1, s2, s3}); + mat = getFactory().create("Ma mat", new List[] { s1, s2, s3 }); // la matrice doit avoir ca propre copie des semantiques s2.set(1, "pas bon"); @@ -86,13 +86,14 @@ } public void testName() throws Exception { - List s1 = Arrays.asList(new String[]{"a", "b", "c"}); - List s2 = Arrays.asList(new String[]{"e", "f", "g"}); - List s3 = Arrays.asList(new String[]{"k", "l", "m"}); + List s1 = Arrays.asList(new String[] { "a", "b", "c" }); + List s2 = Arrays.asList(new String[] { "e", "f", "g" }); + List s3 = Arrays.asList(new String[] { "k", "l", "m" }); MatrixND mat = null; - mat = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + mat = getFactory().create("Ma mat", new List[] { s1, s2, s3 }, + new String[] { "dim abc", "dim efg", "dim klm" }); assertEquals("Ma mat", mat.getName()); mat.setName("Renamed"); @@ -104,15 +105,16 @@ } public void testGetSet() throws Exception { - List s1 = Arrays.asList(new String[]{"a", "b", "c"}); - List s2 = Arrays.asList(new String[]{"e", "f", "g"}); - List s3 = Arrays.asList(new String[]{"k", "l", "m"}); + List s1 = Arrays.asList(new String[] { "a", "b", "c" }); + List s2 = Arrays.asList(new String[] { "e", "f", "g" }); + List s3 = Arrays.asList(new String[] { "k", "l", "m" }); MatrixND mat = null; - mat = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + mat = getFactory().create("Ma mat", new List[] { s1, s2, s3 }, + new String[] { "dim abc", "dim efg", "dim klm" }); - mat.setValue(1,1,1, 34); + mat.setValue(1, 1, 1, 34); assertEquals(34, mat.getValue("b", "f", "l"), 0); mat.setValue("a", "f", "m", 22); @@ -120,128 +122,102 @@ } public void testIterator() throws Exception { - int [][] val27 = new int[][]{ - {0,0,0}, - {0,0,1}, - {0,0,2}, - {0,1,0}, - {0,1,1}, - {0,1,2}, - {0,2,0}, - {0,2,1}, - {0,2,2}, - {1,0,0}, - {1,0,1}, - {1,0,2}, - {1,1,0}, - {1,1,1}, - {1,1,2}, - {1,2,0}, - {1,2,1}, - {1,2,2}, - {2,0,0}, - {2,0,1}, - {2,0,2}, - {2,1,0}, - {2,1,1}, - {2,1,2}, - {2,2,0}, - {2,2,1}, - {2,2,2}, - }; + int[][] val27 = new int[][] { { 0, 0, 0 }, { 0, 0, 1 }, { 0, 0, 2 }, + { 0, 1, 0 }, { 0, 1, 1 }, { 0, 1, 2 }, { 0, 2, 0 }, + { 0, 2, 1 }, { 0, 2, 2 }, { 1, 0, 0 }, { 1, 0, 1 }, + { 1, 0, 2 }, { 1, 1, 0 }, { 1, 1, 1 }, { 1, 1, 2 }, + { 1, 2, 0 }, { 1, 2, 1 }, { 1, 2, 2 }, { 2, 0, 0 }, + { 2, 0, 1 }, { 2, 0, 2 }, { 2, 1, 0 }, { 2, 1, 1 }, + { 2, 1, 2 }, { 2, 2, 0 }, { 2, 2, 1 }, { 2, 2, 2 }, }; - String [][] vals27 = new String[][]{ - {"a","e","k"}, - {"a","e","l"}, - {"a","e","m"}, - {"a","f","k"}, - {"a","f","l"}, - {"a","f","m"}, - {"a","g","k"}, - {"a","g","l"}, - {"a","g","m"}, - {"b","e","k"}, - {"b","e","l"}, - {"b","e","m"}, - {"b","f","k"}, - {"b","f","l"}, - {"b","f","m"}, - {"b","g","k"}, - {"b","g","l"}, - {"b","g","m"}, - {"c","e","k"}, - {"c","e","l"}, - {"c","e","m"}, - {"c","f","k"}, - {"c","f","l"}, - {"c","f","m"}, - {"c","g","k"}, - {"c","g","l"}, - {"c","g","m"}, - }; + String[][] vals27 = new String[][] { { "a", "e", "k" }, + { "a", "e", "l" }, { "a", "e", "m" }, { "a", "f", "k" }, + { "a", "f", "l" }, { "a", "f", "m" }, { "a", "g", "k" }, + { "a", "g", "l" }, { "a", "g", "m" }, { "b", "e", "k" }, + { "b", "e", "l" }, { "b", "e", "m" }, { "b", "f", "k" }, + { "b", "f", "l" }, { "b", "f", "m" }, { "b", "g", "k" }, + { "b", "g", "l" }, { "b", "g", "m" }, { "c", "e", "k" }, + { "c", "e", "l" }, { "c", "e", "m" }, { "c", "f", "k" }, + { "c", "f", "l" }, { "c", "f", "m" }, { "c", "g", "k" }, + { "c", "g", "l" }, { "c", "g", "m" }, }; - List s1 = Arrays.asList(new String[]{"a", "b", "c"}); - List s2 = Arrays.asList(new String[]{"e", "f", "g"}); - List s3 = Arrays.asList(new String[]{"k", "l", "m"}); + List s1 = Arrays.asList(new String[] { "a", "b", "c" }); + List s2 = Arrays.asList(new String[] { "e", "f", "g" }); + List s3 = Arrays.asList(new String[] { "k", "l", "m" }); MatrixND mat = null; - mat = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + mat = getFactory().create("Ma mat", new List[] { s1, s2, s3 }, + new String[] { "dim abc", "dim efg", "dim klm" }); int cpt = 0; - for(MatrixIterator i=mat.iterator(); i.hasNext();){ + for (MatrixIterator i = mat.iterator(); i.hasNext();) { i.next(); assertTrue(Arrays.equals(val27[cpt], i.getCoordinates())); assertTrue(Arrays.equals(vals27[cpt], i.getSemanticsCoordinates())); - cpt ++; + cpt++; } assertEquals(27, cpt); } public void testAdd() throws Exception { - List s1 = Arrays.asList(new String[]{"a", "b", "c"}); - List s2 = Arrays.asList(new String[]{"e", "f", "g"}); - List s3 = Arrays.asList(new String[]{"k", "l", "m"}); + List s1 = Arrays.asList(new String[] { "a", "b", "c" }); + List s2 = Arrays.asList(new String[] { "e", "f", "g" }); + List s3 = Arrays.asList(new String[] { "k", "l", "m" }); - MatrixND mat1 = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); - MatrixND mat2 = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + MatrixND mat1 = getFactory().create("Ma mat", + new List[] { s1, s2, s3 }, + new String[] { "dim abc", "dim efg", "dim klm" }); + MatrixND mat2 = getFactory().create("Ma mat", + new List[] { s1, s2, s3 }, + new String[] { "dim abc", "dim efg", "dim klm" }); MatrixHelper.fill(mat1, 3); MatrixHelper.fill(mat2, 26); mat1.add(mat2); - assertEquals(29, mat1.getValue(0,0,0), 0); - assertEquals(29, mat1.getValue(1,2,0), 0); - assertEquals(29, mat1.getValue(2,2,2), 0); + assertEquals(29, mat1.getValue(0, 0, 0), 0); + assertEquals(29, mat1.getValue(1, 2, 0), 0); + assertEquals(29, mat1.getValue(2, 2, 2), 0); } public void testMinus() throws Exception { - List s1 = Arrays.asList(new String[]{"a", "b", "c"}); - List s2 = Arrays.asList(new String[]{"e", "f", "g"}); - List s3 = Arrays.asList(new String[]{"k", "l", "m"}); + List s1 = Arrays.asList(new String[] { "a", "b", "c" }); + List s2 = Arrays.asList(new String[] { "e", "f", "g" }); + List s3 = Arrays.asList(new String[] { "k", "l", "m" }); - MatrixND mat1 = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); - MatrixND mat2 = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + MatrixND mat1 = getFactory().create("Ma mat", + new List[] { s1, s2, s3 }, + new String[] { "dim abc", "dim efg", "dim klm" }); + MatrixND mat2 = getFactory().create("Ma mat", + new List[] { s1, s2, s3 }, + new String[] { "dim abc", "dim efg", "dim klm" }); MatrixHelper.fill(mat1, 3); MatrixHelper.fill(mat2, 26); mat1.minus(mat2); - assertEquals(-23, mat1.getValue(0,0,0), 0); - assertEquals(-23, mat1.getValue(1,2,0), 0); - assertEquals(-23, mat1.getValue(2,2,2), 0); + assertEquals(-23, mat1.getValue(0, 0, 0), 0); + assertEquals(-23, mat1.getValue(1, 2, 0), 0); + assertEquals(-23, mat1.getValue(2, 2, 2), 0); } public void testEquals() throws Exception { - List s1 = Arrays.asList(new String[]{"a", "b", "c"}); - List s2 = Arrays.asList(new String[]{"e", "f", "g"}); - List s3 = Arrays.asList(new String[]{"k", "l", "m"}); + List s1 = Arrays.asList(new String[] { "a", "b", "c" }); + List s2 = Arrays.asList(new String[] { "e", "f", "g" }); + List s3 = Arrays.asList(new String[] { "k", "l", "m" }); - MatrixND mat1 = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); - MatrixND mat2 = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); - MatrixND mat3 = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + MatrixND mat1 = getFactory().create("Ma mat", + new List[] { s1, s2, s3 }, + new String[] { "dim abc", "dim efg", "dim klm" }); + MatrixND mat2 = getFactory().create("Ma mat", + new List[] { s1, s2, s3 }, + new String[] { "dim abc", "dim efg", "dim klm" }); + MatrixND mat3 = getFactory().create("Ma mat", + new List[] { s1, s2, s3 }, + new String[] { "dim abc", "dim efg", "dim klm" }); MatrixHelper.fill(mat1, 3); MatrixHelper.fill(mat2, 26); @@ -253,17 +229,16 @@ } public void testsumOverDim() throws Exception { - List s1 = Arrays.asList(new String[]{"a", "b", "c"}); - List s2 = Arrays.asList(new String[]{"e", "f", "g"}); - List s3 = Arrays.asList(new String[]{"k", "l", "m"}); + List s1 = Arrays.asList(new String[] { "a", "b", "c" }); + List s2 = Arrays.asList(new String[] { "e", "f", "g" }); + List s3 = Arrays.asList(new String[] { "k", "l", "m" }); MatrixND mat = null; - - mat = getFactory().create(new int[]{4,4}); + mat = getFactory().create(new int[] { 4, 4 }); MatrixND mat2 = mat; - int i=0; - for(MatrixIterator mi=mat.iterator(); mi.next();){ + int i = 0; + for (MatrixIterator mi = mat.iterator(); mi.next();) { mi.setValue(++i); } @@ -297,23 +272,22 @@ assertEquals(42, mat2.getValue(2, 0), 0); assertEquals(58, mat2.getValue(3, 0), 0); + mat = getFactory().create("Ma mat", new List[] { s1, s2, s3 }, + new String[] { "dim abc", "dim efg", "dim klm" }); - mat = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); - MatrixHelper.fill(mat, 3); mat.setValue(0, 0, 0, 2); mat.setValue(2, 2, 2, 4); mat = mat.sumOverDim(1); - assertTrue(MatrixHelper.sameDimension(new int[]{3,1,3}, mat.getDim())); + assertTrue(MatrixHelper.sameDimension(new int[] { 3, 1, 3 }, mat + .getDim())); - assertEquals(8, mat.getValue(0,0,0), 0); - assertEquals(9, mat.getValue(2,0,1), 0); - assertEquals(10, mat.getValue(2,0,2), 0); + assertEquals(8, mat.getValue(0, 0, 0), 0); + assertEquals(9, mat.getValue(2, 0, 1), 0); + assertEquals(10, mat.getValue(2, 0, 2), 0); + mat = getFactory().create(new int[] { 6, 6, 6 }); - - mat = getFactory().create(new int[]{6,6,6}); - MatrixHelper.fill(mat, 3); mat.setValue(0, 0, 0, 0); mat.setValue(0, 1, 0, 1); @@ -323,17 +297,18 @@ mat.setValue(0, 5, 0, 5); mat = mat.sumOverDim(1, 3); - assertTrue(MatrixHelper.sameDimension(new int[]{6,2,6}, mat.getDim())); - assertEquals(3, mat.getValue(0,0,0), 0); - assertEquals(12, mat.getValue(0,1,0), 0); - assertEquals(9, mat.getValue(1,1,5), 0); - assertEquals(9, mat.getValue(5,0,3), 0); + assertTrue(MatrixHelper.sameDimension(new int[] { 6, 2, 6 }, mat + .getDim())); + assertEquals(3, mat.getValue(0, 0, 0), 0); + assertEquals(12, mat.getValue(0, 1, 0), 0); + assertEquals(9, mat.getValue(1, 1, 5), 0); + assertEquals(9, mat.getValue(5, 0, 3), 0); } public void testTranspose() throws Exception { MatrixND mat = null; - mat = getFactory().create(new int[]{2,4}); + mat = getFactory().create(new int[] { 2, 4 }); mat.setValue(1, 3, 56); mat.setValue(0, 2, 34); mat.setValue(0, 1, 64); @@ -345,7 +320,7 @@ assertEquals(64, mat.getValue(1, 0), 0); assertEquals(46, mat.getValue(0, 1), 0); - mat = getFactory().create(new int[]{4}); + mat = getFactory().create(new int[] { 4 }); mat.setValue(1, 56); mat.setValue(2, 34); mat.setValue(3, 64); @@ -359,12 +334,16 @@ } public void testMults() throws Exception { - List s1 = Arrays.asList(new String[]{"a", "b", "c"}); - List s2 = Arrays.asList(new String[]{"e", "f", "g"}); - List s3 = Arrays.asList(new String[]{"k", "l", "m"}); + List s1 = Arrays.asList(new String[] { "a", "b", "c" }); + List s2 = Arrays.asList(new String[] { "e", "f", "g" }); + List s3 = Arrays.asList(new String[] { "k", "l", "m" }); - MatrixND mat1 = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); - MatrixND mat2 = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + MatrixND mat1 = getFactory().create("Ma mat", + new List[] { s1, s2, s3 }, + new String[] { "dim abc", "dim efg", "dim klm" }); + MatrixND mat2 = getFactory().create("Ma mat", + new List[] { s1, s2, s3 }, + new String[] { "dim abc", "dim efg", "dim klm" }); MatrixHelper.fill(mat1, 3); MatrixHelper.fill(mat2, 26); @@ -372,23 +351,27 @@ mat1.mults(3); mat2.mults(0); - assertEquals(9, mat1.getValue(0,0,0), 0); - assertEquals(9, mat1.getValue(1,2,0), 0); - assertEquals(0, mat2.getValue(2,2,2), 0); + assertEquals(9, mat1.getValue(0, 0, 0), 0); + assertEquals(9, mat1.getValue(1, 2, 0), 0); + assertEquals(0, mat2.getValue(2, 2, 2), 0); - MatrixND mat0 = getFactory().create(new int[]{4,4}); + MatrixND mat0 = getFactory().create(new int[] { 4, 4 }); MatrixND matId = getFactory().matrixId(4); matId.mults(0); assertEquals(mat0, matId); } public void testDivs() throws Exception { - List s1 = Arrays.asList(new String[]{"a", "b", "c"}); - List s2 = Arrays.asList(new String[]{"e", "f", "g"}); - List s3 = Arrays.asList(new String[]{"k", "l", "m"}); + List s1 = Arrays.asList(new String[] { "a", "b", "c" }); + List s2 = Arrays.asList(new String[] { "e", "f", "g" }); + List s3 = Arrays.asList(new String[] { "k", "l", "m" }); - MatrixND mat1 = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); - MatrixND mat2 = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + MatrixND mat1 = getFactory().create("Ma mat", + new List[] { s1, s2, s3 }, + new String[] { "dim abc", "dim efg", "dim klm" }); + MatrixND mat2 = getFactory().create("Ma mat", + new List[] { s1, s2, s3 }, + new String[] { "dim abc", "dim efg", "dim klm" }); MatrixHelper.fill(mat1, 3); MatrixHelper.fill(mat2, 26); @@ -396,62 +379,60 @@ mat1.divs(3); mat2.divs(4); - assertEquals(1, mat1.getValue(0,0,0), 0); - assertEquals(6.5, mat2.getValue(1,2,0), 0); - assertEquals(6.5, mat2.getValue(2,2,2), 0); + assertEquals(1, mat1.getValue(0, 0, 0), 0); + assertEquals(6.5, mat2.getValue(1, 2, 0), 0); + assertEquals(6.5, mat2.getValue(2, 2, 2), 0); } public void testPaste() throws Exception { - MatrixND mat1 = getFactory().create(new int[]{6, 7, 8}); - MatrixND mat2 = getFactory().create(new int[]{2, 2, 2}); + MatrixND mat1 = getFactory().create(new int[] { 6, 7, 8 }); + MatrixND mat2 = getFactory().create(new int[] { 2, 2, 2 }); MatrixHelper.fill(mat1, 3); MatrixHelper.fill(mat2, 26); - mat1.paste(new int[]{3, 0, 4}, mat2); + mat1.paste(new int[] { 3, 0, 4 }, mat2); - assertEquals(3, mat1.getValue(0,0,0), 0); - assertEquals(26, mat1.getValue(3,0,4), 0); - assertEquals(26, mat1.getValue(4,1,5), 0); - assertEquals(3, mat1.getValue(5,2,6), 0); + assertEquals(3, mat1.getValue(0, 0, 0), 0); + assertEquals(26, mat1.getValue(3, 0, 4), 0); + assertEquals(26, mat1.getValue(4, 1, 5), 0); + assertEquals(3, mat1.getValue(5, 2, 6), 0); } public void testSumOverDim() throws Exception { MatrixND mat = null; - mat = getFactory().create(new int[]{6, 7}); - MatrixND result = getFactory().create(new int[]{3, 7}); - + mat = getFactory().create(new int[] { 6, 7 }); + MatrixND result = getFactory().create(new int[] { 3, 7 }); + MatrixHelper.fill(mat, 3); MatrixND sub = mat.getSubMatrix(0, 0, 1); - result.paste(new int[]{0,0}, sub.sumOverDim(0)); + result.paste(new int[] { 0, 0 }, sub.sumOverDim(0)); sub = mat.getSubMatrix(0, 1, 3); - result.paste(new int[]{1,0}, sub.sumOverDim(0)); + result.paste(new int[] { 1, 0 }, sub.sumOverDim(0)); sub = mat.getSubMatrix(0, 4, 2); - result.paste(new int[]{2,0}, sub.sumOverDim(0)); - - mat = getFactory().create(new int[]{6, 7}); + result.paste(new int[] { 2, 0 }, sub.sumOverDim(0)); + + mat = getFactory().create(new int[] { 6, 7 }); MatrixHelper.fill(mat, 3); - - - + mat = mat.sumOverDim(0, 0, 1); mat = mat.sumOverDim(0, 1, 3); mat = mat.sumOverDim(0, 2, 2); - + assertTrue(result.equalsValues(mat)); } - + public void testReduce() throws Exception { MatrixND mat = null; - mat = getFactory().create(new int[]{6, 7, 8}); + mat = getFactory().create(new int[] { 6, 7, 8 }); MatrixHelper.fill(mat, 3); mat = mat.sumOverDim(1); @@ -463,8 +444,7 @@ assertEquals(21, mat.getValue(0, 0), 0); assertEquals(21, mat.getValue(5, 7), 0); - - mat = getFactory().create(new int[]{2, 2, 2}); + mat = getFactory().create(new int[] { 2, 2, 2 }); MatrixHelper.fill(mat, 26); mat = mat.sumOverDim(1); @@ -476,8 +456,7 @@ assertEquals(104, mat.getValue(0), 0); assertEquals(104, mat.getValue(1), 0); - - mat = getFactory().create(new int[]{2, 2, 2}); + mat = getFactory().create(new int[] { 2, 2, 2 }); MatrixHelper.fill(mat, 6); mat = mat.sumOverDim(1); @@ -489,9 +468,7 @@ assertEquals(1, mat.getDim(0)); assertEquals(48, mat.getValue(0), 0); - - - mat = getFactory().create(new int[]{6, 7, 8}); + mat = getFactory().create(new int[] { 6, 7, 8 }); MatrixHelper.fill(mat, 3); mat = mat.sumOverDim(1); @@ -503,8 +480,7 @@ assertEquals(21, mat.getValue(0, 0), 0); assertEquals(21, mat.getValue(5, 7), 0); - - mat = getFactory().create(new int[]{2, 2, 2}); + mat = getFactory().create(new int[] { 2, 2, 2 }); MatrixHelper.fill(mat, 26); mat = mat.sumOverDim(1); @@ -517,8 +493,7 @@ assertEquals(104, mat.getValue(0, 0), 0); assertEquals(104, mat.getValue(0, 1), 0); - - mat = getFactory().create(new int[]{2, 2, 2}); + mat = getFactory().create(new int[] { 2, 2, 2 }); MatrixHelper.fill(mat, 6); mat = mat.sumOverDim(1); @@ -532,14 +507,13 @@ assertEquals(1, mat.getDim(2)); assertEquals(48, mat.getValue(0, 0, 0), 0); - } - + public void testReduceDims() throws Exception { MatrixND mat = null; - mat = getFactory().create(new int[]{6, 7, 8}); + mat = getFactory().create(new int[] { 6, 7, 8 }); MatrixHelper.fill(mat, 3); mat = mat.sumOverDim(1); @@ -551,35 +525,31 @@ assertEquals(21, mat.getValue(0, 0), 0); assertEquals(21, mat.getValue(5, 7), 0); - - mat = getFactory().create(new int[]{2, 2, 2}); + mat = getFactory().create(new int[] { 2, 2, 2 }); MatrixHelper.fill(mat, 26); mat = mat.sumOverDim(1); mat = mat.sumOverDim(0); assertEquals(104, mat.getValue(0, 0, 0), 0); - mat = mat.reduceDims(1,0); + mat = mat.reduceDims(1, 0); assertEquals(1, mat.getNbDim()); assertEquals(2, mat.getDim(0)); assertEquals(104, mat.getValue(0), 0); assertEquals(104, mat.getValue(1), 0); - - mat = getFactory().create(new int[]{2, 2, 2}); + mat = getFactory().create(new int[] { 2, 2, 2 }); MatrixHelper.fill(mat, 6); mat = mat.sumOverDim(1); mat = mat.sumOverDim(2); mat = mat.sumOverDim(0); assertEquals(48, mat.getValue(0, 0, 0), 0); - mat = mat.reduceDims(1,2,0); + mat = mat.reduceDims(1, 2, 0); assertEquals(1, mat.getNbDim()); assertEquals(1, mat.getDim(0)); assertEquals(48, mat.getValue(0), 0); - - - mat = getFactory().create(new int[]{6, 7, 8}); + mat = getFactory().create(new int[] { 6, 7, 8 }); MatrixHelper.fill(mat, 3); mat = mat.sumOverDim(1); @@ -592,8 +562,7 @@ assertEquals(21, mat.getValue(0, 0, 0), 0); assertEquals(21, mat.getValue(5, 0, 7), 0); - - mat = getFactory().create(new int[]{2, 2, 2}); + mat = getFactory().create(new int[] { 2, 2, 2 }); MatrixHelper.fill(mat, 26); mat = mat.sumOverDim(1); @@ -606,8 +575,7 @@ assertEquals(104, mat.getValue(0, 0), 0); assertEquals(104, mat.getValue(0, 1), 0); - - mat = getFactory().create(new int[]{2, 2, 2}); + mat = getFactory().create(new int[] { 2, 2, 2 }); MatrixHelper.fill(mat, 6); mat = mat.sumOverDim(1); @@ -619,64 +587,63 @@ assertEquals(1, mat.getDim(0)); assertEquals(48, mat.getValue(0), 0); - } - - public void testToList() throws Exception { - MatrixND mat1 = getFactory().create(new int[]{3, 2, 1}); + + public void testToList() throws Exception { + MatrixND mat1 = getFactory().create(new int[] { 3, 2, 1 }); mat1.setValue(0, 0, 0, 1.0E-7); mat1.setValue(1, 1, 0, 2); mat1.setValue(2, 1, 0, 5.0E-7); List l = mat1.toList(); System.out.println(l); - - MatrixND mat2 = getFactory().create(new int[]{3, 2, 1}); + + MatrixND mat2 = getFactory().create(new int[] { 3, 2, 1 }); mat2.fromList(l); - + System.out.println(mat1); System.out.println(mat2); - + assertEquals(mat1, mat2); - + String s = String.valueOf(l); List l2 = convertStringToList2(s); List l1 = convertStringToList1(s); List l0 = convertStringToList0(s); - + System.out.println(l); System.out.println(l2); System.out.println(l1); System.out.println(l0); // implatation fausse - + assertEquals(l, l2); - + int MAX = 10000; int dummy = 0; - { + { long timeStart = System.nanoTime(); - for (int i=0; i<MAX; i++) { + for (int i = 0; i < MAX; i++) { List tmp = convertStringToList1(s); dummy += tmp.size(); } long time = System.nanoTime() - timeStart; time = time / 1000000; - System.out.println(MAX +" call to convertStringToList time: " + DurationFormatUtils.formatDuration(time, "s'.'S")); + System.out.println(MAX + " call to convertStringToList time: " + + DurationFormatUtils.formatDuration(time, "s'.'S")); } { long timeStart = System.nanoTime(); - for (int i=0; i<MAX; i++) { + for (int i = 0; i < MAX; i++) { List tmp = convertStringToList2(s); dummy += tmp.size(); } long time = System.nanoTime() - timeStart; time = time / 1000000; - System.out.println(MAX +" call to convertStringToList2 time: " + DurationFormatUtils.formatDuration(time, "s'.'S")); + System.out.println(MAX + " call to convertStringToList2 time: " + + DurationFormatUtils.formatDuration(time, "s'.'S")); } System.out.println("dummy: " + dummy); } - - - + /** * implantation peut performante */ @@ -684,9 +651,9 @@ List result = new ArrayList(); s = s.trim(); if (s.startsWith("[") && s.endsWith("]")) { - s = s.substring(1, s.length() -1); + s = s.substring(1, s.length() - 1); } - String [] las = StringUtil.split(s, ","); + String[] las = StringUtil.split(s, ","); for (String l : las) { l = l.trim(); if (l.startsWith("[")) { @@ -700,20 +667,21 @@ } return result; } - + /** * implantation utilisé actuellement dans MatrixHelper */ static public List convertStringToList2(String s) { List result = null; Stack<List> stack = new Stack<List>(); - StringBuffer number = new StringBuffer(20); // initial to 20 char - - for (int i=0; i<s.length(); i++) { + StringBuffer number = new StringBuffer(20); // initial to 20 char + + for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c == ' ') { // skip space - }if (c == '[') { + } + if (c == '[') { stack.push(new ArrayList()); } else if (c == ',') { if (number.length() != 0) { @@ -723,7 +691,7 @@ stack.peek().add(value); } number.setLength(0); - } else if (c == ']'){ + } else if (c == ']') { // fin d'une liste, il doit rester un nombre dans number // a mois que la liste etait vide if (number.length() != 0) { @@ -739,7 +707,7 @@ stack.peek().add(current); } } else { - // pas un '[' ou ']', pas une ',' devrait etre + // pas un '[' ou ']', pas une ',' devrait etre // un bout du nombre, si c un espace qui traine n'importe ou // c pas grace car Double.valueOf gere les espaces number.append(c); @@ -747,21 +715,21 @@ } return result; } - + /** * implantation fausse pour les nombres 5.0E-7 */ static public List convertStringToList0(String s) throws IOException { List result = null; Stack<List> stack = new Stack<List>(); - StringBuffer number = new StringBuffer(20); // initial to 20 char + StringBuffer number = new StringBuffer(20); // initial to 20 char StreamTokenizer tok = new StreamTokenizer(new StringReader(s)); int v = tok.nextToken(); while (v != StreamTokenizer.TT_EOF) { if (v == '[') { stack.push(new ArrayList()); - } else if (v == ']'){ + } else if (v == ']') { List current = stack.pop(); if (stack.empty()) { result = current; @@ -776,7 +744,5 @@ } return result; } - - } Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/PerfTest.java =================================================================== --- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/PerfTest.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/PerfTest.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,21 +1,19 @@ -/* *##% - * Copyright (C) 2006 - * Code Lutin, Cédric Pineau, Benjamin Poussin +/* *##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin * - * 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 2 - * of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Lesser Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * * PerfTest.java @@ -38,398 +36,430 @@ import org.apache.commons.lang.time.DurationFormatUtils; - /** * @author poussin - * + * */ public class PerfTest extends TestCase { static char CMAX = 'j'; static int MAX = 10; - - public void testDoubleVectorIterator() throws Exception { + + public void testDoubleVectorIterator() throws Exception { List sem = new ArrayList(); - for (char c='a'; c<=CMAX; c++) { - for (int i=1; i<=MAX; i++) { + for (char c = 'a'; c <= CMAX; c++) { + for (int i = 1; i <= MAX; i++) { sem.add(c + " " + i); - } + } } - + MatrixND mat = null; // [ 2600 x 2600 x 2600 ] long timestart = System.nanoTime(); - mat = MatrixFactory.getInstance(DoubleVector.class).create("Ma mat", new List[]{sem, sem, sem}); + mat = MatrixFactory.getInstance(DoubleVector.class).create("Ma mat", + new List[] { sem, sem, sem }); long timeinit = System.nanoTime(); // parcours avec iterator long cpt = 1; - for (MatrixIterator i=mat.iterator(); i.hasNext();) { + for (MatrixIterator i = mat.iterator(); i.hasNext();) { i.next(); i.setValue(cpt++); - } + } long timeend = System.nanoTime(); - - System.out.println("Iterator DoubleVector init: " + DurationFormatUtils.formatDuration((timeinit-timestart)/1000000, "s'.'S") + - " fill: " + DurationFormatUtils.formatDuration((timeend-timeinit)/1000000, "s'.'S") ); + + System.out.println("Iterator DoubleVector init: " + + DurationFormatUtils.formatDuration( + (timeinit - timestart) / 1000000, "s'.'S") + + " fill: " + + DurationFormatUtils.formatDuration( + (timeend - timeinit) / 1000000, "s'.'S")); } - public void testDoubleVectorIndex() throws Exception { + public void testDoubleVectorIndex() throws Exception { List sem = new ArrayList(); - for (char c='a'; c<=CMAX; c++) { - for (int i=1; i<=MAX; i++) { + for (char c = 'a'; c <= CMAX; c++) { + for (int i = 1; i <= MAX; i++) { sem.add(c + " " + i); - } + } } int size = sem.size(); - + MatrixND mat = null; // [ 2600 x 2600 x 2600 ] long timestart = System.nanoTime(); - mat = MatrixFactory.getInstance(DoubleVector.class).create("Ma mat", new List[]{sem, sem, sem}); + mat = MatrixFactory.getInstance(DoubleVector.class).create("Ma mat", + new List[] { sem, sem, sem }); long timeinit = System.nanoTime(); // parcours avec iterator long cpt = 1; - for (int x=0; x<size; x++) { - for (int y=0; y<size; y++) { - for (int z=0; z<size; z++) { - mat.setValue(x,y,z, cpt++); + for (int x = 0; x < size; x++) { + for (int y = 0; y < size; y++) { + for (int z = 0; z < size; z++) { + mat.setValue(x, y, z, cpt++); } } - } + } long timeend = System.nanoTime(); - - System.out.println("Index DoubleVector init: " + DurationFormatUtils.formatDuration((timeinit-timestart)/1000000, "s'.'S") + - " fill: " + DurationFormatUtils.formatDuration((timeend-timeinit)/1000000, "s'.'S") ); + + System.out.println("Index DoubleVector init: " + + DurationFormatUtils.formatDuration( + (timeinit - timestart) / 1000000, "s'.'S") + + " fill: " + + DurationFormatUtils.formatDuration( + (timeend - timeinit) / 1000000, "s'.'S")); } - public void testDoubleVectorSemantic() throws Exception { + public void testDoubleVectorSemantic() throws Exception { List<String> sem = new ArrayList<String>(); - for (char c='a'; c<=CMAX; c++) { - for (int i=1; i<=MAX; i++) { + for (char c = 'a'; c <= CMAX; c++) { + for (int i = 1; i <= MAX; i++) { sem.add(c + " " + i); - } + } } int size = sem.size(); - + MatrixND mat = null; // [ 2600 x 2600 x 2600 ] long timestart = System.nanoTime(); - mat = MatrixFactory.getInstance(DoubleVector.class).create("Ma mat", new List[]{sem, sem, sem}); + mat = MatrixFactory.getInstance(DoubleVector.class).create("Ma mat", + new List[] { sem, sem, sem }); long timeinit = System.nanoTime(); // parcours avec iterator long cpt = 1; - for (int x=0; x<size; x++) { - for (int y=0; y<size; y++) { - for (int z=0; z<size; z++) { + for (int x = 0; x < size; x++) { + for (int y = 0; y < size; y++) { + for (int z = 0; z < size; z++) { String X = sem.get(x); String Y = sem.get(y); String Z = sem.get(z); - mat.setValue(X,Y,Z, cpt++); + mat.setValue(X, Y, Z, cpt++); } } - } + } long timeend = System.nanoTime(); - - System.out.println("Semantic DoubleVector init: " + DurationFormatUtils.formatDuration((timeinit-timestart)/1000000, "s'.'S") + - " fill: " + DurationFormatUtils.formatDuration((timeend-timeinit)/1000000, "s'.'S") ); + + System.out.println("Semantic DoubleVector init: " + + DurationFormatUtils.formatDuration( + (timeinit - timestart) / 1000000, "s'.'S") + + " fill: " + + DurationFormatUtils.formatDuration( + (timeend - timeinit) / 1000000, "s'.'S")); } - - - - - - public void testDoubleBigVectorIterator() throws Exception { + public void testDoubleBigVectorIterator() throws Exception { List sem = new ArrayList(); - for (char c='a'; c<=CMAX; c++) { - for (int i=1; i<=MAX; i++) { + for (char c = 'a'; c <= CMAX; c++) { + for (int i = 1; i <= MAX; i++) { sem.add(c + " " + i); - } + } } - + MatrixND mat = null; // [ 2600 x 2600 x 2600 ] long timestart = System.nanoTime(); - mat = MatrixFactory.getInstance(DoubleBigVector.class).create("Ma mat", new List[]{sem, sem, sem}); + mat = MatrixFactory.getInstance(DoubleBigVector.class).create("Ma mat", + new List[] { sem, sem, sem }); long timeinit = System.nanoTime(); // parcours avec iterator long cpt = 1; - for (MatrixIterator i=mat.iterator(); i.hasNext();) { + for (MatrixIterator i = mat.iterator(); i.hasNext();) { i.next(); i.setValue(cpt++); - } + } long timeend = System.nanoTime(); - - System.out.println("Iterator DoubleBigVector init: " + DurationFormatUtils.formatDuration((timeinit-timestart)/1000000, "s'.'S") + - " fill: " + DurationFormatUtils.formatDuration((timeend-timeinit)/1000000, "s'.'S") ); + + System.out.println("Iterator DoubleBigVector init: " + + DurationFormatUtils.formatDuration( + (timeinit - timestart) / 1000000, "s'.'S") + + " fill: " + + DurationFormatUtils.formatDuration( + (timeend - timeinit) / 1000000, "s'.'S")); } - public void testDoubleBigVectorIndex() throws Exception { + public void testDoubleBigVectorIndex() throws Exception { List sem = new ArrayList(); - for (char c='a'; c<=CMAX; c++) { - for (int i=1; i<=MAX; i++) { + for (char c = 'a'; c <= CMAX; c++) { + for (int i = 1; i <= MAX; i++) { sem.add(c + " " + i); - } + } } int size = sem.size(); - + MatrixND mat = null; // [ 2600 x 2600 x 2600 ] long timestart = System.nanoTime(); - mat = MatrixFactory.getInstance(DoubleBigVector.class).create("Ma mat", new List[]{sem, sem, sem}); + mat = MatrixFactory.getInstance(DoubleBigVector.class).create("Ma mat", + new List[] { sem, sem, sem }); long timeinit = System.nanoTime(); // parcours avec iterator long cpt = 1; - for (int x=0; x<size; x++) { - for (int y=0; y<size; y++) { - for (int z=0; z<size; z++) { - mat.setValue(x,y,z, cpt++); + for (int x = 0; x < size; x++) { + for (int y = 0; y < size; y++) { + for (int z = 0; z < size; z++) { + mat.setValue(x, y, z, cpt++); } } - } + } long timeend = System.nanoTime(); - - System.out.println("Index DoubleBigVector init: " + DurationFormatUtils.formatDuration((timeinit-timestart)/1000000, "s'.'S") + - " fill: " + DurationFormatUtils.formatDuration((timeend-timeinit)/1000000, "s'.'S") ); + + System.out.println("Index DoubleBigVector init: " + + DurationFormatUtils.formatDuration( + (timeinit - timestart) / 1000000, "s'.'S") + + " fill: " + + DurationFormatUtils.formatDuration( + (timeend - timeinit) / 1000000, "s'.'S")); } - public void testDoubleBigVectorSemantic() throws Exception { + public void testDoubleBigVectorSemantic() throws Exception { List<String> sem = new ArrayList<String>(); - for (char c='a'; c<=CMAX; c++) { - for (int i=1; i<=MAX; i++) { + for (char c = 'a'; c <= CMAX; c++) { + for (int i = 1; i <= MAX; i++) { sem.add(c + " " + i); - } + } } int size = sem.size(); - + MatrixND mat = null; // [ 2600 x 2600 x 2600 ] long timestart = System.nanoTime(); - mat = MatrixFactory.getInstance(DoubleBigVector.class).create("Ma mat", new List[]{sem, sem, sem}); + mat = MatrixFactory.getInstance(DoubleBigVector.class).create("Ma mat", + new List[] { sem, sem, sem }); long timeinit = System.nanoTime(); // parcours avec iterator long cpt = 1; - for (int x=0; x<size; x++) { - for (int y=0; y<size; y++) { - for (int z=0; z<size; z++) { + for (int x = 0; x < size; x++) { + for (int y = 0; y < size; y++) { + for (int z = 0; z < size; z++) { String X = sem.get(x); String Y = sem.get(y); String Z = sem.get(z); - mat.setValue(X,Y,Z, cpt++); + mat.setValue(X, Y, Z, cpt++); } } - } + } long timeend = System.nanoTime(); - - System.out.println("Semantic DoubleBigVector init: " + DurationFormatUtils.formatDuration((timeinit-timestart)/1000000, "s'.'S") + - " fill: " + DurationFormatUtils.formatDuration((timeend-timeinit)/1000000, "s'.'S") ); + + System.out.println("Semantic DoubleBigVector init: " + + DurationFormatUtils.formatDuration( + (timeinit - timestart) / 1000000, "s'.'S") + + " fill: " + + DurationFormatUtils.formatDuration( + (timeend - timeinit) / 1000000, "s'.'S")); } - - - - - - - - - - - - - public void testFloatVectorIterator() throws Exception { + public void testFloatVectorIterator() throws Exception { List sem = new ArrayList(); - for (char c='a'; c<=CMAX; c++) { - for (int i=1; i<=MAX; i++) { + for (char c = 'a'; c <= CMAX; c++) { + for (int i = 1; i <= MAX; i++) { sem.add(c + " " + i); - } + } } - + MatrixND mat = null; // [ 2600 x 2600 x 2600 ] long timestart = System.nanoTime(); - mat = MatrixFactory.getInstance(FloatVector.class).create("Ma mat", new List[]{sem, sem, sem}); + mat = MatrixFactory.getInstance(FloatVector.class).create("Ma mat", + new List[] { sem, sem, sem }); long timeinit = System.nanoTime(); // parcours avec iterator long cpt = 1; - for (MatrixIterator i=mat.iterator(); i.hasNext();) { + for (MatrixIterator i = mat.iterator(); i.hasNext();) { i.next(); i.setValue(cpt++); - } + } long timeend = System.nanoTime(); - - System.out.println("Iterator FloatVector init: " + DurationFormatUtils.formatDuration((timeinit-timestart)/1000000, "s'.'S") + - " fill: " + DurationFormatUtils.formatDuration((timeend-timeinit)/1000000, "s'.'S") ); + + System.out.println("Iterator FloatVector init: " + + DurationFormatUtils.formatDuration( + (timeinit - timestart) / 1000000, "s'.'S") + + " fill: " + + DurationFormatUtils.formatDuration( + (timeend - timeinit) / 1000000, "s'.'S")); } - public void testFloatVectorIndex() throws Exception { + public void testFloatVectorIndex() throws Exception { List sem = new ArrayList(); - for (char c='a'; c<=CMAX; c++) { - for (int i=1; i<=MAX; i++) { + for (char c = 'a'; c <= CMAX; c++) { + for (int i = 1; i <= MAX; i++) { sem.add(c + " " + i); - } + } } int size = sem.size(); - + MatrixND mat = null; // [ 2600 x 2600 x 2600 ] long timestart = System.nanoTime(); - mat = MatrixFactory.getInstance(FloatVector.class).create("Ma mat", new List[]{sem, sem, sem}); + mat = MatrixFactory.getInstance(FloatVector.class).create("Ma mat", + new List[] { sem, sem, sem }); long timeinit = System.nanoTime(); // parcours avec iterator long cpt = 1; - for (int x=0; x<size; x++) { - for (int y=0; y<size; y++) { - for (int z=0; z<size; z++) { - mat.setValue(x,y,z, cpt++); + for (int x = 0; x < size; x++) { + for (int y = 0; y < size; y++) { + for (int z = 0; z < size; z++) { + mat.setValue(x, y, z, cpt++); } } - } + } long timeend = System.nanoTime(); - - System.out.println("Index FloatVector init: " + DurationFormatUtils.formatDuration((timeinit-timestart)/1000000, "s'.'S") + - " fill: " + DurationFormatUtils.formatDuration((timeend-timeinit)/1000000, "s'.'S") ); + + System.out.println("Index FloatVector init: " + + DurationFormatUtils.formatDuration( + (timeinit - timestart) / 1000000, "s'.'S") + + " fill: " + + DurationFormatUtils.formatDuration( + (timeend - timeinit) / 1000000, "s'.'S")); } - public void testFloatVectorSemantic() throws Exception { + public void testFloatVectorSemantic() throws Exception { List<String> sem = new ArrayList<String>(); - for (char c='a'; c<=CMAX; c++) { - for (int i=1; i<=MAX; i++) { + for (char c = 'a'; c <= CMAX; c++) { + for (int i = 1; i <= MAX; i++) { sem.add(c + " " + i); - } + } } int size = sem.size(); - + MatrixND mat = null; // [ 2600 x 2600 x 2600 ] long timestart = System.nanoTime(); - mat = MatrixFactory.getInstance(FloatVector.class).create("Ma mat", new List[]{sem, sem, sem}); + mat = MatrixFactory.getInstance(FloatVector.class).create("Ma mat", + new List[] { sem, sem, sem }); long timeinit = System.nanoTime(); // parcours avec iterator long cpt = 1; - for (int x=0; x<size; x++) { - for (int y=0; y<size; y++) { - for (int z=0; z<size; z++) { + for (int x = 0; x < size; x++) { + for (int y = 0; y < size; y++) { + for (int z = 0; z < size; z++) { String X = sem.get(x); String Y = sem.get(y); String Z = sem.get(z); - mat.setValue(X,Y,Z, cpt++); + mat.setValue(X, Y, Z, cpt++); } } - } + } long timeend = System.nanoTime(); - - System.out.println("Semantic FloatVector init: " + DurationFormatUtils.formatDuration((timeinit-timestart)/1000000, "s'.'S") + - " fill: " + DurationFormatUtils.formatDuration((timeend-timeinit)/1000000, "s'.'S") ); + + System.out.println("Semantic FloatVector init: " + + DurationFormatUtils.formatDuration( + (timeinit - timestart) / 1000000, "s'.'S") + + " fill: " + + DurationFormatUtils.formatDuration( + (timeend - timeinit) / 1000000, "s'.'S")); } - - - - - - public void testFloatBigVectorIterator() throws Exception { + public void testFloatBigVectorIterator() throws Exception { List sem = new ArrayList(); - for (char c='a'; c<=CMAX; c++) { - for (int i=1; i<=MAX; i++) { + for (char c = 'a'; c <= CMAX; c++) { + for (int i = 1; i <= MAX; i++) { sem.add(c + " " + i); - } + } } - + MatrixND mat = null; // [ 2600 x 2600 x 2600 ] long timestart = System.nanoTime(); - mat = MatrixFactory.getInstance(FloatBigVector.class).create("Ma mat", new List[]{sem, sem, sem}); + mat = MatrixFactory.getInstance(FloatBigVector.class).create("Ma mat", + new List[] { sem, sem, sem }); long timeinit = System.nanoTime(); // parcours avec iterator long cpt = 1; - for (MatrixIterator i=mat.iterator(); i.hasNext();) { + for (MatrixIterator i = mat.iterator(); i.hasNext();) { i.next(); i.setValue(cpt++); - } + } long timeend = System.nanoTime(); - - System.out.println("Iterator FloatBigVector init: " + DurationFormatUtils.formatDuration((timeinit-timestart)/1000000, "s'.'S") + - " fill: " + DurationFormatUtils.formatDuration((timeend-timeinit)/1000000, "s'.'S") ); + + System.out.println("Iterator FloatBigVector init: " + + DurationFormatUtils.formatDuration( + (timeinit - timestart) / 1000000, "s'.'S") + + " fill: " + + DurationFormatUtils.formatDuration( + (timeend - timeinit) / 1000000, "s'.'S")); } - public void testFloatBigVectorIndex() throws Exception { + public void testFloatBigVectorIndex() throws Exception { List sem = new ArrayList(); - for (char c='a'; c<=CMAX; c++) { - for (int i=1; i<=MAX; i++) { + for (char c = 'a'; c <= CMAX; c++) { + for (int i = 1; i <= MAX; i++) { sem.add(c + " " + i); - } + } } int size = sem.size(); - + MatrixND mat = null; // [ 2600 x 2600 x 2600 ] long timestart = System.nanoTime(); - mat = MatrixFactory.getInstance(FloatBigVector.class).create("Ma mat", new List[]{sem, sem, sem}); + mat = MatrixFactory.getInstance(FloatBigVector.class).create("Ma mat", + new List[] { sem, sem, sem }); long timeinit = System.nanoTime(); // parcours avec iterator long cpt = 1; - for (int x=0; x<size; x++) { - for (int y=0; y<size; y++) { - for (int z=0; z<size; z++) { - mat.setValue(x,y,z, cpt++); + for (int x = 0; x < size; x++) { + for (int y = 0; y < size; y++) { + for (int z = 0; z < size; z++) { + mat.setValue(x, y, z, cpt++); } } - } + } long timeend = System.nanoTime(); - - System.out.println("Index FloatBigVector init: " + DurationFormatUtils.formatDuration((timeinit-timestart)/1000000, "s'.'S") + - " fill: " + DurationFormatUtils.formatDuration((timeend-timeinit)/1000000, "s'.'S") ); + + System.out.println("Index FloatBigVector init: " + + DurationFormatUtils.formatDuration( + (timeinit - timestart) / 1000000, "s'.'S") + + " fill: " + + DurationFormatUtils.formatDuration( + (timeend - timeinit) / 1000000, "s'.'S")); } - public void testFloatBigVectorSemantic() throws Exception { + public void testFloatBigVectorSemantic() throws Exception { List<String> sem = new ArrayList<String>(); - for (char c='a'; c<=CMAX; c++) { - for (int i=1; i<=MAX; i++) { + for (char c = 'a'; c <= CMAX; c++) { + for (int i = 1; i <= MAX; i++) { sem.add(c + " " + i); - } + } } int size = sem.size(); - + MatrixND mat = null; // [ 2600 x 2600 x 2600 ] long timestart = System.nanoTime(); - mat = MatrixFactory.getInstance(FloatBigVector.class).create("Ma mat", new List[]{sem, sem, sem}); + mat = MatrixFactory.getInstance(FloatBigVector.class).create("Ma mat", + new List[] { sem, sem, sem }); long timeinit = System.nanoTime(); // parcours avec iterator long cpt = 1; - for (int x=0; x<size; x++) { - for (int y=0; y<size; y++) { - for (int z=0; z<size; z++) { + for (int x = 0; x < size; x++) { + for (int y = 0; y < size; y++) { + for (int z = 0; z < size; z++) { String X = sem.get(x); String Y = sem.get(y); String Z = sem.get(z); - mat.setValue(X,Y,Z, cpt++); + mat.setValue(X, Y, Z, cpt++); } } - } + } long timeend = System.nanoTime(); - - System.out.println("Semantic FloatBigVector init: " + DurationFormatUtils.formatDuration((timeinit-timestart)/1000000, "s'.'S") + - " fill: " + DurationFormatUtils.formatDuration((timeend-timeinit)/1000000, "s'.'S") ); + + System.out.println("Semantic FloatBigVector init: " + + DurationFormatUtils.formatDuration( + (timeinit - timestart) / 1000000, "s'.'S") + + " fill: " + + DurationFormatUtils.formatDuration( + (timeend - timeinit) / 1000000, "s'.'S")); } - - - } - - Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/SubMatrixTest.java =================================================================== --- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/SubMatrixTest.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/SubMatrixTest.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,41 +1,38 @@ -/* *##% - * Copyright (C) 2002, 2003, 2004 Code Lutin, Cédric Pineau, - * Benjamin Poussin +/*##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin * - * 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 2 - * of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Lesser Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/* * - * SubMatrixTest.java - * - * Created: 29 oct. 2004 - * - * @author Benjamin Poussin <poussin@codelutin.com> - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ - - package org.codelutin.math.matrix; import java.util.Arrays; import java.util.List; + import junit.framework.TestCase; +/** + * SubMatrixTest.java + * + * Created: 29 oct. 2004 + * + * @author Benjamin Poussin <poussin@codelutin.com> + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ public class SubMatrixTest extends TestCase { // SubMatrixTest public MatrixFactory getFactory() throws Exception { @@ -43,142 +40,109 @@ } public void testNew() throws Exception { - List s1 = Arrays.asList(new String[]{"a", "b", "c"}); - List s2 = Arrays.asList(new String[]{"e", "f", "g"}); - List s3 = Arrays.asList(new String[]{"k", "l", "m"}); + List s1 = Arrays.asList(new String[] { "a", "b", "c" }); + List s2 = Arrays.asList(new String[] { "e", "f", "g" }); + List s3 = Arrays.asList(new String[] { "k", "l", "m" }); MatrixND mat = null; - mat = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + mat = getFactory().create("Ma mat", new List[] { s1, s2, s3 }, + new String[] { "dim abc", "dim efg", "dim klm" }); MatrixND smat = mat.getSubMatrix(1, 0, 2); - assertTrue(Arrays.equals(new int[]{3,2,3}, smat.getDim())); + assertTrue(Arrays.equals(new int[] { 3, 2, 3 }, smat.getDim())); } public void testIterator() throws Exception { - int [][] val18 = new int[][]{ - {0,0,0}, - {0,0,1}, - {0,0,2}, - {0,1,0}, - {0,1,1}, - {0,1,2}, - {1,0,0}, - {1,0,1}, - {1,0,2}, - {1,1,0}, - {1,1,1}, - {1,1,2}, - {2,0,0}, - {2,0,1}, - {2,0,2}, - {2,1,0}, - {2,1,1}, - {2,1,2}, - }; + int[][] val18 = new int[][] { { 0, 0, 0 }, { 0, 0, 1 }, { 0, 0, 2 }, + { 0, 1, 0 }, { 0, 1, 1 }, { 0, 1, 2 }, { 1, 0, 0 }, + { 1, 0, 1 }, { 1, 0, 2 }, { 1, 1, 0 }, { 1, 1, 1 }, + { 1, 1, 2 }, { 2, 0, 0 }, { 2, 0, 1 }, { 2, 0, 2 }, + { 2, 1, 0 }, { 2, 1, 1 }, { 2, 1, 2 }, }; - String [][] vals18 = new String[][]{ - {"a","e","k"}, - {"a","e","l"}, - {"a","e","m"}, - {"a","f","k"}, - {"a","f","l"}, - {"a","f","m"}, - {"b","e","k"}, - {"b","e","l"}, - {"b","e","m"}, - {"b","f","k"}, - {"b","f","l"}, - {"b","f","m"}, - {"c","e","k"}, - {"c","e","l"}, - {"c","e","m"}, - {"c","f","k"}, - {"c","f","l"}, - {"c","f","m"}, - }; + String[][] vals18 = new String[][] { { "a", "e", "k" }, + { "a", "e", "l" }, { "a", "e", "m" }, { "a", "f", "k" }, + { "a", "f", "l" }, { "a", "f", "m" }, { "b", "e", "k" }, + { "b", "e", "l" }, { "b", "e", "m" }, { "b", "f", "k" }, + { "b", "f", "l" }, { "b", "f", "m" }, { "c", "e", "k" }, + { "c", "e", "l" }, { "c", "e", "m" }, { "c", "f", "k" }, + { "c", "f", "l" }, { "c", "f", "m" }, }; - List s1 = Arrays.asList(new String[]{"a", "b", "c"}); - List s2 = Arrays.asList(new String[]{"e", "f", "g"}); - List s3 = Arrays.asList(new String[]{"k", "l", "m"}); + List s1 = Arrays.asList(new String[] { "a", "b", "c" }); + List s2 = Arrays.asList(new String[] { "e", "f", "g" }); + List s3 = Arrays.asList(new String[] { "k", "l", "m" }); MatrixND mat = null; - mat = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + mat = getFactory().create("Ma mat", new List[] { s1, s2, s3 }, + new String[] { "dim abc", "dim efg", "dim klm" }); MatrixND smat = mat.getSubMatrix(1, 0, 2); -// System.out.println(MatrixHelper.coordinatesToString(smat.getDim())); + // System.out.println(MatrixHelper.coordinatesToString(smat.getDim())); int cpt = 0; - for(MatrixIterator i=smat.iterator(); i.hasNext();){ + for (MatrixIterator i = smat.iterator(); i.hasNext();) { i.next(); -// System.out.println(MatrixHelper.coordinatesToString(i.getCoordinates())); -// System.out.println(MatrixHelper.coordinatesToString(i.getSemanticsCoordinates())); + // System.out.println(MatrixHelper.coordinatesToString(i. + // getCoordinates())); + // System.out.println(MatrixHelper.coordinatesToString(i. + // getSemanticsCoordinates())); assertTrue(Arrays.equals(val18[cpt], i.getCoordinates())); assertTrue(Arrays.equals(vals18[cpt], i.getSemanticsCoordinates())); - cpt ++; + cpt++; } assertEquals(18, cpt); } public void testSubSubMatrix() throws Exception { - int [][] val6 = new int[][]{ - {0,0,0}, - {0,0,1}, - {0,0,2}, - {0,1,0}, - {0,1,1}, - {0,1,2}, - }; + int[][] val6 = new int[][] { { 0, 0, 0 }, { 0, 0, 1 }, { 0, 0, 2 }, + { 0, 1, 0 }, { 0, 1, 1 }, { 0, 1, 2 }, }; - String [][] vals6 = new String[][]{ - {"c","e","k"}, - {"c","e","l"}, - {"c","e","m"}, - {"c","f","k"}, - {"c","f","l"}, - {"c","f","m"}, - }; + String[][] vals6 = new String[][] { { "c", "e", "k" }, + { "c", "e", "l" }, { "c", "e", "m" }, { "c", "f", "k" }, + { "c", "f", "l" }, { "c", "f", "m" }, }; - List s1 = Arrays.asList(new String[]{"a", "b", "c"}); - List s2 = Arrays.asList(new String[]{"e", "f", "g"}); - List s3 = Arrays.asList(new String[]{"k", "l", "m"}); + List s1 = Arrays.asList(new String[] { "a", "b", "c" }); + List s2 = Arrays.asList(new String[] { "e", "f", "g" }); + List s3 = Arrays.asList(new String[] { "k", "l", "m" }); MatrixND mat = null; - mat = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + mat = getFactory().create("Ma mat", new List[] { s1, s2, s3 }, + new String[] { "dim abc", "dim efg", "dim klm" }); MatrixND smat1 = mat.getSubMatrix(1, 0, 2); MatrixND smat2 = smat1.getSubMatrix(0, 2, 1); -// System.out.println(" smat2.getDim: "+MatrixHelper.coordinatesToString(smat2.getDim())); - assertTrue(Arrays.equals(new int[]{1, 2, 3}, smat2.getDim())); + //System.out.println(" smat2.getDim: "+MatrixHelper.coordinatesToString( + // smat2.getDim())); + assertTrue(Arrays.equals(new int[] { 1, 2, 3 }, smat2.getDim())); -// System.out.println(MatrixHelper.coordinatesToString(smat2.getDim())); + // System.out.println(MatrixHelper.coordinatesToString(smat2.getDim())); int cpt = 0; - for(MatrixIterator i=smat2.iterator(); i.hasNext();){ + for (MatrixIterator i = smat2.iterator(); i.hasNext();) { i.next(); assertTrue(Arrays.equals(val6[cpt], i.getCoordinates())); assertTrue(Arrays.equals(vals6[cpt], i.getSemanticsCoordinates())); - cpt ++; + cpt++; } assertEquals(6, cpt); } - public void testSubSubGetSet() throws Exception { - List s1 = Arrays.asList(new String[]{"a", "b", "c"}); - List s2 = Arrays.asList(new String[]{"e", "f", "g"}); - List s3 = Arrays.asList(new String[]{"k", "l", "m"}); + List s1 = Arrays.asList(new String[] { "a", "b", "c" }); + List s2 = Arrays.asList(new String[] { "e", "f", "g" }); + List s3 = Arrays.asList(new String[] { "k", "l", "m" }); MatrixND mat = null; - mat = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + mat = getFactory().create("Ma mat", new List[] { s1, s2, s3 }, + new String[] { "dim abc", "dim efg", "dim klm" }); MatrixND smat1 = mat.getSubMatrix(1, 0, 2); MatrixND smat2 = smat1.getSubMatrix(0, 2, 1); @@ -190,20 +154,22 @@ } public void testSubMapping() throws Exception { - List s1 = Arrays.asList(new String[]{"a", "b", "c"}); - List s2 = Arrays.asList(new String[]{"e", "f", "g"}); - List s3 = Arrays.asList(new String[]{"k", "l", "m"}); + List s1 = Arrays.asList(new String[] { "a", "b", "c" }); + List s2 = Arrays.asList(new String[] { "e", "f", "g" }); + List s3 = Arrays.asList(new String[] { "k", "l", "m" }); MatrixND mat = null; - mat = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + mat = getFactory().create("Ma mat", new List[] { s1, s2, s3 }, + new String[] { "dim abc", "dim efg", "dim klm" }); - MatrixND smat1 = mat.getSubMatrix(1, new int []{0, 1}); + MatrixND smat1 = mat.getSubMatrix(1, new int[] { 0, 1 }); assertEquals(2, smat1.getDim(1)); - assertEquals(Arrays.asList(new String[]{"e","f"}), smat1.getSemantics(1)); - MatrixND smat2 = smat1.getSubMatrix(0, new Object[]{"c"}); + assertEquals(Arrays.asList(new String[] { "e", "f" }), smat1 + .getSemantics(1)); + MatrixND smat2 = smat1.getSubMatrix(0, new Object[] { "c" }); assertEquals(1, smat2.getDim(0)); - assertEquals(Arrays.asList(new String[]{"c"}), smat2.getSemantics(0)); + assertEquals(Arrays.asList(new String[] { "c" }), smat2.getSemantics(0)); mat.setValue("c", "f", "k", 12); assertEquals(12, smat1.getValue(2, 1, 0), 0); @@ -222,13 +188,17 @@ } public void testSubAdd() throws Exception { - List s1 = Arrays.asList(new String[]{"a", "b", "c"}); - List s2 = Arrays.asList(new String[]{"e", "f", "g"}); - List s3 = Arrays.asList(new String[]{"k", "l", "m"}); + List s1 = Arrays.asList(new String[] { "a", "b", "c" }); + List s2 = Arrays.asList(new String[] { "e", "f", "g" }); + List s3 = Arrays.asList(new String[] { "k", "l", "m" }); - MatrixND mat1 = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + MatrixND mat1 = getFactory().create("Ma mat", + new List[] { s1, s2, s3 }, + new String[] { "dim abc", "dim efg", "dim klm" }); - MatrixND mat2 = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + MatrixND mat2 = getFactory().create("Ma mat", + new List[] { s1, s2, s3 }, + new String[] { "dim abc", "dim efg", "dim klm" }); MatrixHelper.fill(mat1, 5); MatrixHelper.fill(mat2, 3); @@ -269,11 +239,10 @@ } - public void testSubSubMults() throws Exception { MatrixND mat = null; - mat = getFactory().create("Ma mat", new int[]{4, 4}); + mat = getFactory().create("Ma mat", new int[] { 4, 4 }); MatrixHelper.fill(mat, 4); @@ -294,6 +263,5 @@ } - } // SubMatrixTest Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/gui/MatrixTableModelTest.java =================================================================== --- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/gui/MatrixTableModelTest.java 2008-09-23 09:32:14 UTC (rev 89) +++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/gui/MatrixTableModelTest.java 2008-09-23 10:30:37 UTC (rev 90) @@ -1,21 +1,19 @@ -/* *##% - * Copyright (C) 2006 - * Code Lutin, Cédric Pineau, Benjamin Poussin +/* *##% lutinmatrix + * Copyright (C) 2004 - 2008 CodeLutin * - * 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 2 - * of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Lesser Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * * MatrixTableModelND.java @@ -34,34 +32,36 @@ import java.util.Arrays; import java.util.List; +import junit.framework.TestCase; + import org.codelutin.math.matrix.MatrixFactory; import org.codelutin.math.matrix.MatrixND; -import junit.framework.TestCase; - - /** * @author poussin - * + * */ public class MatrixTableModelTest extends TestCase { MatrixTableModelND model = null; MatrixND mat = null; - + /* * @see TestCase#setUp() */ protected void setUp() throws Exception { - List dim0 = Arrays.asList(new String[]{"dim0-0","dim0-1","dim0-2","dim0-3"}); - List dim1 = Arrays.asList(new String[]{"dim1-0","dim1-1"}); - List dim2 = Arrays.asList(new String[]{"dim2-0","dim2-1"}); - List dim3 = Arrays.asList(new String[]{"dim3-0","dim3-1","dim3-2","dim3-3"}); - List dim4 = Arrays.asList(new String[]{"dim4-0","dim4-1","dim4-2"}); + List dim0 = Arrays.asList(new String[] { "dim0-0", "dim0-1", "dim0-2", + "dim0-3" }); + List dim1 = Arrays.asList(new String[] { "dim1-0", "dim1-1" }); + List dim2 = Arrays.asList(new String[] { "dim2-0", "dim2-1" }); + List dim3 = Arrays.asList(new String[] { "dim3-0", "dim3-1", "dim3-2", + "dim3-3" }); + List dim4 = Arrays + .asList(new String[] { "dim4-0", "dim4-1", "dim4-2" }); mat = MatrixFactory.getInstance().create("mat", - new List[]{dim0,dim1,dim2,dim3,dim4}, - new String[]{"dim0","dim1","dim2","dim3","dim4"}); + new List[] { dim0, dim1, dim2, dim3, dim4 }, + new String[] { "dim0", "dim1", "dim2", "dim3", "dim4" }); model = new MatrixTableModelND(mat); } @@ -69,32 +69,39 @@ assertEquals(2, model.addRow); assertEquals(3, model.addCol); int[] val = model.multRowCol; - assertEquals(true, Arrays.equals(new int[]{6,4,3,1,1}, val)); + assertEquals(true, Arrays.equals(new int[] { 6, 4, 3, 1, 1 }, val)); } - + /* - * Test method for 'org.codelutin.math.matrix.gui.MatrixTableModelND.isCellEditable(int, int)' + * Test method for + * 'org.codelutin.math.matrix.gui.MatrixTableModelND.isCellEditable(int, + * int)' */ public void testIsCellEditable() { - assertEquals(false, model.isCellEditable(model.addRow - 1, model.addCol - 1)); + assertEquals(false, model.isCellEditable(model.addRow - 1, + model.addCol - 1)); assertEquals(true, model.isCellEditable(model.addRow, model.addCol)); - assertEquals(true, model.isCellEditable(model.addRow + 1, model.addCol + 1)); + assertEquals(true, model.isCellEditable(model.addRow + 1, + model.addCol + 1)); } /* - * Test method for 'org.codelutin.math.matrix.gui.MatrixTableModelND.tableToMatrix(int, int)' + * Test method for + * 'org.codelutin.math.matrix.gui.MatrixTableModelND.tableToMatrix(int, + * int)' */ public void testTableToMatrix() { int[] val = model.tableToMatrix(5, 4); - assertEquals(true, Arrays.equals(new int[]{0, 1, 1, 0, 2}, val)); + assertEquals(true, Arrays.equals(new int[] { 0, 1, 1, 0, 2 }, val)); val = model.tableToMatrix(0, 0); - assertEquals(true, Arrays.equals(new int[]{0, 0, 0, 0, 0}, val)); + assertEquals(true, Arrays.equals(new int[] { 0, 0, 0, 0, 0 }, val)); val = model.tableToMatrix(23, 5); - assertEquals(true, Arrays.equals(new int[]{3, 1, 1, 1, 2}, val)); + assertEquals(true, Arrays.equals(new int[] { 3, 1, 1, 1, 2 }, val)); } /* - * Test method for 'org.codelutin.math.matrix.gui.MatrixTableModelND.getValue(int, int)' + * Test method for + * 'org.codelutin.math.matrix.gui.MatrixTableModelND.getValue(int, int)' */ public void testGetValue() { assertEquals("dim0-0", model.getValue(2, 0)); @@ -102,16 +109,16 @@ assertEquals("dim0-0", model.getValue(4, 0)); assertEquals("dim0-0", model.getValue(7, 0)); assertEquals("dim0-1", model.getValue(8, 0)); - + assertEquals("dim2-0", model.getValue(2, 1)); assertEquals("dim2-0", model.getValue(3, 1)); assertEquals("dim2-1", model.getValue(5, 1)); - + assertEquals("dim4-0", model.getValue(2, 2)); assertEquals("dim4-1", model.getValue(3, 2)); assertEquals("dim4-2", model.getValue(4, 2)); assertEquals("dim4-0", model.getValue(5, 2)); - + assertEquals("dim1-0", model.getValue(0, 3)); assertEquals(0.0, model.getValue(model.addRow, model.addCol)); @@ -119,40 +126,44 @@ } /* - * Test method for 'org.codelutin.math.matrix.gui.MatrixTableModelND.getColumnName(int)' + * Test method for + * 'org.codelutin.math.matrix.gui.MatrixTableModelND.getColumnName(int)' */ public void testGetColumnNameInt() { } /* - * Test method for 'org.codelutin.math.matrix.gui.MatrixTableModelND.getRowCount()' + * Test method for + * 'org.codelutin.math.matrix.gui.MatrixTableModelND.getRowCount()' */ public void testGetRowCount() { } /* - * Test method for 'org.codelutin.math.matrix.gui.MatrixTableModelND.getColumnCount()' + * Test method for + * 'org.codelutin.math.matrix.gui.MatrixTableModelND.getColumnCount()' */ public void testGetColumnCount() { } /* - * Test method for 'org.codelutin.math.matrix.gui.MatrixTableModelND.getValueAt(int, int)' + * Test method for + * 'org.codelutin.math.matrix.gui.MatrixTableModelND.getValueAt(int, int)' */ public void testGetValueAt() { } /* - * Test method for 'org.codelutin.math.matrix.gui.MatrixTableModelND.setValueAt(Object, int, int)' + * Test method for + * 'org.codelutin.math.matrix.gui.MatrixTableModelND.setValueAt(Object, int, + * int)' */ public void testSetValueAtObjectIntInt() { } } - -