Java Code Examples for org.apache.commons.lang.ArrayUtils#isEquals()

The following examples show how to use org.apache.commons.lang.ArrayUtils#isEquals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SnapshotTable.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@Override
public boolean equals(Object o) {
    if ((o instanceof SnapshotTable) == false)
        return false;
    SnapshotTable that = (SnapshotTable) o;

    if (this.dict.equals(that.dict) == false)
        return false;

    //compare row by row
    if (this.rowIndices.size() != that.rowIndices.size())
        return false;
    for (int i = 0; i < this.rowIndices.size(); ++i) {
        if (!ArrayUtils.isEquals(this.rowIndices.get(i), that.rowIndices.get(i)))
            return false;
    }

    return true;
}
 
Example 2
Source File: TagMap.java    From apimanager-swagger-promote with Apache License 2.0 6 votes vote down vote up
@Override
public boolean equals(Object o) {
	if (o == this) return true;
	
	if (!(o instanceof TagMap)) return false;
	
	TagMap<String,String[]> otherTagMap = (TagMap<String,String[]>) o;
	
	if (otherTagMap.size() != size()) return false;
	
	Iterator<String> it = this.keySet().iterator();
	
	while(it.hasNext()) {
		String tagName = it.next();
		if(!otherTagMap.containsKey(tagName)) return false;
		String[] myTags = this.get(tagName);
		String[] otherTags = otherTagMap.get(tagName);
		if(!ArrayUtils.isEquals(myTags, otherTags)) return false;
	}
	return true;
}
 
Example 3
Source File: SnapshotTable.java    From kylin with Apache License 2.0 6 votes vote down vote up
@Override
public boolean equals(Object o) {
    if ((o instanceof SnapshotTable) == false)
        return false;
    SnapshotTable that = (SnapshotTable) o;

    if (this.dict.equals(that.dict) == false)
        return false;

    //compare row by row
    if (this.rowIndices.size() != that.rowIndices.size())
        return false;
    for (int i = 0; i < this.rowIndices.size(); ++i) {
        if (!ArrayUtils.isEquals(this.rowIndices.get(i), that.rowIndices.get(i)))
            return false;
    }

    return true;
}
 
Example 4
Source File: SnapshotTable.java    From Kylin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(Object o) {
    if ((o instanceof SnapshotTable) == false)
        return false;
    SnapshotTable that = (SnapshotTable) o;

    //compare row by row
    if (this.rows.size() != that.rows.size())
        return false;
    for (int i = 0; i < this.rows.size(); ++i) {
        if (!ArrayUtils.isEquals(this.rows.get(i), that.rows.get(i)))
            return false;
    }
    return true;
}
 
Example 5
Source File: RuleResultMessage.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
private boolean hasSameArgs(RuleResultMessage other) {
    if (this.args == null && other.args == null) {
        return true;
    }

    if (this.args != null && other.args != null && this.args.length == other.args.length) {
        return ArrayUtils.isEquals(this.args, other.args);
    }

    return false;
}
 
Example 6
Source File: TestConfiguration.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
private static synchronized void init(final String[] contextFiles)
{
  if (testConfiguration == null) {
    testConfiguration = new TestConfiguration(contextFiles);
  } else if (ArrayUtils.isEquals(testConfiguration.contextFiles, contextFiles) == false) {
    final String msg = "Already initialized with incompatible context files: "
        + StringHelper.listToString(", ",
            testConfiguration.contextFiles
            + ". New context files: "
            + StringHelper.listToString(",", contextFiles)
            + ". This is OK if the test case is started in fork-mode.");
    log.warn(msg);
    testConfiguration = new TestConfiguration(contextFiles);
  }
}
 
Example 7
Source File: PublicKeyAuthenticator.java    From Bukkit-SSHD with Apache License 2.0 5 votes vote down vote up
@Override
public boolean authenticate(String username, PublicKey key, ServerSession session) {
    byte[] keyBytes = key.getEncoded();
    File keyFile = new File(authorizedKeysDir, username);

    if (keyFile.exists()) {
        try {

            FileReader fr = new FileReader(keyFile);
            PemDecoder pd = new PemDecoder(fr);
            PublicKey k = pd.getPemBytes();
            pd.close();

            if (k != null) {
                if (ArrayUtils.isEquals(key.getEncoded(), k.getEncoded())) {
                    return true;
                }
            } else {
                SshdPlugin.instance.getLogger().severe("Failed to parse PEM file. " + keyFile.getAbsolutePath());
            }
        } catch (Exception e) {
            SshdPlugin.instance.getLogger()
                    .severe("Failed to process public key " + keyFile.getAbsolutePath() + ". " + e.getMessage());
        }
    } else {
        SshdPlugin.instance.getLogger().warning("Could not locate public key for " + username +
                                                ". Make sure the user's key is named the same as their user name " +
                                                "without a file extension.");
    }

    return false;
}
 
Example 8
Source File: EncoderFactory.java    From systemds with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public static Encoder createEncoder(String spec, String[] colnames, ValueType[] schema, FrameBlock meta) {
	Encoder encoder = null;
	int clen = schema.length;
	
	try {
		//parse transform specification
		JSONObject jSpec = new JSONObject(spec);
		List<Encoder> lencoders = new ArrayList<>();
	
		//prepare basic id lists (recode, feature hash, dummycode, pass-through)
		List<Integer> rcIDs = Arrays.asList(ArrayUtils.toObject(
			TfMetaUtils.parseJsonIDList(jSpec, colnames, TfMethod.RECODE.toString())));
		List<Integer>haIDs = Arrays.asList(ArrayUtils.toObject(
			TfMetaUtils.parseJsonIDList(jSpec, colnames, TfMethod.HASH.toString())));
		List<Integer> dcIDs = Arrays.asList(ArrayUtils.toObject(
			TfMetaUtils.parseJsonIDList(jSpec, colnames, TfMethod.DUMMYCODE.toString())));
		List<Integer> binIDs = TfMetaUtils.parseBinningColIDs(jSpec, colnames);
		//note: any dummycode column requires recode as preparation, unless it follows binning
		rcIDs = new ArrayList<Integer>(CollectionUtils.subtract(
			CollectionUtils.union(rcIDs, CollectionUtils.subtract(dcIDs, binIDs)), haIDs));
		List<Integer> ptIDs = new ArrayList<Integer>(CollectionUtils.subtract(
			CollectionUtils.subtract(UtilFunctions.getSeqList(1, clen, 1),
				CollectionUtils.union(rcIDs,haIDs)), binIDs));
		List<Integer> oIDs = Arrays.asList(ArrayUtils.toObject(
			TfMetaUtils.parseJsonIDList(jSpec, colnames, TfMethod.OMIT.toString())));
		List<Integer> mvIDs = Arrays.asList(ArrayUtils.toObject(
			TfMetaUtils.parseJsonObjectIDList(jSpec, colnames, TfMethod.IMPUTE.toString())));
		
		//create individual encoders
		if( !rcIDs.isEmpty() ) {
			EncoderRecode ra = new EncoderRecode(jSpec, colnames, clen);
			ra.setColList(ArrayUtils.toPrimitive(rcIDs.toArray(new Integer[0])));
			lencoders.add(ra);
		}
		if( !haIDs.isEmpty() ) {
			EncoderFeatureHash ha = new EncoderFeatureHash(jSpec, colnames, clen);
			ha.setColList(ArrayUtils.toPrimitive(haIDs.toArray(new Integer[0])));
			lencoders.add(ha);
		}
		if( !ptIDs.isEmpty() )
			lencoders.add(new EncoderPassThrough(
				ArrayUtils.toPrimitive(ptIDs.toArray(new Integer[0])), clen));
		if( !binIDs.isEmpty() )
			lencoders.add(new EncoderBin(jSpec, colnames, schema.length));
		if( !dcIDs.isEmpty() )
			lencoders.add(new EncoderDummycode(jSpec, colnames, schema.length));
		if( !oIDs.isEmpty() )
			lencoders.add(new EncoderOmit(jSpec, colnames, schema.length));
		if( !mvIDs.isEmpty() ) {
			EncoderMVImpute ma = new EncoderMVImpute(jSpec, colnames, schema.length);
			ma.initRecodeIDList(rcIDs);
			lencoders.add(ma);
		}
		
		//create composite decoder of all created encoders
		encoder = new EncoderComposite(lencoders);
		
		//initialize meta data w/ robustness for superset of cols
		if( meta != null ) {
			String[] colnames2 = meta.getColumnNames();
			if( !TfMetaUtils.isIDSpec(jSpec) && colnames!=null && colnames2!=null 
				&& !ArrayUtils.isEquals(colnames, colnames2) ) 
			{
				HashMap<String, Integer> colPos = getColumnPositions(colnames2);
				//create temporary meta frame block w/ shallow column copy
				FrameBlock meta2 = new FrameBlock(meta.getSchema(), colnames2);
				meta2.setNumRows(meta.getNumRows());
				for( int i=0; i<colnames.length; i++ ) {
					if( !colPos.containsKey(colnames[i]) ) {
						throw new DMLRuntimeException("Column name not found in meta data: "
							+colnames[i]+" (meta: "+Arrays.toString(colnames2)+")");
					}
					int pos = colPos.get(colnames[i]);
					meta2.setColumn(i, meta.getColumn(pos));
					meta2.setColumnMetadata(i, meta.getColumnMetadata(pos));
				}
				meta = meta2;
			}
			encoder.initMetaData(meta);
		}
	}
	catch(Exception ex) {
		throw new DMLRuntimeException(ex);
	}
	
	return encoder;
}
 
Example 9
Source File: HardwareAddressImpl.java    From c2mon with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * The two addresses are considered equals if they're of the same type and all their non-static attributes are equal
 */
@Override
public final boolean equals(final Object copy) {

  boolean result = copy != null && copy instanceof HardwareAddress && this.getClass().equals(copy.getClass());

  if (result) {

    Field[] fields = this.getClass().getDeclaredFields();
    for (Field field : fields) {
      if (!Modifier.isFinal(field.getModifiers()) && !Modifier.isStatic(field.getModifiers())
          && !Modifier.isTransient(field.getModifiers())) {
        try {

          if ((field.get(this) != null && field.get(copy) == null)
              || (field.get(this) == null && field.get(copy) != null)) {
            result = false;
          } else if (field.get(this) != null && field.get(copy) != null) {

            if (field.getType().isArray()) {

              if (Object[].class.isAssignableFrom(field.getType())) {
                result = Arrays.equals((Object[]) field.get(this), (Object[]) field.get(copy));
              } else {
                result = ArrayUtils.isEquals(field.get(this), field.get(copy));
              }

            } else {
              result = field.get(this).equals(field.get(copy));
            }
          }
        } catch (Exception e) {
          result = false;
        }
      }

      if (!result) {
        break;
      }
    }
  }

  return result;
}
 
Example 10
Source File: EncoderFactory.java    From systemds with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public static Encoder createEncoder(String spec, String[] colnames, ValueType[] schema, FrameBlock meta) {
	Encoder encoder = null;
	int clen = schema.length;
	
	try {
		//parse transform specification
		JSONObject jSpec = new JSONObject(spec);
		List<Encoder> lencoders = new ArrayList<>();
	
		//prepare basic id lists (recode, feature hash, dummycode, pass-through)
		List<Integer> rcIDs = Arrays.asList(ArrayUtils.toObject(
			TfMetaUtils.parseJsonIDList(jSpec, colnames, TfMethod.RECODE.toString())));
		List<Integer>haIDs = Arrays.asList(ArrayUtils.toObject(
			TfMetaUtils.parseJsonIDList(jSpec, colnames, TfMethod.HASH.toString())));
		List<Integer> dcIDs = Arrays.asList(ArrayUtils.toObject(
			TfMetaUtils.parseJsonIDList(jSpec, colnames, TfMethod.DUMMYCODE.toString())));
		List<Integer> binIDs = TfMetaUtils.parseBinningColIDs(jSpec, colnames);
		//note: any dummycode column requires recode as preparation, unless it follows binning
		rcIDs = new ArrayList<Integer>(CollectionUtils.subtract(
			CollectionUtils.union(rcIDs, CollectionUtils.subtract(dcIDs, binIDs)), haIDs));
		List<Integer> ptIDs = new ArrayList<Integer>(CollectionUtils.subtract(
			CollectionUtils.subtract(UtilFunctions.getSeqList(1, clen, 1),
				CollectionUtils.union(rcIDs,haIDs)), binIDs));
		List<Integer> oIDs = Arrays.asList(ArrayUtils.toObject(
			TfMetaUtils.parseJsonIDList(jSpec, colnames, TfMethod.OMIT.toString())));
		List<Integer> mvIDs = Arrays.asList(ArrayUtils.toObject(
			TfMetaUtils.parseJsonObjectIDList(jSpec, colnames, TfMethod.IMPUTE.toString())));
		
		//create individual encoders
		if( !rcIDs.isEmpty() ) {
			EncoderRecode ra = new EncoderRecode(jSpec, colnames, clen);
			ra.setColList(ArrayUtils.toPrimitive(rcIDs.toArray(new Integer[0])));
			lencoders.add(ra);
		}
		if( !haIDs.isEmpty() ) {
			EncoderFeatureHash ha = new EncoderFeatureHash(jSpec, colnames, clen);
			ha.setColList(ArrayUtils.toPrimitive(haIDs.toArray(new Integer[0])));
			lencoders.add(ha);
		}
		if( !ptIDs.isEmpty() )
			lencoders.add(new EncoderPassThrough(
				ArrayUtils.toPrimitive(ptIDs.toArray(new Integer[0])), clen));
		if( !binIDs.isEmpty() )
			lencoders.add(new EncoderBin(jSpec, colnames, schema.length));
		if( !dcIDs.isEmpty() )
			lencoders.add(new EncoderDummycode(jSpec, colnames, schema.length));
		if( !oIDs.isEmpty() )
			lencoders.add(new EncoderOmit(jSpec, colnames, schema.length));
		if( !mvIDs.isEmpty() ) {
			EncoderMVImpute ma = new EncoderMVImpute(jSpec, colnames, schema.length);
			ma.initRecodeIDList(rcIDs);
			lencoders.add(ma);
		}
		
		//create composite decoder of all created encoders
		encoder = new EncoderComposite(lencoders);
		
		//initialize meta data w/ robustness for superset of cols
		if( meta != null ) {
			String[] colnames2 = meta.getColumnNames();
			if( !TfMetaUtils.isIDSpec(jSpec) && colnames!=null && colnames2!=null 
				&& !ArrayUtils.isEquals(colnames, colnames2) ) 
			{
				HashMap<String, Integer> colPos = getColumnPositions(colnames2);
				//create temporary meta frame block w/ shallow column copy
				FrameBlock meta2 = new FrameBlock(meta.getSchema(), colnames2);
				meta2.setNumRows(meta.getNumRows());
				for( int i=0; i<colnames.length; i++ ) {
					if( !colPos.containsKey(colnames[i]) ) {
						throw new DMLRuntimeException("Column name not found in meta data: "
							+colnames[i]+" (meta: "+Arrays.toString(colnames2)+")");
					}
					int pos = colPos.get(colnames[i]);
					meta2.setColumn(i, meta.getColumn(pos));
					meta2.setColumnMetadata(i, meta.getColumnMetadata(pos));
				}
				meta = meta2;
			}
			encoder.initMetaData(meta);
		}
	}
	catch(Exception ex) {
		throw new DMLRuntimeException(ex);
	}
	
	return encoder;
}
 
Example 11
Source File: MTLSService.java    From oxAuth with MIT License 4 votes vote down vote up
public boolean processMTLS(HttpServletRequest httpRequest, HttpServletResponse httpResponse, FilterChain filterChain, Client client) throws Exception {
    log.debug("Trying to authenticate client {} via {} ...", client.getClientId(),
            client.getAuthenticationMethod());

    final String clientCertAsPem = httpRequest.getHeader("X-ClientCert");
    if (StringUtils.isBlank(clientCertAsPem)) {
        log.debug("Client certificate is missed in `X-ClientCert` header, client_id: {}.", client.getClientId());
        return false;
    }

    X509Certificate cert = CertUtils.x509CertificateFromPem(clientCertAsPem);
    if (cert == null) {
        log.debug("Failed to parse client certificate, client_id: {}.", client.getClientId());
        return false;
    }
    final String cn = CertUtils.getCN(cert);
    if (!cn.equals(client.getClientId())) {
        log.error("Client certificate CN does not match clientId. Reject call, CN: " + cn + ", clientId: " + client.getClientId());
        throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).entity(errorResponseFactory.getErrorAsJson(TokenErrorResponseType.INVALID_CLIENT, httpRequest.getParameter("state"), "")).build());
    }

    if (client.getAuthenticationMethod() == AuthenticationMethod.TLS_CLIENT_AUTH) {

        final String subjectDn = client.getAttributes().getTlsClientAuthSubjectDn();
        if (StringUtils.isBlank(subjectDn)) {
            log.debug(
                    "SubjectDN is not set for client {} which is required to authenticate it via `tls_client_auth`.",
                    client.getClientId());
            return false;
        }

        // we check only `subjectDn`, the PKI certificate validation is performed by
        // apache/httpd
        if (subjectDn.equals(cert.getSubjectDN().getName())) {
            log.debug("Client {} authenticated via `tls_client_auth`.", client.getClientId());
            authenticatedSuccessfully(client, httpRequest);

            filterChain.doFilter(httpRequest, httpResponse);
            return true;
        }
    }

    if (client.getAuthenticationMethod() == AuthenticationMethod.SELF_SIGNED_TLS_CLIENT_AUTH) { // disable it
        final PublicKey publicKey = cert.getPublicKey();
        final byte[] encodedKey = publicKey.getEncoded();

        JSONObject jsonWebKeys = Strings.isNullOrEmpty(client.getJwks())
                ? JwtUtil.getJSONWebKeys(client.getJwksUri())
                : new JSONObject(client.getJwks());

        if (jsonWebKeys == null) {
            log.debug("Unable to load json web keys for client: {}, jwks_uri: {}, jks: {}", client.getClientId(),
                    client.getJwksUri(), client.getJwks());
            return false;
        }

        final JSONWebKeySet keySet = JSONWebKeySet.fromJSONObject(jsonWebKeys);
        for (JSONWebKey key : keySet.getKeys()) {
            if (ArrayUtils.isEquals(encodedKey,
                    cryptoProvider.getPublicKey(key.getKid(), jsonWebKeys, null).getEncoded())) {
                log.debug("Client {} authenticated via `self_signed_tls_client_auth`, matched kid: {}.",
                        client.getClientId(), key.getKid());
                authenticatedSuccessfully(client, httpRequest);

                filterChain.doFilter(httpRequest, httpResponse);
                return true;
            }
        }
    }
    return false;
}