Java tutorial
//package com.java2s; /******************************************************************************* * Copyright (c) 2006, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ import java.util.HashSet; public class Main { private static void addNumberToBase(StringBuffer base, boolean bracketed, HashSet<Integer> set) { if (set.size() > 0) { // Limit on the number of auto-generated item numbers to check for int limit = 100; // Check the set for the numbers encountered and generate the // lowest number accordingly if (set.contains(new Integer(0)) == false) { // Use base } else { for (int x = 1; x < limit; x++) { // Check if the number was already used to auto-generate an // existing item if (set.contains(new Integer(x)) == false) { if (bracketed) base.append(" ("); //$NON-NLS-1$ base.append(x); if (bracketed) base.append(")"); //$NON-NLS-1$ break; } } } } } }