Codota Logo
SingleElementHandler
Code IndexAdd Codota to your IDE (free)

How to use
SingleElementHandler
in
de.westnordost.osmapi.common

Best Java code snippets using de.westnordost.osmapi.common.SingleElementHandler (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
LocalDateTime l =
  • Codota Iconnew LocalDateTime()
  • Codota IconLocalDateTime.now()
  • Codota IconDateTimeFormatter formatter;String text;formatter.parseLocalDateTime(text)
  • Smart code suggestions by Codota
}
origin: westnordost/StreetComplete

private Note findAlreadyExistingNoteWithSameAssociatedElement(final CreateNote newNote)
{
  SingleElementHandler<Note> handler = new SingleElementHandler<Note>()
  {
    @Override public void handle(Note oldNote)
    {
      if(newNote.hasAssociatedElement())
      {
        String firstCommentText = oldNote.comments.get(0).text;
        String newNoteRegex = getAssociatedElementRegex(newNote);
        if(firstCommentText.matches(newNoteRegex))
        {
          super.handle(oldNote);
        }
      }
    }
  };
  final int hideClosedNoteAfter = 7;
  osmDao.getAll(new BoundingBox(
      newNote.position.getLatitude(), newNote.position.getLongitude(),
      newNote.position.getLatitude(), newNote.position.getLongitude()
  ), handler, 10, hideClosedNoteAfter);
  return handler.get();
}
origin: westnordost/StreetComplete

  @Override public void handle(Note oldNote)
  {
    if(newNote.hasAssociatedElement())
    {
      String firstCommentText = oldNote.comments.get(0).text;
      String newNoteRegex = getAssociatedElementRegex(newNote);
      if(firstCommentText.matches(newNoteRegex))
      {
        super.handle(oldNote);
      }
    }
  }
};
origin: westnordost/osmapi

/** @return the user info of the current user
 *  @throws OsmAuthorizationException if the user does not have the permission
 *                                     Permission.READ_PREFERENCES_AND_USER_DETAILS*/
public UserDetails getMine()
{
  SingleElementHandler<UserInfo> handler = new SingleElementHandler<>();
  osm.makeAuthenticatedRequest("user/details", null, new UserDetailsParser(handler));
  return (UserDetails) handler.get();
}
origin: westnordost/osmapi

/**
 * Reopen the given note with the given reason. The reason is optional.
 *
 * @throws OsmConflictException if the note has already been reopened.
 * @throws OsmAuthorizationException if this application is not authorized to write notes
 *                                    (Permission.WRITE_NOTES)
 * @throws OsmNotFoundException if the note with the given id does not exist (anymore)
 *
 * @return the updated reopened note
 */
public Note reopen(long id, String reason)
{
  SingleElementHandler<Note> noteHandler = new SingleElementHandler<>();
  makeSingleNoteRequest(id, "reopen", reason, new NotesParser(noteHandler));
  return noteHandler.get();
}
origin: westnordost/osmapi

/**
 * @throws OsmAuthorizationException if not logged in
 * @return the user info of the given user. Null if the user does not exist.
 *  */
public UserInfo get(long userId)
{
  try
  {
    SingleElementHandler<UserInfo> handler = new SingleElementHandler<>();
    osm.makeAuthenticatedRequest("user/" + userId, null, new UserInfoParser(handler));
    return handler.get();
  }
  catch(OsmNotFoundException e)
  {
    return null;
  }
}
origin: westnordost/osmapi

/** Get the changeset information with the given id. Always includes the changeset discussion.
 *
 * @param id changeset id
 * @throws OsmAuthorizationException if not logged in
 * @return info for the given changeset. Null if it does not exist. */
public ChangesetInfo get(long id)
{
  SingleElementHandler<ChangesetInfo> handler = new SingleElementHandler<>();
  String query = CHANGESET + "/" + id + "?include_discussion=true";
  try
  {
    osm.makeAuthenticatedRequest(query, null, new ChangesetParser(handler));
  }
  catch(OsmNotFoundException e)
  {
    return null;
  }
  return handler.get();
}
origin: westnordost/osmapi

/**
 * Close aka resolve the note with the given id and reason.
 *
 * @param id id of the note
 * @param reason comment to be added to the note as a reason for it being closed. Optional.
 *
 * @throws OsmConflictException if the note has already been closed.
 * @throws OsmAuthorizationException if this application is not authorized to write notes
 *                                   (Permission.WRITE_NOTES)
 * @throws OsmNotFoundException if the note with the given id does not exist (anymore)
 *
 * @return the closed note
 */
public Note close(long id, String reason)
{
  SingleElementHandler<Note> noteHandler = new SingleElementHandler<>();
  makeSingleNoteRequest(id, "close", reason, new NotesParser(noteHandler));
  return noteHandler.get();
}
origin: westnordost/osmapi

/**
 * @param id id of the note
 *
 * @throws OsmAuthorizationException if not logged in
 *
 * @return the note with the given id. null if the note with that id does not exist (anymore).
 */
public Note get(long id)
{
  SingleElementHandler<Note> noteHandler = new SingleElementHandler<>();
  try
  {
    osm.makeAuthenticatedRequest(NOTES + "/" + id, null, new NotesParser(noteHandler));
  }
  catch (OsmNotFoundException e)
  {
    return null;
  }
  return noteHandler.get();
}
origin: westnordost/osmapi

/**
 * @param id id of the note
 * @param text comment to be added to the note. Must not be null or empty
 *
 * @throws OsmConflictException if the note has already been closed.
 * @throws OsmAuthorizationException if this application is not authorized to write notes
 *                                   (Permission.WRITE_NOTES)
 * @throws OsmNotFoundException if the note with the given id does not exist (anymore)
 *
 * @return the updated commented note
 */
public Note comment(long id, String text)
{
  if(text.isEmpty())
  {
    throw new IllegalArgumentException("comment must not be empty");
  }
  SingleElementHandler<Note> noteHandler = new SingleElementHandler<>();
  makeSingleNoteRequest(id, "comment", text, new NotesParser(noteHandler));
  return noteHandler.get();
}
origin: westnordost/osmapi

/**
 * Get information about a given GPS trace or null if it does not exist.
 * 
 * @throws OsmAuthorizationException if this application is not authorized to read the user's
 *                                   traces (Permission.READ_GPS_TRACES)
 *                                   OR if the trace in question is not the user's own trace 
 *                                   and at the same time it is not public
 *                                   OR if not logged in at all
 */
public GpsTraceDetails get(long id)
{
  SingleElementHandler<GpsTraceDetails> handler = new SingleElementHandler<>();
  try
  {
    osm.makeAuthenticatedRequest(GPX + "/" + id, "GET", new GpsTracesParser(handler) );
  }
  catch(OsmNotFoundException e)
  {
    return null;
  }
  return handler.get();
}
 
origin: westnordost/osmapi

private Note parseOne(String xml)
{
  SingleElementHandler<Note> handler = new SingleElementHandler<>();
  parse(xml, handler);
  return handler.get();
}
 
origin: westnordost/osmapi

private GpsTrackpoint parseOne(String xml)
{
  SingleElementHandler<GpsTrackpoint> handler = new SingleElementHandler<>();
  parse(xml, handler);
  return handler.get();
}
 
origin: westnordost/osmapi

private ChangesetInfo parseOne(String xml)
{
  SingleElementHandler<ChangesetInfo> handler = new SingleElementHandler<>();
  parse(xml, handler);
  return handler.get();
}
 
origin: westnordost/osmapi

/**
 * Add a comment to the given changeset. The changeset must already be closed. Adding a comment
 * to a changeset automatically subscribes the user to it.
 * 
 * TODO monitor https://github.com/openstreetmap/openstreetmap-website/issues/1165
 *
 * @param id id of the changeset
 * @param text text to add to the changeset. Must not be empty
 * 
 * @return the updated changeset
 *
 * @throws OsmAuthorizationException if this application is not authorized to modify the map
 *                                    (Permission.MODIFY_MAP)
 * @throws OsmConflictException if the changeset is not yet closed. (Only closed changesets can
 *                              be commented
 */
public ChangesetInfo comment(long id, String text)
{
  if(text.isEmpty())
  {
    throw new IllegalArgumentException("Text must not be empty");
  }
  SingleElementHandler<ChangesetInfo> handler = new SingleElementHandler<>();
  String apiCall = CHANGESET + "/" + id + "/comment?text=" + urlEncodeText(text);
  osm.makeAuthenticatedRequest(apiCall, "POST", new ChangesetParser(handler));
  return handler.get();
}
origin: westnordost/osmapi

/**
 * Subscribe the user to a changeset discussion. The changeset must be closed already.
 *
 * @param id id of the changeset
 * @return the changeset
 *
 * @throws OsmAuthorizationException if this application is not authorized to modify the map
 *                                    (Permission.MODIFY_MAP)
 * @throws OsmNotFoundException if the given changeset does not exist
 */
public ChangesetInfo subscribe(long id)
{
  SingleElementHandler<ChangesetInfo> handler = new SingleElementHandler<>();
  ChangesetInfo result;
  try
  {
    String apiCall = CHANGESET + "/" + id + "/subscribe";
    osm.makeAuthenticatedRequest(apiCall, "POST", new ChangesetParser(handler));
    result = handler.get();
  }
  catch(OsmConflictException ignore)
  {
    /* ignore this exception which occurs when the user already subscribed to the changeset */
    result = get(id);
  }
  return result;
}
origin: westnordost/osmapi

SingleElementHandler<ChangesetInfo> handler = new SingleElementHandler<>();
ChangesetInfo result;
  result = handler.get();
origin: westnordost/osmapi

/**
 * Create a new note at the given location
 *
 * @param pos position of the note. Must not be null.
 * @param text text for the new note. Must not be empty nor null.
 *
 * @throws OsmAuthorizationException if this application is not authorized to write notes
 *                                   (Permission.WRITE_NOTES)
 *
 * @return the new note
 */
public Note create(LatLon pos, String text)
{
  if(text.isEmpty())
  {
    throw new IllegalArgumentException("Text may not be empty");
  }
  String data =
      "lat=" + numberFormat.format(pos.getLatitude()) +
      "&lon=" + numberFormat.format(pos.getLongitude()) +
      "&text=" + urlEncode(text);
  String call = NOTES + "?" + data;
  SingleElementHandler<Note> noteHandler = new SingleElementHandler<>();
  osm.makeAuthenticatedRequest(call, "POST", new NotesParser(noteHandler));
  return noteHandler.get();
}
origin: westnordost/osmapi

private GpsTraceDetails parseOne(String xml)
{
  try
  {
    SingleElementHandler<GpsTraceDetails> handler = new SingleElementHandler<>();
    new GpsTracesParser(handler).parse(TestUtils.asInputStream(xml));
    return handler.get();
  }
  catch(IOException e)
  {
    throw new RuntimeException(e);
  }
}
origin: westnordost/osmapi

  private UserDetails parseOneDetails(String xml)
  {
    try
    {
      SingleElementHandler<UserInfo> handler = new SingleElementHandler<>();
      new UserDetailsParser(handler).parse(TestUtils.asInputStream(xml));
      return (UserDetails) handler.get();
    }
    catch(IOException e)
    {
      throw new RuntimeException(e);
    }
  }
}
origin: westnordost/osmapi

private UserInfo parseOne(String xml)
{
  try
  {
    SingleElementHandler<UserInfo> handler = new SingleElementHandler<>();
    new UserInfoParser(handler).parse(TestUtils.asInputStream(xml));
    return handler.get();
  }
  catch(IOException e)
  {
    throw new RuntimeException(e);
  }
}
de.westnordost.osmapi.commonSingleElementHandler

Javadoc

Handler that expects just a single element. It can be queried via get().

Most used methods

  • get
  • <init>
  • handle

Popular in Java

  • Finding current android device location
  • getSupportFragmentManager (FragmentActivity)
  • getSystemService (Context)
  • getContentResolver (Context)
  • EOFException (java.io)
    Thrown when a program encounters the end of a file or stream during an input operation.
  • Permission (java.security)
    Abstract class for representing access to a system resource. All permissions have a name (whose inte
  • Timestamp (java.sql)
    A Java representation of the SQL TIMESTAMP type. It provides the capability of representing the SQL
  • Annotation (javassist.bytecode.annotation)
    The annotation structure.An instance of this class is returned bygetAnnotations() in AnnotationsAttr
  • JCheckBox (javax.swing)
  • Logger (org.slf4j)
    The main user interface to logging. It is expected that logging takes place through concrete impleme
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now