From 8fc1410cd08c6e0cf50c02760eee80f0230bdc52 Mon Sep 17 00:00:00 2001 From: Krrish Ghimire Date: Tue, 3 Dec 2019 23:25:18 +0545 Subject: [PATCH] fix: Ignore if field does not exist --- LICENSE | 56 +++++++++++------------ src/{ => np/com/krrish}/Mapper.java | 5 +- test/{ => np/com/krrish}/Destination.java | 4 +- test/{ => np/com/krrish}/MapperTest.java | 6 ++- test/{ => np/com/krrish}/Source.java | 6 ++- 5 files changed, 43 insertions(+), 34 deletions(-) rename src/{ => np/com/krrish}/Mapper.java (90%) rename test/{ => np/com/krrish}/Destination.java (78%) rename test/{ => np/com/krrish}/MapperTest.java (82%) rename test/{ => np/com/krrish}/Source.java (61%) diff --git a/LICENSE b/LICENSE index 9f37dab..1a62993 100644 --- a/LICENSE +++ b/LICENSE @@ -109,7 +109,7 @@ work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. - 1. Source Code. + 1. np.com.krrish.Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source @@ -131,24 +131,24 @@ implementation is available to the public in source code form. A (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. - The "Corresponding Source" for a work in object code form means all + The "Corresponding np.com.krrish.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 +which are not part of the work. For example, Corresponding np.com.krrish.Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. - The Corresponding Source need not include anything that users + The Corresponding np.com.krrish.Source need not include anything that users can regenerate automatically from other parts of the Corresponding -Source. +np.com.krrish.Source. - The Corresponding Source for a work in source code form is that + The Corresponding np.com.krrish.Source for a work in source code form is that same work. 2. Basic Permissions. @@ -205,7 +205,7 @@ 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. + 5. Conveying Modified np.com.krrish.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 @@ -242,16 +242,16 @@ 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. + 6. Conveying Non-np.com.krrish.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, +machine-readable Corresponding np.com.krrish.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 + Corresponding np.com.krrish.Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product @@ -259,39 +259,39 @@ in one of these ways: 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 + copy of the Corresponding np.com.krrish.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. + Corresponding np.com.krrish.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 + written offer to provide the Corresponding np.com.krrish.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 + Corresponding np.com.krrish.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 + Corresponding np.com.krrish.Source along with the object code. If the place to + copy the object code is a network server, the Corresponding np.com.krrish.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 + Corresponding np.com.krrish.Source. Regardless of what server hosts the + Corresponding np.com.krrish.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 + np.com.krrish.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 +from the Corresponding np.com.krrish.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 @@ -310,7 +310,7 @@ 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 +a modified version of its Corresponding np.com.krrish.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. @@ -320,7 +320,7 @@ 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 +Corresponding np.com.krrish.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 @@ -334,7 +334,7 @@ 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, + Corresponding np.com.krrish.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 @@ -457,7 +457,7 @@ 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 +Corresponding np.com.krrish.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 @@ -497,10 +497,10 @@ 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 +and the Corresponding np.com.krrish.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 +then you must either (1) cause the Corresponding np.com.krrish.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 @@ -631,7 +631,7 @@ 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. - Object Mapper + Object np.com.krrish.Mapper Copyright (C) 2019 krrishg This program is free software: you can redistribute it and/or modify @@ -652,7 +652,7 @@ 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: - Object Mapper Copyright (C) 2019 krrishg + Object np.com.krrish.Mapper Copyright (C) 2019 krrishg 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. diff --git a/src/Mapper.java b/src/np/com/krrish/Mapper.java similarity index 90% rename from src/Mapper.java rename to src/np/com/krrish/Mapper.java index 2afe1c5..12863c9 100644 --- a/src/Mapper.java +++ b/src/np/com/krrish/Mapper.java @@ -1,3 +1,5 @@ +package np.com.krrish; + import java.lang.reflect.*; public class Mapper { @@ -13,8 +15,9 @@ public class Mapper { destinationField.setAccessible(true); destinationField.set(object, sourceField.get(source)); } - } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException | NoSuchFieldException e) { + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { e.printStackTrace(); + } catch (NoSuchFieldException ignored) { } return object; } diff --git a/test/Destination.java b/test/np/com/krrish/Destination.java similarity index 78% rename from test/Destination.java rename to test/np/com/krrish/Destination.java index 6d0496e..2999cf1 100644 --- a/test/Destination.java +++ b/test/np/com/krrish/Destination.java @@ -1,8 +1,10 @@ +package np.com.krrish; + public class Destination { private String first; private String second; - public String getFirst() { + String getFirst() { return first; } diff --git a/test/MapperTest.java b/test/np/com/krrish/MapperTest.java similarity index 82% rename from test/MapperTest.java rename to test/np/com/krrish/MapperTest.java index ab153b3..e4cbb3d 100644 --- a/test/MapperTest.java +++ b/test/np/com/krrish/MapperTest.java @@ -1,3 +1,5 @@ +package np.com.krrish; + import org.junit.jupiter.api.*; import static org.junit.jupiter.api.Assertions.*; @@ -13,7 +15,7 @@ class MapperTest { @Test void testEmptyFieldsMap() { Source source = new Source(); - Object destination = mapper.map(source, "Destination"); + Object destination = mapper.map(source, "np.com.krrish.Destination"); assertEquals(Destination.class, destination.getClass()); } @@ -23,7 +25,7 @@ class MapperTest { source.setFirst("first"); source.setSecond("second"); - Destination destination = (Destination) mapper.map(source, "Destination"); + Destination destination = (Destination) mapper.map(source, "np.com.krrish.Destination"); assertEquals("first", destination.getFirst()); } } diff --git a/test/Source.java b/test/np/com/krrish/Source.java similarity index 61% rename from test/Source.java rename to test/np/com/krrish/Source.java index e266ccb..f9ec9dd 100644 --- a/test/Source.java +++ b/test/np/com/krrish/Source.java @@ -1,12 +1,14 @@ +package np.com.krrish; + public class Source { private String first; private String second; - public void setFirst(String first) { + void setFirst(String first) { this.first = first; } - public void setSecond(String second) { + void setSecond(String second) { this.second = second; } }