001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.data.osm.search; 003 004import java.util.Arrays; 005 006/** 007 * Search mode. 008 * @since 12659 (extracted from {@code SearchAction}) 009 */ 010public enum SearchMode { 011 /** replace selection */ 012 replace('R'), 013 /** add to selection */ 014 add('A'), 015 /** remove from selection */ 016 remove('D'), 017 /** find in selection */ 018 in_selection('S'); 019 020 private final char code; 021 022 SearchMode(char code) { 023 this.code = code; 024 } 025 026 /** 027 * Returns the unique character code of this mode. 028 * @return the unique character code of this mode 029 */ 030 public char getCode() { 031 return code; 032 } 033 034 /** 035 * Returns the search mode matching the given character code. 036 * @param code character code 037 * @return search mode matching the given character code 038 */ 039 public static SearchMode fromCode(char code) { 040 return Arrays.stream(values()) 041 .filter(mode -> mode.getCode() == code) 042 .findFirst().orElse(null); 043 } 044}