com.bazaarvoice.jolt.defaultr.ArrayKey Maven / Gradle / Ivy
/*
* Copyright 2013 Bazaarvoice, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.bazaarvoice.jolt.defaultr;
import com.bazaarvoice.jolt.common.DeepCopy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
public class ArrayKey extends Key {
private Collection keyInts;
private int keyInt = -1;
public ArrayKey( String jsonKey, Object spec ) {
super( jsonKey, spec );
// Handle ArrayKey specific stuff
switch( getOp() ){
case OR :
keyInts = new ArrayList<>();
for( String orLiteral : keyStrings ) {
int orInt = Integer.parseInt( orLiteral );
keyInts.add( orInt );
}
break;
case LITERAL:
keyInt = Integer.parseInt( rawKey );
keyInts = Arrays.asList( keyInt );
break;
case STAR:
keyInts = Collections.emptyList();
break;
default :
throw new IllegalStateException( "Someone has added an op type without changing this method." );
}
}
@Override
protected int getLiteralIntKey() {
return keyInt;
}
@Override
protected void applyChild( Object container ) {
if ( container instanceof List ) {
@SuppressWarnings( "unchecked" )
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy