當前位置: 首頁>>代碼示例>>Java>>正文


Java ObjectArrays.newArray方法代碼示例

本文整理匯總了Java中com.google.common.collect.ObjectArrays.newArray方法的典型用法代碼示例。如果您正苦於以下問題:Java ObjectArrays.newArray方法的具體用法?Java ObjectArrays.newArray怎麽用?Java ObjectArrays.newArray使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.common.collect.ObjectArrays的用法示例。


在下文中一共展示了ObjectArrays.newArray方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: remove

import com.google.common.collect.ObjectArrays; //導入方法依賴的package包/類
/**
 * Removes the first occurrence of a given value from an array, if it is present in the array.
 * The array is assumed to be unordered.
 *
 * @param array
 *          to remove the value from; may be {@code null}
 * @param value
 *          to remove; must not be {@code null}
 * @return an array not containing the first occurrence of value, but containing all other elements of
 *         the original array. If the original array does not contain the given value, the returned
 *         array is == identical to the array passed in.
 */
public T[] remove(final T[] array, final T value) {
  if (array == null) {
    return null;
  }
  int i = find(array, value);
  if (i == 0 && array.length == 1) {
    return null;
  }
  if (i >= 0) {
    // Found it: remove value. i is guaranteed to be < array.length here.
    T[] newArray = ObjectArrays.newArray(componentType, array.length - 1);
    if (i > 0) {
      System.arraycopy(array, 0, newArray, 0, i);
    }
    if (i + 1 < array.length) {
      System.arraycopy(array, i + 1, newArray, i, array.length - i - 1);
    }
    return newArray;
  }
  return array;
}
 
開發者ID:dsldevkit,項目名稱:dsl-devkit,代碼行數:34,代碼來源:ArrayUtils.java

示例2: readSignal

import com.google.common.collect.ObjectArrays; //導入方法依賴的package包/類
protected <T> T[] readSignal(Class<T> t, OffsetLength offsetLength) throws ReconException {
    if (offsetLength.getOffset() == 0 || offsetLength.getLength() == 0) {
        throw new ReconException("Cannot read signal as offset and length invalid " + offsetLength);
    }
    try {
        byte[] bytes = new byte[offsetLength.getLength()];
        if (offsetLength.getLength() == resource.read(offsetLength.getOffset(), bytes)) {
            if (isCompressed()) {
                bytes = Compression.decompress(bytes);
            }
            BufferUnpacker unpacker = getMessagePack().createBufferUnpacker(bytes);
            int arrayLength = unpacker.readArrayBegin();
            T[] out = ObjectArrays.newArray(t, arrayLength);
            for (int i = 0; i < arrayLength; i++) {
                out[i] = (T) readObject(unpacker);
            }
            unpacker.readArrayEnd();
            unpacker.close();
            return out;
        }
        throw new ReconException("Failed to read signal at location");
    } catch (IOException ex) {
        throw new ReconException("Failed to read signal", ex);
    }
}
 
開發者ID:harmanpa,項目名稱:jrecon,代碼行數:26,代碼來源:MeldReader.java

示例3: getHandles

import com.google.common.collect.ObjectArrays; //導入方法依賴的package包/類
static Object[] getHandles(NMSPathPoint[] points) {
	Object[] handles = ObjectArrays.newArray(NMSPathPoint.nmsPathPoint, points.length);
	for (int i = 0; i < points.length; i++) {
		handles[i] = points[i].getHandle();
	}
	return handles;
}
 
開發者ID:InventivetalentDev,項目名稱:CompactNPCLib,代碼行數:8,代碼來源:NMSPathEntity.java

示例4: convertArrayWithDeserializer

import com.google.common.collect.ObjectArrays; //導入方法依賴的package包/類
public static <T> T[] convertArrayWithDeserializer(ScriptObjectMirror mirror, String key, IScriptObjectDeserializer deserializer, Class<T> toClass) {
    try {
        Object val = mirror.get(key);
        return convertArrayWithDeserializer(val, deserializer, toClass);
    } catch (Exception e) {
        LogHelper.error("Error deserializing array of " + toClass.getName(), e);
        return ObjectArrays.newArray(toClass, 0);
    }
}
 
開發者ID:legendblade,項目名稱:CraftingHarmonics,代碼行數:10,代碼來源:DeserializerHelpers.java

示例5: arrayIf

import com.google.common.collect.ObjectArrays; //導入方法依賴的package包/類
@Override protected <T> Object arrayIf(T[] resolvedP, boolean isPrimitive) {
	int l = Math.max(2, r.nextInt(5));
	if (isPrimitive) {
		this.clazz = Primitives.wrap(this.clazz);
	}
	Object[] rArr = ObjectArrays.newArray(this.clazz, l);
	for (int i = 0; i < rArr.length; i++) {
		rArr[i] = get(this.clazz);
	}
	if (isPrimitive) {
		return Arrays2.unwraps(rArr);
	}
	
	return rArr;
}
 
開發者ID:jronrun,項目名稱:benayn,代碼行數:16,代碼來源:Randoms.java

示例6: getElements

import com.google.common.collect.ObjectArrays; //導入方法依賴的package包/類
@Override
public Object[] getElements(Object inputElement) {
    if (topLevelElement == null) {
        return ObjectArrays.newArray(Object.class, 0);
    }
    return getElements();
}
 
開發者ID:kopl,項目名稱:SPLevo,代碼行數:8,代碼來源:RefinementTreeContentProviderBase.java

示例7: initialize_string_array_java_with_guava

import com.google.common.collect.ObjectArrays; //導入方法依賴的package包/類
@Test
public void initialize_string_array_java_with_guava () {
	
	String[] nflNorthStadiums = ObjectArrays.newArray(String.class, 4);

	nflNorthStadiums[0] = "Lambeau Field";
       nflNorthStadiums[1] = "Soldier Field";
       nflNorthStadiums[2] = "Mall of America Fielddagger";
       nflNorthStadiums[3] = "Ford Fielddagger";
       
       assertTrue(nflNorthStadiums.length == 4);
}
 
開發者ID:wq19880601,項目名稱:java-util-examples,代碼行數:13,代碼來源:InitializeArray.java

示例8: initialize_string_array_java_with_guava_reference_type

import com.google.common.collect.ObjectArrays; //導入方法依賴的package包/類
@Test
public void initialize_string_array_java_with_guava_reference_type () {

	String[] nflStadiums = {""};

	String[] nflNorthStadiums = ObjectArrays.newArray(nflStadiums, 4);
	
	nflNorthStadiums[0] = "Lambeau Field";
       nflNorthStadiums[1] = "Soldier Field";
       nflNorthStadiums[2] = "Mall of America Fielddagger";
       nflNorthStadiums[3] = "Ford Fielddagger";
       
       assertEquals(4, nflNorthStadiums.length);
}
 
開發者ID:wq19880601,項目名稱:java-util-examples,代碼行數:15,代碼來源:InitializeArray.java

示例9: DirList3

import com.google.common.collect.ObjectArrays; //導入方法依賴的package包/類
public DirList3(Entry3[] entries, boolean eof) {
  this.entries = ObjectArrays.newArray(entries, entries.length);
  System.arraycopy(this.entries, 0, entries, 0, entries.length);
  this.eof = eof;
}
 
開發者ID:ict-carch,項目名稱:hadoop-plus,代碼行數:6,代碼來源:READDIR3Response.java

示例10: DirListPlus3

import com.google.common.collect.ObjectArrays; //導入方法依賴的package包/類
public DirListPlus3(EntryPlus3[] entries, boolean eof) {
  this.entries = ObjectArrays.newArray(entries, entries.length);
  System.arraycopy(this.entries, 0, entries, 0, entries.length);
  this.eof = eof;
}
 
開發者ID:ict-carch,項目名稱:hadoop-plus,代碼行數:6,代碼來源:READDIRPLUS3Response.java

示例11: arrayIf

import com.google.common.collect.ObjectArrays; //導入方法依賴的package包/類
@Override protected <T> Object arrayIf(T[] resolvedP, boolean isPrimitive) {
	return ObjectArrays.newArray(this.clazz, 0);
}
 
開發者ID:jronrun,項目名稱:benayn,代碼行數:4,代碼來源:Me3Test.java

示例12: wraps

import com.google.common.collect.ObjectArrays; //導入方法依賴的package包/類
/**
 * Converts the given target as an array of primitive to object.
 * 
 * @param target
 * @return
 */
@SuppressWarnings("unchecked")
public static <T> T[] wraps(Object target, Class<?> expectClazz) {
	if (null == target) {
		return null;
	}
	
	Class<?> clazz = target.getClass();
	
	if (null != expectClazz) {
	    expectClazz = expectClazz.isArray() ? expectClazz.getComponentType() : expectClazz;
	    Function<Object, T> func = (Function<Object, T>) Funcs.getParseFunction(expectClazz);
	    
	    if (null != func) {
	        expectClazz = Primitives.wrap(expectClazz);
	        T[] expectArray = null;
	        
	        //target is array
	        if (clazz.isArray()) {
	            Object[] providArray = wraps(target);
	            expectArray = (T[]) ObjectArrays.newArray(expectClazz, providArray.length);
	            
                   for (int i = 0; i < providArray.length; i++) {
                       expectArray[i] = func.apply(providArray[i]);
                   }
               }
	        //target is not array
	        else {
	            expectArray = (T[]) ObjectArrays.newArray(expectClazz, 1);
	            expectArray[0] = func.apply(target);
	        }
	        
	        return expectArray;
	    }
	    
	}
	
	if (!clazz.isArray()) {
		T[] a = (T[]) ObjectArrays.newArray(clazz, 1);
		a[0] = (T) target;
		return a;
	}
	
	return new StructBehavior<T[]>(target) {

		@Override protected T[] primitiveIs(boolean primitive) { return primitive ? toBeContinued() : noneMatched(); }
		@Override protected T[] booleanIf() { return (T[]) wrap((boolean[]) this.delegate); }
		@Override protected T[] byteIf() { return (T[]) wrap((byte[]) this.delegate); }
		@Override protected T[] characterIf() { return (T[]) wrap((char[]) this.delegate); }
		@Override protected T[] doubleIf() { return (T[]) wrap((double[]) this.delegate); }
		@Override protected T[] floatIf() { return (T[]) wrap((float[]) this.delegate); }
		@Override protected T[] integerIf() { return (T[]) wrap((int[]) this.delegate); }
		@Override protected T[] longIf() { return (T[]) wrap((long[]) this.delegate); }
		@Override protected T[] shortIf() { return (T[]) wrap((short[]) this.delegate); }
		@Override protected T[] nullIf() { return null; }
		@Override protected T[] noneMatched() { return (T[]) this.delegate; }
		
	}.doDetect();
}
 
開發者ID:jronrun,項目名稱:benayn,代碼行數:65,代碼來源:Arrays2.java

示例13: toArray

import com.google.common.collect.ObjectArrays; //導入方法依賴的package包/類
public Object[] toArray(Object[] a) {
  return ObjectArrays.newArray(a, 0);
}
 
開發者ID:joshng,項目名稱:papaya,代碼行數:4,代碼來源:FunCollection.java

示例14: toArray

import com.google.common.collect.ObjectArrays; //導入方法依賴的package包/類
/**
 * Returns an array containing all of the elements in this queue, in
 * proper sequence; the runtime type of the returned array is that of
 * the specified array.  If the queue fits in the specified array, it
 * is returned therein.  Otherwise, a new array is allocated with the
 * runtime type of the specified array and the size of this queue.
 *
 * <p>If this queue fits in the specified array with room to spare
 * (i.e., the array has more elements than this queue), the element in
 * the array immediately following the end of the queue is set to
 * <tt>null</tt>.
 *
 * <p>Like the {@link #toArray()} method, this method acts as bridge between
 * array-based and collection-based APIs.  Further, this method allows
 * precise control over the runtime type of the output array, and may,
 * under certain circumstances, be used to save allocation costs.
 *
 * <p>Suppose <tt>x</tt> is a queue known to contain only strings.
 * The following code can be used to dump the queue into a newly
 * allocated array of <tt>String</tt>:
 *
 * <pre>
 *     String[] y = x.toArray(new String[0]);</pre>
 *
 * <p>Note that <tt>toArray(new Object[0])</tt> is identical in function to
 * <tt>toArray()</tt>.
 *
 * @param a the array into which the elements of the queue are to
 *          be stored, if it is big enough; otherwise, a new array of the
 *          same runtime type is allocated for this purpose
 * @return an array containing all of the elements in this queue
 * @throws ArrayStoreException if the runtime type of the specified array
 *         is not a supertype of the runtime type of every element in
 *         this queue
 * @throws NullPointerException if the specified array is null
 */
@Override public <T> T[] toArray(T[] a) {
    final E[] items = this.items;
    final Monitor monitor = this.monitor;
    monitor.enter();
    try {
        if (a.length < count)
            a = ObjectArrays.newArray(a, count);

        int k = 0;
        int i = takeIndex;
        while (k < count) {
            // This cast is not itself safe, but the following statement
            // will fail if the runtime type of items[i] is not assignable
            // to the runtime type of a[k++], which is all that the method
            // contract requires (see @throws ArrayStoreException above).
            @SuppressWarnings("unchecked")
            T t = (T) items[i];
            a[k++] = t;
            i = inc(i);
        }
        if (a.length > count)
            a[count] = null;
        return a;
    } finally {
        monitor.leave();
    }
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:64,代碼來源:MonitorBasedArrayBlockingQueue.java

示例15: removeAll

import com.google.common.collect.ObjectArrays; //導入方法依賴的package包/類
/**
 * Remove from array {@code o1} all elements which exists in {@code o2} if {@code retain} flag is
 * set to {@code false}. If argument {@code retain} is set to {@code true}, then in result
 * collection will be common elements from both arrays.
 *
 * @param o1 input array
 * @param o2 array, elements of which should be removed from the {@code o2} array
 * @param retain true if operation should be performed with retain algorithm, false means that
 *     from {@code o1} should be removed all elements that contains in {@code o2}
 * @param <T> type of given {@code o1} and {@code o2}
 * @return new array, which contains elements based on operation type
 * @throws IllegalArgumentException in case if given arrays null
 * @since 4.3.0
 */
public static <T> T[] removeAll(T[] o1, T[] o2, boolean retain) {
  checkArgument(o1 != null && o2 != null, "Input arrays are null");

  T[] retained = retain ? ObjectArrays.newArray(o1, 0) : o1;

  for (int index = 0; index < o1.length; index++) {
    if (indexOf(o2, o1[index]) != -1) {
      retained = retain ? add(retained, o1[index]) : remove(retained, o1[index]);
    }
  }

  return retained;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:28,代碼來源:Arrays.java


注:本文中的com.google.common.collect.ObjectArrays.newArray方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。