-
Notifications
You must be signed in to change notification settings - Fork 435
Developer guide: five more sentences that promise code #5814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+257
−9
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0b59cb6
Developer guide: five more sentences that promise code
shai-almog 70475a8
Developer guide: the key migration has to move every entry
shai-almog 5d5f8ce
Developer guide: let the migration's close failures reach the caller
shai-almog 917a877
Developer guide: an interrupted key migration must not strand the store
shai-almog 8696939
Developer guide: stop trying to make the key migration crash-safe in …
shai-almog File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
123 changes: 123 additions & 0 deletions
123
...codenameone/developerguide/snippets/generated/AnnotationJsonXmlMappingJava003Snippet.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| /* | ||
| * Copyright (c) 2012, Codename One and/or its affiliates. All rights reserved. | ||
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| * This code is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU General Public License version 2 only, as | ||
| * published by the Free Software Foundation. Codename One designates this | ||
| * particular file as subject to the "Classpath" exception as provided | ||
| * by Oracle in the LICENSE file that accompanied this code. | ||
| * | ||
| * This code 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 | ||
| * version 2 for more details (a copy is included in the LICENSE file that | ||
| * accompanied this code). | ||
| * | ||
| * You should have received a copy of the GNU General Public License version | ||
| * 2 along with this work; if not, write to the Free Software Foundation, | ||
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * Please contact Codename One through http://www.codenameone.com/ if you | ||
| * need additional information or have any questions. | ||
| */ | ||
|
|
||
| package com.codenameone.developerguide.snippets.generated; | ||
|
|
||
| import com.codename1.gpu.*; | ||
| import com.codename1.ui.*; | ||
| import com.codename1.ui.animations.*; | ||
| import com.codename1.ui.events.*; | ||
| import com.codename1.ui.geom.*; | ||
| import com.codename1.ui.layouts.*; | ||
| import com.codename1.ui.list.*; | ||
| import com.codename1.ui.plaf.*; | ||
| import com.codename1.ui.util.*; | ||
| import com.codename1.components.*; | ||
| import com.codename1.charts.models.*; | ||
| import com.codename1.charts.renderers.*; | ||
| import com.codename1.charts.views.*; | ||
| import com.codename1.capture.*; | ||
| import com.codename1.io.*; | ||
| import com.codename1.l10n.*; | ||
| import com.codename1.location.*; | ||
| import com.codename1.maps.*; | ||
| import com.codename1.media.*; | ||
| import com.codename1.messaging.*; | ||
| import com.codename1.payment.*; | ||
| import com.codename1.processing.*; | ||
| import com.codename1.properties.*; | ||
| import com.codename1.push.*; | ||
| import com.codename1.security.*; | ||
| import com.codename1.social.*; | ||
| import com.codename1.ui.spinner.*; | ||
| import java.io.*; | ||
| import com.codename1.mapping.*; | ||
| import com.codename1.xml.*; | ||
| import java.util.*; | ||
| import com.codename1.annotations.*; | ||
| import com.codename1.properties.*; | ||
|
|
||
| class AnnotationJsonXmlMappingJava003Snippet { | ||
|
|
||
| // tag::annotation-json-xml-mapping-java-003[] | ||
| // A type from a third-party jar the build cannot annotate. | ||
| static class LatLon { | ||
| double lat; | ||
| double lon; | ||
| } | ||
|
|
||
| static class LatLonMapper implements Mapper<LatLon> { | ||
| @Override | ||
| public Class<LatLon> type() { | ||
| return LatLon.class; | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, Object> toMap(LatLon instance) { | ||
| Map<String, Object> m = new LinkedHashMap<String, Object>(); | ||
| m.put("lat", Double.valueOf(instance.lat)); | ||
| m.put("lon", Double.valueOf(instance.lon)); | ||
| return m; | ||
| } | ||
|
|
||
| @Override | ||
| public LatLon fromMap(Map<String, Object> map) { | ||
| LatLon out = new LatLon(); | ||
| out.lat = readDouble(map.get("lat")); | ||
| out.lon = readDouble(map.get("lon")); | ||
| return out; | ||
| } | ||
|
|
||
| @Override | ||
| public String xmlRootName() { | ||
| return "latLon"; | ||
| } | ||
|
|
||
| @Override | ||
| public void writeXml(LatLon instance, Element root) { | ||
| root.setAttribute("lat", String.valueOf(instance.lat)); | ||
| root.setAttribute("lon", String.valueOf(instance.lon)); | ||
| } | ||
|
|
||
| @Override | ||
| public LatLon readXml(Element root) { | ||
| LatLon out = new LatLon(); | ||
| out.lat = Double.parseDouble(root.getAttribute("lat")); | ||
| out.lon = Double.parseDouble(root.getAttribute("lon")); | ||
| return out; | ||
| } | ||
|
|
||
| // JSONParser hands back a Double for every number, but a map that came | ||
| // from somewhere else may hold any Number. Read through the interface | ||
| // rather than casting to Double: a failed cast does not throw on iOS, | ||
| // so the catch you would write for it never runs. | ||
| private double readDouble(Object value) { | ||
| return value instanceof Number ? ((Number) value).doubleValue() : 0; | ||
| } | ||
| } | ||
|
|
||
| void registerMappers() { | ||
| Mappers.register(new LatLonMapper()); | ||
| } | ||
| // end::annotation-json-xml-mapping-java-003[] | ||
| } |
83 changes: 83 additions & 0 deletions
83
...om/codenameone/developerguide/snippets/generated/MiscellaneousFeaturesJava010Snippet.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /* | ||
| * Copyright (c) 2012, Codename One and/or its affiliates. All rights reserved. | ||
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| * This code is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU General Public License version 2 only, as | ||
| * published by the Free Software Foundation. Codename One designates this | ||
| * particular file as subject to the "Classpath" exception as provided | ||
| * by Oracle in the LICENSE file that accompanied this code. | ||
| * | ||
| * This code 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 | ||
| * version 2 for more details (a copy is included in the LICENSE file that | ||
| * accompanied this code). | ||
| * | ||
| * You should have received a copy of the GNU General Public License version | ||
| * 2 along with this work; if not, write to the Free Software Foundation, | ||
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * Please contact Codename One through http://www.codenameone.com/ if you | ||
| * need additional information or have any questions. | ||
| */ | ||
|
|
||
| package com.codenameone.developerguide.snippets.generated; | ||
|
|
||
| import com.codename1.gpu.*; | ||
| import com.codename1.ui.*; | ||
| import com.codename1.ui.animations.*; | ||
| import com.codename1.ui.events.*; | ||
| import com.codename1.ui.geom.*; | ||
| import com.codename1.ui.layouts.*; | ||
| import com.codename1.ui.list.*; | ||
| import com.codename1.ui.plaf.*; | ||
| import com.codename1.ui.util.*; | ||
| import com.codename1.components.*; | ||
| import com.codename1.charts.models.*; | ||
| import com.codename1.charts.renderers.*; | ||
| import com.codename1.charts.views.*; | ||
| import com.codename1.capture.*; | ||
| import com.codename1.io.*; | ||
| import com.codename1.l10n.*; | ||
| import com.codename1.location.*; | ||
| import com.codename1.maps.*; | ||
| import com.codename1.media.*; | ||
| import com.codename1.messaging.*; | ||
| import com.codename1.payment.*; | ||
| import com.codename1.processing.*; | ||
| import com.codename1.properties.*; | ||
| import com.codename1.push.*; | ||
| import com.codename1.security.*; | ||
| import com.codename1.social.*; | ||
| import com.codename1.ui.spinner.*; | ||
| import java.io.*; | ||
| import java.util.*; | ||
|
|
||
|
|
||
| class MiscellaneousFeaturesJava010Snippet { | ||
|
|
||
| // tag::miscellaneous-features-java-010[] | ||
| void ensureLocationUsageDescription() { | ||
| // Both calls only work in the simulator, and setProjectBuildHint throws | ||
| // anywhere else -- so this belongs behind an isSimulator() check, run | ||
| // once during development rather than on every launch. | ||
| if (!Display.getInstance().isSimulator()) { | ||
| return; | ||
| } | ||
|
|
||
| Map<String, String> hints = Display.getInstance().getProjectBuildHints(); | ||
| if (hints == null) { | ||
| // No codename1_settings.properties beside the running project, or | ||
| // it could not be read. Nothing to check against, and nothing to | ||
| // write into. | ||
| return; | ||
| } | ||
|
|
||
| String description = hints.get("ios.locationUsageDescription"); | ||
| if (description == null || description.length() == 0) { | ||
| Display.getInstance().setProjectBuildHint("ios.locationUsageDescription", | ||
| "Used to show nearby results on the map"); | ||
| } | ||
| } | ||
| // end::miscellaneous-features-java-010[] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.