Double checking retrieval/creation of an object

@param args Optional arguments to pass to {@link #retrieve(Object...)}, {@link
#create(Object...)}, and {@link #invalid(Object, Object...)}.
@return A retrieved or created object.
355462
public final T get(Object... args) {
        // Grab a read lock to try retrieving the object
        this.readLock.lock();
        try {

            // See if the object already exists and is valid
            final T value = this.retrieve(args);
            if (!this.invalid(value, args)) {
                if (getLogger().isDebugEnabled()) {
                    getLogger().debug("Using retrieved (first attempt) Object='" + value + "'");
                }

                return value;
            }
        } finally {
            // Release the read lock
            this.readLock.unlock();
        }

        // Object must not be valid, switch to a write lock
        this.writeLock.lock();
        try {
            // Check again if the object exists and is valid
            T value = this.retrieve(args);
            if (this.invalid(value, args)) {

                // Object is not valid, create it
                value = this.create(args);

                if (getLogger().isDebugEnabled()) {
                    getLogger().debug("Created new Object='" + value + "'");
                }
            } else if (getLogger().isDebugEnabled()) {
                getLogger().debug("Using retrieved (second attempt) Object='" + value + "'");
            }

            return value;
        } finally {
            // switch back to the read lock
            this.writeLock.unlock();
        }
    }
488938
public List<Object> querySingleRowResults(String sql, String[] args) {
		return db.querySingleRowResults(sql, args);
	}
458311
function ( arg, obj ) {
		if ( $[arg] !== undefined || !obj instanceof Object ) {
			throw new Error( label.error.invalidArguments );
		}
		
		$[arg] = obj;

		return $[arg];
	}
1123813
@Override
    protected final T create(Object... args) {
        if (this.creating.get()) {
            throw new IllegalStateException(
                    "Singleton creator has been called again while creation is in progress, this is indicative of a creation loop in a single thread");
        }

        this.creating.set(true);
        try {
            final T instance = this.createSingleton(args);
            this.instance = instance;
            this.created.set(true);
            return instance;
        } finally {
            this.creating.set(false);
        }
    }
198232
def get_or_create(cls, **kwargs):
        """"""

        data = cls._get(**kwargs)
        if data is None:
            return cls(**kwargs), True
        return cls.deserialize(data), False
1006995
public static ProcessExecutionResult getResultFromProcess(String[] args) {
    try {
      Process process = Runtime.getRuntime().exec(args);
      StringBuilder outputSb = new StringBuilder();
      try (BufferedReader processOutputReader = new BufferedReader(
          new InputStreamReader(process.getInputStream()))) {
        String line;
        while ((line = processOutputReader.readLine()) != null) {
          outputSb.append(line);
          outputSb.append(LINE_SEPARATOR);
        }
      }
      StringBuilder errorSb = new StringBuilder();
      try (BufferedReader processErrorReader = new BufferedReader(
          new InputStreamReader(process.getErrorStream()))) {
        String line;
        while ((line = processErrorReader.readLine()) != null) {
          errorSb.append(line);
          errorSb.append(LINE_SEPARATOR);
        }
      }
      process.waitFor();
      return new ProcessExecutionResult(process.exitValue(), outputSb.toString().trim(),
          errorSb.toString().trim());
    } catch (IOException e) {
      System.err.println("Failed to execute command.");
      return new ProcessExecutionResult(1, "", e.getMessage());
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
      System.err.println("Interrupted.");
      return new ProcessExecutionResult(1, "", e.getMessage());
    }
  }
559768
private void lookupInstance(String args[]) {
        String serviceName = args[1];
        System.out.println("lookupInstance, serviceName=" + serviceName);
        try {
            ServiceInstance instance = ServiceDirectory.getLookupManager().lookupInstance(serviceName);
            printServiceInstance(instance);
        } catch (ServiceException e) {
            e.printStackTrace();
            fail(e.getServiceDirectoryError().getErrorMessage());
        }
    }
985988
public static boolean checkArgs(String[] args) {        
        if (args.length < 4) {
            return false;
        }
        
        if (args[0].compareToIgnoreCase("-modeldir") != 0) {
            return false;
        }
        
        if (!(args[2].compareToIgnoreCase("-inputfile") == 0 ||
                args[2].compareToIgnoreCase("-inputdir") == 0)) {
            return false;
        }
        
        return true;
    }
877193
@Override
	public Object create(Object locator) throws CreateException {
		for (Registration registration : _registrations) {
			if (registration.getLocator().equals(locator)) {
				try {
					return registration.getFactory().create(locator);
				} catch (Exception ex) {
					if (ex instanceof CreateException)
						throw (CreateException) ex;

					throw (CreateException) new CreateException(null, "Failed to create object for " + locator)
							.withCause(ex);
				}
			}
		}
		return null;
	}
151288
def get_or_create(cls, **kwargs):
    

    try:
        obj = cls.objects.get(**kwargs)
        created = False
    except cls.DoesNotExist:
        obj = cls(**kwargs)
        created = True
        calculate_hash(obj)
        obj.save()

    return (obj, created)
918658
public static Class<?>[] collectArgTypes(final Object[] args) {
        final Class<?>[] result = new Class<?>[args.length];
        collectArgTypes(args, result, 0, 0, args.length);
        return result;
    }
521080
public static void main(String[] args) {
        try {
            Twitter twitter = new TwitterFactory().getInstance();
            List<SavedSearch> savedSearches = twitter.getSavedSearches();
            for (SavedSearch savedSearch : savedSearches) {
                System.out.println("[name:" + savedSearch.getName() + " query:" + savedSearch.getQuery() + " id:"
                        + savedSearch.getId() + "]");
            }
            System.exit(0);
        } catch (TwitterException te) {
            te.printStackTrace();
            System.out.println("Failed to retrieve saved searches: " + te.getMessage());
            System.exit(-1);
        }
    }
646613
public T newInstance(Object... args) throws Throwable
    {
        Constructor<? extends T> constructor = ClassUtils.findBestTypedConstructor(klass, args);
        return ClassUtils.invoke(constructor, args);
    }
620941
public static BeanCodeGen createFromArgs(String[] args) {
        if (args == null) {
            throw new IllegalArgumentException("Arguments must not be null");
        }
        String indent = "    ";
        String prefix = "";
        String defaultStyle = null;
        boolean recurse = false;
        int verbosity = 1;
        boolean write = true;
        File file = null;
        BeanGenConfig config = null;
        if (args.length == 0) {
            throw new IllegalArgumentException("No arguments specified");
        }
        for (int i = 0; i < args.length - 1; i++) {
            String arg = args[i];
            if (arg == null) {
                throw new IllegalArgumentException("Argument must not be null: " + Arrays.toString(args));
            }
            if (arg.startsWith("-indent=tab")) {
                indent = "\t";
            } else if (arg.startsWith("-indent=")) {
                indent = "          ".substring(0, Integer.parseInt(arg.substring(8)));
            } else if (arg.startsWith("-prefix=")) {
                prefix = arg.substring(8);
            } else if (arg.equals("-R")) {
                recurse = true;
            } else if (arg.startsWith("-config=")) {
                if (config != null) {
                    throw new IllegalArgumentException("Argument 'config' must not be specified twice: " + Arrays.toString(args));
                }
                config = BeanGenConfig.parse(arg.substring(8));
            } else if (arg.startsWith("-style=")) {
                if (defaultStyle != null) {
                    throw new IllegalArgumentException("Argument 'style' must not be specified twice: " + Arrays.toString(args));
                }
                defaultStyle = arg.substring(7);
            } else if (arg.startsWith("-verbose=")) {
                verbosity = Integer.parseInt(arg.substring(9));
            } else if (arg.startsWith("-v=")) {
                System.out.println("Deprecated command line argument -v (use -verbose instead)");
                verbosity = Integer.parseInt(arg.substring(3));
            } else if (arg.equals("-nowrite")) {
                write = false;
            } else {
                throw new IllegalArgumentException("Unknown argument: " + arg);
            }
        }
        file = new File(args[args.length - 1]);
        List<File> files = findFiles(file, recurse);
        
        if (config == null) {
            config = BeanGenConfig.parse("guava");
        }
        config.setIndent(indent);
        config.setPrefix(prefix);
        if (defaultStyle != null) {
            config.setDefaultStyle(defaultStyle);
        }
        return new BeanCodeGen(files, config, verbosity, write);
    }
265422
public static <T> Set<T> createSet(T... args) {
        HashSet<T> newSet = new HashSet<T>();
        Collections.addAll(newSet, args);
        return newSet;
    }
735525
def get_or_create(self, **kwargs):
        
        assert kwargs, "get_or_create() must be passed at least one keyword argument"

        defaults = kwargs.pop("defaults", {})
        lookup = kwargs.copy()

        try:
            return self.get(**lookup), False
        except self.resource.DoesNotExist:
            params = dict([(k, v) for k, v in kwargs.items()])
            params.update(defaults)

            obj = self.create(**params)
            return obj, True
54502
@Override
    protected final T create(Object... args) {
        final K key = this.getKey(args);
        final T value = this.createInternal(key, args);
        this.objectCache.put(key, value);
        return value;
    }