Path: blob/master/src/java.desktop/unix/classes/sun/awt/X11/XCreateWindowParams.java
41159 views
/*1* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.awt.X11;2627import java.util.HashMap;28import java.util.Iterator;29import java.util.Map;3031@SuppressWarnings("serial") // JDK-implementation class32public class XCreateWindowParams extends HashMap<Object, Object> {33public XCreateWindowParams() {34}35public XCreateWindowParams(Object[] map) {36init(map);37}38private void init(Object[] map) {39if (map.length % 2 != 0) {40throw new IllegalArgumentException("Map size should be devisible by two");41}42for (int i = 0; i < map.length; i += 2) {43put(map[i], map[i+1]);44}45}4647public XCreateWindowParams putIfNull(Object key, Object value) {48if (!containsKey(key)) {49put(key, value);50}51return this;52}53public XCreateWindowParams putIfNull(Object key, int value) {54if (!containsKey(key)) {55put(key, Integer.valueOf(value));56}57return this;58}59public XCreateWindowParams putIfNull(Object key, long value) {60if (!containsKey(key)) {61put(key, Long.valueOf(value));62}63return this;64}6566public XCreateWindowParams add(Object key, Object value) {67put(key, value);68return this;69}70public XCreateWindowParams add(Object key, int value) {71put(key, Integer.valueOf(value));72return this;73}74public XCreateWindowParams add(Object key, long value) {75put(key, Long.valueOf(value));76return this;77}78public XCreateWindowParams delete(Object key) {79remove(key);80return this;81}82public String toString() {83StringBuilder buf = new StringBuilder();84Iterator<Map.Entry<Object, Object>> eIter = entrySet().iterator();85while (eIter.hasNext()) {86Map.Entry<Object, Object> entry = eIter.next();87buf.append(entry.getKey())88.append(": ")89.append(entry.getValue())90.append("\n");91}92return buf.toString();93}9495}969798