11/*******************************************************************************
2- * Copyright (c) 2012 EclipseSource.
2+ * Copyright (c) 2012, 2013 EclipseSource.
33 * All rights reserved. This program and the accompanying materials
44 * are made available under the terms of the Eclipse Public License v1.0
55 * which accompanies this distribution, and is available at
1010 ******************************************************************************/
1111package com .eclipsesource .jshint ;
1212
13- import java . util . LinkedHashMap ;
14- import java . util . Map ;
13+ import com . eclipsesource . json . JsonObject ;
14+ import com . eclipsesource . json . JsonValue ;
1515
1616
1717/**
2121 */
2222public class Configuration {
2323
24- private final Map < String , Object > options ;
25- private final Map < String , Object > predefs ;
24+ private final JsonObject options ;
25+ private final JsonObject predefs ;
2626
2727 public Configuration () {
28- predefs = new LinkedHashMap < String , Object > ();
29- options = new LinkedHashMap < String , Object > ();
28+ options = new JsonObject ();
29+ predefs = new JsonObject ();
3030 }
3131
3232 /**
3333 * Adds an option. If the option is already defined, it is overridden.
3434 *
35- * @param option
35+ * @param name
3636 * the name of the option
3737 * @param value
38- * the value for this option, <code>true</code> to enable the option, <code>false</code>
39- * to disable it
40- * @return the configuration to allow chaining
38+ * the value for this option
39+ * @return the configuration itself to allow chaining
40+ * @see http://www.jshint.com/docs/
41+ */
42+ public Configuration addOption ( String name , boolean value ) {
43+ options .remove ( name ).add ( name , value );
44+ return this ;
45+ }
46+
47+ /**
48+ * Adds an option. If the option is already defined, it is overridden.
49+ *
50+ * @param name
51+ * the name of the option
52+ * @param value
53+ * the value for this option
54+ * @return the configuration itself to allow chaining
55+ * @see http://www.jshint.com/docs/
56+ */
57+ public Configuration addOption ( String name , long value ) {
58+ options .remove ( name ).add ( name , value );
59+ return this ;
60+ }
61+
62+ /**
63+ * Adds an option. If the option is already defined, it is overridden.
64+ *
65+ * @param name
66+ * the name of the option
67+ * @param value
68+ * the value for this option
69+ * @return the configuration itself to allow chaining
4170 * @see http://www.jshint.com/docs/
4271 */
43- public Configuration addOption ( String option , boolean value ) {
44- options .put ( option , Boolean . valueOf ( value ) );
72+ public Configuration addOption ( String name , JsonValue value ) {
73+ options .remove ( name ). add ( name , value );
4574 return this ;
4675 }
4776
@@ -57,42 +86,19 @@ public Configuration addOption( String option, boolean value ) {
5786 * @return the configuration to allow chaining
5887 */
5988 public Configuration addPredefined ( String identifier , boolean overwrite ) {
60- predefs .put ( identifier , Boolean . valueOf ( overwrite ) );
89+ predefs .remove ( identifier ). add ( identifier , overwrite );
6190 return this ;
6291 }
6392
6493 public String toJson () {
65- StringBuilder builder = new StringBuilder ();
66- builder .append ( "{" );
6794 if ( !predefs .isEmpty () ) {
68- builder .append ( "\" predef\" : {" );
69- addMap ( builder , predefs );
70- builder .append ( "}" );
71- if ( !options .isEmpty () ) {
72- builder .append ( ", " );
73- }
95+ options .remove ( "predef" ).add ( "predef" , predefs );
7496 }
75- addMap ( builder , options );
76- builder .append ( "}" );
77- return builder .toString ();
97+ return options .toString ();
7898 }
7999
80100 Object getOption ( String option ) {
81101 return options .get ( option );
82102 }
83103
84- private void addMap ( StringBuilder builder , Map <String , Object > map ) {
85- boolean first = true ;
86- for ( String key : map .keySet () ) {
87- if ( !first ) {
88- builder .append ( ", " );
89- }
90- builder .append ( '"' );
91- builder .append ( key );
92- builder .append ( "\" : " );
93- builder .append ( map .get ( key ) );
94- first = false ;
95- }
96- }
97-
98104}
0 commit comments