Java edu.emory.mathcs.backport.java.util.Arrays 代码实例

・11 分钟阅读

以下是展示如何使用edu.emory.mathcs.backport.java.util.Arrays的最佳示例。 我们使用了代码质量辨别算法从开源项目中提取出了最佳的优秀示例。

实例 1


/**
 * Return a map of Person objects in the db with only accountId, email and additionalProperties populated. 
 * {@inheritDoc}
 * .
 */
@SuppressWarnings("unchecked")
@Override
public List<Map<String, Object>> execute(final String inRequest)
{
    return (List<Map<String, Object>>) getEntityManager().createQuery(
            "select new map(p.accountId as accountId, p.email as email,"
                    + "p.additionalProperties as additionalProperties) from Person p where p.accountId in (:uuids)")
                    .setParameter("uuids", new ArrayList<String>(Arrays.asList(inRequest.split(","))))
                    .getResultList();
}
 

实例 2


/**
 * Get the list of {@link Component}s which must be on the local system for this bootstrapper to
 * be executable.
 * 
 * @note If the {@link DependsLocal} annotation is not specified this bootstrapper will always
 *       execute.
 * @see {@link DependsLocal}
 * @see BootstrapException#throwFatal(String)
 * @return List<Component> which must present on the local system for this bootstrapper to
 *         execute.
 */
public List<Component> getDependsLocal( ) {
  if ( dependsLocal != null ) {
    return dependsLocal;
  } else {
    synchronized ( this ) {
      if ( dependsLocal != null ) {
        return dependsLocal;
      } else {
        if ( !From( this.getClass( ) ).has( DependsLocal.class ) ) {
          dependsLocal = Lists.newArrayListWithExpectedSize( 0 );
        } else {
          dependsLocal = Arrays.asList( From( this.getClass( ) ).get( DependsLocal.class ).value( ) );
        }
        return dependsLocal;
      }
    }
  }
}
 

实例 3


@SuppressWarnings("unchecked")
@Before
public void setup() {
        includesAnalyzer = mock(IncludesAnalyzer.class);
        recompilationJudge = new GccRecompilationJudge(mock(Log.class), includesAnalyzer);
        sourceFile = mock(File.class);
        objectFile = mock(File.class);
        dependFile = mock(File.class);
        includedFile = mock(File.class);
        when(sourceFile.exists()).thenReturn(true);
        when(objectFile.exists()).thenReturn(true);
        when(dependFile.exists()).thenReturn(true);
        when(includedFile.exists()).thenReturn(true);
        ncf = mock(NativeCodeFile.class);
        when(ncf.getSourceFile()).thenReturn(sourceFile);
        when(ncf.getObjectFile()).thenReturn(objectFile);
        when(ncf.getDependFile()).thenReturn(dependFile);
        try {
                when(includesAnalyzer.getIncludedFiles(ncf)).thenReturn(Arrays.asList(new File[] { includedFile }));
        } 
        catch (MojoExecutionException e) {
                fail();
        }
}
 

实例 4


@SuppressWarnings("unchecked")
public void setFilterContent(String filterContent)
{
    if(filterContent != null)
    {
        filterContent = filterContent.replace("r","");
        this.filterItems =
            Arrays.asList(filterContent.split(NEWLINE));
    } else {
        this.filterItems = new ArrayList<String>();
    }
}
 

实例 5


@Test
public void shouldReturnSingleResultWhenNoInterestCalculationResultsAreReturned() {
    // setup
    List<EndOfDayDetail> endOfDayDetailsForPeriods =  new ArrayList<EndOfDayDetail>();
    CalendarPeriod today = new CalendarPeriodBuilder().build();
    List<CalendarPeriod> postingPeriods = Arrays.asList(new CalendarPeriod[] {today});
    List<InterestCalculationPeriodResult> noInterestCalculationResults = new ArrayList<InterestCalculationPeriodResult>();
    // stubbing
    when(interestCalculationPeriodCalculator.calculateDetails(today, TestUtils.createMoney("0"), endOfDayDetailsForPeriods)).thenReturn(noInterestCalculationResults);
    // exercise test
    List<InterestPostingPeriodResult> results = interestPostingPeriodCalculator.calculateAllPostingPeriodDetails(endOfDayDetailsForPeriods, postingPeriods);
    assertFalse(results.isEmpty());
}
 

实例 6


public List<ListView> getListViewsBySystem(String... sysCodes){
        List<String> codes=Arrays.asList(sysCodes);
        StringBuilder hql = new StringBuilder();
        int len=0;
        if(codes!=null)len=codes.size();
        Object[] vals=new Object[len+1];
        hql.append("select lv from ListView lv,Menu m where lv.menuId=m.id and lv.companyId=?");// order by lv.code
        if(ContextUtils.getCompanyId()==null){
                log.debug("companyId???null");
                throw new RuntimeException("companyId???null");
        }
        vals[0]=ContextUtils.getCompanyId();
        if(codes!=null){
                hql.append(" and ");
                int i=1;
                for(String code:codes){
                        hql.append(" (m.code=?");
                        hql.append(" or ");
                        vals[i++]=code;
                }
                if(hql.toString().contains("or")){
                        hql.replace(hql.lastIndexOf("or"), hql.length(), "");
                        hql.append(")");
                }
        }
        hql.append(" order by lv.code");
        return this.find(hql.toString(), vals);
}
 

实例 7


@Test
public void testGetAllUsers() throws Exception {
  List<String> foundUsers = Arrays.asList( new String[] { "admin", "suzy" } );
  when( usernameSearch.search( any( filterArgs.getClass() ) ) ).thenReturn( foundUsers );
  service.setAllUsernamesSearch( usernameSearch );
  service.setUsernameComparator( usernameComparator );
  List<String> users = service.getAllUsers();
  assertNotNull( users );
  assertEquals( foundUsers.size(), users.size() );
  for ( String user : foundUsers ) {
    assertTrue( users.contains( user ) );
  }
  verify( usernameComparator ).compare( "suzy", "admin" );
}
 

实例 8


@Override
public List<String> getNextNetworkPartitions(NetworkPartitionAlgorithmContext networkPartitionAlgorithmContext) {
    if (networkPartitionAlgorithmContext == null) {
        return null;
    }
    ApplicationPolicy applicationPolicy = PolicyManager.getInstance().getApplicationPolicy(
            networkPartitionAlgorithmContext.getApplicationPolicyId());
    if (applicationPolicy == null) {
        return null;
    }
    String[] networkPartitions = applicationPolicy.getNetworkPartitions();
    if (networkPartitions == null || networkPartitions.length == 0) {
        return null;
    }
    return Arrays.asList(networkPartitions);
}
 

实例 9


public CopyOnWriteArrayList(Collection c) {
    // must deal with concurrent collections
    Object[] array = c.toArray();
    // make sure the array is Object[] type
    if (array.getClass() != Object[].class) {
        array = Arrays.copyOf(array, array.length, Object[].class);
    }
    // assume that c.toArray() has returned a new array instance, as
    // required by the spec
    setArray(array);
}
 

实例 10


public Object[] toArray(Object[] a) {
    Object[] array = getArray();
    int length = array.length;
    if (a.length < length) {
        return Arrays.copyOf(array, length, a.getClass());
    }
    else {
        System.arraycopy(array, 0, a, 0, length);
        if (a.length > length) a[length] = null;
        return a;
    }
}
 

实例 11


public CopyOnWriteArrayList(Collection c) {
    // must deal with concurrent collections
    Object[] array = c.toArray();
    // make sure the array is Object[] type
    if (array.getClass() != Object[].class) {
        array = Arrays.copyOf(array, array.length, Object[].class);
    }
    // assume that c.toArray() has returned a new array instance, as
    // required by the spec
    setArray(array);
}
 

实例 12


public Object[] toArray(Object[] a) {
    Object[] array = getArray();
    int length = array.length;
    if (a.length < length) {
        return Arrays.copyOf(array, length, a.getClass());
    }
    else {
        System.arraycopy(array, 0, a, 0, length);
        if (a.length > length) a[length] = null;
        return a;
    }
}
 

实例 13


private void pushValues(double[] values, long timestamp)
{
    synchronized (this)
    {
        this._timestamps.add(timestamp);
        this._values.add(Arrays.copyOf(values, values.length));
    }
}
 
讨论
淘淘あ西西 profile image