001/*
002 * JPPF.
003 * Copyright (C) 2005-2018 JPPF Team.
004 * http://www.jppf.org
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package org.jppf.utils.configuration;
020
021import org.jppf.utils.StringUtils;
022
023/**
024 * Implementation of {@link JPPFProperty} for properties whose value is an array of space-separated {@code int}s.
025 * @author Laurent Cohen
026 * @since 6.0
027 */
028public class IntArrayProperty extends AbstractJPPFProperty<int[]> {
029  /**
030   * Explicit serialVersionUID.
031   */
032  private static final long serialVersionUID = 1L;
033
034  /**
035   * Initialize this property with the specified name and default value.
036   * @param name the name of this property.
037   * @param defaultValue the default value of this property, used when the property is not defined.
038   * @param aliases other names that may be given to this property (e.g. older names from previous versions).
039   */
040  public IntArrayProperty(final String name, final int[] defaultValue, final String...aliases) {
041    super(name, defaultValue, aliases);
042  }
043
044  @Override
045  public int[] valueOf(final String value) {
046    return StringUtils.parseIntValues(value);
047  }
048
049  @Override
050  public String toString(final int[] value) {
051    if (value == null) return null;
052    final StringBuilder sb = new StringBuilder();
053    for (int i=0; i<value.length; i++) {
054      if (i > 0) sb.append(" ");
055      sb.append(value[i]);
056    }
057    return sb.toString();
058  }
059
060  @Override
061  public Class<int[]> valueType() {
062    return int[].class;
063  }
064}